Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Apply suggestions from review
  • Loading branch information
YoannQDQ authored and nyalldawson committed Apr 24, 2023
1 parent a905b1a commit 99f4533
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 162 deletions.
45 changes: 3 additions & 42 deletions python/core/auto_generated/qgsuserprofilemanager.sip.in
Expand Up @@ -29,13 +29,6 @@ A user profile is all settings and anything that used to be found in .qgis3 in t
%End
public:

enum UserProfileSelectionPolicy
{
LastProfile,
DefaultProfile,
AskUser,
};

QgsUserProfileManager( const QString &rootLocation = QString(), QObject *parent = 0 );
%Docstring
User profile manager used to manage user profiles for the instance of QGIS.
Expand Down Expand Up @@ -152,57 +145,25 @@ Set the default profile name from the current active profile.

QString lastProfileName() const;
%Docstring
Returns the name of the lastly closed profile. Empty if its the first time QGIS has been run.
Returns the name of the most recently closed profile. Empty if its the first time QGIS has been run.

.. versionadded:: 3.32
%End


UserProfileSelectionPolicy userProfileSelectionPolicy() const;
Qgis::UserProfileSelectionPolicy userProfileSelectionPolicy() const;
%Docstring
Returns the user profile selection policy.

.. versionadded:: 3.32
%End

void setUserProfileSelectionPolicy( UserProfileSelectionPolicy policy );
void setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy policy );
%Docstring
Sets the user profile selection policy.

:param policy: The policy to use when selecting a user profile.

.. versionadded:: 3.32
%End

int profileSelectorIconSize() const;
%Docstring
Returns the icon size for the profile selector.

.. versionadded:: 3.32
%End

void setProfileSelectorIconSize( int size );
%Docstring
Sets the icon size for the profile selector.

:param size: The size of the icon in pixels.

.. versionadded:: 3.32
%End

bool profileSelectorProfileCreationAllowed() const;
%Docstring
Returns whether the profile selector should allow the creation of new profiles.

.. versionadded:: 3.32
%End

void setProfileSelectorProfileCreationAllowed( bool allow );
%Docstring
Sets whether the profile selector should allow the creation of new profiles.

:param allow: ``True`` if new profiles should be allowed.

.. versionadded:: 3.32
%End

Expand Down
9 changes: 3 additions & 6 deletions src/app/main.cpp
Expand Up @@ -1032,7 +1032,7 @@ int main( int argc, char *argv[] )
switch ( manager.userProfileSelectionPolicy() )
{
// Use the last closed profile (default behavior prior to QGIS 3.32)
case QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile:
case Qgis::UserProfileSelectionPolicy::LastProfile:
profileName = manager.lastProfileName();
// If last used profile no longer exists, use the default profile
if ( !manager.profileExists( profileName ) )
Expand All @@ -1042,7 +1042,7 @@ int main( int argc, char *argv[] )
break;

// Ask the user to select a profile (if more than one exists)
case QgsUserProfileManager::UserProfileSelectionPolicy::AskUser:
case Qgis::UserProfileSelectionPolicy::AskUser:
{
if ( manager.allProfiles().size() == 1 )
{
Expand All @@ -1063,8 +1063,7 @@ int main( int argc, char *argv[] )
}

// Use the default profile
case QgsUserProfileManager::UserProfileSelectionPolicy::DefaultProfile:
default:
case Qgis::UserProfileSelectionPolicy::DefaultProfile:
profileName = manager.defaultProfileName();
break;
}
Expand All @@ -1077,8 +1076,6 @@ int main( int argc, char *argv[] )
profileName = profile->name();
delete profile;



{
// The profile is selected, we can now set up the translation file for QGIS.
QString myUserTranslation = QgsApplication::settingsLocaleUserLocale->value();
Expand Down
37 changes: 16 additions & 21 deletions src/app/options/qgsuserprofileoptions.cpp
Expand Up @@ -29,7 +29,7 @@ QgsUserProfileOptionsWidget::QgsUserProfileOptionsWidget( QWidget *parent )
{
setupUi( this );

auto manager = QgisApp::instance()->userProfileManager();
QgsUserProfileManager *manager = QgisApp::instance()->userProfileManager();

// Disable combobox if default profile is not selected
mDefaultProfileComboBox->setEnabled( false );
Expand All @@ -40,40 +40,35 @@ QgsUserProfileOptionsWidget::QgsUserProfileOptionsWidget( QWidget *parent )
connect( mAskUser, &QRadioButton::toggled, mProfileSelectorGroupBox, &QGroupBox::setEnabled );

// Connect icon size and allow profile creation
mIconSize->setCurrentText( QString::number( manager->profileSelectorIconSize() ) );
mAllowProfileCreation->setChecked( manager->profileSelectorProfileCreationAllowed() );
mIconSize->setCurrentText( QString::number( QSettings().value( QStringLiteral( "/selector/iconSize" ), 24 ).toInt() ) );
connect( mIconSize, &QComboBox::currentTextChanged, this, []( const QString & text )
{
auto manager = QgisApp::instance()->userProfileManager();
manager->setProfileSelectorIconSize( text.toInt() );
} );
connect( mAllowProfileCreation, &QCheckBox::toggled, this, []( bool checked )
{
auto manager = QgisApp::instance()->userProfileManager();
manager->setProfileSelectorProfileCreationAllowed( checked );
QSettings settings;
settings.setValue( QStringLiteral( "/selector/iconSize" ), text.toInt() );
settings.sync();
} );

// Connect change icon button
connect( mChangeIconButton, &QToolButton::clicked, this, &QgsUserProfileOptionsWidget::onChangeIconClicked );
connect( mResetIconButton, &QToolButton::clicked, this, &QgsUserProfileOptionsWidget::onResetIconClicked );

// Init radio buttons
if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile )
if ( manager->userProfileSelectionPolicy() == Qgis::UserProfileSelectionPolicy::LastProfile )
{
mLastProfile->setChecked( true );
}
else if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::AskUser )
else if ( manager->userProfileSelectionPolicy() == Qgis::UserProfileSelectionPolicy::AskUser )
{
mAskUser->setChecked( true );
}
else if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::DefaultProfile )
else if ( manager->userProfileSelectionPolicy() == Qgis::UserProfileSelectionPolicy::DefaultProfile )
{
mDefaultProfile->setChecked( true );
}

