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 cache directory" ),
115 QStringLiteral(
"/cache/directory" ),
120 mSettings[ sCacheDir.envVar ] = sCacheDir;
125 QStringLiteral(
"Specify the cache size" ),
126 QStringLiteral(
"/cache/size" ),
128 QVariant( 50 * 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(
"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0" ),
262 QStringLiteral(
"/qgis/server_log_profile" ),
268 mSettings[ sLogProfile.envVar ] = sLogProfile;
279 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
291 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
292 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
296 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
304 QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv()
const
306 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
308 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
309 for (
int i = 0; i < metaEnum.keyCount(); i++ )
321 const QString envValue( getenv(
name( envVar ).toStdString().c_str() ) );
323 if ( ! envValue.isEmpty() )
329 return mSettings[ envVar ].defaultVal;
333 return mSettings[ envVar ].val;
337 void QgsServerSettings::loadQSettings(
const QString &envOptPath )
const
339 if ( ! envOptPath.isEmpty() )
341 QSettings::setDefaultFormat( QSettings::IniFormat );
342 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
346 void QgsServerSettings::prioritize(
const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
348 const auto constKeys( env.keys() );
351 Setting s = mSettings[ e ];
354 if ( ! env.value( e ).isEmpty() )
356 varValue.setValue( env.value( e ) );
359 if ( ! varValue.isNull() && varValue.canConvert( s.type ) )
364 else if ( ! s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
366 s.val = QSettings().value( s.iniKey );
377 if ( s.type == QVariant::String && s.val.toString().isEmpty() )
389 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
390 return metaEnumEnv.valueToKey( env );
395 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
398 for (
const Setting &s : qgis::as_const( mSettings ) )
400 const QString src = metaEnumSrc.valueToKey( s.src );
401 const QString var =
name( s.envVar );
403 const QString msg =
" - " + var +
" / '" + s.iniKey +
"' (" + s.descr +
"): '" + value( s.envVar ).toString() +
"' (read from " + src +
")";
409 const QString msg =
"Ini file used to initialize settings: " +
iniFile();
417 return QSettings().fileName();
MessageLevel
Level for messages This will be used both for message log and message bar in application.
static QString pkgDataPath()
Returns the common root path of all application data directories.
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::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_IGNORE_BAD_LAYERS
Do not consider the whole project unavailable if it contains bad layers.
@ QGIS_SERVER_MAX_THREADS
@ QGIS_SERVER_TRUST_LAYER_METADATA
Trust layer metadata. Improves project read time. (since QGIS 3.16).
@ QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE
Override system locale (since QGIS 3.8)
@ QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS
PostgreSQL connection strings used by the landing page service to find projects (since QGIS 3....
@ QGIS_SERVER_PARALLEL_RENDERING
@ QGIS_SERVER_API_WFS3_MAX_LIMIT
Maximum value for "limit" in a features request, defaults to 10000 (since QGIS 3.10).
@ 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 (sinc...
@ QGIS_SERVER_WMS_MAX_HEIGHT
Maximum height for a WMS request. The most conservative between this and the project one is used (sin...
@ QGIS_SERVER_DISABLE_GETPRINT
Disabled WMS GetPrint request and don't load layouts. Improves project read time. (since QGIS 3....
@ QGIS_SERVER_CACHE_DIRECTORY
@ QGIS_SERVER_SHOW_GROUP_SEPARATOR
Show group (thousands) separator when formatting numeric values, defaults to false (since QGIS 3....
@ QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES
Directories used by the landing page service to find .qgs and .qgz projects (since QGIS 3....
@ QGIS_SERVER_LOG_PROFILE
When QGIS_SERVER_LOG_LEVEL is 0 this flag adds to the logs detailed information about the time taken ...
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.
Qgis::MessageLevel logLevel() const
Returns the log level.
int wmsMaxWidth() const
Returns the server-wide max width of a WMS GetMap request.
static QString name(QgsServerSettingsEnv::EnvVar env)
Returns the string representation of a setting.
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.
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.
bool logProfile()
Returns true if profile information has to be added to the logs, default value is false.
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.