Skip to content

Commit 99f4533

Browse files
YoannQDQnyalldawson
authored andcommittedApr 24, 2023
Apply suggestions from review
1 parent a905b1a commit 99f4533

File tree

9 files changed

+55
-162
lines changed

9 files changed

+55
-162
lines changed
 

‎python/core/auto_generated/qgsuserprofilemanager.sip.in

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ A user profile is all settings and anything that used to be found in .qgis3 in t
2929
%End
3030
public:
3131

32-
enum UserProfileSelectionPolicy
33-
{
34-
LastProfile,
35-
DefaultProfile,
36-
AskUser,
37-
};
38-
3932
QgsUserProfileManager( const QString &rootLocation = QString(), QObject *parent = 0 );
4033
%Docstring
4134
User profile manager used to manage user profiles for the instance of QGIS.
@@ -152,57 +145,25 @@ Set the default profile name from the current active profile.
152145

153146
QString lastProfileName() const;
154147
%Docstring
155-
Returns the name of the lastly closed profile. Empty if its the first time QGIS has been run.
148+
Returns the name of the most recently closed profile. Empty if its the first time QGIS has been run.
156149

157150
.. versionadded:: 3.32
158151
%End
159152

160153

161-
UserProfileSelectionPolicy userProfileSelectionPolicy() const;
154+
Qgis::UserProfileSelectionPolicy userProfileSelectionPolicy() const;
162155
%Docstring
163156
Returns the user profile selection policy.
164157

165158
.. versionadded:: 3.32
166159
%End
167160

168-
void setUserProfileSelectionPolicy( UserProfileSelectionPolicy policy );
161+
void setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy policy );
169162
%Docstring
170163
Sets the user profile selection policy.
171164

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

174-
.. versionadded:: 3.32
175-
%End
176-
177-
int profileSelectorIconSize() const;
178-
%Docstring
179-
Returns the icon size for the profile selector.
180-
181-
.. versionadded:: 3.32
182-
%End
183-
184-
void setProfileSelectorIconSize( int size );
185-
%Docstring
186-
Sets the icon size for the profile selector.
187-
188-
:param size: The size of the icon in pixels.
189-
190-
.. versionadded:: 3.32
191-
%End
192-
193-
bool profileSelectorProfileCreationAllowed() const;
194-
%Docstring
195-
Returns whether the profile selector should allow the creation of new profiles.
196-
197-
.. versionadded:: 3.32
198-
%End
199-
200-
void setProfileSelectorProfileCreationAllowed( bool allow );
201-
%Docstring
202-
Sets whether the profile selector should allow the creation of new profiles.
203-
204-
:param allow: ``True`` if new profiles should be allowed.
205-
206167
.. versionadded:: 3.32
207168
%End
208169

‎src/app/main.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ int main( int argc, char *argv[] )
10321032
switch ( manager.userProfileSelectionPolicy() )
10331033
{
10341034
// Use the last closed profile (default behavior prior to QGIS 3.32)
1035-
case QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile:
1035+
case Qgis::UserProfileSelectionPolicy::LastProfile:
10361036
profileName = manager.lastProfileName();
10371037
// If last used profile no longer exists, use the default profile
10381038
if ( !manager.profileExists( profileName ) )
@@ -1042,7 +1042,7 @@ int main( int argc, char *argv[] )
10421042
break;
10431043

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

10651065
// Use the default profile
1066-
case QgsUserProfileManager::UserProfileSelectionPolicy::DefaultProfile:
1067-
default:
1066+
case Qgis::UserProfileSelectionPolicy::DefaultProfile:
10681067
profileName = manager.defaultProfileName();
10691068
break;
10701069
}
@@ -1077,8 +1076,6 @@ int main( int argc, char *argv[] )
10771076
profileName = profile->name();
10781077
delete profile;
10791078

