Added movement storing
This commit is contained in:
1 parent
e2e0506041
commit
281926cb8b
5 files changed
+48
-14
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user