From 05c9d6c8cd3834c4d5280b780597f1831dcf0b50 Mon Sep 17 00:00:00 2001 From: Julien Cabieces Date: Thu, 5 Dec 2024 15:28:43 +0100 Subject: [PATCH 1/4] fix(AttributeEditor): Restore splitter position --- src/gui/attributetable/qgsdualview.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 7e6f1178e597..720fb6608dd5 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -70,6 +70,7 @@ QgsDualView::QgsDualView( QWidget *parent ) const QgsSettings settings; mConditionalSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() ); + mAttributeEditorViewSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeEditor/splitterState" ), QByteArray() ).toByteArray() ); mPreviewColumnsMenu = new QMenu( this ); mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu ); @@ -115,8 +116,6 @@ QgsDualView::QgsDualView( QWidget *parent ) QgsDualView::~QgsDualView() { - QgsSettings settings; - settings.setValue( QStringLiteral( "/qgis/attributeTable/splitterState" ), mConditionalSplitter->saveState() ); } void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, @@ -835,6 +834,15 @@ void QgsDualView::hideEvent( QHideEvent *event ) { Q_UNUSED( event ) saveRecentDisplayExpressions(); + + // Better to save settings here than in destructor. This this last can be called after a new + // project is loaded. So, when Qgis::ProjectFlag::RememberAttributeTableWindowsBetweenSessions is set, + // a new QgsDualView is created at project loading and we restore the old settings before saving the + // new one. + // And also, we override close event to just hide in QgsDockableWidgetHelper::eventFilter, that's why hideEvent + QgsSettings settings; + settings.setValue( QStringLiteral( "/qgis/attributeTable/splitterState" ), mConditionalSplitter->saveState() ); + settings.setValue( QStringLiteral( "/qgis/attributeEditor/splitterState" ), mAttributeEditorViewSplitter->saveState() ); } void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &masterIndex ) From b494fc1ec5cda285c5e6fb9e85d449627e8f9839 Mon Sep 17 00:00:00 2001 From: Julien Cabieces Date: Thu, 5 Dec 2024 17:01:51 +0100 Subject: [PATCH 2/4] fix(AttributeEditor) use new settings API --- src/gui/attributetable/qgsdualview.cpp | 15 +++++++++------ src/gui/attributetable/qgsdualview.h | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 720fb6608dd5..57fa5bd1ab44 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -48,6 +48,8 @@ #include "qgsvectorlayereditbuffer.h" #include "qgsactionmenu.h" +const std::unique_ptr QgsDualView::conditionnalFormattingSplitterState = std::make_unique( QStringLiteral( "attribute-table-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of conditionnal formatting splitter's layout so it could be restored when opening attribute table view." ) ); +const std::unique_ptr QgsDualView::attributeEditorSplitterState = std::make_unique( QStringLiteral( "attribute-editor-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of attribute editor splitter's layout so it could be restored when opening attribute editor view." ) ); QgsDualView::QgsDualView( QWidget *parent ) : QStackedWidget( parent ) @@ -69,8 +71,10 @@ QgsDualView::QgsDualView( QWidget *parent ) mConditionalFormatWidget->setDockMode( true ); const QgsSettings settings; - mConditionalSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() ); - mAttributeEditorViewSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeEditor/splitterState" ), QByteArray() ).toByteArray() ); + // copy old setting + conditionnalFormattingSplitterState->copyValueFromKey( QStringLiteral( "/qgis/attributeTable/splitterState" ), true ); + mConditionalSplitter->restoreState( conditionnalFormattingSplitterState->value().toByteArray() ); + mAttributeEditorViewSplitter->restoreState( attributeEditorSplitterState->value().toByteArray() ); mPreviewColumnsMenu = new QMenu( this ); mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu ); @@ -835,14 +839,13 @@ void QgsDualView::hideEvent( QHideEvent *event ) Q_UNUSED( event ) saveRecentDisplayExpressions(); - // Better to save settings here than in destructor. This this last can be called after a new + // Better to save settings here than in destructor. This last can be called after a new // project is loaded. So, when Qgis::ProjectFlag::RememberAttributeTableWindowsBetweenSessions is set, // a new QgsDualView is created at project loading and we restore the old settings before saving the // new one. // And also, we override close event to just hide in QgsDockableWidgetHelper::eventFilter, that's why hideEvent - QgsSettings settings; - settings.setValue( QStringLiteral( "/qgis/attributeTable/splitterState" ), mConditionalSplitter->saveState() ); - settings.setValue( QStringLiteral( "/qgis/attributeEditor/splitterState" ), mAttributeEditorViewSplitter->saveState() ); + conditionnalFormattingSplitterState->setValue( mConditionalSplitter->saveState() ); + attributeEditorSplitterState->setValue( mAttributeEditorViewSplitter->saveState() ); } void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &masterIndex ) diff --git a/src/gui/attributetable/qgsdualview.h b/src/gui/attributetable/qgsdualview.h index 9e70f217b5f7..92907ff44e0d 100644 --- a/src/gui/attributetable/qgsdualview.h +++ b/src/gui/attributetable/qgsdualview.h @@ -32,6 +32,7 @@ class QgsFeatureRequest; class QgsMapLayerAction; class QgsScrollArea; class QgsFieldConditionalFormatWidget; +class QgsSettingsEntryVariant; /** * \ingroup gui @@ -427,6 +428,9 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas //! Returns TRUE if the expression dialog has been accepted bool modifySort(); + static const std::unique_ptr conditionnalFormattingSplitterState; + static const std::unique_ptr attributeEditorSplitterState; + QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr; QgsAttributeEditorContext mEditorContext; QgsAttributeTableModel *mMasterModel = nullptr; From 9921db1e6ff9ad0a7481c66a434c5445fabce1df Mon Sep 17 00:00:00 2001 From: Julien Cabieces Date: Mon, 9 Dec 2024 15:17:41 +0100 Subject: [PATCH 3/4] fix(AttributeEdtitor): typo --- src/gui/attributetable/qgsdualview.cpp | 8 ++++---- src/gui/attributetable/qgsdualview.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 57fa5bd1ab44..d043e1c00a1d 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -48,7 +48,7 @@ #include "qgsvectorlayereditbuffer.h" #include "qgsactionmenu.h" -const std::unique_ptr QgsDualView::conditionnalFormattingSplitterState = std::make_unique( QStringLiteral( "attribute-table-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of conditionnal formatting splitter's layout so it could be restored when opening attribute table view." ) ); +const std::unique_ptr QgsDualView::conditionalFormattingSplitterState = std::make_unique( QStringLiteral( "attribute-table-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of conditionnal formatting splitter's layout so it could be restored when opening attribute table view." ) ); const std::unique_ptr QgsDualView::attributeEditorSplitterState = std::make_unique( QStringLiteral( "attribute-editor-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of attribute editor splitter's layout so it could be restored when opening attribute editor view." ) ); QgsDualView::QgsDualView( QWidget *parent ) @@ -72,8 +72,8 @@ QgsDualView::QgsDualView( QWidget *parent ) const QgsSettings settings; // copy old setting - conditionnalFormattingSplitterState->copyValueFromKey( QStringLiteral( "/qgis/attributeTable/splitterState" ), true ); - mConditionalSplitter->restoreState( conditionnalFormattingSplitterState->value().toByteArray() ); + conditionalFormattingSplitterState->copyValueFromKey( QStringLiteral( "/qgis/attributeTable/splitterState" ), true ); + mConditionalSplitter->restoreState( conditionalFormattingSplitterState->value().toByteArray() ); mAttributeEditorViewSplitter->restoreState( attributeEditorSplitterState->value().toByteArray() ); mPreviewColumnsMenu = new QMenu( this ); @@ -844,7 +844,7 @@ void QgsDualView::hideEvent( QHideEvent *event ) // a new QgsDualView is created at project loading and we restore the old settings before saving the // new one. // And also, we override close event to just hide in QgsDockableWidgetHelper::eventFilter, that's why hideEvent - conditionnalFormattingSplitterState->setValue( mConditionalSplitter->saveState() ); + conditionalFormattingSplitterState->setValue( mConditionalSplitter->saveState() ); attributeEditorSplitterState->setValue( mAttributeEditorViewSplitter->saveState() ); } diff --git a/src/gui/attributetable/qgsdualview.h b/src/gui/attributetable/qgsdualview.h index 92907ff44e0d..7908330726b7 100644 --- a/src/gui/attributetable/qgsdualview.h +++ b/src/gui/attributetable/qgsdualview.h @@ -428,7 +428,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas //! Returns TRUE if the expression dialog has been accepted bool modifySort(); - static const std::unique_ptr conditionnalFormattingSplitterState; + static const std::unique_ptr conditionalFormattingSplitterState; static const std::unique_ptr attributeEditorSplitterState; QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr; From 64cf3da49ad8c40dd35b8f4d56ec0d2b101144b7 Mon Sep 17 00:00:00 2001 From: Julien Cabieces Date: Mon, 16 Dec 2024 17:43:22 +0100 Subject: [PATCH 4/4] fix(Settings): Move window state settings in its own group --- src/core/settings/qgssettingstree.h | 1 + src/gui/attributetable/qgsdualview.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/settings/qgssettingstree.h b/src/core/settings/qgssettingstree.h index fdfcdd690522..b7b52788c4cd 100644 --- a/src/core/settings/qgssettingstree.h +++ b/src/core/settings/qgssettingstree.h @@ -65,6 +65,7 @@ class CORE_EXPORT QgsSettingsTree static inline QgsSettingsTreeNode *sTreeAnnotations = treeRoot()->createChildNode( QStringLiteral( "annotations" ) ); static inline QgsSettingsTreeNode *sTreeNetworkCache = treeRoot()->createChildNode( QStringLiteral( "cache" ) ); static inline QgsSettingsTreeNode *sTreeAttributeTable = treeRoot()->createChildNode( QStringLiteral( "attribute-table" ) ); + static inline QgsSettingsTreeNode *sTreeWindowState = sTreeGui->createChildNode( QStringLiteral( "window-state" ) ); #endif diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index d043e1c00a1d..0559da53201c 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -48,8 +48,8 @@ #include "qgsvectorlayereditbuffer.h" #include "qgsactionmenu.h" -const std::unique_ptr QgsDualView::conditionalFormattingSplitterState = std::make_unique( QStringLiteral( "attribute-table-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of conditionnal formatting splitter's layout so it could be restored when opening attribute table view." ) ); -const std::unique_ptr QgsDualView::attributeEditorSplitterState = std::make_unique( QStringLiteral( "attribute-editor-splitter-state" ), QgsSettingsTree::sTreeGui, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of attribute editor splitter's layout so it could be restored when opening attribute editor view." ) ); +const std::unique_ptr QgsDualView::conditionalFormattingSplitterState = std::make_unique( QStringLiteral( "attribute-table-splitter-state" ), QgsSettingsTree::sTreeWindowState, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of conditionnal formatting splitter's layout so it could be restored when opening attribute table view." ) ); +const std::unique_ptr QgsDualView::attributeEditorSplitterState = std::make_unique( QStringLiteral( "attribute-editor-splitter-state" ), QgsSettingsTree::sTreeWindowState, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), QStringLiteral( "State of attribute editor splitter's layout so it could be restored when opening attribute editor view." ) ); QgsDualView::QgsDualView( QWidget *parent ) : QStackedWidget( parent )