QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
27#define SIP_NO_FILE
28
29class QgsDockWidget;
30
32
33class GUI_EXPORT QgsNonRejectableDialog : public QDialog
34{
35 Q_OBJECT
36 public:
37 explicit QgsNonRejectableDialog( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
38 void reject() override;
39};
40
51class GUI_EXPORT QgsDockableWidgetHelper : public QObject
52{
53 Q_OBJECT
54 public:
61 QgsDockableWidgetHelper( bool isDocked, const QString &windowTitle, QWidget *widget, QMainWindow *ownerWindow, Qt::DockWidgetArea defaultDockArea = Qt::NoDockWidgetArea, const QStringList &tabifyWith = QStringList(), bool raiseTab = false, const QString &windowGeometrySettingsKey = QString(), bool usePersistentWidget = false );
62 ~QgsDockableWidgetHelper();
63
65 void writeXml( QDomElement &viewDom );
66 void readXml( const QDomElement &viewDom );
67
69 void setWidget( QWidget *widget );
71 QWidget *widget() { return mWidget; }
72
74 QgsDockWidget *dockWidget();
76 QDialog *dialog();
77
79 void setWindowTitle( const QString &title );
81 QString windowTitle() const { return mWindowTitle; }
82
84 void setDockObjectName( const QString &name );
86 QString dockObjectName() const;
87
92 bool isUserVisible() const;
93
98 QToolButton *createDockUndockToolButton();
99
103 QAction *createDockUndockAction( const QString &title, QWidget *parent );
104
105 bool eventFilter( QObject *watched, QEvent *event ) override;
106
107 static std::function<void( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool )> sAddTabifiedDockWidgetFunction;
108 static std::function<QString()> sAppStylesheetFunction;
109
110 static QMainWindow *sOwnerWindow;
111
112 signals:
113 void closed();
114
115 void dockModeToggled( bool docked );
116
117 void visibilityChanged( bool isVisible );
118
119 public slots:
120 void toggleDockMode( bool docked );
121
122 void setUserVisible( bool visible );
123
124 private:
125 void setupDockWidget( const QStringList &tabSiblings = QStringList() );
126
127 bool mIsDocked = true;
128 QWidget *mWidget = nullptr;
129
130 QPointer<QDialog> mDialog;
131 QRect mDialogGeometry;
132
133 QPointer<QgsDockWidget> mDock;
134 QRect mDockGeometry;
135 bool mIsDockFloating = true;
136 Qt::DockWidgetArea mDockArea = Qt::RightDockWidgetArea;
137
138 QString mWindowTitle;
139 QString mObjectName;
140 QMainWindow *mOwnerWindow = nullptr;
141
142 QStringList mTabifyWith;
143 bool mRaiseTab = false;
144
145 QString mWindowGeometrySettingsKey;
146
147 // Unique identifier of dock
148 QString mUuid;
149
150 bool mUsePersistentWidget = false;
151};
152
154
155#endif // QGSDOCKABLEWIDGETHELPER_H
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.