From 1a4fc053d3e1f8c95486108cbc2d3ce08f162a82 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:45:08 +0300 Subject: [PATCH 01/28] fix comments style --- main/plot_area/plot_area.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/plot_area/plot_area.h b/main/plot_area/plot_area.h index 003257b..3841a7f 100644 --- a/main/plot_area/plot_area.h +++ b/main/plot_area/plot_area.h @@ -233,10 +233,10 @@ class PlotArea { // ~methods private: - // @brief обновляет данные в лейблах все объектов + /// @brief обновляет данные в лейблах все объектов void UpdateInfoLabels(); - // @brief обновляет данные в таблицах всех объектов + /// @brief обновляет данные в таблицах всех объектов void UpdateTables(); // vars From 0f536073db1186d1a9f841425a2d94eb9eb57639 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:35:19 +0300 Subject: [PATCH 02/28] add and fix constructors and operator= to gui classes --- gui/base.h | 6 ++++++ gui/hill.h | 8 +++++++- gui/target.h | 8 +++++++- gui/trappy_circle.h | 9 ++++++++- gui/trappy_line.h | 8 +++++++- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/gui/base.h b/gui/base.h index 620e581..5eb0cd8 100644 --- a/gui/base.h +++ b/gui/base.h @@ -12,6 +12,12 @@ class Drawable { * @param plot: указатель на соотв. полотно */ virtual void Draw(QCustomPlot* plot) const = 0; + + // Drawable(const Drawable&) = delete; + // IDK: нужно ли запрещать копирование и париться с vector, + // учитывая, что индексы должны быть уникальными? + + Drawable() = default; }; // @brief типы объектов по категориям diff --git a/gui/hill.h b/gui/hill.h index f9af842..4dbfb81 100644 --- a/gui/hill.h +++ b/gui/hill.h @@ -38,9 +38,15 @@ class Hill : public Drawable { Hill(std::vector points, QColor color = QColor(50, 200, 50, 255)) : data_(points), color_{color} {} - Hill(lib::Hill data, QColor color = QColor(50, 200, 50, 255)) + Hill(const lib::Hill& data, QColor color = QColor(50, 200, 50, 255)) : data_(data), color_{color} {} + Hill(const Hill&) = default; + Hill(Hill&&) = default; + + Hill& operator=(const Hill&) = default; + Hill& operator=(Hill&&) = default; + lib::Point GetCenter() const { return data_.GetCenter(); } double GetRadius() const { return data_.GetRadius(); } lib::Hill GetData() const { return data_; } diff --git a/gui/target.h b/gui/target.h index d349a7e..18d2b08 100644 --- a/gui/target.h +++ b/gui/target.h @@ -14,7 +14,13 @@ class Target : public Drawable { Target(double x, double y) : data_(x, y) {} Target(lib::Point p) : data_(p) {} - Target(lib::Target data) : data_(data) {} + Target(const lib::Target& data) : data_(data) {} + + Target(const Target&) = default; + Target(Target&&) = default; + + Target& operator=(const Target&) = default; + Target& operator=(Target&&) = default; void SetPoint(lib::Point p) { data_.SetPoint(p); } void SetPoint(double x, double y) { data_.SetPoint(x, y); } diff --git a/gui/trappy_circle.h b/gui/trappy_circle.h index 113faf1..3e9a5c0 100644 --- a/gui/trappy_circle.h +++ b/gui/trappy_circle.h @@ -20,9 +20,16 @@ class TrappyCircle : public Drawable { QColor color = QColor(200, 50, 50, 255)) : data_(center, radius), color_{color} {} - TrappyCircle(lib::TrappyCircle data, QColor color = QColor(200, 50, 50, 255)) + TrappyCircle(const lib::TrappyCircle& data, + QColor color = QColor(200, 50, 50, 255)) : data_(data), color_{color} {} + TrappyCircle(const TrappyCircle&) = default; + TrappyCircle(TrappyCircle&&) = default; + + TrappyCircle& operator=(const TrappyCircle&) = default; + TrappyCircle& operator=(TrappyCircle&&) = default; + lib::Point GetCenter() const { return data_.GetCenter(); } double GetRadius() const { return data_.GetRadius(); } QColor GetColor() const { return color_; } diff --git a/gui/trappy_line.h b/gui/trappy_line.h index 2c32a9d..144c9c1 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -17,7 +17,13 @@ class TrappyLine : public Drawable { TrappyLine(std::initializer_list targets); - TrappyLine(lib::TrappyLine data) : data_(data){}; + TrappyLine(const lib::TrappyLine& data) : data_(data){}; + + TrappyLine(const TrappyLine&) = default; + TrappyLine(TrappyLine&&) = default; + + TrappyLine& operator=(const TrappyLine&) = default; + TrappyLine& operator=(TrappyLine&&) = default; void SetNewTargets(std::initializer_list targets); From 80f0818f7bc78853f4e2ebc2df1ccb6214cfcb00 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:46:31 +0300 Subject: [PATCH 03/28] update TableManager with using DataManager --- main/plot_area/plot_area.h | 4 ++-- main/table_manager/table_manager.h | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/main/plot_area/plot_area.h b/main/plot_area/plot_area.h index 3841a7f..3d11fb0 100644 --- a/main/plot_area/plot_area.h +++ b/main/plot_area/plot_area.h @@ -13,9 +13,9 @@ /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: - PlotArea() = default; + PlotArea() : manager_(), t_manager_(manager_) {} - PlotArea(QCustomPlot* plot) : manager_(), plot_(plot) {} + PlotArea(QCustomPlot* plot) : manager_(), t_manager_(manager_), plot_(plot) {} // methods diff --git a/main/table_manager/table_manager.h b/main/table_manager/table_manager.h index 3316ecb..b6378f8 100644 --- a/main/table_manager/table_manager.h +++ b/main/table_manager/table_manager.h @@ -4,15 +4,12 @@ #include #include -#include "../../gui/hill.h" -#include "../../gui/target.h" -#include "../../gui/trappy_circle.h" -#include "../../gui/trappy_line.h" +#include "../../gui/data_manager/data_manager.h" /// @brief класс, упрощающий отображение классов gui в QTableWidget's class TableManager { public: - TableManager() = default; + TableManager(gui::DataManager& manager) : manager_{manager} {} TableManager(QTableWidget* targets_info, QTableWidget* hills_info, QTableWidget* tr_circles_info, QTableWidget* tr_lines_info) @@ -66,4 +63,6 @@ class TableManager { std::unique_ptr hills_table_{nullptr}; std::unique_ptr tr_circles_table_{nullptr}; std::unique_ptr tr_lines_table_{nullptr}; + + gui::DataManager manager_; }; \ No newline at end of file From 61a4990f169c2077e50ee75e1a96befc8a3cd60d Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:45:48 +0300 Subject: [PATCH 04/28] add itemFlags to beautify tables and try add connections on changing # for some reason connections do not work... --- main/mainwindow.ui | 14 +- main/table_manager/table_manager.cpp | 191 +++++++++++++++++++-------- main/table_manager/table_manager.h | 22 ++- 3 files changed, 167 insertions(+), 60 deletions(-) diff --git a/main/mainwindow.ui b/main/mainwindow.ui index 584d16a..a0ca645 100644 --- a/main/mainwindow.ui +++ b/main/mainwindow.ui @@ -469,11 +469,14 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} - + 0 0 + + QAbstractItemView::AllEditTriggers + 3 @@ -537,6 +540,9 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} + + QAbstractItemView::AllEditTriggers + 1 @@ -590,6 +596,9 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} + + QAbstractItemView::AllEditTriggers + true @@ -664,6 +673,9 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} + + QAbstractItemView::AllEditTriggers + 5 diff --git a/main/table_manager/table_manager.cpp b/main/table_manager/table_manager.cpp index 7d4cfd8..735efdc 100644 --- a/main/table_manager/table_manager.cpp +++ b/main/table_manager/table_manager.cpp @@ -1,22 +1,34 @@ #include "table_manager.h" +#include + void TableManager::UpdateTable(const std::vector& targets) { // кол-во столбцов = кол-во к.т. targets_table_->setColumnCount(targets.size()); for (size_t i = 0; i < targets.size(); i++) { - targets_table_->setHorizontalHeaderItem( - i, new QTableWidgetItem( - "n. " + QString::number(i + 1))); // номер к.т. = индекс + 1 + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + targets_table_->setHorizontalHeaderItem(i, + item); // номер к.т. = индекс + 1 // в строки добавляем индекс на полотне и координаты - targets_table_->setItem( - 0, i, - new QTableWidgetItem(QString::number(targets[i].GetPlottableIndex()))); - targets_table_->setItem( - 1, i, new QTableWidgetItem(QString::number(targets[i].GetPoint().x))); - targets_table_->setItem( - 2, i, new QTableWidgetItem(QString::number(targets[i].GetPoint().y))); + item = + new QTableWidgetItem(QString::number(targets[i].GetPlottableIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + targets_table_->setItem(0, i, item); + + item = new QTableWidgetItem(QString::number(targets[i].GetPoint().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + targets_table_->setItem(1, i, item); + + item = new QTableWidgetItem(QString::number(targets[i].GetPoint().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + targets_table_->setItem(2, i, item); } targets_table_->update(); } @@ -36,26 +48,37 @@ void TableManager::UpdateTable(const std::vector& hills) { hills_table_->setRowCount(hills_max_points * 2 + 1); for (size_t i = 0; i < hills.size(); i++) { - hills_table_->setHorizontalHeaderItem( - i, new QTableWidgetItem( - "n. " + QString::number(i + 1))); // номер рельефа = индекс + 1 + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + hills_table_->setHorizontalHeaderItem(i, + item); // номер рельефа = индекс + 1 // в строки добавляем индекс на полотне и координаты всех точек - hills_table_->setItem( - 0, i, - new QTableWidgetItem(QString::number(hills[i].GetPlottableIndex()))); + item = new QTableWidgetItem(QString::number(hills[i].GetPlottableIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + hills_table_->setItem(0, i, item); + for (size_t j = 1; j < hills[i].GetPoints().size() * 2; j += 2) { + // названия строк с координатами hills_table_->setVerticalHeaderItem( j, new QTableWidgetItem("X_" + QString::number(j / 2 + 1))); hills_table_->setVerticalHeaderItem( j + 1, new QTableWidgetItem("Y_" + QString::number(j / 2 + 1))); - hills_table_->setItem(j, i, - new QTableWidgetItem(QString::number( - hills[i].GetPoints()[(j - 1) / 2].x))); - hills_table_->setItem(j + 1, i, - new QTableWidgetItem(QString::number( - hills[i].GetPoints()[(j - 1) / 2].y))); + // сами координаты + item = new QTableWidgetItem( + QString::number(hills[i].GetPoints()[(j - 1) / 2].x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + hills_table_->setItem(j, i, item); + + item = new QTableWidgetItem( + QString::number(hills[i].GetPoints()[(j - 1) / 2].y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + hills_table_->setItem(j + 1, i, item); } } hills_table_->update(); @@ -67,30 +90,42 @@ void TableManager::UpdateTable( tr_lines_table_->setColumnCount(trappy_lines.size()); for (size_t i = 0; i < trappy_lines.size(); i++) { - tr_lines_table_->setHorizontalHeaderItem( - i, new QTableWidgetItem( - "n. " + QString::number(i + 1))); // номер линии = индекс + 1 + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + tr_lines_table_->setHorizontalHeaderItem(i, + item); // номер линии = индекс + 1 // в строки добавляем индекс на полотне и координаты двух точек - tr_lines_table_->setItem(0, i, - new QTableWidgetItem(QString::number( - trappy_lines[i].GetPlottableIndex()))); - tr_lines_table_->setItem( - 1, i, - new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[0].GetPoint().x))); - tr_lines_table_->setItem( - 2, i, - new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[0].GetPoint().y))); - tr_lines_table_->setItem( - 3, i, - new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[1].GetPoint().x))); - tr_lines_table_->setItem( - 4, i, - new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[1].GetPoint().y))); + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetPlottableIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + tr_lines_table_->setItem(0, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetTargets()[0].GetPoint().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_lines_table_->setItem(1, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetTargets()[0].GetPoint().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_lines_table_->setItem(2, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetTargets()[1].GetPoint().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_lines_table_->setItem(3, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetTargets()[1].GetPoint().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_lines_table_->setItem(4, i, item); } tr_lines_table_->update(); } @@ -101,23 +136,63 @@ void TableManager::UpdateTable( tr_circles_table_->setColumnCount(trappy_circles.size()); for (size_t i = 0; i < trappy_circles.size(); i++) { + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); tr_circles_table_->setHorizontalHeaderItem( - i, new QTableWidgetItem( - "n. " + QString::number(i + 1))); // номер зоны = индекс + 1 + i, item); // номер зоны = индекс + 1 // в строки добавляем индекс на полотне и координаты точки и радиус - tr_circles_table_->setItem(0, i, - new QTableWidgetItem(QString::number( - trappy_circles[i].GetItemIndex()))); - tr_circles_table_->setItem( - 1, i, - new QTableWidgetItem(QString::number(trappy_circles[i].GetCenter().x))); - tr_circles_table_->setItem( - 2, i, - new QTableWidgetItem(QString::number(trappy_circles[i].GetCenter().y))); - tr_circles_table_->setItem( - 3, i, - new QTableWidgetItem(QString::number(trappy_circles[i].GetRadius()))); + item = + new QTableWidgetItem(QString::number(trappy_circles[i].GetItemIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + tr_circles_table_->setItem(0, i, item); + + item = + new QTableWidgetItem(QString::number(trappy_circles[i].GetCenter().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_circles_table_->setItem(1, i, item); + + item = + new QTableWidgetItem(QString::number(trappy_circles[i].GetCenter().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_circles_table_->setItem(2, i, item); + + item = new QTableWidgetItem(QString::number(trappy_circles[i].GetRadius())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_circles_table_->setItem(3, i, item); } tr_circles_table_->update(); } + +void TableManager::TargetsItemChanged(int row, int column) { + // вывод никогда не происходит + // IDK: почему? + IC(); + IC(row, column); +} + +void TableManager::HillsItemChanged(int row, int column) { + // вывод никогда не происходит + // IDK: почему? + IC(); + IC(row, column); +} + +void TableManager::TrappyCirclesItemChanged(int row, int column) { + // вывод никогда не происходит + // IDK: почему? + IC(); + IC(row, column); +} + +void TableManager::TrappyLinesChanged(int row, int column) { + // вывод никогда не происходит + // IDK: почему? + IC(); + IC(row, column); +} diff --git a/main/table_manager/table_manager.h b/main/table_manager/table_manager.h index b6378f8..c98e771 100644 --- a/main/table_manager/table_manager.h +++ b/main/table_manager/table_manager.h @@ -7,7 +7,7 @@ #include "../../gui/data_manager/data_manager.h" /// @brief класс, упрощающий отображение классов gui в QTableWidget's -class TableManager { +class TableManager : public QObject { public: TableManager(gui::DataManager& manager) : manager_{manager} {} @@ -58,7 +58,27 @@ class TableManager { */ void UpdateTable(const std::vector& trappy_circles); + private slots: + void TargetsItemChanged(int row, int column); + void HillsItemChanged(int row, int column); + void TrappyCirclesItemChanged(int row, int column); + void TrappyLinesChanged(int row, int column); + private: + void ConnectSlotsAndSignal() { + QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::TargetsItemChanged); + + QObject::connect(hills_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::HillsItemChanged); + + QObject::connect(tr_circles_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::TrappyCirclesItemChanged); + + QObject::connect(tr_lines_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::TrappyLinesChanged); + } + std::unique_ptr targets_table_{nullptr}; std::unique_ptr hills_table_{nullptr}; std::unique_ptr tr_circles_table_{nullptr}; From 887114f657d307fe3e7eb4913fddad2510ebcb86 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:02:19 +0300 Subject: [PATCH 05/28] fix connections problem --- main/table_manager/table_manager.cpp | 38 ++++++++++++++-------------- main/table_manager/table_manager.h | 21 +++++---------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/main/table_manager/table_manager.cpp b/main/table_manager/table_manager.cpp index 735efdc..c546458 100644 --- a/main/table_manager/table_manager.cpp +++ b/main/table_manager/table_manager.cpp @@ -169,30 +169,30 @@ void TableManager::UpdateTable( tr_circles_table_->update(); } -void TableManager::TargetsItemChanged(int row, int column) { - // вывод никогда не происходит - // IDK: почему? - IC(); - IC(row, column); -} +void TableManager::TargetsItemChanged(int row, int column) { IC(row, column); } -void TableManager::HillsItemChanged(int row, int column) { - // вывод никогда не происходит - // IDK: почему? - IC(); - IC(row, column); -} +void TableManager::HillsItemChanged(int row, int column) { IC(row, column); } void TableManager::TrappyCirclesItemChanged(int row, int column) { - // вывод никогда не происходит - // IDK: почему? - IC(); IC(row, column); } -void TableManager::TrappyLinesChanged(int row, int column) { - // вывод никогда не происходит - // IDK: почему? - IC(); +void TableManager::TrappyLinesItemChanged(int row, int column) { IC(row, column); } + +void TableManager::UpdateTablesConnections() { + { + QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::TargetsItemChanged); + + QObject::connect(hills_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::HillsItemChanged); + + QObject::connect(tr_circles_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::TrappyCirclesItemChanged); + + QObject::connect(tr_lines_table_.get(), &QTableWidget::cellChanged, this, + &TableManager::TrappyLinesItemChanged); + } +} diff --git a/main/table_manager/table_manager.h b/main/table_manager/table_manager.h index c98e771..dafba56 100644 --- a/main/table_manager/table_manager.h +++ b/main/table_manager/table_manager.h @@ -16,7 +16,9 @@ class TableManager : public QObject { : targets_table_{targets_info}, hills_table_{hills_info}, tr_circles_table_{tr_circles_info}, - tr_lines_table_{tr_lines_info} {} + tr_lines_table_{tr_lines_info} { + UpdateTablesConnections(); + } /** * @brief устанавливает значения всех таблиц с информацией @@ -32,6 +34,7 @@ class TableManager : public QObject { hills_table_.reset(hills_info); tr_circles_table_.reset(tr_circles_info); tr_lines_table_.reset(tr_lines_info); + UpdateTablesConnections(); } /** @@ -62,22 +65,10 @@ class TableManager : public QObject { void TargetsItemChanged(int row, int column); void HillsItemChanged(int row, int column); void TrappyCirclesItemChanged(int row, int column); - void TrappyLinesChanged(int row, int column); + void TrappyLinesItemChanged(int row, int column); private: - void ConnectSlotsAndSignal() { - QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::TargetsItemChanged); - - QObject::connect(hills_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::HillsItemChanged); - - QObject::connect(tr_circles_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::TrappyCirclesItemChanged); - - QObject::connect(tr_lines_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::TrappyLinesChanged); - } + void UpdateTablesConnections(); std::unique_ptr targets_table_{nullptr}; std::unique_ptr hills_table_{nullptr}; From cd03d09b7ad53aea7fc77585c7e37cd19f51c0af Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:37:47 +0300 Subject: [PATCH 06/28] code beautify # simplify include's # move error catching gui::TrappyLine -> lib::TrappyLine --- gui/data_manager/data_manager.h | 5 --- gui/hill.h | 5 --- gui/target.cpp | 2 -- gui/target.h | 2 -- gui/trappy_circle.cpp | 2 -- gui/trappy_circle.h | 4 +-- gui/trappy_line.cpp | 6 ---- gui/trappy_line.h | 5 --- lib/trappy_circle.cpp | 2 ++ lib/trappy_circle.h | 2 -- lib/trappy_line.cpp | 31 +++++++++++++++++++ lib/trappy_line.h | 10 +++--- main/add_objects_forms/add_hill_form.cpp | 3 -- main/add_objects_forms/add_hill_form.h | 1 + main/add_objects_forms/add_target_form.h | 1 + .../add_trappy_circle_form.cpp | 2 -- .../add_trappy_circle_form.h | 1 + main/mainwindow.cpp | 7 +++-- main/mainwindow.h | 3 +- main/plot_area/plot_area.h | 5 --- main/table_manager/table_manager.h | 2 -- tests/many_tsp_tests.cpp | 2 -- tests/tsp_tests.cpp | 2 -- 23 files changed, 46 insertions(+), 59 deletions(-) diff --git a/gui/data_manager/data_manager.h b/gui/data_manager/data_manager.h index a6ab234..cad1ca0 100644 --- a/gui/data_manager/data_manager.h +++ b/gui/data_manager/data_manager.h @@ -1,10 +1,5 @@ #pragma once -#include - -#include -#include - #include "../hill.h" #include "../target.h" #include "../trappy_circle.h" diff --git a/gui/hill.h b/gui/hill.h index 4dbfb81..47f2e32 100644 --- a/gui/hill.h +++ b/gui/hill.h @@ -1,10 +1,5 @@ #pragma once -#include - -#include -#include - #include "../lib/hill.h" #include "base.h" diff --git a/gui/target.cpp b/gui/target.cpp index a11980f..20a240f 100644 --- a/gui/target.cpp +++ b/gui/target.cpp @@ -1,7 +1,5 @@ #include "target.h" -#include - void gui::Target::Draw(QCustomPlot* plot) const { // фигура представляет собой малую серую окружность (точку) diff --git a/gui/target.h b/gui/target.h index 18d2b08..7dd2a8d 100644 --- a/gui/target.h +++ b/gui/target.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "../lib/target.h" #include "base.h" diff --git a/gui/trappy_circle.cpp b/gui/trappy_circle.cpp index 75792e2..49a463c 100644 --- a/gui/trappy_circle.cpp +++ b/gui/trappy_circle.cpp @@ -1,7 +1,5 @@ #include "trappy_circle.h" -#include - void gui::TrappyCircle::Draw(QCustomPlot* plot) const { // фигура представляет собой красный круг с полупрозрачной заливкой // (красный по умолчанию, однако цвет задаётся в аргументах конструктора) diff --git a/gui/trappy_circle.h b/gui/trappy_circle.h index 3e9a5c0..ce1f5ff 100644 --- a/gui/trappy_circle.h +++ b/gui/trappy_circle.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "../lib/trappy_circle.h" #include "base.h" @@ -46,7 +44,7 @@ class TrappyCircle : public Drawable { private: lib::TrappyCircle data_; QColor color_; - size_t item_index_; + size_t item_index_{ULLONG_MAX}; }; } // namespace gui diff --git a/gui/trappy_line.cpp b/gui/trappy_line.cpp index 16d325a..3ffbe87 100644 --- a/gui/trappy_line.cpp +++ b/gui/trappy_line.cpp @@ -3,16 +3,10 @@ namespace gui { TrappyLine::TrappyLine(std::initializer_list targets) { - if (targets.size() < 2) - throw std::invalid_argument( - "trappy line should be line with at least 2 targets"); UpdateData(targets); } void TrappyLine::SetNewTargets(std::initializer_list targets) { - if (targets.size() < 2) - throw std::invalid_argument( - "trappy line should be line with at least 2 targets"); UpdateData(targets); } diff --git a/gui/trappy_line.h b/gui/trappy_line.h index 144c9c1..39da73b 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "../lib/trappy_line.h" #include "target.h" diff --git a/lib/trappy_circle.cpp b/lib/trappy_circle.cpp index 199220e..b5a8d7e 100644 --- a/lib/trappy_circle.cpp +++ b/lib/trappy_circle.cpp @@ -1,5 +1,7 @@ #include "trappy_circle.h" +#include + namespace lib { TrappyCircle::TrappyCircle(Point center, double radius) diff --git a/lib/trappy_circle.h b/lib/trappy_circle.h index 0db65dc..8d1a3ac 100644 --- a/lib/trappy_circle.h +++ b/lib/trappy_circle.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "base.h" #include "point.h" diff --git a/lib/trappy_line.cpp b/lib/trappy_line.cpp index db12813..e963b87 100644 --- a/lib/trappy_line.cpp +++ b/lib/trappy_line.cpp @@ -1,7 +1,38 @@ #include "trappy_line.h" +#include + namespace lib { +TrappyLine::TrappyLine(std::initializer_list targets) + : targets_{targets} { + if (targets.size() < 2) + throw std::invalid_argument( + "trappy line should be line with at least 2 targets"); +} + +TrappyLine::TrappyLine(std::vector targets) : targets_{targets} { + if (targets.size() < 2) + throw std::invalid_argument( + "trappy line should be line with at least 2 targets"); +} + +void TrappyLine::SetNewTargets(std::initializer_list targets) { + if (targets.size() < 2) + throw std::invalid_argument( + "trappy line should be line with at least 2 targets"); + + targets_ = targets; +} + +void TrappyLine::SetNewTargets(std::vector targets) { + if (targets.size() < 2) + throw std::invalid_argument( + "trappy line should be line with at least 2 targets"); + + targets_ = targets; +} + QJsonObject TrappyLine::Save(int id) const { QVariantMap trappy_line_map; QVariantMap p1_map; diff --git a/lib/trappy_line.h b/lib/trappy_line.h index cbfd878..2a15f5c 100644 --- a/lib/trappy_line.h +++ b/lib/trappy_line.h @@ -18,14 +18,14 @@ class TrappyLine : public JSONable { * (конструктор исключительно по КТ, только между ними может быть перелет) * @param targets: лист контрольных точек */ - TrappyLine(std::initializer_list targets) : targets_{targets} {} + TrappyLine(std::initializer_list targets); /** * @brief инициализирует новый экземпляр Trappy Line * (конструктор исключительно по КТ, только между ними может быть перелет) * @param targets: вектор контрольных точек */ - TrappyLine(std::vector targets) : targets_{targets} {} + TrappyLine(std::vector targets); TrappyLine(const TrappyLine&) = default; TrappyLine(TrappyLine&&) = default; @@ -37,11 +37,9 @@ class TrappyLine : public JSONable { void Load(QJsonObject trappy_line_obj) override; bool IsChanged(QJsonObject trappy_line_obj) override; - void SetNewTargets(std::initializer_list targets) { - targets_ = targets; - } + void SetNewTargets(std::initializer_list targets); - void SetNewTargets(std::vector targets) { targets_ = targets; } + void SetNewTargets(std::vector targets); void AddTargets(std::initializer_list targets); void AddTargets(std::vector targets); diff --git a/main/add_objects_forms/add_hill_form.cpp b/main/add_objects_forms/add_hill_form.cpp index 3f54e85..9a3bd20 100644 --- a/main/add_objects_forms/add_hill_form.cpp +++ b/main/add_objects_forms/add_hill_form.cpp @@ -1,10 +1,7 @@ #include "add_hill_form.h" -#include - #include "ui_add_hill_form.h" - AddHillForm::AddHillForm(QWidget* parent) : QDialog(parent), ui(new Ui::AddHillForm) { ui->setupUi(this); diff --git a/main/add_objects_forms/add_hill_form.h b/main/add_objects_forms/add_hill_form.h index bbc4ae5..608f0ae 100644 --- a/main/add_objects_forms/add_hill_form.h +++ b/main/add_objects_forms/add_hill_form.h @@ -1,4 +1,5 @@ #pragma once + #include #include #include diff --git a/main/add_objects_forms/add_target_form.h b/main/add_objects_forms/add_target_form.h index d8ddeef..36c1bbb 100644 --- a/main/add_objects_forms/add_target_form.h +++ b/main/add_objects_forms/add_target_form.h @@ -1,4 +1,5 @@ #pragma once + #include namespace Ui { diff --git a/main/add_objects_forms/add_trappy_circle_form.cpp b/main/add_objects_forms/add_trappy_circle_form.cpp index e3bc0ac..fdd2a9e 100644 --- a/main/add_objects_forms/add_trappy_circle_form.cpp +++ b/main/add_objects_forms/add_trappy_circle_form.cpp @@ -1,7 +1,5 @@ #include "add_trappy_circle_form.h" -#include - #include "ui_add_trappy_circle_form.h" AddTrappyCircleForm::AddTrappyCircleForm(QWidget* parent) diff --git a/main/add_objects_forms/add_trappy_circle_form.h b/main/add_objects_forms/add_trappy_circle_form.h index a5fe9f8..ee5af7e 100644 --- a/main/add_objects_forms/add_trappy_circle_form.h +++ b/main/add_objects_forms/add_trappy_circle_form.h @@ -1,4 +1,5 @@ #pragma once + #include namespace Ui { diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index ee06b5a..4f5cca8 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -16,6 +16,7 @@ MainWindow::MainWindow(QWidget* parent) SLOT(on_plot_MousePressed())); area_.SetPlot(ui->plot); + area_.SetSettingsLabels(ui->targetInfoLabel, ui->hillInfoLabel, ui->trappyCircleInfoLabel, ui->trappyLineInfoLabel); @@ -23,6 +24,8 @@ MainWindow::MainWindow(QWidget* parent) ui->trappyCircleInfoTableWidget, ui->trappyLineInfoTableWidget); + ui->plotSettingsDockWidget->setVisible(false); + { // проверка функционала графических классов и менеджера gui::Target t_1(3, 4); @@ -41,10 +44,8 @@ MainWindow::MainWindow(QWidget* parent) area_.Redraw(); - area_.Remove(gui::GuiObjType::Targets, 0); + // area_.Remove(gui::GuiObjType::Targets, 0); } - - ui->plotSettingsDockWidget->setVisible(false); } MainWindow::~MainWindow() { delete ui; } diff --git a/main/mainwindow.h b/main/mainwindow.h index f8e1e1d..0489804 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -2,14 +2,13 @@ #include -#include "./gui_json_file/gui_json_file.h" #include "add_objects_forms/add_hill_form.h" #include "add_objects_forms/add_target_form.h" #include "add_objects_forms/add_trappy_circle_form.h" #include "add_objects_forms/add_trappy_line_form.h" +#include "gui_json_file/gui_json_file.h" #include "plot_area/plot_area.h" - QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; diff --git a/main/plot_area/plot_area.h b/main/plot_area/plot_area.h index 3d11fb0..95dbad4 100644 --- a/main/plot_area/plot_area.h +++ b/main/plot_area/plot_area.h @@ -1,11 +1,6 @@ #pragma once -#include - -#include -#include #include -#include #include "../../gui/data_manager/data_manager.h" #include "../table_manager/table_manager.h" diff --git a/main/table_manager/table_manager.h b/main/table_manager/table_manager.h index dafba56..2f2407a 100644 --- a/main/table_manager/table_manager.h +++ b/main/table_manager/table_manager.h @@ -1,8 +1,6 @@ #pragma once #include -#include -#include #include "../../gui/data_manager/data_manager.h" diff --git a/tests/many_tsp_tests.cpp b/tests/many_tsp_tests.cpp index 067fb0b..0b84906 100644 --- a/tests/many_tsp_tests.cpp +++ b/tests/many_tsp_tests.cpp @@ -4,8 +4,6 @@ #include "../Backend/travelling_salesmans_problem.h" #include "../Backend/tspgraph.h" -// #include "qcustomplot.h" - #if !defined(WIN32) #define BOOST_TEST_DYN_LINK #endif diff --git a/tests/tsp_tests.cpp b/tests/tsp_tests.cpp index 39e6075..b7f8885 100644 --- a/tests/tsp_tests.cpp +++ b/tests/tsp_tests.cpp @@ -4,8 +4,6 @@ #include "../Backend/travelling_salesmans_problem.h" #include "../Backend/tspgraph.h" -// #include "qcustomplot.h" - #if !defined(WIN32) #define BOOST_TEST_DYN_LINK #endif From 2556a3f4d00c05bf8d85b7a47127f8162be5be94 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:54:25 +0300 Subject: [PATCH 07/28] move PlotArea, DataManager and TableManager to spec folder --- CMakeLists.txt | 1 + data_tools/CMakeLists.txt | 21 +++++++++++++++++++ .../data_manager/data_manager.cpp | 0 .../data_manager/data_manager.h | 8 +++---- {main => data_tools}/plot_area/plot_area.cpp | 0 {main => data_tools}/plot_area/plot_area.h | 2 +- .../table_manager/table_manager.cpp | 0 .../table_manager/table_manager.h | 2 +- main/CMakeLists.txt | 1 + main/gui_json_file/gui_json_file.h | 2 +- main/mainwindow.h | 2 +- 11 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 data_tools/CMakeLists.txt rename {gui => data_tools}/data_manager/data_manager.cpp (100%) rename {gui => data_tools}/data_manager/data_manager.h (97%) rename {main => data_tools}/plot_area/plot_area.cpp (100%) rename {main => data_tools}/plot_area/plot_area.h (99%) rename {main => data_tools}/table_manager/table_manager.cpp (100%) rename {main => data_tools}/table_manager/table_manager.h (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 585a8de..e741e9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ add_subdirectory(gui) add_subdirectory(tests) add_subdirectory(main) add_subdirectory(backend) +add_subdirectory(data_tools) # the programmer in VS Code is tired of constantly copying one dll file, # and the command QCUSTOMPLOT_USE_LIBRARY does not work for an unknown reason diff --git a/data_tools/CMakeLists.txt b/data_tools/CMakeLists.txt new file mode 100644 index 0000000..1dad510 --- /dev/null +++ b/data_tools/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.20) + +project(data_tools VERSION 0.1 LANGUAGES CXX) + +file(GLOB_RECURSE PROJECT_SOURCES "*.h" "*.cpp") + +add_library(data_tools STATIC ${PROJECT_SOURCES}) + +target_link_libraries(data_tools PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core) + +target_link_libraries(data_tools PRIVATE lib) +target_link_libraries(data_tools PRIVATE gui) + +target_compile_definitions(data_tools PRIVATE QCUSTOMPLOT_USE_LIBRARY) +target_link_libraries(data_tools PUBLIC qcustomplot) + +include(${CMAKESCRIPTS_DIR}/scripts_for_vscode.cmake) +add_qt_runtime(${CMAKE_CURRENT_SOURCE_DIR} data_tools) + +find_package(IcecreamCpp) +include_directories(${IcecreamCpp_INCLUDE_DIRS}) \ No newline at end of file diff --git a/gui/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp similarity index 100% rename from gui/data_manager/data_manager.cpp rename to data_tools/data_manager/data_manager.cpp diff --git a/gui/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h similarity index 97% rename from gui/data_manager/data_manager.h rename to data_tools/data_manager/data_manager.h index cad1ca0..1bd4528 100644 --- a/gui/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -1,9 +1,9 @@ #pragma once -#include "../hill.h" -#include "../target.h" -#include "../trappy_circle.h" -#include "../trappy_line.h" +#include "../../gui/hill.h" +#include "../../gui/target.h" +#include "../../gui/trappy_circle.h" +#include "../../gui/trappy_line.h" namespace gui { diff --git a/main/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp similarity index 100% rename from main/plot_area/plot_area.cpp rename to data_tools/plot_area/plot_area.cpp diff --git a/main/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h similarity index 99% rename from main/plot_area/plot_area.h rename to data_tools/plot_area/plot_area.h index 95dbad4..5e155cb 100644 --- a/main/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -2,7 +2,7 @@ #include -#include "../../gui/data_manager/data_manager.h" +#include "../data_manager/data_manager.h" #include "../table_manager/table_manager.h" /// @brief класс, упрощающий управление классами gui на QCustomPlot diff --git a/main/table_manager/table_manager.cpp b/data_tools/table_manager/table_manager.cpp similarity index 100% rename from main/table_manager/table_manager.cpp rename to data_tools/table_manager/table_manager.cpp diff --git a/main/table_manager/table_manager.h b/data_tools/table_manager/table_manager.h similarity index 98% rename from main/table_manager/table_manager.h rename to data_tools/table_manager/table_manager.h index 2f2407a..9c35ea6 100644 --- a/main/table_manager/table_manager.h +++ b/data_tools/table_manager/table_manager.h @@ -2,7 +2,7 @@ #include -#include "../../gui/data_manager/data_manager.h" +#include "../data_manager/data_manager.h" /// @brief класс, упрощающий отображение классов gui в QTableWidget's class TableManager : public QObject { diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3bffa60..72c4ec9 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -33,6 +33,7 @@ target_link_libraries(main PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION target_link_libraries(main PRIVATE lib) target_link_libraries(main PRIVATE gui) +target_link_libraries(main PRIVATE data_tools) target_compile_definitions(main PRIVATE QCUSTOMPLOT_USE_LIBRARY) target_link_libraries(main PUBLIC qcustomplot) diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 7e9fd9d..e9cf139 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -1,6 +1,6 @@ #pragma once -#include "./plot_area/plot_area.h" +#include "../../data_tools/plot_area/plot_area.h" class GuiJsonFile { public: diff --git a/main/mainwindow.h b/main/mainwindow.h index 0489804..b07ce9e 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -2,12 +2,12 @@ #include +#include "../data_tools/plot_area/plot_area.h" #include "add_objects_forms/add_hill_form.h" #include "add_objects_forms/add_target_form.h" #include "add_objects_forms/add_trappy_circle_form.h" #include "add_objects_forms/add_trappy_line_form.h" #include "gui_json_file/gui_json_file.h" -#include "plot_area/plot_area.h" QT_BEGIN_NAMESPACE namespace Ui { From 34f462ba99350c2bfd387c078cba223347ec6ed5 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 21:00:17 +0300 Subject: [PATCH 08/28] update comment and delete non-using constructor --- data_tools/plot_area/plot_area.h | 2 -- data_tools/table_manager/table_manager.h | 14 +++++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index 5e155cb..c643da3 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -10,8 +10,6 @@ class PlotArea { public: PlotArea() : manager_(), t_manager_(manager_) {} - PlotArea(QCustomPlot* plot) : manager_(), t_manager_(manager_), plot_(plot) {} - // methods /** diff --git a/data_tools/table_manager/table_manager.h b/data_tools/table_manager/table_manager.h index 9c35ea6..bcecbd9 100644 --- a/data_tools/table_manager/table_manager.h +++ b/data_tools/table_manager/table_manager.h @@ -7,17 +7,13 @@ /// @brief класс, упрощающий отображение классов gui в QTableWidget's class TableManager : public QObject { public: + /** + * @brief инициализирует новый экземпляр Table Manager + * @param manager: ссылка на используемый DataManager + * (благодаря передаче по ссылке, может редактировать данные классов) + */ TableManager(gui::DataManager& manager) : manager_{manager} {} - TableManager(QTableWidget* targets_info, QTableWidget* hills_info, - QTableWidget* tr_circles_info, QTableWidget* tr_lines_info) - : targets_table_{targets_info}, - hills_table_{hills_info}, - tr_circles_table_{tr_circles_info}, - tr_lines_table_{tr_lines_info} { - UpdateTablesConnections(); - } - /** * @brief устанавливает значения всех таблиц с информацией * @param hills_info: QTableWidget с информацией о hills From 9af1c22d7cfb6b098528b8b29be189c61e2f274f Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Fri, 12 Apr 2024 21:29:03 +0300 Subject: [PATCH 09/28] add Redraw button in PlotSettings --- main/mainwindow.h | 4 ++-- main/mainwindow.ui | 18 +++++++++++++++++- main/mainwindow_connections.cpp | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/main/mainwindow.h b/main/mainwindow.h index b07ce9e..3ea4b3e 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -42,11 +42,11 @@ class MainWindow : public QMainWindow { void on_actionSave_as_triggered(); void on_actionOpen_triggered(); - void on_actionSave_triggered(); - void on_actionNew_triggered(); + void on_redrawPushButton_clicked(); + public slots: void AddTrappyCircle(double x, double y, double radius); void AddTarget(double x, double y); diff --git a/main/mainwindow.ui b/main/mainwindow.ui index a0ca645..613535a 100644 --- a/main/mainwindow.ui +++ b/main/mainwindow.ui @@ -379,7 +379,7 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} Qt::RightToLeft - + 5 @@ -395,6 +395,22 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} 5 + + + + + 0 + 0 + + + + PointingHandCursor + + + Redraw + + + diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index acb37c1..d641ea0 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -139,3 +139,5 @@ void MainWindow::on_actionNew_triggered() { } } } + +void MainWindow::on_redrawPushButton_clicked() { area_.Redraw(); } From 338e6fac8812064b05c2d57dffc6aee3912e4452 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:40:26 +0300 Subject: [PATCH 10/28] add changing from table feature for target --- data_tools/plot_area/plot_area.h | 2 +- data_tools/table_manager/table_manager.cpp | 22 ++++++++++++++-------- data_tools/table_manager/table_manager.h | 4 ++-- main/mainwindow.cpp | 16 ++++++++-------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index dedc775..da4e013 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -8,7 +8,7 @@ /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: - PlotArea() : manager_(), t_manager_(manager_) {} + PlotArea() : manager_(), t_manager_(&manager_) {} // methods diff --git a/data_tools/table_manager/table_manager.cpp b/data_tools/table_manager/table_manager.cpp index c546458..e426542 100644 --- a/data_tools/table_manager/table_manager.cpp +++ b/data_tools/table_manager/table_manager.cpp @@ -169,17 +169,23 @@ void TableManager::UpdateTable( tr_circles_table_->update(); } -void TableManager::TargetsItemChanged(int row, int column) { IC(row, column); } +void TableManager::TargetsItemChanged(int row, int column) { + auto x_item = targets_table_->item(1, column); + auto y_item = targets_table_->item(2, column); + + if (x_item != nullptr && y_item != nullptr) { + IC(column, manager_->GetTargets().size()); + if (column < manager_->GetTargets().size()) + manager_->GetTargets()[column].SetPoint(x_item->text().toDouble(), + y_item->text().toDouble()); + } +} -void TableManager::HillsItemChanged(int row, int column) { IC(row, column); } +void TableManager::HillsItemChanged(int row, int column) {} -void TableManager::TrappyCirclesItemChanged(int row, int column) { - IC(row, column); -} +void TableManager::TrappyCirclesItemChanged(int row, int column) {} -void TableManager::TrappyLinesItemChanged(int row, int column) { - IC(row, column); -} +void TableManager::TrappyLinesItemChanged(int row, int column) {} void TableManager::UpdateTablesConnections() { { diff --git a/data_tools/table_manager/table_manager.h b/data_tools/table_manager/table_manager.h index bcecbd9..1f58be8 100644 --- a/data_tools/table_manager/table_manager.h +++ b/data_tools/table_manager/table_manager.h @@ -12,7 +12,7 @@ class TableManager : public QObject { * @param manager: ссылка на используемый DataManager * (благодаря передаче по ссылке, может редактировать данные классов) */ - TableManager(gui::DataManager& manager) : manager_{manager} {} + TableManager(gui::DataManager* manager) : manager_{manager} {} /** * @brief устанавливает значения всех таблиц с информацией @@ -69,5 +69,5 @@ class TableManager : public QObject { std::unique_ptr tr_circles_table_{nullptr}; std::unique_ptr tr_lines_table_{nullptr}; - gui::DataManager manager_; + std::unique_ptr manager_; }; \ No newline at end of file diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index 4f5cca8..5a082b6 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -20,12 +20,6 @@ MainWindow::MainWindow(QWidget* parent) area_.SetSettingsLabels(ui->targetInfoLabel, ui->hillInfoLabel, ui->trappyCircleInfoLabel, ui->trappyLineInfoLabel); - area_.SetSettingsTables(ui->targetInfoTableWidget, ui->hillInfoTableWidget, - ui->trappyCircleInfoTableWidget, - ui->trappyLineInfoTableWidget); - - ui->plotSettingsDockWidget->setVisible(false); - { // проверка функционала графических классов и менеджера gui::Target t_1(3, 4); @@ -42,10 +36,16 @@ MainWindow::MainWindow(QWidget* parent) area_.Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); - area_.Redraw(); - // area_.Remove(gui::GuiObjType::Targets, 0); } + + ui->plotSettingsDockWidget->setVisible(false); + + area_.SetSettingsTables(ui->targetInfoTableWidget, ui->hillInfoTableWidget, + ui->trappyCircleInfoTableWidget, + ui->trappyLineInfoTableWidget); + + area_.Redraw(); } MainWindow::~MainWindow() { delete ui; } From 99452c25d45ad76d6eb93b7fc3c1c8454812d5b7 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:49:29 +0300 Subject: [PATCH 11/28] change name TableManager -> TablesConnection --- data_tools/plot_area/plot_area.cpp | 8 +++--- data_tools/plot_area/plot_area.h | 10 +++---- .../tables_connection.cpp} | 28 +++++++++---------- .../tables_connection.h} | 4 +-- 4 files changed, 25 insertions(+), 25 deletions(-) rename data_tools/{table_manager/table_manager.cpp => tables_connection/tables_connection.cpp} (90%) rename data_tools/{table_manager/table_manager.h => tables_connection/tables_connection.h} (96%) diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index b9daf71..a6787fa 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -65,8 +65,8 @@ void PlotArea::UpdateInfoLabels() { } void PlotArea::UpdateTables() { - t_manager_.UpdateTable(manager_.GetTargets()); - t_manager_.UpdateTable(manager_.GetHills()); - t_manager_.UpdateTable(manager_.GetTrappyLines()); - t_manager_.UpdateTable(manager_.GetTrappyCircles()); + t_connection_.UpdateTable(manager_.GetTargets()); + t_connection_.UpdateTable(manager_.GetHills()); + t_connection_.UpdateTable(manager_.GetTrappyLines()); + t_connection_.UpdateTable(manager_.GetTrappyCircles()); } diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index da4e013..3475a31 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -3,12 +3,12 @@ #include #include "../data_manager/data_manager.h" -#include "../table_manager/table_manager.h" +#include "../tables_connection/tables_connection.h" /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: - PlotArea() : manager_(), t_manager_(&manager_) {} + PlotArea() : manager_(), t_connection_(&manager_) {} // methods @@ -43,8 +43,8 @@ class PlotArea { void SetSettingsTables(QTableWidget* targets_info, QTableWidget* hills_info, QTableWidget* tr_circles_info, QTableWidget* tr_lines_info) { - t_manager_.SetSettingsTables(targets_info, hills_info, tr_circles_info, - tr_lines_info); + t_connection_.SetSettingsTables(targets_info, hills_info, tr_circles_info, + tr_lines_info); } /// @brief перерисовывает на полотне все объекты и обновляет данные @@ -244,7 +244,7 @@ class PlotArea { std::unique_ptr tr_lines_label_{nullptr}; gui::DataManager manager_; - TableManager t_manager_; + TablesConnection t_connection_; // ~vars }; diff --git a/data_tools/table_manager/table_manager.cpp b/data_tools/tables_connection/tables_connection.cpp similarity index 90% rename from data_tools/table_manager/table_manager.cpp rename to data_tools/tables_connection/tables_connection.cpp index e426542..b2e1bfa 100644 --- a/data_tools/table_manager/table_manager.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -1,8 +1,8 @@ -#include "table_manager.h" +#include "tables_connection.h" #include -void TableManager::UpdateTable(const std::vector& targets) { +void TablesConnection::UpdateTable(const std::vector& targets) { // кол-во столбцов = кол-во к.т. targets_table_->setColumnCount(targets.size()); @@ -33,7 +33,7 @@ void TableManager::UpdateTable(const std::vector& targets) { targets_table_->update(); } -void TableManager::UpdateTable(const std::vector& hills) { +void TablesConnection::UpdateTable(const std::vector& hills) { // находим максимально возможное кол-во точек среди всех холмов size_t hills_max_points = hills[0].GetPoints().size(); for (size_t i = 0; i < hills.size() - 1; i++) { @@ -84,7 +84,7 @@ void TableManager::UpdateTable(const std::vector& hills) { hills_table_->update(); } -void TableManager::UpdateTable( +void TablesConnection::UpdateTable( const std::vector& trappy_lines) { // кол-во столбцов = кол-во опасных линий tr_lines_table_->setColumnCount(trappy_lines.size()); @@ -130,7 +130,7 @@ void TableManager::UpdateTable( tr_lines_table_->update(); } -void TableManager::UpdateTable( +void TablesConnection::UpdateTable( const std::vector& trappy_circles) { // кол-во столбцов = кол-во опасных зон tr_circles_table_->setColumnCount(trappy_circles.size()); @@ -169,7 +169,7 @@ void TableManager::UpdateTable( tr_circles_table_->update(); } -void TableManager::TargetsItemChanged(int row, int column) { +void TablesConnection::TargetsItemChanged(int row, int column) { auto x_item = targets_table_->item(1, column); auto y_item = targets_table_->item(2, column); @@ -181,24 +181,24 @@ void TableManager::TargetsItemChanged(int row, int column) { } } -void TableManager::HillsItemChanged(int row, int column) {} +void TablesConnection::HillsItemChanged(int row, int column) {} -void TableManager::TrappyCirclesItemChanged(int row, int column) {} +void TablesConnection::TrappyCirclesItemChanged(int row, int column) {} -void TableManager::TrappyLinesItemChanged(int row, int column) {} +void TablesConnection::TrappyLinesItemChanged(int row, int column) {} -void TableManager::UpdateTablesConnections() { +void TablesConnection::UpdateTablesConnections() { { QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::TargetsItemChanged); + &TablesConnection::TargetsItemChanged); QObject::connect(hills_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::HillsItemChanged); + &TablesConnection::HillsItemChanged); QObject::connect(tr_circles_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::TrappyCirclesItemChanged); + &TablesConnection::TrappyCirclesItemChanged); QObject::connect(tr_lines_table_.get(), &QTableWidget::cellChanged, this, - &TableManager::TrappyLinesItemChanged); + &TablesConnection::TrappyLinesItemChanged); } } diff --git a/data_tools/table_manager/table_manager.h b/data_tools/tables_connection/tables_connection.h similarity index 96% rename from data_tools/table_manager/table_manager.h rename to data_tools/tables_connection/tables_connection.h index 1f58be8..c445413 100644 --- a/data_tools/table_manager/table_manager.h +++ b/data_tools/tables_connection/tables_connection.h @@ -5,14 +5,14 @@ #include "../data_manager/data_manager.h" /// @brief класс, упрощающий отображение классов gui в QTableWidget's -class TableManager : public QObject { +class TablesConnection : public QObject { public: /** * @brief инициализирует новый экземпляр Table Manager * @param manager: ссылка на используемый DataManager * (благодаря передаче по ссылке, может редактировать данные классов) */ - TableManager(gui::DataManager* manager) : manager_{manager} {} + TablesConnection(gui::DataManager* manager) : manager_{manager} {} /** * @brief устанавливает значения всех таблиц с информацией From 611568c053084f0a19b5f027d8dea7b61835bdaa Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 00:01:57 +0300 Subject: [PATCH 12/28] add uniform namespace for DataManager, TablesConnection, PlotArea and rename GuiObjType -> ObjectType --- data_tools/data_manager/data_manager.cpp | 43 ++++++++++--------- data_tools/data_manager/data_manager.h | 10 ++--- data_tools/plot_area/plot_area.cpp | 30 +++++++------ data_tools/plot_area/plot_area.h | 8 +++- .../tables_connection/tables_connection.cpp | 4 ++ .../tables_connection/tables_connection.h | 10 +++-- gui/base.h | 2 +- main/gui_json_file/gui_json_file.h | 6 +-- main/gui_json_file/new.cpp | 2 +- main/gui_json_file/open.cpp | 15 ++++--- main/gui_json_file/save.cpp | 2 +- main/mainwindow.cpp | 2 +- main/mainwindow.h | 2 +- 13 files changed, 77 insertions(+), 59 deletions(-) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index 1b607c3..5374bcc 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -2,29 +2,30 @@ #include -namespace gui { +namespace data_tools { -void DataManager::Draw(GuiObjType obj_type, size_t index, QCustomPlot* plot) { +void DataManager::Draw(gui::ObjectType obj_type, size_t index, + QCustomPlot* plot) { switch (obj_type) { - case GuiObjType::Targets: { + case gui::ObjectType::Targets: { targets_[index].SetGraphIndex(plot->plottableCount()); targets_[index].Draw(plot); break; } - case GuiObjType::Hills: { + case gui::ObjectType::Hills: { hills_[index].SetGraphIndex(plot->plottableCount()); hills_[index].Draw(plot); break; } - case GuiObjType::TrappyCircles: { + case gui::ObjectType::TrappyCircles: { tr_circles_[index].SetItemIndex(plot->itemCount()); tr_circles_[index].Draw(plot); break; } - case GuiObjType::TrappyLines: { + case gui::ObjectType::TrappyLines: { tr_lines_[index].SetGraphIndex(plot->plottableCount()); tr_lines_[index].Draw(plot); break; @@ -32,24 +33,24 @@ void DataManager::Draw(GuiObjType obj_type, size_t index, QCustomPlot* plot) { } } -void DataManager::Remove(GuiObjType obj_type, size_t index) { +void DataManager::Remove(gui::ObjectType 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; } @@ -57,20 +58,20 @@ void DataManager::Remove(GuiObjType obj_type, size_t index) { } void DataManager::Clear() { - while (targets_.size() > 0) Remove(GuiObjType::Targets, 0); + while (targets_.size() > 0) Remove(gui::ObjectType::Targets, 0); - while (tr_circles_.size() > 0) Remove(GuiObjType::TrappyCircles, 0); + while (tr_circles_.size() > 0) Remove(gui::ObjectType::TrappyCircles, 0); - while (tr_lines_.size() > 0) Remove(GuiObjType::TrappyLines, 0); + while (tr_lines_.size() > 0) Remove(gui::ObjectType::TrappyLines, 0); - while (hills_.size() > 0) Remove(GuiObjType::Hills, 0); + while (hills_.size() > 0) Remove(gui::ObjectType::Hills, 0); } -QString DataManager::GetTexted(GuiObjType obj_type) { +QString DataManager::GetTexted(gui::ObjectType obj_type) { QString text; switch (obj_type) { - case GuiObjType::Targets: { + case gui::ObjectType::Targets: { text += "Targets on plot: \n"; for (size_t i = 0; i < targets_.size(); i++) { auto target = targets_[i]; @@ -83,7 +84,7 @@ QString DataManager::GetTexted(GuiObjType obj_type) { break; } - case GuiObjType::Hills: { + case gui::ObjectType::Hills: { text += "Hills on plot: \n"; for (size_t i = 0; i < hills_.size(); i++) { auto hill = hills_[i]; @@ -100,7 +101,7 @@ QString DataManager::GetTexted(GuiObjType obj_type) { break; } - case GuiObjType::TrappyCircles: { + case gui::ObjectType::TrappyCircles: { text += "Trappy circles on plot: \n"; for (size_t i = 0; i < tr_circles_.size(); i++) { auto tr_circle = tr_circles_[i]; @@ -114,7 +115,7 @@ QString DataManager::GetTexted(GuiObjType obj_type) { break; } - case GuiObjType::TrappyLines: { + case gui::ObjectType::TrappyLines: { text += "Trappy lines on plot: \n"; for (size_t i = 0; i < tr_lines_.size(); i++) { auto tr_line = tr_lines_[i]; @@ -277,4 +278,4 @@ void DataManager::Set(std::vector tr_lines) { tr_lines_.push_back(gui::TrappyLine(tr_line)); } -} // namespace gui +} // namespace data_tools diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index c527149..f825dfd 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -5,7 +5,7 @@ #include "../../gui/trappy_circle.h" #include "../../gui/trappy_line.h" -namespace gui { +namespace data_tools { // @brief класс, хранящий gui объекты и связывающий их с QCustomPlot class DataManager { @@ -20,14 +20,14 @@ class DataManager { * @param index: индекс объекта в его векторе * @param plot: указатель на полотно */ - void Draw(GuiObjType obj_type, size_t index, QCustomPlot* plot); + void Draw(gui::ObjectType 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); void Clear(); @@ -36,7 +36,7 @@ class DataManager { * @param obj_type: тип объектов * @return QString: текст */ - QString GetTexted(GuiObjType obj_type); + QString GetTexted(gui::ObjectType obj_type); // ---------------------- Target methods ---------------------- @@ -177,4 +177,4 @@ class DataManager { std::vector tr_lines_; }; -} // namespace gui +} // namespace data_tools diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index a6787fa..ad111c5 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -2,43 +2,45 @@ #include +namespace data_tools { + void PlotArea::Redraw() { plot_->clearPlottables(); plot_->clearItems(); for (size_t i = 0; i < manager_.GetTargets().size(); i++) - manager_.Draw(gui::GuiObjType::Targets, i, plot_.get()); + manager_.Draw(gui::ObjectType::Targets, i, plot_.get()); for (size_t i = 0; i < manager_.GetHills().size(); i++) - manager_.Draw(gui::GuiObjType::Hills, i, plot_.get()); + manager_.Draw(gui::ObjectType::Hills, i, plot_.get()); for (size_t i = 0; i < manager_.GetTrappyCircles().size(); i++) - manager_.Draw(gui::GuiObjType::TrappyCircles, i, plot_.get()); + manager_.Draw(gui::ObjectType::TrappyCircles, i, plot_.get()); for (size_t i = 0; i < manager_.GetTrappyLines().size(); i++) - manager_.Draw(gui::GuiObjType::TrappyLines, i, plot_.get()); + manager_.Draw(gui::ObjectType::TrappyLines, i, plot_.get()); // UpdateInfoLabels(); UpdateTables(); plot_->replot(); } -void PlotArea::Remove(gui::GuiObjType obj_type, size_t index) { +void PlotArea::Remove(gui::ObjectType obj_type, size_t index) { switch (obj_type) { - case gui::GuiObjType::Targets: { + case gui::ObjectType::Targets: { plot_->removePlottable(manager_.GetTargets()[index].GetPlottableIndex()); break; } - case gui::GuiObjType::Hills: { + case gui::ObjectType::Hills: { plot_->removePlottable(manager_.GetHills()[index].GetPlottableIndex()); break; } - case gui::GuiObjType::TrappyLines: { + case gui::ObjectType::TrappyLines: { plot_->removePlottable( manager_.GetTrappyLines()[index].GetPlottableIndex()); break; } - case gui::GuiObjType::TrappyCircles: { + case gui::ObjectType::TrappyCircles: { plot_->removeItem(manager_.GetTrappyCircles()[index].GetItemIndex()); break; } @@ -54,14 +56,14 @@ void PlotArea::Clear() { } void PlotArea::UpdateInfoLabels() { - targets_label_->setText(manager_.GetTexted(gui::GuiObjType::Targets)); + targets_label_->setText(manager_.GetTexted(gui::ObjectType::Targets)); - hills_label_->setText(manager_.GetTexted(gui::GuiObjType::Hills)); + hills_label_->setText(manager_.GetTexted(gui::ObjectType::Hills)); tr_circles_label_->setText( - manager_.GetTexted(gui::GuiObjType::TrappyCircles)); + manager_.GetTexted(gui::ObjectType::TrappyCircles)); - tr_lines_label_->setText(manager_.GetTexted(gui::GuiObjType::TrappyLines)); + tr_lines_label_->setText(manager_.GetTexted(gui::ObjectType::TrappyLines)); } void PlotArea::UpdateTables() { @@ -70,3 +72,5 @@ void PlotArea::UpdateTables() { t_connection_.UpdateTable(manager_.GetTrappyLines()); t_connection_.UpdateTable(manager_.GetTrappyCircles()); } + +} // namespace data_tools \ No newline at end of file diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index 3475a31..3275f1b 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -5,6 +5,8 @@ #include "../data_manager/data_manager.h" #include "../tables_connection/tables_connection.h" +namespace data_tools { + /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: @@ -55,7 +57,7 @@ class PlotArea { * @param obj_type: тип объекта * @param index: индекс в его векторе */ - void Remove(gui::GuiObjType obj_type, size_t index); + void Remove(gui::ObjectType obj_type, size_t index); void Clear(); // ---------------------- Target methods ---------------------- @@ -243,8 +245,10 @@ class PlotArea { std::unique_ptr tr_circles_label_{nullptr}; std::unique_ptr tr_lines_label_{nullptr}; - gui::DataManager manager_; + DataManager manager_; TablesConnection t_connection_; // ~vars }; + +} // namespace data_tools diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index b2e1bfa..d5ef920 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -2,6 +2,8 @@ #include +namespace data_tools { + void TablesConnection::UpdateTable(const std::vector& targets) { // кол-во столбцов = кол-во к.т. targets_table_->setColumnCount(targets.size()); @@ -202,3 +204,5 @@ void TablesConnection::UpdateTablesConnections() { &TablesConnection::TrappyLinesItemChanged); } } + +} // namespace data_tools diff --git a/data_tools/tables_connection/tables_connection.h b/data_tools/tables_connection/tables_connection.h index c445413..94f06ab 100644 --- a/data_tools/tables_connection/tables_connection.h +++ b/data_tools/tables_connection/tables_connection.h @@ -4,6 +4,8 @@ #include "../data_manager/data_manager.h" +namespace data_tools { + /// @brief класс, упрощающий отображение классов gui в QTableWidget's class TablesConnection : public QObject { public: @@ -12,7 +14,7 @@ class TablesConnection : public QObject { * @param manager: ссылка на используемый DataManager * (благодаря передаче по ссылке, может редактировать данные классов) */ - TablesConnection(gui::DataManager* manager) : manager_{manager} {} + TablesConnection(DataManager* manager) : manager_{manager} {} /** * @brief устанавливает значения всех таблиц с информацией @@ -69,5 +71,7 @@ class TablesConnection : public QObject { std::unique_ptr tr_circles_table_{nullptr}; std::unique_ptr tr_lines_table_{nullptr}; - std::unique_ptr manager_; -}; \ No newline at end of file + std::unique_ptr manager_; +}; + +} // namespace data_tools \ No newline at end of file diff --git a/gui/base.h b/gui/base.h index 5eb0cd8..deffddf 100644 --- a/gui/base.h +++ b/gui/base.h @@ -21,6 +21,6 @@ class Drawable { }; // @brief типы объектов по категориям -enum class GuiObjType { Targets, Hills, TrappyCircles, TrappyLines }; +enum class ObjectType { Targets, Hills, TrappyCircles, TrappyLines }; } // namespace gui diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 2e1cbd3..0381a0e 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -7,9 +7,9 @@ class GuiJsonFile { GuiJsonFile() = default; GuiJsonFile(QFile* file) : file_{file} {}; - void Save(PlotArea& plot_area); + void Save(data_tools::PlotArea& plot_area); void New(); - void Open(PlotArea& plot_area); + void Open(data_tools::PlotArea& plot_area); QString GetFileName(); QString GetUntitledFile() { return untitled_file_; } @@ -21,7 +21,7 @@ class GuiJsonFile { bool IsExistsFile() { return (file_->fileName().size() != 0 && file_->exists()); } - bool IsChanged(PlotArea& plot_area); + bool IsChanged(data_tools::PlotArea& plot_area); private: QFile* file_{new QFile}; diff --git a/main/gui_json_file/new.cpp b/main/gui_json_file/new.cpp index 5ccbe6a..8f54cf7 100644 --- a/main/gui_json_file/new.cpp +++ b/main/gui_json_file/new.cpp @@ -30,7 +30,7 @@ QJsonObject GuiJsonFile::LoadJson() { return json_file.object(); } -bool GuiJsonFile::IsChanged(PlotArea& plot_area) { +bool GuiJsonFile::IsChanged(data_tools::PlotArea& plot_area) { file_->open(QIODevice::ReadOnly | QFile::Text); QJsonObject root = LoadJson(); diff --git a/main/gui_json_file/open.cpp b/main/gui_json_file/open.cpp index 0d802f0..137e379 100644 --- a/main/gui_json_file/open.cpp +++ b/main/gui_json_file/open.cpp @@ -1,7 +1,7 @@ #include "gui_json_file.h" std::vector GetTargetsFromFile(QJsonArray arr, - PlotArea& plot_area) { + data_tools::PlotArea& plot_area) { std::vector targets; for (size_t i = 0; i < arr.size(); i++) { lib::Target t; @@ -11,8 +11,8 @@ std::vector GetTargetsFromFile(QJsonArray arr, return targets; } -std::vector GetTrappyCirclesFromFile(QJsonArray arr, - PlotArea& plot_area) { +std::vector GetTrappyCirclesFromFile( + QJsonArray arr, data_tools::PlotArea& plot_area) { std::vector trappy_circles; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyCircle tc; @@ -22,8 +22,8 @@ std::vector GetTrappyCirclesFromFile(QJsonArray arr, return trappy_circles; } -std::vector GetTrappyLinesFromFile(QJsonArray arr, - PlotArea& plot_area) { +std::vector GetTrappyLinesFromFile( + QJsonArray arr, data_tools::PlotArea& plot_area) { std::vector trappy_lines; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyLine tl; @@ -33,7 +33,8 @@ std::vector GetTrappyLinesFromFile(QJsonArray arr, return trappy_lines; } -std::vector GetHillsFromFile(QJsonArray arr, PlotArea& plot_area) { +std::vector GetHillsFromFile(QJsonArray arr, + data_tools::PlotArea& plot_area) { std::vector hills; for (size_t i = 0; i < arr.size(); i++) { lib::Hill h; @@ -43,7 +44,7 @@ std::vector GetHillsFromFile(QJsonArray arr, PlotArea& plot_area) { return hills; } -void GuiJsonFile::Open(PlotArea& plot_area) { +void GuiJsonFile::Open(data_tools::PlotArea& plot_area) { if (file_->open(QIODevice::ReadOnly | QFile::Text)) { QJsonObject root = LoadJson(); diff --git a/main/gui_json_file/save.cpp b/main/gui_json_file/save.cpp index 0a43093..2bf8f2f 100644 --- a/main/gui_json_file/save.cpp +++ b/main/gui_json_file/save.cpp @@ -1,6 +1,6 @@ #include "gui_json_file.h" -void GuiJsonFile::Save(PlotArea& plot_area) { +void GuiJsonFile::Save(data_tools::PlotArea& plot_area) { if (file_->fileName().indexOf("Untitled") != -1) { QString file_name = file_->fileName(); QString old_untitled = ""; diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index 5a082b6..ed90b14 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -36,7 +36,7 @@ MainWindow::MainWindow(QWidget* parent) area_.Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); - // area_.Remove(gui::GuiObjType::Targets, 0); + // area_.Remove(gui::ObjectType::Targets, 0); } ui->plotSettingsDockWidget->setVisible(false); diff --git a/main/mainwindow.h b/main/mainwindow.h index 4e235c5..c301692 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -60,7 +60,7 @@ class MainWindow : public QMainWindow { void AddHill(std::vector points); private: - PlotArea area_; + data_tools::PlotArea area_; Ui::MainWindow* ui; GuiJsonFile json_file_; From 1db3a5f56061591bb50895bf5b17e80b77c47f5d Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 00:21:00 +0300 Subject: [PATCH 13/28] delete subdirs gui and data_tools # now it is included in main --- CMakeLists.txt | 2 -- cmake_paths.cmake | 5 ++++- cmake_scripts/scripts_for_vscode.cmake | 4 +++- data_tools/CMakeLists.txt | 21 --------------------- gui/CMakeLists.txt | 18 ------------------ main/CMakeLists.txt | 5 ++--- 6 files changed, 9 insertions(+), 46 deletions(-) delete mode 100644 data_tools/CMakeLists.txt delete mode 100644 gui/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fecbced..dd54f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,11 +43,9 @@ 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) -add_subdirectory(data_tools) # -------------------------------------------------------------------- diff --git a/cmake_paths.cmake b/cmake_paths.cmake index 72b0c83..9eb0483 100644 --- a/cmake_paths.cmake +++ b/cmake_paths.cmake @@ -1,4 +1,7 @@ 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") \ No newline at end of file +cmake_path(SET IMAGES_DIR "${CMAKE_SOURCE_DIR}/images") + +cmake_path(SET GUI_DIR "${CMAKE_SOURCE_DIR}/gui") +cmake_path(SET DATATOOLS_DIR "${CMAKE_SOURCE_DIR}/data_tools") \ No newline at end of file diff --git a/cmake_scripts/scripts_for_vscode.cmake b/cmake_scripts/scripts_for_vscode.cmake index e2c053a..8c35ada 100644 --- a/cmake_scripts/scripts_for_vscode.cmake +++ b/cmake_scripts/scripts_for_vscode.cmake @@ -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() diff --git a/data_tools/CMakeLists.txt b/data_tools/CMakeLists.txt deleted file mode 100644 index 1dad510..0000000 --- a/data_tools/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -cmake_minimum_required(VERSION 3.20) - -project(data_tools VERSION 0.1 LANGUAGES CXX) - -file(GLOB_RECURSE PROJECT_SOURCES "*.h" "*.cpp") - -add_library(data_tools STATIC ${PROJECT_SOURCES}) - -target_link_libraries(data_tools PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core) - -target_link_libraries(data_tools PRIVATE lib) -target_link_libraries(data_tools PRIVATE gui) - -target_compile_definitions(data_tools PRIVATE QCUSTOMPLOT_USE_LIBRARY) -target_link_libraries(data_tools PUBLIC qcustomplot) - -include(${CMAKESCRIPTS_DIR}/scripts_for_vscode.cmake) -add_qt_runtime(${CMAKE_CURRENT_SOURCE_DIR} data_tools) - -find_package(IcecreamCpp) -include_directories(${IcecreamCpp_INCLUDE_DIRS}) \ No newline at end of file diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt deleted file mode 100644 index fdfbfa8..0000000 --- a/gui/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.20) - -project(gui VERSION 0.1 LANGUAGES CXX) - -file(GLOB_RECURSE PROJECT_SOURCES "*.h" "*.cpp") - -add_library(gui STATIC ${PROJECT_SOURCES}) - -target_link_libraries(gui PRIVATE Qt${QT_VERSION_MAJOR}::Core) - -target_compile_definitions(gui PRIVATE QCUSTOMPLOT_USE_LIBRARY) -target_link_libraries(gui PUBLIC qcustomplot) - -include(${CMAKESCRIPTS_DIR}/scripts_for_vscode.cmake) -add_qt_runtime(${CMAKE_CURRENT_SOURCE_DIR} gui) - -find_package(IcecreamCpp) -include_directories(${IcecreamCpp_INCLUDE_DIRS}) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 72c4ec9..04a1094 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20) project(main VERSION 0.1 LANGUAGES CXX) -file(GLOB_RECURSE PROJECT_SOURCES "*.h" "*.cpp" "*.ui") +file(GLOB_RECURSE PROJECT_SOURCES "*.h" "*.cpp" "*.ui" + "${GUI_DIR}/*.h" "${GUI_DIR}/*.cpp" "${DATATOOLS_DIR}/*.h" "${DATATOOLS_DIR}/*.cpp") if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(main @@ -32,8 +33,6 @@ endif() target_link_libraries(main PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core) target_link_libraries(main PRIVATE lib) -target_link_libraries(main PRIVATE gui) -target_link_libraries(main PRIVATE data_tools) target_compile_definitions(main PRIVATE QCUSTOMPLOT_USE_LIBRARY) target_link_libraries(main PUBLIC qcustomplot) From c52b828e4ffe0ab4b2f066b0a3f96c1019ab2f9b Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 00:58:41 +0300 Subject: [PATCH 14/28] simplify include paths # by adding include_directories to main and lib CMakeLists --- cmake_paths.cmake | 2 ++ data_tools/data_manager/data_manager.h | 8 ++++---- data_tools/plot_area/plot_area.h | 4 ++-- data_tools/tables_connection/tables_connection.h | 2 +- gui/hill.h | 3 ++- gui/target.h | 3 ++- gui/trappy_circle.h | 3 ++- gui/trappy_line.h | 2 +- main/CMakeLists.txt | 2 ++ main/add_objects_forms/add_hill_form.h | 2 +- main/gui_json_file/gui_json_file.h | 2 +- main/mainwindow.cpp | 4 ---- main/mainwindow.h | 2 +- main/mainwindow_connections.cpp | 4 ---- 14 files changed, 21 insertions(+), 22 deletions(-) diff --git a/cmake_paths.cmake b/cmake_paths.cmake index 9eb0483..f39b2cb 100644 --- a/cmake_paths.cmake +++ b/cmake_paths.cmake @@ -3,5 +3,7 @@ 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 PROJECT_DIR "${CMAKE_SOURCE_DIR}") + cmake_path(SET GUI_DIR "${CMAKE_SOURCE_DIR}/gui") cmake_path(SET DATATOOLS_DIR "${CMAKE_SOURCE_DIR}/data_tools") \ No newline at end of file diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index f825dfd..68d3098 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -1,9 +1,9 @@ #pragma once -#include "../../gui/hill.h" -#include "../../gui/target.h" -#include "../../gui/trappy_circle.h" -#include "../../gui/trappy_line.h" +#include "gui/hill.h" +#include "gui/target.h" +#include "gui/trappy_circle.h" +#include "gui/trappy_line.h" namespace data_tools { diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index 3275f1b..de75f81 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -2,8 +2,8 @@ #include -#include "../data_manager/data_manager.h" -#include "../tables_connection/tables_connection.h" +#include "data_tools/data_manager/data_manager.h" +#include "data_tools/tables_connection/tables_connection.h" namespace data_tools { diff --git a/data_tools/tables_connection/tables_connection.h b/data_tools/tables_connection/tables_connection.h index 94f06ab..f486464 100644 --- a/data_tools/tables_connection/tables_connection.h +++ b/data_tools/tables_connection/tables_connection.h @@ -2,7 +2,7 @@ #include -#include "../data_manager/data_manager.h" +#include "data_tools/data_manager/data_manager.h" namespace data_tools { diff --git a/gui/hill.h b/gui/hill.h index 47f2e32..0853281 100644 --- a/gui/hill.h +++ b/gui/hill.h @@ -1,7 +1,8 @@ #pragma once -#include "../lib/hill.h" #include "base.h" +#include "lib/hill.h" + namespace gui { diff --git a/gui/target.h b/gui/target.h index 7dd2a8d..0d6c552 100644 --- a/gui/target.h +++ b/gui/target.h @@ -1,7 +1,8 @@ #pragma once -#include "../lib/target.h" #include "base.h" +#include "lib/target.h" + namespace gui { diff --git a/gui/trappy_circle.h b/gui/trappy_circle.h index ce1f5ff..fe86d4d 100644 --- a/gui/trappy_circle.h +++ b/gui/trappy_circle.h @@ -1,7 +1,8 @@ #pragma once -#include "../lib/trappy_circle.h" #include "base.h" +#include "lib/trappy_circle.h" + namespace gui { diff --git a/gui/trappy_line.h b/gui/trappy_line.h index 39da73b..d2565dd 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -1,6 +1,6 @@ #pragma once -#include "../lib/trappy_line.h" +#include "lib/trappy_line.h" #include "target.h" namespace gui { diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 04a1094..c272263 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -5,6 +5,8 @@ project(main VERSION 0.1 LANGUAGES CXX) file(GLOB_RECURSE PROJECT_SOURCES "*.h" "*.cpp" "*.ui" "${GUI_DIR}/*.h" "${GUI_DIR}/*.cpp" "${DATATOOLS_DIR}/*.h" "${DATATOOLS_DIR}/*.cpp") +include_directories(${PROJECT_DIR}) + if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(main MANUAL_FINALIZATION diff --git a/main/add_objects_forms/add_hill_form.h b/main/add_objects_forms/add_hill_form.h index 608f0ae..2b58cea 100644 --- a/main/add_objects_forms/add_hill_form.h +++ b/main/add_objects_forms/add_hill_form.h @@ -7,7 +7,7 @@ #include #include -#include "../../lib/point.h" +#include "lib/point.h" namespace Ui { class AddHillForm; diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 0381a0e..656805d 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -1,6 +1,6 @@ #pragma once -#include "../../data_tools/plot_area/plot_area.h" +#include "data_tools/plot_area/plot_area.h" class GuiJsonFile { public: diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index ed90b14..f400701 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -1,9 +1,5 @@ #include "mainwindow.h" -#include "../gui/hill.h" -#include "../gui/target.h" -#include "../gui/trappy_circle.h" -#include "../gui/trappy_line.h" #include "./ui_mainwindow.h" MainWindow::MainWindow(QWidget* parent) diff --git a/main/mainwindow.h b/main/mainwindow.h index c301692..5e4c700 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -2,11 +2,11 @@ #include -#include "../data_tools/plot_area/plot_area.h" #include "add_objects_forms/add_hill_form.h" #include "add_objects_forms/add_target_form.h" #include "add_objects_forms/add_trappy_circle_form.h" #include "add_objects_forms/add_trappy_line_form.h" +#include "data_tools/plot_area/plot_area.h" #include "gui_json_file/gui_json_file.h" enum class FileType { UntitledFile, UsualFile }; diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index dda22c7..082ef93 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -2,10 +2,6 @@ // здесь описаны все соединения кнопок со слотами -#include "../gui/hill.h" -#include "../gui/target.h" -#include "../gui/trappy_circle.h" -#include "../gui/trappy_line.h" #include "./ui_mainwindow.h" void MainWindow::AddTarget(double x, double y) { From fb5d6550d369534f8a64b97e8628f73e03b95f8e Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 01:59:48 +0300 Subject: [PATCH 15/28] turn all data_tools to pointer using --- data_tools/plot_area/plot_area.cpp | 44 ++++++------ data_tools/plot_area/plot_area.h | 110 +++++++++++++++-------------- main/gui_json_file/gui_json_file.h | 6 +- main/gui_json_file/new.cpp | 26 +++---- main/gui_json_file/open.cpp | 20 +++--- main/gui_json_file/save.cpp | 27 +++---- main/mainwindow.cpp | 28 ++++---- main/mainwindow.h | 3 +- main/mainwindow_connections.cpp | 52 +++++++------- 9 files changed, 162 insertions(+), 154 deletions(-) diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index ad111c5..44dda69 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -8,17 +8,17 @@ void PlotArea::Redraw() { plot_->clearPlottables(); plot_->clearItems(); - for (size_t i = 0; i < manager_.GetTargets().size(); i++) - manager_.Draw(gui::ObjectType::Targets, i, plot_.get()); + for (size_t i = 0; i < manager_->GetTargets().size(); i++) + manager_->Draw(gui::ObjectType::Targets, i, plot_.get()); - for (size_t i = 0; i < manager_.GetHills().size(); i++) - manager_.Draw(gui::ObjectType::Hills, i, plot_.get()); + for (size_t i = 0; i < manager_->GetHills().size(); i++) + manager_->Draw(gui::ObjectType::Hills, i, plot_.get()); - for (size_t i = 0; i < manager_.GetTrappyCircles().size(); i++) - manager_.Draw(gui::ObjectType::TrappyCircles, i, plot_.get()); + for (size_t i = 0; i < manager_->GetTrappyCircles().size(); i++) + manager_->Draw(gui::ObjectType::TrappyCircles, i, plot_.get()); - for (size_t i = 0; i < manager_.GetTrappyLines().size(); i++) - manager_.Draw(gui::ObjectType::TrappyLines, i, plot_.get()); + for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) + manager_->Draw(gui::ObjectType::TrappyLines, i, plot_.get()); // UpdateInfoLabels(); UpdateTables(); @@ -28,49 +28,49 @@ void PlotArea::Redraw() { void PlotArea::Remove(gui::ObjectType obj_type, size_t index) { switch (obj_type) { case gui::ObjectType::Targets: { - plot_->removePlottable(manager_.GetTargets()[index].GetPlottableIndex()); + plot_->removePlottable(manager_->GetTargets()[index].GetPlottableIndex()); break; } case gui::ObjectType::Hills: { - plot_->removePlottable(manager_.GetHills()[index].GetPlottableIndex()); + plot_->removePlottable(manager_->GetHills()[index].GetPlottableIndex()); break; } case gui::ObjectType::TrappyLines: { plot_->removePlottable( - manager_.GetTrappyLines()[index].GetPlottableIndex()); + manager_->GetTrappyLines()[index].GetPlottableIndex()); break; } case gui::ObjectType::TrappyCircles: { - plot_->removeItem(manager_.GetTrappyCircles()[index].GetItemIndex()); + plot_->removeItem(manager_->GetTrappyCircles()[index].GetItemIndex()); break; } } - manager_.Remove(obj_type, index); + manager_->Remove(obj_type, index); Redraw(); } void PlotArea::Clear() { - manager_.Clear(); + manager_->Clear(); Redraw(); } void PlotArea::UpdateInfoLabels() { - targets_label_->setText(manager_.GetTexted(gui::ObjectType::Targets)); + targets_label_->setText(manager_->GetTexted(gui::ObjectType::Targets)); - hills_label_->setText(manager_.GetTexted(gui::ObjectType::Hills)); + hills_label_->setText(manager_->GetTexted(gui::ObjectType::Hills)); tr_circles_label_->setText( - manager_.GetTexted(gui::ObjectType::TrappyCircles)); + manager_->GetTexted(gui::ObjectType::TrappyCircles)); - tr_lines_label_->setText(manager_.GetTexted(gui::ObjectType::TrappyLines)); + tr_lines_label_->setText(manager_->GetTexted(gui::ObjectType::TrappyLines)); } void PlotArea::UpdateTables() { - t_connection_.UpdateTable(manager_.GetTargets()); - t_connection_.UpdateTable(manager_.GetHills()); - t_connection_.UpdateTable(manager_.GetTrappyLines()); - t_connection_.UpdateTable(manager_.GetTrappyCircles()); + t_connection_->UpdateTable(manager_->GetTargets()); + t_connection_->UpdateTable(manager_->GetHills()); + t_connection_->UpdateTable(manager_->GetTrappyLines()); + t_connection_->UpdateTable(manager_->GetTrappyCircles()); } } // namespace data_tools \ No newline at end of file diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index de75f81..23e0268 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -10,7 +10,9 @@ namespace data_tools { /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: - PlotArea() : manager_(), t_connection_(&manager_) {} + PlotArea() + : manager_(new DataManager), + t_connection_(new TablesConnection(manager_.get())) {} // methods @@ -45,8 +47,8 @@ class PlotArea { void SetSettingsTables(QTableWidget* targets_info, QTableWidget* hills_info, QTableWidget* tr_circles_info, QTableWidget* tr_lines_info) { - t_connection_.SetSettingsTables(targets_info, hills_info, tr_circles_info, - tr_lines_info); + t_connection_->SetSettingsTables(targets_info, hills_info, tr_circles_info, + tr_lines_info); } /// @brief перерисовывает на полотне все объекты и обновляет данные @@ -63,108 +65,110 @@ class PlotArea { // ---------------------- Target methods ---------------------- // for gui::Target - void Add(gui::Target t) { manager_.Add(t); } + void Add(gui::Target t) { manager_->Add(t); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } // for lib::Target - void Add(lib::Target data) { manager_.Add(data); } + void Add(lib::Target data) { manager_->Add(data); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } /** * @brief возвращает значение targets * (позволяет менять объекты, т.к. ссылка не const) * @return std::vector&: ссылки на объекты К.Т. */ - std::vector& GetTargets() { return manager_.GetTargets(); } + std::vector& GetTargets() { return manager_->GetTargets(); } /** * @brief возвращает значение targets * @return const std::vector&: ссылки на объекты К.Т. */ const std::vector& GetTargets() const { - return manager_.GetTargets(); + return manager_->GetTargets(); } // ---------------------- Hill methods ---------------------- // for gui::Hill - void Add(gui::Hill t) { manager_.Add(t); } + void Add(gui::Hill t) { manager_->Add(t); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } // for lib::Hill - void Add(lib::Hill data) { manager_.Add(data); } + void Add(lib::Hill data) { manager_->Add(data); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } /** * @brief возвращает значение Hills * (позволяет менять объекты, т.к. ссылка не const) * @return std::vector&: ссылки на объекты рельефа */ - std::vector& GetHills() { return manager_.GetHills(); } + std::vector& GetHills() { return manager_->GetHills(); } /** * @brief возвращает значение Hills * @return const std::vector&: ссылки на объекты рельефа */ - const std::vector& GetHills() const { return manager_.GetHills(); } + const std::vector& GetHills() const { + return manager_->GetHills(); + } // ---------------------- TrappyCircle methods ---------------------- // for gui::TrappyCircle - void Add(gui::TrappyCircle t) { manager_.Add(t); } + void Add(gui::TrappyCircle t) { manager_->Add(t); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } // for lib::TrappyCircle - void Add(lib::TrappyCircle data) { manager_.Add(data); } + void Add(lib::TrappyCircle data) { manager_->Add(data); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } /** * @brief возвращает значение Trappy Circles @@ -172,7 +176,7 @@ class PlotArea { * @return std::vector&: ссылки на объекты опасной зоны */ std::vector& GetTrappyCircles() { - return manager_.GetTrappyCircles(); + return manager_->GetTrappyCircles(); } /** @@ -180,34 +184,34 @@ class PlotArea { * @return const std::vector&: объекты опасной зоны */ const std::vector& GetTrappyCircles() const { - return manager_.GetTrappyCircles(); + return manager_->GetTrappyCircles(); } // ---------------------- TrappyLine methods ---------------------- // for gui::TrappyLine - void Add(const gui::TrappyLine& t) { manager_.Add(t); } + void Add(const gui::TrappyLine& t) { manager_->Add(t); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } // for lib::TrappyLine - void Add(lib::TrappyLine data) { manager_.Add(data); } + void Add(lib::TrappyLine data) { manager_->Add(data); } void Add(std::initializer_list init_list) { - manager_.Add(init_list); + manager_->Add(init_list); } - void Add(std::vector vec) { manager_.Add(vec); } + void Add(std::vector vec) { manager_->Add(vec); } void Set(std::initializer_list init_list) { - manager_.Set(init_list); + manager_->Set(init_list); } - void Set(std::vector vec) { manager_.Set(vec); } + void Set(std::vector vec) { manager_->Set(vec); } /** * @brief возвращает значение Trappy Lines @@ -215,7 +219,7 @@ class PlotArea { * @return std::vector&: ссылки на объекты оп. перелета */ std::vector& GetTrappyLines() { - return manager_.GetTrappyLines(); + return manager_->GetTrappyLines(); } /** @@ -223,7 +227,7 @@ class PlotArea { * @return const std::vector&: ссылки на объекты оп. перелета */ const std::vector& GetTrappyLines() const { - return manager_.GetTrappyLines(); + return manager_->GetTrappyLines(); } // ~methods @@ -245,8 +249,8 @@ class PlotArea { std::unique_ptr tr_circles_label_{nullptr}; std::unique_ptr tr_lines_label_{nullptr}; - DataManager manager_; - TablesConnection t_connection_; + std::unique_ptr manager_; + std::unique_ptr t_connection_; // ~vars }; diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 656805d..041a9aa 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -7,9 +7,9 @@ class GuiJsonFile { GuiJsonFile() = default; GuiJsonFile(QFile* file) : file_{file} {}; - void Save(data_tools::PlotArea& plot_area); + void Save(data_tools::PlotArea* plot_area); void New(); - void Open(data_tools::PlotArea& plot_area); + void Open(data_tools::PlotArea* plot_area); QString GetFileName(); QString GetUntitledFile() { return untitled_file_; } @@ -21,7 +21,7 @@ class GuiJsonFile { bool IsExistsFile() { return (file_->fileName().size() != 0 && file_->exists()); } - bool IsChanged(data_tools::PlotArea& plot_area); + bool IsChanged(data_tools::PlotArea* plot_area); private: QFile* file_{new QFile}; diff --git a/main/gui_json_file/new.cpp b/main/gui_json_file/new.cpp index 8f54cf7..e4f5931 100644 --- a/main/gui_json_file/new.cpp +++ b/main/gui_json_file/new.cpp @@ -30,7 +30,7 @@ QJsonObject GuiJsonFile::LoadJson() { return json_file.object(); } -bool GuiJsonFile::IsChanged(data_tools::PlotArea& plot_area) { +bool GuiJsonFile::IsChanged(data_tools::PlotArea* plot_area) { file_->open(QIODevice::ReadOnly | QFile::Text); QJsonObject root = LoadJson(); @@ -39,36 +39,36 @@ bool GuiJsonFile::IsChanged(data_tools::PlotArea& plot_area) { QJsonArray json_trappy_lines = root["Trappy_Lines"].toArray(); QJsonArray json_hills = root["Hills"].toArray(); - if (plot_area.GetTargets().size() == json_targets.size() && - plot_area.GetTrappyCircles().size() == json_trappy_circles.size() && - plot_area.GetTrappyLines().size() == json_trappy_lines.size() && - plot_area.GetHills().size() == json_hills.size()) { - for (size_t i = 0; i < plot_area.GetTargets().size(); i++) { - lib::Target t = plot_area.GetTargets()[i].GetData(); + if (plot_area->GetTargets().size() == json_targets.size() && + plot_area->GetTrappyCircles().size() == json_trappy_circles.size() && + plot_area->GetTrappyLines().size() == json_trappy_lines.size() && + plot_area->GetHills().size() == json_hills.size()) { + for (size_t i = 0; i < plot_area->GetTargets().size(); i++) { + lib::Target t = plot_area->GetTargets()[i].GetData(); if (t.IsChanged(json_targets.at(i).toObject())) { file_->close(); return true; } } - for (size_t i = 0; i < plot_area.GetTrappyCircles().size(); i++) { - lib::TrappyCircle tc = plot_area.GetTrappyCircles()[i].GetData(); + for (size_t i = 0; i < plot_area->GetTrappyCircles().size(); i++) { + lib::TrappyCircle tc = plot_area->GetTrappyCircles()[i].GetData(); if (tc.IsChanged(json_trappy_circles.at(i).toObject())) { file_->close(); return true; } } - for (size_t i = 0; i < plot_area.GetTrappyLines().size(); i++) { - lib::TrappyLine tl = plot_area.GetTrappyLines()[i].GetData(); + for (size_t i = 0; i < plot_area->GetTrappyLines().size(); i++) { + lib::TrappyLine tl = plot_area->GetTrappyLines()[i].GetData(); if (tl.IsChanged(json_trappy_lines.at(i).toObject())) { file_->close(); return true; } } - for (size_t i = 0; i < plot_area.GetHills().size(); i++) { - lib::Hill h = plot_area.GetHills()[i].GetData(); + for (size_t i = 0; i < plot_area->GetHills().size(); i++) { + lib::Hill h = plot_area->GetHills()[i].GetData(); if (h.IsChanged(json_hills.at(i).toObject())) { file_->close(); return true; diff --git a/main/gui_json_file/open.cpp b/main/gui_json_file/open.cpp index 137e379..1d4f663 100644 --- a/main/gui_json_file/open.cpp +++ b/main/gui_json_file/open.cpp @@ -1,7 +1,7 @@ #include "gui_json_file.h" std::vector GetTargetsFromFile(QJsonArray arr, - data_tools::PlotArea& plot_area) { + data_tools::PlotArea* plot_area) { std::vector targets; for (size_t i = 0; i < arr.size(); i++) { lib::Target t; @@ -12,7 +12,7 @@ std::vector GetTargetsFromFile(QJsonArray arr, } std::vector GetTrappyCirclesFromFile( - QJsonArray arr, data_tools::PlotArea& plot_area) { + QJsonArray arr, data_tools::PlotArea* plot_area) { std::vector trappy_circles; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyCircle tc; @@ -23,7 +23,7 @@ std::vector GetTrappyCirclesFromFile( } std::vector GetTrappyLinesFromFile( - QJsonArray arr, data_tools::PlotArea& plot_area) { + QJsonArray arr, data_tools::PlotArea* plot_area) { std::vector trappy_lines; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyLine tl; @@ -34,7 +34,7 @@ std::vector GetTrappyLinesFromFile( } std::vector GetHillsFromFile(QJsonArray arr, - data_tools::PlotArea& plot_area) { + data_tools::PlotArea* plot_area) { std::vector hills; for (size_t i = 0; i < arr.size(); i++) { lib::Hill h; @@ -44,7 +44,7 @@ std::vector GetHillsFromFile(QJsonArray arr, return hills; } -void GuiJsonFile::Open(data_tools::PlotArea& plot_area) { +void GuiJsonFile::Open(data_tools::PlotArea* plot_area) { if (file_->open(QIODevice::ReadOnly | QFile::Text)) { QJsonObject root = LoadJson(); @@ -58,12 +58,12 @@ void GuiJsonFile::Open(data_tools::PlotArea& plot_area) { QJsonArray json_trappy_lines = root["Trappy_Lines"].toArray(); QJsonArray json_hills = root["Hills"].toArray(); - plot_area.Set(GetTargetsFromFile(json_targets, plot_area)); - plot_area.Set(GetTrappyCirclesFromFile(json_trappy_circles, plot_area)); - plot_area.Set(GetTrappyLinesFromFile(json_trappy_lines, plot_area)); - plot_area.Set(GetHillsFromFile(json_hills, plot_area)); + plot_area->Set(GetTargetsFromFile(json_targets, plot_area)); + plot_area->Set(GetTrappyCirclesFromFile(json_trappy_circles, plot_area)); + plot_area->Set(GetTrappyLinesFromFile(json_trappy_lines, plot_area)); + plot_area->Set(GetHillsFromFile(json_hills, plot_area)); - plot_area.Redraw(); + plot_area->Redraw(); file_->close(); } } diff --git a/main/gui_json_file/save.cpp b/main/gui_json_file/save.cpp index 2bf8f2f..ce86993 100644 --- a/main/gui_json_file/save.cpp +++ b/main/gui_json_file/save.cpp @@ -1,6 +1,6 @@ #include "gui_json_file.h" -void GuiJsonFile::Save(data_tools::PlotArea& plot_area) { +void GuiJsonFile::Save(data_tools::PlotArea* plot_area) { if (file_->fileName().indexOf("Untitled") != -1) { QString file_name = file_->fileName(); QString old_untitled = ""; @@ -19,34 +19,35 @@ void GuiJsonFile::Save(data_tools::PlotArea& plot_area) { int add_to_id = 10000; - for (size_t i = 0; i < plot_area.GetTargets().size(); i++) { - int id = add_to_id + plot_area.GetTargets()[i].GetPlottableIndex(); - targets_array.append(plot_area.GetTargets()[i].GetData().Save(id)); + for (size_t i = 0; i < plot_area->GetTargets().size(); i++) { + int id = add_to_id + plot_area->GetTargets()[i].GetPlottableIndex(); + targets_array.append(plot_area->GetTargets()[i].GetData().Save(id)); } root.insert("Targets", targets_array); add_to_id = 20000; - for (size_t i = 0; i < plot_area.GetTrappyCircles().size(); i++) { - int id = add_to_id + plot_area.GetTrappyCircles()[i].GetItemIndex(); + for (size_t i = 0; i < plot_area->GetTrappyCircles().size(); i++) { + int id = add_to_id + plot_area->GetTrappyCircles()[i].GetItemIndex(); trappy_circles_array.append( - plot_area.GetTrappyCircles()[i].GetData().Save(id)); + plot_area->GetTrappyCircles()[i].GetData().Save(id)); } root.insert("Trappy_Circles", trappy_circles_array); add_to_id = 30000; - for (size_t i = 0; i < plot_area.GetTrappyLines().size(); i++) { - int id = add_to_id + plot_area.GetTrappyLines()[i].GetPlottableIndex(); - trappy_lines_array.append(plot_area.GetTrappyLines()[i].GetData().Save(id)); + for (size_t i = 0; i < plot_area->GetTrappyLines().size(); i++) { + int id = add_to_id + plot_area->GetTrappyLines()[i].GetPlottableIndex(); + trappy_lines_array.append( + plot_area->GetTrappyLines()[i].GetData().Save(id)); } root.insert("Trappy_Lines", trappy_lines_array); add_to_id = 40000; - for (size_t i = 0; i < plot_area.GetHills().size(); i++) { - int id = add_to_id + plot_area.GetHills()[i].GetPlottableIndex(); - hills_array.append(plot_area.GetHills()[i].GetData().Save(id)); + for (size_t i = 0; i < plot_area->GetHills().size(); i++) { + int id = add_to_id + plot_area->GetHills()[i].GetPlottableIndex(); + hills_array.append(plot_area->GetHills()[i].GetData().Save(id)); } root.insert("Hills", hills_array); diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index f400701..dcb4da2 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -3,7 +3,9 @@ #include "./ui_mainwindow.h" MainWindow::MainWindow(QWidget* parent) - : QMainWindow(parent), ui(new Ui::MainWindow) { + : QMainWindow(parent), + ui(new Ui::MainWindow), + area_(new data_tools::PlotArea) { ui->setupUi(this); ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectItems); @@ -11,10 +13,10 @@ MainWindow::MainWindow(QWidget* parent) connect(ui->plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(on_plot_MousePressed())); - area_.SetPlot(ui->plot); + area_->SetPlot(ui->plot); - area_.SetSettingsLabels(ui->targetInfoLabel, ui->hillInfoLabel, - ui->trappyCircleInfoLabel, ui->trappyLineInfoLabel); + area_->SetSettingsLabels(ui->targetInfoLabel, ui->hillInfoLabel, + ui->trappyCircleInfoLabel, ui->trappyLineInfoLabel); { // проверка функционала графических классов и менеджера @@ -22,26 +24,26 @@ MainWindow::MainWindow(QWidget* parent) gui::Target t_2(2, 1); gui::Target t_3(1, 1); - area_.Set({t_1, t_2, t_3}); + area_->Set({t_1, t_2, t_3}); gui::TrappyLine tr{t_1, t_2}; - area_.Add(tr); + area_->Add(tr); gui::TrappyCircle trc({1, 2}, 0.5); - area_.Add(trc); + area_->Add(trc); - area_.Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); + area_->Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); - // area_.Remove(gui::ObjectType::Targets, 0); + // area_->Remove(gui::ObjectType::Targets, 0); } ui->plotSettingsDockWidget->setVisible(false); - area_.SetSettingsTables(ui->targetInfoTableWidget, ui->hillInfoTableWidget, - ui->trappyCircleInfoTableWidget, - ui->trappyLineInfoTableWidget); + area_->SetSettingsTables(ui->targetInfoTableWidget, ui->hillInfoTableWidget, + ui->trappyCircleInfoTableWidget, + ui->trappyLineInfoTableWidget); - area_.Redraw(); + area_->Redraw(); } MainWindow::~MainWindow() { delete ui; } diff --git a/main/mainwindow.h b/main/mainwindow.h index 5e4c700..184c18c 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -60,7 +60,8 @@ class MainWindow : public QMainWindow { void AddHill(std::vector points); private: - data_tools::PlotArea area_; + std::unique_ptr area_; + // std::unique_ptr manager_; Ui::MainWindow* ui; GuiJsonFile json_file_; diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index 082ef93..a4a771c 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -5,13 +5,13 @@ #include "./ui_mainwindow.h" void MainWindow::AddTarget(double x, double y) { - area_.Add(gui::Target(x, y)); - area_.Redraw(); + area_->Add(gui::Target(x, y)); + area_->Redraw(); } void MainWindow::AddTrappyCircle(double x, double y, double radius) { - area_.Add(gui::TrappyCircle(x, y, radius)); - area_.Redraw(); + area_->Add(gui::TrappyCircle(x, y, radius)); + area_->Redraw(); } void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { @@ -21,17 +21,17 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { gui::Target t1(x1, y1); gui::Target t2(x2, y2); - area_.Add(t1); - area_.Add(t2); - area_.Redraw(); + area_->Add(t1); + area_->Add(t2); + area_->Redraw(); - area_.Add(gui::TrappyLine({t1, t2})); - area_.Redraw(); + area_->Add(gui::TrappyLine({t1, t2})); + area_->Redraw(); } void MainWindow::AddHill(std::vector points) { - area_.Add(gui::Hill(points)); - area_.Redraw(); + area_->Add(gui::Hill(points)); + area_->Redraw(); } void MainWindow::on_pushButtonAddTarget_clicked() { @@ -108,7 +108,7 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { switch (ret) { case QMessageBox::Save: - json_file_.Save(area_); + json_file_.Save(area_.get()); break; case QMessageBox::Discard: break; @@ -146,11 +146,11 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { // есть ли изменения в текущем файле void MainWindow::closeEvent(QCloseEvent* event) { bool is_closed = false; - if (json_file_.IsExistsFile() && json_file_.IsChanged(area_)) + if (json_file_.IsExistsFile() && json_file_.IsChanged(area_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); else if (!json_file_.IsExistsFile() && - (area_.GetTargets().size() + area_.GetTrappyCircles().size() + - area_.GetTrappyLines().size() + area_.GetHills().size()) != 0) + (area_->GetTargets().size() + area_->GetTrappyCircles().size() + + area_->GetTrappyLines().size() + area_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); if (is_closed) event->ignore(); @@ -161,15 +161,15 @@ void MainWindow::closeEvent(QCloseEvent* event) { // Кнопка "New" void MainWindow::on_actionNew_triggered() { bool is_closed = false; - if (json_file_.IsExistsFile() && json_file_.IsChanged(area_)) + if (json_file_.IsExistsFile() && json_file_.IsChanged(area_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); else if (!json_file_.IsExistsFile() && - (area_.GetTargets().size() + area_.GetTrappyCircles().size() + - area_.GetTrappyLines().size() + area_.GetHills().size()) != 0) + (area_->GetTargets().size() + area_->GetTrappyCircles().size() + + area_->GetTrappyLines().size() + area_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); if (!is_closed) { - area_.Clear(); + area_->Clear(); json_file_.Clear(); } } @@ -178,18 +178,18 @@ void MainWindow::on_actionNew_triggered() { void MainWindow::on_actionOpen_triggered() { bool is_closed = false; - if (json_file_.IsExistsFile() && json_file_.IsChanged(area_)) + if (json_file_.IsExistsFile() && json_file_.IsChanged(area_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); else if (!json_file_.IsExistsFile() && - (area_.GetTargets().size() + area_.GetTrappyCircles().size() + - area_.GetTrappyLines().size() + area_.GetHills().size()) != 0) + (area_->GetTargets().size() + area_->GetTrappyCircles().size() + + area_->GetTrappyLines().size() + area_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); if (!is_closed) { QString file_name = QFileDialog::getOpenFileName(this, tr("Open"), "", tr("File (*.json)")); json_file_.SetFile(file_name); try { - json_file_.Open(area_); + json_file_.Open(area_.get()); } catch (...) { QMessageBox::critical(this, "Damaged file", "Invalid format file!"); } @@ -200,7 +200,7 @@ void MainWindow::on_actionSave_triggered() { if (!json_file_.IsExistsFile()) on_actionSave_as_triggered(); else - json_file_.Save(area_); + json_file_.Save(area_.get()); } // Кнопка "Save as" @@ -208,7 +208,7 @@ void MainWindow::on_actionSave_as_triggered() { QString file_name = QFileDialog::getSaveFileName( this, tr("Save as"), json_file_.GetUntitledFile(), tr("File (*.json)")); json_file_.SetFile(file_name); - json_file_.Save(area_); + json_file_.Save(area_.get()); } -void MainWindow::on_redrawPushButton_clicked() { area_.Redraw(); } +void MainWindow::on_redrawPushButton_clicked() { area_->Redraw(); } From bafb36dad9584379d35907f9c4d7c40478405f6e Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 02:25:41 +0300 Subject: [PATCH 16/28] move all data_tools to mainwindow and add Setup methods --- data_tools/data_manager/data_manager.cpp | 5 +++++ data_tools/data_manager/data_manager.h | 10 ++++++++++ data_tools/plot_area/plot_area.cpp | 13 ++++++++++++ data_tools/plot_area/plot_area.h | 20 ++++++++++++------- .../tables_connection/tables_connection.cpp | 5 +++++ .../tables_connection/tables_connection.h | 18 +++++++++++------ main/mainwindow.cpp | 9 ++++++--- main/mainwindow.h | 4 +++- 8 files changed, 67 insertions(+), 17 deletions(-) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index 5374bcc..aecbbd4 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -4,6 +4,11 @@ namespace data_tools { +void DataManager::Setup(PlotArea* area, TablesConnection* t_connection) { + area_.reset(area); + t_connection_.reset(t_connection); +} + void DataManager::Draw(gui::ObjectType obj_type, size_t index, QCustomPlot* plot) { switch (obj_type) { diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index 68d3098..6cb7ee7 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -1,5 +1,7 @@ #pragma once +#include "data_tools/plot_area/plot_area.h" +#include "data_tools/tables_connection/tables_connection.h" #include "gui/hill.h" #include "gui/target.h" #include "gui/trappy_circle.h" @@ -7,11 +9,16 @@ namespace data_tools { +class PlotArea; +class TablesConnection; + // @brief класс, хранящий gui объекты и связывающий их с QCustomPlot class DataManager { public: DataManager() = default; + void Setup(PlotArea* area, TablesConnection* t_connection); + // methods /** @@ -175,6 +182,9 @@ class DataManager { std::vector targets_; std::vector tr_circles_; std::vector tr_lines_; + + std::unique_ptr area_; + std::unique_ptr t_connection_; }; } // namespace data_tools diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index 44dda69..f16c28c 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -4,6 +4,19 @@ namespace data_tools { +void PlotArea::Setup(DataManager* manager, TablesConnection* t_connection) { + manager_.reset(manager); + t_connection_.reset(t_connection); +} + +void PlotArea::SetSettingsTables(QTableWidget* targets_info, + QTableWidget* hills_info, + QTableWidget* tr_circles_info, + QTableWidget* tr_lines_info) { + t_connection_->SetSettingsTables(targets_info, hills_info, tr_circles_info, + tr_lines_info); +} + void PlotArea::Redraw() { plot_->clearPlottables(); plot_->clearItems(); diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index 23e0268..dc32f34 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -4,15 +4,24 @@ #include "data_tools/data_manager/data_manager.h" #include "data_tools/tables_connection/tables_connection.h" +#include "gui/hill.h" +#include "gui/target.h" +#include "gui/trappy_circle.h" +#include "gui/trappy_line.h" namespace data_tools { +class TablesConnection; +class DataManager; + /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: - PlotArea() - : manager_(new DataManager), - t_connection_(new TablesConnection(manager_.get())) {} + PlotArea() = default; + + PlotArea(QCustomPlot* plot) : plot_{plot} {} + + void Setup(DataManager* manager, TablesConnection* t_connection); // methods @@ -46,10 +55,7 @@ class PlotArea { */ void SetSettingsTables(QTableWidget* targets_info, QTableWidget* hills_info, QTableWidget* tr_circles_info, - QTableWidget* tr_lines_info) { - t_connection_->SetSettingsTables(targets_info, hills_info, tr_circles_info, - tr_lines_info); - } + QTableWidget* tr_lines_info); /// @brief перерисовывает на полотне все объекты и обновляет данные void Redraw(); diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index d5ef920..d2c04f2 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -4,6 +4,11 @@ namespace data_tools { +void TablesConnection::Setup(DataManager* manager, PlotArea* area) { + manager_.reset(manager); + area_.reset(area); +} + void TablesConnection::UpdateTable(const std::vector& targets) { // кол-во столбцов = кол-во к.т. targets_table_->setColumnCount(targets.size()); diff --git a/data_tools/tables_connection/tables_connection.h b/data_tools/tables_connection/tables_connection.h index f486464..e26c70e 100644 --- a/data_tools/tables_connection/tables_connection.h +++ b/data_tools/tables_connection/tables_connection.h @@ -3,18 +3,23 @@ #include #include "data_tools/data_manager/data_manager.h" +#include "data_tools/plot_area/plot_area.h" +#include "gui/hill.h" +#include "gui/target.h" +#include "gui/trappy_circle.h" +#include "gui/trappy_line.h" namespace data_tools { +class PlotArea; +class DataManager; + /// @brief класс, упрощающий отображение классов gui в QTableWidget's class TablesConnection : public QObject { public: - /** - * @brief инициализирует новый экземпляр Table Manager - * @param manager: ссылка на используемый DataManager - * (благодаря передаче по ссылке, может редактировать данные классов) - */ - TablesConnection(DataManager* manager) : manager_{manager} {} + TablesConnection() = default; + + void Setup(DataManager* manager, PlotArea* area); /** * @brief устанавливает значения всех таблиц с информацией @@ -72,6 +77,7 @@ class TablesConnection : public QObject { std::unique_ptr tr_lines_table_{nullptr}; std::unique_ptr manager_; + std::unique_ptr area_; }; } // namespace data_tools \ No newline at end of file diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index dcb4da2..dd1a7b9 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -5,7 +5,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow), - area_(new data_tools::PlotArea) { + area_(new data_tools::PlotArea), + manager_(new data_tools::DataManager), + t_connection_(new data_tools::TablesConnection) { ui->setupUi(this); ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectItems); @@ -13,6 +15,9 @@ MainWindow::MainWindow(QWidget* parent) connect(ui->plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(on_plot_MousePressed())); + area_->Setup(manager_.get(), t_connection_.get()); + t_connection_->Setup(manager_.get(), area_.get()); + area_->SetPlot(ui->plot); area_->SetSettingsLabels(ui->targetInfoLabel, ui->hillInfoLabel, @@ -33,8 +38,6 @@ MainWindow::MainWindow(QWidget* parent) area_->Add(trc); area_->Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); - - // area_->Remove(gui::ObjectType::Targets, 0); } ui->plotSettingsDockWidget->setVisible(false); diff --git a/main/mainwindow.h b/main/mainwindow.h index 184c18c..fbbf223 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -61,7 +61,9 @@ class MainWindow : public QMainWindow { private: std::unique_ptr area_; - // std::unique_ptr manager_; + std::unique_ptr manager_; + std::unique_ptr t_connection_; + Ui::MainWindow* ui; GuiJsonFile json_file_; From 28fc635156c7702b3bce152f4e13502f975e0dbe Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 03:13:21 +0300 Subject: [PATCH 17/28] juggle data_tools methods (delete some and change using) --- data_tools/data_manager/data_manager.cpp | 104 +-------- data_tools/data_manager/data_manager.h | 15 +- data_tools/plot_area/plot_area.cpp | 59 +---- data_tools/plot_area/plot_area.h | 213 ------------------ .../tables_connection/tables_connection.cpp | 7 + .../tables_connection/tables_connection.h | 3 + main/gui_json_file/gui_json_file.h | 6 +- main/gui_json_file/new.cpp | 26 +-- main/gui_json_file/open.cpp | 21 +- main/gui_json_file/save.cpp | 27 ++- main/mainwindow.cpp | 21 +- main/mainwindow_connections.cpp | 52 +++-- 12 files changed, 94 insertions(+), 460 deletions(-) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index aecbbd4..3a7e43f 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -38,107 +38,11 @@ void DataManager::Draw(gui::ObjectType obj_type, size_t index, } } -void DataManager::Remove(gui::ObjectType obj_type, size_t index) { - switch (obj_type) { - case gui::ObjectType::Targets: { - targets_.erase(targets_.begin() + index); - break; - } - - case gui::ObjectType::Hills: { - hills_.erase(hills_.begin() + index); - break; - } - - case gui::ObjectType::TrappyCircles: { - tr_circles_.erase(tr_circles_.begin() + index); - break; - } - - case gui::ObjectType::TrappyLines: { - tr_lines_.erase(tr_lines_.begin() + index); - break; - } - } -} - void DataManager::Clear() { - while (targets_.size() > 0) Remove(gui::ObjectType::Targets, 0); - - while (tr_circles_.size() > 0) Remove(gui::ObjectType::TrappyCircles, 0); - - while (tr_lines_.size() > 0) Remove(gui::ObjectType::TrappyLines, 0); - - while (hills_.size() > 0) Remove(gui::ObjectType::Hills, 0); -} - -QString DataManager::GetTexted(gui::ObjectType obj_type) { - QString text; - - switch (obj_type) { - case gui::ObjectType::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 gui::ObjectType::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 gui::ObjectType::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 gui::ObjectType::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 ---------------------- diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index 6cb7ee7..afdb3df 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -29,22 +29,9 @@ class DataManager { */ void Draw(gui::ObjectType obj_type, size_t index, QCustomPlot* plot); - /** - * @brief удаляет объект из менеджера по индексу - * @param obj_type: тип объекта - * @param index: индекс объекта в его векторе - */ - void Remove(gui::ObjectType obj_type, size_t index); - + /// @brief очищает все вектора объектов void Clear(); - /** - * @brief возвращает представление определенных типов объектов в виде текста - * @param obj_type: тип объектов - * @return QString: текст - */ - QString GetTexted(gui::ObjectType obj_type); - // ---------------------- Target methods ---------------------- // for gui::Target diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index f16c28c..54b8be5 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -9,14 +9,6 @@ void PlotArea::Setup(DataManager* manager, TablesConnection* t_connection) { t_connection_.reset(t_connection); } -void PlotArea::SetSettingsTables(QTableWidget* targets_info, - QTableWidget* hills_info, - QTableWidget* tr_circles_info, - QTableWidget* tr_lines_info) { - t_connection_->SetSettingsTables(targets_info, hills_info, tr_circles_info, - tr_lines_info); -} - void PlotArea::Redraw() { plot_->clearPlottables(); plot_->clearItems(); @@ -33,57 +25,8 @@ void PlotArea::Redraw() { for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) manager_->Draw(gui::ObjectType::TrappyLines, i, plot_.get()); - // UpdateInfoLabels(); - UpdateTables(); + t_connection_->UpdateTables(); plot_->replot(); } -void PlotArea::Remove(gui::ObjectType obj_type, size_t index) { - switch (obj_type) { - case gui::ObjectType::Targets: { - plot_->removePlottable(manager_->GetTargets()[index].GetPlottableIndex()); - break; - } - case gui::ObjectType::Hills: { - plot_->removePlottable(manager_->GetHills()[index].GetPlottableIndex()); - break; - } - case gui::ObjectType::TrappyLines: { - plot_->removePlottable( - manager_->GetTrappyLines()[index].GetPlottableIndex()); - break; - } - case gui::ObjectType::TrappyCircles: { - plot_->removeItem(manager_->GetTrappyCircles()[index].GetItemIndex()); - break; - } - } - - manager_->Remove(obj_type, index); - Redraw(); -} - -void PlotArea::Clear() { - manager_->Clear(); - Redraw(); -} - -void PlotArea::UpdateInfoLabels() { - targets_label_->setText(manager_->GetTexted(gui::ObjectType::Targets)); - - hills_label_->setText(manager_->GetTexted(gui::ObjectType::Hills)); - - tr_circles_label_->setText( - manager_->GetTexted(gui::ObjectType::TrappyCircles)); - - tr_lines_label_->setText(manager_->GetTexted(gui::ObjectType::TrappyLines)); -} - -void PlotArea::UpdateTables() { - t_connection_->UpdateTable(manager_->GetTargets()); - t_connection_->UpdateTable(manager_->GetHills()); - t_connection_->UpdateTable(manager_->GetTrappyLines()); - t_connection_->UpdateTable(manager_->GetTrappyCircles()); -} - } // namespace data_tools \ No newline at end of file diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index dc32f34..4f628c4 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -31,230 +31,17 @@ class PlotArea { */ void SetPlot(QCustomPlot* plot) { plot_.reset(plot); } - /** - * @brief устанавливает значение всех лейблов с информацией - * @param targets_info: лейбл с информацией о targets - * @param hills_info: лейбл с информацией о hills - * @param tr_circles_info: лейбл с информацией о trappy circles - * @param tr_lines_info: лейбл с информацией о trappy lines - */ - void SetSettingsLabels(QLabel* targets_info, QLabel* hills_info, - QLabel* tr_circles_info, QLabel* tr_lines_info) { - targets_label_.reset(targets_info); - hills_label_.reset(hills_info); - tr_circles_label_.reset(tr_circles_info); - tr_lines_label_.reset(tr_lines_info); - } - - /** - * @brief устанавливает значения всех таблиц с информацией - * @param hills_info: QTableWidget с информацией о hills - * @param targets_info: QTableWidget с информацией о hills - * @param tr_circles_info: QTableWidget с информацией о hills - * @param tr_lines_info: QTableWidget с информацией о hills - */ - void SetSettingsTables(QTableWidget* targets_info, QTableWidget* hills_info, - QTableWidget* tr_circles_info, - QTableWidget* tr_lines_info); - /// @brief перерисовывает на полотне все объекты и обновляет данные void Redraw(); - /** - * @brief удаляет объект на полотне по индексу объекта в его векторе - * @param obj_type: тип объекта - * @param index: индекс в его векторе - */ - void Remove(gui::ObjectType obj_type, size_t index); - void Clear(); - - // ---------------------- Target methods ---------------------- - - // for gui::Target - void Add(gui::Target t) { manager_->Add(t); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - // for lib::Target - void Add(lib::Target data) { manager_->Add(data); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - /** - * @brief возвращает значение targets - * (позволяет менять объекты, т.к. ссылка не const) - * @return std::vector&: ссылки на объекты К.Т. - */ - std::vector& GetTargets() { return manager_->GetTargets(); } - - /** - * @brief возвращает значение targets - * @return const std::vector&: ссылки на объекты К.Т. - */ - const std::vector& GetTargets() const { - return manager_->GetTargets(); - } - - // ---------------------- Hill methods ---------------------- - - // for gui::Hill - void Add(gui::Hill t) { manager_->Add(t); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - // for lib::Hill - void Add(lib::Hill data) { manager_->Add(data); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - /** - * @brief возвращает значение Hills - * (позволяет менять объекты, т.к. ссылка не const) - * @return std::vector&: ссылки на объекты рельефа - */ - std::vector& GetHills() { return manager_->GetHills(); } - - /** - * @brief возвращает значение Hills - * @return const std::vector&: ссылки на объекты рельефа - */ - const std::vector& GetHills() const { - return manager_->GetHills(); - } - - // ---------------------- TrappyCircle methods ---------------------- - - // for gui::TrappyCircle - void Add(gui::TrappyCircle t) { manager_->Add(t); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - // for lib::TrappyCircle - void Add(lib::TrappyCircle data) { manager_->Add(data); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - /** - * @brief возвращает значение Trappy Circles - * (позволяет менять объекты, т.к. ссылка не const) - * @return std::vector&: ссылки на объекты опасной зоны - */ - std::vector& GetTrappyCircles() { - return manager_->GetTrappyCircles(); - } - - /** - * @brief возвращает значение Trappy Circles - * @return const std::vector&: объекты опасной зоны - */ - const std::vector& GetTrappyCircles() const { - return manager_->GetTrappyCircles(); - } - - // ---------------------- TrappyLine methods ---------------------- - - // for gui::TrappyLine - void Add(const gui::TrappyLine& t) { manager_->Add(t); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - // for lib::TrappyLine - void Add(lib::TrappyLine data) { manager_->Add(data); } - void Add(std::initializer_list init_list) { - manager_->Add(init_list); - } - void Add(std::vector vec) { manager_->Add(vec); } - - void Set(std::initializer_list init_list) { - manager_->Set(init_list); - } - void Set(std::vector vec) { manager_->Set(vec); } - - /** - * @brief возвращает значение Trappy Lines - * (позволяет менять объекты, т.к. ссылка не const) - * @return std::vector&: ссылки на объекты оп. перелета - */ - std::vector& GetTrappyLines() { - return manager_->GetTrappyLines(); - } - - /** - * @brief возвращает значение Trappy Lines - * @return const std::vector&: ссылки на объекты оп. перелета - */ - const std::vector& GetTrappyLines() const { - return manager_->GetTrappyLines(); - } - // ~methods private: - /// @brief обновляет данные в лейблах все объектов - void UpdateInfoLabels(); - - /// @brief обновляет данные в таблицах всех объектов - void UpdateTables(); - // vars // i love unique_ptr's, i love logic schemes std::unique_ptr plot_; - std::unique_ptr hills_label_{nullptr}; - std::unique_ptr targets_label_{nullptr}; - std::unique_ptr tr_circles_label_{nullptr}; - std::unique_ptr tr_lines_label_{nullptr}; - std::unique_ptr manager_; std::unique_ptr t_connection_; diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index d2c04f2..e797d52 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -176,6 +176,13 @@ void TablesConnection::UpdateTable( tr_circles_table_->update(); } +void TablesConnection::UpdateTables() { + UpdateTable(manager_->GetTargets()); + UpdateTable(manager_->GetHills()); + UpdateTable(manager_->GetTrappyLines()); + UpdateTable(manager_->GetTrappyCircles()); +} + void TablesConnection::TargetsItemChanged(int row, int column) { auto x_item = targets_table_->item(1, column); auto y_item = targets_table_->item(2, column); diff --git a/data_tools/tables_connection/tables_connection.h b/data_tools/tables_connection/tables_connection.h index e26c70e..184b290 100644 --- a/data_tools/tables_connection/tables_connection.h +++ b/data_tools/tables_connection/tables_connection.h @@ -38,6 +38,9 @@ class TablesConnection : public QObject { UpdateTablesConnections(); } + /// @brief обновляет данные в таблицах всех объектов + void UpdateTables(); + /** * @brief обновляет значения таблицы с Targets * @param targets: вектор новых значений diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 041a9aa..fb863fb 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -7,9 +7,9 @@ class GuiJsonFile { GuiJsonFile() = default; GuiJsonFile(QFile* file) : file_{file} {}; - void Save(data_tools::PlotArea* plot_area); + void Save(data_tools::DataManager* plot_area); void New(); - void Open(data_tools::PlotArea* plot_area); + void Open(data_tools::DataManager* plot_area); QString GetFileName(); QString GetUntitledFile() { return untitled_file_; } @@ -21,7 +21,7 @@ class GuiJsonFile { bool IsExistsFile() { return (file_->fileName().size() != 0 && file_->exists()); } - bool IsChanged(data_tools::PlotArea* plot_area); + bool IsChanged(data_tools::DataManager* plot_area); private: QFile* file_{new QFile}; diff --git a/main/gui_json_file/new.cpp b/main/gui_json_file/new.cpp index e4f5931..ba8c4d6 100644 --- a/main/gui_json_file/new.cpp +++ b/main/gui_json_file/new.cpp @@ -30,7 +30,7 @@ QJsonObject GuiJsonFile::LoadJson() { return json_file.object(); } -bool GuiJsonFile::IsChanged(data_tools::PlotArea* plot_area) { +bool GuiJsonFile::IsChanged(data_tools::DataManager* manager) { file_->open(QIODevice::ReadOnly | QFile::Text); QJsonObject root = LoadJson(); @@ -39,36 +39,36 @@ bool GuiJsonFile::IsChanged(data_tools::PlotArea* plot_area) { QJsonArray json_trappy_lines = root["Trappy_Lines"].toArray(); QJsonArray json_hills = root["Hills"].toArray(); - if (plot_area->GetTargets().size() == json_targets.size() && - plot_area->GetTrappyCircles().size() == json_trappy_circles.size() && - plot_area->GetTrappyLines().size() == json_trappy_lines.size() && - plot_area->GetHills().size() == json_hills.size()) { - for (size_t i = 0; i < plot_area->GetTargets().size(); i++) { - lib::Target t = plot_area->GetTargets()[i].GetData(); + if (manager->GetTargets().size() == json_targets.size() && + manager->GetTrappyCircles().size() == json_trappy_circles.size() && + manager->GetTrappyLines().size() == json_trappy_lines.size() && + manager->GetHills().size() == json_hills.size()) { + for (size_t i = 0; i < manager->GetTargets().size(); i++) { + lib::Target t = manager->GetTargets()[i].GetData(); if (t.IsChanged(json_targets.at(i).toObject())) { file_->close(); return true; } } - for (size_t i = 0; i < plot_area->GetTrappyCircles().size(); i++) { - lib::TrappyCircle tc = plot_area->GetTrappyCircles()[i].GetData(); + for (size_t i = 0; i < manager->GetTrappyCircles().size(); i++) { + lib::TrappyCircle tc = manager->GetTrappyCircles()[i].GetData(); if (tc.IsChanged(json_trappy_circles.at(i).toObject())) { file_->close(); return true; } } - for (size_t i = 0; i < plot_area->GetTrappyLines().size(); i++) { - lib::TrappyLine tl = plot_area->GetTrappyLines()[i].GetData(); + for (size_t i = 0; i < manager->GetTrappyLines().size(); i++) { + lib::TrappyLine tl = manager->GetTrappyLines()[i].GetData(); if (tl.IsChanged(json_trappy_lines.at(i).toObject())) { file_->close(); return true; } } - for (size_t i = 0; i < plot_area->GetHills().size(); i++) { - lib::Hill h = plot_area->GetHills()[i].GetData(); + for (size_t i = 0; i < manager->GetHills().size(); i++) { + lib::Hill h = manager->GetHills()[i].GetData(); if (h.IsChanged(json_hills.at(i).toObject())) { file_->close(); return true; diff --git a/main/gui_json_file/open.cpp b/main/gui_json_file/open.cpp index 1d4f663..23e0816 100644 --- a/main/gui_json_file/open.cpp +++ b/main/gui_json_file/open.cpp @@ -1,7 +1,7 @@ #include "gui_json_file.h" std::vector GetTargetsFromFile(QJsonArray arr, - data_tools::PlotArea* plot_area) { + data_tools::DataManager* manager) { std::vector targets; for (size_t i = 0; i < arr.size(); i++) { lib::Target t; @@ -12,7 +12,7 @@ std::vector GetTargetsFromFile(QJsonArray arr, } std::vector GetTrappyCirclesFromFile( - QJsonArray arr, data_tools::PlotArea* plot_area) { + QJsonArray arr, data_tools::DataManager* manager) { std::vector trappy_circles; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyCircle tc; @@ -23,7 +23,7 @@ std::vector GetTrappyCirclesFromFile( } std::vector GetTrappyLinesFromFile( - QJsonArray arr, data_tools::PlotArea* plot_area) { + QJsonArray arr, data_tools::DataManager* manager) { std::vector trappy_lines; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyLine tl; @@ -34,7 +34,7 @@ std::vector GetTrappyLinesFromFile( } std::vector GetHillsFromFile(QJsonArray arr, - data_tools::PlotArea* plot_area) { + data_tools::DataManager* manager) { std::vector hills; for (size_t i = 0; i < arr.size(); i++) { lib::Hill h; @@ -44,7 +44,7 @@ std::vector GetHillsFromFile(QJsonArray arr, return hills; } -void GuiJsonFile::Open(data_tools::PlotArea* plot_area) { +void GuiJsonFile::Open(data_tools::DataManager* manager) { if (file_->open(QIODevice::ReadOnly | QFile::Text)) { QJsonObject root = LoadJson(); @@ -58,12 +58,13 @@ void GuiJsonFile::Open(data_tools::PlotArea* plot_area) { QJsonArray json_trappy_lines = root["Trappy_Lines"].toArray(); QJsonArray json_hills = root["Hills"].toArray(); - plot_area->Set(GetTargetsFromFile(json_targets, plot_area)); - plot_area->Set(GetTrappyCirclesFromFile(json_trappy_circles, plot_area)); - plot_area->Set(GetTrappyLinesFromFile(json_trappy_lines, plot_area)); - plot_area->Set(GetHillsFromFile(json_hills, plot_area)); + manager->Set(GetTargetsFromFile(json_targets, manager)); + manager->Set(GetTrappyCirclesFromFile(json_trappy_circles, manager)); + manager->Set(GetTrappyLinesFromFile(json_trappy_lines, manager)); + manager->Set(GetHillsFromFile(json_hills, manager)); - plot_area->Redraw(); file_->close(); + + // перерисовка произойдёт уже после } } diff --git a/main/gui_json_file/save.cpp b/main/gui_json_file/save.cpp index ce86993..0a24187 100644 --- a/main/gui_json_file/save.cpp +++ b/main/gui_json_file/save.cpp @@ -1,6 +1,6 @@ #include "gui_json_file.h" -void GuiJsonFile::Save(data_tools::PlotArea* plot_area) { +void GuiJsonFile::Save(data_tools::DataManager* manager_) { if (file_->fileName().indexOf("Untitled") != -1) { QString file_name = file_->fileName(); QString old_untitled = ""; @@ -19,35 +19,34 @@ void GuiJsonFile::Save(data_tools::PlotArea* plot_area) { int add_to_id = 10000; - for (size_t i = 0; i < plot_area->GetTargets().size(); i++) { - int id = add_to_id + plot_area->GetTargets()[i].GetPlottableIndex(); - targets_array.append(plot_area->GetTargets()[i].GetData().Save(id)); + for (size_t i = 0; i < manager_->GetTargets().size(); i++) { + int id = add_to_id + manager_->GetTargets()[i].GetPlottableIndex(); + targets_array.append(manager_->GetTargets()[i].GetData().Save(id)); } root.insert("Targets", targets_array); add_to_id = 20000; - for (size_t i = 0; i < plot_area->GetTrappyCircles().size(); i++) { - int id = add_to_id + plot_area->GetTrappyCircles()[i].GetItemIndex(); + for (size_t i = 0; i < manager_->GetTrappyCircles().size(); i++) { + int id = add_to_id + manager_->GetTrappyCircles()[i].GetItemIndex(); trappy_circles_array.append( - plot_area->GetTrappyCircles()[i].GetData().Save(id)); + manager_->GetTrappyCircles()[i].GetData().Save(id)); } root.insert("Trappy_Circles", trappy_circles_array); add_to_id = 30000; - for (size_t i = 0; i < plot_area->GetTrappyLines().size(); i++) { - int id = add_to_id + plot_area->GetTrappyLines()[i].GetPlottableIndex(); - trappy_lines_array.append( - plot_area->GetTrappyLines()[i].GetData().Save(id)); + for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) { + int id = add_to_id + manager_->GetTrappyLines()[i].GetPlottableIndex(); + trappy_lines_array.append(manager_->GetTrappyLines()[i].GetData().Save(id)); } root.insert("Trappy_Lines", trappy_lines_array); add_to_id = 40000; - for (size_t i = 0; i < plot_area->GetHills().size(); i++) { - int id = add_to_id + plot_area->GetHills()[i].GetPlottableIndex(); - hills_array.append(plot_area->GetHills()[i].GetData().Save(id)); + for (size_t i = 0; i < manager_->GetHills().size(); i++) { + int id = add_to_id + manager_->GetHills()[i].GetPlottableIndex(); + hills_array.append(manager_->GetHills()[i].GetData().Save(id)); } root.insert("Hills", hills_array); diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index dd1a7b9..e66b3f8 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -9,6 +9,8 @@ MainWindow::MainWindow(QWidget* parent) manager_(new data_tools::DataManager), t_connection_(new data_tools::TablesConnection) { ui->setupUi(this); + ui->plotSettingsDockWidget->setVisible(false); + ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectItems); @@ -20,31 +22,26 @@ MainWindow::MainWindow(QWidget* parent) area_->SetPlot(ui->plot); - area_->SetSettingsLabels(ui->targetInfoLabel, ui->hillInfoLabel, - ui->trappyCircleInfoLabel, ui->trappyLineInfoLabel); - { // проверка функционала графических классов и менеджера gui::Target t_1(3, 4); gui::Target t_2(2, 1); gui::Target t_3(1, 1); - area_->Set({t_1, t_2, t_3}); + manager_->Set({t_1, t_2, t_3}); gui::TrappyLine tr{t_1, t_2}; - area_->Add(tr); + manager_->Add(tr); gui::TrappyCircle trc({1, 2}, 0.5); - area_->Add(trc); + manager_->Add(trc); - area_->Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); + manager_->Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); } - ui->plotSettingsDockWidget->setVisible(false); - - area_->SetSettingsTables(ui->targetInfoTableWidget, ui->hillInfoTableWidget, - ui->trappyCircleInfoTableWidget, - ui->trappyLineInfoTableWidget); + t_connection_->SetSettingsTables( + ui->targetInfoTableWidget, ui->hillInfoTableWidget, + ui->trappyCircleInfoTableWidget, ui->trappyLineInfoTableWidget); area_->Redraw(); } diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index a4a771c..f8b7150 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -5,12 +5,12 @@ #include "./ui_mainwindow.h" void MainWindow::AddTarget(double x, double y) { - area_->Add(gui::Target(x, y)); + manager_->Add(gui::Target(x, y)); area_->Redraw(); } void MainWindow::AddTrappyCircle(double x, double y, double radius) { - area_->Add(gui::TrappyCircle(x, y, radius)); + manager_->Add(gui::TrappyCircle(x, y, radius)); area_->Redraw(); } @@ -21,16 +21,16 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { gui::Target t1(x1, y1); gui::Target t2(x2, y2); - area_->Add(t1); - area_->Add(t2); + manager_->Add(t1); + manager_->Add(t2); area_->Redraw(); - area_->Add(gui::TrappyLine({t1, t2})); + manager_->Add(gui::TrappyLine({t1, t2})); area_->Redraw(); } void MainWindow::AddHill(std::vector points) { - area_->Add(gui::Hill(points)); + manager_->Add(gui::Hill(points)); area_->Redraw(); } @@ -108,7 +108,7 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { switch (ret) { case QMessageBox::Save: - json_file_.Save(area_.get()); + json_file_.Save(manager_.get()); break; case QMessageBox::Discard: break; @@ -146,11 +146,12 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { // есть ли изменения в текущем файле void MainWindow::closeEvent(QCloseEvent* event) { bool is_closed = false; - if (json_file_.IsExistsFile() && json_file_.IsChanged(area_.get())) + if (json_file_.IsExistsFile() && json_file_.IsChanged(manager_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); - else if (!json_file_.IsExistsFile() && - (area_->GetTargets().size() + area_->GetTrappyCircles().size() + - area_->GetTrappyLines().size() + area_->GetHills().size()) != 0) + else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() + + manager_->GetTrappyCircles().size() + + manager_->GetTrappyLines().size() + + manager_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); if (is_closed) event->ignore(); @@ -161,16 +162,19 @@ void MainWindow::closeEvent(QCloseEvent* event) { // Кнопка "New" void MainWindow::on_actionNew_triggered() { bool is_closed = false; - if (json_file_.IsExistsFile() && json_file_.IsChanged(area_.get())) + if (json_file_.IsExistsFile() && json_file_.IsChanged(manager_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); - else if (!json_file_.IsExistsFile() && - (area_->GetTargets().size() + area_->GetTrappyCircles().size() + - area_->GetTrappyLines().size() + area_->GetHills().size()) != 0) + else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() + + manager_->GetTrappyCircles().size() + + manager_->GetTrappyLines().size() + + manager_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); if (!is_closed) { - area_->Clear(); + manager_->Clear(); json_file_.Clear(); + + area_->Redraw(); } } @@ -178,18 +182,20 @@ void MainWindow::on_actionNew_triggered() { void MainWindow::on_actionOpen_triggered() { bool is_closed = false; - if (json_file_.IsExistsFile() && json_file_.IsChanged(area_.get())) + if (json_file_.IsExistsFile() && json_file_.IsChanged(manager_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); - else if (!json_file_.IsExistsFile() && - (area_->GetTargets().size() + area_->GetTrappyCircles().size() + - area_->GetTrappyLines().size() + area_->GetHills().size()) != 0) + else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() + + manager_->GetTrappyCircles().size() + + manager_->GetTrappyLines().size() + + manager_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); if (!is_closed) { QString file_name = QFileDialog::getOpenFileName(this, tr("Open"), "", tr("File (*.json)")); json_file_.SetFile(file_name); try { - json_file_.Open(area_.get()); + json_file_.Open(manager_.get()); + area_->Redraw(); } catch (...) { QMessageBox::critical(this, "Damaged file", "Invalid format file!"); } @@ -200,7 +206,7 @@ void MainWindow::on_actionSave_triggered() { if (!json_file_.IsExistsFile()) on_actionSave_as_triggered(); else - json_file_.Save(area_.get()); + json_file_.Save(manager_.get()); } // Кнопка "Save as" @@ -208,7 +214,7 @@ void MainWindow::on_actionSave_as_triggered() { QString file_name = QFileDialog::getSaveFileName( this, tr("Save as"), json_file_.GetUntitledFile(), tr("File (*.json)")); json_file_.SetFile(file_name); - json_file_.Save(area_.get()); + json_file_.Save(manager_.get()); } void MainWindow::on_redrawPushButton_clicked() { area_->Redraw(); } From 36245b0adefaf3426fcb3af5f8bcea93a10259e5 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:16:00 +0300 Subject: [PATCH 18/28] refactor some files # add missing const to methods and swap Save and Load because of sense --- lib/base.h | 6 +++--- lib/hill.cpp | 6 +++--- lib/hill.h | 6 +++--- lib/target.cpp | 6 +++--- lib/target.h | 6 +++--- lib/trappy_circle.cpp | 6 +++--- lib/trappy_circle.h | 6 +++--- lib/trappy_line.cpp | 6 +++--- lib/trappy_line.h | 6 +++--- main/gui_json_file/gui_json_file.h | 16 ++++++++-------- main/gui_json_file/new.cpp | 11 +++++++---- main/gui_json_file/open.cpp | 17 ++++++++++------- main/gui_json_file/save.cpp | 8 ++++---- main/mainwindow.h | 2 +- main/mainwindow_connections.cpp | 21 +++++++++++++++++++-- 15 files changed, 76 insertions(+), 53 deletions(-) diff --git a/lib/base.h b/lib/base.h index df5b496..ef71b0c 100644 --- a/lib/base.h +++ b/lib/base.h @@ -8,9 +8,9 @@ namespace lib { /// @brief объект, возможный к считыванию по .json файлу [абстрактный класс] class JSONable { public: - virtual QJsonObject Save(int id) const = 0; - virtual void Load(QJsonObject obj) = 0; - virtual bool IsChanged(QJsonObject obj) = 0; + virtual QJsonObject Load(int id) const = 0; + virtual void Save(const QJsonObject& obj) = 0; + virtual bool IsChanged(const QJsonObject& obj) const = 0; }; } // namespace lib diff --git a/lib/hill.cpp b/lib/hill.cpp index ed9c5b7..716bf24 100644 --- a/lib/hill.cpp +++ b/lib/hill.cpp @@ -11,7 +11,7 @@ Hill::Hill(std::initializer_list points) : vertices_{points} { throw std::invalid_argument("hill cannot consist of one or zero points"); } -QJsonObject Hill::Save(int id) const { +QJsonObject Hill::Load(int id) const { QVariantMap hill_map; hill_map.insert("Id", id); @@ -27,7 +27,7 @@ QJsonObject Hill::Save(int id) const { return QJsonObject::fromVariantMap(hill_map); } -void Hill::Load(QJsonObject hill_obj) { +void Hill::Save(const QJsonObject& hill_obj) { if (!hill_obj.contains("Vertices")) throw std::invalid_argument(""); QJsonArray vertices_array = hill_obj.value("Vertices").toArray(); for (size_t i = 0; i < vertices_array.size(); i++) { @@ -41,7 +41,7 @@ void Hill::Load(QJsonObject hill_obj) { } } -bool Hill::IsChanged(QJsonObject hill_obj) { +bool Hill::IsChanged(const QJsonObject& hill_obj) const { for (size_t i = 1; i < hill_obj.size(); i++) { QJsonObject json_p = hill_obj.value("P" + QString::number(i)).toObject(); lib::Point p = {json_p.value("X").toDouble(), json_p.value("Y").toDouble()}; diff --git a/lib/hill.h b/lib/hill.h index e903ca0..e2582e4 100644 --- a/lib/hill.h +++ b/lib/hill.h @@ -39,9 +39,9 @@ class Hill : public JSONable { Hill& operator=(const Hill&) = default; Hill& operator=(Hill&&) = default; - QJsonObject Save(int id) const override; - void Load(QJsonObject hill_obj) override; - bool IsChanged(QJsonObject hill_obj) override; + QJsonObject Load(int id) const override; + void Save(const QJsonObject& hill_obj) override; + bool IsChanged(const QJsonObject& hill_obj) const override; Point GetCenter() const; double GetRadius() const; diff --git a/lib/target.cpp b/lib/target.cpp index f29bdfc..8debd07 100644 --- a/lib/target.cpp +++ b/lib/target.cpp @@ -2,7 +2,7 @@ namespace lib { -QJsonObject Target::Save(int id) const { +QJsonObject Target::Load(int id) const { QVariantMap target_map; target_map.insert("Id", id); @@ -12,7 +12,7 @@ QJsonObject Target::Save(int id) const { return QJsonObject::fromVariantMap(target_map); } -void Target::Load(QJsonObject target_obj) { +void Target::Save(const QJsonObject& target_obj) { if (!(target_obj.contains("X") && target_obj.contains("Y"))) throw std::invalid_argument(""); double x = target_obj.value("X").toDouble(); @@ -20,7 +20,7 @@ void Target::Load(QJsonObject target_obj) { SetPoint({x, y}); } -bool Target::IsChanged(QJsonObject target_obj) { +bool Target::IsChanged(const QJsonObject& target_obj) const { Point p = {target_obj.value("X").toDouble(), target_obj.value("Y").toDouble()}; return p != p_; diff --git a/lib/target.h b/lib/target.h index b2bfa85..32357b2 100644 --- a/lib/target.h +++ b/lib/target.h @@ -18,9 +18,9 @@ class Target : public JSONable { Target& operator=(const Target&) = default; Target& operator=(Target&&) = default; - QJsonObject Save(int id) const override; - void Load(QJsonObject target_obj) override; - bool IsChanged(QJsonObject target_obj) override; + QJsonObject Load(int id) const override; + void Save(const QJsonObject& target_obj) override; + bool IsChanged(const QJsonObject& target_obj) const override; Point GetPoint() const { return p_; } diff --git a/lib/trappy_circle.cpp b/lib/trappy_circle.cpp index 8be86f6..c3e292d 100644 --- a/lib/trappy_circle.cpp +++ b/lib/trappy_circle.cpp @@ -10,7 +10,7 @@ TrappyCircle::TrappyCircle(Point center, double radius) throw std::invalid_argument("trappy circle cannot have of negative radius"); } -QJsonObject TrappyCircle::Save(int id) const { +QJsonObject TrappyCircle::Load(int id) const { QVariantMap trappy_circle_map; trappy_circle_map.insert("Id", id); @@ -21,7 +21,7 @@ QJsonObject TrappyCircle::Save(int id) const { return QJsonObject::fromVariantMap(trappy_circle_map); } -void TrappyCircle::Load(QJsonObject trappy_circle_obj) { +void TrappyCircle::Save(const QJsonObject& trappy_circle_obj) { if (!(trappy_circle_obj.contains("X") && trappy_circle_obj.contains("Y") && trappy_circle_obj.contains("Radius"))) throw std::invalid_argument(""); @@ -32,7 +32,7 @@ void TrappyCircle::Load(QJsonObject trappy_circle_obj) { SetRadius(r); } -bool TrappyCircle::IsChanged(QJsonObject trappy_circle_obj) { +bool TrappyCircle::IsChanged(const QJsonObject& trappy_circle_obj) const { Point c = {trappy_circle_obj.value("X").toDouble(), trappy_circle_obj.value("Y").toDouble()}; double r = trappy_circle_obj.value("Radius").toDouble(); diff --git a/lib/trappy_circle.h b/lib/trappy_circle.h index 8d1a3ac..2c13a14 100644 --- a/lib/trappy_circle.h +++ b/lib/trappy_circle.h @@ -16,9 +16,9 @@ class TrappyCircle : public JSONable { TrappyCircle& operator=(const TrappyCircle&) = default; TrappyCircle& operator=(TrappyCircle&&) = default; - QJsonObject Save(int id) const override; - void Load(QJsonObject trappy_circle_obj) override; - bool IsChanged(QJsonObject trappy_circle_obj) override; + QJsonObject Load(int id) const override; + void Save(const QJsonObject& trappy_circle_obj) override; + bool IsChanged(const QJsonObject& trappy_circle_obj) const override; Point GetCenter() const { return center_; } double GetRadius() const { return radius_; } diff --git a/lib/trappy_line.cpp b/lib/trappy_line.cpp index ed09885..37aa80b 100644 --- a/lib/trappy_line.cpp +++ b/lib/trappy_line.cpp @@ -33,7 +33,7 @@ void TrappyLine::SetNewTargets(std::vector targets) { targets_ = targets; } -QJsonObject TrappyLine::Save(int id) const { +QJsonObject TrappyLine::Load(int id) const { QVariantMap trappy_line_map; QVariantMap p1_map; QVariantMap p2_map; @@ -51,7 +51,7 @@ QJsonObject TrappyLine::Save(int id) const { return QJsonObject::fromVariantMap(trappy_line_map); } -void TrappyLine::Load(QJsonObject trappy_line_obj) { +void TrappyLine::Save(const QJsonObject& trappy_line_obj) { if (!(trappy_line_obj.contains("P1") && trappy_line_obj.contains("P2"))) throw std::invalid_argument(""); @@ -67,7 +67,7 @@ void TrappyLine::Load(QJsonObject trappy_line_obj) { SetNewTargets({{x1, y1}, {x2, y2}}); } -bool TrappyLine::IsChanged(QJsonObject trappy_line_obj) { +bool TrappyLine::IsChanged(const QJsonObject& trappy_line_obj) const { QJsonObject p1_obj = trappy_line_obj.value("P1").toObject(); QJsonObject p2_obj = trappy_line_obj.value("P2").toObject(); Point p1 = {p1_obj.value("X").toDouble(), p1_obj.value("Y").toDouble()}; diff --git a/lib/trappy_line.h b/lib/trappy_line.h index 2a15f5c..09b51b1 100644 --- a/lib/trappy_line.h +++ b/lib/trappy_line.h @@ -33,9 +33,9 @@ class TrappyLine : public JSONable { TrappyLine& operator=(const TrappyLine&) = default; TrappyLine& operator=(TrappyLine&&) = default; - QJsonObject Save(int id) const override; - void Load(QJsonObject trappy_line_obj) override; - bool IsChanged(QJsonObject trappy_line_obj) override; + QJsonObject Load(int id) const override; + void Save(const QJsonObject& trappy_line_obj) override; + bool IsChanged(const QJsonObject& trappy_line_obj) const override; void SetNewTargets(std::initializer_list targets); diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index fb863fb..66b10de 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -8,24 +8,24 @@ class GuiJsonFile { GuiJsonFile(QFile* file) : file_{file} {}; void Save(data_tools::DataManager* plot_area); - void New(); void Open(data_tools::DataManager* plot_area); - QString GetFileName(); - QString GetUntitledFile() { return untitled_file_; } + QString GetFileName() const; + QString GetUntitledFile() const { return untitled_file_; } - void SetFile(QString file_name) { file_->setFileName(file_name); } - void ChangeUntitled(QString old_untitled); + void SetFile(const QString& file_name) { file_->setFileName(file_name); } + void ChangeUntitled(const QString& old_untitled); void Clear() { file_->setFileName(""); } - bool IsExistsFile() { + bool IsExistsFile() const { return (file_->fileName().size() != 0 && file_->exists()); } - bool IsChanged(data_tools::DataManager* plot_area); + + bool IsChanged(data_tools::DataManager* plot_area) const; private: QFile* file_{new QFile}; QString untitled_file_ = "Untitled.json"; - QJsonObject LoadJson(); + QJsonObject LoadJson() const; }; diff --git a/main/gui_json_file/new.cpp b/main/gui_json_file/new.cpp index ba8c4d6..a789db0 100644 --- a/main/gui_json_file/new.cpp +++ b/main/gui_json_file/new.cpp @@ -1,6 +1,6 @@ #include "gui_json_file.h" -void GuiJsonFile::ChangeUntitled(QString old_untitled) { +void GuiJsonFile::ChangeUntitled(const QString& old_untitled) { if (old_untitled == "Untitled.json") untitled_file_ = "Untitled (2).json"; @@ -10,27 +10,30 @@ void GuiJsonFile::ChangeUntitled(QString old_untitled) { i < old_untitled.indexOf(')'); i++) { num += old_untitled[i]; } + QString new_num = QString::number(num.toInt() + 1); untitled_file_ = "Untitled (" + new_num + ").json"; } } -QString GuiJsonFile::GetFileName() { +QString GuiJsonFile::GetFileName() const { QString file_name = file_->fileName(); QString new_file_name = ""; + for (size_t i = file_name.lastIndexOf('/') + 1; i < file_name.size(); i++) { new_file_name += file_name[i]; } + return new_file_name; } -QJsonObject GuiJsonFile::LoadJson() { +QJsonObject GuiJsonFile::LoadJson() const { QString json_text = file_->readAll(); QJsonDocument json_file = QJsonDocument::fromJson(json_text.toUtf8()); return json_file.object(); } -bool GuiJsonFile::IsChanged(data_tools::DataManager* manager) { +bool GuiJsonFile::IsChanged(data_tools::DataManager* manager) const { file_->open(QIODevice::ReadOnly | QFile::Text); QJsonObject root = LoadJson(); diff --git a/main/gui_json_file/open.cpp b/main/gui_json_file/open.cpp index 23e0816..f6f7389 100644 --- a/main/gui_json_file/open.cpp +++ b/main/gui_json_file/open.cpp @@ -5,9 +5,10 @@ std::vector GetTargetsFromFile(QJsonArray arr, std::vector targets; for (size_t i = 0; i < arr.size(); i++) { lib::Target t; - t.Load(arr.at(i).toObject()); + t.Save(arr.at(i).toObject()); targets.push_back(t); } + return targets; } @@ -16,9 +17,10 @@ std::vector GetTrappyCirclesFromFile( std::vector trappy_circles; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyCircle tc; - tc.Load(arr.at(i).toObject()); + tc.Save(arr.at(i).toObject()); trappy_circles.push_back(tc); } + return trappy_circles; } @@ -27,9 +29,10 @@ std::vector GetTrappyLinesFromFile( std::vector trappy_lines; for (size_t i = 0; i < arr.size(); i++) { lib::TrappyLine tl; - tl.Load(arr.at(i).toObject()); + tl.Save(arr.at(i).toObject()); trappy_lines.push_back(tl); } + return trappy_lines; } @@ -38,9 +41,10 @@ std::vector GetHillsFromFile(QJsonArray arr, std::vector hills; for (size_t i = 0; i < arr.size(); i++) { lib::Hill h; - h.Load(arr.at(i).toObject()); + h.Save(arr.at(i).toObject()); hills.push_back(h); } + return hills; } @@ -48,9 +52,8 @@ void GuiJsonFile::Open(data_tools::DataManager* manager) { if (file_->open(QIODevice::ReadOnly | QFile::Text)) { QJsonObject root = LoadJson(); - if (root.contains("Targets") + root.contains("Trappy_Circles") + - root.contains("Trappy_Lines") + root.contains("Hills") != - 4) + if (!(root.contains("Targets") && root.contains("Trappy_Circles") && + root.contains("Trappy_Lines") && root.contains("Hills"))) throw std::invalid_argument(""); QJsonArray json_targets = root["Targets"].toArray(); diff --git a/main/gui_json_file/save.cpp b/main/gui_json_file/save.cpp index 0a24187..3ea5394 100644 --- a/main/gui_json_file/save.cpp +++ b/main/gui_json_file/save.cpp @@ -21,7 +21,7 @@ void GuiJsonFile::Save(data_tools::DataManager* manager_) { for (size_t i = 0; i < manager_->GetTargets().size(); i++) { int id = add_to_id + manager_->GetTargets()[i].GetPlottableIndex(); - targets_array.append(manager_->GetTargets()[i].GetData().Save(id)); + targets_array.append(manager_->GetTargets()[i].GetData().Load(id)); } root.insert("Targets", targets_array); @@ -30,7 +30,7 @@ void GuiJsonFile::Save(data_tools::DataManager* manager_) { for (size_t i = 0; i < manager_->GetTrappyCircles().size(); i++) { int id = add_to_id + manager_->GetTrappyCircles()[i].GetItemIndex(); trappy_circles_array.append( - manager_->GetTrappyCircles()[i].GetData().Save(id)); + manager_->GetTrappyCircles()[i].GetData().Load(id)); } root.insert("Trappy_Circles", trappy_circles_array); @@ -38,7 +38,7 @@ void GuiJsonFile::Save(data_tools::DataManager* manager_) { for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) { int id = add_to_id + manager_->GetTrappyLines()[i].GetPlottableIndex(); - trappy_lines_array.append(manager_->GetTrappyLines()[i].GetData().Save(id)); + trappy_lines_array.append(manager_->GetTrappyLines()[i].GetData().Load(id)); } root.insert("Trappy_Lines", trappy_lines_array); @@ -46,7 +46,7 @@ void GuiJsonFile::Save(data_tools::DataManager* manager_) { for (size_t i = 0; i < manager_->GetHills().size(); i++) { int id = add_to_id + manager_->GetHills()[i].GetPlottableIndex(); - hills_array.append(manager_->GetHills()[i].GetData().Save(id)); + hills_array.append(manager_->GetHills()[i].GetData().Load(id)); } root.insert("Hills", hills_array); diff --git a/main/mainwindow.h b/main/mainwindow.h index fbbf223..49a4e00 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -67,5 +67,5 @@ class MainWindow : public QMainWindow { Ui::MainWindow* ui; GuiJsonFile json_file_; - bool OpenMessageWindow(FileType file_type); + bool OpenMessageWindow(const FileType& file_type); }; diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index f8b7150..f37d91a 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -23,9 +23,9 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { manager_->Add(t1); manager_->Add(t2); - area_->Redraw(); manager_->Add(gui::TrappyLine({t1, t2})); + area_->Redraw(); } @@ -97,7 +97,7 @@ void MainWindow::on_plot_MousePressed() { // Вызов окна, которое сообщает об изменениях в файле // и возвращает true, если окно было закрыто -bool MainWindow::OpenMessageWindow(FileType file_type) { +bool MainWindow::OpenMessageWindow(const FileType& file_type) { switch (file_type) { case FileType::UsualFile: { QString text = @@ -110,8 +110,10 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { case QMessageBox::Save: json_file_.Save(manager_.get()); break; + case QMessageBox::Discard: break; + case QMessageBox::Cancel: case QMessageBox::Close: return true; @@ -119,6 +121,7 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { } break; } + case FileType::UntitledFile: { QString text = "Do you want save changes in file " + json_file_.GetUntitledFile() + '?'; @@ -129,8 +132,10 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { case QMessageBox::Save: on_actionSave_as_triggered(); break; + case QMessageBox::Discard: break; + case QMessageBox::Cancel: case QMessageBox::Close: return true; @@ -146,13 +151,16 @@ bool MainWindow::OpenMessageWindow(FileType file_type) { // есть ли изменения в текущем файле void MainWindow::closeEvent(QCloseEvent* event) { bool is_closed = false; + if (json_file_.IsExistsFile() && json_file_.IsChanged(manager_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); + else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() + manager_->GetTrappyCircles().size() + manager_->GetTrappyLines().size() + manager_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); + if (is_closed) event->ignore(); else @@ -162,8 +170,10 @@ void MainWindow::closeEvent(QCloseEvent* event) { // Кнопка "New" void MainWindow::on_actionNew_triggered() { bool is_closed = false; + if (json_file_.IsExistsFile() && json_file_.IsChanged(manager_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); + else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() + manager_->GetTrappyCircles().size() + manager_->GetTrappyLines().size() + @@ -184,27 +194,33 @@ void MainWindow::on_actionOpen_triggered() { if (json_file_.IsExistsFile() && json_file_.IsChanged(manager_.get())) is_closed = OpenMessageWindow(FileType::UsualFile); + else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() + manager_->GetTrappyCircles().size() + manager_->GetTrappyLines().size() + manager_->GetHills().size()) != 0) is_closed = OpenMessageWindow(FileType::UntitledFile); + if (!is_closed) { QString file_name = QFileDialog::getOpenFileName(this, tr("Open"), "", tr("File (*.json)")); json_file_.SetFile(file_name); + try { json_file_.Open(manager_.get()); area_->Redraw(); + } catch (...) { QMessageBox::critical(this, "Damaged file", "Invalid format file!"); } } } + // Кнопка "Save" void MainWindow::on_actionSave_triggered() { if (!json_file_.IsExistsFile()) on_actionSave_as_triggered(); + else json_file_.Save(manager_.get()); } @@ -213,6 +229,7 @@ void MainWindow::on_actionSave_triggered() { void MainWindow::on_actionSave_as_triggered() { QString file_name = QFileDialog::getSaveFileName( this, tr("Save as"), json_file_.GetUntitledFile(), tr("File (*.json)")); + json_file_.SetFile(file_name); json_file_.Save(manager_.get()); } From 216d64db4e83638baaec46f309a28928af97cb9e Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:30:32 +0300 Subject: [PATCH 19/28] move PlottableIndex setting to Draw in gui classes --- data_tools/data_manager/data_manager.cpp | 4 - .../tables_connection/tables_connection.cpp | 324 ++++++++++-------- gui/base.h | 6 +- gui/hill.cpp | 5 +- gui/hill.h | 8 +- gui/target.cpp | 5 +- gui/target.h | 8 +- gui/trappy_circle.cpp | 5 +- gui/trappy_circle.h | 4 +- gui/trappy_line.cpp | 5 +- gui/trappy_line.h | 7 +- main/mainwindow.cpp | 18 +- 12 files changed, 204 insertions(+), 195 deletions(-) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index 3a7e43f..d2b6d00 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -13,25 +13,21 @@ void DataManager::Draw(gui::ObjectType obj_type, size_t index, QCustomPlot* plot) { switch (obj_type) { case gui::ObjectType::Targets: { - targets_[index].SetGraphIndex(plot->plottableCount()); targets_[index].Draw(plot); break; } case gui::ObjectType::Hills: { - hills_[index].SetGraphIndex(plot->plottableCount()); hills_[index].Draw(plot); break; } case gui::ObjectType::TrappyCircles: { - tr_circles_[index].SetItemIndex(plot->itemCount()); tr_circles_[index].Draw(plot); break; } case gui::ObjectType::TrappyLines: { - tr_lines_[index].SetGraphIndex(plot->plottableCount()); tr_lines_[index].Draw(plot); break; } diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index e797d52..de3163b 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -10,170 +10,182 @@ void TablesConnection::Setup(DataManager* manager, PlotArea* area) { } void TablesConnection::UpdateTable(const std::vector& targets) { - // кол-во столбцов = кол-во к.т. - targets_table_->setColumnCount(targets.size()); - - for (size_t i = 0; i < targets.size(); i++) { - // устанавливаем столбик с номером объекта - auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - item->setTextAlignment(Qt::AlignCenter); - targets_table_->setHorizontalHeaderItem(i, - item); // номер к.т. = индекс + 1 - - // в строки добавляем индекс на полотне и координаты - item = - new QTableWidgetItem(QString::number(targets[i].GetPlottableIndex())); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - targets_table_->setItem(0, i, item); - - item = new QTableWidgetItem(QString::number(targets[i].GetPoint().x)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - targets_table_->setItem(1, i, item); - - item = new QTableWidgetItem(QString::number(targets[i].GetPoint().y)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - targets_table_->setItem(2, i, item); + if (!targets.empty()) { + // кол-во столбцов = кол-во к.т. + targets_table_->setColumnCount(targets.size()); + + for (size_t i = 0; i < targets.size(); i++) { + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + targets_table_->setHorizontalHeaderItem(i, + item); // номер к.т. = индекс + 1 + + // в строки добавляем индекс на полотне и координаты + item = + new QTableWidgetItem(QString::number(targets[i].GetPlottableIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + targets_table_->setItem(0, i, item); + + item = new QTableWidgetItem(QString::number(targets[i].GetPoint().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + targets_table_->setItem(1, i, item); + + item = new QTableWidgetItem(QString::number(targets[i].GetPoint().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + targets_table_->setItem(2, i, item); + } + targets_table_->update(); } - targets_table_->update(); } void TablesConnection::UpdateTable(const std::vector& hills) { - // находим максимально возможное кол-во точек среди всех холмов - size_t hills_max_points = hills[0].GetPoints().size(); - for (size_t i = 0; i < hills.size() - 1; i++) { - hills_max_points = - std::max(hills[i].GetPoints().size(), hills[i + 1].GetPoints().size()); + if (!hills.empty()) { + // находим максимально возможное кол-во точек среди всех холмов + size_t hills_max_points = hills[0].GetPoints().size(); + for (size_t i = 0; i < hills.size() - 1; i++) { + hills_max_points = std::max(hills[i].GetPoints().size(), + hills[i + 1].GetPoints().size()); + } + + // кол-во столбцов = кол-во рельефов + hills_table_->setColumnCount(hills.size()); + + // кол-во строк = максимальное число точек * 2 (т.к. x и y) и индекс + hills_table_->setRowCount(hills_max_points * 2 + 1); + + for (size_t i = 0; i < hills.size(); i++) { + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + hills_table_->setHorizontalHeaderItem( + i, + item); // номер рельефа = индекс + 1 + + // в строки добавляем индекс на полотне и координаты всех точек + item = + new QTableWidgetItem(QString::number(hills[i].GetPlottableIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + hills_table_->setItem(0, i, item); + + for (size_t j = 1; j < hills[i].GetPoints().size() * 2; j += 2) { + // названия строк с координатами + hills_table_->setVerticalHeaderItem( + j, new QTableWidgetItem("X_" + QString::number(j / 2 + 1))); + hills_table_->setVerticalHeaderItem( + j + 1, new QTableWidgetItem("Y_" + QString::number(j / 2 + 1))); + + // сами координаты + item = new QTableWidgetItem( + QString::number(hills[i].GetPoints()[(j - 1) / 2].x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + hills_table_->setItem(j, i, item); + + item = new QTableWidgetItem( + QString::number(hills[i].GetPoints()[(j - 1) / 2].y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + hills_table_->setItem(j + 1, i, item); + } + } + hills_table_->update(); } +} + +void TablesConnection::UpdateTable( + const std::vector& trappy_lines) { + if (!trappy_lines.empty()) { + // кол-во столбцов = кол-во опасных линий + tr_lines_table_->setColumnCount(trappy_lines.size()); + + for (size_t i = 0; i < trappy_lines.size(); i++) { + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + tr_lines_table_->setHorizontalHeaderItem( + i, + item); // номер линии = индекс + 1 + + // в строки добавляем индекс на полотне и координаты двух точек + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetPlottableIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + tr_lines_table_->setItem(0, i, item); - // кол-во столбцов = кол-во рельефов - hills_table_->setColumnCount(hills.size()); - - // кол-во строк = максимальное число точек * 2 (т.к. x и y) и индекс - hills_table_->setRowCount(hills_max_points * 2 + 1); - - for (size_t i = 0; i < hills.size(); i++) { - // устанавливаем столбик с номером объекта - auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - item->setTextAlignment(Qt::AlignCenter); - hills_table_->setHorizontalHeaderItem(i, - item); // номер рельефа = индекс + 1 - - // в строки добавляем индекс на полотне и координаты всех точек - item = new QTableWidgetItem(QString::number(hills[i].GetPlottableIndex())); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - hills_table_->setItem(0, i, item); - - for (size_t j = 1; j < hills[i].GetPoints().size() * 2; j += 2) { - // названия строк с координатами - hills_table_->setVerticalHeaderItem( - j, new QTableWidgetItem("X_" + QString::number(j / 2 + 1))); - hills_table_->setVerticalHeaderItem( - j + 1, new QTableWidgetItem("Y_" + QString::number(j / 2 + 1))); - - // сами координаты item = new QTableWidgetItem( - QString::number(hills[i].GetPoints()[(j - 1) / 2].x)); + QString::number(trappy_lines[i].GetTargets()[0].GetPoint().x)); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); - hills_table_->setItem(j, i, item); + tr_lines_table_->setItem(1, i, item); item = new QTableWidgetItem( - QString::number(hills[i].GetPoints()[(j - 1) / 2].y)); + QString::number(trappy_lines[i].GetTargets()[0].GetPoint().y)); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); - hills_table_->setItem(j + 1, i, item); - } - } - hills_table_->update(); -} + tr_lines_table_->setItem(2, i, item); -void TablesConnection::UpdateTable( - const std::vector& trappy_lines) { - // кол-во столбцов = кол-во опасных линий - tr_lines_table_->setColumnCount(trappy_lines.size()); - - for (size_t i = 0; i < trappy_lines.size(); i++) { - // устанавливаем столбик с номером объекта - auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - item->setTextAlignment(Qt::AlignCenter); - tr_lines_table_->setHorizontalHeaderItem(i, - item); // номер линии = индекс + 1 - - // в строки добавляем индекс на полотне и координаты двух точек - item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetPlottableIndex())); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - tr_lines_table_->setItem(0, i, item); - - item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[0].GetPoint().x)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_lines_table_->setItem(1, i, item); - - item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[0].GetPoint().y)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_lines_table_->setItem(2, i, item); - - item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[1].GetPoint().x)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_lines_table_->setItem(3, i, item); - - item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[1].GetPoint().y)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_lines_table_->setItem(4, i, item); + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetTargets()[1].GetPoint().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_lines_table_->setItem(3, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_lines[i].GetTargets()[1].GetPoint().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_lines_table_->setItem(4, i, item); + } + tr_lines_table_->update(); } - tr_lines_table_->update(); } void TablesConnection::UpdateTable( const std::vector& trappy_circles) { - // кол-во столбцов = кол-во опасных зон - tr_circles_table_->setColumnCount(trappy_circles.size()); - - for (size_t i = 0; i < trappy_circles.size(); i++) { - // устанавливаем столбик с номером объекта - auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - item->setTextAlignment(Qt::AlignCenter); - tr_circles_table_->setHorizontalHeaderItem( - i, item); // номер зоны = индекс + 1 - - // в строки добавляем индекс на полотне и координаты точки и радиус - item = - new QTableWidgetItem(QString::number(trappy_circles[i].GetItemIndex())); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - tr_circles_table_->setItem(0, i, item); - - item = - new QTableWidgetItem(QString::number(trappy_circles[i].GetCenter().x)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_circles_table_->setItem(1, i, item); - - item = - new QTableWidgetItem(QString::number(trappy_circles[i].GetCenter().y)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_circles_table_->setItem(2, i, item); - - item = new QTableWidgetItem(QString::number(trappy_circles[i].GetRadius())); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | - Qt::ItemIsEnabled); - tr_circles_table_->setItem(3, i, item); + if (!trappy_circles.empty()) { + // кол-во столбцов = кол-во опасных зон + tr_circles_table_->setColumnCount(trappy_circles.size()); + + for (size_t i = 0; i < trappy_circles.size(); i++) { + // устанавливаем столбик с номером объекта + auto item = new QTableWidgetItem("№ " + QString::number(i + 1)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setTextAlignment(Qt::AlignCenter); + tr_circles_table_->setHorizontalHeaderItem( + i, item); // номер зоны = индекс + 1 + + // в строки добавляем индекс на полотне и координаты точки и радиус + item = new QTableWidgetItem( + QString::number(trappy_circles[i].GetItemIndex())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + tr_circles_table_->setItem(0, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_circles[i].GetCenter().x)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_circles_table_->setItem(1, i, item); + + item = new QTableWidgetItem( + QString::number(trappy_circles[i].GetCenter().y)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_circles_table_->setItem(2, i, item); + + item = + new QTableWidgetItem(QString::number(trappy_circles[i].GetRadius())); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | + Qt::ItemIsEnabled); + tr_circles_table_->setItem(3, i, item); + } + tr_circles_table_->update(); } - tr_circles_table_->update(); } void TablesConnection::UpdateTables() { @@ -188,18 +200,32 @@ void TablesConnection::TargetsItemChanged(int row, int column) { auto y_item = targets_table_->item(2, column); if (x_item != nullptr && y_item != nullptr) { - IC(column, manager_->GetTargets().size()); - if (column < manager_->GetTargets().size()) + if (column < manager_->GetTargets().size()) { manager_->GetTargets()[column].SetPoint(x_item->text().toDouble(), y_item->text().toDouble()); + + // area_->Redraw(); + } } } -void TablesConnection::HillsItemChanged(int row, int column) {} +void TablesConnection::HillsItemChanged(int row, int column) { + if (column < manager_->GetHills().size()) { + // area_->Redraw(); + } +} -void TablesConnection::TrappyCirclesItemChanged(int row, int column) {} +void TablesConnection::TrappyCirclesItemChanged(int row, int column) { + if (column < manager_->GetTrappyCircles().size()) { + // area_->Redraw(); + } +} -void TablesConnection::TrappyLinesItemChanged(int row, int column) {} +void TablesConnection::TrappyLinesItemChanged(int row, int column) { + if (column < manager_->GetTrappyLines().size()) { + // area_->Redraw(); + } +} void TablesConnection::UpdateTablesConnections() { { diff --git a/gui/base.h b/gui/base.h index deffddf..d12e6fd 100644 --- a/gui/base.h +++ b/gui/base.h @@ -11,11 +11,7 @@ class Drawable { * @brief привязывает (рисует) экземпляр класса на полотне * @param plot: указатель на соотв. полотно */ - virtual void Draw(QCustomPlot* plot) const = 0; - - // Drawable(const Drawable&) = delete; - // IDK: нужно ли запрещать копирование и париться с vector, - // учитывая, что индексы должны быть уникальными? + virtual void Draw(QCustomPlot* plot) = 0; Drawable() = default; }; diff --git a/gui/hill.cpp b/gui/hill.cpp index bd984c7..ccdb535 100644 --- a/gui/hill.cpp +++ b/gui/hill.cpp @@ -1,6 +1,6 @@ #include "hill.h" -void gui::Hill::Draw(QCustomPlot* plot) const { +void gui::Hill::Draw(QCustomPlot* plot) { // фигура представляет собой зеленый многоугольник с полупрозрачной заливкой // (зеленый по умолчанию, однако цвет задаётся в аргументах конструктора) @@ -24,4 +24,7 @@ void gui::Hill::Draw(QCustomPlot* plot) const { // замыкаем, соединяя с первой точкой curve->addData({points[0].x}, {points[0].y}); + + // индекс последнего созданного = кол-во всех - 1 + plottable_index_ = plot->plottableCount() - 1; } diff --git a/gui/hill.h b/gui/hill.h index 0853281..d4f8094 100644 --- a/gui/hill.h +++ b/gui/hill.h @@ -3,7 +3,6 @@ #include "base.h" #include "lib/hill.h" - namespace gui { /// @brief фигура рельефа с высотой @@ -49,15 +48,14 @@ class Hill : public Drawable { std::vector GetPoints() const { return data_.GetPoints(); } - void Draw(QCustomPlot* plot) const override; + void Draw(QCustomPlot* plot) override; - size_t GetPlottableIndex() const { return graph_index_; } - void SetGraphIndex(size_t index) { graph_index_ = index; } + size_t GetPlottableIndex() const { return plottable_index_; } private: lib::Hill data_; QColor color_; - size_t graph_index_{ULLONG_MAX}; + size_t plottable_index_{ULLONG_MAX}; }; } // namespace gui diff --git a/gui/target.cpp b/gui/target.cpp index 20a240f..2f5837c 100644 --- a/gui/target.cpp +++ b/gui/target.cpp @@ -1,6 +1,6 @@ #include "target.h" -void gui::Target::Draw(QCustomPlot* plot) const { +void gui::Target::Draw(QCustomPlot* plot) { // фигура представляет собой малую серую окружность (точку) auto graph = plot->addGraph(plot->xAxis, plot->yAxis); @@ -10,4 +10,7 @@ void gui::Target::Draw(QCustomPlot* plot) const { graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4)); graph->setData({GetPoint().x}, {GetPoint().y}); + + // индекс последнего созданного = кол-во всех - 1 + plottable_index_ = plot->plottableCount() - 1; } diff --git a/gui/target.h b/gui/target.h index 0d6c552..231f9f5 100644 --- a/gui/target.h +++ b/gui/target.h @@ -3,7 +3,6 @@ #include "base.h" #include "lib/target.h" - namespace gui { /// @brief фигура контрольной точки @@ -27,14 +26,13 @@ class Target : public Drawable { lib::Point GetPoint() const { return data_.GetPoint(); } lib::Target GetData() const { return data_; } - void Draw(QCustomPlot* plot) const override; + void Draw(QCustomPlot* plot) override; - size_t GetPlottableIndex() const { return graph_index_; } - void SetGraphIndex(size_t index) { graph_index_ = index; } + size_t GetPlottableIndex() const { return plottable_index_; } private: lib::Target data_; - size_t graph_index_{ULLONG_MAX}; + size_t plottable_index_{ULLONG_MAX}; }; } // namespace gui diff --git a/gui/trappy_circle.cpp b/gui/trappy_circle.cpp index 49a463c..2c6fc66 100644 --- a/gui/trappy_circle.cpp +++ b/gui/trappy_circle.cpp @@ -1,6 +1,6 @@ #include "trappy_circle.h" -void gui::TrappyCircle::Draw(QCustomPlot* plot) const { +void gui::TrappyCircle::Draw(QCustomPlot* plot) { // фигура представляет собой красный круг с полупрозрачной заливкой // (красный по умолчанию, однако цвет задаётся в аргументах конструктора) @@ -14,4 +14,7 @@ void gui::TrappyCircle::Draw(QCustomPlot* plot) const { GetCenter().y + GetRadius()); ellipse->bottomRight->setCoords(GetCenter().x + GetRadius(), GetCenter().y - GetRadius()); + + // индекс последнего созданного = кол-во всех - 1 + item_index_ = plot->itemCount() - 1; } diff --git a/gui/trappy_circle.h b/gui/trappy_circle.h index fe86d4d..938c35f 100644 --- a/gui/trappy_circle.h +++ b/gui/trappy_circle.h @@ -3,7 +3,6 @@ #include "base.h" #include "lib/trappy_circle.h" - namespace gui { /// @brief фигура опасной зоны @@ -37,10 +36,9 @@ class TrappyCircle : public Drawable { void SetCenter(const lib::Point& center) { data_.SetCenter(center); } void SetRadius(double radius) { data_.SetRadius(radius); } - void Draw(QCustomPlot* plot) const override; + void Draw(QCustomPlot* plot) override; size_t GetItemIndex() const { return item_index_; } - void SetItemIndex(size_t index) { item_index_ = index; } private: lib::TrappyCircle data_; diff --git a/gui/trappy_line.cpp b/gui/trappy_line.cpp index 3ffbe87..a5b1055 100644 --- a/gui/trappy_line.cpp +++ b/gui/trappy_line.cpp @@ -10,7 +10,7 @@ void TrappyLine::SetNewTargets(std::initializer_list targets) { UpdateData(targets); } -void TrappyLine::Draw(QCustomPlot* plot) const { +void TrappyLine::Draw(QCustomPlot* plot) { // фигура представляет собой пунктирное красное соединение между // заданными контрольными точками (причем эти точки выделяются) @@ -29,6 +29,9 @@ void TrappyLine::Draw(QCustomPlot* plot) const { for (int i = 0; i < targets.size(); i++) { graph->addData({targets[i].GetPoint().x}, {targets[i].GetPoint().y}); } + + // индекс последнего созданного = кол-во всех - 1 + plottable_index_ = plot->plottableCount() - 1; } void TrappyLine::UpdateData(std::initializer_list targets) { diff --git a/gui/trappy_line.h b/gui/trappy_line.h index d2565dd..855ef3c 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -29,10 +29,9 @@ class TrappyLine : public Drawable { std::vector GetTargets() const { return data_.GetTargets(); } lib::TrappyLine GetData() const { return data_; } - void Draw(QCustomPlot* plot) const override; + void Draw(QCustomPlot* plot) override; - size_t GetPlottableIndex() const { return graph_index_; } - void SetGraphIndex(size_t index) { graph_index_ = index; } + size_t GetPlottableIndex() const { return plottable_index_; } private: /** @@ -48,7 +47,7 @@ class TrappyLine : public Drawable { void AddData(std::initializer_list targets); lib::TrappyLine data_; - size_t graph_index_{ULLONG_MAX}; + size_t plottable_index_{ULLONG_MAX}; }; } // namespace gui diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index e66b3f8..977204c 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -19,25 +19,11 @@ MainWindow::MainWindow(QWidget* parent) area_->Setup(manager_.get(), t_connection_.get()); t_connection_->Setup(manager_.get(), area_.get()); + manager_->Setup(area_.get(), t_connection_.get()); area_->SetPlot(ui->plot); - { // проверка функционала графических классов и менеджера - - gui::Target t_1(3, 4); - gui::Target t_2(2, 1); - gui::Target t_3(1, 1); - - manager_->Set({t_1, t_2, t_3}); - - gui::TrappyLine tr{t_1, t_2}; - manager_->Add(tr); - - gui::TrappyCircle trc({1, 2}, 0.5); - manager_->Add(trc); - - manager_->Add(gui::Hill(lib::Point(1, 4), 0.5, 7)); - } + // нынче для проверки функционала файл открывают t_connection_->SetSettingsTables( ui->targetInfoTableWidget, ui->hillInfoTableWidget, From dd3180c18832aa0392e87ee96939442196c8f5ff Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 13:16:21 +0300 Subject: [PATCH 20/28] add ptrs on plot saving feature in gui classes --- gui/hill.cpp | 12 ++++++------ gui/hill.h | 11 +++++++++++ gui/target.cpp | 10 +++++----- gui/target.h | 11 +++++++++++ gui/trappy_circle.cpp | 14 +++++++------- gui/trappy_circle.h | 11 +++++++++++ gui/trappy_line.cpp | 10 +++++----- gui/trappy_line.h | 11 +++++++++++ 8 files changed, 67 insertions(+), 23 deletions(-) diff --git a/gui/hill.cpp b/gui/hill.cpp index ccdb535..239f869 100644 --- a/gui/hill.cpp +++ b/gui/hill.cpp @@ -4,26 +4,26 @@ void gui::Hill::Draw(QCustomPlot* plot) { // фигура представляет собой зеленый многоугольник с полупрозрачной заливкой // (зеленый по умолчанию, однако цвет задаётся в аргументах конструктора) - auto curve = new QCPCurve(plot->xAxis, plot->yAxis); + curve_ = new QCPCurve(plot->xAxis, plot->yAxis); QColor fill_color = QColor(color_.red(), color_.green(), color_.blue(), 100); QPen pen; pen.setColor(color_); pen.setStyle(Qt::SolidLine); - curve->setPen(pen); - curve->setBrush(fill_color); + curve_->setPen(pen); + curve_->setBrush(fill_color); - curve->setLineStyle(QCPCurve::lsLine); + curve_->setLineStyle(QCPCurve::lsLine); auto points = data_.GetPoints(); for (int i = 0; i < points.size(); i++) { - curve->addData({points[i].x}, {points[i].y}); + curve_->addData({points[i].x}, {points[i].y}); } // замыкаем, соединяя с первой точкой - curve->addData({points[0].x}, {points[0].y}); + curve_->addData({points[0].x}, {points[0].y}); // индекс последнего созданного = кол-во всех - 1 plottable_index_ = plot->plottableCount() - 1; diff --git a/gui/hill.h b/gui/hill.h index d4f8094..937353d 100644 --- a/gui/hill.h +++ b/gui/hill.h @@ -50,12 +50,23 @@ class Hill : public Drawable { void Draw(QCustomPlot* plot) override; + /** + * @brief возвращает индекс на полотне [plottable] + * @return size_t: индекс + */ size_t GetPlottableIndex() const { return plottable_index_; } + /** + * @brief возвращает значение указателя на полотне + * @return QCPGraph*: указатель + */ + QCPCurve* GetCurvePtr() const { return curve_; } + private: lib::Hill data_; QColor color_; size_t plottable_index_{ULLONG_MAX}; + QCPCurve* curve_{nullptr}; }; } // namespace gui diff --git a/gui/target.cpp b/gui/target.cpp index 2f5837c..74f93c5 100644 --- a/gui/target.cpp +++ b/gui/target.cpp @@ -3,13 +3,13 @@ void gui::Target::Draw(QCustomPlot* plot) { // фигура представляет собой малую серую окружность (точку) - auto graph = plot->addGraph(plot->xAxis, plot->yAxis); + graph_ = plot->addGraph(plot->xAxis, plot->yAxis); - graph->setPen(QColor(50, 50, 50, 255)); - graph->setLineStyle(QCPGraph::lsNone); - graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4)); + graph_->setPen(QColor(50, 50, 50, 255)); + graph_->setLineStyle(QCPGraph::lsNone); + graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4)); - graph->setData({GetPoint().x}, {GetPoint().y}); + graph_->setData({GetPoint().x}, {GetPoint().y}); // индекс последнего созданного = кол-во всех - 1 plottable_index_ = plot->plottableCount() - 1; diff --git a/gui/target.h b/gui/target.h index 231f9f5..3273cfe 100644 --- a/gui/target.h +++ b/gui/target.h @@ -28,11 +28,22 @@ class Target : public Drawable { void Draw(QCustomPlot* plot) override; + /** + * @brief возвращает индекс на полотне [plottable] + * @return size_t: индекс + */ size_t GetPlottableIndex() const { return plottable_index_; } + /** + * @brief возвращает значение указателя на полотне + * @return QCPGraph*: указатель + */ + QCPGraph* GetGraphPtr() const { return graph_; } + private: lib::Target data_; size_t plottable_index_{ULLONG_MAX}; + QCPGraph* graph_{nullptr}; }; } // namespace gui diff --git a/gui/trappy_circle.cpp b/gui/trappy_circle.cpp index 2c6fc66..60a51f8 100644 --- a/gui/trappy_circle.cpp +++ b/gui/trappy_circle.cpp @@ -4,16 +4,16 @@ void gui::TrappyCircle::Draw(QCustomPlot* plot) { // фигура представляет собой красный круг с полупрозрачной заливкой // (красный по умолчанию, однако цвет задаётся в аргументах конструктора) - auto ellipse = new QCPItemEllipse(plot); + ellipse_ = new QCPItemEllipse(plot); QColor fill_color = QColor(color_.red(), color_.green(), color_.blue(), 100); - ellipse->setPen(QColor(color_)); - ellipse->setBrush(fill_color); - ellipse->topLeft->setCoords(GetCenter().x - GetRadius(), - GetCenter().y + GetRadius()); - ellipse->bottomRight->setCoords(GetCenter().x + GetRadius(), - GetCenter().y - GetRadius()); + ellipse_->setPen(QColor(color_)); + ellipse_->setBrush(fill_color); + ellipse_->topLeft->setCoords(GetCenter().x - GetRadius(), + GetCenter().y + GetRadius()); + ellipse_->bottomRight->setCoords(GetCenter().x + GetRadius(), + GetCenter().y - GetRadius()); // индекс последнего созданного = кол-во всех - 1 item_index_ = plot->itemCount() - 1; diff --git a/gui/trappy_circle.h b/gui/trappy_circle.h index 938c35f..a0d8115 100644 --- a/gui/trappy_circle.h +++ b/gui/trappy_circle.h @@ -38,12 +38,23 @@ class TrappyCircle : public Drawable { void Draw(QCustomPlot* plot) override; + /** + * @brief возвращает индекс на полотне [item] + * @return size_t: индекс + */ size_t GetItemIndex() const { return item_index_; } + /** + * @brief возвращает значение указателя на полотне + * @return QCPItemEllipse*: указатель + */ + QCPItemEllipse* GetItemEllipsePtr() const { return ellipse_; } + private: lib::TrappyCircle data_; QColor color_; size_t item_index_{ULLONG_MAX}; + QCPItemEllipse* ellipse_{nullptr}; }; } // namespace gui diff --git a/gui/trappy_line.cpp b/gui/trappy_line.cpp index a5b1055..12dfe3d 100644 --- a/gui/trappy_line.cpp +++ b/gui/trappy_line.cpp @@ -14,20 +14,20 @@ void TrappyLine::Draw(QCustomPlot* plot) { // фигура представляет собой пунктирное красное соединение между // заданными контрольными точками (причем эти точки выделяются) - auto graph = plot->addGraph(plot->xAxis, plot->yAxis); + graph_ = plot->addGraph(plot->xAxis, plot->yAxis); QPen pen; pen.setColor(QColor(200, 50, 50, 255)); pen.setStyle(Qt::DashLine); - graph->setPen(pen); + graph_->setPen(pen); - graph->setLineStyle(QCPGraph::lsLine); - graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 8)); + graph_->setLineStyle(QCPGraph::lsLine); + graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 8)); auto targets = data_.GetTargets(); for (int i = 0; i < targets.size(); i++) { - graph->addData({targets[i].GetPoint().x}, {targets[i].GetPoint().y}); + graph_->addData({targets[i].GetPoint().x}, {targets[i].GetPoint().y}); } // индекс последнего созданного = кол-во всех - 1 diff --git a/gui/trappy_line.h b/gui/trappy_line.h index 855ef3c..604a0cc 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -31,8 +31,18 @@ class TrappyLine : public Drawable { void Draw(QCustomPlot* plot) override; + /** + * @brief возвращает индекс на полотне [plottable] + * @return size_t: индекс + */ size_t GetPlottableIndex() const { return plottable_index_; } + /** + * @brief возвращает значение указателя на полотне + * @return QCPGraph*: указатель + */ + QCPGraph* GetGraphPtr() const { return graph_; } + private: /** * @brief обновляет объекты в приватном поле lib::TrappyLine @@ -48,6 +58,7 @@ class TrappyLine : public Drawable { lib::TrappyLine data_; size_t plottable_index_{ULLONG_MAX}; + QCPGraph* graph_{nullptr}; }; } // namespace gui From 08da97deb94221ea023eaf4bfff83a4329ee7f7f Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 13:35:12 +0300 Subject: [PATCH 21/28] realize TrappyCirclesItemChanged --- .../tables_connection/tables_connection.cpp | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index de3163b..2018a25 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -199,13 +199,12 @@ void TablesConnection::TargetsItemChanged(int row, int column) { auto x_item = targets_table_->item(1, column); auto y_item = targets_table_->item(2, column); - if (x_item != nullptr && y_item != nullptr) { - if (column < manager_->GetTargets().size()) { - manager_->GetTargets()[column].SetPoint(x_item->text().toDouble(), - y_item->text().toDouble()); + if (x_item != nullptr && y_item != nullptr && + column < manager_->GetTargets().size()) { + manager_->GetTargets()[column].SetPoint(x_item->text().toDouble(), + y_item->text().toDouble()); - // area_->Redraw(); - } + // area_->Redraw(); } } @@ -216,7 +215,16 @@ void TablesConnection::HillsItemChanged(int row, int column) { } void TablesConnection::TrappyCirclesItemChanged(int row, int column) { - if (column < manager_->GetTrappyCircles().size()) { + auto x_item = tr_circles_table_->item(1, column); + auto y_item = tr_circles_table_->item(2, column); + auto r_item = tr_circles_table_->item(3, column); + + if (x_item != nullptr && y_item != nullptr && r_item != nullptr && + column < manager_->GetTrappyCircles().size()) { + manager_->GetTrappyCircles()[column].SetCenter( + {x_item->text().toDouble(), y_item->text().toDouble()}); + manager_->GetTrappyCircles()[column].SetRadius(r_item->text().toDouble()); + // area_->Redraw(); } } From 2587e8e48d2f37d4acc300eb43c410aacfc836c4 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:30:44 +0300 Subject: [PATCH 22/28] remake TrappyLine (now pair<*,*>) and add const & in some methods --- .../tables_connection/tables_connection.cpp | 8 +-- gui/hill.h | 6 ++- gui/target.h | 3 +- gui/trappy_circle.h | 3 +- gui/trappy_line.cpp | 32 ++++------- gui/trappy_line.h | 44 ++++++++------- lib/hill.h | 3 +- lib/trappy_line.cpp | 53 +++---------------- lib/trappy_line.h | 32 ++++------- main/gui_json_file/gui_json_file.h | 2 +- main/mainwindow_connections.cpp | 2 +- 11 files changed, 68 insertions(+), 120 deletions(-) diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index 2018a25..6e3ec03 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -119,25 +119,25 @@ void TablesConnection::UpdateTable( tr_lines_table_->setItem(0, i, item); item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[0].GetPoint().x)); + QString::number(trappy_lines[i].GetTargets().first.GetPoint().x)); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); tr_lines_table_->setItem(1, i, item); item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[0].GetPoint().y)); + QString::number(trappy_lines[i].GetTargets().first.GetPoint().y)); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); tr_lines_table_->setItem(2, i, item); item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[1].GetPoint().x)); + QString::number(trappy_lines[i].GetTargets().second.GetPoint().x)); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); tr_lines_table_->setItem(3, i, item); item = new QTableWidgetItem( - QString::number(trappy_lines[i].GetTargets()[1].GetPoint().y)); + QString::number(trappy_lines[i].GetTargets().second.GetPoint().y)); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); tr_lines_table_->setItem(4, i, item); diff --git a/gui/hill.h b/gui/hill.h index 937353d..bf004ad 100644 --- a/gui/hill.h +++ b/gui/hill.h @@ -44,9 +44,11 @@ class Hill : public Drawable { lib::Point GetCenter() const { return data_.GetCenter(); } double GetRadius() const { return data_.GetRadius(); } - lib::Hill GetData() const { return data_; } - std::vector GetPoints() const { return data_.GetPoints(); } + const lib::Hill& GetData() const { return data_; } + lib::Hill& GetData() { return data_; } + + const std::vector& GetPoints() const { return data_.GetPoints(); } void Draw(QCustomPlot* plot) override; diff --git a/gui/target.h b/gui/target.h index 3273cfe..6c44472 100644 --- a/gui/target.h +++ b/gui/target.h @@ -24,7 +24,8 @@ class Target : public Drawable { void SetPoint(double x, double y) { data_.SetPoint(x, y); } lib::Point GetPoint() const { return data_.GetPoint(); } - lib::Target GetData() const { return data_; } + lib::Target& GetData() { return data_; } + const lib::Target& GetData() const { return data_; } void Draw(QCustomPlot* plot) override; diff --git a/gui/trappy_circle.h b/gui/trappy_circle.h index a0d8115..7490ca1 100644 --- a/gui/trappy_circle.h +++ b/gui/trappy_circle.h @@ -31,7 +31,8 @@ class TrappyCircle : public Drawable { lib::Point GetCenter() const { return data_.GetCenter(); } double GetRadius() const { return data_.GetRadius(); } QColor GetColor() const { return color_; } - lib::TrappyCircle GetData() const { return data_; } + const lib::TrappyCircle& GetData() const { return data_; } + lib::TrappyCircle& GetData() { return data_; } void SetCenter(const lib::Point& center) { data_.SetCenter(center); } void SetRadius(double radius) { data_.SetRadius(radius); } diff --git a/gui/trappy_line.cpp b/gui/trappy_line.cpp index 12dfe3d..1184e37 100644 --- a/gui/trappy_line.cpp +++ b/gui/trappy_line.cpp @@ -2,14 +2,6 @@ namespace gui { -TrappyLine::TrappyLine(std::initializer_list targets) { - UpdateData(targets); -} - -void TrappyLine::SetNewTargets(std::initializer_list targets) { - UpdateData(targets); -} - void TrappyLine::Draw(QCustomPlot* plot) { // фигура представляет собой пунктирное красное соединение между // заданными контрольными точками (причем эти точки выделяются) @@ -26,28 +18,22 @@ void TrappyLine::Draw(QCustomPlot* plot) { auto targets = data_.GetTargets(); - for (int i = 0; i < targets.size(); i++) { - graph_->addData({targets[i].GetPoint().x}, {targets[i].GetPoint().y}); - } + graph_->addData({targets.first.GetPoint().x}, {targets.first.GetPoint().y}); + graph_->addData({targets.second.GetPoint().x}, {targets.second.GetPoint().y}); // индекс последнего созданного = кол-во всех - 1 plottable_index_ = plot->plottableCount() - 1; } -void TrappyLine::UpdateData(std::initializer_list targets) { - std::vector l_targets; - for (const auto& target : targets) { - l_targets.push_back(target.GetData()); - } - data_ = lib::TrappyLine(l_targets); +void TrappyLine::UpdateData(gui::Target* first_target, + gui::Target* second_target) { + data_.SetTargets(&first_target->GetData(), &second_target->GetData()); + targets_ides_ = std::make_pair(first_target->GetPlottableIndex(), + second_target->GetPlottableIndex()); } -void TrappyLine::AddData(std::initializer_list targets) { - std::vector l_targets = data_.GetTargets(); - for (const auto& target : targets) { - l_targets.push_back(target.GetData()); - } - data_ = lib::TrappyLine(l_targets); +void TrappyLine::UpdateData(std::pair targets) { + UpdateData(targets.first, targets.second); } } // namespace gui diff --git a/gui/trappy_line.h b/gui/trappy_line.h index 604a0cc..da6dad3 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -10,9 +10,15 @@ class TrappyLine : public Drawable { public: TrappyLine() = default; - TrappyLine(std::initializer_list targets); + TrappyLine(gui::Target* first_target, gui::Target* second_target) { + UpdateData(first_target, second_target); + } + + TrappyLine(std::pair targets) { + UpdateData(targets); + } - TrappyLine(const lib::TrappyLine& data) : data_(data){}; + TrappyLine(const lib::TrappyLine& data) : data_(data) {} TrappyLine(const TrappyLine&) = default; TrappyLine(TrappyLine&&) = default; @@ -20,14 +26,20 @@ class TrappyLine : public Drawable { TrappyLine& operator=(const TrappyLine&) = default; TrappyLine& operator=(TrappyLine&&) = default; - void SetNewTargets(std::initializer_list targets); + void SetTargets(gui::Target* first_target, gui::Target* second_target) { + UpdateData(first_target, second_target); + } - void AddTargets(std::initializer_list targets) { - AddData(targets); + void SetTargets(std::pair targets) { + UpdateData(targets); } - std::vector GetTargets() const { return data_.GetTargets(); } - lib::TrappyLine GetData() const { return data_; } + std::pair GetTargets() const { + return data_.GetTargets(); + } + + const lib::TrappyLine& GetData() const { return data_; } + lib::TrappyLine& GetData() { return data_; } void Draw(QCustomPlot* plot) override; @@ -43,22 +55,18 @@ class TrappyLine : public Drawable { */ QCPGraph* GetGraphPtr() const { return graph_; } - private: - /** - * @brief обновляет объекты в приватном поле lib::TrappyLine - * @param targets: объекты - контр. точки - */ - void UpdateData(std::initializer_list targets); + const std::pair& GetTargetsPlottableIndexes() const { + return targets_ides_; + } - /** - * @brief добавляет объекты в приватное поле lib::TrappyLine - * @param targets: объекты - контр. точки - */ - void AddData(std::initializer_list targets); + private: + void UpdateData(gui::Target* first_target, gui::Target* second_target); + void UpdateData(std::pair targets); lib::TrappyLine data_; size_t plottable_index_{ULLONG_MAX}; QCPGraph* graph_{nullptr}; + std::pair targets_ides_; }; } // namespace gui diff --git a/lib/hill.h b/lib/hill.h index e2582e4..5c9be7e 100644 --- a/lib/hill.h +++ b/lib/hill.h @@ -46,7 +46,8 @@ class Hill : public JSONable { Point GetCenter() const; double GetRadius() const; - std::vector GetPoints() const { return vertices_; } + const std::vector& GetPoints() const { return vertices_; } + std::vector& GetPoints() { return vertices_; } private: std::vector vertices_; diff --git a/lib/trappy_line.cpp b/lib/trappy_line.cpp index 37aa80b..1bccef2 100644 --- a/lib/trappy_line.cpp +++ b/lib/trappy_line.cpp @@ -4,35 +4,6 @@ namespace lib { -TrappyLine::TrappyLine(std::initializer_list targets) - : targets_{targets} { - if (targets.size() < 2) - throw std::invalid_argument( - "trappy line should be line with at least 2 targets"); -} - -TrappyLine::TrappyLine(std::vector targets) : targets_{targets} { - if (targets.size() < 2) - throw std::invalid_argument( - "trappy line should be line with at least 2 targets"); -} - -void TrappyLine::SetNewTargets(std::initializer_list targets) { - if (targets.size() < 2) - throw std::invalid_argument( - "trappy line should be line with at least 2 targets"); - - targets_ = targets; -} - -void TrappyLine::SetNewTargets(std::vector targets) { - if (targets.size() < 2) - throw std::invalid_argument( - "trappy line should be line with at least 2 targets"); - - targets_ = targets; -} - QJsonObject TrappyLine::Load(int id) const { QVariantMap trappy_line_map; QVariantMap p1_map; @@ -40,10 +11,10 @@ QJsonObject TrappyLine::Load(int id) const { trappy_line_map.insert("Id", id); - p1_map.insert("X", targets_[0].GetPoint().x); - p1_map.insert("Y", targets_[0].GetPoint().y); - p2_map.insert("X", targets_[1].GetPoint().x); - p2_map.insert("Y", targets_[1].GetPoint().y); + p1_map.insert("X", targets_.first->GetPoint().x); + p1_map.insert("Y", targets_.first->GetPoint().y); + p2_map.insert("X", targets_.second->GetPoint().x); + p2_map.insert("Y", targets_.second->GetPoint().y); trappy_line_map.insert("P1", p1_map); trappy_line_map.insert("P2", p2_map); @@ -64,7 +35,7 @@ void TrappyLine::Save(const QJsonObject& trappy_line_obj) { if (!(p2.contains("X") && p2.contains("Y"))) throw std::invalid_argument(""); double x2 = p2.value("X").toDouble(); double y2 = p2.value("Y").toDouble(); - SetNewTargets({{x1, y1}, {x2, y2}}); + SetTargets({new Target(x1, y1), new Target(x2, y2)}); } bool TrappyLine::IsChanged(const QJsonObject& trappy_line_obj) const { @@ -72,19 +43,7 @@ bool TrappyLine::IsChanged(const QJsonObject& trappy_line_obj) const { QJsonObject p2_obj = trappy_line_obj.value("P2").toObject(); Point p1 = {p1_obj.value("X").toDouble(), p1_obj.value("Y").toDouble()}; Point p2 = {p2_obj.value("X").toDouble(), p2_obj.value("Y").toDouble()}; - return p1 != targets_[0].GetPoint() || p2 != targets_[1].GetPoint(); -} - -void TrappyLine::AddTargets(std::initializer_list targets) { - for (const auto& target : targets) { - targets_.push_back(target); - } -} - -void TrappyLine::AddTargets(std::vector targets) { - for (const auto& target : targets) { - targets_.push_back(target); - } + return p1 != targets_.first->GetPoint() || p2 != targets_.second->GetPoint(); } } // namespace lib diff --git a/lib/trappy_line.h b/lib/trappy_line.h index 09b51b1..3e777fe 100644 --- a/lib/trappy_line.h +++ b/lib/trappy_line.h @@ -13,19 +13,9 @@ class TrappyLine : public JSONable { public: TrappyLine() = default; - /** - * @brief инициализирует новый экземпляр Trappy Line - * (конструктор исключительно по КТ, только между ними может быть перелет) - * @param targets: лист контрольных точек - */ - TrappyLine(std::initializer_list targets); - - /** - * @brief инициализирует новый экземпляр Trappy Line - * (конструктор исключительно по КТ, только между ними может быть перелет) - * @param targets: вектор контрольных точек - */ - TrappyLine(std::vector targets); + TrappyLine(Target* first_target, Target* second_target) + : targets_{std::make_pair(first_target, second_target)} {} + TrappyLine(std::pair targets) : targets_{targets} {} TrappyLine(const TrappyLine&) = default; TrappyLine(TrappyLine&&) = default; @@ -37,17 +27,17 @@ class TrappyLine : public JSONable { void Save(const QJsonObject& trappy_line_obj) override; bool IsChanged(const QJsonObject& trappy_line_obj) const override; - void SetNewTargets(std::initializer_list targets); + void SetTargets(Target* first_target, Target* second_target) { + targets_ = std::make_pair(first_target, second_target); + } + void SetTargets(std::pair targets) { targets_ = targets; } - void SetNewTargets(std::vector targets); - - void AddTargets(std::initializer_list targets); - void AddTargets(std::vector targets); - - std::vector GetTargets() const { return targets_; } + std::pair GetTargets() const { + return std::make_pair(*targets_.first, *targets_.second); + } private: - std::vector targets_; + std::pair targets_; }; } // namespace lib diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 66b10de..3091ea5 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -11,7 +11,7 @@ class GuiJsonFile { void Open(data_tools::DataManager* plot_area); QString GetFileName() const; - QString GetUntitledFile() const { return untitled_file_; } + const QString& GetUntitledFile() const { return untitled_file_; } void SetFile(const QString& file_name) { file_->setFileName(file_name); } void ChangeUntitled(const QString& old_untitled); diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index f37d91a..76388ed 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -24,7 +24,7 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { manager_->Add(t1); manager_->Add(t2); - manager_->Add(gui::TrappyLine({t1, t2})); + manager_->Add(gui::TrappyLine(&t1, &t2)); area_->Redraw(); } From 0e15f00e6909c0ca54106f867c831bce47b94363 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:18:35 +0300 Subject: [PATCH 23/28] fix bug and make redraw button useless # bug with not updating tables after creating new file # now tables do redraw by every change --- data_tools/data_manager/data_manager.cpp | 5 ----- data_tools/data_manager/data_manager.h | 10 ---------- data_tools/plot_area/plot_area.cpp | 6 +----- data_tools/plot_area/plot_area.h | 19 +------------------ .../tables_connection/tables_connection.cpp | 16 ++++++++++++---- .../tables_connection/tables_connection.h | 8 -------- main/mainwindow.cpp | 5 +---- main/mainwindow.h | 2 ++ main/mainwindow_connections.cpp | 15 ++++++++++++++- 9 files changed, 31 insertions(+), 55 deletions(-) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index d2b6d00..410791e 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -4,11 +4,6 @@ namespace data_tools { -void DataManager::Setup(PlotArea* area, TablesConnection* t_connection) { - area_.reset(area); - t_connection_.reset(t_connection); -} - void DataManager::Draw(gui::ObjectType obj_type, size_t index, QCustomPlot* plot) { switch (obj_type) { diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index afdb3df..301f59b 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -1,7 +1,5 @@ #pragma once -#include "data_tools/plot_area/plot_area.h" -#include "data_tools/tables_connection/tables_connection.h" #include "gui/hill.h" #include "gui/target.h" #include "gui/trappy_circle.h" @@ -9,16 +7,11 @@ namespace data_tools { -class PlotArea; -class TablesConnection; - // @brief класс, хранящий gui объекты и связывающий их с QCustomPlot class DataManager { public: DataManager() = default; - void Setup(PlotArea* area, TablesConnection* t_connection); - // methods /** @@ -169,9 +162,6 @@ class DataManager { std::vector targets_; std::vector tr_circles_; std::vector tr_lines_; - - std::unique_ptr area_; - std::unique_ptr t_connection_; }; } // namespace data_tools diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index 54b8be5..f9a304d 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -4,10 +4,7 @@ namespace data_tools { -void PlotArea::Setup(DataManager* manager, TablesConnection* t_connection) { - manager_.reset(manager); - t_connection_.reset(t_connection); -} +void PlotArea::Setup(DataManager* manager) { manager_.reset(manager); } void PlotArea::Redraw() { plot_->clearPlottables(); @@ -25,7 +22,6 @@ void PlotArea::Redraw() { for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) manager_->Draw(gui::ObjectType::TrappyLines, i, plot_.get()); - t_connection_->UpdateTables(); plot_->replot(); } diff --git a/data_tools/plot_area/plot_area.h b/data_tools/plot_area/plot_area.h index 4f628c4..e11f9bc 100644 --- a/data_tools/plot_area/plot_area.h +++ b/data_tools/plot_area/plot_area.h @@ -3,17 +3,9 @@ #include #include "data_tools/data_manager/data_manager.h" -#include "data_tools/tables_connection/tables_connection.h" -#include "gui/hill.h" -#include "gui/target.h" -#include "gui/trappy_circle.h" -#include "gui/trappy_line.h" namespace data_tools { -class TablesConnection; -class DataManager; - /// @brief класс, упрощающий управление классами gui на QCustomPlot class PlotArea { public: @@ -21,9 +13,7 @@ class PlotArea { PlotArea(QCustomPlot* plot) : plot_{plot} {} - void Setup(DataManager* manager, TablesConnection* t_connection); - - // methods + void Setup(DataManager* manager); /** * @brief устанавливает значение plot @@ -34,18 +24,11 @@ class PlotArea { /// @brief перерисовывает на полотне все объекты и обновляет данные void Redraw(); - // ~methods - private: - // vars - // i love unique_ptr's, i love logic schemes std::unique_ptr plot_; std::unique_ptr manager_; - std::unique_ptr t_connection_; - - // ~vars }; } // namespace data_tools diff --git a/data_tools/tables_connection/tables_connection.cpp b/data_tools/tables_connection/tables_connection.cpp index 6e3ec03..a1b47a4 100644 --- a/data_tools/tables_connection/tables_connection.cpp +++ b/data_tools/tables_connection/tables_connection.cpp @@ -39,6 +39,8 @@ void TablesConnection::UpdateTable(const std::vector& targets) { targets_table_->setItem(2, i, item); } targets_table_->update(); + } else { + targets_table_->setColumnCount(0); } } @@ -94,6 +96,8 @@ void TablesConnection::UpdateTable(const std::vector& hills) { } } hills_table_->update(); + } else { + hills_table_->setColumnCount(0); } } @@ -143,6 +147,8 @@ void TablesConnection::UpdateTable( tr_lines_table_->setItem(4, i, item); } tr_lines_table_->update(); + } else { + tr_lines_table_->setColumnCount(0); } } @@ -185,6 +191,8 @@ void TablesConnection::UpdateTable( tr_circles_table_->setItem(3, i, item); } tr_circles_table_->update(); + } else { + tr_circles_table_->setColumnCount(0); } } @@ -204,13 +212,13 @@ void TablesConnection::TargetsItemChanged(int row, int column) { manager_->GetTargets()[column].SetPoint(x_item->text().toDouble(), y_item->text().toDouble()); - // area_->Redraw(); + area_->Redraw(); } } void TablesConnection::HillsItemChanged(int row, int column) { if (column < manager_->GetHills().size()) { - // area_->Redraw(); + area_->Redraw(); } } @@ -225,13 +233,13 @@ void TablesConnection::TrappyCirclesItemChanged(int row, int column) { {x_item->text().toDouble(), y_item->text().toDouble()}); manager_->GetTrappyCircles()[column].SetRadius(r_item->text().toDouble()); - // area_->Redraw(); + area_->Redraw(); } } void TablesConnection::TrappyLinesItemChanged(int row, int column) { if (column < manager_->GetTrappyLines().size()) { - // area_->Redraw(); + area_->Redraw(); } } diff --git a/data_tools/tables_connection/tables_connection.h b/data_tools/tables_connection/tables_connection.h index 184b290..bc1aefc 100644 --- a/data_tools/tables_connection/tables_connection.h +++ b/data_tools/tables_connection/tables_connection.h @@ -2,18 +2,10 @@ #include -#include "data_tools/data_manager/data_manager.h" #include "data_tools/plot_area/plot_area.h" -#include "gui/hill.h" -#include "gui/target.h" -#include "gui/trappy_circle.h" -#include "gui/trappy_line.h" namespace data_tools { -class PlotArea; -class DataManager; - /// @brief класс, упрощающий отображение классов gui в QTableWidget's class TablesConnection : public QObject { public: diff --git a/main/mainwindow.cpp b/main/mainwindow.cpp index 977204c..d07f367 100644 --- a/main/mainwindow.cpp +++ b/main/mainwindow.cpp @@ -17,9 +17,8 @@ MainWindow::MainWindow(QWidget* parent) connect(ui->plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(on_plot_MousePressed())); - area_->Setup(manager_.get(), t_connection_.get()); + area_->Setup(manager_.get()); t_connection_->Setup(manager_.get(), area_.get()); - manager_->Setup(area_.get(), t_connection_.get()); area_->SetPlot(ui->plot); @@ -28,8 +27,6 @@ MainWindow::MainWindow(QWidget* parent) t_connection_->SetSettingsTables( ui->targetInfoTableWidget, ui->hillInfoTableWidget, ui->trappyCircleInfoTableWidget, ui->trappyLineInfoTableWidget); - - area_->Redraw(); } MainWindow::~MainWindow() { delete ui; } diff --git a/main/mainwindow.h b/main/mainwindow.h index 49a4e00..1552481 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -6,7 +6,9 @@ #include "add_objects_forms/add_target_form.h" #include "add_objects_forms/add_trappy_circle_form.h" #include "add_objects_forms/add_trappy_line_form.h" +#include "data_tools/data_manager/data_manager.h" #include "data_tools/plot_area/plot_area.h" +#include "data_tools/tables_connection/tables_connection.h" #include "gui_json_file/gui_json_file.h" enum class FileType { UntitledFile, UsualFile }; diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index 76388ed..c02e5dc 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -2,16 +2,20 @@ // здесь описаны все соединения кнопок со слотами +#include + #include "./ui_mainwindow.h" void MainWindow::AddTarget(double x, double y) { manager_->Add(gui::Target(x, y)); area_->Redraw(); + t_connection_->UpdateTables(); } void MainWindow::AddTrappyCircle(double x, double y, double radius) { manager_->Add(gui::TrappyCircle(x, y, radius)); area_->Redraw(); + t_connection_->UpdateTables(); } void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { @@ -27,11 +31,13 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { manager_->Add(gui::TrappyLine(&t1, &t2)); area_->Redraw(); + t_connection_->UpdateTables(); } void MainWindow::AddHill(std::vector points) { manager_->Add(gui::Hill(points)); area_->Redraw(); + t_connection_->UpdateTables(); } void MainWindow::on_pushButtonAddTarget_clicked() { @@ -144,6 +150,7 @@ bool MainWindow::OpenMessageWindow(const FileType& file_type) { break; } } + return false; } @@ -181,10 +188,12 @@ void MainWindow::on_actionNew_triggered() { is_closed = OpenMessageWindow(FileType::UntitledFile); if (!is_closed) { + IC(); manager_->Clear(); json_file_.Clear(); area_->Redraw(); + t_connection_->UpdateTables(); } } @@ -209,6 +218,7 @@ void MainWindow::on_actionOpen_triggered() { try { json_file_.Open(manager_.get()); area_->Redraw(); + t_connection_->UpdateTables(); } catch (...) { QMessageBox::critical(this, "Damaged file", "Invalid format file!"); @@ -234,4 +244,7 @@ void MainWindow::on_actionSave_as_triggered() { json_file_.Save(manager_.get()); } -void MainWindow::on_redrawPushButton_clicked() { area_->Redraw(); } +void MainWindow::on_redrawPushButton_clicked() { + area_->Redraw(); + t_connection_->UpdateTables(); +} From b642f613d81d220603f6a7878c2b048d92e9b0da Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:29:08 +0300 Subject: [PATCH 24/28] remove redraw button --- main/mainwindow.h | 2 -- main/mainwindow.ui | 20 ++------------------ main/mainwindow_connections.cpp | 6 +----- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/main/mainwindow.h b/main/mainwindow.h index 1552481..1dc8b38 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -53,8 +53,6 @@ class MainWindow : public QMainWindow { void on_actionNew_triggered(); - void on_redrawPushButton_clicked(); - public slots: void AddTrappyCircle(double x, double y, double radius); void AddTarget(double x, double y); diff --git a/main/mainwindow.ui b/main/mainwindow.ui index 613535a..5e4be78 100644 --- a/main/mainwindow.ui +++ b/main/mainwindow.ui @@ -277,7 +277,7 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} 0 0 800 - 26 + 25 @@ -329,7 +329,7 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} 175 - 117 + 130 @@ -395,22 +395,6 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} 5 - - - - - 0 - 0 - - - - PointingHandCursor - - - Redraw - - - diff --git a/main/mainwindow_connections.cpp b/main/mainwindow_connections.cpp index c02e5dc..a12da7f 100644 --- a/main/mainwindow_connections.cpp +++ b/main/mainwindow_connections.cpp @@ -36,6 +36,7 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { void MainWindow::AddHill(std::vector points) { manager_->Add(gui::Hill(points)); + area_->Redraw(); t_connection_->UpdateTables(); } @@ -243,8 +244,3 @@ void MainWindow::on_actionSave_as_triggered() { json_file_.SetFile(file_name); json_file_.Save(manager_.get()); } - -void MainWindow::on_redrawPushButton_clicked() { - area_->Redraw(); - t_connection_->UpdateTables(); -} From 45da7dc2201b901ccf69f0c8606155dc176be017 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:55:22 +0300 Subject: [PATCH 25/28] add maybe useful methods to TrappyLine --- data_tools/data_manager/data_manager.h | 5 +---- gui/trappy_line.cpp | 6 ++++-- gui/trappy_line.h | 10 ++++++++-- lib/trappy_line.h | 2 ++ main/gui_json_file/gui_json_file.h | 2 ++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index 301f59b..f5c913f 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -12,8 +12,6 @@ class DataManager { public: DataManager() = default; - // methods - /** * @brief отрисовывает на полотне объект по индексу * @param obj_type: тип объекта @@ -155,9 +153,8 @@ class DataManager { return tr_lines_; } - // ~methods - private: + // TODO: переп. всё на указатели, чтобы исправить проблему c изменением копий std::vector hills_; std::vector targets_; std::vector tr_circles_; diff --git a/gui/trappy_line.cpp b/gui/trappy_line.cpp index 1184e37..fa7778e 100644 --- a/gui/trappy_line.cpp +++ b/gui/trappy_line.cpp @@ -28,8 +28,10 @@ void TrappyLine::Draw(QCustomPlot* plot) { void TrappyLine::UpdateData(gui::Target* first_target, gui::Target* second_target) { data_.SetTargets(&first_target->GetData(), &second_target->GetData()); - targets_ides_ = std::make_pair(first_target->GetPlottableIndex(), - second_target->GetPlottableIndex()); + targets_indexes_ = std::make_pair(first_target->GetPlottableIndex(), + second_target->GetPlottableIndex()); + targets_graphs_ = + std::make_pair(first_target->GetGraphPtr(), second_target->GetGraphPtr()); } void TrappyLine::UpdateData(std::pair targets) { diff --git a/gui/trappy_line.h b/gui/trappy_line.h index da6dad3..21dca97 100644 --- a/gui/trappy_line.h +++ b/gui/trappy_line.h @@ -56,7 +56,11 @@ class TrappyLine : public Drawable { QCPGraph* GetGraphPtr() const { return graph_; } const std::pair& GetTargetsPlottableIndexes() const { - return targets_ides_; + return targets_indexes_; + } + + const std::pair& GetTargetsGraphPtrs() const { + return targets_graphs_; } private: @@ -66,7 +70,9 @@ class TrappyLine : public Drawable { lib::TrappyLine data_; size_t plottable_index_{ULLONG_MAX}; QCPGraph* graph_{nullptr}; - std::pair targets_ides_; + + std::pair targets_indexes_; + std::pair targets_graphs_; }; } // namespace gui diff --git a/lib/trappy_line.h b/lib/trappy_line.h index 3e777fe..d4c73db 100644 --- a/lib/trappy_line.h +++ b/lib/trappy_line.h @@ -36,6 +36,8 @@ class TrappyLine : public JSONable { return std::make_pair(*targets_.first, *targets_.second); } + std::pair& GetTargetsPtrs() { return targets_; } + private: std::pair targets_; }; diff --git a/main/gui_json_file/gui_json_file.h b/main/gui_json_file/gui_json_file.h index 3091ea5..d868d71 100644 --- a/main/gui_json_file/gui_json_file.h +++ b/main/gui_json_file/gui_json_file.h @@ -2,6 +2,8 @@ #include "data_tools/plot_area/plot_area.h" +// TODO: исправить добавление TrappyLines вместо точек на Targets id + class GuiJsonFile { public: GuiJsonFile() = default; From 980c89a4d5d29cac7bac4015034b0024bd47708c Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 18:40:37 +0300 Subject: [PATCH 26/28] fix precision (tolerance) in tests --- tests/lib/hill_test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/lib/hill_test.cpp b/tests/lib/hill_test.cpp index 483ff17..5c944c0 100644 --- a/tests/lib/hill_test.cpp +++ b/tests/lib/hill_test.cpp @@ -13,7 +13,7 @@ namespace tt = boost::test_tools; namespace utf = boost::unit_test; using namespace lib; -BOOST_AUTO_TEST_SUITE(lib_hill) +BOOST_AUTO_TEST_SUITE(lib_hill, *utf::tolerance(1.0E-7)) struct { double x, y, r; @@ -25,9 +25,9 @@ struct { BOOST_AUTO_TEST_CASE(simple_regular_construct) { for (auto c : cases) { Hill h(lib::Point(c.x, c.y), c.r, c.v_a); - BOOST_TEST(std::abs(h.GetCenter().x - c.x) < 1.0E-7); // приближенно равны - BOOST_TEST(std::abs(h.GetCenter().y - c.y) < 1.0E-7); // приближенно равны - BOOST_TEST(std::abs(h.GetRadius() - c.r) < 1.0E-7); // приближенно равны + BOOST_TEST(h.GetCenter().x == c.x); + BOOST_TEST(h.GetCenter().y == c.y); + BOOST_TEST(h.GetRadius() == c.r); BOOST_TEST(h.GetPoints().size() == c.v_a); } @@ -50,9 +50,9 @@ BOOST_AUTO_TEST_CASE(random_regular_construct) { Hill h(lib::Point(x, y), r, v_a); - BOOST_TEST(std::abs(h.GetCenter().x - x) < 1.0E-7); // приближенно равны - BOOST_TEST(std::abs(h.GetCenter().y - y) < 1.0E-7); // приближенно равны - BOOST_TEST(std::abs(h.GetRadius() - r) < 1.0E-7); // приближенно равны + BOOST_TEST(h.GetCenter().x == x); + BOOST_TEST(h.GetCenter().y == y); + BOOST_TEST(h.GetRadius() == r); BOOST_TEST(h.GetPoints().size() == v_a); } } From 6a6e775366442d0d5586f98478468069cf73e1cf Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 19:25:30 +0300 Subject: [PATCH 27/28] remove Draw from DataManager (logically) --- data_tools/data_manager/data_manager.cpp | 25 ------------------------ data_tools/data_manager/data_manager.h | 8 -------- data_tools/plot_area/plot_area.cpp | 13 +++++------- 3 files changed, 5 insertions(+), 41 deletions(-) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index 410791e..8aeaa42 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -4,31 +4,6 @@ namespace data_tools { -void DataManager::Draw(gui::ObjectType obj_type, size_t index, - QCustomPlot* plot) { - switch (obj_type) { - case gui::ObjectType::Targets: { - targets_[index].Draw(plot); - break; - } - - case gui::ObjectType::Hills: { - hills_[index].Draw(plot); - break; - } - - case gui::ObjectType::TrappyCircles: { - tr_circles_[index].Draw(plot); - break; - } - - case gui::ObjectType::TrappyLines: { - tr_lines_[index].Draw(plot); - break; - } - } -} - void DataManager::Clear() { targets_.clear(); tr_circles_.clear(); diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index f5c913f..b8aaf72 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -12,14 +12,6 @@ class DataManager { public: DataManager() = default; - /** - * @brief отрисовывает на полотне объект по индексу - * @param obj_type: тип объекта - * @param index: индекс объекта в его векторе - * @param plot: указатель на полотно - */ - void Draw(gui::ObjectType obj_type, size_t index, QCustomPlot* plot); - /// @brief очищает все вектора объектов void Clear(); diff --git a/data_tools/plot_area/plot_area.cpp b/data_tools/plot_area/plot_area.cpp index f9a304d..a8a470e 100644 --- a/data_tools/plot_area/plot_area.cpp +++ b/data_tools/plot_area/plot_area.cpp @@ -10,17 +10,14 @@ void PlotArea::Redraw() { plot_->clearPlottables(); plot_->clearItems(); - for (size_t i = 0; i < manager_->GetTargets().size(); i++) - manager_->Draw(gui::ObjectType::Targets, i, plot_.get()); + for (auto& target : manager_->GetTargets()) target.Draw(plot_.get()); - for (size_t i = 0; i < manager_->GetHills().size(); i++) - manager_->Draw(gui::ObjectType::Hills, i, plot_.get()); + for (auto& hill : manager_->GetHills()) hill.Draw(plot_.get()); - for (size_t i = 0; i < manager_->GetTrappyCircles().size(); i++) - manager_->Draw(gui::ObjectType::TrappyCircles, i, plot_.get()); + for (auto& tr_circle : manager_->GetTrappyCircles()) + tr_circle.Draw(plot_.get()); - for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) - manager_->Draw(gui::ObjectType::TrappyLines, i, plot_.get()); + for (auto& tr_line : manager_->GetTrappyLines()) tr_line.Draw(plot_.get()); plot_->replot(); } From 5338bc53e3af09a5872972a82b538b79d1e3f0c3 Mon Sep 17 00:00:00 2001 From: Dmitry Krivoruchko <144147209+UmbrellaLeaf5@users.noreply.github.com> Date: Sun, 14 Apr 2024 19:31:03 +0300 Subject: [PATCH 28/28] THE RETURN OF REMOVE # this commit sounds like film name, doesn't it?) # this method unused in PlotArea but needed in DataManager --- data_tools/data_manager/data_manager.cpp | 24 ++++++++++++++++++++++++ data_tools/data_manager/data_manager.h | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/data_tools/data_manager/data_manager.cpp b/data_tools/data_manager/data_manager.cpp index 8aeaa42..fe5e832 100644 --- a/data_tools/data_manager/data_manager.cpp +++ b/data_tools/data_manager/data_manager.cpp @@ -4,6 +4,30 @@ namespace data_tools { +void DataManager::Remove(gui::ObjectType obj_type, size_t index) { + switch (obj_type) { + case gui::ObjectType::Targets: { + targets_.erase(targets_.begin() + index); + break; + } + + case gui::ObjectType::Hills: { + hills_.erase(hills_.begin() + index); + break; + } + + case gui::ObjectType::TrappyCircles: { + tr_circles_.erase(tr_circles_.begin() + index); + break; + } + + case gui::ObjectType::TrappyLines: { + tr_lines_.erase(tr_lines_.begin() + index); + break; + } + } +} + void DataManager::Clear() { targets_.clear(); tr_circles_.clear(); diff --git a/data_tools/data_manager/data_manager.h b/data_tools/data_manager/data_manager.h index b8aaf72..5e8db18 100644 --- a/data_tools/data_manager/data_manager.h +++ b/data_tools/data_manager/data_manager.h @@ -12,6 +12,13 @@ class DataManager { public: DataManager() = default; + /** + * @brief удаляет объект из менеджера по индексу + * @param obj_type: тип объекта + * @param index: индекс объекта в его векторе + */ + void Remove(gui::ObjectType obj_type, size_t index); + /// @brief очищает все вектора объектов void Clear();