Skip to content

Commit

Permalink
remove old method
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored and nyalldawson committed Feb 21, 2025
1 parent 72d106e commit 4c67afa
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A custom dock widget for code editors.
#include "qgscodeeditordockwidget.h"
%End
public:
QgsCodeEditorDockWidget( const QString &windowGeometrySettingsKey = QString(), bool usePersistentWidget = false );
QgsCodeEditorDockWidget( const QString &dockId = QString(), bool usePersistentWidget = false );
%Docstring
Constructor for QgsCodeEditorDockWidget, with the specified window geometry settings key.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A custom dock widget for code editors.
#include "qgscodeeditordockwidget.h"
%End
public:
QgsCodeEditorDockWidget( const QString &windowGeometrySettingsKey = QString(), bool usePersistentWidget = false );
QgsCodeEditorDockWidget( const QString &dockId = QString(), bool usePersistentWidget = false );
%Docstring
Constructor for QgsCodeEditorDockWidget, with the specified window geometry settings key.

Expand Down
3 changes: 2 additions & 1 deletion src/app/3d/qgs3dmapcanvaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )

onTotalPendingJobsCountChanged();

mDockableWidgetHelper = new QgsDockableWidgetHelper( isDocked, mCanvasName, this, QgisApp::instance() );
mDockableWidgetHelper = new QgsDockableWidgetHelper( mCanvasName, this, QgisApp::instance(), mCanvasName, QStringList(), isDocked ? QgsDockableWidgetHelper::OpeningMode::ForceDocked : QgsDockableWidgetHelper::OpeningMode::RespectSetting );

if ( QDialog *dialog = mDockableWidgetHelper->dialog() )
{
QFontMetrics fm( font() );
Expand Down
3 changes: 2 additions & 1 deletion src/app/elevation/qgselevationprofilewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ QgsElevationProfileWidget::QgsElevationProfileWidget( const QString &name )
} );
setLayout( layout );

mDockableWidgetHelper = new QgsDockableWidgetHelper( true, mCanvasName, this, QgisApp::instance(), Qt::BottomDockWidgetArea, QStringList(), true );
mDockableWidgetHelper = new QgsDockableWidgetHelper( mCanvasName, this, QgisApp::instance(), mCanvasName, QStringList(), QgsDockableWidgetHelper::OpeningMode::RespectSetting, false, Qt::DockWidgetArea::BottomDockWidgetArea, QgsDockableWidgetHelper::Option::RaiseTab );

QToolButton *toggleButton = mDockableWidgetHelper->createDockUndockToolButton();
toggleButton->setToolTip( tr( "Dock Elevation Profile View" ) );
toolBar->addWidget( toggleButton );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmapcanvasdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa

connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemeRenamed, this, &QgsMapCanvasDockWidget::currentMapThemeRenamed );

mDockableWidgetHelper = new QgsDockableWidgetHelper( isDocked, mCanvasName, this, QgisApp::instance(), Qt::RightDockWidgetArea );
mDockableWidgetHelper = new QgsDockableWidgetHelper( mCanvasName, this, QgisApp::instance(), mCanvasName, QStringList(), isDocked ? QgsDockableWidgetHelper::OpeningMode::ForceDocked : QgsDockableWidgetHelper::OpeningMode::RespectSetting );
QToolButton *toggleButton = mDockableWidgetHelper->createDockUndockToolButton();
toggleButton->setToolTip( tr( "Dock 2D Map View" ) );
mToolbar->addWidget( toggleButton );
Expand Down
18 changes: 16 additions & 2 deletions src/gui/codeeditors/qgscodeeditordockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@
#include "moc_qgscodeeditordockwidget.cpp"
#include "qgsdockablewidgethelper.h"

QgsCodeEditorDockWidget::QgsCodeEditorDockWidget( const QString &windowGeometrySettingsKey, bool usePersistentWidget )
QgsCodeEditorDockWidget::QgsCodeEditorDockWidget( const QString &dockId, bool usePersistentWidget )
: QWidget( nullptr )
{
mDockableWidgetHelper = new QgsDockableWidgetHelper( true, tr( "Code Editor" ), this, QgsDockableWidgetHelper::sOwnerWindow, Qt::BottomDockWidgetArea, QStringList(), true, windowGeometrySettingsKey, usePersistentWidget );
QgsDockableWidgetHelper::Options options = QgsDockableWidgetHelper::Option::RaiseTab;
if ( usePersistentWidget )
options.setFlag( QgsDockableWidgetHelper::Option::PermanentWidget );

mDockableWidgetHelper = new QgsDockableWidgetHelper(
tr( "Code Editor" ),
this,
QgsDockableWidgetHelper::sOwnerWindow,
dockId,
QStringList(),
QgsDockableWidgetHelper::OpeningMode::RespectSetting,
true,
Qt::BottomDockWidgetArea,
options
);

mDockToggleButton = mDockableWidgetHelper->createDockUndockToolButton();
mDockToggleButton->setToolTip( tr( "Dock Code Editor" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/codeeditors/qgscodeeditordockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GUI_EXPORT QgsCodeEditorDockWidget : public QWidget
*
* If \a usePersistentWidget is TRUE then the widget (either as a dock or window) cannot be destroyed and must be hidden instead.
*/
QgsCodeEditorDockWidget( const QString &windowGeometrySettingsKey = QString(), bool usePersistentWidget = false );
QgsCodeEditorDockWidget( const QString &dockId = QString(), bool usePersistentWidget = false );
~QgsCodeEditorDockWidget() override;

/**
Expand Down
48 changes: 11 additions & 37 deletions src/gui/qgsdockablewidgethelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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

#include <QLayout>
#include <QAction>
Expand All @@ -27,30 +26,14 @@
///@cond PRIVATE

const QgsSettingsEntryBool *QgsDockableWidgetHelper::sSettingsIsDocked = new QgsSettingsEntryBool( QStringLiteral( "is-docked" ), QgsDockableWidgetHelper::sTtreeDockConfigs, false );
const QgsSettingsEntryVariant *QgsDockableWidgetHelper::sSettingsWindowGeometry = new QgsSettingsEntryVariant( QStringLiteral( "geometry" ), QgsDockableWidgetHelper::sTtreeDockConfigs );
const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *QgsDockableWidgetHelper::sSettingsDockArea = new QgsSettingsEntryEnumFlag<Qt::DockWidgetArea>( QStringLiteral( "area" ), QgsDockableWidgetHelper::sTtreeDockConfigs, Qt::RightDockWidgetArea );
const QgsSettingsEntryVariant *QgsDockableWidgetHelper::sSettingsDockGeometry = new QgsSettingsEntryVariant( QStringLiteral( "dock-geometry" ), QgsDockableWidgetHelper::sTtreeDockConfigs );
const QgsSettingsEntryVariant *QgsDockableWidgetHelper::sSettingsDialogGeometry = new QgsSettingsEntryVariant( QStringLiteral( "dialog-geometry" ), QgsDockableWidgetHelper::sTtreeDockConfigs );
const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *QgsDockableWidgetHelper::sSettingsDockArea = new QgsSettingsEntryEnumFlag<Qt::DockWidgetArea>( QStringLiteral( "dock-area" ), QgsDockableWidgetHelper::sTtreeDockConfigs, Qt::RightDockWidgetArea );

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

QgsDockableWidgetHelper::QgsDockableWidgetHelper( bool isDocked, const QString &windowTitle, QWidget *widget, QMainWindow *ownerWindow, Qt::DockWidgetArea defaultDockArea, const QStringList &tabifyWith, bool raiseTab, const QString &windowGeometrySettingsKey, bool usePersistentWidget )
: QObject( nullptr )
, mWidget( widget )
, mDialogGeometry( 0, 0, 0, 0 )
, mIsDockFloating( defaultDockArea == Qt::DockWidgetArea::NoDockWidgetArea )
, mDockArea( defaultDockArea == Qt::DockWidgetArea::NoDockWidgetArea ? Qt::DockWidgetArea::RightDockWidgetArea : defaultDockArea )
, mWindowTitle( windowTitle )
, mOwnerWindow( ownerWindow )
, mTabifyWith( tabifyWith )
, mWindowGeometrySettingsKey( windowGeometrySettingsKey )
, mUuid( QUuid::createUuid().toString() )
{
mOptions.setFlag( Option::RaiseTab, raiseTab );
mOptions.setFlag( Option::PermanentWidget, usePersistentWidget );
toggleDockMode( isDocked );
}

QgsDockableWidgetHelper::QgsDockableWidgetHelper( const QString &windowTitle, QWidget *widget, QMainWindow *ownerWindow, const QString &dockId, const QStringList &tabifyWith, OpeningMode openingMode, bool defaultIsDocked, Qt::DockWidgetArea defaultDockArea, Options options )
: QObject( nullptr )
, mWidget( widget )
Expand Down Expand Up @@ -79,7 +62,7 @@ QgsDockableWidgetHelper::~QgsDockableWidgetHelper()
{
mDockGeometry = mDock->geometry();
if ( !mSettingKeyDockId.isEmpty() )
sSettingsWindowGeometry->setValue( mDock->saveGeometry(), mSettingKeyDockId );
sSettingsDockGeometry->setValue( mDock->saveGeometry(), mSettingKeyDockId );
mIsDockFloating = mDock->isFloating();
if ( mOwnerWindow )
mDockArea = mOwnerWindow->dockWidgetArea( mDock );
Expand All @@ -96,12 +79,8 @@ QgsDockableWidgetHelper::~QgsDockableWidgetHelper()
{
mDialogGeometry = mDialog->geometry();

if ( !mWindowGeometrySettingsKey.isEmpty() )
{
QgsSettings().setValue( mWindowGeometrySettingsKey, mDialog->saveGeometry() );
}
if ( !mSettingKeyDockId.isEmpty() )
sSettingsWindowGeometry->setValue( mDialog->saveGeometry(), mSettingKeyDockId );
sSettingsDialogGeometry->setValue( mDialog->saveGeometry(), mSettingKeyDockId );

mDialog->layout()->removeWidget( mWidget );
mDialog->deleteLater();
Expand Down Expand Up @@ -259,8 +238,8 @@ void QgsDockableWidgetHelper::toggleDockMode( bool docked )
if ( mDialog )
{
// going from window -> dock, so save current window geometry
if ( !mWindowGeometrySettingsKey.isEmpty() )
QgsSettings().setValue( mWindowGeometrySettingsKey, mDialog->saveGeometry() );
if ( !mSettingKeyDockId.isEmpty() )
sSettingsDialogGeometry->setValue( mDialog->saveGeometry(), mSettingKeyDockId );

mDialogGeometry = mDialog->geometry();

Expand Down Expand Up @@ -332,14 +311,9 @@ void QgsDockableWidgetHelper::toggleDockMode( bool docked )
vl->setContentsMargins( 0, 0, 0, 0 );
vl->addWidget( mWidget );

if ( !mWindowGeometrySettingsKey.isEmpty() )
{
QgsSettings settings;
mDialog->restoreGeometry( settings.value( mWindowGeometrySettingsKey ).toByteArray() );
}
else if ( !mSettingKeyDockId.isEmpty() )
if ( !mSettingKeyDockId.isEmpty() )
{
mDialog->restoreGeometry( sSettingsWindowGeometry->value( mSettingKeyDockId ).toByteArray() );
mDialog->restoreGeometry( sSettingsDialogGeometry->value( mSettingKeyDockId ).toByteArray() );
}
else
{
Expand Down Expand Up @@ -455,8 +429,8 @@ void QgsDockableWidgetHelper::setupDockWidget( const QStringList &tabSiblings )
// can only resize properly and set the dock geometry after pending events have been processed,
// so queue the geometry setting on the end of the event loop
QMetaObject::invokeMethod( mDock, [this] {
if (mIsDockFloating && sSettingsWindowGeometry->exists(mSettingKeyDockId))
mDock->restoreGeometry( sSettingsWindowGeometry->value(mSettingKeyDockId).toByteArray() );
if (mIsDockFloating && sSettingsDockGeometry->exists( mSettingKeyDockId ) )
mDock->restoreGeometry( sSettingsDockGeometry->value( mSettingKeyDockId ).toByteArray() );
else
mDock->setGeometry( mDockGeometry ); }, Qt::QueuedConnection );
}
Expand Down
13 changes: 2 additions & 11 deletions src/gui/qgsdockablewidgethelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class GUI_EXPORT QgsDockableWidgetHelper : public QObject
static inline QgsSettingsTreeNode *sTtreeDockConfigs = QgsGui::sTtreeWidgetGeometry->createNamedListNode( QStringLiteral( "docks" ) ) SIP_SKIP;

static const QgsSettingsEntryBool *sSettingsIsDocked SIP_SKIP;
static const QgsSettingsEntryVariant *sSettingsWindowGeometry SIP_SKIP;
static const QgsSettingsEntryVariant *sSettingsDockGeometry SIP_SKIP;
static const QgsSettingsEntryVariant *sSettingsDialogGeometry SIP_SKIP;
static const QgsSettingsEntryEnumFlag<Qt::DockWidgetArea> *sSettingsDockArea SIP_SKIP;

Q_OBJECT
Expand All @@ -77,14 +78,6 @@ class GUI_EXPORT QgsDockableWidgetHelper : public QObject
Q_ENUM( Option )
Q_DECLARE_FLAGS( Options, Option )

/**
* Constructs an object that is responsible of making a docked widget or a window titled \a windowTitle that holds the \a widget
* The ownership of \a widget is returned to \a ownerWindow once the object is destroyed.
*
* If \a usePersistentWidget is TRUE then the \a widget (either as a dock or window) cannot be destroyed and must be hidden instead.
*/
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 );

/**
* Constructs an object that is responsible of making a docked widget or a window titled \a windowTitle that holds the \a widget
* The ownership of \a widget is returned to \a ownerWindow once the object is destroyed.
Expand Down Expand Up @@ -193,8 +186,6 @@ class GUI_EXPORT QgsDockableWidgetHelper : public QObject
QStringList mTabifyWith;
Options mOptions;

QString mWindowGeometrySettingsKey;

// Unique identifier of dock
QString mUuid;

Expand Down

0 comments on commit 4c67afa

Please sign in to comment.