Locus No Pilotus
Project of four first grade MIPT DAFE/RSE students (for engineering practical work in the second semester) in Qt C++
Loading...
Searching...
No Matches
AddHillForm Class Reference

#include <add_hill_form.h>

Inheritance diagram for AddHillForm:
Collaboration diagram for AddHillForm:

Signals

void AddHill (const std::vector< std::pair< double, double > > &points)
 

Public Member Functions

 AddHillForm (QWidget *parent=nullptr)
 
 ~AddHillForm ()
 

Private Slots

void on_clearPushButton_clicked ()
 
void on_createPushButton_clicked ()
 
void on_deletePushButton_clicked ()
 
void on_newPushButton_clicked ()
 

Private Member Functions

void AddNewInputFields (size_t amount=1)
 Добавляет определенное количество новых полей ввода на форму
 

Private Attributes

std::vector< PointLineEditsboth_coords_point_line_edits_
 
std::vector< std::unique_ptr< QWidget > > point_layouts_widgets_
 
Ui::AddHillForm * ui
 

Constructor & Destructor Documentation

◆ AddHillForm()

AddHillForm::AddHillForm ( QWidget * parent = nullptr)
explicit
8 : QDialog(parent), ui(new Ui::AddHillForm) {
9 ui->setupUi(this);
10
11 // на начальный момент на окне находится 3 поля ввода
13}
Ui::AddHillForm * ui
Definition add_hill_form.h:56
void AddNewInputFields(size_t amount=1)
Добавляет определенное количество новых полей ввода на форму
Definition add_hill_form.cpp:49
Here is the call graph for this function:

◆ ~AddHillForm()

AddHillForm::~AddHillForm ( )
15{ delete ui; }

Member Function Documentation

◆ AddHill

void AddHillForm::AddHill ( const std::vector< std::pair< double, double > > & points)
signal
Here is the caller graph for this function:

◆ AddNewInputFields()

void AddHillForm::AddNewInputFields ( size_t amount = 1)
private

Добавляет определенное количество новых полей ввода на форму

Parameters
amountкол-ло новых полей ввода точки
49 {
50 // передвигаем кнопки в конец
51 ui->gridLayout->removeItem(ui->buttonsLayout);
52 ui->gridLayout->addItem(
53 ui->buttonsLayout, ui->gridLayout->count() + static_cast<int>(amount), 0);
54
55 // (-1, так как buttonsLayout считается за отдельный уже находящийся элемент)
56 auto old_size = ui->gridLayout->count() - 1;
57 auto new_size = ui->gridLayout->count() - 1 + amount;
58
59 for (size_t i = old_size; i < new_size; i++) {
60 // создаём виджет и лейаут, на который будем добавлять поля ввода и лейблы
61 point_layouts_widgets_.emplace_back(new QWidget(ui->gridLayoutWidget));
62 point_layouts_widgets_[i]->setObjectName("point" + QString::number(i + 1) +
63 "LayoutWidget");
64 point_layouts_widgets_[i]->setLayout(new QHBoxLayout);
65 ui->gridLayout->addWidget(point_layouts_widgets_[i].get(),
66 static_cast<int>(i), 0);
67
68 // создаем валидатор
69 QDoubleValidator* double_validator{new QDoubleValidator()};
70
71 // добавляем лейбл с указанием, к какой точке он относится
72 QLabel* point_label = new QLabel(this);
73 point_label->setObjectName("point" + QString::number(i + 1) + "Label");
74 point_label->setText("Point " + QString::number(i + 1) + ":");
75 point_layouts_widgets_[i]->layout()->addWidget(point_label);
76
77 // добавляем лейбл координаты X и поле для его ввода
78 QLabel* abscissa_label = new QLabel(this);
79 abscissa_label->setObjectName("abscissa" + QString::number(i + 1) +
80 "Label");
81 abscissa_label->setText("X:");
82 point_layouts_widgets_[i]->layout()->addWidget(abscissa_label);
83
84 QLineEdit* abscissa_line_edit = new QLineEdit(this);
85 abscissa_line_edit->setValidator(double_validator);
86 abscissa_line_edit->setObjectName("abscissa" + QString::number(i + 1) +
87 "LineEdit");
88 point_layouts_widgets_[i]->layout()->addWidget(abscissa_line_edit);
89
90 // добавляем лейбл координаты Y и поле для его ввода
91 QLabel* ordinate_label = new QLabel(this);
92 ordinate_label->setObjectName("ordinate" + QString::number(i + 1) +
93 "Label");
94 ordinate_label->setText("Y:");
95 point_layouts_widgets_[i]->layout()->addWidget(ordinate_label);
96
97 QLineEdit* ordinate_line_edit = new QLineEdit(this);
98 ordinate_line_edit->setValidator(double_validator);
99 ordinate_line_edit->setObjectName("ordinate" + QString::number(i + 1) +
100 "LineEdit");
101 point_layouts_widgets_[i]->layout()->addWidget(ordinate_line_edit);
102
103 // добавляем оба лейбла в вектор
105 PointLineEdits(abscissa_line_edit, ordinate_line_edit));
106 }
107}
std::vector< std::unique_ptr< QWidget > > point_layouts_widgets_
Definition add_hill_form.h:57
std::vector< PointLineEdits > both_coords_point_line_edits_
Definition add_hill_form.h:58
Структура из двух QLineEdit, относящихся к вводу координаты точки (чтобы не использовать std::pair<st...
Definition add_hill_form.h:24
Here is the caller graph for this function:

◆ on_clearPushButton_clicked

void AddHillForm::on_clearPushButton_clicked ( )
privateslot
40 {
41 for (size_t i = 0; i < both_coords_point_line_edits_.size(); i++) {
42 both_coords_point_line_edits_[i].abscissa->clear();
43 both_coords_point_line_edits_[i].ordinate->clear();
44 }
45}

◆ on_createPushButton_clicked

void AddHillForm::on_createPushButton_clicked ( )
privateslot
17 {
18 std::vector<std::pair<double, double>> points;
19 for (size_t i = 0; i < both_coords_point_line_edits_.size(); i++) {
20 QString x =
21 both_coords_point_line_edits_[i].abscissa->displayText().replace(',',
22 '.');
23 QString y =
24 both_coords_point_line_edits_[i].ordinate->displayText().replace(',',
25 '.');
26 if (x.isEmpty() || y.isEmpty()) {
27 QMessageBox::warning(
28 this, "Warning!",
29 "There are empty fields! Please, enter values in all fields.");
30 break;
31 }
32 points.push_back({x.toDouble(), y.toDouble()});
33 }
34 if (points.size() == both_coords_point_line_edits_.size()) {
35 emit AddHill(points);
36 close();
37 }
38}
void AddHill(const std::vector< std::pair< double, double > > &points)
Here is the call graph for this function:

◆ on_deletePushButton_clicked

void AddHillForm::on_deletePushButton_clicked ( )
privateslot
109 {
110 if (both_coords_point_line_edits_.size() > 3) {
113 1);
115 point_layouts_widgets_.size() - 1);
116 }
117}

◆ on_newPushButton_clicked

void AddHillForm::on_newPushButton_clicked ( )
privateslot
Here is the call graph for this function:

Member Data Documentation

◆ both_coords_point_line_edits_

std::vector<PointLineEdits> AddHillForm::both_coords_point_line_edits_
private

◆ point_layouts_widgets_

std::vector<std::unique_ptr<QWidget> > AddHillForm::point_layouts_widgets_
private

◆ ui

Ui::AddHillForm* AddHillForm::ui
private

The documentation for this class was generated from the following files: