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