Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui fix #68

Merged
merged 7 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 91 additions & 19 deletions data_tools/tables_connection/tables_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void TablesConnection::Setup(DataManager* manager, PlotArea* area) {
// MARK: U.T. by Targets

void TablesConnection::UpdateTable(const std::vector<gui::Target>& targets) {
DisableTablesConnections();

if (targets.empty()) {
targets_table_->setColumnCount(0);
return;
Expand All @@ -27,7 +29,7 @@ void TablesConnection::UpdateTable(const std::vector<gui::Target>& targets) {
item); // номер к.т. = индекс + 1

// в строки добавляем индекс на полотне и координаты
item = new QTableWidgetItem(QString::number(targets[i].GetIndexOnPlot()));
item = new QTableWidgetItem(QString::number(targets[i].GetData().GetId()));
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved Hide resolved
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
targets_table_->setItem(0, static_cast<int>(i), item);

Expand All @@ -43,11 +45,14 @@ void TablesConnection::UpdateTable(const std::vector<gui::Target>& targets) {
}

targets_table_->update();
UpdateTablesConnections();
}

// MARK: U.T. by Hills

void TablesConnection::UpdateTable(const std::vector<gui::Hill>& hills) {
DisableTablesConnections();

if (hills.empty()) {
hills_table_->setColumnCount(0);
return;
Expand Down Expand Up @@ -75,7 +80,7 @@ void TablesConnection::UpdateTable(const std::vector<gui::Hill>& hills) {
item); // номер рельефа = индекс + 1

// в строки добавляем индекс на полотне и координаты всех точек
item = new QTableWidgetItem(QString::number(hills[i].GetIndexOnPlot()));
item = new QTableWidgetItem(QString::number(hills[i].GetData().GetId()));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
hills_table_->setItem(0, static_cast<int>(i), item);

Expand Down Expand Up @@ -104,12 +109,15 @@ void TablesConnection::UpdateTable(const std::vector<gui::Hill>& hills) {
}

hills_table_->update();
UpdateTablesConnections();
}

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

void TablesConnection::UpdateTable(
const std::vector<gui::TrappyLine>& trappy_lines) {
DisableTablesConnections();

if (trappy_lines.empty()) {
tr_lines_table_->setColumnCount(0);
return;
Expand All @@ -127,8 +135,8 @@ void TablesConnection::UpdateTable(
item); // номер линии = индекс + 1

// в строки добавляем индекс на полотне
item =
new QTableWidgetItem(QString::number(trappy_lines[i].GetIndexOnPlot()));
item = new QTableWidgetItem(
QString::number(trappy_lines[i].GetData().GetId()));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tr_lines_table_->setItem(0, static_cast<int>(i), item);

Expand All @@ -154,15 +162,27 @@ void TablesConnection::UpdateTable(
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable |
Qt::ItemIsEnabled);
tr_lines_table_->setItem(2, static_cast<int>(i), item);

// если эти номера остались огромными, то валидные к.т. не нашлись
if (t_1_n == ULLONG_MAX || t_2_n == ULLONG_MAX) {
QMessageBox::warning(targets_table_.get(), "Error!",
"Wrong targets numbers in TrappyLines!");

manager_->Remove(gui::ObjectType::TrappyLines, i);
area_->Redraw();
}
}

tr_lines_table_->update();
UpdateTablesConnections();
}

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

void TablesConnection::UpdateTable(
const std::vector<gui::TrappyCircle>& trappy_circles) {
DisableTablesConnections();

if (trappy_circles.empty()) {
tr_circles_table_->setColumnCount(0);
return;
Expand All @@ -181,7 +201,7 @@ void TablesConnection::UpdateTable(

// в строки добавляем индекс на полотне, координаты точки и радиус
item = new QTableWidgetItem(
QString::number(trappy_circles[i].GetIndexOnPlot()));
QString::number(trappy_circles[i].GetData().GetId()));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tr_circles_table_->setItem(0, static_cast<int>(i), item);

Expand All @@ -204,6 +224,27 @@ void TablesConnection::UpdateTable(
}

tr_circles_table_->update();
UpdateTablesConnections();
}

void TablesConnection::UpdateTable(gui::ObjectType obj_type) {
switch (obj_type) {
case gui::ObjectType::Targets:
UpdateTable(manager_->GetTargets());
break;

case gui::ObjectType::Hills:
UpdateTable(manager_->GetHills());
break;

case gui::ObjectType::TrappyCircles:
UpdateTable(manager_->GetTrappyCircles());
break;

case gui::ObjectType::TrappyLines:
UpdateTable(manager_->GetTrappyLines());
break;
}
}

void TablesConnection::UpdateTables() {
Expand Down Expand Up @@ -234,7 +275,10 @@ void TablesConnection::TargetsItemChanged(int row, int column) {

} catch (const std::exception& e) {
manager_->Remove(gui::ObjectType::Targets, static_cast<size_t>(column));
UpdateTables();
UpdateTable(gui::ObjectType::Targets);

// (в случае удаления к.т., которая была привязана, надо обновить)
UpdateTable(gui::ObjectType::TrappyLines);
area_->Redraw();

QMessageBox::critical(targets_table_.get(), "Error!", e.what());
Expand Down Expand Up @@ -277,7 +321,7 @@ void TablesConnection::HillsItemChanged(int row, int column) {

} catch (const std::exception& e) {
manager_->Remove(gui::ObjectType::Hills, static_cast<size_t>(column));
UpdateTables();
UpdateTable(gui::ObjectType::Hills);
area_->Redraw();

QMessageBox::critical(targets_table_.get(), "Error!", e.what());
Expand Down Expand Up @@ -307,7 +351,7 @@ void TablesConnection::TrappyCirclesItemChanged(int row, int column) {
} catch (const std::exception& e) {
manager_->Remove(gui::ObjectType::TrappyCircles,
static_cast<size_t>(column));
UpdateTables();
UpdateTable(gui::ObjectType::TrappyCircles);
area_->Redraw();

QMessageBox::critical(targets_table_.get(), "Error!", e.what());
Expand Down Expand Up @@ -343,7 +387,7 @@ void TablesConnection::TrappyLinesItemChanged(int row, int column) {

} catch (const std::exception& e) {
manager_->Remove(gui::ObjectType::TrappyLines, static_cast<size_t>(column));
UpdateTables();
UpdateTable(gui::ObjectType::TrappyLines);
area_->Redraw();

QMessageBox::warning(targets_table_.get(), "Error!", e.what());
Expand All @@ -353,46 +397,74 @@ void TablesConnection::TrappyLinesItemChanged(int row, int column) {
// MARK: Remove Items

void TablesConnection::RemoveTargetItem() {
DisableTablesConnections();

manager_->Remove(gui::ObjectType::Targets, selected_column_);
area_->Redraw();
UpdateTable(manager_->GetTargets());
UpdateTable(manager_->GetTrappyLines());

UpdateTablesConnections();
}

void TablesConnection::RemoveHillItem() {
DisableTablesConnections();

manager_->Remove(gui::ObjectType::Hills, selected_column_);
area_->Redraw();
UpdateTable(manager_->GetHills());

UpdateTablesConnections();
}

void TablesConnection::RemoveTrappyCircleItem() {
DisableTablesConnections();

manager_->Remove(gui::ObjectType::TrappyCircles, selected_column_);
area_->Redraw();
UpdateTable(manager_->GetTrappyCircles());

UpdateTablesConnections();
}

void TablesConnection::RemoveTrappyLineItem() {
DisableTablesConnections();

manager_->Remove(gui::ObjectType::TrappyLines, selected_column_);
area_->Redraw();
UpdateTable(manager_->GetTrappyLines());

UpdateTablesConnections();
}

// MARK: Update Connections

void TablesConnection::UpdateTablesConnections() {
{
QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TargetsItemChanged);
QObject::connect(targets_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TargetsItemChanged);

QObject::connect(hills_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::HillsItemChanged);
QObject::connect(hills_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::HillsItemChanged);

QObject::connect(tr_circles_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TrappyCirclesItemChanged);
QObject::connect(tr_circles_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TrappyCirclesItemChanged);

QObject::connect(tr_lines_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TrappyLinesItemChanged);
}
QObject::connect(tr_lines_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TrappyLinesItemChanged);
}

void TablesConnection::DisableTablesConnections() {
QObject::disconnect(targets_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TargetsItemChanged);

QObject::disconnect(hills_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::HillsItemChanged);

QObject::disconnect(tr_circles_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TrappyCirclesItemChanged);

QObject::disconnect(tr_lines_table_.get(), &QTableWidget::cellChanged, this,
&TablesConnection::TrappyLinesItemChanged);
}

void TablesConnection::UpdateRemoveButtonConnections() {
Expand Down
49 changes: 28 additions & 21 deletions data_tools/tables_connection/tables_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,10 @@ class TablesConnection : public QObject {
void UpdateTables();

/**
* @brief Обновляет значения таблицы с Targets
* @param targets: вектор новых значений
*/
void UpdateTable(const std::vector<gui::Target>& targets);

/**
* @brief Обновляет значения таблицы с Hills
* @param hills: вектор новых значений
* @brief Обновляет значения таблицы с определенным типом объекта
* @param obj_type: тип объекта
*/
void UpdateTable(const std::vector<gui::Hill>& hills);

/**
* @brief Обновляет значения таблицы с TrappyLines
* @param trappy_lines: вектор новых значений
*/
void UpdateTable(const std::vector<gui::TrappyLine>& trappy_lines);

/**
* @brief Обновляет значения таблицы с TrappyCircles
* @param trappy_circles: вектор новых значений
*/
void UpdateTable(const std::vector<gui::TrappyCircle>& trappy_circles);
void UpdateTable(gui::ObjectType obj_type);

private slots:
void TargetsItemChanged(int row, int column);
Expand Down Expand Up @@ -125,8 +107,33 @@ class TablesConnection : public QObject {
}

private:
/**
* @brief Обновляет значения таблицы с Targets
* @param targets: вектор новых значений
*/
void UpdateTable(const std::vector<gui::Target>& targets);

/**
* @brief Обновляет значения таблицы с Hills
* @param hills: вектор новых значений
*/
void UpdateTable(const std::vector<gui::Hill>& hills);

/**
* @brief Обновляет значения таблицы с TrappyLines
* @param trappy_lines: вектор новых значений
*/
void UpdateTable(const std::vector<gui::TrappyLine>& trappy_lines);

/**
* @brief Обновляет значения таблицы с TrappyCircles
* @param trappy_circles: вектор новых значений
*/
void UpdateTable(const std::vector<gui::TrappyCircle>& trappy_circles);

int selected_column_{INT_MAX};
void UpdateTablesConnections();
void DisableTablesConnections();
void UpdateRemoveButtonConnections();

std::unique_ptr<QTableWidget> targets_table_{nullptr};
Expand Down
2 changes: 1 addition & 1 deletion gui/airport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void gui::Airport::Draw(QCustomPlot* plot) {
Target::Draw(plot);
auto graph = plot->graph(static_cast<int>(Target::GetIndexOnPlot()));
auto graph = Target::GetGraphPtr();

graph->setPen(QColor(0, 0, 0, 255));
graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCrossCircle, 10));
Expand Down
11 changes: 0 additions & 11 deletions gui/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ class Drawable {
*/
virtual void Draw(QCustomPlot* plot) = 0;

/**
* @brief Возвращает индекс на полотне [plottable]
* @return size_t: индекс
*/
virtual size_t GetIndexOnPlot() const { return index_on_plot_; }

protected:
virtual void SetIndexOnPlot(QCustomPlot* plot) {
index_on_plot_ = plot->plottableCount() - 1;
}

private:
size_t index_on_plot_{ULLONG_MAX};
};
Expand Down
3 changes: 0 additions & 3 deletions gui/hill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ void gui::Hill::Draw(QCustomPlot* plot) {

// замыкаем, соединяя с первой точкой
curve_->addData(points[0].x, points[0].y);

// индекс последнего созданного = кол-во всех - 1
SetIndexOnPlot(plot);
}
3 changes: 0 additions & 3 deletions gui/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ void gui::Target::Draw(QCustomPlot* plot) {
graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4));

graph_->setData({GetPoint().x}, {GetPoint().y});

// индекс последнего созданного = кол-во всех - 1
SetIndexOnPlot(plot);
}
3 changes: 0 additions & 3 deletions gui/trappy_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ void gui::TrappyCircle::Draw(QCustomPlot* plot) {
GetCenter().y + GetRadius());
ellipse_->bottomRight->setCoords(GetCenter().x + GetRadius(),
GetCenter().y - GetRadius());

// индекс последнего созданного = кол-во всех - 1
SetIndexOnPlot(plot);
}
Loading