OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
WidgetViewManager.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/Flags.h"
15
16// Qt ADS header
17#include <ads/DockWidget.h>
18
19// Qt header
20#include <QtCore/qobject.h>
21#include <QtCore/qbytearray.h>
22
23// std header
24#include <list>
25#include <string>
26
27class QAction;
28
29namespace ads {
30 class CDockAreaWidget;
31}
32
33namespace ot {
34
35 class WidgetView;
36
39 Q_OBJECT
41 public:
42 typedef std::pair<std::string, WidgetViewBase::ViewType> ViewNameTypeListEntry;
43 typedef std::list<ViewNameTypeListEntry> ViewNameTypeList;
44 typedef std::pair<BasicServiceInformation, ot::WidgetView*> ViewEntry;
45
46 enum ManagerConfigFlag : uint32_t {
47 NoFlags = 0 << 0,
48 InputFocusCentralViewOnFocusChange = 1 << 0,
49 InputFocusSideViewOnFocusChange = 1 << 1,
50 InputFocusToolViewOnFocusChange = 1 << 2,
51 IgnoreInputFocusOnViewInsert = 1 << 3,
52
54 InputFocusOnAnyViewFocusChange = InputFocusCentralViewOnFocusChange | InputFocusSideViewOnFocusChange | InputFocusToolViewOnFocusChange,
55
57 InputFocusOnFocusChangeMask = ~InputFocusOnAnyViewFocusChange,
58
59
64 UseBestAreaFinderOnViewInsert = 1 << 4
65
66 };
68
70 static WidgetViewManager& instance(void);
71
73 void initialize(WidgetViewDockManager* _dockManager = nullptr);
74
76 ads::CDockManager* getDockManager(void) const { return m_dockManager; };
77
78 // ###########################################################################################################################################################################################################################################################################################################################
79
80 // View Management
81
87 bool addView(const BasicServiceInformation& _owner, WidgetView* _view, const WidgetView::InsertFlags& _insertFlags = WidgetView::InsertFlags(WidgetView::NoInsertFlags), WidgetView* _parentView = (WidgetView*)nullptr);
88
92 WidgetView* findView(const std::string& _entityName, WidgetViewBase::ViewType _type) const;
93
97 WidgetView* findViewFromTitle(const std::string& _viewTitle) const;
98
101 bool findViewAndOwner(const std::string& _entityName, WidgetViewBase::ViewType _type, WidgetView*& _view, BasicServiceInformation& _owner) const;
102
104 WidgetView* getViewFromDockWidget(ads::CDockWidget* _dock) const;
105
108 void closeView(WidgetView* _view);
109
113 void closeView(const std::string& _entityName, WidgetViewBase::ViewType _type);
114
118 void closeViews(const BasicServiceInformation& _owner);
119
122 void closeViews(void);
123
127 void forgetView(WidgetView* _view);
128
132 WidgetView* forgetView(const std::string& _entityName, WidgetViewBase::ViewType _type);
133
134 // ###########################################################################################################################################################################################################################################################################################################################
135
136 // View manipulation
137
140 void setCurrentView(const std::string& _entityName, WidgetViewBase::ViewType _type);
141
143 void setCurrentViewFromTitle(const std::string& _viewTitle);
144
147 std::string saveState(int _version = 0) const;
148
152 bool restoreState(std::string _state, int _version = 0);
153
154 void setConfigFlag(ManagerConfigFlag _flag, bool _active = true) { m_config.setFlag(_flag, _active); };
155 void setConfigFlags(const ManagerConfigFlags& _flags) { m_config = _flags; };
156 const ManagerConfigFlags& getConfigFlags(void) const { return m_config; };
157
158 // ###########################################################################################################################################################################################################################################################################################################################
159
160 // Information gathering
161
164 BasicServiceInformation getOwnerFromView(WidgetView* _view) const;
165
168 WidgetView* findViewFromWidget(QWidget* _widget) const;
169
172 bool getViewExists(const std::string& _entityName, WidgetViewBase::ViewType _type) const;
173
176 bool getViewTitleExists(const std::string& _title) const;
177
179 ViewNameTypeList getViewNamesFromOwner(const BasicServiceInformation& _owner) const;
180
182 std::list<std::string> getViewNamesFromOwner(const BasicServiceInformation& _owner, WidgetViewBase::ViewType _type) const;
183
185 bool getAnyViewContentModified(void);
186
188 QAction* getDockToggleAction(void) const { return m_dockToggleRoot; };
189
190 WidgetView* getCurrentlyFocusedView(void) const;
191
192 WidgetView* getLastFocusedView(void) const { return m_focusInfo.last; };
193 WidgetView* getLastFocusedSideView(void) const { return m_focusInfo.lastSide; };
194 WidgetView* getLastFocusedToolView(void) const { return m_focusInfo.lastTool; };
195 WidgetView* getLastFocusedCentralView(void) const { return m_focusInfo.lastCentral; };
196
197 Q_SIGNALS:
198 void viewFocusChanged(WidgetView* _focusedView, WidgetView* _previousView);
202
203 private Q_SLOTS:
204 void slotViewFocused(ads::CDockWidget* _oldFocus, ads::CDockWidget* _newFocus);
205 void slotViewCloseRequested(void);
206 void slotUpdateViewVisibility(void);
207 void slotViewTabClicked(void);
208 void slotViewDataModifiedChanged(void);
209
210 private:
211 enum ManagerState {
212 DefaultState = 0 << 0,
213 InsertViewState = 1 << 0,
214 CloseViewState = 1 << 1,
215 MulticloseViewState = 1 << 2
216 };
217 typedef Flags<ManagerState> ManagerStateFlags;
218
219 struct FocusInfo {
220 WidgetView* last;
221 WidgetView* lastCentral;
222 WidgetView* lastSide;
223 WidgetView* lastTool;
224 };
225
226 WidgetViewManager();
227 ~WidgetViewManager();
228
229 bool getViewExists(const ViewNameTypeListEntry& _entry) const;
230
231 WidgetView* findView(const ViewNameTypeListEntry& _entry) const;
232
237 bool addViewImpl(const BasicServiceInformation& _owner, WidgetView* _view, const WidgetView::InsertFlags& _insertFlags, WidgetView* _parentView);
238
239 ads::CDockAreaWidget* getBestDockArea(const WidgetView* _view) const;
240 ads::CDockAreaWidget* getFirstMatchingView(WidgetViewBase::ViewFlag _viewTypeFlag) const;
241
242 ViewNameTypeList* findViewNameTypeList(const BasicServiceInformation& _owner);
243 ViewNameTypeList* findOrCreateViewNameTypeList(const BasicServiceInformation& _owner);
244
245 WidgetViewDockManager* m_dockManager;
246 QAction* m_dockToggleRoot;
247
248 ManagerStateFlags m_state;
249 ManagerConfigFlags m_config;
250
251 FocusInfo m_focusInfo;
252
253 std::map<BasicServiceInformation, ViewNameTypeList*> m_viewOwnerMap;
254 std::list<ViewEntry> m_views;
255
256 OT_ADD_FRIEND_FLAG_FUNCTIONS(ManagerState)
257 };
258
259}
260
#define OT_ADD_FRIEND_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided private 32/64 bit bitfield....
Definition Flags.h:182
#define OT_ADD_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided private 32/64 bit bitfield....
Definition Flags.h:129
This file contains defines that may be used simplyfy class creation.
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
#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
ViewType
Definition WidgetViewBase.h:49
Definition WidgetViewDockManager.h:18
The WidgetView class is used to integrate the Qt-ADS functionallity into open twin.
Definition WidgetView.h:33
The widget view manager is used to manage widget views.
Definition WidgetViewManager.h:38
void setConfigFlags(const ManagerConfigFlags &_flags)
Definition WidgetViewManager.h:155
QAction * getDockToggleAction(void) const
Return the dock toggle action.
Definition WidgetViewManager.h:188
void viewFocusChanged(WidgetView *_focusedView, WidgetView *_previousView)
std::pair< BasicServiceInformation, ot::WidgetView * > ViewEntry
Definition WidgetViewManager.h:44
void viewCloseRequested(WidgetView *_view)
Flags< ManagerConfigFlag > ManagerConfigFlags
Definition WidgetViewManager.h:67
WidgetView * getLastFocusedView(void) const
Definition WidgetViewManager.h:192
void setConfigFlag(ManagerConfigFlag _flag, bool _active=true)
Definition WidgetViewManager.h:154
std::list< ViewNameTypeListEntry > ViewNameTypeList
Definition WidgetViewManager.h:43
const ManagerConfigFlags & getConfigFlags(void) const
Definition WidgetViewManager.h:156
void viewDataModifiedChanged(ot::WidgetView *_view)
ManagerConfigFlag
Definition WidgetViewManager.h:46
WidgetView * getLastFocusedToolView(void) const
Definition WidgetViewManager.h:194
ads::CDockManager * getDockManager(void) const
Returns the dock manager that is managed by this widget view manager.
Definition WidgetViewManager.h:76
WidgetView * getLastFocusedCentralView(void) const
Definition WidgetViewManager.h:195
WidgetView * getLastFocusedSideView(void) const
Definition WidgetViewManager.h:193
std::pair< std::string, WidgetViewBase::ViewType > ViewNameTypeListEntry
Definition WidgetViewManager.h:42
void viewTabClicked(WidgetView *_view)
Definition WidgetView.h:23
Definition Connector.h:8