Updated attribute dialog
This commit is contained in:
		
							parent
							
								
									05fa2abbb0
								
							
						
					
					
						commit
						23764776f1
					
				| @ -2,6 +2,8 @@ | ||||
| #define ATTRIBUTE_DIALOG_H | ||||
| 
 | ||||
| #include <QIntValidator> | ||||
| #include <QPushButton> | ||||
| #include <QComboBox> | ||||
| #include <QGroupBox> | ||||
| #include <QRadioButton> | ||||
| #include <QDialog> | ||||
| @ -15,9 +17,35 @@ | ||||
| namespace display { | ||||
| 
 | ||||
| class AttributeDialog: public QDialog { | ||||
|     domain::Value value; | ||||
| 
 | ||||
|     long long int parseInt(std::string expression) { | ||||
|         try { | ||||
|             if (expression.size() > 2) { | ||||
|                 if (expression.substr(0, 2) == "0x") { | ||||
|                     return std::stoll(expression, 0, 16); | ||||
|                 } else if (expression.substr(0, 2) == "0b") { | ||||
|                     return std::stoll(expression, 0, 2); | ||||
|                 } else { | ||||
|                     return std::stoll(expression, 0, 10); | ||||
|                 } | ||||
|             } else { | ||||
|                 return std::stoll(expression, 0, 10); | ||||
|             } | ||||
|         } catch (std::exception &e) { | ||||
|             return 0; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     domain::InstanceAttribute* attributeValue; | ||||
| 
 | ||||
| public: | ||||
|     AttributeDialog(domain::InstanceAttribute *attribute) { | ||||
| 
 | ||||
|         setAttribute(Qt::WA_DeleteOnClose); | ||||
| 
 | ||||
|         attributeValue = attribute; | ||||
| 
 | ||||
|         this->setWindowTitle(QString::fromStdString("Izmjeni " + attribute->attribute.getName())); | ||||
| 
 | ||||
|         auto layout = new QVBoxLayout(this); | ||||
| @ -28,12 +56,29 @@ public: | ||||
|         layout->addWidget(new QLabel(popup.getText().c_str())); | ||||
| 
 | ||||
|         auto type = attribute->attribute.getDefault().getType(); | ||||
|         value = attribute->value; | ||||
| 
 | ||||
|         if(attribute->attribute.getPopup()->isEnumerated()) { | ||||
|             auto* combo = new QComboBox(this); | ||||
|             auto enumeration = attribute->attribute.getPopup()->getEnumeration(); | ||||
|             for(auto entry: enumeration) { | ||||
|                 combo->addItem(QString::fromStdString(entry.getName()), QVariant::fromValue(NULL)); | ||||
|             } | ||||
| 
 | ||||
|             connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AttributeDialog::onEnumerationChanged); | ||||
|             layout->addWidget(combo); | ||||
| 
 | ||||
|             for(int i=0; i<enumeration.size(); i++) { | ||||
|                 if(attributeValue->value.equals(enumeration[i].getValue())) { | ||||
|                     combo->setCurrentIndex(i); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|         } else if(!(type == domain::Value::ValueType::WIRE_REFERENCE || type == domain::Value::ValueType::BOOL)) { | ||||
| 
 | ||||
|             auto edit = new QLineEdit(this); | ||||
|             connect(edit, &QLineEdit::textChanged, this, &AttributeDialog::onTextChanged); | ||||
|             layout->addWidget(edit); | ||||
| 
 | ||||
|             switch (attribute->attribute.getDefault().getType()) { | ||||
| @ -46,15 +91,20 @@ public: | ||||
|                     break; | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         } else if(type == domain::Value::ValueType::BOOL) { | ||||
|             auto *group = new QGroupBox(this); | ||||
|             group->setCheckable(true); | ||||
|             group->setChecked(true); | ||||
| 
 | ||||
|             auto *radioLayout = new QHBoxLayout(group); | ||||
|             group->setLayout(radioLayout); | ||||
| 
 | ||||
|             auto isTrue = new QRadioButton("true", group); | ||||
|             connect(isTrue, &QRadioButton::clicked, [this]() { | ||||
|                 this->value = domain::Value::fromBool(true); | ||||
|             }); | ||||
|             auto isFalse = new QRadioButton("false", group); | ||||
|             connect(isFalse, &QRadioButton::clicked, [this]() { | ||||
|                 this->value = domain::Value::fromBool(false); | ||||
|             }); | ||||
| 
 | ||||
|             if(attribute->value.asBool()) { | ||||
|                 isTrue->setChecked(true); | ||||
| @ -62,10 +112,35 @@ public: | ||||
|                 isFalse->setChecked(true); | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|             radioLayout->addWidget(isTrue); | ||||
|             radioLayout->addWidget(isFalse); | ||||
|             layout->addWidget(group); | ||||
|         } | ||||
| 
 | ||||
|         auto button = new QPushButton("Ažuriraj"); | ||||
|         connect(button, &QPushButton::clicked, this, &AttributeDialog::onUpdate); | ||||
| 
 | ||||
|         layout->addWidget(button); | ||||
|     } | ||||
| 
 | ||||
| public slots: | ||||
|     void onTextChanged(const QString& string) { | ||||
|         switch (value.getType()) { | ||||
|             case domain::Value::STRING: | ||||
|                 value.setString(string.toStdString()); | ||||
|             break; | ||||
|             case domain::Value::INT: | ||||
|                 value = domain::Value::fromInt(parseInt(string.toStdString())); | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     void onEnumerationChanged(int index) { | ||||
|         value = attributeValue->attribute.getPopup()->getEnumeration()[index].getValue(); | ||||
|     } | ||||
| 
 | ||||
|     void onUpdate() { | ||||
|         attributeValue->value = value; | ||||
|         accept(); | ||||
|     } | ||||
| 
 | ||||
| }; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| #include "component_display.h" | ||||
| #include "attribute_dialog.h" | ||||
| #include "name_dialog.h" | ||||
| 
 | ||||
| #include <QMenu> | ||||
| #include <QGraphicsSceneContextMenuEvent> | ||||
| @ -11,11 +13,15 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { | ||||
|     QMenu menu; | ||||
|     menu.addAction("Izmjeni ime", [this](){}); | ||||
|     menu.addSeparator(); | ||||
|     for(auto attr: this->instance->attributes) { | ||||
|         bool enabled = attr.attribute.getPopup().has_value(); | ||||
|     for(int i=0; i<this->instance->attributes.size(); i++) { | ||||
|         auto* attr = &this->instance->attributes[i]; | ||||
|         bool enabled = attr->attribute.getPopup().has_value(); | ||||
| 
 | ||||
|         auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr.name), | ||||
|                                      [&attr, this]() {}); | ||||
|         auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name), | ||||
|                                      [attr]() { | ||||
|             auto dialog = new AttributeDialog(attr); | ||||
|             dialog->exec(); | ||||
|         }); | ||||
|         action->setEnabled(enabled); | ||||
|     } | ||||
|     menu.exec(event->screenPos()); | ||||
|  | ||||
| @ -6,7 +6,7 @@ Enumeration::Enumeration(std::string name, Value value) | ||||
|     : name(name), value(value) | ||||
| {} | ||||
| 
 | ||||
| std::string Enumeration::getName() { | ||||
| std::string& Enumeration::getName() { | ||||
|     return name; | ||||
| } | ||||
| Value Enumeration::getValue() { | ||||
|  | ||||
| @ -15,7 +15,7 @@ class Enumeration { | ||||
| public: | ||||
|     Enumeration(std::string name, Value value); | ||||
| 
 | ||||
|     std::string getName(); | ||||
|     std::string& getName(); | ||||
|     Value getValue(); | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -39,6 +39,29 @@ public: | ||||
|         this->type = UNDEFINED; | ||||
|     } | ||||
| 
 | ||||
|     bool equals(Value value) { | ||||
|         if(value.getType() == type) { | ||||
|             switch (type) { | ||||
|                 case INT: | ||||
|                     return value.asInt() == intValue; | ||||
|                 case STRING: | ||||
|                     return value.asString() == stringValue; | ||||
|                 case NIL: | ||||
|                 case UNDEFINED: | ||||
|                     return true; | ||||
|                 case WIRE_REFERENCE: | ||||
|                 case ATTRIBUTE_REFERENCE: | ||||
|                 case ADDRESS_SPACE_REFERENCE: | ||||
|                     return value.asReference() == reference; | ||||
|                 case BOOL: | ||||
|                     return value.asBool() == boolValue; | ||||
|                 default: | ||||
|                     return false; | ||||
|             } | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     std::string string(); | ||||
| 
 | ||||
|     ValueType getType(); | ||||
|  | ||||
| @ -75,6 +75,27 @@ | ||||
|     @tooltip "Memorijska komponenta, mora postojati barem jedna" | ||||
|     @count (1,1000) | ||||
|     @source "memory.cdl" | ||||
| 
 | ||||
|     @attribute sinkroniziran bool default false { | ||||
|         @popup automatic { | ||||
|             @title "Postavite sinkroniziranost" | ||||
|             @text "Zadajte sinkronizaciju" | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @attribute brzina int default 1 { | ||||
|         @popup automatic { | ||||
|             @title "Postavite brzinu memorije" | ||||
|             @text "Zadajte brzinu memorije" | ||||
|             @enumerated { | ||||
|                 "Spora" = 1, | ||||
|                 "Srednja" = 5, | ||||
|                 "Brza" = 25, | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @attribute kapacitet int default 65536 { | ||||
|         @popup automatic { | ||||
|             @title "Kapacitet memorije" | ||||
| @ -171,6 +192,7 @@ | ||||
|     @tooltip "DMA-kontroler" | ||||
|     @count (1,1000) | ||||
|     @source "dma.cdl" | ||||
| 
 | ||||
|     @attribute pocetnaAdresa int default 0 { | ||||
|         @popup automatic { | ||||
|             @title "Početna adresa DMA-kontrolera" | ||||
|  | ||||
| @ -7,6 +7,8 @@ | ||||
| 
 | ||||
|     @instance mem Memorija { | ||||
|         @position (0, 250) | ||||
|         @attribute sinkroniziran false | ||||
|         @attribute brzina 1 | ||||
|         @attribute kapacitet 1024 | ||||
|         @attribute size 8 | ||||
|         @attribute pocetnaAdresa 1023 | ||||
|  | ||||
| @ -7,9 +7,10 @@ | ||||
| 
 | ||||
| 	@instance mem Memorija { | ||||
| 		@position (0, 250) | ||||
| 		@attribute kapacitet 1024 | ||||
| 		@attribute brzina 25 | ||||
| 		@attribute kapacitet 2048 | ||||
| 		@attribute size 8 | ||||
| 		@attribute pocetnaAdresa 1023 | ||||
| 		@attribute pocetnaAdresa 0 | ||||
| 	} | ||||
| 
 | ||||
| 	@instance bus glavnaSabirnica { | ||||
| @ -17,18 +18,17 @@ | ||||
| 		@size 100 | ||||
| 	} | ||||
| 
 | ||||
| 	@wire wire_001 { | ||||
| 		@position (50, 116) | ||||
| 		@display {} | ||||
| 	} | ||||
| 	@wire wire_002 { | ||||
| 		@position (50, 220) | ||||
| 		@display {} | ||||
| 	@instance testBus Test { | ||||
| 		@position (0, 200) | ||||
| 		@size 0 | ||||
| 	} | ||||
| 
 | ||||
| 	@connection (proc.glavniPin, bus) { | ||||
| 		@wire wire_001 | ||||
| 	} | ||||
| 	@connection (mem.glavniPin, bus) { | ||||
| 		@wire wire_002 | ||||
| 	} | ||||
| 	@connection (proc.glavniPin, testBus, mem.glavniPin) { | ||||
| 		@attribute dmaPoveznica "READY" | ||||
| 		@attribute mmaPoveznica "PIO_DATA" | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user