Skip to content

Commit

Permalink
Merge pull request #40 from UmbrellaLeaf5/gui_restructure_and_table_m…
Browse files Browse the repository at this point in the history
…odify

gui restructure and table modify
  • Loading branch information
Stargazer2005 authored Apr 14, 2024
2 parents cbd74c6 + 5338bc5 commit dfc0a32
Show file tree
Hide file tree
Showing 48 changed files with 786 additions and 965 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ add_subdirectory(${QCUSTOMPLOT_DIR}) # here adding qcustomplot subfolder

# ---------------------- Our code folders ----------------------
add_subdirectory(lib)
add_subdirectory(gui)
add_subdirectory(tests)
add_subdirectory(main)
add_subdirectory(backend)
Expand Down
7 changes: 6 additions & 1 deletion cmake_paths.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cmake_path(SET QCUSTOMPLOT_DIR "${CMAKE_SOURCE_DIR}/qcustomplot")
cmake_path(SET ICECREAM-CPP_DIR "${CMAKE_SOURCE_DIR}/icecream-cpp")
cmake_path(SET CMAKESCRIPTS_DIR "${CMAKE_SOURCE_DIR}/cmake_scripts")
cmake_path(SET IMAGES_DIR "${CMAKE_SOURCE_DIR}/images")
cmake_path(SET IMAGES_DIR "${CMAKE_SOURCE_DIR}/images")

cmake_path(SET PROJECT_DIR "${CMAKE_SOURCE_DIR}")

cmake_path(SET GUI_DIR "${CMAKE_SOURCE_DIR}/gui")
cmake_path(SET DATATOOLS_DIR "${CMAKE_SOURCE_DIR}/data_tools")
4 changes: 3 additions & 1 deletion cmake_scripts/scripts_for_vscode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ function(load_qcustomplot_dll START_DIR)
endif()

foreach(file ${QCUSTOMPLOTDLLFILES})
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/main)
if(QCUSTOMPLOTDLLFILES)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/main)
endif()
endforeach()
return()
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,37 @@

#include <icecream.hpp>

