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(
"Trust layer metadata" ),
175 mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;
180 QStringLiteral(
"Don't load layouts" ),
186 mSettings[ sDontLoadLayouts.envVar ] = sDontLoadLayouts;
191 QStringLiteral(
"Show group (thousands) separator" ),
192 QStringLiteral(
"/locale/showGroupSeparator" ),
197 mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;
202 QStringLiteral(
"Maximum height for a WMS request. The lower one of this and the project configuration is used." ),
203 QStringLiteral(
"/qgis/max_wms_height" ),
208 mSettings[ sMaxHeight.envVar ] = sMaxHeight;
213 QStringLiteral(
"Maximum width for a WMS request. The most conservative between this and the project one is used" ),
214 QStringLiteral(
"/qgis/max_wms_width" ),
219 mSettings[ sMaxWidth.envVar ] = sMaxWidth;
224 QStringLiteral(
"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for" ),
225 QStringLiteral(
"/qgis/server_api_resources_directory" ),
231 mSettings[ sApiResourcesDirectory.envVar ] = sApiResourcesDirectory;
236 QStringLiteral(
"Maximum value for \"limit\" in a features request, defaults to 10000" ),
237 QStringLiteral(
"/qgis/server_api_wfs3_max_limit" ),
243 mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;
248 QStringLiteral(
"Directories used by the landing page service to find .qgs and .qgz projects" ),
249 QStringLiteral(
"/qgis/server_projects_directories" ),
255 mSettings[ sProjectsDirectories.envVar ] = sProjectsDirectories;
260 QStringLiteral(
"PostgreSQL connection strings used by the landing page service to find projects" ),
261 QStringLiteral(
"/qgis/server_projects_pg_connections" ),
267 mSettings[ sProjectsPgConnections.envVar ] = sProjectsPgConnections;
277 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
289 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
290 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
294 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
302 QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
304 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
306 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
307 for (
int i = 0; i < metaEnum.keyCount(); i++ )
319 const QString envValue( getenv(
name( envVar ).toStdString().c_str() ) );
321 if ( ! envValue.isEmpty() )
327 return mSettings[ envVar ].defaultVal;
331 return mSettings[ envVar ].val;
335 void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
337 if ( ! envOptPath.isEmpty() )
339 QSettings::setDefaultFormat( QSettings::IniFormat );
340 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
344 void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
348 Setting s = mSettings[ e ];
351 if ( ! env.value( e ).isEmpty() )
353 varValue.setValue( env.value( e ) );
356 if ( ! varValue.isNull() && varValue.canConvert( s.type ) )
361 else if ( ! s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
363 s.val = QSettings().value( s.iniKey );
374 if ( s.type == QVariant::String && s.val.toString().isEmpty() )
386 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
387 return metaEnumEnv.valueToKey( env );
392 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
397 const QString src = metaEnumSrc.valueToKey( s.src );
398 const QString var =
name( s.envVar );
400 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
406 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
414 return QSettings().fileName();