Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move QgsDockableWidgetHelper to a private GUI class
  • Loading branch information
nyalldawson committed Mar 30, 2023
1 parent ab6c1c5 commit eb69eb9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -74,7 +74,6 @@ set(QGIS_APP_SRCS
qgsrecentprojectsitemsmodel.cpp
qgsvectorlayerdigitizingproperties.cpp
qgswelcomepage.cpp
qgsdockablewidgethelper.cpp

qgsmaptooladdfeature.cpp
qgsmaptooladdpart.cpp
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -128,6 +128,8 @@

#include "canvas/qgscanvasrefreshblocker.h"

#include "qgsdockablewidgethelper.h"

#ifdef HAVE_3D
#include "qgs3d.h"
#include "qgs3danimationsettings.h"
Expand Down Expand Up @@ -975,6 +977,15 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers

setDockOptions( dockOptions() | QMainWindow::GroupedDragging );

QgsDockableWidgetHelper::sAddTabifiedDockWidgetFunction = []( Qt::DockWidgetArea dockArea, QDockWidget * dock, const QStringList & tabSiblings, bool raiseTab )
{
QgisApp::instance()->addTabifiedDockWidget( dockArea, dock, tabSiblings, raiseTab );
};
QgsDockableWidgetHelper::sAppStylesheetFunction = []()->QString
{
return QgisApp::instance()->styleSheet();
};

//////////

startProfile( tr( "Checking user database" ) );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -497,6 +497,7 @@ set(QGIS_GUI_SRCS
qgsdial.cpp
qgsdialog.cpp
qgsdirectionallightwidget.cpp
qgsdockablewidgethelper.cpp
qgsdoublevalidator.cpp
qgsdockwidget.cpp
qgsencodingfiledialog.cpp
Expand Down Expand Up @@ -766,6 +767,7 @@ set(QGIS_GUI_HDRS
qgsdial.h
qgsdialog.h
qgsdirectionallightwidget.h
qgsdockablewidgethelper.h
qgsdockwidget.h
qgsdoublevalidator.h
qgsencodingfiledialog.h
Expand Down
Expand Up @@ -17,9 +17,17 @@

#include "qgsdockwidget.h"
#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgssettings.h"

#include <QLayout>
#include <QAction>
#include <QUuid>

///@cond PRIVATE


std::function< void( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool ) > QgsDockableWidgetHelper::sAddTabifiedDockWidgetFunction = []( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool ) {};
std::function< QString( ) > QgsDockableWidgetHelper::sAppStylesheetFunction = [] { return QString(); };

QgsDockableWidgetHelper::QgsDockableWidgetHelper( bool isDocked, const QString &windowTitle, QWidget *widget, QMainWindow *ownerWindow,
Qt::DockWidgetArea defaultDockArea,
Expand Down Expand Up @@ -243,7 +251,7 @@ void QgsDockableWidgetHelper::toggleDockMode( bool docked )
// note -- we explicitly DO NOT set the parent for the dialog, as we want these treated as
// proper top level windows and have their own taskbar entries. See https://github.com/qgis/QGIS/issues/49286
mDialog = new QDialog( nullptr, Qt::Window );
mDialog->setStyleSheet( QgisApp::instance()->styleSheet() );
mDialog->setStyleSheet( sAppStylesheetFunction() );

mDialog->setWindowTitle( mWindowTitle );
QVBoxLayout *vl = new QVBoxLayout();
Expand Down Expand Up @@ -304,11 +312,11 @@ void QgsDockableWidgetHelper::setupDockWidget( const QStringList &tabSiblings )
}
if ( !tabSiblings.isEmpty() )
{
QgisApp::instance()->addTabifiedDockWidget( mDockArea, mDock, tabSiblings, false );
sAddTabifiedDockWidgetFunction( mDockArea, mDock, tabSiblings, false );
}
else if ( mRaiseTab )
{
QgisApp::instance()->addTabifiedDockWidget( mDockArea, mDock, mTabifyWith, mRaiseTab );
sAddTabifiedDockWidgetFunction( mDockArea, mDock, mTabifyWith, mRaiseTab );
}
else
{
Expand Down Expand Up @@ -341,3 +349,5 @@ QAction *QgsDockableWidgetHelper::createDockUndockAction( const QString &title,
connect( toggleAction, &QAction::toggled, this, &QgsDockableWidgetHelper::toggleDockMode );
return toggleAction;
}

///@endcond
Expand Up @@ -16,7 +16,7 @@
#ifndef QGSDOCKABLEWIDGETHELPER_H
#define QGSDOCKABLEWIDGETHELPER_H

#include "qgis_app.h"
#include "qgis_gui.h"

#include <QDialog>
#include <QToolButton>
Expand All @@ -27,14 +27,19 @@

class QgsDockWidget;

///@cond PRIVATE

/**
* This class is responible of displaying a QWidget inside a top level window or a dock widget (only one of the 2 is alive at most).
* The widget is not owned by this class and its ownership is passed to the owner window before this class's object is deleted or
* another widget is set using setWidget() function
*
* \note Not available from Python bindings
*
* \ingroup gui
* \since QGIS 3.24
*/
class APP_EXPORT QgsDockableWidgetHelper : public QObject
class GUI_EXPORT QgsDockableWidgetHelper : public QObject
{
Q_OBJECT
public:
Expand Down Expand Up @@ -79,6 +84,9 @@ class APP_EXPORT QgsDockableWidgetHelper : public QObject
*/
QAction *createDockUndockAction( const QString &title, QWidget *parent );

static std::function< void( Qt::DockWidgetArea, QDockWidget *, const QStringList &, bool ) > sAddTabifiedDockWidgetFunction;
static std::function< QString( ) > sAppStylesheetFunction;

signals:
void closed();

Expand Down Expand Up @@ -113,4 +121,6 @@ class APP_EXPORT QgsDockableWidgetHelper : public QObject
QString mUuid;
};

///@endcond

#endif // QGSDOCKABLEWIDGETHELPER_H

0 comments on commit eb69eb9

Please sign in to comment.