namespace gui {
namespace data_tools {

void DataManager::Draw(GuiObjType obj_type, size_t index, QCustomPlot* plot) {
void DataManager::Remove(gui::ObjectType obj_type, size_t index) {
switch (obj_type) {
case GuiObjType::Targets: {
targets_[index].SetGraphIndex(plot->plottableCount());
targets_[index].Draw(plot);
break;
}

case GuiObjType::Hills: {
hills_[index].SetGraphIndex(plot->plottableCount());
hills_[index].Draw(plot);
break;
}

case GuiObjType::TrappyCircles: {
tr_circles_[index].SetItemIndex(plot->itemCount());
tr_circles_[index].Draw(plot);
break;
}

case GuiObjType::TrappyLines: {
tr_lines_[index].SetGraphIndex(plot->plottableCount());
tr_lines_[index].Draw(plot);
break;
}
}
}

void DataManager::Remove(GuiObjType obj_type, size_t index) {
switch (obj_type) {
case GuiObjType::Targets: {
case gui::ObjectType::Targets: {
targets_.erase(targets_.begin() + index);
break;
}

case GuiObjType::Hills: {
case gui::ObjectType::Hills: {
hills_.erase(hills_.begin() + index);
break;
}

case GuiObjType::TrappyCircles: {
case gui::ObjectType::TrappyCircles: {
tr_circles_.erase(tr_circles_.begin() + index);
break;
}

case GuiObjType::TrappyLines: {
case gui::ObjectType::TrappyLines: {
tr_lines_.erase(tr_lines_.begin() + index);
break;
}
}
}

void DataManager::Clear() {
while (targets_.size() > 0) Remove(GuiObjType::Targets, 0);

while (tr_circles_.size() > 0) Remove(GuiObjType::TrappyCircles, 0);

while (tr_lines_.size() > 0) Remove(GuiObjType::TrappyLines, 0);

while (hills_.size() > 0) Remove(GuiObjType::Hills, 0);
}

QString DataManager::GetTexted(GuiObjType obj_type) {
QString text;

switch (obj_type) {
case GuiObjType::Targets: {
text += "Targets on plot: \n";
for (size_t i = 0; i < targets_.size(); i++) {
auto target = targets_[i];
text += "• target n." + QString::number(i + 1) + ":\n";
text += " plot id: " + QString::number(target.GetPlottableIndex()) +
":\n";
text += " x: " + QString::number(target.GetPoint().x) + "\n";
text += " y: " + QString::number(target.GetPoint().y) + "\n";
}
break;
}

case GuiObjType::Hills: {
text += "Hills on plot: \n";
for (size_t i = 0; i < hills_.size(); i++) {
auto hill = hills_[i];
text += "• hill n." + QString::number(i + 1) + ":\n";
text +=
" plot id: " + QString::number(hill.GetPlottableIndex()) + ":\n";
for (size_t j = 0; j < hill.GetPoints().size(); j++) {
auto point = hill.GetPoints()[j];
text += " point n." + QString::number(j + 1) + ":\n";
text += " x: " + QString::number(point.x) + "\n";
text += " y: " + QString::number(point.y) + "\n";
}
}
break;
}

case GuiObjType::TrappyCircles: {
text += "Trappy circles on plot: \n";
for (size_t i = 0; i < tr_circles_.size(); i++) {
auto tr_circle = tr_circles_[i];
text += "• trappy c. n." + QString::number(i + 1) + ":\n";
text +=
" plot id: " + QString::number(tr_circle.GetItemIndex()) + ":\n";
text += " x: " + QString::number(tr_circle.GetCenter().x) + "\n";
text += " y: " + QString::number(tr_circle.GetCenter().y) + "\n";
text += " r: " + QString::number(tr_circle.GetRadius()) + "\n";
}
break;
}

case GuiObjType::TrappyLines: {
text += "Trappy lines on plot: \n";
for (size_t i = 0; i < tr_lines_.size(); i++) {
auto tr_line = tr_lines_[i];
text += "• trappy l. n." + QString::number(i + 1) + ":\n";
text += " plot id: " + QString::number(tr_line.GetPlottableIndex()) +
":\n";
for (size_t j = 0; j < tr_line.GetTargets().size(); j++) {
auto target = tr_line.GetTargets()[j];
text += " target n." + QString::number(j + 1) + ":\n";
text += " x: " + QString::number(target.GetPoint().x) + "\n";
text += " y: " + QString::number(target.GetPoint().y) + "\n";
}
}
break;
}
}

return text;
targets_.clear();
tr_circles_.clear();
tr_lines_.clear();
hills_.clear();
}

// ---------------------- Target methods ----------------------
Expand Down Expand Up @@ -277,4 +177,4 @@ void DataManager::Set(std::vector<lib::TrappyLine> tr_lines) {
tr_lines_.push_back(gui::TrappyLine(tr_line));
}

} // namespace gui
} // namespace data_tools
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
#pragma once

#include <qcustomplot.h>
#include "gui/hill.h"
#include "gui/target.h"
#include "gui/trappy_circle.h"
#include "gui/trappy_line.h"

#include <initializer_list>
#include <vector>

#include "../hill.h"
#include "../target.h"
#include "../trappy_circle.h"
#include "../trappy_line.h"

namespace gui {
namespace data_tools {

// @brief класс, хранящий gui объекты и связывающий их с QCustomPlot
class DataManager {
public:
DataManager() = default;

// methods

/**
* @brief отрисовывает на полотне объект по индексу
* @param obj_type: тип объекта
* @param index: индекс объекта в его векторе
* @param plot: указатель на полотно
*/
void Draw(GuiObjType obj_type, size_t index, QCustomPlot* plot);

/**
* @brief удаляет объект из менеджера по индексу
* @param obj_type: тип объекта
* @param index: индекс объекта в его векторе
*/
void Remove(GuiObjType obj_type, size_t index);
void Remove(gui::ObjectType obj_type, size_t index);

/// @brief очищает все вектора объектов
void Clear();

/**
* @brief возвращает представление определенных типов объектов в виде текста
* @param obj_type: тип объектов
* @return QString: текст
*/
QString GetTexted(GuiObjType obj_type);

// ---------------------- Target methods ----------------------

// for gui::Target
Expand Down Expand Up @@ -173,13 +152,12 @@ class DataManager {
return tr_lines_;
}

// ~methods

private:
// TODO: переп. всё на указатели, чтобы исправить проблему c изменением копий
std::vector<gui::Hill> hills_;
std::vector<gui::Target> targets_;
std::vector<gui::TrappyCircle> tr_circles_;
std::vector<gui::TrappyLine> tr_lines_;
};

} // namespace gui
} // namespace data_tools
25 changes: 25 additions & 0 deletions data_tools/plot_area/plot_area.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "plot_area.h"

#include <icecream.hpp>

namespace data_tools {

void PlotArea::Setup(DataManager* manager) { manager_.reset(manager); }

void PlotArea::Redraw() {
plot_->clearPlottables();
plot_->clearItems();

for (auto& target : manager_->GetTargets()) target.Draw(plot_.get());

for (auto& hill : manager_->GetHills()) hill.Draw(plot_.get());

for (auto& tr_circle : manager_->GetTrappyCircles())
tr_circle.Draw(plot_.get());

for (auto& tr_line : manager_->GetTrappyLines()) tr_line.Draw(plot_.get());

plot_->replot();
}

} // namespace data_tools
34 changes: 34 additions & 0 deletions data_tools/plot_area/plot_area.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <memory>

#include "data_tools/data_manager/data_manager.h"

namespace data_tools {

/// @brief класс, упрощающий управление классами gui на QCustomPlot
class PlotArea {
public:
PlotArea() = default;

PlotArea(QCustomPlot* plot) : plot_{plot} {}

void Setup(DataManager* manager);

/**
* @brief устанавливает значение plot
* @param plot: указатель на полотно
*/
void SetPlot(QCustomPlot* plot) { plot_.reset(plot); }

/// @brief перерисовывает на полотне все объекты и обновляет данные
void Redraw();

private:
// i love unique_ptr's, i love logic schemes
std::unique_ptr<QCustomPlot> plot_;

std::unique_ptr<DataManager> manager_;
};

} // namespace data_tools
Loading

0 comments on commit dfc0a32

Please sign in to comment.