Skip to content

Commit

Permalink
[server][feature][needs-docs] Add env vars to override locale ...
Browse files Browse the repository at this point in the history
...and group separator:

QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE (default '')
QGIS_SERVER_SHOW_GROUP_SEPARATOR (default false)
  • Loading branch information
elpaso committed Apr 1, 2019
1 parent 62895d1 commit 120ae77
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 22 deletions.
14 changes: 14 additions & 0 deletions python/server/auto_generated/qgsserversettings.sip.in
Expand Up @@ -117,6 +117,20 @@ Returns the cache size.
Returns the cache directory.

:return: the directory.
%End

QString overrideSystemLocale() const;
%Docstring
Overrides system locale

:return: the optional override for system locale.
%End

bool showGroupSeparator() const;
%Docstring
Show group (thousand) separator

:return: if group separator must be shown, default to ``False``.
%End

};
Expand Down
23 changes: 23 additions & 0 deletions src/server/qgsserver.cpp
Expand Up @@ -156,6 +156,26 @@ QString QgsServer::configPath( const QString &defaultConfigPath, const QString &
return cfPath;
}

void QgsServer::initLocale()
{
// System locale override
if ( ! sSettings.overrideSystemLocale().isEmpty() )
{
QLocale::setDefault( QLocale( sSettings.overrideSystemLocale() ) );
}
// Number group separator settings
QLocale currentLocale;
if ( sSettings.showGroupSeparator() )
{
currentLocale.setNumberOptions( currentLocale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
}
else
{
currentLocale.setNumberOptions( currentLocale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
}
QLocale::setDefault( currentLocale );
}

bool QgsServer::init()
{
if ( sInitialized )
Expand Down Expand Up @@ -191,6 +211,9 @@ bool QgsServer::init()
QgsServerLogger::instance()->setLogStderr();
}

// Configure locale
initLocale();

// log settings currently used
sSettings.logSummary();

Expand Down
3 changes: 3 additions & 0 deletions src/server/qgsserver.h
Expand Up @@ -144,5 +144,8 @@ class SERVER_EXPORT QgsServer

//! cache
QgsConfigCache *mConfigCache = nullptr;

//! Initialize locale
static void initLocale();
};
#endif // QGSSERVER_H
34 changes: 34 additions & 0 deletions src/server/qgsserversettings.cpp
Expand Up @@ -139,6 +139,29 @@ void QgsServerSettings::initSettings()
QVariant()
};
mSettings[ sCacheSize.envVar ] = sCacheSize;

// system locale override
const Setting sOverrideSystemLocale = { QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "Override system locale" ),
QStringLiteral( "/locale/userLocale" ),
QVariant::String,
QVariant( "" ),
QVariant()
};
mSettings[ sOverrideSystemLocale.envVar ] = sOverrideSystemLocale;

// show group separator
const Setting sShowGroupSeparator = { QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "Show group (thousands) separator" ),
QStringLiteral( "/locale/showGroupSeparator" ),
QVariant::String,
QVariant( false ),
QVariant()
};
mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;

}

void QgsServerSettings::load()
Expand Down Expand Up @@ -319,3 +342,14 @@ QString QgsServerSettings::cacheDirectory() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
}

QString QgsServerSettings::overrideSystemLocale() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE ).toString();
}

bool QgsServerSettings::showGroupSeparator() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR ).toBool();
}

58 changes: 36 additions & 22 deletions src/server/qgsserversettings.h
Expand Up @@ -60,7 +60,9 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
QGIS_PROJECT_FILE,
MAX_CACHE_LAYERS,
QGIS_SERVER_CACHE_DIRECTORY,
QGIS_SERVER_CACHE_SIZE
QGIS_SERVER_CACHE_SIZE,
QGIS_SERVER_SHOW_GROUP_SEPARATOR, //! Show group (thousands) separator when formatting numeric values, defaults to FALSE
QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE, //! Override system locale
};
Q_ENUM( EnvVar )
};
Expand Down Expand Up @@ -88,41 +90,41 @@ class SERVER_EXPORT QgsServerSettings

/**
* Constructor.
*/
*/
QgsServerSettings();

/**
* Load settings according to current environment variables.
*/
*/
void load();

/**
* Load setting for a specific environment variable name.
* \returns TRUE if loading is successful, FALSE in case of an invalid name.
*/
* \returns TRUE if loading is successful, FALSE in case of an invalid name.
*/
bool load( const QString &envVarName );

/**
* Log a summary of settings currently loaded.
*/
*/
void logSummary() const;

/**
* Returns the ini file loaded by QSetting.
* \returns the path of the ini file or an empty string if none is loaded.
*/
* \returns the path of the ini file or an empty string if none is loaded.
*/
QString iniFile() const;

/**
* Returns parallel rendering setting.
* \returns TRUE if parallel rendering is activated, FALSE otherwise.
*/
* \returns TRUE if parallel rendering is activated, FALSE otherwise.
*/
bool parallelRendering() const;

/**
* Returns the maximum number of threads to use.
* \returns the number of threads.
*/
* \returns the number of threads.
*/
int maxThreads() const;

/**
Expand All @@ -133,20 +135,20 @@ class SERVER_EXPORT QgsServerSettings

/**
* Returns the log level.
* \returns the log level.
*/
* \returns the log level.
*/
Qgis::MessageLevel logLevel() const;

/**
* Returns the QGS project file to use.
* \returns the path of the QGS project or an empty string if none is defined.
*/
* \returns the path of the QGS project or an empty string if none is defined.
*/
QString projectFile() const;

/**
* Returns the log file.
* \returns the path of the log file or an empty string if none is defined.
*/
* \returns the path of the log file or an empty string if none is defined.
*/
QString logFile() const;

/**
Expand All @@ -158,16 +160,28 @@ class SERVER_EXPORT QgsServerSettings

/**
* Returns the cache size.
* \returns the cache size.
*/
* \returns the cache size.
*/
qint64 cacheSize() const;

/**
* Returns the cache directory.
* \returns the directory.
*/
* \returns the directory.
*/
QString cacheDirectory() const;

/**
* Overrides system locale
* \returns the optional override for system locale.
*/
QString overrideSystemLocale() const;

/**
* Show group (thousand) separator
* \returns if group separator must be shown, default to FALSE.
*/
bool showGroupSeparator() const;

private:
void initSettings();
QVariant value( QgsServerSettingsEnv::EnvVar envVar ) const;
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -300,6 +300,7 @@ IF (WITH_SERVER)
ADD_PYTHON_TEST(PyQgsServerWMTS test_qgsserver_wmts.py)
ADD_PYTHON_TEST(PyQgsServerWFS test_qgsserver_wfs.py)
ADD_PYTHON_TEST(PyQgsServerWFST test_qgsserver_wfst.py)
ADD_PYTHON_TEST(PyQgsServerLocaleOverride test_qgsserver_locale_override.py)
ADD_PYTHON_TEST(PyQgsOfflineEditingWFS test_offline_editing_wfs.py)
ADD_PYTHON_TEST(PyQgsAuthManagerPasswordOWSTest test_authmanager_password_ows.py)
ADD_PYTHON_TEST(PyQgsAuthManagerPKIOWSTest test_authmanager_pki_ows.py)
Expand Down

0 comments on commit 120ae77

Please sign in to comment.