Merge pull request #7337 from elpaso/locale-options

Add options to override locale and number group sep.
This commit is contained in:
Alessandro Pasotti 2018-07-03 09:47:43 +02:00 committed by GitHub
commit 85da39aa82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 175 additions and 70 deletions

View File

@ -1142,9 +1142,18 @@ int main( int argc, char *argv[] )
/* Translation file for QGIS.
*/
QString i18nPath = QgsApplication::i18nPath();
QString myUserLocale = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
QString myUserTranslation = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
QString myGlobalLocale = mySettings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString();
bool myShowGroupSeparatorFlag = false; // Default to false
bool myLocaleOverrideFlag = mySettings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
// Override Show Group Separator if the global override flag is set
if ( myLocaleOverrideFlag )
{
// Default to false again
myShowGroupSeparatorFlag = mySettings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool();
}
//
// Priority of translation is:
// - command line
@ -1160,7 +1169,7 @@ int main( int argc, char *argv[] )
}
else
{
if ( !myLocaleOverrideFlag || myUserLocale.isEmpty() )
if ( !myLocaleOverrideFlag || myUserTranslation.isEmpty() )
{
myTranslationCode = QLocale().name();
//setting the locale/userLocale when the --lang= option is not set will allow third party
@ -1169,10 +1178,30 @@ int main( int argc, char *argv[] )
}
else
{
myTranslationCode = myUserLocale;
myTranslationCode = myUserTranslation;
}
}
// Global locale settings
if ( myLocaleOverrideFlag && ! myGlobalLocale.isEmpty( ) )
{
QLocale currentLocale( myGlobalLocale );
QLocale::setDefault( currentLocale );
}
// Number settings
QLocale currentLocale;
if ( myShowGroupSeparatorFlag )
{
currentLocale.setNumberOptions( currentLocale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
}
else
{
currentLocale.setNumberOptions( currentLocale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
}
QLocale::setDefault( currentLocale );
QTranslator qgistor( nullptr );
QTranslator qttor( nullptr );
if ( myTranslationCode != QLatin1String( "C" ) )

View File

@ -96,6 +96,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
connect( mCustomVariablesChkBx, &QCheckBox::toggled, this, &QgsOptions::mCustomVariablesChkBx_toggled );
connect( mCurrentVariablesQGISChxBx, &QCheckBox::toggled, this, &QgsOptions::mCurrentVariablesQGISChxBx_toggled );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsOptions::showHelp );
connect( cboGlobalLocale, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), [ = ]( int ) { updateSampleLocaleText( ); } );
connect( cbShowGroupSeparator, &QCheckBox::toggled, this, [ = ]( bool ) { updateSampleLocaleText(); } );
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
@ -672,30 +674,30 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mRasterCumulativeCutUpperDoubleSpinBox->setValue( 100.0 * mSettings->value( QStringLiteral( "/Raster/cumulativeCutUpper" ), QString::number( QgsRasterMinMaxOrigin::CUMULATIVE_CUT_UPPER ) ).toDouble() );
//set the color for selections
int myRed = mSettings->value( QStringLiteral( "/qgis/default_selection_color_red" ), 255 ).toInt();
int myGreen = mSettings->value( QStringLiteral( "/qgis/default_selection_color_green" ), 255 ).toInt();
int myBlue = mSettings->value( QStringLiteral( "/qgis/default_selection_color_blue" ), 0 ).toInt();
int myAlpha = mSettings->value( QStringLiteral( "/qgis/default_selection_color_alpha" ), 255 ).toInt();
pbnSelectionColor->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
int red = mSettings->value( QStringLiteral( "/qgis/default_selection_color_red" ), 255 ).toInt();
int green = mSettings->value( QStringLiteral( "/qgis/default_selection_color_green" ), 255 ).toInt();
int blue = mSettings->value( QStringLiteral( "/qgis/default_selection_color_blue" ), 0 ).toInt();
int alpha = mSettings->value( QStringLiteral( "/qgis/default_selection_color_alpha" ), 255 ).toInt();
pbnSelectionColor->setColor( QColor( red, green, blue, alpha ) );
pbnSelectionColor->setColorDialogTitle( tr( "Set Selection Color" ) );
pbnSelectionColor->setAllowOpacity( true );
pbnSelectionColor->setContext( QStringLiteral( "gui" ) );
pbnSelectionColor->setDefaultColor( QColor( 255, 255, 0, 255 ) );
//set the default color for canvas background
myRed = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_red" ), 255 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_green" ), 255 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_blue" ), 255 ).toInt();
pbnCanvasColor->setColor( QColor( myRed, myGreen, myBlue ) );
red = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_red" ), 255 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_green" ), 255 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_blue" ), 255 ).toInt();
pbnCanvasColor->setColor( QColor( red, green, blue ) );
pbnCanvasColor->setColorDialogTitle( tr( "Set Canvas Color" ) );
pbnCanvasColor->setContext( QStringLiteral( "gui" ) );
pbnCanvasColor->setDefaultColor( Qt::white );
// set the default color for the measure tool
myRed = mSettings->value( QStringLiteral( "/qgis/default_measure_color_red" ), 222 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/default_measure_color_green" ), 155 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/default_measure_color_blue" ), 67 ).toInt();
pbnMeasureColor->setColor( QColor( myRed, myGreen, myBlue ) );
red = mSettings->value( QStringLiteral( "/qgis/default_measure_color_red" ), 222 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/default_measure_color_green" ), 155 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/default_measure_color_blue" ), 67 ).toInt();
pbnMeasureColor->setColor( QColor( red, green, blue ) );
pbnMeasureColor->setColorDialogTitle( tr( "Set Measuring Tool Color" ) );
pbnMeasureColor->setContext( QStringLiteral( "gui" ) );
pbnMeasureColor->setDefaultColor( QColor( 222, 155, 67 ) );
@ -901,38 +903,60 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mOffsetYSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetY" ), 0, QgsSettings::Gui ).toDouble() );
//
// Locale settings
// Translation and locale settings
//
QString mySystemLocale = QLocale().name();
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( mySystemLocale ) );
QString myUserLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
QStringList myI18nList = i18nList();
Q_FOREACH ( const QString &l, myI18nList )
QString currentLocale = QLocale().name();
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( currentLocale ) );
QString userLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString( ) ).toString();
bool showGroupSeparator = mSettings->value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool();
QString globalLocale = mSettings->value( QStringLiteral( "locale/globalLocale" ), currentLocale ).toString();
const QStringList language18nList( i18nList() );
for ( const auto &l : language18nList )
{
// QTBUG-57802: eo locale is improperly handled
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
cboLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
cboTranslation->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
}
cboLocale->setCurrentIndex( cboLocale->findData( myUserLocale ) );
bool myLocaleOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
grpLocale->setChecked( myLocaleOverrideFlag );
const QList<QLocale> allLocales = QLocale::matchingLocales(
QLocale::AnyLanguage,
QLocale::AnyScript,
QLocale::AnyCountry );
QSet<QString> addedLocales;
for ( const auto &l : allLocales )
{
// Do not add duplicates (like en_US)
if ( ! addedLocales.contains( l.name() ) )
{
cboGlobalLocale->addItem( QStringLiteral( "%1 %2 (%3)" ).arg( QLocale::languageToString( l.language() ), QLocale::countryToString( l.country() ), l.name() ), l.name() );
addedLocales.insert( l.name() );
}
}
cboTranslation->setCurrentIndex( cboTranslation->findData( userLocale ) );
cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( globalLocale ) );
bool localeOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
grpLocale->setChecked( localeOverrideFlag );
cbShowGroupSeparator->setChecked( showGroupSeparator );
//set elements in digitizing tab
mLineWidthSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt() );
myRed = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt();
myAlpha = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt();
mLineColorToolButton->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
red = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt();
alpha = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt();
mLineColorToolButton->setColor( QColor( red, green, blue, alpha ) );
mLineColorToolButton->setAllowOpacity( true );
mLineColorToolButton->setContext( QStringLiteral( "gui" ) );
mLineColorToolButton->setDefaultColor( QColor( 255, 0, 0, 200 ) );
myRed = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_red" ), 255 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_green" ), 0 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), 0 ).toInt();
myAlpha = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt();
mFillColorToolButton->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
red = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_red" ), 255 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_green" ), 0 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), 0 ).toInt();
alpha = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt();
mFillColorToolButton->setColor( QColor( red, green, blue, alpha ) );
mFillColorToolButton->setAllowOpacity( true );
mFillColorToolButton->setContext( QStringLiteral( "gui" ) );
mFillColorToolButton->setDefaultColor( QColor( 255, 0, 0, 30 ) );
@ -1586,8 +1610,12 @@ void QgsOptions::saveOptions()
//
// Locale settings
//
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboLocale->currentData().toString() );
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboTranslation->currentData().toString() );
mSettings->setValue( QStringLiteral( "locale/overrideFlag" ), grpLocale->isChecked() );
mSettings->setValue( QStringLiteral( "locale/globalLocale" ), cboGlobalLocale->currentData( ).toString() );
// Number settings
mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) );
// Gdal skip driver list
if ( mLoadedGdalDriverList )
@ -2355,6 +2383,24 @@ void QgsOptions::refreshSchemeComboBox()
mColorSchemesComboBox->blockSignals( false );
}
void QgsOptions::updateSampleLocaleText()
{
QLocale locale( cboGlobalLocale->currentData( ).toString() );
if ( cbShowGroupSeparator->isChecked( ) )
{
locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
}
else
{
locale.setNumberOptions( locale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
}
lblLocaleSample->setText( tr( "Sample date: %1 money: %2 int: %3 float: %4" ).arg(
QDate::currentDate().toString( locale.dateFormat( QLocale::FormatType::ShortFormat ) ),
locale.toCurrencyString( 1000.00 ),
locale.toString( 1000 ),
locale.toString( 1000.00, 'f', 2 ) ) );
}
void QgsOptions::updateActionsForCurrentColorScheme( QgsColorScheme *scheme )
{
if ( !scheme )

View File

@ -255,6 +255,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
void refreshSchemeComboBox();
void updateSampleLocaleText();
protected:
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
QMap<QString, QVariant> mStyleSheetNewOpts;

View File

@ -320,7 +320,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>8</number>
<number>0</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -349,8 +349,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>662</height>
<width>843</width>
<height>885</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
@ -368,6 +368,23 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout_25">
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt; Enabling / changing override on locale requires an application restart</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_52">
<property name="text">
<string>Locale (numbers, date and currency formats)</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
@ -376,15 +393,15 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cboLocale"/>
<widget class="QComboBox" name="cboTranslation"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<item row="2" column="1">
<widget class="QComboBox" name="cboGlobalLocale"/>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="cbShowGroupSeparator">
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt; Enabling / changing override on locale requires an application restart</string>
</property>
<property name="wordWrap">
<bool>true</bool>
<string>Show group (thousand) separator</string>
</property>
</widget>
</item>
@ -400,6 +417,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblLocaleSample">
<property name="styleSheet">
<string notr="true">QLabel {background-color: #ffffff; }</string>
</property>
<property name="text">
<string>Sample text for locale formatting</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -1043,8 +1070,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>437</width>
<height>1011</height>
<width>544</width>
<height>1094</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
@ -1579,8 +1606,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>443</width>
<height>312</height>
<width>556</width>
<height>369</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
@ -1746,8 +1773,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>648</height>
<width>496</width>
<height>753</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
@ -2114,8 +2141,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>541</width>
<height>866</height>
<width>675</width>
<height>1052</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_22">
@ -2865,8 +2892,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>195</height>
<width>507</width>
<height>314</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
@ -3176,8 +3203,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>515</width>
<height>527</height>
<width>613</width>
<height>636</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
@ -3620,8 +3647,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>124</width>
<height>230</height>
<width>154</width>
<height>271</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_46">
@ -3788,8 +3815,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>862</width>
<height>838</height>
<width>547</width>
<height>873</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_31">
@ -4390,8 +4417,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>539</height>
<width>474</width>
<height>606</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_39">
@ -4659,8 +4686,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>862</width>
<height>838</height>
<width>415</width>
<height>392</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
@ -4828,8 +4855,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>862</width>
<height>838</height>
<width>616</width>
<height>737</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
@ -5449,7 +5476,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<tabstop>mOptionsListWidget</tabstop>
<tabstop>mOptionsScrollArea_01</tabstop>
<tabstop>grpLocale</tabstop>
<tabstop>cboLocale</tabstop>
<tabstop>cboTranslation</tabstop>
<tabstop>cmbStyle</tabstop>
<tabstop>cmbUITheme</tabstop>
<tabstop>cmbIconSize</tabstop>
@ -5672,6 +5699,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>