Skip to content

Commit

Permalink
Remember the last used tag when closing the style manager window
Browse files Browse the repository at this point in the history
We intentionally don't remember this between sessions, but just
for the current session only
  • Loading branch information
nyalldawson committed Nov 4, 2021
1 parent cb27c14 commit fa0ae4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gui/symbology/qgsstylemanagerdialog.cpp
Expand Up @@ -168,6 +168,8 @@ bool QgsCheckableStyleModel::setData( const QModelIndex &i, const QVariant &valu

#include "qgsgui.h"

QString QgsStyleManagerDialog::sPreviousTag;

QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent, Qt::WindowFlags flags, bool readOnly )
: QDialog( parent, flags )
, mStyle( style )
Expand Down Expand Up @@ -302,7 +304,9 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
groupTree->setModel( groupModel );
groupTree->setHeaderHidden( true );
populateGroups();
groupTree->setCurrentIndex( groupTree->model()->index( 0, 0 ) );

const QModelIndexList prevIndex = groupTree->model()->match( groupTree->model()->index( 0, 0 ), Qt::UserRole + 1, sPreviousTag, 1, Qt::MatchFixedString | Qt::MatchCaseSensitive | Qt::MatchRecursive );
groupTree->setCurrentIndex( !prevIndex.empty() ? prevIndex.at( 0 ) : groupTree->model()->index( 0, 0 ) );

connect( groupTree->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsStyleManagerDialog::groupChanged );
Expand Down Expand Up @@ -2266,6 +2270,8 @@ void QgsStyleManagerDialog::groupChanged( const QModelIndex &index )
QStringList groupSymbols;

const QString category = index.data( Qt::UserRole + 1 ).toString();
sPreviousTag = category;

if ( mGroupingMode )
{
mModel->setTagId( -1 );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.h
Expand Up @@ -425,6 +425,8 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
bool mSmartGroupVisible = true;
QString mBaseName;

static QString sPreviousTag;

bool addTextFormat();
bool editTextFormat();

Expand Down

0 comments on commit fa0ae4f

Please sign in to comment.