Skip to content

Commit c4b3ada

Browse files
committed
Add options to override locale and number group sep.
1 parent 9e5dccd commit c4b3ada

File tree

3 files changed

+92
-39
lines changed

3 files changed

+92
-39
lines changed

src/app/main.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,9 @@ int main( int argc, char *argv[] )
11421142
/* Translation file for QGIS.
11431143
*/
11441144
QString i18nPath = QgsApplication::i18nPath();
1145-
QString myUserLocale = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
1145+
QString myUserTranslation = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
1146+
QString myGlobalLocale = mySettings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString();
1147+
bool myOmitGroupSeparatorFlag = mySettings.value( QStringLiteral( "locale/omitGroupSeparator" ), true ).toBool();
11461148
bool myLocaleOverrideFlag = mySettings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
11471149

11481150
//
@@ -1160,7 +1162,7 @@ int main( int argc, char *argv[] )
11601162
}
11611163
else
11621164
{
1163-
if ( !myLocaleOverrideFlag || myUserLocale.isEmpty() )
1165+
if ( !myLocaleOverrideFlag || myUserTranslation.isEmpty() )
11641166
{
11651167
myTranslationCode = QLocale().name();
11661168
//setting the locale/userLocale when the --lang= option is not set will allow third party
@@ -1169,10 +1171,33 @@ int main( int argc, char *argv[] )
11691171
}
11701172
else
11711173
{
1172-
myTranslationCode = myUserLocale;
1174+
myTranslationCode = myUserTranslation;
11731175
}
11741176
}
11751177

1178+
// Global locale settings
1179+
if ( myLocaleOverrideFlag && ! myGlobalLocale.isEmpty( ) )
1180+
{
1181+
QLocale currentLocale( myGlobalLocale );
1182+
QLocale::setDefault( currentLocale );
1183+
}
1184+
1185+
// Number settings
1186+
if ( myLocaleOverrideFlag )
1187+
{
1188+
QLocale currentLocale;
1189+
if ( myOmitGroupSeparatorFlag )
1190+
{
1191+
currentLocale.setNumberOptions( currentLocale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
1192+
}
1193+
else
1194+
{
1195+
currentLocale.setNumberOptions( currentLocale.numberOptions() &= ! QLocale::NumberOption::OmitGroupSeparator );
1196+
}
1197+
QLocale::setDefault( currentLocale );
1198+
}
1199+
1200+
11761201
QTranslator qgistor( nullptr );
11771202
QTranslator qttor( nullptr );
11781203
if ( myTranslationCode != QLatin1String( "C" ) )

src/app/qgsoptions.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,16 +906,22 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
906906
QString mySystemLocale = QLocale().name();
907907
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( mySystemLocale ) );
908908
QString myUserLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
909+
bool omitGroupSeparator = mSettings->value( QStringLiteral( "locale/omitGroupSeparator" ), false ).toBool();
910+
QString myGlobalLocale = mSettings->value( QStringLiteral( "locale/globalLocale" ), QString() ).toString();
909911
QStringList myI18nList = i18nList();
910912
Q_FOREACH ( const QString &l, myI18nList )
911913
{
912914
// QTBUG-57802: eo locale is improperly handled
913915
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
914-
cboLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
916+
cboTranslation->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
917+
cboGlobalLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
915918
}
916-
cboLocale->setCurrentIndex( cboLocale->findData( myUserLocale ) );
919+
cboTranslation->setCurrentIndex( cboTranslation->findData( myUserLocale ) );
920+
cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( myGlobalLocale ) );
917921
bool myLocaleOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
918922
grpLocale->setChecked( myLocaleOverrideFlag );
923+
cbOmitGroupSeparator->setChecked( omitGroupSeparator );
924+
919925

920926
//set elements in digitizing tab
921927
mLineWidthSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt() );
@@ -1586,8 +1592,12 @@ void QgsOptions::saveOptions()
15861592
//
15871593
// Locale settings
15881594
//
1589-
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboLocale->currentData().toString() );
1595+
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboTranslation->currentData().toString() );
15901596
mSettings->setValue( QStringLiteral( "locale/overrideFlag" ), grpLocale->isChecked() );
1597+
mSettings->setValue( QStringLiteral( "locale/globalLocale" ), cboGlobalLocale->currentData( ).toString() );
1598+
1599+
// Number settings
1600+
mSettings->setValue( QStringLiteral( "locale/omitGroupSeparator" ), cbOmitGroupSeparator->isChecked( ) );
15911601

15921602
// Gdal skip driver list
15931603
if ( mLoadedGdalDriverList )

