[FEATURE] new global expression variable $qgis_locale

Returns current locale used by QGIS. By default this is current
system locale. If user enabled locale override in QGIS settings
overriden locale will be returned.
This commit is contained in:
Alexander Bruy 2017-01-05 20:35:29 +02:00
parent 68e09d4c63
commit c2bd4b940b
3 changed files with 21 additions and 0 deletions

View File

@ -48,6 +48,7 @@
#include <QIcon>
#include <QPixmap>
#include <QThreadPool>
#include <QLocale>
#ifndef Q_OS_WIN
#include <netinet/in.h>
@ -902,6 +903,20 @@ QString QgsApplication::platform()
return sPlatformName;
}
QString QgsApplication::locale()
{
QSettings settings;
bool overrideLocale = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
if ( overrideLocale )
{
return settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
}
else
{
return QLocale::system().name().left( 2 );
}
}
QString QgsApplication::userThemesFolder()
{
return qgisSettingsDirPath() + QStringLiteral( "/themes" );

View File

@ -241,6 +241,11 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
static QString platform();
/** Returns the QGIS locale.
* @note added in QGIS 3.0
*/
static QString locale();
//! Returns the path to user's themes folder
static QString userThemesFolder();

View File

@ -524,6 +524,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::globalScope()
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_release_name" ), Qgis::QGIS_RELEASE_NAME, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_platform" ), QgsApplication::platform(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_os_name" ), QgsApplication::osName(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_locale" ), QgsApplication::locale(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "user_account_name" ), QgsApplication::userLoginName(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "user_full_name" ), QgsApplication::userFullName(), true ) );