33 return mProfileFolder;
39 if ( !QDir( mProfileFolder ).exists() )
41 error.
append( QObject::tr(
"Profile folder doesn't exist" ) );
48 const QDir dir( mProfileFolder );
55 QSettings::setDefaultFormat( QSettings::IniFormat );
56 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope,
folder() );
61 const QString dbFile = qgisDB();
62 QString profileAlias =
name();
66 if ( !QFile::exists( dbFile ) )
74 int result = database.
open( dbFile );
75 if ( result != SQLITE_OK )
81 if ( result == SQLITE_OK )
83 if ( preparedStatement.
step() == SQLITE_ROW )
86 if ( !
alias.isEmpty() )
96 const QString dbFile = qgisDB();
100 if ( !QFile::exists( dbFile ) )
102 error.
append( QObject::tr(
"qgis.db doesn't exist in the user's profile folder" ) );
109 int result = database.
open( dbFile );
110 if ( result != SQLITE_OK )
112 error.
append( QObject::tr(
"Unable to open qgis.db for update." ) );
116 const QString sql = QStringLiteral(
"INSERT OR REPLACE INTO tbl_config_variables VALUES ('ALIAS', %1);" ).arg(
120 if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
122 error.
append( QObject::tr(
"Could not save alias to database: %1" ).arg( database.
errorMessage() ) );
130 const QStringList extensions = {
".svg",
".png",
".jpg",
".jpeg",
".gif",
".bmp"};
131 const QString basename = mProfileFolder + QDir::separator() +
"icon";
133 for (
const QString &extension : extensions )
135 const QString path = basename + extension;
136 if ( QFileInfo::exists( path ) )
137 return QIcon( path );
142QString QgsUserProfile::qgisDB()
const
144 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 a 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.