1080-
1081-
10821079
{
10831080
// The profile is selected, we can now set up the translation file for QGIS.
10841081
QString myUserTranslation = QgsApplication::settingsLocaleUserLocale->value();

‎src/app/options/qgsuserprofileoptions.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ QgsUserProfileOptionsWidget::QgsUserProfileOptionsWidget( QWidget *parent )
2929
{
3030
setupUi( this );
3131

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

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

4242
// Connect icon size and allow profile creation
43-
mIconSize->setCurrentText( QString::number( manager->profileSelectorIconSize() ) );
44-
mAllowProfileCreation->setChecked( manager->profileSelectorProfileCreationAllowed() );
43+
mIconSize->setCurrentText( QString::number( QSettings().value( QStringLiteral( "/selector/iconSize" ), 24 ).toInt() ) );
4544
connect( mIconSize, &QComboBox::currentTextChanged, this, []( const QString & text )
4645
{
47-
auto manager = QgisApp::instance()->userProfileManager();
48-
manager->setProfileSelectorIconSize( text.toInt() );
49-
} );
50-
connect( mAllowProfileCreation, &QCheckBox::toggled, this, []( bool checked )
51-
{
52-
auto manager = QgisApp::instance()->userProfileManager();
53-
manager->setProfileSelectorProfileCreationAllowed( checked );
46+
QSettings settings;
47+
settings.setValue( QStringLiteral( "/selector/iconSize" ), text.toInt() );
48+
settings.sync();
5449
} );
5550

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

6055
// Init radio buttons
61-
if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile )
56+
if ( manager->userProfileSelectionPolicy() == Qgis::UserProfileSelectionPolicy::LastProfile )
6257
{
6358
mLastProfile->setChecked( true );
6459
}
65-
else if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::AskUser )
60+
else if ( manager->userProfileSelectionPolicy() == Qgis::UserProfileSelectionPolicy::AskUser )
6661
{
6762
mAskUser->setChecked( true );
6863
}
69-
else if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::DefaultProfile )
64+
else if ( manager->userProfileSelectionPolicy() == Qgis::UserProfileSelectionPolicy::DefaultProfile )
7065
{
7166
mDefaultProfile->setChecked( true );
7267
}
7368

7469
// Fill combobox with profiles
7570
mDefaultProfileComboBox->clear();
76-
for ( auto profile : manager->allProfiles() )
71+
for ( const QString &profile : manager->allProfiles() )
7772
{
7873
QIcon icon = manager->profileForName( profile )->icon();
7974
mDefaultProfileComboBox->addItem( icon, profile );
@@ -87,26 +82,26 @@ QgsUserProfileOptionsWidget::QgsUserProfileOptionsWidget( QWidget *parent )
8782

8883
void QgsUserProfileOptionsWidget::apply()
8984
{
90-
auto manager = QgisApp::instance()->userProfileManager();
85+
QgsUserProfileManager *manager = QgisApp::instance()->userProfileManager();
9186
if ( mLastProfile->isChecked() )
9287
{
93-
manager->setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile );
88+
manager->setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy::LastProfile );
9489
}
9590
else if ( mAskUser->isChecked() )
9691
{
97-
manager->setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy::AskUser );
92+
manager->setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy::AskUser );
9893
}
9994
else if ( mDefaultProfile->isChecked() )
10095
{
101-
manager->setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy::DefaultProfile );
96+
manager->setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy::DefaultProfile );
10297
manager->setDefaultProfileName( mDefaultProfileComboBox->currentText() );
10398
}
10499
}
105100

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

