QGIS API Documentation 4.1.0-Master (d6fb7a379fb)
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.h"
20#include "qgis_gui.h"
21#include "qgsgui.h"
24
25#include <QDialog>
26#include <QDomElement>
27#include <QMainWindow>
28#include <QPointer>
29#include <QString>
30#include <QToolButton>
31
32#define SIP_NO_FILE
33
34using namespace Qt::StringLiterals;
35
36
37class QgsDockWidget;
38
40
41class GUI_EXPORT QgsNonRejectableDialog : public QDialog
42{
43 Q_OBJECT
44 public:
45 explicit QgsNonRejectableDialog( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
46 void reject() override;
47};
48
59class GUI_EXPORT QgsDockableWidgetHelper : public QObject
60{
61 static inline QgsSettingsTreeNode *sTtreeDockConfigs = QgsGui::sTtreeWidgetGeometry->createNamedListNode( u"docks"_s ) SIP_SKIP;
62
63 static const QgsSettingsEntryBool *sSettingsIsDocked SIP_SKIP;
64 static const QgsSettingsEntryVariant *sSettingsDockGeometry SIP_SKIP;
65 static const QgsSettingsEntryVariant *sSettingsDialogGeometry SIP_SKIP;
66 static const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *sSettingsDockArea SIP_SKIP;
67
68 Q_OBJECT
69 public:
70 enum class Option : int
71 {
72 RaiseTab = 1 << 1,
73 PermanentWidget = 1 << 2,
74 };
75 Q_ENUM( Option )
76 Q_DECLARE_FLAGS( Options, Option )
77
78
87 QgsDockableWidgetHelper(
88 const QString &windowTitle,
89 QWidget *widget,
90 QMainWindow *ownerWindow,
91 const QString &dockId,
92 const QStringList &tabifyWith = QStringList(),
94 bool defaultIsDocked = false,
95 Qt::DockWidgetArea defaultDockArea = Qt::DockWidgetArea::RightDockWidgetArea,
96 Options options = Options()
97 );
98
99 ~QgsDockableWidgetHelper() override;
100
105 bool isDocked() const { return mIsDocked; }
106
108 void writeXml( QDomElement &viewDom );
109 void readXml( const QDomElement &viewDom );
110
112 void setWidget( QWidget *widget );
114 QWidget *widget() { return mWidget; }
115
117 QgsDockWidget *dockWidget();
119 QDialog *dialog();
120
122 void setWindowTitle( const QString &title );
124 QString windowTitle() const { return mWindowTitle; }
125
127 void setDockObjectName( const QString &name );
129 QString dockObjectName() const;
130
136 void setSettingKeyDockId( const QString &id );
137
142 bool isUserVisible() const;
143
148 QToolButton *createDockUndockToolButton();
149
153 QAction *createDockUndockAction( const QString &title, QWidget *parent );
154
155 bool eventFilter( QObject *watched, QEvent *event ) override;
156
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
181 void reject();
182
183 private:
184 void setupDockWidget( const QStringList &tabSiblings = QStringList() );
185
186 bool mIsDocked = true;
187 QWidget *mWidget = nullptr;
188
189 QPointer<QDialog> mDialog;
190 QRect mDialogGeometry;
191
192 QPointer<QgsDockWidget> mDock;
193 QRect mDockGeometry;
194 bool mIsDockFloating = true;
195 Qt::DockWidgetArea mDockArea = Qt::RightDockWidgetArea;
196
197 QString mWindowTitle;
198 QString mObjectName;
199 QMainWindow *mOwnerWindow = nullptr;
200
201 QStringList mTabifyWith;
202 Options mOptions;
203
204 // Unique identifier of dock
205 QString mUuid;
206
207 QString mSettingKeyDockId;
208
209 friend class TestQgsDockableWidgetHelper;
210};
211
212Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDockableWidgetHelper::Options )
213
214
215
216
217#endif // QGSDOCKABLEWIDGETHELPER_H
DockableWidgetInitialState
Dockable widget initial states.
Definition qgis.h:6776
@ RestorePreviousState
Restore the previous state of this dock.
Definition qgis.h:6777
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)