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