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 <QGraphicsSceneContextMenuEvent>
#include <QGraphicsScene>
#include <iostream>
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

View File

@ -24,9 +24,12 @@ private:
std::shared_ptr<domain::ComponentInstance> instance;
public:
Component(const std::shared_ptr<domain::ComponentInstance>& 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<domain::ComponentInstance>& 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<domain::BusInstance>& 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

View File

@ -946,7 +946,7 @@ vector<Enumeration> SchemaCreator::createWireEnumeration(vector<Value> wireValue
}
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() {

View File

@ -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();

View File

@ -29,22 +29,20 @@ public:
};
private:
long long intValue;
long long intValue = 0;
std::string stringValue;
bool boolValue;
std::optional<AddressSpace> addressSpace;
bool boolValue = false;
std::optional<AddressSpace> addressSpace = std::nullopt;
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:
Value() {
this->type = UNDEFINED;
}
Value() {}
bool equals(Value value) {
if(value.getType() == type) {