Skip to content

Commit

Permalink
Merge pull request #65 from UmbrellaLeaf5/update_adding_objects
Browse files Browse the repository at this point in the history
Update adding objects
  • Loading branch information
UmbrellaLeaf5 authored Apr 30, 2024
2 parents ccc66f2 + 6100681 commit ca19c12
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 37 deletions.
18 changes: 15 additions & 3 deletions main/add_objects_forms/add_hill_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ AddHillForm::AddHillForm(QWidget* parent)
AddHillForm::~AddHillForm() { delete ui; }

void AddHillForm::on_createPushButton_clicked() {
std::vector<lib::Point> points;
std::vector<std::pair<std::string, std::string>> 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();
Expand Down Expand Up @@ -85,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);
}
}
3 changes: 2 additions & 1 deletion main/add_objects_forms/add_hill_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class AddHillForm : public QDialog {
~AddHillForm();

signals:
void AddHill(std::vector<lib::Point> points);
void AddHill(std::vector<std::pair<std::string, std::string>> points);

private slots:
void on_createPushButton_clicked();
void on_clearPushButton_clicked();
void on_newPushButton_clicked();
void on_deletePushButton_clicked();

private:
/**
Expand Down
26 changes: 19 additions & 7 deletions main/add_objects_forms/add_hill_form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>280</width>
<width>420</width>
<height>310</height>
</rect>
</property>
Expand All @@ -24,7 +24,7 @@
</property>
<property name="maximumSize">
<size>
<width>280</width>
<width>500</width>
<height>310</height>
</size>
</property>
Expand All @@ -44,10 +44,10 @@
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>0</x>
<x>10</x>
<y>0</y>
<width>280</width>
<height>310</height>
<width>401</width>
<height>311</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -64,8 +64,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>278</width>
<height>308</height>
<width>399</width>
<height>309</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -111,6 +111,18 @@ QPushButton::pressed{background-color: rgb(135, 135, 135);}
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deletePushButton">
<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>Delete point</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newPushButton">
<property name="styleSheet">
Expand Down
4 changes: 2 additions & 2 deletions main/add_objects_forms/add_target_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion main/add_objects_forms/add_target_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions main/add_objects_forms/add_trappy_circle_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion main/add_objects_forms/add_trappy_circle_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions main/add_objects_forms/add_trappy_line_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
3 changes: 2 additions & 1 deletion main/add_objects_forms/add_trappy_line_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions main/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<lib::Point> 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<std::pair<std::string, std::string>> points);

private:
std::unique_ptr<data_tools::PlotArea> area_;
Expand Down
72 changes: 62 additions & 10 deletions main/mainwindow_connections/menu_add_actions.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
#include "main/mainwindow.h"

void MainWindow::AddTarget(double x, double y) {
void ChecksValues(std::vector<std::string> 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();

Expand All @@ -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();

Expand All @@ -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],
Expand All @@ -39,9 +84,16 @@ void MainWindow::AddTrappyLine(double x1, double y1, double x2, double y2) {
}
}

void MainWindow::AddHill(std::vector<lib::Point> points) {
void MainWindow::AddHill(
std::vector<std::pair<std::string, std::string>> points) {
try {
manager_->Add(new gui::Hill(points));
std::vector<lib::Point> 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();
Expand Down Expand Up @@ -83,4 +135,4 @@ void MainWindow::on_actionHill_triggered() {
AddHillForm* adh = new AddHillForm;
adh->show();
connect(adh, &AddHillForm::AddHill, this, &MainWindow::AddHill);
}
}

0 comments on commit ca19c12

Please sign in to comment.