Skip to content

Commit

Permalink
Add User Settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ authored and nyalldawson committed Apr 24, 2023
1 parent e1b6d8f commit 7b5f745
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -260,6 +260,7 @@ set(QGIS_APP_SRCS
options/qgsrasterrenderingoptions.cpp
options/qgsrenderingoptions.cpp
options/qgsvectorrenderingoptions.cpp
options/qgsuserprofilesettingsdialog.cpp

gps/qgsappgpsconnection.cpp
gps/qgsappgpsdigitizing.cpp
Expand Down
69 changes: 69 additions & 0 deletions src/app/options/qgsuserprofilesettingsdialog.cpp
@@ -0,0 +1,69 @@
/***************************************************************************
qgsuserprofilesettingsdialog.cpp
--------------------------------------
Date : February 2023
Copyright : (C) 2023 by Yoann Quenach de Quivillic
Email : yoann dot quenach at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgisapp.h"
#include "qgsuserprofilemanager.h"

#include "qgsuserprofilesettingsdialog.h"


QgsUserProfileSettingsDialog::QgsUserProfileSettingsDialog( QWidget *parent )
: QDialog( parent )

{
setupUi( this );
connect( mDefaultProfile, &QRadioButton::toggled, mDefaultProfileComboBox, &QComboBox::setEnabled );
connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsUserProfileSettingsDialog::apply );

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

// Fill combobox with profiles
mDefaultProfileComboBox->clear();
mDefaultProfileComboBox->addItems( manager->allProfiles() );
mDefaultProfileComboBox->setCurrentText( manager->defaultProfileName() );

}

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

50 changes: 50 additions & 0 deletions src/app/options/qgsuserprofilesettingsdialog.h
@@ -0,0 +1,50 @@
/***************************************************************************
qgsuserprofilesettingsdialog.h
--------------------------------------
Date : February 2023
Copyright : (C) 2023 by Yoann Quenach de Quivillic
Email : yoann dot quenach at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSUSERPROFILESETTINGSDIALOG_H
#define QGSUSERPROFILESETTINGSDIALOG_H

#include <QDialog>
#include "ui_qgsuserprofilesettingsdialog.h"

/**
* \class QgsUserProfileSettingsDialog
* \brief A dialog displaying user profile policy settings (open last closed profile, open specific, let user choose)
* \since QGIS 3.32
*/
class QgsUserProfileSettingsDialog : public QDialog, private Ui::QgsUserProfileSettingsDialog
{
Q_OBJECT

public:

/**
* Constructor for QgsUserProfileSettingsDialog.
* \param parent parent widget
*/
explicit QgsUserProfileSettingsDialog( QWidget *parent = nullptr );
virtual ~QgsUserProfileSettingsDialog() = default;

public slots:

/**
* Apply changes
*/
void apply();


};

#endif // QGSUSERPROFILESETTINGSDIALOG_H
13 changes: 13 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -116,6 +116,7 @@
#include "options/qgsrasterrenderingoptions.h"
#include "options/qgsrenderingoptions.h"
#include "options/qgsvectorrenderingoptions.h"
#include "options/qgsuserprofilesettingsdialog.h"

#include "raster/qgsrasterelevationpropertieswidget.h"
#include "qgsrasterattributetableapputils.h"
Expand Down Expand Up @@ -3412,6 +3413,12 @@ void QgisApp::refreshProfileMenu()
QAction *newProfileAction = mConfigMenu->addAction( tr( "New Profile…" ) );
newProfileAction->setObjectName( "mActionNewProfile" );
connect( newProfileAction, &QAction::triggered, this, &QgisApp::newProfile );

QAction *profileSettingsAction = mConfigMenu->addAction( tr( "Profiles settings..." ) );
profileSettingsAction->setObjectName( "mActionProfileSettings" );
connect( profileSettingsAction, &QAction::triggered, this, &QgisApp::showUserProfileSettingsDialog );


}

void QgisApp::createProfileMenu()
Expand Down Expand Up @@ -15685,6 +15692,12 @@ void QgisApp::newProfile()
}
}

void QgisApp::showUserProfileSettingsDialog()
{
QgsUserProfileSettingsDialog dlg;
dlg.exec();
}

void QgisApp::onTaskCompleteShowNotify( long taskId, int status )
{
if ( status == QgsTask::Complete || status == QgsTask::Terminated )
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1425,6 +1425,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
private slots:
void newProfile();

void showUserProfileSettingsDialog();

void onTaskCompleteShowNotify( long taskId, int status );

void onTransactionGroupsChanged();
Expand Down
129 changes: 129 additions & 0 deletions src/ui/qgsuserprofilesettingsdialog.ui
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsUserProfileSettingsDialog</class>
<widget class="QDialog" name="QgsUserProfileSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>412</width>
<height>226</height>
</rect>
</property>
<property name="windowTitle">
<string>User Profile Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Which profile should be used when QGIS starts ?</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QRadioButton" name="mDefaultProfile">
<property name="text">
<string>Always use profile</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mDefaultProfileComboBox"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>9</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>These settings do not apply if a profile was explicitely selected with the --profile command line argument</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="mLastProfile">
<property name="text">
<string>Use last closed profile</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="mAskUser">
<property name="text">
<string>Let user choose profile at start up</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>mButtonBox</sender>
<signal>accepted()</signal>
<receiver>QgsUserProfileSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>mButtonBox</sender>
<signal>rejected()</signal>
<receiver>QgsUserProfileSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 7b5f745

Please sign in to comment.