schema_editor/comdel/display/dialog/memory_dialog.cpp

59 lines
2.0 KiB
C++
Raw Normal View History

2022-06-13 22:53:46 +00:00
#include <QVBoxLayout>
#include <QLabel>
#include "memory_dialog.h"
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));
}
combo->addItem("null");
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