Skip to content

Commit

Permalink
Merge pull request #4956 from jgrocha/profilemenu
Browse files Browse the repository at this point in the history
Fix #16970 (related to PR#4184)
  • Loading branch information
elpaso committed Aug 4, 2017
2 parents 21653c0 + 511521f commit 34ef954
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2298,49 +2298,43 @@ void QgisApp::refreshProfileMenu()
QString activeName = profile->name();
mConfigMenu->setTitle( tr( "&User Profiles" ) );

mConfigMenu->addAction( new QgsMenuHeaderWidgetAction( tr( "Active Profile" ), mConfigMenu ) );

mConfigMenu->addAction( new QgsMenuHeaderWidgetAction( tr( "Profiles" ), mConfigMenu ) );
QAction *profileSection = mConfigMenu->actions().at( 1 );

mConfigMenu->addAction( new QgsMenuHeaderWidgetAction( tr( "Config" ), mConfigMenu ) );
QAction *configSection = mConfigMenu->actions().at( 2 );

QAction *openProfileFolderAction = mConfigMenu->addAction( tr( "Open active profile folder" ) );
connect( openProfileFolderAction, &QAction::triggered, this, [this]()
{
QDesktopServices::openUrl( QUrl::fromLocalFile( userProfileManager()->userProfile()->folder() ) );
} );

QAction *newProfileAction = mConfigMenu->addAction( tr( "New profile" ) );
connect( newProfileAction, &QAction::triggered, this, &QgisApp::newProfile );
QActionGroup *profileGroup = new QActionGroup( this );
profileGroup->setExclusive( true );

Q_FOREACH ( const QString &name, userProfileManager()->allProfiles() )
{
profile = userProfileManager()->profileForName( name );
// Qt 5.5 has no parent default as nullptr
QAction *action = new QAction( profile->icon(), profile->alias(), nullptr );
action->setToolTip( profile->folder() );
action->setCheckable( true );
profileGroup->addAction( action );
mConfigMenu->addAction( action );
delete profile;

if ( name == activeName )
{
mConfigMenu->insertAction( profileSection, action );
action->setChecked( true );
}
else
{
mConfigMenu->insertAction( configSection, action );
connect( action, &QAction::triggered, this, [this, name]()
{
userProfileManager()->loadUserProfile( name );
} );
}
connect( action, &QAction::triggered, this, [this, name]()
{
userProfileManager()->loadUserProfile( name );
} );
}

if ( userProfileManager()->allProfiles().count() == 1 )
mConfigMenu->addSeparator( );

QAction *openProfileFolderAction = mConfigMenu->addAction( tr( "Open active profile folder" ) );
connect( openProfileFolderAction, &QAction::triggered, this, [this]()
{
profileSection->setVisible( false );
}
QDesktopServices::openUrl( QUrl::fromLocalFile( userProfileManager()->userProfile()->folder() ) );
} );

QAction *newProfileAction = mConfigMenu->addAction( tr( "New profile" ) );
connect( newProfileAction, &QAction::triggered, this, &QgisApp::newProfile );
}

void QgisApp::createProfileMenu()
Expand Down

0 comments on commit 34ef954

Please sign in to comment.