QGIS API Documentation 3.99.0-Master (0c964c3d988)
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 <QString>
29#include <QToolButton>
30
31#define SIP_NO_FILE
32
33using namespace Qt::StringLiterals;
34
35
36class QgsDockWidget;
37
39
40class GUI_EXPORT QgsNonRejectableDialog : public QDialog
41{
42 Q_OBJECT
43 public:
44 explicit QgsNonRejectableDialog( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
45 void reject() override;
46};
47
58class GUI_EXPORT QgsDockableWidgetHelper : public QObject
59{
60 static inline QgsSettingsTreeNode *sTtreeDockConfigs = QgsGui::sTtreeWidgetGeometry->createNamedListNode( u"docks"_s ) SIP_SKIP;
61
62 static const QgsSettingsEntryBool *sSettingsIsDocked SIP_SKIP;
63 static const QgsSettingsEntryVariant *sSettingsDockGeometry SIP_SKIP;
64 static const QgsSettingsEntryVariant *sSettingsDialogGeometry SIP_SKIP;
65 static const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *sSettingsDockArea SIP_SKIP;
66
67 Q_OBJECT
68 public:
69 enum class OpeningMode : int
70 {
71 RespectSetting,
72 ForceDocked,
73 ForceDialog,
74 };
75
76 enum class Option : int
77 {
78 RaiseTab = 1 << 1,
79 PermanentWidget = 1 << 2,
80 };
81 Q_ENUM( Option )
82 Q_DECLARE_FLAGS( Options, Option )
83
84
93 QgsDockableWidgetHelper(
94 const QString &windowTitle,
95 QWidget *widget,
96 QMainWindow *ownerWindow,
97 const QString &dockId,
98 const QStringList &tabifyWith = QStringList(),
99 OpeningMode openingMode = OpeningMode::RespectSetting,
100 bool defaultIsDocked = false,
101 Qt::DockWidgetArea defaultDockArea = Qt::DockWidgetArea::RightDockWidgetArea,
102 Options options = Options()
103 );
104
105 ~QgsDockableWidgetHelper() override;
106
111 bool isDocked() const { return mIsDocked; }
112
114 void writeXml( QDomElement &viewDom );
115 void readXml( const QDomElement &viewDom );
116
118 void setWidget( QWidget *widget );
120 QWidget *widget() { return mWidget; }
121
123 QgsDockWidget *dockWidget();
125 QDialog *dialog();
126
128 void setWindowTitle( const QString &title );
130 QString windowTitle() const { return mWindowTitle; }
131
133 void setDockObjectName( const QString &name );
135 QString dockObjectName() const;
136
141 bool isUserVisible() const;
142
147 QToolButton *createDockUndockToolButton();
148
152 QAction *createDockUndockAction( const QString &title, QWidget *parent );
153
154 bool eventFilter( QObject *watched, QEvent *event ) override;
155
156 static std::function<void( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool )> sAddTabifiedDockWidgetFunction;
157 static std::function<QString()> sAppStylesheetFunction;
158
159 static QMainWindow *sOwnerWindow;
160
161 signals:
162 void closed();
163
164 void dockModeToggled( bool docked );
165
166 void visibilityChanged( bool isVisible );
167
168 public slots:
169 void toggleDockMode( bool docked );
170
171 void setUserVisible( bool visible );
172
173 private:
174 void setupDockWidget( const QStringList &tabSiblings = QStringList() );
175
176 bool mIsDocked = true;
177 QWidget *mWidget = nullptr;
178
179 QPointer<QDialog> mDialog;
180 QRect mDialogGeometry;
181
182 QPointer<QgsDockWidget> mDock;
183 QRect mDockGeometry;
184 bool mIsDockFloating = true;
185 Qt::DockWidgetArea mDockArea = Qt::RightDockWidgetArea;
186
187 QString mWindowTitle;
188 QString mObjectName;
189 QMainWindow *mOwnerWindow = nullptr;
190
191 QStringList mTabifyWith;
192 Options mOptions;
193
194 // Unique identifier of dock
195 QString mUuid;
196
197
198 const QString mSettingKeyDockId;
199};
200
201Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDockableWidgetHelper::Options )
202
203
204
205
206#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:75
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
#define SIP_SKIP
Definition qgis_sip.h:133
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)