QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
24 #include <QTextStream>
26 #include <QStandardPaths>
37 return basePath + QDir::separator() +
"profiles";
42 const QString profileName = defaultProfile.isEmpty() ?
defaultProfileName() : defaultProfile;
58 mRootProfilePath = rootProfileLocation;
63 mSettings.reset(
new QSettings( settingsFile(), QSettings::IniFormat ) );
68 mWatchProfiles = enabled;
69 if ( mWatchProfiles && !mRootProfilePath.isEmpty() && QDir( mRootProfilePath ).exists() )
71 mWatcher.reset(
new QFileSystemWatcher() );
72 mWatcher->addPath( mRootProfilePath );
73 connect( mWatcher.get(), &QFileSystemWatcher::directoryChanged,
this, [
this]
75 emit profilesChanged();
86 return static_cast< bool >( mWatcher.get() );
91 return !mRootProfilePath.isEmpty();
96 const QString defaultName = QStringLiteral(
"default" );
102 if ( !mSettings->contains( QStringLiteral(
"/core/defaultProfile" ) ) || globalSettings.
value( QStringLiteral(
"overrideLocalProfile" ),
false,
QgsSettings::Core ).toBool() )
104 return globalSettings.
value( QStringLiteral(
"defaultProfile" ), defaultName,
QgsSettings::Core ).toString();
106 return mSettings->value( QStringLiteral(
"/core/defaultProfile" ), defaultName ).toString();
111 mSettings->setValue( QStringLiteral(
"/core/defaultProfile" ), name );
122 return QDir( mRootProfilePath ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );
132 const QString profilePath = mRootProfilePath + QDir::separator() + name;
142 const QDir folder( mRootProfilePath + QDir::separator() + name );
143 if ( !folder.exists() )
145 QDir().mkpath( folder.absolutePath() );
148 QFile qgisPrivateDbFile( folder.absolutePath() + QDir::separator() +
"qgis.db" );
151 if ( !qgisPrivateDbFile.exists() )
155 QFile masterFile( qgisMasterDbFileName );
158 masterFile.copy( qgisPrivateDbFile.fileName() );
162 const QFile::Permissions perms = QFile( qgisPrivateDbFile.fileName() ).permissions();
163 if ( !( perms & QFile::WriteOwner ) )
165 if ( !qgisPrivateDbFile.setPermissions( perms | QFile::WriteOwner ) )
167 error.
append( tr(
"Can not make '%1' user writable" ).arg( qgisPrivateDbFile.fileName() ) );
183 QDir folder( mRootProfilePath + QDir::separator() + name );
186 const bool deleted = folder.removeRecursively();
189 error.
append( ( tr(
"Unable to fully delete user profile folder" ) ) );
198 QString QgsUserProfileManager::settingsFile()
const
200 return mRootProfilePath + QDir::separator() +
"profiles.ini";
205 return mUserProfile.get();
210 #if QT_CONFIG(process)
211 const QString path = QDir::toNativeSeparators( QCoreApplication::applicationFilePath() );
212 QStringList arguments;
213 arguments << QCoreApplication::arguments();
217 arguments.removeFirst();
218 arguments << QStringLiteral(
"--profile" ) << name;
219 QgsDebugMsg( QStringLiteral(
"Starting instance from %1 with %2" ).arg( path ).arg( arguments.join(
" " ) ) );
220 QProcess::startDetached( path, arguments, QDir::toNativeSeparators( QCoreApplication::applicationDirPath() ) );
223 Q_ASSERT(
"Starting the user profile is not supported on the platform" );
224 #endif //QT_CONFIG(process)
229 if ( ! mUserProfile.get() )
void setActiveUserProfile(const QString &profile)
Sets the active profile in the manager.
void setDefaultProfileName(const QString &name)
Sets the default profile name.
QgsUserProfileManager(const QString &rootLocation=QString(), QObject *parent=nullptr)
User profile manager used to manage user profiles for the instance of QGIS.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QStringList allProfiles() const
Returns a list of all found profile names.
static QString resolveProfilesFolder(const QString &basePath=QString())
Resolves the profiles folder for the given path.
QgsError is container for error messages (report). It may contain chain (sort of traceback) of error ...
This class is a composition of two QSettings instances:
void append(const QString &message, const QString &tag)
Append new error message.
QgsError deleteProfile(const QString &name)
Deletes a profile from the root profiles folder.
void setRootLocation(const QString &rootProfileLocation)
Set the root profile location for the profile manager.
QgsUserProfile * getProfile(const QString &defaultProfile="default", bool createNew=true, bool initSettings=true)
Returns the profile from the given root profile location.
static QString qgisMasterDatabaseFilePath()
Returns the path to the master qgis.db file.
QgsError createUserProfile(const QString &name)
Create a user profile given by the name.
QgsUserProfile * userProfile()
The currently active user profile.
bool isEmpty() const
Test if any error is set.
void setNewProfileNotificationEnabled(bool enabled)
Sets whether the manager should watch for the creation of new user profiles and emit the profilesChan...
void initSettings() const
Init the settings from the user folder.
QString defaultProfileName() const
Returns the name of the default profile that has been set in .default.
QgsUserProfile * profileForName(const QString &name) const
Returns the profile found for a given name.
void setDefaultFromActive()
Set the default profile name from the current active profile.
bool isNewProfileNotificationEnabled() const
Returns whether the manager is watching for the creation of new user profiles and emitting the profil...
User profile contains information about the user profile folders on the machine. In QGIS 3 all settin...
bool profileExists(const QString &name) const
Check if a profile exists.
void profilesChanged()
Emitted when the list of profiles is changed.
bool rootLocationIsSet() const
Check if the root location has been set for the manager.
void loadUserProfile(const QString &name)
Starts a new instance of QGIS for the given profile.
QString rootLocation()
Returns the path to the root profiles location.