Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add User Selection Dialog
- Loading branch information
1 parent
7b5f745
commit aa4701e
Showing
6 changed files
with
443 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/*************************************************************************** | ||
qgsuserprofileselectiondialog.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 <QListWidgetItem> | ||
#include <QMessageBox> | ||
|
||
#include "qgisapp.h" | ||
#include "qgsapplication.h" | ||
#include "qgsuserprofilemanager.h" | ||
#include "qgsnewnamedialog.h" | ||
|
||
#include "qgsuserprofileselectiondialog.h" | ||
|
||
QgsUserProfileSelectionDialog::QgsUserProfileSelectionDialog( QgsUserProfileManager *manager, QWidget *parent ) | ||
: QDialog( parent ), mManager( manager ) | ||
|
||
{ | ||
setupUi( this ); | ||
setWindowIcon( QIcon( QgsApplication::appIconPath() ) ); | ||
|
||
// Select user profile on double click | ||
connect( mProfileListWidget, &QListWidget::itemDoubleClicked, this, &QgsUserProfileSelectionDialog::accept ); | ||
|
||
// Add a new profile on button click | ||
connect( mAddProfileButton, &QPushButton::clicked, this, &QgsUserProfileSelectionDialog::onAddProfile ); | ||
|
||
// Fill the list of profiles | ||
mProfileListWidget->clear(); // Clear bogus profiles in the Ui form | ||
for ( auto profile : mManager->allProfiles() ) | ||
{ | ||
auto item = new QListWidgetItem( mManager->profileForName( profile )->icon(), profile ); | ||
mProfileListWidget->addItem( item ); | ||
|
||
// If the profile is the last used one, select it | ||
if ( profile == mManager->lastProfileName() ) | ||
{ | ||
mProfileListWidget->setCurrentItem( item ); | ||
item->setSelected( true ); | ||
} | ||
} | ||
} | ||
|
||
QString QgsUserProfileSelectionDialog::selectedProfileName() const | ||
{ | ||
return mProfileListWidget->currentItem()->text(); | ||
} | ||
|
||
void QgsUserProfileSelectionDialog::accept() | ||
{ | ||
// Accept only if an item is selected | ||
if ( mProfileListWidget->currentItem() != nullptr && mProfileListWidget->currentItem()->isSelected() ) | ||
{ | ||
QDialog::accept(); | ||
} | ||
} | ||
|
||
void QgsUserProfileSelectionDialog::onAddProfile() | ||
{ | ||
// Ask for a new profile name | ||
QgsNewNameDialog dlg( QString(), QString(), QStringList(), mManager->allProfiles(), Qt::CaseInsensitive, this ); | ||
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" ) ); | ||
|
||
// Prevent from entering slashes and backslashes | ||
dlg.setRegularExpression( "[^/\\\\]+" ); | ||
|
||
if ( dlg.exec() != QDialog::Accepted ) | ||
return; | ||
|
||
// Try to create the profile folder | ||
QString profileName = dlg.name(); | ||
QgsError error = mManager->createUserProfile( profileName ); | ||
if ( error.isEmpty() ) | ||
{ | ||
auto item = new QListWidgetItem( QgsApplication::getThemeIcon( "user.svg" ), profileName ); | ||
mProfileListWidget->addItem( item ); | ||
mProfileListWidget->setCurrentItem( item ); | ||
item->setSelected( true ); | ||
// Automatically accept the dialog | ||
accept(); | ||
} | ||
else | ||
{ | ||
QMessageBox::warning( this, tr( "New Profile" ), tr( "Cannot create folder '%1'" ).arg( profileName ) ); | ||
return; | ||
} | ||
} | ||
|
||
QgsUserProfileSelectionDialog::~QgsUserProfileSelectionDialog() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*************************************************************************** | ||
qgsuserprofileselectiondialog.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 QGSUSERPROFILESELECTIONDIALOG_H | ||
#define QGSUSERPROFILESELECTIONDIALOG_H | ||
|
||
#include <QDialog> | ||
|
||
#include "ui_qgsuserprofileselectiondialog.h" | ||
|
||
|
||
// Forward declarations | ||
class QgsUserProfileManager; | ||
class QEvent; | ||
|
||
/** | ||
* \class QgsUserProfileSelectionDialog | ||
* \brief A dialog shown at startup to select the user profile | ||
* \since QGIS 3.32 | ||
*/ | ||
class GUI_EXPORT QgsUserProfileSelectionDialog : public QDialog, private Ui::QgsUserProfileSelectionDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsUserProfileSelectionDialog. | ||
* \param manager QgsUserProfileManager manager that will be used to fill the list of profiles | ||
* \param parent parent widget | ||
*/ | ||
explicit QgsUserProfileSelectionDialog( QgsUserProfileManager *manager, QWidget *parent = nullptr ); | ||
virtual ~QgsUserProfileSelectionDialog(); | ||
|
||
|
||
/* Return the selected profile name */ | ||
QString selectedProfileName() const; | ||
|
||
public slots: | ||
void accept() override; | ||
|
||
private slots: | ||
void onAddProfile(); | ||
|
||
private: | ||
QgsUserProfileManager *mManager = nullptr; | ||
|
||
|
||
}; | ||
|
||
#endif // QGSUSERPROFILESELECTIONDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.