QGIS API Documentation 3.43.0-Master (87898417f79)
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
21#include <QDialog>
22#include <QToolButton>
23#include <QMainWindow>
24#include <QDomElement>
25#include <QPointer>
26
29#include "qgsgui.h"
30
31#define SIP_NO_FILE
32
33class QgsDockWidget;
34
36
37class GUI_EXPORT QgsNonRejectableDialog : public QDialog
38{
39 Q_OBJECT
40 public:
41 explicit QgsNonRejectableDialog( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
42 void reject() override;
43};
44
55class GUI_EXPORT QgsDockableWidgetHelper : public QObject
56{
57 static inline QgsSettingsTreeNode *sTtreeDockConfigs = QgsGui::sTtreeWidgetGeometry->createNamedListNode( QStringLiteral( "docks" ) ) SIP_SKIP;
58
59 static const QgsSettingsEntryBool *sSettingsIsDocked SIP_SKIP;
60 static const QgsSettingsEntryVariant *sSettingsDockGeometry SIP_SKIP;
61 static const QgsSettingsEntryVariant *sSettingsDialogGeometry SIP_SKIP;
62 static const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *sSettingsDockArea SIP_SKIP;
63
64 Q_OBJECT
65 public:
66 enum class OpeningMode : int
67 {
68 RespectSetting,
69 ForceDocked,
70 ForceDialog,
71 };
72
73 enum class Option : int
74 {
75 RaiseTab = 1 << 1,
76 PermanentWidget = 1 << 2,
77 };
78 Q_ENUM( Option )
79 Q_DECLARE_FLAGS( Options, Option )
80
81
90 QgsDockableWidgetHelper(
91 const QString &windowTitle,
92 QWidget *widget,
93 QMainWindow *ownerWindow,
94 const QString &dockId,
95 const QStringList &tabifyWith = QStringList(),
96 OpeningMode openingMode = OpeningMode::RespectSetting,
97 bool defaultIsDocked = false,
98 Qt::DockWidgetArea defaultDockArea = Qt::DockWidgetArea::RightDockWidgetArea,
99 Options options = Options()
100 );
101
102 ~QgsDockableWidgetHelper();
103
106 bool isDocked() const { return mIsDocked; }
107
109 void writeXml( QDomElement &viewDom );
110 void readXml( const QDomElement &viewDom );
111
113 void setWidget( QWidget *widget );
115 QWidget *widget() { return mWidget; }
116
118 QgsDockWidget *dockWidget();
120 QDialog *dialog();
121
123 void setWindowTitle( const QString &title );
125 QString windowTitle() const { return mWindowTitle; }
126
128 void setDockObjectName( const QString &name );
130 QString dockObjectName() const;
131
136 bool isUserVisible() const;
137
142 QToolButton *createDockUndockToolButton();
143
147 QAction *createDockUndockAction( const QString &title, QWidget *parent );
148
149 bool eventFilter( QObject *watched, QEvent *event ) override;
150
151 static std::function<void( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool )> sAddTabifiedDockWidgetFunction;
152 static std::function<QString()> sAppStylesheetFunction;
153
154 static QMainWindow *sOwnerWindow;
155
156 signals:
157 void closed();
158
159 void dockModeToggled( bool docked );
160
161 void visibilityChanged( bool isVisible );
162
163 public slots:
164 void toggleDockMode( bool docked );
165
166 void setUserVisible( bool visible );
167
168 private:
169 void setupDockWidget( const QStringList &tabSiblings = QStringList() );
170
171 bool mIsDocked = true;
172 QWidget *mWidget = nullptr;
173
174 QPointer<QDialog> mDialog;
175 QRect mDialogGeometry;
176
177 QPointer<QgsDockWidget> mDock;
178 QRect mDockGeometry;
179 bool mIsDockFloating = true;
180 Qt::DockWidgetArea mDockArea = Qt::RightDockWidgetArea;
181
182 QString mWindowTitle;
183 QString mObjectName;
184 QMainWindow *mOwnerWindow = nullptr;
185
186 QStringList mTabifyWith;
187 Options mOptions;
188
189 // Unique identifier of dock
190 QString mUuid;
191
192
193 const QString mSettingKeyDockId;
194};
195
196Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDockableWidgetHelper::Options )
197
198
199
200
201#endif // QGSDOCKABLEWIDGETHELPER_H
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.
static QgsSettingsTreeNode * sTtreeWidgetGeometry
Definition qgsgui.h:68
A boolean settings entry.
A template class for enum and flag settings entry.
A variant settings entry.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
#define SIP_SKIP
Definition qgis_sip.h:126
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)