From 5eb0a50442444acb8cfb542bb97a904badcfeabc Mon Sep 17 00:00:00 2001 From: Juho Ervasti Date: Tue, 17 Sep 2024 09:50:07 +0300 Subject: [PATCH] Gray out and disable choosing active profile - I think this is clearer and also matches the behaviour of the User Profiles menu - Also add ... to indicate a dialog --- src/app/main.cpp | 2 +- src/app/options/qgsuserprofileselectiondialog.cpp | 12 ++++++++---- src/app/options/qgsuserprofileselectiondialog.h | 4 +++- src/app/qgisapp.cpp | 7 ++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 36b936ff22e04..4a1d42d687a38 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1099,7 +1099,7 @@ int main( int argc, char *argv[] ) profileName = manager.allProfiles()[0]; break; } - QgsUserProfileSelectionDialog dlg( &manager ); + QgsUserProfileSelectionDialog dlg( &manager, QString() ); if ( dlg.exec() == QDialog::Accepted ) { profileName = dlg.selectedProfileName(); diff --git a/src/app/options/qgsuserprofileselectiondialog.cpp b/src/app/options/qgsuserprofileselectiondialog.cpp index 4262d1b232bc0..f65b0e8eb1e23 100644 --- a/src/app/options/qgsuserprofileselectiondialog.cpp +++ b/src/app/options/qgsuserprofileselectiondialog.cpp @@ -21,11 +21,12 @@ #include "qgsapplication.h" #include "qgsuserprofilemanager.h" #include "qgsnewnamedialog.h" +#include "qnamespace.h" #include "qgsuserprofileselectiondialog.h" -QgsUserProfileSelectionDialog::QgsUserProfileSelectionDialog( QgsUserProfileManager *manager, QWidget *parent ) - : QDialog( parent ), mManager( manager ) +QgsUserProfileSelectionDialog::QgsUserProfileSelectionDialog( QgsUserProfileManager *manager, const QString &activeProfile, QWidget *parent ) + : QDialog( parent ), mManager( manager ), mActiveProfile( activeProfile ) { setupUi( this ); @@ -53,6 +54,9 @@ void QgsUserProfileSelectionDialog::populateProfileList() for ( auto profile : mManager->allProfiles() ) { auto item = new QListWidgetItem( mManager->profileForName( profile )->icon(), profile ); + if ( profile == mActiveProfile ) + item->setBackground( Qt::lightGray ); + mProfileListWidget->addItem( item ); // If the profile is the last used one, select it @@ -71,8 +75,8 @@ QString QgsUserProfileSelectionDialog::selectedProfileName() const void QgsUserProfileSelectionDialog::accept() { - // Accept only if an item is selected - if ( mProfileListWidget->currentItem() != nullptr && mProfileListWidget->currentItem()->isSelected() ) + // Accept only if an item is selected and not the already active profile + if ( mProfileListWidget->currentItem() != nullptr && mProfileListWidget->currentItem()->isSelected() && mProfileListWidget->currentItem()->text() != mActiveProfile ) { QDialog::accept(); } diff --git a/src/app/options/qgsuserprofileselectiondialog.h b/src/app/options/qgsuserprofileselectiondialog.h index 6f545651dac7a..f5e38df1e5029 100644 --- a/src/app/options/qgsuserprofileselectiondialog.h +++ b/src/app/options/qgsuserprofileselectiondialog.h @@ -40,9 +40,10 @@ class APP_EXPORT QgsUserProfileSelectionDialog : public QDialog, private Ui::Qgs /** * Constructor for QgsUserProfileSelectionDialog. * \param manager QgsUserProfileManager manager that will be used to fill the list of profiles + * \param activeProfile QString current profile * \param parent parent widget */ - explicit QgsUserProfileSelectionDialog( QgsUserProfileManager *manager, QWidget *parent = nullptr ); + explicit QgsUserProfileSelectionDialog( QgsUserProfileManager *manager, const QString &activeProfile, QWidget *parent = nullptr ); virtual ~QgsUserProfileSelectionDialog(); @@ -58,6 +59,7 @@ class APP_EXPORT QgsUserProfileSelectionDialog : public QDialog, private Ui::Qgs private: QgsUserProfileManager *mManager = nullptr; + QString mActiveProfile; void populateProfileList(); diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 119a13c1de4a9..5c890d9533299 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -3548,11 +3548,12 @@ void QgisApp::refreshProfileMenu() mConfigMenu->addSeparator( ); - QAction *openProfileSelectionDialog = mConfigMenu->addAction( tr( "Open Profile Selector" ) ); + QAction *openProfileSelectionDialog = mConfigMenu->addAction( tr( "Open Profile Selector…" ) ); openProfileSelectionDialog->setObjectName( "mActionOpenProfileSelector" ); - connect( openProfileSelectionDialog, &QAction::triggered, this, [this]() + connect( openProfileSelectionDialog, &QAction::triggered, this, [this, activeName]() { - auto dlg = QgsUserProfileSelectionDialog( userProfileManager() ); + auto dlg = QgsUserProfileSelectionDialog( userProfileManager(), activeName ); + if ( dlg.exec() == QDialog::Accepted ) { userProfileManager()->loadUserProfile( dlg.selectedProfileName() );