Skip to content

Commit

Permalink
Merge pull request #52 from UmbrellaLeaf5/gui_coding
Browse files Browse the repository at this point in the history
gui complete tables
  • Loading branch information
MrWh1teF0x authored Apr 20, 2024
2 parents f312e0e + d9dc350 commit 9bdd27d
Show file tree
Hide file tree
Showing 12 changed files with 700 additions and 257 deletions.
87 changes: 85 additions & 2 deletions data_tools/tables_connection/tables_connection.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "tables_connection.h"

#include <icecream.hpp>

namespace data_tools {

void TablesConnection::Setup(DataManager* manager, PlotArea* area) {
manager_.reset(manager);
area_.reset(area);
}

// MARK: U.T. by Targets

void TablesConnection::UpdateTable(const std::vector<gui::Target>& targets) {
if (!targets.empty()) {
// кол-во столбцов = кол-во к.т.
Expand Down Expand Up @@ -45,6 +45,8 @@ void TablesConnection::UpdateTable(const std::vector<gui::Target>& targets) {
}
}

// MARK: U.T. by Hills

void TablesConnection::UpdateTable(const std::vector<gui::Hill>& hills) {
if (!hills.empty()) {
// находим максимально возможное кол-во точек среди всех холмов
Expand Down Expand Up @@ -103,6 +105,8 @@ void TablesConnection::UpdateTable(const std::vector<gui::Hill>& hills) {
}
}

// MARK: U.T. by Tr. Lines

void TablesConnection::UpdateTable(
const std::vector<gui::TrappyLine>& trappy_lines) {
if (!trappy_lines.empty()) {
Expand Down Expand Up @@ -154,6 +158,8 @@ void TablesConnection::UpdateTable(
}
}

// MARK: U.T. by Tr. Circles

void TablesConnection::UpdateTable(
const std::vector<gui::TrappyCircle>& trappy_circles) {
if (!trappy_circles.empty()) {
Expand Down Expand Up @@ -206,6 +212,8 @@ void TablesConnection::UpdateTables() {
UpdateTable(manager_->GetTrappyCircles());
}

// MARK: Targets Item C.

void TablesConnection::TargetsItemChanged(int row, int column) {
auto x_item = targets_table_->item(1, column);
auto y_item = targets_table_->item(2, column);
Expand All @@ -219,6 +227,8 @@ void TablesConnection::TargetsItemChanged(int row, int column) {
}
}

// MARK: Hills Item C.

void TablesConnection::HillsItemChanged(int row, int column) {
auto x_item = hills_table_->item(row, column);
auto y_item = hills_table_->item(row, column);
Expand Down Expand Up @@ -249,6 +259,8 @@ void TablesConnection::HillsItemChanged(int row, int column) {
}
}

// MARK: Tr. Circles Item C.

void TablesConnection::TrappyCirclesItemChanged(int row, int column) {
auto x_item = tr_circles_table_->item(1, column);
auto y_item = tr_circles_table_->item(2, column);
Expand All @@ -265,6 +277,8 @@ void TablesConnection::TrappyCirclesItemChanged(int row, int column) {
}
}

// MARK: Tr. Lines Item C.

void TablesConnection::TrappyLinesItemChanged(int row, int column) {
auto t_1_item = tr_lines_table_->item(1, column);
auto t_2_item = tr_lines_table_->item(2, column);
Expand All @@ -286,6 +300,34 @@ void TablesConnection::TrappyLinesItemChanged(int row, int column) {
}
}

// MARK: Remove Items

void TablesConnection::RemoveTargetItem() {
manager_->Remove(gui::ObjectType::Targets, selected_column_);
UpdateTable(manager_->GetTargets());
area_->Redraw();
}

void TablesConnection::RemoveHillItem() {
manager_->Remove(gui::ObjectType::Hills, selected_column_);
UpdateTable(manager_->GetHills());
area_->Redraw();
}

void TablesConnection::RemoveTrappyCircleItem() {
manager_->Remove(gui::ObjectType::TrappyCircles, selected_column_);
UpdateTable(manager_->GetTrappyCircles());
area_->Redraw();
}

void TablesConnection::RemoveTrappyLineItem() {
manager_->Remove(gui::ObjectType::TrappyLines, selected_column_);
UpdateTable(manager_->GetTrappyLines());
area_->Redraw();
}

// MARK: Update Connections

void TablesConnection::UpdateTablesConnections() {
{
QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this,
Expand All @@ -302,4 +344,45 @@ void TablesConnection::UpdateTablesConnections() {
}
}

void TablesConnection::UpdateRemoveButtonConnections() {
// активируем кнопки при выборе любой клетки
QObject::connect(targets_table_.get(), &QTableWidget::cellClicked, this,
&TablesConnection::EnableRemoveTargetButton);

QObject::connect(hills_table_.get(), &QTableWidget::cellClicked, this,
&TablesConnection::EnableRemoveHillButton);

QObject::connect(tr_lines_table_.get(), &QTableWidget::cellClicked, this,
&TablesConnection::EnableRemoveTrappyLineButton);

QObject::connect(tr_circles_table_.get(), &QTableWidget::cellClicked, this,
&TablesConnection::EnableRemoveTrappyCircleButton);

// деактивируем кнопки, если выбор изменился
QObject::connect(targets_table_.get(), &QTableWidget::itemSelectionChanged,
this, &TablesConnection::DisableRemoveTargetButton);

QObject::connect(hills_table_.get(), &QTableWidget::itemSelectionChanged,
this, &TablesConnection::DisableRemoveHillButton);

QObject::connect(tr_lines_table_.get(), &QTableWidget::itemSelectionChanged,
this, &TablesConnection::DisableRemoveTrappyLineButton);

QObject::connect(tr_circles_table_.get(), &QTableWidget::itemSelectionChanged,
this, &TablesConnection::DisableRemoveTrappyCircleButton);

// привязываем сами функции к сигналам
QObject::connect(targets_remove_button_.get(), &QPushButton::clicked, this,
&TablesConnection::RemoveTargetItem);

QObject::connect(hills_remove_button_.get(), &QPushButton::clicked, this,
&TablesConnection::RemoveHillItem);

QObject::connect(tr_circles_remove_button_.get(), &QPushButton::clicked, this,
&TablesConnection::RemoveTrappyCircleItem);

QObject::connect(tr_lines_remove_button_.get(), &QPushButton::clicked, this,
&TablesConnection::RemoveTrappyLineItem);
}

} // namespace data_tools
68 changes: 68 additions & 0 deletions data_tools/tables_connection/tables_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ class TablesConnection : public QObject {
UpdateTablesConnections();
}

/**
* @brief устанавливает значение всех кнопок для удаления объектов
* @param targets_remove_button
* @param hills_remove_button
* @param tr_circles_remove_button
* @param tr_lines_remove_button
*/
void SetRemoveButtons(QPushButton* targets_remove_button,
QPushButton* hills_remove_button,
QPushButton* tr_circles_remove_button,
QPushButton* tr_lines_remove_button) {
targets_remove_button_.reset(targets_remove_button);
hills_remove_button_.reset(hills_remove_button);
tr_circles_remove_button_.reset(tr_circles_remove_button);
tr_lines_remove_button_.reset(tr_lines_remove_button);
UpdateRemoveButtonConnections();
}

/// @brief Обновляет данные в таблицах всех объектов
void UpdateTables();

Expand Down Expand Up @@ -63,14 +81,64 @@ class TablesConnection : public QObject {
void TrappyCirclesItemChanged(int row, int column);
void TrappyLinesItemChanged(int row, int column);

void RemoveTargetItem();
void RemoveHillItem();
void RemoveTrappyCircleItem();
void RemoveTrappyLineItem();

void EnableRemoveTargetButton(int row, int column) {
Q_UNUSED(row);
selected_column_ = column;
targets_remove_button_->setEnabled(true);
}

void EnableRemoveHillButton(int row, int column) {
Q_UNUSED(row);
selected_column_ = column;
hills_remove_button_->setEnabled(true);
}

void EnableRemoveTrappyCircleButton(int row, int column) {
Q_UNUSED(row);
selected_column_ = column;
tr_circles_remove_button_->setEnabled(true);
}

void EnableRemoveTrappyLineButton(int row, int column) {
Q_UNUSED(row);
selected_column_ = column;
tr_lines_remove_button_->setEnabled(true);
}

void DisableRemoveTargetButton() {
targets_remove_button_->setEnabled(false);
}

void DisableRemoveHillButton() { hills_remove_button_->setEnabled(false); }

void DisableRemoveTrappyCircleButton() {
tr_circles_remove_button_->setEnabled(false);
}

void DisableRemoveTrappyLineButton() {
tr_lines_remove_button_->setEnabled(false);
}

private:
int selected_column_{INT_MAX};
void UpdateTablesConnections();
void UpdateRemoveButtonConnections();

std::unique_ptr<QTableWidget> targets_table_{nullptr};
std::unique_ptr<QTableWidget> hills_table_{nullptr};
std::unique_ptr<QTableWidget> tr_circles_table_{nullptr};
std::unique_ptr<QTableWidget> tr_lines_table_{nullptr};

std::unique_ptr<QPushButton> targets_remove_button_{nullptr};
std::unique_ptr<QPushButton> hills_remove_button_{nullptr};
std::unique_ptr<QPushButton> tr_circles_remove_button_{nullptr};
std::unique_ptr<QPushButton> tr_lines_remove_button_{nullptr};

std::unique_ptr<DataManager> manager_;
std::unique_ptr<PlotArea> area_;
};
Expand Down
4 changes: 2 additions & 2 deletions gui/hill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ void gui::Hill::Draw(QCustomPlot* plot) {
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;
Expand Down
4 changes: 2 additions & 2 deletions gui/trappy_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void TrappyLine::Draw(QCustomPlot* plot) {

auto targets = data_.GetTargets();

graph_->addData({targets.first.GetPoint().x}, {targets.first.GetPoint().y});
graph_->addData({targets.second.GetPoint().x}, {targets.second.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;
Expand Down
15 changes: 15 additions & 0 deletions main/add_objects_forms/add_hill_form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Create</string>
</property>
Expand All @@ -96,13 +101,23 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Clear all</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newPushButton">
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>New point</string>
</property>
Expand Down
10 changes: 10 additions & 0 deletions main/add_objects_forms/add_target_form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Create</string>
</property>
Expand All @@ -130,6 +135,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Clear all</string>
</property>
Expand Down
10 changes: 10 additions & 0 deletions main/add_objects_forms/add_trappy_circle_form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Create</string>
</property>
Expand All @@ -72,6 +77,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Clear all</string>
</property>
Expand Down
10 changes: 10 additions & 0 deletions main/add_objects_forms/add_trappy_line_form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Create</string>
</property>
Expand All @@ -72,6 +77,11 @@
<family>Segoe UI</family>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;}
QPushButton::pressed{background-color: rgb(135, 135, 135);}
</string>
</property>
<property name="text">
<string>Clear all</string>
</property>
Expand Down
Loading

0 comments on commit 9bdd27d

Please sign in to comment.