From 540ca87398bfadad80d11293f8b04a74ceb80e59 Mon Sep 17 00:00:00 2001 From: MrWh1teF0x <142975991+MrWh1teF0x@users.noreply.github.com> Date: Tue, 30 Apr 2024 20:05:21 +0300 Subject: [PATCH 1/2] add check that the entered values are valid --- main/add_objects_forms/add_hill_form.cpp | 8 ++- main/add_objects_forms/add_hill_form.h | 2 +- main/add_objects_forms/add_target_form.cpp | 4 +- main/add_objects_forms/add_target_form.h | 2 +- .../add_trappy_circle_form.cpp | 6 +- .../add_trappy_circle_form.h | 2 +- .../add_trappy_line_form.cpp | 9 +-- main/add_objects_forms/add_trappy_line_form.h | 3 +- main/mainwindow.h | 9 +-- .../menu_add_actions.cpp | 72 ++++++++++++++++--- 10 files changed, 87 insertions(+), 30 deletions(-) diff --git a/main/add_objects_forms/add_hill_form.cpp b/main/add_objects_forms/add_hill_form.cpp index 9a3bd20..fafb810 100644 --- a/main/add_objects_forms/add_hill_form.cpp +++ b/main/add_objects_forms/add_hill_form.cpp @@ -13,11 +13,13 @@ AddHillForm::AddHillForm(QWidget* parent) AddHillForm::~AddHillForm() { delete ui; } void AddHillForm::on_createPushButton_clicked() { - std::vector points; + std::vector> points; for (size_t i = 0; i < both_coords_point_line_edits_.size(); i++) { points.push_back( - {both_coords_point_line_edits_[i].abscissa->displayText().toDouble(), - both_coords_point_line_edits_[i].ordinate->displayText().toDouble()}); + {both_coords_point_line_edits_[i].abscissa->displayText().toStdString(), + both_coords_point_line_edits_[i] + .ordinate->displayText() + .toStdString()}); } emit AddHill(points); close(); diff --git a/main/add_objects_forms/add_hill_form.h b/main/add_objects_forms/add_hill_form.h index 3d7b398..e75a44c 100644 --- a/main/add_objects_forms/add_hill_form.h +++ b/main/add_objects_forms/add_hill_form.h @@ -32,7 +32,7 @@ class AddHillForm : public QDialog { ~AddHillForm(); signals: - void AddHill(std::vector points); + void AddHill(std::vector> points); private slots: void on_createPushButton_clicked(); diff --git a/main/add_objects_forms/add_target_form.cpp b/main/add_objects_forms/add_target_form.cpp index 45e5780..0904c9a 100644 --- a/main/add_objects_forms/add_target_form.cpp +++ b/main/add_objects_forms/add_target_form.cpp @@ -15,8 +15,8 @@ void AddTargetForm::on_clearPushButton_clicked() { } void AddTargetForm::on_createPushButton_clicked() { - double x = (ui->abscissaLineEdit->displayText()).toDouble(); - double y = (ui->ordinateLineEdit->displayText()).toDouble(); + std::string x = ui->abscissaLineEdit->displayText().toStdString(); + std::string y = ui->ordinateLineEdit->displayText().toStdString(); emit AddTarget(x, y); close(); } diff --git a/main/add_objects_forms/add_target_form.h b/main/add_objects_forms/add_target_form.h index 36c1bbb..894113e 100644 --- a/main/add_objects_forms/add_target_form.h +++ b/main/add_objects_forms/add_target_form.h @@ -14,7 +14,7 @@ class AddTargetForm : public QDialog { ~AddTargetForm(); signals: - void AddTarget(double x, double y); + void AddTarget(std::string x, std::string y); private slots: void on_clearPushButton_clicked(); diff --git a/main/add_objects_forms/add_trappy_circle_form.cpp b/main/add_objects_forms/add_trappy_circle_form.cpp index fdd2a9e..77fcab3 100644 --- a/main/add_objects_forms/add_trappy_circle_form.cpp +++ b/main/add_objects_forms/add_trappy_circle_form.cpp @@ -16,9 +16,9 @@ void AddTrappyCircleForm::on_clearPushButton_clicked() { } void AddTrappyCircleForm::on_createPushButton_clicked() { - double x = (ui->abscissaLineEdit->displayText()).toDouble(); - double y = (ui->ordinateLineEdit->displayText()).toDouble(); - double radius = (ui->radiusLineEdit->displayText()).toDouble(); + std::string x = ui->abscissaLineEdit->displayText().toStdString(); + std::string y = ui->ordinateLineEdit->displayText().toStdString(); + std::string radius = ui->radiusLineEdit->displayText().toStdString(); emit AddTrappyCircle(x, y, radius); close(); diff --git a/main/add_objects_forms/add_trappy_circle_form.h b/main/add_objects_forms/add_trappy_circle_form.h index ee5af7e..ff68537 100644 --- a/main/add_objects_forms/add_trappy_circle_form.h +++ b/main/add_objects_forms/add_trappy_circle_form.h @@ -14,7 +14,7 @@ class AddTrappyCircleForm : public QDialog { ~AddTrappyCircleForm(); signals: - void AddTrappyCircle(double x, double y, double radius); + void AddTrappyCircle(std::string x, std::string y, std::string radius); private slots: void on_clearPushButton_clicked(); diff --git a/main/add_objects_forms/add_trappy_line_form.cpp b/main/add_objects_forms/add_trappy_line_form.cpp index a9f8567..4a78459 100644 --- a/main/add_objects_forms/add_trappy_line_form.cpp +++ b/main/add_objects_forms/add_trappy_line_form.cpp @@ -17,10 +17,11 @@ void AddTrappyLineForm::on_clearPushButton_clicked() { } void AddTrappyLineForm::on_createPushButton_clicked() { - double x1 = (ui->firstPointAbscissaLineEdit->displayText()).toDouble(); - double y1 = (ui->firstPointOrdinateLineEdit->displayText()).toDouble(); - double x2 = (ui->secondPointAbscissaLineEdit->displayText()).toDouble(); - double y2 = (ui->secondPointOrdinateLineEdit->displayText()).toDouble(); + std::string x1 = ui->firstPointAbscissaLineEdit->displayText().toStdString(); + std::string y1 = ui->firstPointOrdinateLineEdit->displayText().toStdString(); + std::string x2 = ui->secondPointAbscissaLineEdit->displayText().toStdString(); + std::string y2 = ui->secondPointOrdinateLineEdit->displayText().toStdString(); + emit AddTrappyLine(x1, y1, x2, y2); close(); } diff --git a/main/add_objects_forms/add_trappy_line_form.h b/main/add_objects_forms/add_trappy_line_form.h index 4560de3..f6f3124 100644 --- a/main/add_objects_forms/add_trappy_line_form.h +++ b/main/add_objects_forms/add_trappy_line_form.h @@ -14,7 +14,8 @@ class AddTrappyLineForm : public QDialog { ~AddTrappyLineForm(); signals: - void AddTrappyLine(double x1, double y1, double x2, double y2); + void AddTrappyLine(std::string x1, std::string y1, std::string x2, + std::string y2); private slots: void on_clearPushButton_clicked(); diff --git a/main/mainwindow.h b/main/mainwindow.h index 2c31970..7ac0300 100644 --- a/main/mainwindow.h +++ b/main/mainwindow.h @@ -87,10 +87,11 @@ class MainWindow : public QMainWindow { void on_pushButtonEditObjects_clicked(); public slots: - void AddTrappyCircle(double x, double y, double radius); - void AddTarget(double x, double y); - void AddTrappyLine(double x1, double y1, double x2, double y2); - void AddHill(std::vector points); + void AddTrappyCircle(std::string x, std::string y, std::string radius); + void AddTarget(std::string x, std::string y); + void AddTrappyLine(std::string x1, std::string y1, std::string x2, + std::string y2); + void AddHill(std::vector> points); private: std::unique_ptr area_; diff --git a/main/mainwindow_connections/menu_add_actions.cpp b/main/mainwindow_connections/menu_add_actions.cpp index 641199d..afbd94b 100644 --- a/main/mainwindow_connections/menu_add_actions.cpp +++ b/main/mainwindow_connections/menu_add_actions.cpp @@ -1,8 +1,46 @@ #include "main/mainwindow.h" -void MainWindow::AddTarget(double x, double y) { +void ChecksValues(std::vector values) { + for (const auto& value : values) { + bool is_dot = false; + if (value.empty()) throw std::invalid_argument("The number is empty!"); + for (size_t i = 0; i < value.size(); i++) { + switch (value[i]) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + break; + case '-': + if (i > 0) + throw std::invalid_argument( + "A minus can only be at the beginning of a number!"); + break; + case '.': + if (is_dot) + throw std::invalid_argument("A number can't have a second point!"); + else if (i == 0 || value[i - 1] == '-') + throw std::invalid_argument("A number can't starts with a point!"); + is_dot = true; + break; + default: + throw std::invalid_argument("Incorrect number!"); + } + } + } +} + +void MainWindow::AddTarget(std::string x, std::string y) { try { - manager_->Add(new gui::Target(x, y)); + ChecksValues({x, y}); + + manager_->Add(new gui::Target(std::stod(x), std::stod(y))); area_->Redraw(); t_connection_->UpdateTables(); @@ -11,9 +49,13 @@ void MainWindow::AddTarget(double x, double y) { } } -void MainWindow::AddTrappyCircle(double x, double y, double radius) { +void MainWindow::AddTrappyCircle(std::string x, std::string y, + std::string radius) { try { - manager_->Add(new gui::TrappyCircle(x, y, radius)); + ChecksValues({x, y, radius}); + + manager_->Add( + new gui::TrappyCircle(std::stod(x), std::stod(y), std::stod(radius))); area_->Redraw(); t_connection_->UpdateTables(); @@ -22,10 +64,13 @@ void MainWindow::AddTrappyCircle(double x, double y, double radius) { } } -void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { +void MainWindow::AddTrappyLine(std::string x1, std::string y1, std::string x2, + std::string y2) { try { - manager_->Add(new gui::Target(x1, y1)); - manager_->Add(new gui::Target(x2, y2)); + ChecksValues({x1, y1, x2, y2}); + + manager_->Add(new gui::Target(std::stod(x1), std::stod(y1))); + manager_->Add(new gui::Target(std::stod(x2), std::stod(y2))); manager_->Add(new gui::TrappyLine( manager_->GetTargetsPtrs()[manager_->GetTargets().size() - 2], @@ -39,9 +84,16 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) { } } -void MainWindow::AddHill(std::vector points) { +void MainWindow::AddHill( + std::vector> points) { try { - manager_->Add(new gui::Hill(points)); + std::vector lib_points; + for (const auto& point : points) { + ChecksValues({point.first, point.second}); + lib_points.push_back({std::stod(point.first), std::stod(point.second)}); + } + + manager_->Add(new gui::Hill(lib_points)); area_->Redraw(); t_connection_->UpdateTables(); @@ -83,4 +135,4 @@ void MainWindow::on_actionHill_triggered() { AddHillForm* adh = new AddHillForm; adh->show(); connect(adh, &AddHillForm::AddHill, this, &MainWindow::AddHill); -} \ No newline at end of file +} From 6100681495fe927be684fc25b74c90baa495dea2 Mon Sep 17 00:00:00 2001 From: MrWh1teF0x <142975991+MrWh1teF0x@users.noreply.github.com> Date: Tue, 30 Apr 2024 20:06:59 +0300 Subject: [PATCH 2/2] add delete button to "AddHill" menu button --- main/add_objects_forms/add_hill_form.cpp | 10 +++++++++ main/add_objects_forms/add_hill_form.h | 1 + main/add_objects_forms/add_hill_form.ui | 26 +++++++++++++++++------- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/main/add_objects_forms/add_hill_form.cpp b/main/add_objects_forms/add_hill_form.cpp index fafb810..a159536 100644 --- a/main/add_objects_forms/add_hill_form.cpp +++ b/main/add_objects_forms/add_hill_form.cpp @@ -87,3 +87,13 @@ void AddHillForm::AddNewInputFields(size_t amount) { PointLineEdits(abscissa_line_edit, ordinate_line_edit)); } } + +void AddHillForm::on_deletePushButton_clicked() { + if (both_coords_point_line_edits_.size() > 3) { + both_coords_point_line_edits_.erase(both_coords_point_line_edits_.begin() + + both_coords_point_line_edits_.size() - + 1); + point_layouts_widgets_.erase(point_layouts_widgets_.begin() + + point_layouts_widgets_.size() - 1); + } +} diff --git a/main/add_objects_forms/add_hill_form.h b/main/add_objects_forms/add_hill_form.h index e75a44c..589f80f 100644 --- a/main/add_objects_forms/add_hill_form.h +++ b/main/add_objects_forms/add_hill_form.h @@ -38,6 +38,7 @@ class AddHillForm : public QDialog { void on_createPushButton_clicked(); void on_clearPushButton_clicked(); void on_newPushButton_clicked(); + void on_deletePushButton_clicked(); private: /** diff --git a/main/add_objects_forms/add_hill_form.ui b/main/add_objects_forms/add_hill_form.ui index 3ffdbe7..fd26d36 100644 --- a/main/add_objects_forms/add_hill_form.ui +++ b/main/add_objects_forms/add_hill_form.ui @@ -6,7 +6,7 @@ 0 0 - 280 + 420 310 @@ -24,7 +24,7 @@ - 280 + 500 310 @@ -44,10 +44,10 @@ - 0 + 10 0 - 280 - 310 + 401 + 311 @@ -64,8 +64,8 @@ 0 0 - 278 - 308 + 399 + 309 @@ -111,6 +111,18 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);} + + + + QPushButton::hover{background-color: rgb(184, 184, 184);border: 1px solid #6f6f6f;} +QPushButton::pressed{background-color: rgb(135, 135, 135);} + + + + Delete point + + +