Skip to content

Commit

Permalink
Gray out and disable choosing active profile
Browse files Browse the repository at this point in the history
- I think this is clearer and also matches the behaviour of the User
  Profiles menu
- Also add ... to indicate a dialog
  • Loading branch information
JuhoErvasti committed Sep 17, 2024
1 parent a1eb314 commit 5eb0a50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions src/app/options/qgsuserprofileselectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/options/qgsuserprofileselectiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();


Expand All @@ -58,6 +59,7 @@ class APP_EXPORT QgsUserProfileSelectionDialog : public QDialog, private Ui::Qgs

private:
QgsUserProfileManager *mManager = nullptr;
QString mActiveProfile;
void populateProfileList();


Expand Down
7 changes: 4 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down

0 comments on commit 5eb0a50

Please sign in to comment.