QgsUserProfileManager class
User profile manager is used to manager list, and manage user profiles on the users machine.
Contents
In QGIS 3 all settings, plugins, etc were moved into a APPDATA%/profiles folder for each platform. This allows for manage different user profiles per machine vs the single default one that was allowed in the past.
A user profile is all settings and anything that used to be found in .qgis3 in the users home folder.
Public static functions
- static auto resolveProfilesFolder(const QString& basePath = QString()) -> QString
- Resolves the profiles folder for the given path.
Constructors, destructors, conversion operators
- QgsUserProfileManager(const QString& rootLocation = QString(), QObject* parent = nullptr)
- User profile manager used to manage user profiles for the instance of QGIS.
Public functions
- auto allProfiles() const -> QStringList
- Returns a list of all found profile names.
- auto createUserProfile(const QString& name) -> QgsError
- Create a user profile given by the name.
- auto defaultProfileName() const -> QString
- Returns the name of the default profile that has been set in .default.
- auto deleteProfile(const QString& name) -> QgsError
- Deletes a profile from the root profiles folder.
- auto getProfile(const QString& defaultProfile = "default", bool createNew = true, bool initSettings = true) -> QgsUserProfile*
- Returns the profile from the given root profile location.
- auto isNewProfileNotificationEnabled() const -> bool
- Returns whether the manager is watching for the creation of new user profiles and emitting the profilesChanged() signal when this occurs.
- void loadUserProfile(const QString& name)
- Starts a new instance of QGIS for the given profile.
- auto profileExists(const QString& name) const -> bool
- Check if a profile exists.
- auto profileForName(const QString& name) const -> QgsUserProfile*
- Returns the profile found for a given name.
- auto rootLocation() -> QString
- Returns the path to the root profiles location.
- auto rootLocationIsSet() const -> bool
- Check if the root location has been set for the manager.
- void setActiveUserProfile(const QString& profile)
- Sets the active profile in the manager.
- void setDefaultFromActive()
- Set the default profile name from the current active profile.
- void setDefaultProfileName(const QString& name)
- Sets the default profile name.
- void setNewProfileNotificationEnabled(bool enabled)
- Sets whether the manager should watch for the creation of new user profiles and emit the profilesChanged() signal when this occurs.
- void setRootLocation(const QString& rootProfileLocation)
- Set the root profile location for the profile manager.
- auto userProfile() -> QgsUserProfile*
- The currently active user profile.
Signals
- void profilesChanged()
- Emitted when the list of profiles is changed.
Function documentation
static QString QgsUserProfileManager:: resolveProfilesFolder(const QString& basePath = QString())
Resolves the profiles folder for the given path.
| Parameters | |
|---|---|
| basePath | The base path to resolve the path from to append the \profiles folder to. |
| Returns | The root path to store user profiles. |
Path will have \profiles appended to the path
QgsError QgsUserProfileManager:: createUserProfile(const QString& name)
Create a user profile given by the name.
| Parameters | |
|---|---|
| name | |
| Returns | A QgsError which report if there was any error creating the user profile. |
QString QgsUserProfileManager:: defaultProfileName() const
Returns the name of the default profile that has been set in .default.
| Returns | The name of the default profile. |
|---|
First checks profile.ini in \profiles folder Then checks defaultProfile in global settings Finally returns "default" if all else fails
QgsError QgsUserProfileManager:: deleteProfile(const QString& name)
Deletes a profile from the root profiles folder.
| Parameters | |
|---|---|
| name | The name of the profile to delete. |
| Returns | A QgsError with a message if the profile failed to be deleted. |
QgsUserProfile* QgsUserProfileManager:: getProfile(const QString& defaultProfile = "default",
bool createNew = true,
bool initSettings = true)
Returns the profile from the given root profile location.
| Parameters | |
|---|---|
| defaultProfile | The profile name to find. Empty profile name will return "default" for the name. |
| createNew | Create the profile folder if it doesn't exist. |
| initSettings | if the settings should be initialized |
| Returns | The user profile |
If no name is given it returns a profile called "default". By default will create the profile folder if not found. By default will init the user settings.
bool QgsUserProfileManager:: isNewProfileNotificationEnabled() const
Returns whether the manager is watching for the creation of new user profiles and emitting the profilesChanged() signal when this occurs.
By default new profile notification is disabled.
void QgsUserProfileManager:: loadUserProfile(const QString& name)
Starts a new instance of QGIS for the given profile.
| Parameters | |
|---|---|
| name | The profile to start QGIS with. |
bool QgsUserProfileManager:: profileExists(const QString& name) const
Check if a profile exists.
| Returns | False if the profile can't be found. |
|---|
QgsUserProfile* QgsUserProfileManager:: profileForName(const QString& name) const
Returns the profile found for a given name.
| Parameters | |
|---|---|
| name | The name of the profile to return. |
| Returns | A QgsUserprofile pointing to the location of the user profile. |
QString QgsUserProfileManager:: rootLocation()
Returns the path to the root profiles location.
| Returns | The root path to the profiles folder. |
|---|
bool QgsUserProfileManager:: rootLocationIsSet() const
Check if the root location has been set for the manager.
| Returns | True if the root location has been set. |
|---|
void QgsUserProfileManager:: setActiveUserProfile(const QString& profile)
Sets the active profile in the manager.
| Parameters | |
|---|---|
| profile | The name of the active profile |
This can only be set once. Setting this again does nothing.
void QgsUserProfileManager:: setDefaultProfileName(const QString& name)
Sets the default profile name.
| Parameters | |
|---|---|
| name | The name of the profile to save. |
The default profile name is used when loading QGIS with no arguments.
void QgsUserProfileManager:: setNewProfileNotificationEnabled(bool enabled)
Sets whether the manager should watch for the creation of new user profiles and emit the profilesChanged() signal when this occurs.
By default new profile notification is disabled.
Before calling this, ensure that the correct root location has been set via calling setRootLocation().
void QgsUserProfileManager:: setRootLocation(const QString& rootProfileLocation)
Set the root profile location for the profile manager.
| Parameters | |
|---|---|
| rootProfileLocation | Path to the top level profile folder which contains folders for each profile. |
All profiles are loaded from this location. Will also contain a profiles.ini for holding profile settings.
QgsUserProfile* QgsUserProfileManager:: userProfile()
The currently active user profile.
| Returns | The currently active user profile. |
|---|
void QgsUserProfileManager:: profilesChanged() signal
Emitted when the list of profiles is changed.
This signal will only be emitted when isNewProfileNotificationEnabled() is true. By default new profile notification is disabled.