2022-06-05 17:02:44 +00:00
|
|
|
#include "single_automatic_dialog.h"
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
namespace display {
|
|
|
|
|
2022-06-13 22:53:46 +00:00
|
|
|
SingleAutomaticDialog::SingleAutomaticDialog(std::string title, std::string action,
|
|
|
|
std::vector<domain::InstanceAttribute> &values)
|
|
|
|
: GenericDialog(title, action), attributes(values) {
|
2022-06-05 17:02:44 +00:00
|
|
|
firstValue = values[0].value;
|
|
|
|
secondValue = values[1].value;
|
|
|
|
|
2022-06-13 22:53:46 +00:00
|
|
|
auto *contentLayout = new QHBoxLayout();
|
|
|
|
auto *firstLayout = new QVBoxLayout();
|
|
|
|
auto *secondLayout = new QVBoxLayout();
|
2022-06-05 17:02:44 +00:00
|
|
|
|
2022-06-13 22:53:46 +00:00
|
|
|
content->setLayout(contentLayout);
|
2022-06-05 17:02:44 +00:00
|
|
|
contentLayout->addLayout(firstLayout);
|
|
|
|
contentLayout->addLayout(secondLayout);
|
|
|
|
|
|
|
|
setupValues(firstLayout, values[0], &SingleAutomaticDialog::onFirstEnumerationChanged);
|
|
|
|
setupValues(secondLayout, values[1], &SingleAutomaticDialog::onSecondEnumerationChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SingleAutomaticDialog::setupValues(QVBoxLayout *layout, domain::InstanceAttribute &attribute, void (display::SingleAutomaticDialog::* handler)(int)) {
|
|
|
|
|
|
|
|
auto popup = *attribute.attribute.getPopup();
|
|
|
|
|
|
|
|
layout->addWidget(new QLabel(popup.getTitle().c_str()));
|
|
|
|
layout->addWidget(new QLabel(popup.getText().c_str()));
|
|
|
|
|
|
|
|
auto *combo = new QComboBox(this);
|
|
|
|
auto enumeration = attribute.attribute.getPopup()->getEnumeration();
|
|
|
|
for (auto entry: enumeration) {
|
|
|
|
combo->addItem(QString::fromStdString(entry.getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,handler);
|
|
|
|
layout->addWidget(combo);
|
|
|
|
|
|
|
|
for (int i = 0; i < enumeration.size(); i++) {
|
|
|
|
if (attribute.value.equals(enumeration[i].getValue())) {
|
|
|
|
combo->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SingleAutomaticDialog::onFirstEnumerationChanged(int index) {
|
|
|
|
firstValue = attributes[0].attribute.getPopup()->getEnumeration()[index].getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SingleAutomaticDialog::onSecondEnumerationChanged(int index) {
|
|
|
|
secondValue = attributes[1].attribute.getPopup()->getEnumeration()[index].getValue();
|
|
|
|
}
|
|
|
|
|
2022-06-13 22:53:46 +00:00
|
|
|
bool SingleAutomaticDialog::onUpdate() {
|
2022-06-05 17:02:44 +00:00
|
|
|
attributes[0].value = firstValue;
|
|
|
|
attributes[1].value = secondValue;
|
2022-06-13 22:53:46 +00:00
|
|
|
return true;
|
2022-06-05 17:02:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // display
|