29using namespace Qt::StringLiterals;
38 return mProfileFolder;
44 if ( !QDir( mProfileFolder ).exists() )
46 error.
append( QObject::tr(
"Profile folder doesn't exist" ) );
53 const QDir dir( mProfileFolder );
60 QSettings::setDefaultFormat( QSettings::IniFormat );
61 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope,
folder() );
66 const QString dbFile = qgisDB();
67 QString profileAlias =
name();
71 if ( !QFile::exists( dbFile ) )
79 int result = database.
open( dbFile );
80 if ( result != SQLITE_OK )
86 if ( result == SQLITE_OK )
88 if ( preparedStatement.
step() == SQLITE_ROW )
91 if ( !
alias.isEmpty() )
101 const QString dbFile = qgisDB();
105 if ( !QFile::exists( dbFile ) )
107 error.
append( QObject::tr(
"qgis.db doesn't exist in the user's profile folder" ) );
114 int result = database.
open( dbFile );
115 if ( result != SQLITE_OK )
117 error.
append( QObject::tr(
"Unable to open qgis.db for update." ) );
121 const QString sql = u
"INSERT OR REPLACE INTO tbl_config_variables VALUES ('ALIAS', %1);"_s.arg(
125 if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
127 error.
append( QObject::tr(
"Could not save alias to database: %1" ).arg( database.
errorMessage() ) );
135 const QStringList extensions = {
".svg",
".png",
".jpg",
".jpeg",
".gif",
".bmp"};
136 const QString basename = mProfileFolder + QDir::separator() +
"icon";
138 for (
const QString &extension : extensions )
140 const QString path = basename + extension;
141 if ( QFileInfo::exists( path ) )
142 return QIcon( path );
147QString QgsUserProfile::qgisDB()
const
149 return mProfileFolder + QDir::separator() +
"qgis.db";
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
A container for error messages.
void append(const QString &message, const QString &tag)
Append new error message.
static QString quotedString(const QString &value)
Returns a quoted string value, surround by ' characters and with special characters correctly escaped...
QgsUserProfile(const QString &folder)
Reference to an existing user profile folder.
const QString folder() const
The base folder for the user profile.
const QString name() const
The name for the user profile.
QgsError setAlias(const QString &alias) const
Set the alias of the profile.
const QString alias() const
Returns the alias for the user profile.
const QIcon icon() const
The icon for the user profile.
QgsError validate() const
Check of the profile is in a valid state.
void initSettings() const
Init the settings from the user folder.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
QString errorMessage() const
Returns the most recent error message encountered by the database.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
int step()
Steps to the next record in the statement, returning the sqlite3 result code.