130125
void QgsUserProfileOptionsWidget::onResetIconClicked()
131126
{
132-
auto activeProfile = QgisApp::instance()->userProfileManager()->userProfile();
127+
const QgsUserProfile *activeProfile = QgisApp::instance()->userProfileManager()->userProfile();
133128
// Remove existing icon files
134129
QDir dir( activeProfile->folder(), "icon.*", QDir::Name, QDir::Files );
135130
for ( const QString &file : dir.entryList() )

‎src/app/options/qgsuserprofileselectiondialog.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QListWidgetItem>
1717
#include <QMessageBox>
1818
#include <QPushButton>
19+
#include <QSettings>
1920

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

3637
// Add a new profile on button click
37-
if ( mManager->profileSelectorProfileCreationAllowed() )
38-
{
39-
connect( mAddProfileButton, &QPushButton::clicked, this, &QgsUserProfileSelectionDialog::onAddProfile );
40-
}
41-
else
42-
{
43-
mAddProfileButton->hide();
44-
}
38+
connect( mAddProfileButton, &QPushButton::clicked, this, &QgsUserProfileSelectionDialog::onAddProfile );
4539

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

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

8783
// Prevent from entering slashes and backslashes
8884
dlg.setRegularExpression( "[^/\\\\]+" );

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15672,7 +15672,7 @@ void QgisApp::newProfile()
1567215672
dlg.setConflictingNameWarning( tr( "A profile with this name already exists" ) );
1567315673
dlg.setOverwriteEnabled( false );
1567415674
dlg.setHintString( tr( "New profile name" ) );
15675-
dlg.setWindowTitle( tr( "New profile name" ) );
15675+
dlg.setWindowTitle( tr( "New Profile Name" ) );
1567615676

1567715677
// Prevent from entering slashes and backslashes
1567815678
dlg.setRegularExpression( "[^/\\\\]+" );

‎src/core/qgis.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,19 @@ class CORE_EXPORT Qgis
34153415
Q_DECLARE_FLAGS( DatabaseProviderConnectionCapabilities2, DatabaseProviderConnectionCapability2 )
34163416
Q_FLAG( DatabaseProviderConnectionCapabilities2 )
34173417

3418+
/**
3419+
* User profile selection policy.
3420+
*
3421+
* \since QGIS 3.32
3422+
*/
3423+
enum class UserProfileSelectionPolicy : int
3424+
{
3425+
LastProfile, //!< Open the last closed profile (only mode supported prior to QGIS 3.32)
3426+
DefaultProfile, //!< Open a specific profile
3427+
AskUser, //!< Let the user choose which profile to open
3428+
};
3429+
Q_ENUM( UserProfileSelectionPolicy )
3430+
34183431
/**
34193432
* Identify search radius in mm
34203433
* \since QGIS 2.3

‎src/core/qgsuserprofilemanager.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,41 +128,17 @@ void QgsUserProfileManager::updateLastProfileName( )
128128
mSettings->sync();
129129
}
130130

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

136-
void QgsUserProfileManager::setUserProfileSelectionPolicy( QgsUserProfileManager::UserProfileSelectionPolicy policy )
136+
void QgsUserProfileManager::setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy policy )
137137
{
138138
mSettings->setValue( QStringLiteral( "/core/selectionPolicy" ), static_cast< int >( policy ) );
139139
mSettings->sync();
140140
}
141141

142-
int QgsUserProfileManager::profileSelectorIconSize() const
143-
{
144-
return mSettings->value( QStringLiteral( "/selector/iconSize" ), 24 ).toInt();
145-
}
146-
147-
void QgsUserProfileManager::setProfileSelectorIconSize( int size )
148-
{
149-
mSettings->setValue( QStringLiteral( "/selector/iconSize" ), size );
150-
mSettings->sync();
151-
}
152-
153-
bool QgsUserProfileManager::profileSelectorProfileCreationAllowed() const
154-
{
155-
return mSettings->value( QStringLiteral( "/selector/allowCreation" ), true ).toBool();
156-
}
157-
158-
void QgsUserProfileManager::setProfileSelectorProfileCreationAllowed( bool allow )
159-
{
160-
mSettings->setValue( QStringLiteral( "/selector/allowCreation" ), allow );
161-
mSettings->sync();
162-
}
163-
164-
165-
166142
QStringList QgsUserProfileManager::allProfiles() const
167143
{
168144
return QDir( mRootProfilePath ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );

‎src/core/qgsuserprofilemanager.h

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QFileSystemWatcher>
2020

2121

22+
#include "qgis.h"
2223
#include "qgis_sip.h"
2324
#include "qgis_core.h"
2425
#include "qgserror.h"
@@ -44,18 +45,6 @@ class CORE_EXPORT QgsUserProfileManager : public QObject
4445

4546
public:
4647

47-
/**
48-
* User profile selection policy.
49-
*
50-
* \since QGIS 3.32
51-
*/
52-
enum UserProfileSelectionPolicy
53-
{
54-
LastProfile = 0, //!< Open the last closed profile (only mode supported prior to QGIS 3.32)
55-
DefaultProfile, //!< Open a specific profile
56-
AskUser, //!< Let the user choose which profile to open
57-
};
58-
5948
/**
6049
* User profile manager used to manage user profiles for the instance of QGIS.
6150
*/
@@ -155,7 +144,7 @@ class CORE_EXPORT QgsUserProfileManager : public QObject
155144
void setDefaultFromActive();
156145

157146
/**
158-
* Returns the name of the lastly closed profile. Empty if its the first time QGIS has been run.
147+
* Returns the name of the most recently closed profile. Empty if its the first time QGIS has been run.
159148
* \since QGIS 3.32
160149
*/
161150
QString lastProfileName() const;
@@ -167,43 +156,17 @@ class CORE_EXPORT QgsUserProfileManager : public QObject
167156
void updateLastProfileName() SIP_SKIP;
168157

169158
/**
170-
* Returns the user profile selection policy.
171-
* \since QGIS 3.32
172-
*/
173-
UserProfileSelectionPolicy userProfileSelectionPolicy() const;
174-
175-
/**
176-
* Sets the user profile selection policy.
177-
* \param policy The policy to use when selecting a user profile.
178-
* \since QGIS 3.32
179-
*/
180-
void setUserProfileSelectionPolicy( UserProfileSelectionPolicy policy );
181-
182-
/**
183-
* Returns the icon size for the profile selector.
184-
* \since QGIS 3.32
185-
*/
186-
int profileSelectorIconSize() const;
187-
188-
/**
189-
* Sets the icon size for the profile selector.
190-
* \param size The size of the icon in pixels.
191-
* \since QGIS 3.32
192-
*/
193-
void setProfileSelectorIconSize( int size );
194-
195-
/**
196-
* Returns whether the profile selector should allow the creation of new profiles.
159+
* Returns the user profile selection policy.
197160
* \since QGIS 3.32
198161
*/
199-
bool profileSelectorProfileCreationAllowed() const;
162+
Qgis::UserProfileSelectionPolicy userProfileSelectionPolicy() const;
200163

201164
/**
202-
* Sets whether the profile selector should allow the creation of new profiles.
203-
* \param allow TRUE if new profiles should be allowed.
165+
* Sets the user profile selection policy.
166+
* \param policy The policy to use when selecting a user profile.
204167
* \since QGIS 3.32
205168
*/
206-
void setProfileSelectorProfileCreationAllowed( bool allow );
169+
void setUserProfileSelectionPolicy( Qgis::UserProfileSelectionPolicy policy );
207170

208171
/**
209172
* Returns the profile found for a given name.

‎src/ui/qgsuserprofileoptionswidgetbase.ui

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<item>
1818
<widget class="QGroupBox" name="mProfilePolicyGroupBox">
1919
<property name="title">
20-
<string>Which profile should be used when QGIS starts ?</string>
20+
<string>Startup Profile</string>
2121
</property>
2222
<layout class="QGridLayout" name="gridLayout">
2323
<item row="5" column="0" colspan="2">
@@ -79,21 +79,14 @@
7979
<string>Profile Selector</string>
8080
</property>
8181
<layout class="QFormLayout" name="formLayout">
82-
<item row="0" column="0" colspan="2">
83-
<widget class="QCheckBox" name="mAllowProfileCreation">
84-
<property name="text">
85-
<string>Let user create a new profile when starting QGIS</string>
86-
</property>
87-
</widget>
88-
</item>
89-
<item row="1" column="0">
82+
<item row="0" column="0">
9083
<widget class="QLabel" name="mIconSizeLabel">
9184
<property name="text">
9285
<string>Icon size</string>
9386
</property>
9487
</widget>
9588
</item>
96-
<item row="1" column="1">
89+
<item row="0" column="1">
9790
<widget class="QComboBox" name="mIconSize">
9891
<property name="maximumSize">
9992
<size>
@@ -212,7 +205,6 @@
212205
<tabstop>mDefaultProfileComboBox</tabstop>
213206
<tabstop>mAskUser</tabstop>
214207
<tabstop>mChangeIconButton</tabstop>
215-
<tabstop>mAllowProfileCreation</tabstop>
216208
</tabstops>
217209
<resources>
218210
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.