31void QgsServerSettings::initSettings()
38 QStringLiteral(
"Override the default path for user configuration" ),
40 QMetaType::Type::QString,
44 mSettings[ sOptPath.envVar ] = sOptPath;
49 QStringLiteral(
"Activate/Deactivate parallel rendering for WMS getMap request" ),
50 QStringLiteral(
"/qgis/parallel_rendering" ),
51 QMetaType::Type::Bool,
55 mSettings[ sParRend.envVar ] = sParRend;
60 QStringLiteral(
"Number of threads to use when parallel rendering is activated" ),
61 QStringLiteral(
"/qgis/max_threads" ),
66 mSettings[ sMaxThreads.envVar ] = sMaxThreads;
71 QStringLiteral(
"Log level" ),
77 mSettings[ sLogLevel.envVar ] = sLogLevel;
82 QStringLiteral(
"Log file" ),
84 QMetaType::Type::QString,
88 mSettings[ sLogFile.envVar ] = sLogFile;
93 QStringLiteral(
"Activate/Deactivate logging to stderr" ),
95 QMetaType::Type::Bool,
99 mSettings[ sLogStderr.envVar ] = sLogStderr;
104 QStringLiteral(
"QGIS project file" ),
106 QMetaType::Type::QString,
110 mSettings[ sProject.envVar ] = sProject;
115 QStringLiteral(
"Specify the cache directory" ),
116 QStringLiteral(
"/cache/directory" ),
117 QMetaType::Type::QString,
121 mSettings[ sCacheDir.envVar ] = sCacheDir;
126 QStringLiteral(
"Specify the cache size (0 = automatic size)" ),
127 QStringLiteral(
"/cache/size-bytes" ),
128 QMetaType::Type::LongLong,
132 mSettings[ sCacheSize.envVar ] = sCacheSize;
137 QStringLiteral(
"Override system locale" ),
138 QStringLiteral(
"/locale/userLocale" ),
139 QMetaType::Type::QString,
143 mSettings[ sOverrideSystemLocale.envVar ] = sOverrideSystemLocale;
148 QStringLiteral(
"Ignore bad layers" ),
150 QMetaType::Type::Bool,
154 mSettings[ sIgnoreBadLayers.envVar ] = sIgnoreBadLayers;
159 QStringLiteral(
"Trust layer metadata" ),
161 QMetaType::Type::Bool,
165 mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;
171 QStringLiteral(
"Force to open layers in read-only mode" ),
173 QMetaType::Type::Bool,
177 mSettings[ sForceReadOnlyLayers.envVar ] = sForceReadOnlyLayers;
182 QStringLiteral(
"Don't load layouts" ),
184 QMetaType::Type::Bool,
188 mSettings[ sDontLoadLayouts.envVar ] = sDontLoadLayouts;
193 QStringLiteral(
"Show group (thousands) separator" ),
194 QStringLiteral(
"/locale/showGroupSeparator" ),
195 QMetaType::Type::QString,
199 mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;
204 QStringLiteral(
"Maximum height for a WMS request. The lower one of this and the project configuration is used." ),
205 QStringLiteral(
"/qgis/max_wms_height" ),
206 QMetaType::Type::LongLong,
210 mSettings[ sMaxHeight.envVar ] = sMaxHeight;
215 QStringLiteral(
"Maximum width for a WMS request. The most conservative between this and the project one is used" ),
216 QStringLiteral(
"/qgis/max_wms_width" ),
217 QMetaType::Type::LongLong,
221 mSettings[ sMaxWidth.envVar ] = sMaxWidth;
226 QStringLiteral(
"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for" ),
227 QStringLiteral(
"/qgis/server_api_resources_directory" ),
228 QMetaType::Type::QString,
233 mSettings[ sApiResourcesDirectory.envVar ] = sApiResourcesDirectory;
238 QStringLiteral(
"Maximum value for \"limit\" in a features request, defaults to 10000" ),
239 QStringLiteral(
"/qgis/server_api_wfs3_max_limit" ),
240 QMetaType::Type::LongLong,
245 mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;
250 QStringLiteral(
"Directories used by the landing page service to find .qgs and .qgz projects" ),
251 QStringLiteral(
"/qgis/server_projects_directories" ),
252 QMetaType::Type::QString,
257 mSettings[ sProjectsDirectories.envVar ] = sProjectsDirectories;
262 QStringLiteral(
"PostgreSQL connection strings used by the landing page service to find projects" ),
263 QStringLiteral(
"/qgis/server_projects_pg_connections" ),
264 QMetaType::Type::QString,
269 mSettings[ sProjectsPgConnections.envVar ] = sProjectsPgConnections;
274 QStringLiteral(
"Landing page base URL path prefix" ),
275 QStringLiteral(
"/qgis/server_landing_page_base_url_prefix" ),
276 QMetaType::Type::QString,
281 mSettings[ sLandingPageBaseUrlPrefix.envVar ] = sLandingPageBaseUrlPrefix;
286 QStringLiteral(
"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0" ),
287 QStringLiteral(
"/qgis/server_log_profile" ),
288 QMetaType::Type::Bool,
293 mSettings[ sLogProfile.envVar ] = sLogProfile;
298 QStringLiteral(
"The default service URL" ),
299 QStringLiteral(
"/qgis/server_service_url" ),
300 QMetaType::Type::QString,
304 mSettings[ sServiceUrl.envVar ] = sServiceUrl;
309 QStringLiteral(
"The default WMS service URL" ),
310 QStringLiteral(
"/qgis/server_wms_service_url" ),
311 QMetaType::Type::QString,
315 mSettings[ sServiceUrl.envVar ] = sWmsServiceUrl;
320 QStringLiteral(
"The default WFS service URL" ),
321 QStringLiteral(
"/qgis/server_wfs_service_url" ),
322 QMetaType::Type::QString,
326 mSettings[ sServiceUrl.envVar ] = sWfsServiceUrl;
331 QStringLiteral(
"The default WcS service URL" ),
332 QStringLiteral(
"/qgis/server_wcs_service_url" ),
333 QMetaType::Type::QString,
337 mSettings[ sServiceUrl.envVar ] = sWfsServiceUrl;
342 QStringLiteral(
"The default WMTS service URL" ),
343 QStringLiteral(
"/qgis/server_wmts_service_url" ),
344 QMetaType::Type::QString,
348 mSettings[ sServiceUrl.envVar ] = sWmtsServiceUrl;
353 QStringLiteral(
"The default project cache check interval (in ms)" ),
354 QStringLiteral(
"/qgis/server_project_cache_check_interval" ),
355 QMetaType::Type::Int,
359 mSettings[ sConfigCacheCheckInterval.envVar ] = sConfigCacheCheckInterval;
364 QStringLiteral(
"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'" ),
365 QStringLiteral(
"/qgis/server_project_cache_strategy" ),
366 QMetaType::Type::QString,
370 mSettings[ sProjectCacheStrategy.envVar ] = sProjectCacheStrategy;
374 QStringLiteral(
"List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features" ),
375 QStringLiteral(
"/qgis/server_allowed_extra_sql_tokens" ),
376 QMetaType::Type::QString,
380 mSettings[ sAllowedExtraSqlTokens.envVar ] = sAllowedExtraSqlTokens;
384 QStringLiteral(
"The QGIS Server application name" ),
385 QStringLiteral(
"/qgis/application_full_name" ),
386 QMetaType::Type::QString,
390 mSettings[ sApplicationName.envVar ] = sApplicationName;
394 QStringLiteral(
"The QGIS Server capabilities cache size" ),
395 QStringLiteral(
"/qgis/capabilities_cache_size" ),
396 QMetaType::Type::Int,
400 mSettings[ sCapabilitiesCacheSize.envVar ] = sCapabilitiesCacheSize;
410 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
422 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
423 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
427 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
435QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
437 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
439 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
440 for (
int i = 0; i < metaEnum.keyCount(); i++ )
452 const QString envValue( getenv(
name( envVar ).toStdString().c_str() ) );
454 if ( ! envValue.isEmpty() )
460 return mSettings[ envVar ].defaultVal;
464 return mSettings[ envVar ].val;
468void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
470 if ( ! envOptPath.isEmpty() )
472 QSettings::setDefaultFormat( QSettings::IniFormat );
473 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
477void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
479 const auto constKeys( env.keys() );
482 Setting s = mSettings[ e ];
485 if ( ! env.value( e ).isEmpty() )
487 varValue.setValue( env.value( e ) );
495 else if ( ! s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
497 s.val = QSettings().value( s.iniKey );
508 if ( s.type == QMetaType::Type::QString && s.val.toString().isEmpty() )
520 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
521 return metaEnumEnv.valueToKey( env );
526 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
529 for (
const Setting &s : std::as_const( mSettings ) )
531 const QString src = metaEnumSrc.valueToKey( s.src );
532 const QString var =
name( s.envVar );
534 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
540 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
548 return QSettings().fileName();
664 if ( service.compare( QLatin1String(
"WMS" ) ) )
668 else if ( service.compare( QLatin1String(
"WFS" ) ) )
672 else if ( service.compare( QLatin1String(
"WCS" ) ) )
676 else if ( service.compare( QLatin1String(
"WMTS" ) ) )
681 if ( result.isEmpty() )
697 if ( result.compare( QLatin1String(
"filesystem" ) ) &&
698 result.compare( QLatin1String(
"periodic" ) ) &&
699 result.compare( QLatin1String(
"off" ) ) )
702 result = QStringLiteral(
"filesystem" );
710 if ( strVal.isEmpty() )
712 return QStringList();
714 return strVal.split(
',' );
726 if ( ok && size >= 1 )
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
@ Info
Information message.
static QString pkgDataPath()
Returns the common root path of all application data directories.
static QString applicationFullName()
Returns the QGIS application full name.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
EnvVar
Environment variables to configure the server.
@ QGIS_SERVER_WCS_SERVICE_URL
To set the WCS service URL if it's not present in the project.
@ QGIS_SERVER_WMTS_SERVICE_URL
To set the WMTS service URL if it's not present in the project.
@ QGIS_SERVER_IGNORE_BAD_LAYERS
Do not consider the whole project unavailable if it contains bad layers.
@ QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS
Adds these tokens to the list of allowed tokens that the services accept when filtering features.
@ QGIS_SERVER_MAX_THREADS
@ QGIS_SERVER_CAPABILITIES_CACHE_SIZE
Define the QGIS Server capabilities cache size.
@ QGIS_SERVER_LANDING_PAGE_PREFIX
Prefix of the path component of the landing page base URL, default is empty.
@ QGIS_SERVER_TRUST_LAYER_METADATA
Trust layer metadata. Improves project read time.
@ QGIS_SERVER_WFS_SERVICE_URL
To set the WFS service URL if it's not present in the project.
@ QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE
Override system locale.
@ QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS
PostgreSQL connection strings used by the landing page service to find projects.
@ QGIS_SERVER_PARALLEL_RENDERING
@ QGIS_SERVER_API_WFS3_MAX_LIMIT
Maximum value for "limit" in a features request, defaults to 10000.
@ QGIS_SERVER_API_RESOURCES_DIRECTORY
Base directory where HTML templates and static assets (e.g. images, js and css files) are searched fo...
@ QGIS_SERVER_WMS_MAX_WIDTH
Maximum width for a WMS request. The most conservative between this and the project one is used.
@ QGIS_SERVER_FORCE_READONLY_LAYERS
Force to open layers in read-only mode.
@ QGIS_SERVER_PROJECT_CACHE_STRATEGY
Set the project cache strategy. Possible values are 'filesystem', 'periodic' or 'off'.
@ QGIS_SERVER_APPLICATION_NAME
Define the QGIS Server application name.
@ QGIS_SERVER_WMS_MAX_HEIGHT
Maximum height for a WMS request. The most conservative between this and the project one is used.
@ QGIS_SERVER_WMS_SERVICE_URL
To set the WMS service URL if it's not present in the project.
@ QGIS_SERVER_DISABLE_GETPRINT
Disabled WMS GetPrint request and don't load layouts. Improves project read time.
@ QGIS_SERVER_PROJECT_CACHE_CHECK_INTERVAL
Set the interval in milliseconds for cache invalidation strategy 'interval', default to 0 which selec...
@ QGIS_SERVER_CACHE_DIRECTORY
@ QGIS_SERVER_SHOW_GROUP_SEPARATOR
Show group (thousands) separator when formatting numeric values, defaults to false.
@ QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES
Directories used by the landing page service to find .qgs and .qgz projects.
@ QGIS_SERVER_LOG_PROFILE
When QGIS_SERVER_LOG_LEVEL is 0 this flag adds to the logs detailed information about the time taken ...
@ QGIS_SERVER_SERVICE_URL
To set the service URL if it's not present in the project.
QString serviceUrl(const QString &service) const
Returns the service URL from the setting.
QString cacheDirectory() const
Returns the cache directory.
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
QString landingPageProjectsPgConnections() const
Returns the PostgreSQL connection strings used by the landing page service to find projects.
int maxThreads() const
Returns the maximum number of threads to use.
bool logStderr() const
Returns whether logging to stderr is activated.
QgsServerSettings()
Constructor.
QString projectFile() const
Returns the QGS project file to use.
QString apiResourcesDirectory() const
Returns the server-wide base directory where HTML templates and static assets (e.g.
int projectCacheCheckInterval() const
Returns the config cache check interval (in ms) for the 'periodic' strategy.
Qgis::MessageLevel logLevel() const
Returns the log level.
bool logProfile() const
Returns true if profile information has to be added to the logs, default value is false.
QStringList allowedExtraSqlTokens() const
Returns the list of strings that represent the allowed extra SQL tokens accepted as components of a f...
bool forceReadOnlyLayers() const
Returns true if the reading flag force layer read only is activated.
int wmsMaxWidth() const
Returns the server-wide max width of a WMS GetMap request.
int capabilitiesCacheSize() const
Returns the maximum number of project capabilities to cache.
static QString name(QgsServerSettingsEnv::EnvVar env)
Returns the string representation of a setting.
QString landingPageBaseUrlPrefix() const
Returns the landing page base URL regular expression, defaults to /.
void logSummary() const
Log a summary of settings currently loaded.
QString logFile() const
Returns the log file.
qlonglong apiWfs3MaxLimit() const
Returns the server-wide maximum allowed value for "limit" in a features request.
int wmsMaxHeight() const
Returns the server-wide max height of a WMS GetMap request.
QString landingPageProjectsDirectories() const
Returns the directories used by the landing page service to find .qgs and .qgz projects.
bool parallelRendering() const
Returns parallel rendering setting.
QString applicationName() const
Returns the QGIS Server application name.
bool showGroupSeparator() const
Show group (thousand) separator.
bool ignoreBadLayers() const
Returns true if the bad layers are ignored and false when the presence of a bad layers invalidates th...
QString iniFile() const
Returns the ini file loaded by QSetting.
QString projectCacheStrategy() const
Returns the project's cache strategy The default value is 'filesystem', the value can be changed by s...
QString overrideSystemLocale() const
Overrides system locale.
bool trustLayerMetadata() const
Returns true if the reading flag trust layer metadata is activated.
void load()
Load settings according to current environment variables.
qint64 cacheSize() const
Returns the cache size.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.