60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <QVBoxLayout>
 | |
| #include <QLabel>
 | |
| #include "memory_dialog.h"
 | |
| #include "message_source.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(QMESSAGE("msg_dialog_memory_default"));
 | |
| 
 | |
|         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
 |