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"
15
16// Qt header
17#include <QtWidgets/qgraphicsview.h>
20
21// std header
22#include <map>
23#include <list>
24#include <string>
25#include <atomic>
26
27namespace ot {
28
29 class GraphicsItem;
30 class GraphicsScene;
31 class GraphicsItemCfg;
32 class GraphicsConnectionItem;
33
36 class OT_WIDGETS_API_EXPORT GraphicsView : public QGraphicsView, public QWidgetInterface {
37 Q_OBJECT
38 public:
40 NoViewFlags = 0x00,
41 ViewManagesSceneRect = 0x01,
42 IgnoreConnectionByUser = 0x02
43 };
45
47 DefaultState = 0 << 0,
48 ItemMoveInProgress = 1 << 0,
49 MiddleMousePressedState = 1 << 1,
50 ReadOnlyState = 1 << 2
51 };
53
54 GraphicsView(GraphicsScene* _scene = (GraphicsScene*)nullptr);
55 virtual ~GraphicsView();
56
57 virtual QWidget* getQWidget(void) override { return this; };
58
59 void resetView(void);
60 void ensureViewInBounds(void);
61
62 void setMouseWheelEnabled(bool _enabled) { m_wheelEnabled = _enabled; };
63 bool getMouseWheelEnabled(void) const { return m_wheelEnabled; };
64
65 void setOwner(const BasicServiceInformation& _owner) { m_owner = _owner; };
66 const BasicServiceInformation& getOwner(void) const { return m_owner; };
67
68 void setGraphicsViewFlag(GraphicsViewFlag _flag, bool _active = true) { m_viewFlags.setFlag(_flag, _active); };
69 void setGraphicsViewFlags(const GraphicsViewFlags& _flags) { m_viewFlags = _flags; };
70 const GraphicsViewFlags& getGraphicsViewFlags(void) const { return m_viewFlags; };
71
72 void setGraphicsScene(GraphicsScene* _scene);
73 GraphicsScene* getGraphicsScene(void) { return m_scene; };
74
75 GraphicsItem* getItem(const ot::UID& _itemUid);
76 GraphicsConnectionItem* getConnection(const ot::UID& _connectionUid);
77
78 bool connectionAlreadyExists(const ot::GraphicsConnectionCfg& connection);
79
80 void setDropsEnabled(bool _enabled) { m_dropEnabled = _enabled; };
81
82 void setGraphicsViewName(const std::string& _name) { m_viewName = _name; };
83 const std::string& getGraphicsViewName(void) const { return m_viewName; };
84
85 void addItem(ot::GraphicsItem* _item);
86 void removeItem(const ot::UID& _itemUid, bool bufferConnections = false);
87 std::list<ot::UID> getSelectedItemUIDs(void) const;
88 std::list<GraphicsItem*> getSelectedGraphicsItems(void) const;
89
90 void setSceneMargins(const QMarginsF& _margins) { m_sceneMargins = _margins; };
91 const QMarginsF& getSceneMargins(void) const { return m_sceneMargins; };
92
93 bool addConnectionIfConnectedItemsExist(const GraphicsConnectionCfg& _config);
94
95 void removeConnection(const GraphicsConnectionCfg& _connectionInformation);
96 void removeConnection(const ot::UID& _connectionInformation);
97 ot::UIDList getSelectedConnectionUIDs(void) const;
98 std::list<GraphicsConnectionItem*> getSelectedConnectionItems(void) const;
99
100 void requestConnection(const ot::UID& _fromUid, const std::string& _fromConnector, const ot::UID& _toUid, const std::string& _toConnector);
101
102 void requestConnectionToConnection(const ot::UID& _fromItemUid, const std::string& _fromItemConnector, const ot::UID& _toConnectionUid, const ot::Point2DD& _newControlPoint);
103
104 void notifyItemMoved(const ot::GraphicsItem* _item);
105
106 void notifyItemConfigurationChanged(const ot::GraphicsItem* _item);
107
108 QRectF getVisibleSceneRect(void) const;
109
110 void setReadOnly(bool _isReadOnly) { m_viewStateFlags.setFlag(ViewStateFlag::ReadOnlyState, _isReadOnly); };
111 bool isReadOnly(void) const { return m_viewStateFlags.flagIsSet(ViewStateFlag::ReadOnlyState); };
112
113 Q_SIGNALS:
117 void itemRequested(const QString& _name, const QPointF& _pos);
118
124 void connectionRequested(const ot::UID& _fromUid, const std::string& _fromConnector, const ot::UID& _toUid, const std::string& _toConnector);
125
126 void connectionToConnectionRequested(const ot::UID& _fromItemUid, const std::string& _fromItemConnector, const ot::UID& _toConnectionUid, const ot::Point2DD& _newControlPoint);
127
128 void itemMoved(const ot::UID& _uid, const QPointF& _newPos);
129
130 void itemConfigurationChanged(const ot::GraphicsItemCfg* _newConfig);
131
132 void removeItemsRequested(const ot::UIDList& _items, const ot::UIDList& _connections);
133
134 protected:
135 virtual void wheelEvent(QWheelEvent* _event) override;
136 virtual void mousePressEvent(QMouseEvent* _event) override;
137 virtual void mouseReleaseEvent(QMouseEvent* _event) override;
138 virtual void mouseMoveEvent(QMouseEvent* _event) override;
139 virtual void keyPressEvent(QKeyEvent* _event) override;
140 virtual void keyReleaseEvent(QKeyEvent* _event) override;
141 virtual void resizeEvent(QResizeEvent* _event) override;
142
143 virtual void dragEnterEvent(QDragEnterEvent* _event) override;
144 virtual void dropEvent(QDropEvent* _event) override;
145 virtual void dragMoveEvent(QDragMoveEvent* _event) override;
146
147 private:
151 void beginItemMove(void);
152
156 void endItemMove(void);
157
159
160 GraphicsViewFlags m_viewFlags;
161 ViewStateFlags m_viewStateFlags;
162
163 std::string m_viewName;
164 GraphicsScene* m_scene;
165 QMarginsF m_sceneMargins;
166
167 bool m_wheelEnabled;
168 bool m_dropEnabled;
169
170 QPoint m_lastPanPos;
171
172 std::map<ot::UID, ot::GraphicsItem*> m_items;
173 std::map<ot::UID, ot::GraphicsConnectionItem*> m_connections;
174 std::list<GraphicsConnectionCfg> m_connectionCreationBuffer;
175 std::list<GraphicsConnectionCfg> m_itemRemovalConnectionBuffer;
176
177 void addConnection(const GraphicsConnectionCfg& _config);
178 bool connectedGraphicItemsExist(const GraphicsConnectionCfg& _config);
179 };
180
181}
182
mongocxx::pool::entry connection
Definition ConnectionAPI.h:9
#define OT_ADD_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided 32 bit bitfield. Use this at the bottom of t...
Definition Flags.h:60
#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
This class is used to manage flags. Don't forget to add OT_ADD_FLAG_FUNCTIONS and the bottom of your ...
Definition Flags.h:91
Definition GraphicsConnectionCfg.h:22
Definition GraphicsConnectionItem.h:25
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:36
const BasicServiceInformation & getOwner(void) const
Definition GraphicsView.h:66
void setReadOnly(bool _isReadOnly)
Definition GraphicsView.h:110
virtual QWidget * getQWidget(void) override
Returns a pointer to the root widget of this object.
Definition GraphicsView.h:57
void setGraphicsViewFlag(GraphicsViewFlag _flag, bool _active=true)
Definition GraphicsView.h:68
const QMarginsF & getSceneMargins(void) const
Definition GraphicsView.h:91
ViewStateFlag
Definition GraphicsView.h:46
const std::string & getGraphicsViewName(void) const
Definition GraphicsView.h:83
ot::Flags< ViewStateFlag > ViewStateFlags
Definition GraphicsView.h:52
void setGraphicsViewFlags(const GraphicsViewFlags &_flags)
Definition GraphicsView.h:69
bool isReadOnly(void) const
Definition GraphicsView.h:111
void setMouseWheelEnabled(bool _enabled)
Definition GraphicsView.h:62
void setDropsEnabled(bool _enabled)
Definition GraphicsView.h:80
void setGraphicsViewName(const std::string &_name)
Definition GraphicsView.h:82
void setOwner(const BasicServiceInformation &_owner)
Definition GraphicsView.h:65
void setSceneMargins(const QMarginsF &_margins)
Definition GraphicsView.h:90
GraphicsScene * getGraphicsScene(void)
Definition GraphicsView.h:73
Flags< GraphicsViewFlag > GraphicsViewFlags
Definition GraphicsView.h:44
bool getMouseWheelEnabled(void) const
Definition GraphicsView.h:63
GraphicsViewFlag
Definition GraphicsView.h:39
const GraphicsViewFlags & getGraphicsViewFlags(void) const
Definition GraphicsView.h:70
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