Skip to content

Commit 920dba2

Browse files
committedApr 11, 2023
Remember last active dev tools panel between sessions
1 parent 5f62066 commit 920dba2

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
13291329
showDevToolsDock->setObjectName( QStringLiteral( "ShowDevToolsPanel" ) );
13301330
showDevToolsDock->setWhatsThis( tr( "Show Debugging/Development Tools" ) );
13311331

1332+
// store last dev tools tab before populating, as the value will be altered as tabs are created
1333+
const QString lastDevToolsTab = QgsDevToolsPanelWidget::settingLastActiveTab->value();
13321334
mDevToolsWidget = new QgsDevToolsPanelWidget( mDevToolFactories );
13331335
mDevToolsDock->setWidget( mDevToolsWidget );
13341336
// connect( mDevToolsDock, &QDockWidget::visibilityChanged, mActionStyleDock, &QAction::setChecked );
@@ -1969,6 +1971,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
19691971
messageBar()->pushWidget( messageWidget, Qgis::MessageLevel::Warning, 0 );
19701972
} );
19711973
QgsApplication::fontManager()->enableFontDownloadsForSession();
1974+
1975+
mDevToolsWidget->setActiveTab( lastDevToolsTab );
19721976
}
19731977

19741978
QgisApp::QgisApp()

‎src/app/qgsdevtoolspanelwidget.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "qgsdevtoolwidgetfactory.h"
1818
#include "qgsdevtoolwidget.h"
1919
#include "qgspanelwidgetstack.h"
20+
#include "qgssettingsentryimpl.h"
21+
22+
const QgsSettingsEntryString *QgsDevToolsPanelWidget::settingLastActiveTab = new QgsSettingsEntryString( QStringLiteral( "last-active-tab" ), QgsDevToolsPanelWidget::sTreeDevTools, QString(), QStringLiteral( "Last visible tab in developer tools panel" ) );
2023

2124

2225
QgsDevToolsPanelWidget::QgsDevToolsPanelWidget( const QList<QgsDevToolWidgetFactory *> &factories, QWidget *parent )
@@ -30,7 +33,12 @@ QgsDevToolsPanelWidget::QgsDevToolsPanelWidget( const QList<QgsDevToolWidgetFact
3033
for ( QgsDevToolWidgetFactory *factory : factories )
3134
addToolFactory( factory );
3235

33-
connect( mOptionsListWidget, &QListWidget::currentRowChanged, this, &QgsDevToolsPanelWidget::setCurrentTool );
36+
connect( mOptionsListWidget, &QListWidget::currentRowChanged, this, [ = ]( int row )
37+
{
38+
setCurrentTool( row );
39+
settingLastActiveTab->setValue( mOptionsListWidget->currentItem()->data( Qt::UserRole ).toString() );
40+
} );
41+
3442
}
3543

3644
QgsDevToolsPanelWidget::~QgsDevToolsPanelWidget() = default;
@@ -45,6 +53,8 @@ void QgsDevToolsPanelWidget::addToolFactory( QgsDevToolWidgetFactory *factory )
4553

4654
QListWidgetItem *item = new QListWidgetItem( factory->icon(), QString() );
4755
item->setToolTip( factory->title() );
56+
item->setData( Qt::UserRole, factory->title() );
57+
4858
mOptionsListWidget->addItem( item );
4959
const int row = mOptionsListWidget->row( item );
5060
mFactoryPages[factory] = row;
@@ -73,6 +83,21 @@ void QgsDevToolsPanelWidget::removeToolFactory( QgsDevToolWidgetFactory *factory
7383
}
7484
}
7585

86+
void QgsDevToolsPanelWidget::setActiveTab( const QString &title )
87+
{
88+
if ( !title.isEmpty() )
89+
{
90+
for ( int row = 0; row < mOptionsListWidget->count(); ++row )
91+
{
92+
if ( mOptionsListWidget->item( row )->data( Qt::UserRole ).toString() == title )
93+
{
94+
setCurrentTool( row );
95+
break;
96+
}
97+
}
98+
}
99+
}
100+
76101
void QgsDevToolsPanelWidget::setCurrentTool( int row )
77102
{
78103
whileBlocking( mOptionsListWidget )->setCurrentRow( row );

‎src/app/qgsdevtoolspanelwidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "ui_qgsdevtoolswidgetbase.h"
1919
#include "qgis_app.h"
20+
#include "qgssettingstree.h"
2021

2122
class QgsDevToolWidgetFactory;
2223

@@ -25,13 +26,18 @@ class APP_EXPORT QgsDevToolsPanelWidget : public QWidget, private Ui::QgsDevTool
2526
Q_OBJECT
2627
public:
2728

29+
static inline QgsSettingsTreeNode *sTreeDevTools = QgsSettingsTree::sTreeApp->createChildNode( QStringLiteral( "devtools" ) );
30+
static const QgsSettingsEntryString *settingLastActiveTab;
31+
2832
QgsDevToolsPanelWidget( const QList<QgsDevToolWidgetFactory *> &factories, QWidget *parent = nullptr );
2933
~QgsDevToolsPanelWidget() override;
3034

3135
void addToolFactory( QgsDevToolWidgetFactory *factory );
3236

3337
void removeToolFactory( QgsDevToolWidgetFactory *factory );
3438

39+
void setActiveTab( const QString &title );
40+
3541
private slots:
3642

3743
void setCurrentTool( int row );

0 commit comments

Comments
 (0)
Please sign in to comment.