29 void QgsServerSettings::initSettings()
36 "Override the default path for user configuration",
42 mSettings[ sOptPath.
envVar ] = sOptPath;
47 "Activate/Deactivate parallel rendering for WMS getMap request",
48 "/qgis/parallel_rendering",
53 mSettings[ sParRend.
envVar ] = sParRend;
58 "Number of threads to use when parallel rendering is activated",
64 mSettings[ sMaxThreads.
envVar ] = sMaxThreads;
75 mSettings[ sLogLevel.
envVar ] = sLogLevel;
86 mSettings[ sLogFile.
envVar ] = sLogFile;
91 "Activate/Deactivate logging to stderr",
97 mSettings[ sLogStderr.
envVar ] = sLogStderr;
108 mSettings[ sProject.
envVar ] = sProject;
113 "Specify the maximum number of cached layers",
119 mSettings[ sMaxCacheLayers.
envVar ] = sMaxCacheLayers;
124 "Specify the cache directory",
130 mSettings[ sCacheDir.
envVar ] = sCacheDir;
135 "Specify the cache size",
138 QVariant( 50 * 1024 * 1024 ),
141 mSettings[ sCacheSize.
envVar ] = sCacheSize;
151 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
163 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
164 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
168 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
176 QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const 178 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
180 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
181 for (
int i = 0; i < metaEnum.keyCount(); i++ )
193 return mSettings[ envVar ].defaultVal;
197 return mSettings[ envVar ].val;
201 void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const 203 if ( ! envOptPath.isEmpty() )
205 QSettings::setDefaultFormat( QSettings::IniFormat );
206 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
210 void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
217 if ( ! env.value( e ).isEmpty() )
219 varValue.setValue( env.value( e ) );
222 if ( ! varValue.isNull() && varValue.canConvert( s.
type ) )
227 else if ( ! s.
iniKey.isEmpty() && QSettings().contains( s.
iniKey ) && QSettings().value( s.
iniKey ).canConvert( s.
type ) )
240 if ( s.
type == QVariant::String && s.
val.toString().isEmpty() )
252 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
253 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
258 const QString src = metaEnumSrc.valueToKey( s.src );
259 const QString var = metaEnumEnv.valueToKey( s.envVar );
261 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
267 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
275 return QSettings().fileName();
QString cacheDirectory() const
Returns the cache directory.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QString iniFile() const
Returns the ini file loaded by QSetting.
QString projectFile() const
Returns the QGS project file to use.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
int maxCacheLayers() const
Returns the maximum number of cached layers.
qint64 cacheSize() const
Returns the cache size.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QString logFile() const
Returns the log file.
bool parallelRendering() const
Returns parallel rendering setting.
void load()
Load settings according to current environment variables.
void logSummary() const
Log a summary of settings currently loaded.
QgsServerSettingsEnv::EnvVar envVar
QgsServerSettingsEnv::Source src
Qgis::MessageLevel logLevel() const
Returns the log level.
EnvVar
Environment variables to configure the server.
int maxThreads() const
Returns the maximum number of threads to use.
bool logStderr() const
Returns whether logging to stderr is activated.
QgsServerSettings()
Constructor.