QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsdockablewidgethelper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdockablewidgethelper.h
3 --------------------------------------
4 Date : January 2022
5 Copyright : (C) 2022 by Belgacem Nedjima
6 Email : belgacem dot nedjima at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSDOCKABLEWIDGETHELPER_H
17#define QGSDOCKABLEWIDGETHELPER_H
18
19#include "qgis_gui.h"
20#include "qgsgui.h"
23
24#include <QDialog>
25#include <QDomElement>
26#include <QMainWindow>
27#include <QPointer>
28#include <QToolButton>
29
30#define SIP_NO_FILE
31
32class QgsDockWidget;
33
35
36class GUI_EXPORT QgsNonRejectableDialog : public QDialog
37{
38 Q_OBJECT
39 public:
40 explicit QgsNonRejectableDialog( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
41 void reject() override;
42};
43
54class GUI_EXPORT QgsDockableWidgetHelper : public QObject
55{
56 static inline QgsSettingsTreeNode *sTtreeDockConfigs = QgsGui::sTtreeWidgetGeometry->createNamedListNode( QStringLiteral( "docks" ) ) SIP_SKIP;
57
58 static const QgsSettingsEntryBool *sSettingsIsDocked SIP_SKIP;
59 static const QgsSettingsEntryVariant *sSettingsDockGeometry SIP_SKIP;
60 static const QgsSettingsEntryVariant *sSettingsDialogGeometry SIP_SKIP;
61 static const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *sSettingsDockArea SIP_SKIP;
62
63 Q_OBJECT
64 public:
65 enum class OpeningMode : int
66 {
67 RespectSetting,
68 ForceDocked,
69 ForceDialog,
70 };
71
72 enum class Option : int
73 {
74 RaiseTab = 1 << 1,
75 PermanentWidget = 1 << 2,
76 };
77 Q_ENUM( Option )
78 Q_DECLARE_FLAGS( Options, Option )
79
80
89 QgsDockableWidgetHelper(
90 const QString &windowTitle,
91 QWidget *widget,
92 QMainWindow *ownerWindow,
93 const QString &dockId,
94 const QStringList &tabifyWith = QStringList(),
95 OpeningMode openingMode = OpeningMode::RespectSetting,
96 bool defaultIsDocked = false,
97 Qt::DockWidgetArea defaultDockArea = Qt::DockWidgetArea::RightDockWidgetArea,
98 Options options = Options()
99 );
100
101 ~QgsDockableWidgetHelper() override;
102
107 bool isDocked() const { return mIsDocked; }
108
110 void writeXml( QDomElement &viewDom );
111 void readXml( const QDomElement &viewDom );
112
114 void setWidget( QWidget *widget );
116 QWidget *widget() { return mWidget; }
117
119 QgsDockWidget *dockWidget();
121 QDialog *dialog();
122
124 void setWindowTitle( const QString &title );
126 QString windowTitle() const { return mWindowTitle; }
127
129 void setDockObjectName( const QString &name );
131 QString dockObjectName() const;
132
137 bool isUserVisible() const;
138
143 QToolButton *createDockUndockToolButton();
144
148 QAction *createDockUndockAction( const QString &title, QWidget *parent );
149
150 bool eventFilter( QObject *watched, QEvent *event ) override;
151
152 static std::function<void( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool )> sAddTabifiedDockWidgetFunction;
153 static std::function<QString()> sAppStylesheetFunction;
154
155 static QMainWindow *sOwnerWindow;
156
157 signals:
158 void closed();
159
160 void dockModeToggled( bool docked );
161
162 void visibilityChanged( bool isVisible );
163
164 public slots:
165 void toggleDockMode( bool docked );
166
167 void setUserVisible( bool visible );
168
169 private:
170 void setupDockWidget( const QStringList &tabSiblings = QStringList() );
171
172 bool mIsDocked = true;
173 QWidget *mWidget = nullptr;
174
175 QPointer<QDialog> mDialog;
176 QRect mDialogGeometry;
177
178 QPointer<QgsDockWidget> mDock;
179 QRect mDockGeometry;
180 bool mIsDockFloating = true;
181 Qt::DockWidgetArea mDockArea = Qt::RightDockWidgetArea;
182
183 QString mWindowTitle;
184 QString mObjectName;
185 QMainWindow *mOwnerWindow = nullptr;
186
187 QStringList mTabifyWith;
188 Options mOptions;
189
190 // Unique identifier of dock
191 QString mUuid;
192
193
194 const QString mSettingKeyDockId;
195};
196
197Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDockableWidgetHelper::Options )
198
199
200
201
202#endif // QGSDOCKABLEWIDGETHELPER_H
A QDockWidget subclass with more fine-grained control over how the widget is closed or opened.
static QgsSettingsTreeNode * sTtreeWidgetGeometry
Definition qgsgui.h:72
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
#define SIP_SKIP
Definition qgis_sip.h:134
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)