// Fill combobox with profiles
mDefaultProfileComboBox->clear();
for ( auto profile : manager->allProfiles() )
for ( const QString &profile : manager->allProfiles() )
{
QIcon icon = manager->profileForName( profile )->icon();
mDefaultProfileComboBox->addItem( icon, profile );
Expand All @@ -87,26 +82,26 @@ QgsUserProfileOptionsWidget::QgsUserProfileOptionsWidget( QWidget *parent )

void QgsUserProfileOptionsWidget::apply()
{
auto manager = QgisApp::instance()->userProfileManager();
QgsUserProfileManager *manager = QgisApp::instance()->userProfileManager();
if ( mLastProfile->isChecked() )
{
manager->setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile );
manager->setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy::LastProfile );
}
else if ( mAskUser->isChecked() )
{
manager->setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy::AskUser );
manager->setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy::AskUser );
}
else if ( mDefaultProfile->isChecked() )
{
manager->setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy::DefaultProfile );
manager->setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy::DefaultProfile );
manager->setDefaultProfileName( mDefaultProfileComboBox->currentText() );
}
}

void QgsUserProfileOptionsWidget::onChangeIconClicked()
{
auto activeProfile = QgisApp::instance()->userProfileManager()->userProfile();
const QString iconPath = QFileDialog::getOpenFileName( this, tr( "Select icon" ), "", tr( "Images (*.png *.jpg *.jpeg *.gif *.bmp *.svg)" ) );
const QgsUserProfile *activeProfile = QgisApp::instance()->userProfileManager()->userProfile();
const QString iconPath = QFileDialog::getOpenFileName( this, tr( "Select Icon" ), "", tr( "Images (*.png *.jpg *.jpeg *.gif *.bmp *.svg)" ) );
if ( !iconPath.isEmpty() )
{
// Remove existing icon files
Expand All @@ -129,7 +124,7 @@ void QgsUserProfileOptionsWidget::onChangeIconClicked()

void QgsUserProfileOptionsWidget::onResetIconClicked()
{
auto activeProfile = QgisApp::instance()->userProfileManager()->userProfile();
const QgsUserProfile *activeProfile = QgisApp::instance()->userProfileManager()->userProfile();
// Remove existing icon files
QDir dir( activeProfile->folder(), "icon.*", QDir::Name, QDir::Files );
for ( const QString &file : dir.entryList() )
Expand Down
16 changes: 6 additions & 10 deletions src/app/options/qgsuserprofileselectiondialog.cpp
Expand Up @@ -16,6 +16,7 @@
#include <QListWidgetItem>
#include <QMessageBox>
#include <QPushButton>
#include <QSettings>

#include "qgsapplication.h"
#include "qgsuserprofilemanager.h"
Expand All @@ -34,16 +35,11 @@ QgsUserProfileSelectionDialog::QgsUserProfileSelectionDialog( QgsUserProfileMana
connect( mProfileListWidget, &QListWidget::itemDoubleClicked, this, &QgsUserProfileSelectionDialog::accept );

// Add a new profile on button click
if ( mManager->profileSelectorProfileCreationAllowed() )
{
connect( mAddProfileButton, &QPushButton::clicked, this, &QgsUserProfileSelectionDialog::onAddProfile );
}
else
{
mAddProfileButton->hide();
}
connect( mAddProfileButton, &QPushButton::clicked, this, &QgsUserProfileSelectionDialog::onAddProfile );

mProfileListWidget->setIconSize( QSize( mManager->profileSelectorIconSize(), mManager->profileSelectorIconSize() ) );
QSettings settings;
int iconSize = settings.value( QStringLiteral( "/selector/iconSize" ), 24 ).toInt();
mProfileListWidget->setIconSize( QSize( iconSize, iconSize ) );

// Fill the list of profiles
mProfileListWidget->clear(); // Clear bogus profiles in the Ui form
Expand Down Expand Up @@ -82,7 +78,7 @@ void QgsUserProfileSelectionDialog::onAddProfile()
dlg.setConflictingNameWarning( tr( "A profile with this name already exists" ) );
dlg.setOverwriteEnabled( false );
dlg.setHintString( tr( "New profile name" ) );
dlg.setWindowTitle( tr( "New profile name" ) );
dlg.setWindowTitle( tr( "New Profile Name" ) );

// Prevent from entering slashes and backslashes
dlg.setRegularExpression( "[^/\\\\]+" );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -15672,7 +15672,7 @@ void QgisApp::newProfile()
dlg.setConflictingNameWarning( tr( "A profile with this name already exists" ) );
dlg.setOverwriteEnabled( false );
dlg.setHintString( tr( "New profile name" ) );
dlg.setWindowTitle( tr( "New profile name" ) );
dlg.setWindowTitle( tr( "New Profile Name" ) );

// Prevent from entering slashes and backslashes
dlg.setRegularExpression( "[^/\\\\]+" );
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgis.h
Expand Up @@ -3415,6 +3415,19 @@ class CORE_EXPORT Qgis
Q_DECLARE_FLAGS( DatabaseProviderConnectionCapabilities2, DatabaseProviderConnectionCapability2 )
Q_FLAG( DatabaseProviderConnectionCapabilities2 )

/**
* User profile selection policy.
*
* \since QGIS 3.32
*/
enum class UserProfileSelectionPolicy : int
{
LastProfile, //!< Open the last closed profile (only mode supported prior to QGIS 3.32)
DefaultProfile, //!< Open a specific profile
AskUser, //!< Let the user choose which profile to open
};
Q_ENUM( UserProfileSelectionPolicy )

/**
* Identify search radius in mm
* \since QGIS 2.3
Expand Down
30 changes: 3 additions & 27 deletions src/core/qgsuserprofilemanager.cpp
Expand Up @@ -128,41 +128,17 @@ void QgsUserProfileManager::updateLastProfileName( )
mSettings->sync();
}

QgsUserProfileManager::UserProfileSelectionPolicy QgsUserProfileManager::userProfileSelectionPolicy() const
Qgis::UserProfileSelectionPolicy QgsUserProfileManager::userProfileSelectionPolicy() const
{
return static_cast< UserProfileSelectionPolicy >( mSettings->value( QStringLiteral( "/core/selectionPolicy" ), 0 ).toInt() );
return static_cast< Qgis::UserProfileSelectionPolicy >( mSettings->value( QStringLiteral( "/core/selectionPolicy" ), 0 ).toInt() );
}

void QgsUserProfileManager::setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy policy )
void QgsUserProfileManager::setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy policy )
{
mSettings->setValue( QStringLiteral( "/core/selectionPolicy" ), static_cast< int >( policy ) );
mSettings->sync();
}

int QgsUserProfileManager::profileSelectorIconSize() const
{
return mSettings->value( QStringLiteral( "/selector/iconSize" ), 24 ).toInt();
}

void QgsUserProfileManager::setProfileSelectorIconSize( int size )
{
mSettings->setValue( QStringLiteral( "/selector/iconSize" ), size );
mSettings->sync();
}

bool QgsUserProfileManager::profileSelectorProfileCreationAllowed() const
{
return mSettings->value( QStringLiteral( "/selector/allowCreation" ), true ).toBool();
}

void QgsUserProfileManager::setProfileSelectorProfileCreationAllowed( bool allow )
{
mSettings->setValue( QStringLiteral( "/selector/allowCreation" ), allow );
mSettings->sync();
}



QStringList QgsUserProfileManager::allProfiles() const
{
return QDir( mRootProfilePath ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );
Expand Down

0 comments on commit 99f4533

Please sign in to comment.