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" ),
73 QVariant::fromValue( Qgis::MessageLevel::NoLevel ),
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 cache directory" ),
115 QStringLiteral(
"/cache/directory" ),
120 mSettings[ sCacheDir.envVar ] = sCacheDir;
125 QStringLiteral(
"Specify the cache size" ),
126 QStringLiteral(
"/cache/size" ),
128 QVariant( 256 * 1024 * 1024 ),
131 mSettings[ sCacheSize.envVar ] = sCacheSize;
136 QStringLiteral(
"Override system locale" ),
137 QStringLiteral(
"/locale/userLocale" ),
142 mSettings[ sOverrideSystemLocale.envVar ] = sOverrideSystemLocale;
147 QStringLiteral(
"Ignore bad layers" ),
153 mSettings[ sIgnoreBadLayers.envVar ] = sIgnoreBadLayers;
158 QStringLiteral(
"Trust layer metadata" ),
164 mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;
169 QStringLiteral(
"Don't load layouts" ),
175 mSettings[ sDontLoadLayouts.envVar ] = sDontLoadLayouts;
180 QStringLiteral(
"Show group (thousands) separator" ),
181 QStringLiteral(
"/locale/showGroupSeparator" ),
186 mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;
191 QStringLiteral(
"Maximum height for a WMS request. The lower one of this and the project configuration is used." ),
192 QStringLiteral(
"/qgis/max_wms_height" ),
197 mSettings[ sMaxHeight.envVar ] = sMaxHeight;
202 QStringLiteral(
"Maximum width for a WMS request. The most conservative between this and the project one is used" ),
203 QStringLiteral(
"/qgis/max_wms_width" ),
208 mSettings[ sMaxWidth.envVar ] = sMaxWidth;
213 QStringLiteral(
"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for" ),
214 QStringLiteral(
"/qgis/server_api_resources_directory" ),
220 mSettings[ sApiResourcesDirectory.envVar ] = sApiResourcesDirectory;
225 QStringLiteral(
"Maximum value for \"limit\" in a features request, defaults to 10000" ),
226 QStringLiteral(
"/qgis/server_api_wfs3_max_limit" ),
232 mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;
237 QStringLiteral(
"Directories used by the landing page service to find .qgs and .qgz projects" ),
238 QStringLiteral(
"/qgis/server_projects_directories" ),
244 mSettings[ sProjectsDirectories.envVar ] = sProjectsDirectories;
249 QStringLiteral(
"PostgreSQL connection strings used by the landing page service to find projects" ),
250 QStringLiteral(
"/qgis/server_projects_pg_connections" ),
256 mSettings[ sProjectsPgConnections.envVar ] = sProjectsPgConnections;
261 QStringLiteral(
"Landing page base URL path prefix" ),
262 QStringLiteral(
"/qgis/server_landing_page_base_url_prefix" ),
268 mSettings[ sLandingPageBaseUrlPrefix.envVar ] = sLandingPageBaseUrlPrefix;
273 QStringLiteral(
"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0" ),
274 QStringLiteral(
"/qgis/server_log_profile" ),
280 mSettings[ sLogProfile.envVar ] = sLogProfile;
285 QStringLiteral(
"The default service URL" ),
286 QStringLiteral(
"/qgis/server_service_url" ),
291 mSettings[ sServiceUrl.envVar ] = sServiceUrl;
296 QStringLiteral(
"The default WMS service URL" ),
297 QStringLiteral(
"/qgis/server_wms_service_url" ),
302 mSettings[ sServiceUrl.envVar ] = sWmsServiceUrl;
307 QStringLiteral(
"The default WFS service URL" ),
308 QStringLiteral(
"/qgis/server_wfs_service_url" ),
313 mSettings[ sServiceUrl.envVar ] = sWfsServiceUrl;
318 QStringLiteral(
"The default WcS service URL" ),
319 QStringLiteral(
"/qgis/server_wcs_service_url" ),
324 mSettings[ sServiceUrl.envVar ] = sWfsServiceUrl;
329 QStringLiteral(
"The default WMTS service URL" ),
330 QStringLiteral(
"/qgis/server_wmts_service_url" ),
335 mSettings[ sServiceUrl.envVar ] = sWmtsServiceUrl;
340 QStringLiteral(
"The default project cache check interval" ),
341 QStringLiteral(
"/qgis/server_project_cache_check_interval" ),
346 mSettings[ sConfigCacheCheckInterval.envVar ] = sConfigCacheCheckInterval;
351 QStringLiteral(
"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'" ),
352 QStringLiteral(
"/qgis/server_project_cache_strategy" ),
357 mSettings[ sProjectCacheStrategy.envVar ] = sProjectCacheStrategy;
368 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
380 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
381 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
385 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
393 QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
395 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
397 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
398 for (
int i = 0; i < metaEnum.keyCount(); i++ )
410 const QString envValue( getenv(
name( envVar ).toStdString().c_str() ) );
412 if ( ! envValue.isEmpty() )
418 return mSettings[ envVar ].defaultVal;
422 return mSettings[ envVar ].val;
426 void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
428 if ( ! envOptPath.isEmpty() )
430 QSettings::setDefaultFormat( QSettings::IniFormat );
431 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
435 void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
437 const auto constKeys( env.keys() );
440 Setting s = mSettings[ e ];
443 if ( ! env.value( e ).isEmpty() )
445 varValue.setValue( env.value( e ) );
448 if ( ! varValue.isNull() && varValue.canConvert( s.type ) )
453 else if ( ! s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
455 s.val = QSettings().value( s.iniKey );
466 if ( s.type == QVariant::String && s.val.toString().isEmpty() )
478 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
479 return metaEnumEnv.valueToKey( env );
484 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
487 for (
const Setting &s : std::as_const( mSettings ) )
489 const QString src = metaEnumSrc.valueToKey( s.src );
490 const QString var =
name( s.envVar );
492 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
498 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
506 return QSettings().fileName();
617 if ( service.compare( QLatin1String(
"WMS" ) ) )
621 else if ( service.compare( QLatin1String(
"WFS" ) ) )
625 else if ( service.compare( QLatin1String(
"WCS" ) ) )
629 else if ( service.compare( QLatin1String(
"WMTS" ) ) )
634 if ( result.isEmpty() )
650 if ( result.compare( QLatin1String(
"filesystem" ) ) &&
651 result.compare( QLatin1String(
"periodic" ) ) &&
652 result.compare( QLatin1String(
"off" ) ) )
654 QgsMessageLog::logMessage( QStringLiteral(
"Invalid cache strategy, expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default." ),
"Server", Qgis::MessageLevel::Warning );
655 result = QStringLiteral(
"filesystem" );