OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
GraphicsView.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/Flags.h"
10#include "OTCore/Point2D.h"
11#include "OTCore/CoreTypes.h"
16
17// Qt header
18#include <QtWidgets/qgraphicsview.h>
21
22// std header
23#include <map>
24#include <list>
25#include <string>
26#include <atomic>
27
28namespace ot {
29
30 class GraphicsItem;
31 class GraphicsScene;
32 class GraphicsItemCfg;
33 class GraphicsConnectionItem;
34
37 class OT_WIDGETS_API_EXPORT GraphicsView : public QGraphicsView, public QWidgetInterface {
38 Q_OBJECT
39 public:
41 NoViewFlags = 0x00,
42 ViewManagesSceneRect = 0x01,
43 IgnoreConnectionByUser = 0x02
44 };
46
48 DefaultState = 0 << 0,
49 ItemMoveInProgress = 1 << 0,
50 MiddleMousePressedState = 1 << 1,
51 ReadOnlyState = 1 << 2
52 };
54
55 GraphicsView(GraphicsScene* _scene = (GraphicsScene*)nullptr);
56 virtual ~GraphicsView();
57
58 virtual QWidget* getQWidget(void) override { return this; };
59 virtual const QWidget* getQWidget(void) const override { return this; };
60
61 void resetView(void);
62 void ensureViewInBounds(void);
63
64 void setMouseWheelEnabled(bool _enabled) { m_wheelEnabled = _enabled; };
65 bool getMouseWheelEnabled(void) const { return m_wheelEnabled; };
66
67 void setOwner(const BasicServiceInformation& _owner) { m_owner = _owner; };
68 const BasicServiceInformation& getOwner(void) const { return m_owner; };
69
70 void setGraphicsViewFlag(GraphicsViewFlag _flag, bool _active = true) { m_viewFlags.setFlag(_flag, _active); };
71 void setGraphicsViewFlags(const GraphicsViewFlags& _flags) { m_viewFlags = _flags; };
72 const GraphicsViewFlags& getGraphicsViewFlags(void) const { return m_viewFlags; };
73
74 void setGraphicsScene(GraphicsScene* _scene);
75 GraphicsScene* getGraphicsScene(void) { return m_scene; };
76
77 GraphicsItem* getItem(const ot::UID& _itemUid);
78 GraphicsConnectionItem* getConnection(const ot::UID& _connectionUid);
79
80 bool connectionAlreadyExists(const ot::GraphicsConnectionCfg& connection);
81
82 void setDropsEnabled(bool _enabled) { m_dropEnabled = _enabled; };
83
84 void setGraphicsViewName(const std::string& _name) { m_viewName = _name; };
85 const std::string& getGraphicsViewName(void) const { return m_viewName; };
86
87 void addItem(ot::GraphicsItem* _item);
88 void removeItem(const ot::UID& _itemUid, bool bufferConnections = false);
89 std::list<ot::UID> getSelectedItemUIDs(void) const;
90 std::list<GraphicsItem*> getSelectedGraphicsItems(void) const;
91
92 void setSceneMargins(const QMarginsF& _margins) { m_sceneMargins = _margins; };
93 const QMarginsF& getSceneMargins(void) const { return m_sceneMargins; };
94
95 bool addConnectionIfConnectedItemsExist(const GraphicsConnectionCfg& _config);
96
97 void removeConnection(const GraphicsConnectionCfg& _connectionInformation);
98 void removeConnection(const ot::UID& _connectionInformation);
99 ot::UIDList getSelectedConnectionUIDs(void) const;
100 std::list<GraphicsConnectionItem*> getSelectedConnectionItems(void) const;
101
102 void requestConnection(const ot::UID& _fromUid, const std::string& _fromConnector, const ot::UID& _toUid, const std::string& _toConnector);
103
104 void requestConnectionToConnection(const ot::UID& _fromItemUid, const std::string& _fromItemConnector, const ot::UID& _toConnectionUid, const ot::Point2DD& _newControlPoint);
105
106 void notifyItemMoved(const ot::GraphicsItem* _item);
107
108 void notifyItemConfigurationChanged(const ot::GraphicsItem* _item);
109
110 QRectF getVisibleSceneRect(void) const;
111
112 void setReadOnly(bool _isReadOnly) { m_viewStateFlags.setFlag(ViewStateFlag::ReadOnlyState, _isReadOnly); };
113 bool isReadOnly(void) const { return m_viewStateFlags.flagIsSet(ViewStateFlag::ReadOnlyState); };
114
115 Q_SIGNALS:
119 void itemRequested(const QString& _name, const QPointF& _pos);
120
126 void connectionRequested(const ot::UID& _fromUid, const std::string& _fromConnector, const ot::UID& _toUid, const std::string& _toConnector);
127
128 void connectionToConnectionRequested(const ot::UID& _fromItemUid, const std::string& _fromItemConnector, const ot::UID& _toConnectionUid, const ot::Point2DD& _newControlPoint);
129
130 void itemMoved(const ot::UID& _uid, const QPointF& _newPos);
131
133
134 void removeItemsRequested(const ot::UIDList& _items, const ot::UIDList& _connections);
135
137
138 protected:
139 virtual void wheelEvent(QWheelEvent* _event) override;
140 virtual void mousePressEvent(QMouseEvent* _event) override;
141 virtual void mouseReleaseEvent(QMouseEvent* _event) override;
142 virtual void mouseMoveEvent(QMouseEvent* _event) override;
143 virtual void keyPressEvent(QKeyEvent* _event) override;
144 virtual void keyReleaseEvent(QKeyEvent* _event) override;
145 virtual void resizeEvent(QResizeEvent* _event) override;
146
147 virtual void dragEnterEvent(QDragEnterEvent* _event) override;
148 virtual void dropEvent(QDropEvent* _event) override;
149 virtual void dragMoveEvent(QDragMoveEvent* _event) override;
150
151 private Q_SLOTS:
152 void slotCopy(void);
153 void slotPaste(void);
154
155 private:
159 void beginItemMove(void);
160
164 void endItemMove(void);
165
167
168 GraphicsViewFlags m_viewFlags;
169 ViewStateFlags m_viewStateFlags;
170
171 std::string m_viewName;
172 GraphicsScene* m_scene;
173 QMarginsF m_sceneMargins;
174
175 bool m_wheelEnabled;
176 bool m_dropEnabled;
177
178 QPoint m_lastPanPos;
179
180 std::map<ot::UID, ot::GraphicsItem*> m_items;
181 std::map<ot::UID, ot::GraphicsConnectionItem*> m_connections;
182 std::list<GraphicsConnectionCfg> m_connectionCreationBuffer;
183 std::list<GraphicsConnectionCfg> m_itemRemovalConnectionBuffer;
184
185 void addConnection(const GraphicsConnectionCfg& _config);
186 bool connectedGraphicItemsExist(const GraphicsConnectionCfg& _config);
187 };
188
189}
190
mongocxx::pool::entry connection
Definition ConnectionAPI.h:9
#define OT_ADD_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided private 32/64 bit bitfield....
Definition Flags.h:129
#define OT_WIDGETS_API_EXPORT
Definition OTWidgetsAPIExport.h:12
The BasicServiceInformation class is used to hold a service name and type. The BasicServiceInformatio...
Definition BasicServiceInformation.h:21
The Flags class is a wrapper around a enum that allows bitwise operations (flags)....
Definition Flags.h:214
Definition GraphicsConnectionCfg.h:22
Definition GraphicsConnectionItem.h:25
Definition GraphicsCopyInformation.h:20
The GraphicsItemCfg is the base class for all graphics item configurations.
Definition GraphicsItemCfg.h:33
Base class for all OpenTwin GraphicsItems GraphicsItems should be created by the GraphicsFactory and ...
Definition GraphicsItem.h:35
Graphics Scene for ot::GraphicsItem Adding QGraphicsItems to the scene that do not inherit ot::Graphi...
Definition GraphicsScene.h:31
View widget used to display GraphicsItems Note that the View creates its own scene.
Definition GraphicsView.h:37
void itemMoved(const ot::UID &_uid, const QPointF &_newPos)
const BasicServiceInformation & getOwner(void) const
Definition GraphicsView.h:68
void setReadOnly(bool _isReadOnly)
Definition GraphicsView.h:112
virtual QWidget * getQWidget(void) override
Returns a pointer to the root widget of this object.
Definition GraphicsView.h:58
void removeItemsRequested(const ot::UIDList &_items, const ot::UIDList &_connections)
void setGraphicsViewFlag(GraphicsViewFlag _flag, bool _active=true)
Definition GraphicsView.h:70
const QMarginsF & getSceneMargins(void) const
Definition GraphicsView.h:93
ViewStateFlag
Definition GraphicsView.h:47
const std::string & getGraphicsViewName(void) const
Definition GraphicsView.h:85
void itemRequested(const QString &_name, const QPointF &_pos)
Will be emitted when an item was dropped into the scene by the user.
ot::Flags< ViewStateFlag > ViewStateFlags
Definition GraphicsView.h:53
void connectionRequested(const ot::UID &_fromUid, const std::string &_fromConnector, const ot::UID &_toUid, const std::string &_toConnector)
Will be emitted when a connection was "dropped" by the user.
void setGraphicsViewFlags(const GraphicsViewFlags &_flags)
Definition GraphicsView.h:71
bool isReadOnly(void) const
Definition GraphicsView.h:113
void setMouseWheelEnabled(bool _enabled)
Definition GraphicsView.h:64
void setDropsEnabled(bool _enabled)
Definition GraphicsView.h:82
void setGraphicsViewName(const std::string &_name)
Definition GraphicsView.h:84
void setOwner(const BasicServiceInformation &_owner)
Definition GraphicsView.h:67
void itemConfigurationChanged(const ot::GraphicsItemCfg *_newConfig)
void setSceneMargins(const QMarginsF &_margins)
Definition GraphicsView.h:92
GraphicsScene * getGraphicsScene(void)
Definition GraphicsView.h:75
virtual const QWidget * getQWidget(void) const override
Definition GraphicsView.h:59
Flags< GraphicsViewFlag > GraphicsViewFlags
Definition GraphicsView.h:45
void connectionToConnectionRequested(const ot::UID &_fromItemUid, const std::string &_fromItemConnector, const ot::UID &_toConnectionUid, const ot::Point2DD &_newControlPoint)
bool getMouseWheelEnabled(void) const
Definition GraphicsView.h:65
GraphicsViewFlag
Definition GraphicsView.h:40
const GraphicsViewFlags & getGraphicsViewFlags(void) const
Definition GraphicsView.h:72
void itemCopyRequested(const GraphicsCopyInformation *_info)
2D Point with double values
Definition Point2D.h:144
Definition QWidgetInterface.h:18
Definition Connector.h:8
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27
std::list< UID > UIDList
Unique identifier list.
Definition CoreTypes.h:31