10#include <QtCore/QtGlobal>
11#include <QtWidgets/QGraphicsSceneMouseEvent>
24template <
class GraphicsItemClass,
class ObjectClass>
43 QVariant
itemChange(QGraphicsItem::GraphicsItemChange change,
const QVariant& value)
override;
56 QPointF m_lastPosition;
58 bool m_isShapeUpdateBlocked;
60 std::unique_ptr<istd::CChangeGroup> m_dragNotifierPtr;
68template <
class GraphicsItemClass,
class ObjectClass>
71 m_isShapeUpdateBlocked(false)
78 BaseClass::setFlags(BaseClass::ItemIsMovable | BaseClass::ItemIsSelectable | BaseClass::ItemSendsGeometryChanges);
79 BaseClass::setCursor(QCursor(Qt::ArrowCursor));
91template <
class GraphicsItemClass,
class ObjectClass>
94 if (
auto* objectPtr = BaseClass2::GetObservedObject()){
95 m_isShapeUpdateBlocked =
true;
97 UpdateGraphicsItem(*objectPtr);
99 m_isShapeUpdateBlocked =
false;
108template <
class GraphicsItemClass,
class ObjectClass>
112 BaseClass::SwitchColorSheme(BaseClass::SelectedColor);
115 if (BaseClass::IsEditable()){
116 BaseClass::SwitchColorSheme(BaseClass::EditableColor);
119 BaseClass::SwitchColorSheme(BaseClass::InactiveColor);
125template <
class GraphicsItemClass,
class ObjectClass>
129 if (objectPtr !=
nullptr){
130 QPointF offset = position - m_lastPosition;
134 m_lastPosition = position;
137 BaseClass::OnPositionChanged(position);
141template <
class GraphicsItemClass,
class ObjectClass>
144 if (!m_isShapeUpdateBlocked){
145 return BaseClass::itemChange(change, value);
152template <
class GraphicsItemClass,
class ObjectClass>
155 BaseClass::mousePressEvent(eventPtr);
157 if (BaseClass::IsEditable() && (eventPtr->button() == Qt::LeftButton)){
158 m_lastPosition = BaseClass::pos();
160 m_dragNotifierPtr = std::make_unique<istd::CChangeGroup>(BaseClass2::GetObservedObject(), &s_moveObjectChangeSet);
165template <
class GraphicsItemClass,
class ObjectClass>
168 BaseClass::mouseReleaseEvent(eventPtr);
170 m_dragNotifierPtr =
nullptr;
174template <
class GraphicsItemClass,
class ObjectClass>
177 BaseClass::mouseDoubleClickEvent(eventPtr);
179 m_dragNotifierPtr =
nullptr;
185template <
class GraphicsItemClass,
class ObjectClass>
188 if (BaseClass2::OnModelAttached(modelPtr, changeMask)) {
198template <
class GraphicsItemClass,
class ObjectClass>
201 Q_ASSERT(!m_isShapeUpdateBlocked);
207 BaseClass2::AfterModelChange(modelPtr, changeSet);
213template <
class GraphicsItemClass,
class ObjectClass>
Definition of position or mathematical vector on 2D plane.
Common interface for describing the 2D-objects.
virtual void MoveCenterTo(const CVector2d &position)=0
Move object to position position.
virtual CVector2d GetCenter() const =0
Returns center of this 2D-object.
Interface for GUI objects managing scene.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *eventPtr) override
void OnPositionChanged(const QPointF &position) override
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override
void AfterModelChange(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
This function will be called after update of the observer contents occures.
bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
This call back function will be called, if an observable object is about to be attached.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *eventPtr) override
TShapeBase< GraphicsItemClass > BaseClass
void mousePressEvent(QGraphicsSceneMouseEvent *eventPtr) override
virtual void UpdateGraphicsItem(const ObjectClass &object)=0
TObjectShapeBase(bool isEditable=false, const ISceneProvider *providerPtr=nullptr)
void OnSelectionChanged(bool isSelected) override
imod::TSingleModelObserverBase< ObjectClass > BaseClass2
virtual void SwitchColorSheme(int colorSheme)
virtual void SetPen(int colorSheme, const QPen &pen)
@ InactiveColor
Color for a shape, that can not be edited on the graphics view.
@ SelectedColor
Color for a selected shape.
@ EditableColor
Color for a shape, that can be edited on the graphics view.
Common interface for model objects, that supports Model/Observer design pattern.
Basic implementation for a single model observer with binding to concrete data object interface.
Set of change flags (its IDs).
bool ContainsExplicit(int changeId, bool singleOnly=false) const
Check if there is specific change flag in the set explicit set by user.
@ CF_DESTROYING
Change flag indicate that model is during destruction.
This package contains (Qt based) implementations of compositor components.