QtCanpool 3.3.0
载入中...
搜索中...
未找到
docksubwindow.cpp
浏览该文件的文档.
1
5#include "docksubwindow.h"
7#include "dockgroup.h"
8#include "dockpanel.h"
9
10#include <QMenu>
11#include <QSettings>
12
14
15class DockSubWindowPrivate
16{
17public:
18 QX_DECLARE_PUBLIC(DockSubWindow)
19public:
20 DockSubWindowPrivate();
21public:
22 DockGroup *m_group;
23};
24
25DockSubWindowPrivate::DockSubWindowPrivate()
26{
27}
28
29DockSubWindow::DockSubWindow(DockGroup *parent)
30 : Super(parent)
31{
33 Q_D(DockSubWindow);
34 d->m_group = parent;
35}
36
41
42void DockSubWindow::fillViewMenu(QMenu *menu, const std::vector<DockSubWindow *> &moveTo)
43{
44 Q_D(DockSubWindow);
45 auto widgetsMap = dockWidgetsMap();
46 for (auto iter = widgetsMap.begin(); iter != widgetsMap.end(); ++iter) {
47 auto widget = iter.value()->widget();
48 auto action = iter.value()->toggleViewAction();
49
50 DockGroup *grp = dynamic_cast<DockGroup *>(widget);
51 if (grp) {
52 auto subMenu = menu->addMenu(iter.key());
53
54 subMenu->addAction(action);
55 subMenu->addSeparator();
56
57 grp->setupMenu(subMenu, moveTo);
58 } else {
59 menu->addAction(action);
60 }
61 }
62
63 if (d->m_group->canCreateNewGroups()) {
64 // see how this works, to create it in the right place,
65 // and also to have load perspective work when some groups are missing
66 menu->addSeparator();
67
68 menu->addAction(new CreateChildDockAction(d->m_group, menu));
69
70 if (d->m_group->topLevelGroup()->subWindow() != this)
71 menu->addAction(new DestroyGroupAction(d->m_group, menu));
72 }
73}
74
75void DockSubWindow::fillMoveMenu(QMenu *menu, const std::vector<DockSubWindow *> &moveTo)
76{
77 auto widgetsMap = dockWidgetsMap();
78 for (auto iter = widgetsMap.begin(); iter != widgetsMap.end(); ++iter) {
79 auto subMenu = menu->addMenu(iter.key());
80
81 for (auto sw : moveTo) {
82 // iterate over all possible target managers
83 if (sw == this) {
84 // if dock is already in mgr, no reason to move it there
85 } else if (sw == subWindow(iter.value())) {
86 // if target is the group itself, can't move it there, would make no sense
87 } else {
88 subMenu->addAction(new MoveDockWidgetAction(iter.value(), sw, subMenu));
89 }
90 }
91 }
92}
93
95{
96 std::vector<DockSubWindow *> childrens = allSubWindows(true, true);
97
98 for (auto child : childrens)
99 child->addPerspective(name);
100}
101
103{
104 std::vector<DockSubWindow *> childrens = allSubWindows(true, true);
105
106 for (auto child : childrens)
107 child->openPerspective(name);
108}
109
111{
112 std::vector<DockSubWindow *> childrens = allSubWindows(true, true);
113
114 for (auto child : childrens)
115 child->removePerspectives(child->perspectiveNames());
116}
117
118void DockSubWindow::loadPerspectivesRec(QSettings &settings)
119{
120 std::vector<DockSubWindow *> childrens = allSubWindows(true, true);
121
122 for (auto child : childrens) {
123 settings.beginGroup(child->getPersistGroupName());
124 child->loadPerspectives(settings);
125 settings.endGroup();
126 }
127}
128
129void DockSubWindow::savePerspectivesRec(QSettings &settings) const
130{
131 std::vector<DockSubWindow *> childrens = allSubWindows(true, true);
132
133 for (auto child : childrens) {
134 settings.beginGroup(child->getPersistGroupName());
135 child->savePerspectives(settings);
136 settings.endGroup();
137 }
138}
139
141{
142 DockGroup *group = widget ? dynamic_cast<DockGroup *>(widget->widget()) : nullptr;
143 return (group) ? group->subWindow() : nullptr;
144}
145
146void DockSubWindow::childWindows(std::vector<DockSubWindow *> &subs, bool rec) const
147{
148 auto widgets = getWidgetsInGUIOrder();
149 for (auto widget : widgets) {
150 DockSubWindow *sw = subWindow(widget);
151 if (sw) {
152 subs.push_back(sw);
153 if (rec) { // recursion
154 sw->childWindows(subs, rec);
155 }
156 }
157 }
158}
159
160std::vector<DockSubWindow *> DockSubWindow::allSubWindows(bool includeThis, bool rec) const
161{
162 std::vector<DockSubWindow *> sws;
163 if (includeThis)
164 sws.push_back(const_cast<DockSubWindow *>(this));
165 childWindows(sws, rec);
166 return sws;
167}
168
169std::vector<std::pair<DockSubWindow *, DockWidget *>> DockSubWindow::allDockWidgets(bool includeThis, bool rec) const
170{
171 std::vector<std::pair<DockSubWindow *, DockWidget *>> widgets;
172 for (auto sw : allSubWindows(includeThis, rec)) {
173 for (auto widget : sw->getWidgetsInGUIOrder())
174 widgets.push_back(std::make_pair(sw, widget));
175 }
176 return widgets;
177}
178
180{
181 Q_D(DockSubWindow);
182 return d->m_group->objectName();
183}
184
185#define CHILD_PREFIX QString("Child-")
187{
188 QString group = "Top";
189 if (!getGroupName().isEmpty())
191 return group;
192}
193
194QString DockSubWindow::getGroupNameFromPersistGroupName(QString persistGroupName)
195{
196 if (persistGroupName.startsWith(CHILD_PREFIX)) {
197 persistGroupName = persistGroupName.mid(CHILD_PREFIX.size());
198 } else {
199 assert(false);
200 }
201 return persistGroupName;
202}
203
205{
206 Q_D(DockSubWindow);
207 return d->m_group;
208}
209
210QMap<QString, QStringList> DockSubWindow::getGroupContents()
211{
212 QMap<QString, QStringList> result;
213 std::vector<DockSubWindow *> childrens = allSubWindows(true, true);
214 for (auto child : childrens) {
215 result[child->getPersistGroupName()] = child->dockWidgetsMap().keys();
216 }
217 return result;
218}
219
221{
222 DockPanel *defaultPos = nullptr;
223 if (dockPanelCount() != 0)
224 defaultPos = dockPanel(dockPanelCount() - 1);
225 return defaultPos;
226}
227
228std::vector<DockWidget *> DockSubWindow::getWidgetsInGUIOrder() const
229{
230 std::vector<DockWidget *> result;
231 result.reserve(dockWidgetsMap().size());
232 for (int i = 0; i != dockPanelCount(); ++i) {
233 for (auto widget : dockPanel(i)->dockWidgets())
234 result.push_back(widget);
235 }
236 return result;
237}
238
DockPanel * dockPanel(int index) const
void setupMenu(QMenu *menu, const std::vector< DockSubWindow * > &moveTo)
DockSubWindow * subWindow() const
DockPanel manages multiple instances of DockWidgets.
Definition dockpanel.h:31
QList< DockWidget * > dockWidgets() const
void openPerspectiveRec(const QString &name)
QMap< QString, QStringList > getGroupContents()
void savePerspectivesRec(QSettings &Settings) const
DockPanel * getInsertDefaultPos()
void loadPerspectivesRec(QSettings &Settings)
void childWindows(std::vector< DockSubWindow * > &subs, bool rec) const
static QString getGroupNameFromPersistGroupName(QString persistGroupName)
std::vector< DockSubWindow * > allSubWindows(bool includeThis, bool rec) const
std::vector< DockWidget * > getWidgetsInGUIOrder() const
std::vector< std::pair< DockSubWindow *, DockWidget * > > allDockWidgets(bool includeThis, bool rec) const
virtual ~DockSubWindow() override
void addPerspectiveRec(const QString &name)
void fillViewMenu(QMenu *menu, const std::vector< DockSubWindow * > &moveTo)
static DockSubWindow * subWindow(DockWidget *widget)
void fillMoveMenu(QMenu *menu, const std::vector< DockSubWindow * > &moveTo)
The DockWidget class provides a widget that can be docked inside a DockWindow or floated as a top-lev...
Definition dockwidget.h:31
QWidget * widget() const
Returns the widget for the dock widget.
The central dock window that maintains the complete docking system.
Definition dockwindow.h:36
QMap< QString, DockWidget * > dockWidgetsMap() const
This function returns a readable reference to the internal dock widgets map so that it is possible to...
#define CHILD_PREFIX
#define QX_INIT_PRIVATE(Class)
#define QX_DECLARE_PUBLIC(Class)
#define QX_FINI_PRIVATE()
#define QX_DOCK_END_NAMESPACE
#define QX_DOCK_BEGIN_NAMESPACE
const char * name
Definition qxtheme.cpp:25