diff --git a/comdel/display/component_display.cpp b/comdel/display/component_display.cpp index 14cd4ae..d9a89e0 100644 --- a/comdel/display/component_display.cpp +++ b/comdel/display/component_display.cpp @@ -5,7 +5,6 @@ #include #include -#include #include namespace display { @@ -46,4 +45,24 @@ void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { menu.exec(event->screenPos()); } + QVariant BusGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { + if (change == ItemPositionChange && scene()) { + // value is the new position. + QPointF newPos = value.toPointF(); + busInstance->position.first = newPos.x(); + busInstance->position.second = newPos.y(); + } + return QGraphicsItem::itemChange(change, value); + } + + + QVariant ComponentGroup::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { + if (change == ItemPositionChange && scene()) { + // value is the new position. + QPointF newPos = value.toPointF(); + componentInstance->position.first = newPos.x(); + componentInstance->position.second = newPos.y(); + } + return QGraphicsItem::itemChange(change, value); + } } // namespace display diff --git a/comdel/display/component_display.h b/comdel/display/component_display.h index c782767..1fbe5e1 100644 --- a/comdel/display/component_display.h +++ b/comdel/display/component_display.h @@ -24,9 +24,12 @@ private: std::shared_ptr instance; public: Component(const std::shared_ptr& instance): instance(instance) { + setFlag(ItemSendsGeometryChanges, true); + instance->component.getDisplay().render(this); } void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; + }; class Bus: public QGraphicsItemGroup @@ -37,6 +40,7 @@ public: instance->bus.getDisplay()->render(this); } void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; + }; class ComponentGroup: public QGraphicsItemGroup @@ -47,6 +51,8 @@ private: public: explicit ComponentGroup(const std::shared_ptr& instance): componentInstance(instance) { setFlag(ItemIsMovable, true); + setFlag(ItemSendsGeometryChanges, true); + setHandlesChildEvents(false); addToGroup(new display::Component(instance)); @@ -57,6 +63,10 @@ public: setPos(instance->position.first, instance->position.second); } + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + }; class BusGroup: public QGraphicsItemGroup @@ -67,14 +77,21 @@ private: public: explicit BusGroup(const std::shared_ptr& instance): busInstance(instance) { setFlag(ItemIsMovable, true); + setFlag(ItemSendsGeometryChanges, true); + setHandlesChildEvents(false); addToGroup(new display::Bus(instance)); setPos(instance->position.first, instance->position.second); } + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; + + } // namespace display #endif // DISPLAY_COMPONENT_H diff --git a/comdel/domain/schemacreator.cpp b/comdel/domain/schemacreator.cpp index a52b7a1..aa14599 100644 --- a/comdel/domain/schemacreator.cpp +++ b/comdel/domain/schemacreator.cpp @@ -946,7 +946,7 @@ vector SchemaCreator::createWireEnumeration(vector wireValue } std::optional SchemaCreator::createMemoryAttribute() { - return Attribute("_memory", Value::fromMemoryReference(nullopt), createMemoryPopup()); + return Attribute("_memory", Value::fromMemoryReference(std::nullopt), createMemoryPopup()); } std::optional SchemaCreator::createMemoryPopup() { diff --git a/comdel/domain/value.cpp b/comdel/domain/value.cpp index 54ba553..805342f 100644 --- a/comdel/domain/value.cpp +++ b/comdel/domain/value.cpp @@ -162,10 +162,10 @@ std::string Value::stringify() { case ATTRIBUTE_REFERENCE: return reference; case MEMORY_REFERENCE: - if(memoryReference->empty()) { - return "null"; - } else { + if(memoryReference.has_value()) { return memoryReference.value(); + } else { + return "null"; } default: throw std::exception(); diff --git a/comdel/domain/value.h b/comdel/domain/value.h index 3af0497..c011ef4 100644 --- a/comdel/domain/value.h +++ b/comdel/domain/value.h @@ -29,22 +29,20 @@ public: }; private: - long long intValue; + long long intValue = 0; std::string stringValue; - bool boolValue; - std::optional addressSpace; + bool boolValue = false; + std::optional addressSpace = std::nullopt; std::string reference; - domain::ComponentInstance *memory; + domain::ComponentInstance *memory = nullptr; - std::optional memoryReference; + std::optional memoryReference = std::nullopt; - ValueType type; + ValueType type = UNDEFINED; public: - Value() { - this->type = UNDEFINED; - } + Value() {} bool equals(Value value) { if(value.getType() == type) {