From c0a0ddf1e026c0a67f517839b8ca658b1345cf58 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 24 Mar 2023 19:52:15 +0100 Subject: [PATCH] Gui: by default restore the last visited page in the preferences dialog See also: https://forum.freecad.org/viewtopic.php?t=77071 --- src/Gui/CommandStd.cpp | 13 ++++++++++++- src/Gui/DlgPreferencesImp.cpp | 23 ++++++++++++++++++++--- src/Gui/DlgPreferencesImp.h | 3 ++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index cdfd61c2ff..4141b754fd 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -370,8 +370,19 @@ Action * StdCmdDlgPreferences::createAction() void StdCmdDlgPreferences::activated(int iMsg) { Q_UNUSED(iMsg); + + static QString groupName{}; + static int index{}; + Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow()); - cDlg.exec(); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences"); + if (hGrp->GetBool("RestoreGroupPage", true)) { + cDlg.activateGroupPage(groupName, index); + } + + if (cDlg.exec()) { + cDlg.activeGroupPage(groupName, index); + } } //=========================================================================== diff --git a/src/Gui/DlgPreferencesImp.cpp b/src/Gui/DlgPreferencesImp.cpp index cca16af18f..e2b98f5c60 100644 --- a/src/Gui/DlgPreferencesImp.cpp +++ b/src/Gui/DlgPreferencesImp.cpp @@ -305,13 +305,30 @@ void DlgPreferencesImp::activateGroupPage(const QString& group, int index) QListWidgetItem* item = ui->listBox->item(i); if (item->data(GroupNameRole).toString() == group) { ui->listBox->setCurrentItem(item); - auto tabWidget = static_cast(ui->tabWidgetStack->widget(i)); - tabWidget->setCurrentIndex(index); - break; + auto tabWidget = dynamic_cast(ui->tabWidgetStack->widget(i)); + if (tabWidget) { + tabWidget->setCurrentIndex(index); + break; + } } } } +/** + * Returns the group name \a group and position \a index of the active page. + */ +void DlgPreferencesImp::activeGroupPage(QString& group, int& index) const +{ + int row = ui->listBox->currentRow(); + auto item = ui->listBox->item(row); + auto tabWidget = dynamic_cast(ui->tabWidgetStack->widget(row)); + + if (item && tabWidget) { + group = item->data(GroupNameRole).toString(); + index = tabWidget->currentIndex(); + } +} + void DlgPreferencesImp::accept() { this->invalidParameter = false; diff --git a/src/Gui/DlgPreferencesImp.h b/src/Gui/DlgPreferencesImp.h index 762c9a6737..2c5de5d002 100644 --- a/src/Gui/DlgPreferencesImp.h +++ b/src/Gui/DlgPreferencesImp.h @@ -123,7 +123,8 @@ public: void accept() override; void reload(); - void activateGroupPage(const QString& group, int id); + void activateGroupPage(const QString& group, int index); + void activeGroupPage(QString& group, int& index) const; protected: void changeEvent(QEvent *e) override;