29 void QgsServerSettings::initSettings()
36 QStringLiteral(
"Override the default path for user configuration" ),
42 mSettings[ sOptPath.
envVar ] = sOptPath;
47 QStringLiteral(
"Activate/Deactivate parallel rendering for WMS getMap request" ),
48 QStringLiteral(
"/qgis/parallel_rendering" ),
53 mSettings[ sParRend.
envVar ] = sParRend;
58 QStringLiteral(
"Number of threads to use when parallel rendering is activated" ),
59 QStringLiteral(
"/qgis/max_threads" ),
64 mSettings[ sMaxThreads.
envVar ] = sMaxThreads;
69 QStringLiteral(
"Log level" ),
75 mSettings[ sLogLevel.
envVar ] = sLogLevel;
80 QStringLiteral(
"Log file" ),
86 mSettings[ sLogFile.
envVar ] = sLogFile;
91 QStringLiteral(
"Activate/Deactivate logging to stderr" ),
97 mSettings[ sLogStderr.
envVar ] = sLogStderr;
102 QStringLiteral(
"QGIS project file" ),
108 mSettings[ sProject.
envVar ] = sProject;
113 QStringLiteral(
"Specify the maximum number of cached layers" ),
119 mSettings[ sMaxCacheLayers.
envVar ] = sMaxCacheLayers;
124 QStringLiteral(
"Specify the cache directory" ),
125 QStringLiteral(
"/cache/directory" ),
130 mSettings[ sCacheDir.
envVar ] = sCacheDir;
135 QStringLiteral(
"Specify the cache size" ),
136 QStringLiteral(
"/cache/size" ),
138 QVariant( 50 * 1024 * 1024 ),
141 mSettings[ sCacheSize.
envVar ] = sCacheSize;
146 QStringLiteral(
"Override system locale" ),
147 QStringLiteral(
"/locale/userLocale" ),
152 mSettings[ sOverrideSystemLocale.
envVar ] = sOverrideSystemLocale;
157 QStringLiteral(
"Show group (thousands) separator" ),
158 QStringLiteral(
"/locale/showGroupSeparator" ),
163 mSettings[ sShowGroupSeparator.
envVar ] = sShowGroupSeparator;
168 QStringLiteral(
"Maximum height for a WMS request. The lower one of this and the project configuration is used." ),
169 QStringLiteral(
"/qgis/max_wms_height" ),
174 mSettings[ sMaxHeight.
envVar ] = sMaxHeight;
179 QStringLiteral(
"Maximum width for a WMS request. The most conservative between this and the project one is used" ),
180 QStringLiteral(
"/qgis/max_wms_width" ),
185 mSettings[ sMaxWidth.
envVar ] = sMaxWidth;
195 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
207 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
208 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
212 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
220 QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const 222 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
224 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
225 for (
int i = 0; i < metaEnum.keyCount(); i++ )
237 return mSettings[ envVar ].defaultVal;
241 return mSettings[ envVar ].val;
245 void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const 247 if ( ! envOptPath.isEmpty() )
249 QSettings::setDefaultFormat( QSettings::IniFormat );
250 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
254 void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
261 if ( ! env.value( e ).isEmpty() )
263 varValue.setValue( env.value( e ) );
266 if ( ! varValue.isNull() && varValue.canConvert( s.
type ) )
271 else if ( ! s.
iniKey.isEmpty() && QSettings().contains( s.
iniKey ) && QSettings().value( s.
iniKey ).canConvert( s.
type ) )
284 if ( s.
type == QVariant::String && s.
val.toString().isEmpty() )
296 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
297 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
302 const QString src = metaEnumSrc.valueToKey( s.src );
303 const QString var = metaEnumEnv.valueToKey( s.envVar );
305 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
311 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
319 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.
int wmsMaxWidth() const
Returns the server-wide max width of a WMS GetMap request.
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.
Show group (thousands) separator when formatting numeric values, defaults to false (since QGIS 3...
Override system locale (since QGIS 3.8)
int maxCacheLayers() const
Returns the maximum number of cached layers.
qint64 cacheSize() const
Returns the cache size.
bool showGroupSeparator() const
Show group (thousand) separator.
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.
int wmsMaxHeight() const
Returns the server-wide max height of a WMS GetMap request.
bool parallelRendering() const
Returns parallel rendering setting.
QString overrideSystemLocale() const
Overrides system locale.
Maximum height for a WMS request. The most conservative between this and the project one is used (sin...
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.