Skip to content

Commit

Permalink
Merge pull request qgis#59762 from troopa81/restore_attributeeditor_s…
Browse files Browse the repository at this point in the history
…pliiter

fix(AttributeEditor): Restore splitter position
  • Loading branch information
troopa81 authored Dec 19, 2024
2 parents e55c6bb + 64cf3da commit 99c3852
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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

0 comments on commit 99c3852

Please sign in to comment.