@@ -96,6 +96,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
96
96
connect ( mCustomVariablesChkBx , &QCheckBox::toggled, this , &QgsOptions::mCustomVariablesChkBx_toggled );
97
97
connect ( mCurrentVariablesQGISChxBx , &QCheckBox::toggled, this , &QgsOptions::mCurrentVariablesQGISChxBx_toggled );
98
98
connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsOptions::showHelp );
99
+ connect ( cboGlobalLocale, qgis::overload< int >::of ( &QComboBox::currentIndexChanged ), [ = ]( int ) { updateSampleLocaleText ( ); } );
100
+ connect ( cbShowGroupSeparator, &QCheckBox::toggled, this , [ = ]( bool ) { updateSampleLocaleText (); } );
99
101
100
102
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
101
103
// 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
672
674
mRasterCumulativeCutUpperDoubleSpinBox ->setValue ( 100.0 * mSettings ->value ( QStringLiteral ( " /Raster/cumulativeCutUpper" ), QString::number ( QgsRasterMinMaxOrigin::CUMULATIVE_CUT_UPPER ) ).toDouble () );
673
675
674
676
// set the color for selections
675
- int myRed = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_red" ), 255 ).toInt ();
676
- int myGreen = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_green" ), 255 ).toInt ();
677
- int myBlue = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_blue" ), 0 ).toInt ();
678
- int myAlpha = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_alpha" ), 255 ).toInt ();
679
- pbnSelectionColor->setColor ( QColor ( myRed, myGreen, myBlue, myAlpha ) );
677
+ int red = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_red" ), 255 ).toInt ();
678
+ int green = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_green" ), 255 ).toInt ();
679
+ int blue = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_blue" ), 0 ).toInt ();
680
+ int alpha = mSettings ->value ( QStringLiteral ( " /qgis/default_selection_color_alpha" ), 255 ).toInt ();
681
+ pbnSelectionColor->setColor ( QColor ( red, green, blue, alpha ) );
680
682
pbnSelectionColor->setColorDialogTitle ( tr ( " Set Selection Color" ) );
681
683
pbnSelectionColor->setAllowOpacity ( true );
682
684
pbnSelectionColor->setContext ( QStringLiteral ( " gui" ) );
683
685
pbnSelectionColor->setDefaultColor ( QColor ( 255 , 255 , 0 , 255 ) );
684
686
685
687
// set the default color for canvas background
686
- myRed = mSettings ->value ( QStringLiteral ( " /qgis/default_canvas_color_red" ), 255 ).toInt ();
687
- myGreen = mSettings ->value ( QStringLiteral ( " /qgis/default_canvas_color_green" ), 255 ).toInt ();
688
- myBlue = mSettings ->value ( QStringLiteral ( " /qgis/default_canvas_color_blue" ), 255 ).toInt ();
689
- pbnCanvasColor->setColor ( QColor ( myRed, myGreen, myBlue ) );
688
+ red = mSettings ->value ( QStringLiteral ( " /qgis/default_canvas_color_red" ), 255 ).toInt ();
689
+ green = mSettings ->value ( QStringLiteral ( " /qgis/default_canvas_color_green" ), 255 ).toInt ();
690
+ blue = mSettings ->value ( QStringLiteral ( " /qgis/default_canvas_color_blue" ), 255 ).toInt ();
691
+ pbnCanvasColor->setColor ( QColor ( red, green, blue ) );
690
692
pbnCanvasColor->setColorDialogTitle ( tr ( " Set Canvas Color" ) );
691
693
pbnCanvasColor->setContext ( QStringLiteral ( " gui" ) );
692
694
pbnCanvasColor->setDefaultColor ( Qt::white );
693
695
694
696
// set the default color for the measure tool
695
- myRed = mSettings ->value ( QStringLiteral ( " /qgis/default_measure_color_red" ), 222 ).toInt ();
696
- myGreen = mSettings ->value ( QStringLiteral ( " /qgis/default_measure_color_green" ), 155 ).toInt ();
697
- myBlue = mSettings ->value ( QStringLiteral ( " /qgis/default_measure_color_blue" ), 67 ).toInt ();
698
- pbnMeasureColor->setColor ( QColor ( myRed, myGreen, myBlue ) );
697
+ red = mSettings ->value ( QStringLiteral ( " /qgis/default_measure_color_red" ), 222 ).toInt ();
698
+ green = mSettings ->value ( QStringLiteral ( " /qgis/default_measure_color_green" ), 155 ).toInt ();
699
+ blue = mSettings ->value ( QStringLiteral ( " /qgis/default_measure_color_blue" ), 67 ).toInt ();
700
+ pbnMeasureColor->setColor ( QColor ( red, green, blue ) );
699
701
pbnMeasureColor->setColorDialogTitle ( tr ( " Set Measuring Tool Color" ) );
700
702
pbnMeasureColor->setContext ( QStringLiteral ( " gui" ) );
701
703
pbnMeasureColor->setDefaultColor ( QColor ( 222 , 155 , 67 ) );
@@ -901,38 +903,60 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
901
903
mOffsetYSpinBox ->setValue ( mSettings ->value ( QStringLiteral ( " LayoutDesigner/defaultSnapGridOffsetY" ), 0 , QgsSettings::Gui ).toDouble () );
902
904
903
905
//
904
- // Locale settings
906
+ // Translation and locale settings
905
907
//
906
- QString mySystemLocale = QLocale ().name ();
907
- lblSystemLocale->setText ( tr ( " Detected active locale on your system: %1" ).arg ( mySystemLocale ) );
908
- QString myUserLocale = mSettings ->value ( QStringLiteral ( " locale/userLocale" ), QString () ).toString ();
909
- QStringList myI18nList = i18nList ();
910
- Q_FOREACH ( const QString &l, myI18nList )
908
+ QString currentLocale = QLocale ().name ();
909
+ lblSystemLocale->setText ( tr ( " Detected active locale on your system: %1" ).arg ( currentLocale ) );
910
+ QString userLocale = mSettings ->value ( QStringLiteral ( " locale/userLocale" ), QString ( ) ).toString ();
911
+ bool showGroupSeparator = mSettings ->value ( QStringLiteral ( " locale/showGroupSeparator" ), false ).toBool ();
912
+ QString globalLocale = mSettings ->value ( QStringLiteral ( " locale/globalLocale" ), currentLocale ).toString ();
913
+ const QStringList language18nList ( i18nList () );
914
+ for ( const auto &l : language18nList )
911
915
{
912
916
// QTBUG-57802: eo locale is improperly handled
913
917
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 );
918
+ cboTranslation ->addItem ( QIcon ( QString ( " :/images/flags/%1.svg" ).arg ( l ) ), displayName, l );
915
919
}
916
- cboLocale->setCurrentIndex ( cboLocale->findData ( myUserLocale ) );
917
- bool myLocaleOverrideFlag = mSettings ->value ( QStringLiteral ( " locale/overrideFlag" ), false ).toBool ();
918
- grpLocale->setChecked ( myLocaleOverrideFlag );
920
+
921
+ const QList<QLocale> allLocales = QLocale::matchingLocales (
922
+ QLocale::AnyLanguage,
923
+ QLocale::AnyScript,
924
+ QLocale::AnyCountry );
925
+
926
+ QSet<QString> addedLocales;
927
+ for ( const auto &l : allLocales )
928
+ {
929
+ // Do not add duplicates (like en_US)
930
+ if ( ! addedLocales.contains ( l.name () ) )
931
+ {
932
+ cboGlobalLocale->addItem ( QStringLiteral ( " %1 %2 (%3)" ).arg ( QLocale::languageToString ( l.language () ), QLocale::countryToString ( l.country () ), l.name () ), l.name () );
933
+ addedLocales.insert ( l.name () );
934
+ }
935
+ }
936
+
937
+ cboTranslation->setCurrentIndex ( cboTranslation->findData ( userLocale ) );
938
+ cboGlobalLocale->setCurrentIndex ( cboGlobalLocale->findData ( globalLocale ) );
939
+ bool localeOverrideFlag = mSettings ->value ( QStringLiteral ( " locale/overrideFlag" ), false ).toBool ();
940
+ grpLocale->setChecked ( localeOverrideFlag );
941
+ cbShowGroupSeparator->setChecked ( showGroupSeparator );
942
+
919
943
920
944
// set elements in digitizing tab
921
945
mLineWidthSpinBox ->setValue ( mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_width" ), 1 ).toInt () );
922
- myRed = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_red" ), 255 ).toInt ();
923
- myGreen = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_green" ), 0 ).toInt ();
924
- myBlue = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_blue" ), 0 ).toInt ();
925
- myAlpha = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_alpha" ), 200 ).toInt ();
926
- mLineColorToolButton ->setColor ( QColor ( myRed, myGreen, myBlue, myAlpha ) );
946
+ red = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_red" ), 255 ).toInt ();
947
+ green = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_green" ), 0 ).toInt ();
948
+ blue = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_blue" ), 0 ).toInt ();
949
+ alpha = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/line_color_alpha" ), 200 ).toInt ();
950
+ mLineColorToolButton ->setColor ( QColor ( red, green, blue, alpha ) );
927
951
mLineColorToolButton ->setAllowOpacity ( true );
928
952
mLineColorToolButton ->setContext ( QStringLiteral ( " gui" ) );
929
953
mLineColorToolButton ->setDefaultColor ( QColor ( 255 , 0 , 0 , 200 ) );
930
954
931
- myRed = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_red" ), 255 ).toInt ();
932
- myGreen = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_green" ), 0 ).toInt ();
933
- myBlue = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_blue" ), 0 ).toInt ();
934
- myAlpha = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_alpha" ), 30 ).toInt ();
935
- mFillColorToolButton ->setColor ( QColor ( myRed, myGreen, myBlue, myAlpha ) );
955
+ red = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_red" ), 255 ).toInt ();
956
+ green = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_green" ), 0 ).toInt ();
957
+ blue = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_blue" ), 0 ).toInt ();
958
+ alpha = mSettings ->value ( QStringLiteral ( " /qgis/digitizing/fill_color_alpha" ), 30 ).toInt ();
959
+ mFillColorToolButton ->setColor ( QColor ( red, green, blue, alpha ) );
936
960
mFillColorToolButton ->setAllowOpacity ( true );
937
961
mFillColorToolButton ->setContext ( QStringLiteral ( " gui" ) );
938
962
mFillColorToolButton ->setDefaultColor ( QColor ( 255 , 0 , 0 , 30 ) );
@@ -1586,8 +1610,12 @@ void QgsOptions::saveOptions()
1586
1610
//
1587
1611
// Locale settings
1588
1612
//
1589
- mSettings ->setValue ( QStringLiteral ( " locale/userLocale" ), cboLocale ->currentData ().toString () );
1613
+ mSettings ->setValue ( QStringLiteral ( " locale/userLocale" ), cboTranslation ->currentData ().toString () );
1590
1614
mSettings ->setValue ( QStringLiteral ( " locale/overrideFlag" ), grpLocale->isChecked () );
1615
+ mSettings ->setValue ( QStringLiteral ( " locale/globalLocale" ), cboGlobalLocale->currentData ( ).toString () );
1616
+
1617
+ // Number settings
1618
+ mSettings ->setValue ( QStringLiteral ( " locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked ( ) );
1591
1619
1592
1620
// Gdal skip driver list
1593
1621
if ( mLoadedGdalDriverList )
@@ -2355,6 +2383,24 @@ void QgsOptions::refreshSchemeComboBox()
2355
2383
mColorSchemesComboBox ->blockSignals ( false );
2356
2384
}
2357
2385
2386
+ void QgsOptions::updateSampleLocaleText ()
2387
+ {
2388
+ QLocale locale ( cboGlobalLocale->currentData ( ).toString () );
2389
+ if ( cbShowGroupSeparator->isChecked ( ) )
2390
+ {
2391
+ locale.setNumberOptions ( locale.numberOptions () &= ~QLocale::NumberOption::OmitGroupSeparator );
2392
+ }
2393
+ else
2394
+ {
2395
+ locale.setNumberOptions ( locale.numberOptions () |= QLocale::NumberOption::OmitGroupSeparator );
2396
+ }
2397
+ lblLocaleSample->setText ( tr ( " Sample date: %1 money: %2 int: %3 float: %4" ).arg (
2398
+ QDate::currentDate ().toString ( locale.dateFormat ( QLocale::FormatType::ShortFormat ) ),
2399
+ locale.toCurrencyString ( 1000.00 ),
2400
+ locale.toString ( 1000 ),
2401
+ locale.toString ( 1000.00 , ' f' , 2 ) ) );
2402
+ }
2403
+
2358
2404
void QgsOptions::updateActionsForCurrentColorScheme ( QgsColorScheme *scheme )
2359
2405
{
2360
2406
if ( !scheme )
0 commit comments