2022-06-13 22:53:46 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include "memory_dialog.h"
|
2022-06-19 18:10:44 +00:00
|
|
|
#include "message_source.h"
|
2022-06-13 22:53:46 +00:00
|
|
|
|
|
|
|
namespace display {
|
|
|
|
|
|
|
|
|
|
|
|
MemoryDialog::MemoryDialog(std::string title, std::string action, domain::InstanceAttribute *attribute,
|
|
|
|
std::vector<std::shared_ptr<domain::ComponentInstance>> instances)
|
|
|
|
: GenericDialog(title, action), value(attribute->value), attributeValue(attribute), popup(*attribute->attribute.getPopup()) {
|
|
|
|
|
|
|
|
for (auto &instance: instances) {
|
|
|
|
if (instance->component.getType() == domain::Component::MEMORY) {
|
|
|
|
memoryInstances.push_back(instance->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto contentLayout = new QVBoxLayout(content);
|
|
|
|
content->setLayout(contentLayout);
|
|
|
|
|
|
|
|
contentLayout->addWidget(new QLabel(popup.getTitle().c_str()));
|
|
|
|
contentLayout->addWidget(new QLabel(popup.getText().c_str()));
|
|
|
|
|
|
|
|
contentLayout->addWidget(setupEnumeration());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryDialog::onUpdate() {
|
|
|
|
attributeValue->value = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QComboBox *MemoryDialog::setupEnumeration() {
|
|
|
|
auto *combo = new QComboBox(this);
|
|
|
|
|
|
|
|
for (const auto& entry: memoryInstances) {
|
|
|
|
combo->addItem(QString::fromStdString(entry));
|
|
|
|
}
|
2022-06-19 18:10:44 +00:00
|
|
|
combo->addItem(QMESSAGE("msg_dialog_memory_default"));
|
2022-06-13 22:53:46 +00:00
|
|
|
|
|
|
|
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if(index == memoryInstances.size()) {
|
|
|
|
value = domain::Value::fromMemoryReference(std::nullopt);
|
|
|
|
} else {
|
|
|
|
value = domain::Value::fromMemoryReference(this->memoryInstances[index]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
combo->setCurrentIndex(memoryInstances.size());
|
|
|
|
for (int i = 0; i < memoryInstances.size(); i++) {
|
|
|
|
if (attributeValue->value.equals(domain::Value::fromMemoryReference(memoryInstances[i]))) {
|
|
|
|
combo->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // display
|