Added movement storing

This commit is contained in:
Borna Rajković 2022-05-17 21:31:32 +02:00
parent e2e0506041
commit 281926cb8b
5 changed files with 48 additions and 14 deletions

View File

@ -5,7 +5,6 @@
#include <QMenu> #include <QMenu>
#include <QGraphicsSceneContextMenuEvent> #include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsScene>
#include <iostream> #include <iostream>
namespace display { namespace display {
@ -46,4 +45,24 @@ void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
menu.exec(event->screenPos()); 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 } // namespace display

View File

@ -24,9 +24,12 @@ private:
std::shared_ptr<domain::ComponentInstance> instance; std::shared_ptr<domain::ComponentInstance> instance;
public: public:
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) { Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
setFlag(ItemSendsGeometryChanges, true);
instance->component.getDisplay().render(this); instance->component.getDisplay().render(this);
} }
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
}; };
class Bus: public QGraphicsItemGroup class Bus: public QGraphicsItemGroup
@ -37,6 +40,7 @@ public:
instance->bus.getDisplay()->render(this); instance->bus.getDisplay()->render(this);
} }
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
}; };
class ComponentGroup: public QGraphicsItemGroup class ComponentGroup: public QGraphicsItemGroup
@ -47,6 +51,8 @@ private:
public: public:
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) { explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) {
setFlag(ItemIsMovable, true); setFlag(ItemIsMovable, true);
setFlag(ItemSendsGeometryChanges, true);
setHandlesChildEvents(false); setHandlesChildEvents(false);
addToGroup(new display::Component(instance)); addToGroup(new display::Component(instance));
@ -57,6 +63,10 @@ public:
setPos(instance->position.first, instance->position.second); setPos(instance->position.first, instance->position.second);
} }
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
}; };
class BusGroup: public QGraphicsItemGroup class BusGroup: public QGraphicsItemGroup
@ -67,14 +77,21 @@ private:
public: public:
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) { explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
setFlag(ItemIsMovable, true); setFlag(ItemIsMovable, true);
setFlag(ItemSendsGeometryChanges, true);
setHandlesChildEvents(false); setHandlesChildEvents(false);
addToGroup(new display::Bus(instance)); addToGroup(new display::Bus(instance));
setPos(instance->position.first, instance->position.second); setPos(instance->position.first, instance->position.second);
} }
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
}; };
} // namespace display } // namespace display
#endif // DISPLAY_COMPONENT_H #endif // DISPLAY_COMPONENT_H

View File

@ -946,7 +946,7 @@ vector<Enumeration> SchemaCreator::createWireEnumeration(vector<Value> wireValue
} }
std::optional<Attribute> SchemaCreator::createMemoryAttribute() { std::optional<Attribute> SchemaCreator::createMemoryAttribute() {
return Attribute("_memory", Value::fromMemoryReference(nullopt), createMemoryPopup()); return Attribute("_memory", Value::fromMemoryReference(std::nullopt), createMemoryPopup());
} }
std::optional<Popup> SchemaCreator::createMemoryPopup() { std::optional<Popup> SchemaCreator::createMemoryPopup() {

View File

@ -162,10 +162,10 @@ std::string Value::stringify() {
case ATTRIBUTE_REFERENCE: case ATTRIBUTE_REFERENCE:
return reference; return reference;
case MEMORY_REFERENCE: case MEMORY_REFERENCE:
if(memoryReference->empty()) { if(memoryReference.has_value()) {
return "null";
} else {
return memoryReference.value(); return memoryReference.value();
} else {
return "null";
} }
default: default:
throw std::exception(); throw std::exception();

View File

@ -29,22 +29,20 @@ public:
}; };
private: private:
long long intValue; long long intValue = 0;
std::string stringValue; std::string stringValue;
bool boolValue; bool boolValue = false;
std::optional<AddressSpace> addressSpace; std::optional<AddressSpace> addressSpace = std::nullopt;
std::string reference; std::string reference;
domain::ComponentInstance *memory; domain::ComponentInstance *memory = nullptr;
std::optional<std::string> memoryReference; std::optional<std::string> memoryReference = std::nullopt;
ValueType type; ValueType type = UNDEFINED;
public: public:
Value() { Value() {}
this->type = UNDEFINED;
}
bool equals(Value value) { bool equals(Value value) {
if(value.getType() == type) { if(value.getType() == type) {