20#include "moc_qgsserversettings.cpp"
32void QgsServerSettings::initSettings()
39 QStringLiteral(
"Override the default path for user configuration" ),
41 QMetaType::Type::QString,
45 mSettings[ sOptPath.envVar ] = sOptPath;
50 QStringLiteral(
"Activate/Deactivate parallel rendering for WMS getMap request" ),
51 QStringLiteral(
"/qgis/parallel_rendering" ),
52 QMetaType::Type::Bool,
56 mSettings[ sParRend.envVar ] = sParRend;
61 QStringLiteral(
"Number of threads to use when parallel rendering is activated" ),
62 QStringLiteral(
"/qgis/max_threads" ),
67 mSettings[ sMaxThreads.envVar ] = sMaxThreads;
72 QStringLiteral(
"Log level" ),
78 mSettings[ sLogLevel.envVar ] = sLogLevel;
83 QStringLiteral(
"Log file" ),
85 QMetaType::Type::QString,
89 mSettings[ sLogFile.envVar ] = sLogFile;
94 QStringLiteral(
"Activate/Deactivate logging to stderr" ),
96 QMetaType::Type::Bool,
100 mSettings[ sLogStderr.envVar ] = sLogStderr;
105 QStringLiteral(
"QGIS project file" ),
107 QMetaType::Type::QString,
111 mSettings[ sProject.envVar ] = sProject;
116 QStringLiteral(
"Specify the cache directory" ),
117 QStringLiteral(
"/cache/directory" ),
118 QMetaType::Type::QString,
122 mSettings[ sCacheDir.envVar ] = sCacheDir;
127 QStringLiteral(
"Specify the cache size (0 = automatic size)" ),
128 QStringLiteral(
"/cache/size-bytes" ),
129 QMetaType::Type::LongLong,
133 mSettings[ sCacheSize.envVar ] = sCacheSize;
138 QStringLiteral(
"Override system locale" ),
139 QStringLiteral(
"/locale/userLocale" ),
140 QMetaType::Type::QString,
144 mSettings[ sOverrideSystemLocale.envVar ] = sOverrideSystemLocale;
149 QStringLiteral(
"Ignore bad layers" ),
151 QMetaType::Type::Bool,
155 mSettings[ sIgnoreBadLayers.envVar ] = sIgnoreBadLayers;
160 QStringLiteral(
"Trust layer metadata" ),
162 QMetaType::Type::Bool,
166 mSettings[ sTrustLayerMetadata.envVar ] = sTrustLayerMetadata;
172 QStringLiteral(
"Force to open layers in read-only mode" ),
174 QMetaType::Type::Bool,
178 mSettings[ sForceReadOnlyLayers.envVar ] = sForceReadOnlyLayers;
183 QStringLiteral(
"Don't load layouts" ),
185 QMetaType::Type::Bool,
189 mSettings[ sDontLoadLayouts.envVar ] = sDontLoadLayouts;
194 QStringLiteral(
"Show group (thousands) separator" ),
195 QStringLiteral(
"/locale/showGroupSeparator" ),
196 QMetaType::Type::QString,
200 mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;
205 QStringLiteral(
"Maximum height for a WMS request. The lower one of this and the project configuration is used." ),
206 QStringLiteral(
"/qgis/max_wms_height" ),
207 QMetaType::Type::LongLong,
211 mSettings[ sMaxHeight.envVar ] = sMaxHeight;
216 QStringLiteral(
"Maximum width for a WMS request. The most conservative between this and the project one is used" ),
217 QStringLiteral(
"/qgis/max_wms_width" ),
218 QMetaType::Type::LongLong,
222 mSettings[ sMaxWidth.envVar ] = sMaxWidth;
227 QStringLiteral(
"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for" ),
228 QStringLiteral(
"/qgis/server_api_resources_directory" ),
229 QMetaType::Type::QString,
234 mSettings[ sApiResourcesDirectory.envVar ] = sApiResourcesDirectory;
239 QStringLiteral(
"Maximum value for \"limit\" in a features request, defaults to 10000" ),
240 QStringLiteral(
"/qgis/server_api_wfs3_max_limit" ),
241 QMetaType::Type::LongLong,
246 mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;
251 QStringLiteral(
"Directories used by the landing page service to find .qgs and .qgz projects" ),
252 QStringLiteral(
"/qgis/server_projects_directories" ),
253 QMetaType::Type::QString,
258 mSettings[ sProjectsDirectories.envVar ] = sProjectsDirectories;
263 QStringLiteral(
"PostgreSQL connection strings used by the landing page service to find projects" ),
264 QStringLiteral(
"/qgis/server_projects_pg_connections" ),
265 QMetaType::Type::QString,
270 mSettings[ sProjectsPgConnections.envVar ] = sProjectsPgConnections;
275 QStringLiteral(
"Landing page base URL path prefix" ),
276 QStringLiteral(
"/qgis/server_landing_page_base_url_prefix" ),
277 QMetaType::Type::QString,
282 mSettings[ sLandingPageBaseUrlPrefix.envVar ] = sLandingPageBaseUrlPrefix;
287 QStringLiteral(
"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0" ),
288 QStringLiteral(
"/qgis/server_log_profile" ),
289 QMetaType::Type::Bool,
294 mSettings[ sLogProfile.envVar ] = sLogProfile;
299 QStringLiteral(
"The default service URL" ),
300 QStringLiteral(
"/qgis/server_service_url" ),
301 QMetaType::Type::QString,
305 mSettings[ sServiceUrl.envVar ] = sServiceUrl;
310 QStringLiteral(
"The default WMS service URL" ),
311 QStringLiteral(
"/qgis/server_wms_service_url" ),
312 QMetaType::Type::QString,
316 mSettings[ sServiceUrl.envVar ] = sWmsServiceUrl;
321 QStringLiteral(
"The default WFS service URL" ),
322 QStringLiteral(
"/qgis/server_wfs_service_url" ),
323 QMetaType::Type::QString,
327 mSettings[ sServiceUrl.envVar ] = sWfsServiceUrl;
332 QStringLiteral(
"The default WcS service URL" ),
333 QStringLiteral(
"/qgis/server_wcs_service_url" ),
334 QMetaType::Type::QString,
338 mSettings[ sServiceUrl.envVar ] = sWfsServiceUrl;
343 QStringLiteral(
"The default WMTS service URL" ),
344 QStringLiteral(
"/qgis/server_wmts_service_url" ),
345 QMetaType::Type::QString,
349 mSettings[ sServiceUrl.envVar ] = sWmtsServiceUrl;
354 QStringLiteral(
"The default project cache check interval (in ms)" ),
355 QStringLiteral(
"/qgis/server_project_cache_check_interval" ),
356 QMetaType::Type::Int,
360 mSettings[ sConfigCacheCheckInterval.envVar ] = sConfigCacheCheckInterval;
365 QStringLiteral(
"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'" ),
366 QStringLiteral(
"/qgis/server_project_cache_strategy" ),
367 QMetaType::Type::QString,
371 mSettings[ sProjectCacheStrategy.envVar ] = sProjectCacheStrategy;
375 QStringLiteral(
"List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features" ),
376 QStringLiteral(
"/qgis/server_allowed_extra_sql_tokens" ),
377 QMetaType::Type::QString,
381 mSettings[ sAllowedExtraSqlTokens.envVar ] = sAllowedExtraSqlTokens;
385 QStringLiteral(
"The QGIS Server application name" ),
386 QStringLiteral(
"/qgis/application_full_name" ),
387 QMetaType::Type::QString,
391 mSettings[ sApplicationName.envVar ] = sApplicationName;
395 QStringLiteral(
"The QGIS Server capabilities cache size" ),
396 QStringLiteral(
"/qgis/capabilities_cache_size" ),
397 QMetaType::Type::Int,
401 mSettings[ sCapabilitiesCacheSize.envVar ] = sCapabilitiesCacheSize;
411 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
423 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
424 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
428 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
436QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
438 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
440 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
441 for (
int i = 0; i < metaEnum.keyCount(); i++ )
453 const QString envValue( getenv(
name( envVar ).toStdString().c_str() ) );
455 if ( ! envValue.isEmpty() )
461 return mSettings[ envVar ].defaultVal;
465 return mSettings[ envVar ].val;
469void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
471 if ( ! envOptPath.isEmpty() )
473 QSettings::setDefaultFormat( QSettings::IniFormat );
474 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
478void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
480 const auto constKeys( env.keys() );
483 Setting s = mSettings[ e ];
486 if ( ! env.value( e ).isEmpty() )
488 varValue.setValue( env.value( e ) );
496 else if ( ! s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
498 s.val = QSettings().value( s.iniKey );
509 if ( s.type == QMetaType::Type::QString && s.val.toString().isEmpty() )
521 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
522 return metaEnumEnv.valueToKey( env );
527 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
530 for (
const Setting &s : std::as_const( mSettings ) )
532 const QString src = metaEnumSrc.valueToKey( s.src );
533 const QString var =
name( s.envVar );
535 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
541 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
549 return QSettings().fileName();
665 if ( service.compare( QLatin1String(
"WMS" ) ) )
669 else if ( service.compare( QLatin1String(
"WFS" ) ) )
673 else if ( service.compare( QLatin1String(
"WCS" ) ) )
677 else if ( service.compare( QLatin1String(
"WMTS" ) ) )
682 if ( result.isEmpty() )
698 if ( result.compare( QLatin1String(
"filesystem" ) ) &&
699 result.compare( QLatin1String(
"periodic" ) ) &&
700 result.compare( QLatin1String(
"off" ) ) )
703 result = QStringLiteral(
"filesystem" );
711 if ( strVal.isEmpty() )
713 return QStringList();
715 return strVal.split(
',' );
727 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.