Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add icon size and allow creation settings
  • Loading branch information
YoannQDQ authored and nyalldawson committed Apr 24, 2023
1 parent 0d5d5c3 commit 4891c9f
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 2 deletions.
32 changes: 32 additions & 0 deletions python/core/auto_generated/qgsuserprofilemanager.sip.in
Expand Up @@ -171,6 +171,38 @@ 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
21 changes: 20 additions & 1 deletion src/app/options/qgsuserprofileoptions.cpp
Expand Up @@ -29,16 +29,35 @@ QgsUserProfileOptionsWidget::QgsUserProfileOptionsWidget( QWidget *parent )
{
setupUi( this );

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

// Disable combobox if default profile is not selected
mDefaultProfileComboBox->setEnabled( false );
connect( mDefaultProfile, &QRadioButton::toggled, mDefaultProfileComboBox, &QComboBox::setEnabled );

// Disable Profile selector groupbox if Ask user is not selected
mProfileSelectorGroupBox->setEnabled( false );
connect( mAskUser, &QRadioButton::toggled, mProfileSelectorGroupBox, &QGroupBox::setEnabled );

// Connect icon size and allow profile creation
mIconSize->setCurrentText( QString::number( manager->profileSelectorIconSize() ) );
mAllowProfileCreation->setChecked( manager->profileSelectorProfileCreationAllowed() );
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 );
} );

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

// Init radio buttons
auto manager = QgisApp::instance()->userProfileManager();
if ( manager->userProfileSelectionPolicy() == QgsUserProfileManager::UserProfileSelectionPolicy::LastProfile )
{
mLastProfile->setChecked( true );
Expand Down
11 changes: 10 additions & 1 deletion src/app/options/qgsuserprofileselectiondialog.cpp
Expand Up @@ -34,7 +34,16 @@ QgsUserProfileSelectionDialog::QgsUserProfileSelectionDialog( QgsUserProfileMana
connect( mProfileListWidget, &QListWidget::itemDoubleClicked, this, &QgsUserProfileSelectionDialog::accept );

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

mProfileListWidget->setIconSize( QSize( mManager->profileSelectorIconSize(), mManager->profileSelectorIconSize() ) );

// Fill the list of profiles
mProfileListWidget->clear(); // Clear bogus profiles in the Ui form
Expand Down
24 changes: 24 additions & 0 deletions src/core/qgsuserprofilemanager.cpp
Expand Up @@ -139,6 +139,30 @@ void QgsUserProfileManager::setUserProfileSelectionPolicy( QgsUserProfileManager
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
26 changes: 26 additions & 0 deletions src/core/qgsuserprofilemanager.h
Expand Up @@ -179,6 +179,32 @@ class CORE_EXPORT QgsUserProfileManager : public QObject
*/
void setUserProfileSelectionPolicy( UserProfileSelectionPolicy policy );

/**
* Returns the icon size for the profile selector.
* \since QGIS 3.32
*/
int profileSelectorIconSize() const;

/**
* Sets the icon size for the profile selector.
* \param size The size of the icon in pixels.
* \since QGIS 3.32
*/
void setProfileSelectorIconSize( int size );

/**
* Returns whether the profile selector should allow the creation of new profiles.
* \since QGIS 3.32
*/
bool profileSelectorProfileCreationAllowed() const;

/**
* Sets whether the profile selector should allow the creation of new profiles.
* \param allow TRUE if new profiles should be allowed.
* \since QGIS 3.32
*/
void setProfileSelectorProfileCreationAllowed( bool allow );

/**
* Returns the profile found for a given name.
* \param name The name of the profile to return.
Expand Down
59 changes: 59 additions & 0 deletions src/ui/qgsuserprofileoptionswidgetbase.ui
Expand Up @@ -73,6 +73,64 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mProfileSelectorGroupBox">
<property name="title">
<string>Profile Selector</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="mAllowProfileCreation">
<property name="text">
<string>Let user create a new profile when starting QGIS</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mIconSizeLabel">
<property name="text">
<string>Icon size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mIconSize">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>16</string>
</property>
</item>
<item>
<property name="text">
<string>24</string>
</property>
</item>
<item>
<property name="text">
<string>32</string>
</property>
</item>
<item>
<property name="text">
<string>48</string>
</property>
</item>
<item>
<property name="text">
<string>64</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mActiveProfileGroupBox">
<property name="title">
Expand Down Expand Up @@ -154,6 +212,7 @@
<tabstop>mDefaultProfileComboBox</tabstop>
<tabstop>mAskUser</tabstop>
<tabstop>mChangeIconButton</tabstop>
<tabstop>mAllowProfileCreation</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 4891c9f

Please sign in to comment.