Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Backport release-3_40] fix(AttributeEditor): Restore splitter position #59966

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/settings/qgssettingstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 14 additions & 3 deletions src/gui/attributetable/qgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsactionmenu.h"

const std::unique_ptr<QgsSettingsEntryVariant> QgsDualView::conditionalFormattingSplitterState = std::make_unique<QgsSettingsEntryVariant>( 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<QgsSettingsEntryVariant> QgsDualView::attributeEditorSplitterState = std::make_unique<QgsSettingsEntryVariant>( 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 )
Expand All @@ -69,7 +71,10 @@ QgsDualView::QgsDualView( QWidget *parent )
mConditionalFormatWidget->setDockMode( true );

const QgsSettings settings;
mConditionalSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() );
// copy old setting
conditionalFormattingSplitterState->copyValueFromKey( QStringLiteral( "/qgis/attributeTable/splitterState" ), true );
mConditionalSplitter->restoreState( conditionalFormattingSplitterState->value().toByteArray() );
mAttributeEditorViewSplitter->restoreState( attributeEditorSplitterState->value().toByteArray() );

mPreviewColumnsMenu = new QMenu( this );
mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu );
Expand Down Expand Up @@ -114,8 +119,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, const QgsAttributeEditorContext &context, bool loadFeatures, bool showFirstFeature )
Expand Down Expand Up @@ -815,6 +818,14 @@ void QgsDualView::hideEvent( QHideEvent *event )
{
Q_UNUSED( event )
saveRecentDisplayExpressions();

// 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
conditionalFormattingSplitterState->setValue( mConditionalSplitter->saveState() );
attributeEditorSplitterState->setValue( mAttributeEditorViewSplitter->saveState() );
}

void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &masterIndex )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/attributetable/qgsdualview.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class QgsFeatureRequest;
class QgsMapLayerAction;
class QgsScrollArea;
class QgsFieldConditionalFormatWidget;
class QgsSettingsEntryVariant;

/**
* \ingroup gui
Expand Down Expand Up @@ -421,6 +422,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<QgsSettingsEntryVariant> conditionalFormattingSplitterState;
static const std::unique_ptr<QgsSettingsEntryVariant> attributeEditorSplitterState;

QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
QgsAttributeEditorContext mEditorContext;
QgsAttributeTableModel *mMasterModel = nullptr;
Expand Down
Loading