30 void QgsServerSettings::initSettings()
37 QStringLiteral(
"Override the default path for user configuration" ),
43 mSettings[ sOptPath.envVar ] = sOptPath;
48 QStringLiteral(
"Activate/Deactivate parallel rendering for WMS getMap request" ),
49 QStringLiteral(
"/qgis/parallel_rendering" ),
54 mSettings[ sParRend.envVar ] = sParRend;
59 QStringLiteral(
"Number of threads to use when parallel rendering is activated" ),
60 QStringLiteral(
"/qgis/max_threads" ),
65 mSettings[ sMaxThreads.envVar ] = sMaxThreads;
70 QStringLiteral(
"Log level" ),
76 mSettings[ sLogLevel.envVar ] = sLogLevel;
81 QStringLiteral(
"Log file" ),
87 mSettings[ sLogFile.envVar ] = sLogFile;
92 QStringLiteral(
"Activate/Deactivate logging to stderr" ),
98 mSettings[ sLogStderr.envVar ] = sLogStderr;
103 QStringLiteral(
"QGIS project file" ),
109 mSettings[ sProject.envVar ] = sProject;
114 QStringLiteral(
"Specify the maximum number of cached layers" ),
120 mSettings[ sMaxCacheLayers.envVar ] = sMaxCacheLayers;
125 QStringLiteral(
"Specify the cache directory" ),
126 QStringLiteral(
"/cache/directory" ),
131 mSettings[ sCacheDir.envVar ] = sCacheDir;
136 QStringLiteral(
"Specify the cache size" ),
137 QStringLiteral(
"/cache/size" ),
139 QVariant( 50 * 1024 * 1024 ),
142 mSettings[ sCacheSize.envVar ] = sCacheSize;
147 QStringLiteral(
"Override system locale" ),
148 QStringLiteral(
"/locale/userLocale" ),
153 mSettings[ sOverrideSystemLocale.envVar ] = sOverrideSystemLocale;
158 QStringLiteral(
"Ignore bad layers" ),
164 mSettings[ sIgnoreBadLayers.envVar ] = sIgnoreBadLayers;
169 QStringLiteral(
"Show group (thousands) separator" ),
170 QStringLiteral(
"/locale/showGroupSeparator" ),
175 mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;
180 QStringLiteral(
"Maximum height for a WMS request. The lower one of this and the project configuration is used." ),
181 QStringLiteral(
"/qgis/max_wms_height" ),
186 mSettings[ sMaxHeight.envVar ] = sMaxHeight;
191 QStringLiteral(
"Maximum width for a WMS request. The most conservative between this and the project one is used" ),
192 QStringLiteral(
"/qgis/max_wms_width" ),
197 mSettings[ sMaxWidth.envVar ] = sMaxWidth;
202 QStringLiteral(
"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for" ),
203 QStringLiteral(
"/qgis/server_api_resources_directory" ),
209 mSettings[ sApiResourcesDirectory.envVar ] = sApiResourcesDirectory;
214 QStringLiteral(
"Maximum value for \"limit\" in a features request, defaults to 10000" ),
215 QStringLiteral(
"/qgis/server_api_wfs3_max_limit" ),
221 mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;
231 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
243 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
244 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
248 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
256 QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
258 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
260 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
261 for (
int i = 0; i < metaEnum.keyCount(); i++ )
273 return mSettings[ envVar ].defaultVal;
277 return mSettings[ envVar ].val;
281 void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
283 if ( ! envOptPath.isEmpty() )
285 QSettings::setDefaultFormat( QSettings::IniFormat );
286 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
290 void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
294 Setting s = mSettings[ e ];
297 if ( ! env.value( e ).isEmpty() )
299 varValue.setValue( env.value( e ) );
302 if ( ! varValue.isNull() && varValue.canConvert( s.type ) )
307 else if ( ! s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
309 s.val = QSettings().value( s.iniKey );
320 if ( s.type == QVariant::String && s.val.toString().isEmpty() )
332 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
333 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
338 const QString src = metaEnumSrc.valueToKey( s.src );
339 const QString var = metaEnumEnv.valueToKey( s.envVar );
341 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
347 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
355 return QSettings().fileName();