28#include "moc_qgsserversettings.cpp"
30using namespace Qt::StringLiterals;
37void QgsServerSettings::initSettings()
43 const Setting sOptPath
45 mSettings[sOptPath.envVar] = sOptPath;
53 u
"Activate/Deactivate parallel rendering for WMS getMap request"_s,
54 u
"/qgis/parallel_rendering"_s,
55 QMetaType::Type::Bool,
59 mSettings[sParRend.envVar] = sParRend;
66 mSettings[sMaxThreads.envVar] = sMaxThreads;
73 mSettings[sLogLevel.envVar] = sLogLevel;
79 mSettings[sLogFile.envVar] = sLogFile;
86 mSettings[sLogStderr.envVar] = sLogStderr;
92 mSettings[sProject.envVar] = sProject;
99 mSettings[sCacheDir.envVar] = sCacheDir;
106 mSettings[sCacheSize.envVar] = sCacheSize;
111 const Setting sOverrideSystemLocale
113 mSettings[sOverrideSystemLocale.envVar] = sOverrideSystemLocale;
120 mSettings[sIgnoreBadLayers.envVar] = sIgnoreBadLayers;
124 const Setting sIgnoreRenderingErrors
126 mSettings[sIgnoreRenderingErrors.envVar] = sIgnoreRenderingErrors;
133 mSettings[sRetryBadLayers.envVar] = sRetryBadLayers;
138 const Setting sTrustLayerMetadata
140 mSettings[sTrustLayerMetadata.envVar] = sTrustLayerMetadata;
145 const Setting sForceReadOnlyLayers
147 mSettings[sForceReadOnlyLayers.envVar] = sForceReadOnlyLayers;
154 mSettings[sDontLoadLayouts.envVar] = sDontLoadLayouts;
159 const Setting sShowGroupSeparator
161 mSettings[sShowGroupSeparator.envVar] = sShowGroupSeparator;
169 u
"Maximum height for a WMS request. The lower one of this and the project configuration is used."_s,
170 u
"/qgis/max_wms_height"_s,
171 QMetaType::Type::LongLong,
175 mSettings[sMaxHeight.envVar] = sMaxHeight;
183 u
"Maximum width for a WMS request. The most conservative between this and the project one is used"_s,
184 u
"/qgis/max_wms_width"_s,
185 QMetaType::Type::LongLong,
189 mSettings[sMaxWidth.envVar] = sMaxWidth;
194 const Setting sApiResourcesDirectory = {
197 u
"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for"_s,
198 u
"/qgis/server_api_resources_directory"_s,
199 QMetaType::Type::QString,
203 mSettings[sApiResourcesDirectory.envVar] = sApiResourcesDirectory;
208 const Setting sApiWfs3MaxLimit = {
211 u
"Maximum value for \"limit\" in a features request, defaults to 10000"_s,
212 u
"/qgis/server_api_wfs3_max_limit"_s,
213 QMetaType::Type::LongLong,
217 mSettings[sApiWfs3MaxLimit.envVar] = sApiWfs3MaxLimit;
223#if _QGIS_VERSION_INT > 40000
230 mSettings[sApiWfs3RootPath.envVar] = sApiWfs3RootPath;
235 const Setting sProjectsDirectories = {
238 u
"Directories used by the landing page service to find .qgs and .qgz projects"_s,
239 u
"/qgis/server_projects_directories"_s,
240 QMetaType::Type::QString,
244 mSettings[sProjectsDirectories.envVar] = sProjectsDirectories;
249 const Setting sProjectsPgConnections = {
252 u
"PostgreSQL connection strings used by the landing page service to find projects"_s,
253 u
"/qgis/server_projects_pg_connections"_s,
254 QMetaType::Type::QString,
258 mSettings[sProjectsPgConnections.envVar] = sProjectsPgConnections;
263 const Setting sLandingPageBaseUrlPrefix
265 mSettings[sLandingPageBaseUrlPrefix.envVar] = sLandingPageBaseUrlPrefix;
273 u
"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0"_s,
274 u
"/qgis/server_log_profile"_s,
275 QMetaType::Type::Bool,
279 mSettings[sLogProfile.envVar] = sLogProfile;
286 mSettings[sServiceUrl.envVar] = sServiceUrl;
293 mSettings[sWmsServiceUrl.envVar] = sWmsServiceUrl;
300 mSettings[sWfsServiceUrl.envVar] = sWfsServiceUrl;
307 mSettings[sWcsServiceUrl.envVar] = sWcsServiceUrl;
314 mSettings[sWmtsServiceUrl.envVar] = sWmtsServiceUrl;
319 const Setting sConfigCacheCheckInterval = {
322 u
"The default project cache check interval (in ms)"_s,
323 u
"/qgis/server_project_cache_check_interval"_s,
324 QMetaType::Type::Int,
328 mSettings[sConfigCacheCheckInterval.envVar] = sConfigCacheCheckInterval;
333 const Setting sProjectCacheStrategy = {
336 u
"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'"_s,
337 u
"/qgis/server_project_cache_strategy"_s,
338 QMetaType::Type::QString,
342 mSettings[sProjectCacheStrategy.envVar] = sProjectCacheStrategy;
347 const Setting sProjectCacheSize
349 mSettings[sProjectCacheSize.envVar] = sProjectCacheSize;
353 const Setting sAllowedExtraSqlTokens = {
356 u
"List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features"_s,
357 u
"/qgis/server_allowed_extra_sql_tokens"_s,
358 QMetaType::Type::QString,
362 mSettings[sAllowedExtraSqlTokens.envVar] = sAllowedExtraSqlTokens;
366 const Setting sApplicationName = {
369 u
"The QGIS Server application name"_s,
370 u
"/qgis/application_full_name"_s,
371 QMetaType::Type::QString,
375 mSettings[sApplicationName.envVar] = sApplicationName;
379 const Setting sCapabilitiesCacheSize
381 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
392 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
404 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
405 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
409 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
417QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
419 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
421 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
422 for (
int i = 0; i < metaEnum.keyCount(); i++ )
434 const QString envValue( getenv(
name( envVar ).toStdString().c_str() ) );
436 if ( !envValue.isEmpty() )
442 return mSettings[envVar].defaultVal;
446 return mSettings[envVar].val;
450void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
452 if ( !envOptPath.isEmpty() )
454 QSettings::setDefaultFormat( QSettings::IniFormat );
455 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
459void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
461 for (
auto envIt = env.constBegin(); envIt != env.constEnd(); ++envIt )
465 auto settingIt = mSettings.find( e );
466 if ( settingIt == mSettings.end() )
470 if ( !envIt.value().isEmpty() )
472 varValue.setValue( envIt.value() );
477 settingIt->val = varValue;
480 else if ( !settingIt->iniKey.isEmpty() && QSettings().contains( settingIt->iniKey ) && QSettings().value( settingIt->iniKey ).canConvert( settingIt->type ) )
482 settingIt->val = QSettings().value( settingIt->iniKey );
487 settingIt->val = QVariant();
493 if ( settingIt->type == QMetaType::Type::QString && settingIt->val.toString().isEmpty() )
495 settingIt->val = QVariant();
503 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
504 return metaEnumEnv.valueToKey( env );
509 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
512 for (
const Setting &s : std::as_const( mSettings ) )
514 const QString src = metaEnumSrc.valueToKey( s.src );
515 const QString var =
name( s.envVar );
517 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
523 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
531 return QSettings().fileName();
662 if ( service.compare(
"WMS"_L1, Qt::CaseInsensitive ) == 0 )
666 else if ( service.compare(
"WFS"_L1, Qt::CaseInsensitive ) == 0 )
670 else if ( service.compare(
"WCS"_L1, Qt::CaseInsensitive ) == 0 )
674 else if ( service.compare(
"WMTS"_L1, Qt::CaseInsensitive ) == 0 )
679 if ( result.isEmpty() )
695 if ( result.compare(
"filesystem"_L1 ) && result.compare(
"periodic"_L1 ) && result.compare(
"off"_L1 ) )
697 if ( !result.isEmpty() )
705 result = u
"filesystem"_s;
714 if ( ok && size >= 1 )
724 if ( strVal.isEmpty() )
726 return QStringList();
728 return strVal.split(
',' );
740 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, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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_PROJECT_CACHE_SIZE
Set the project cache size, in number of projects.
@ 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_API_WFS3_ROOT_PATH
Root path for OAPIF (WFS3) service API, default value is "/wfs3".
@ 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_RETRY_BAD_LAYERS
Retry bad layers in following request in case they might only be temporary unavailable.
@ 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_IGNORE_RENDERING_ERRORS
Ignore rendering errors if true. If false, the server returns an error if a rendering error occurs.
@ 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:...
int projectCacheSize() const
Returns the projects cache size The default value is 100, the value can be changed by setting the env...
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 retryBadLayers() const
Returns true if bad layers should be re-checked after the project has been cached.
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 apiWfs3RootPath() const
Returns the server-wide root path for OAPIF (WFS3) service API.
QString logFile() const
Returns the log file.
qlonglong apiWfs3MaxLimit() const
Returns the server-wide maximum allowed value for "limit" in a features request.
bool ignoreRenderingErrors() const
Returns true if rendering errors are ignored by the server.
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.