src/ui/qgsoptionsbase.ui

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
<item>
321321
<widget class="QStackedWidget" name="mOptionsStackedWidget">
322322
<property name="currentIndex">
323-
<number>8</number>
323+
<number>0</number>
324324
</property>
325325
<widget class="QWidget" name="mOptionsPageGeneral">
326326
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -349,8 +349,8 @@
349349
<rect>
350350
<x>0</x>
351351
<y>0</y>
352-
<width>411</width>
353-
<height>662</height>
352+
<width>843</width>
353+
<height>855</height>
354354
</rect>
355355
</property>
356356
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -368,6 +368,23 @@
368368
</property>
369369
<item>
370370
<layout class="QGridLayout" name="gridLayout_25">
371+
<item row="6" column="0" colspan="2">
372+
<widget class="QLabel" name="label_7">
373+
<property name="text">
374+
<string>&lt;b&gt;Note:&lt;/b&gt; Enabling / changing override on locale requires an application restart</string>
375+
</property>
376+
<property name="wordWrap">
377+
<bool>true</bool>
378+
</property>
379+
</widget>
380+
</item>
381+
<item row="2" column="0">
382+
<widget class="QLabel" name="label_52">
383+
<property name="text">
384+
<string>Locale (affects numbers representation)</string>
385+
</property>
386+
</widget>
387+
</item>
371388
<item row="0" column="0">
372389
<widget class="QLabel" name="label_5">
373390
<property name="text">
@@ -376,15 +393,15 @@
376393
</widget>
377394
</item>
378395
<item row="0" column="1">
379-
<widget class="QComboBox" name="cboLocale"/>
396+
<widget class="QComboBox" name="cboTranslation"/>
380397
</item>
381-
<item row="1" column="0" colspan="2">
382-
<widget class="QLabel" name="label_7">
398+
<item row="2" column="1">
399+
<widget class="QComboBox" name="cboGlobalLocale"/>
400+
</item>
401+
<item row="3" column="1">
402+
<widget class="QCheckBox" name="cbOmitGroupSeparator">
383403
<property name="text">
384-
<string>&lt;b&gt;Note:&lt;/b&gt; Enabling / changing override on locale requires an application restart</string>
385-
</property>
386-
<property name="wordWrap">
387-
<bool>true</bool>
404+
<string>Omit group (thousand) separator</string>
388405
</property>
389406
</widget>
390407
</item>
@@ -1043,8 +1060,8 @@
10431060
<rect>
10441061
<x>0</x>
10451062
<y>0</y>
1046-
<width>437</width>
1047-
<height>1011</height>
1063+
<width>544</width>
1064+
<height>1096</height>
10481065
</rect>
10491066
</property>
10501067
<layout class="QVBoxLayout" name="verticalLayout_22">
@@ -1579,8 +1596,8 @@
15791596
<rect>
15801597
<x>0</x>
15811598
<y>0</y>
1582-
<width>443</width>
1583-
<height>312</height>
1599+
<width>556</width>
1600+
<height>369</height>
15841601
</rect>
15851602
</property>
15861603
<layout class="QGridLayout" name="gridLayout_15">
@@ -1746,8 +1763,8 @@
17461763
<rect>
17471764
<x>0</x>
17481765
<y>0</y>
1749-
<width>393</width>
1750-
<height>648</height>
1766+
<width>496</width>
1767+
<height>753</height>
17511768
</rect>
17521769
</property>
17531770
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -2114,8 +2131,8 @@
21142131
<rect>
21152132
<x>0</x>
21162133
<y>0</y>
2117-
<width>541</width>
2118-
<height>866</height>
2134+
<width>675</width>
2135+
<height>1052</height>
21192136
</rect>
21202137
</property>
21212138
<layout class="QGridLayout" name="gridLayout_22">
@@ -2865,8 +2882,8 @@
28652882
<rect>
28662883
<x>0</x>
28672884
<y>0</y>
2868-
<width>449</width>
2869-
<height>195</height>
2885+
<width>507</width>
2886+
<height>314</height>
28702887
</rect>
28712888
</property>
28722889
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -3176,8 +3193,8 @@
31763193
<rect>
31773194
<x>0</x>
31783195
<y>0</y>
3179-
<width>515</width>
3180-
<height>527</height>
3196+
<width>613</width>
3197+
<height>646</height>
31813198
</rect>
31823199
</property>
31833200
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -3620,8 +3637,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
36203637
<rect>
36213638
<x>0</x>
36223639
<y>0</y>
3623-
<width>124</width>
3624-
<height>230</height>
3640+
<width>154</width>
3641+
<height>271</height>
36253642
</rect>
36263643
</property>
36273644
<layout class="QHBoxLayout" name="horizontalLayout_46">
@@ -3788,8 +3805,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
37883805
<rect>
37893806
<x>0</x>
37903807
<y>0</y>
3791-
<width>862</width>
3792-
<height>838</height>
3808+
<width>547</width>
3809+
<height>873</height>
37933810
</rect>
37943811
</property>
37953812
<layout class="QVBoxLayout" name="verticalLayout_31">
@@ -4390,8 +4407,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
43904407
<rect>
43914408
<x>0</x>
43924409
<y>0</y>
4393-
<width>390</width>
4394-
<height>539</height>
4410+
<width>474</width>
4411+
<height>606</height>
43954412
</rect>
43964413
</property>
43974414
<layout class="QVBoxLayout" name="verticalLayout_39">
@@ -4659,8 +4676,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
46594676
<rect>
46604677
<x>0</x>
46614678
<y>0</y>
4662-
<width>862</width>
4663-
<height>838</height>
4679+
<width>415</width>
4680+
<height>392</height>
46644681
</rect>
46654682
</property>
46664683
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -4828,8 +4845,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
48284845
<rect>
48294846
<x>0</x>
48304847
<y>0</y>
4831-
<width>862</width>
4832-
<height>838</height>
4848+
<width>616</width>
4849+
<height>737</height>
48334850
</rect>
48344851
</property>
48354852
<layout class="QVBoxLayout" name="verticalLayout_33">
@@ -5449,7 +5466,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
54495466
<tabstop>mOptionsListWidget</tabstop>
54505467
<tabstop>mOptionsScrollArea_01</tabstop>
54515468
<tabstop>grpLocale</tabstop>
5452-
<tabstop>cboLocale</tabstop>
5469+
<tabstop>cboTranslation</tabstop>
54535470
<tabstop>cmbStyle</tabstop>
54545471
<tabstop>cmbUITheme</tabstop>
54555472
<tabstop>cmbIconSize</tabstop>
@@ -5672,6 +5689,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
56725689
<include location="../../images/images.qrc"/>
56735690
<include location="../../images/images.qrc"/>
56745691
<include location="../../images/images.qrc"/>
5692+
<include location="../../images/images.qrc"/>
56755693
</resources>
56765694
<connections>
56775695
<connection>

0 commit comments

Comments
 (0)