-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddElementDialog.cpp
More file actions
41 lines (38 loc) · 1.62 KB
/
AddElementDialog.cpp
File metadata and controls
41 lines (38 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "AddElementDialog.h"
#include "ElectricalElementsManager.h"
// Конструктор
AddElementDialog::AddElementDialog(QWidget *parent) : QDialog(parent) {
ui.setupUi(this);
ElectricalElementsManager::getInstance().fillElementsList(
ui.elementsListWidget);
}
// Выбор элемента в списке
void AddElementDialog::on_elementsListWidget_itemSelectionChanged() {
// Очистка таблицы свойств
ui.elementPropertiesTableWidget->clear();
const auto &v = ui.elementsListWidget->selectedItems();
if (!v.empty()) {
// Если есть выбранный элемент, то заполнить таблицу свойств
int row = ui.elementsListWidget->row(v[0]);
ElectricalElementsManager::getInstance().fillPropertiesTable(
ui.elementPropertiesTableWidget, row);
}
}
// Нажатие кнопки "ОК"
void AddElementDialog::on_okButton_clicked() {
const auto &v = ui.elementsListWidget->selectedItems();
// Если нет выбранного элемента
if (v.empty()) {
elementIndex = -1;
elementProperties.clear();
} else {
// Если есть, то заполнить номер и свойства
elementIndex = ui.elementsListWidget->row(v[0]);
elementProperties.clear();
elementProperties.reserve(ui.elementPropertiesTableWidget->rowCount());
for (int i = 0; i < ui.elementPropertiesTableWidget->rowCount(); i++)
elementProperties.push_back(
ui.elementPropertiesTableWidget->item(i, 1)->text());
}
accept();
}