Skip to content

Commit 879c699

Browse files
committed
Add preview for locale settings
1 parent c4b3ada commit 879c699

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/app/qgsoptions.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
9696
connect( mCustomVariablesChkBx, &QCheckBox::toggled, this, &QgsOptions::mCustomVariablesChkBx_toggled );
9797
connect( mCurrentVariablesQGISChxBx, &QCheckBox::toggled, this, &QgsOptions::mCurrentVariablesQGISChxBx_toggled );
9898
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsOptions::showHelp );
99+
connect( cboGlobalLocale, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), [ = ]( int ) { updateSampleLocaleText( ); } );
100+
connect( cbOmitGroupSeparator, &QCheckBox::toggled, this, [ = ]( bool ) { updateSampleLocaleText(); } );
99101

100102
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
101103
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
@@ -2365,6 +2367,24 @@ void QgsOptions::refreshSchemeComboBox()
23652367
mColorSchemesComboBox->blockSignals( false );
23662368
}
23672369

2370+
void QgsOptions::updateSampleLocaleText()
2371+
{
2372+
QLocale locale( cboGlobalLocale->currentData( ).toString() );
2373+
if ( cbOmitGroupSeparator->isChecked( ) )
2374+
{
2375+
locale.setNumberOptions( locale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
2376+
}
2377+
else
2378+
{
2379+
locale.setNumberOptions( locale.numberOptions() &= ! QLocale::NumberOption::OmitGroupSeparator );
2380+
}
2381+
lblLocaleSample->setText( tr( "Sample date: %1 money: %2 int: %3 float: %4" ).arg(
2382+
QDate::currentDate().toString( locale.dateFormat( QLocale::FormatType::ShortFormat ) ),
2383+
locale.toCurrencyString( 1000.00 ),
2384+
locale.toString( 1000 ),
2385+
locale.toString( 1000.00, 'f', 2 ) ) );
2386+
}
2387+
23682388
void QgsOptions::updateActionsForCurrentColorScheme( QgsColorScheme *scheme )
23692389
{
23702390
if ( !scheme )

src/app/qgsoptions.h

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
255255

256256
void refreshSchemeComboBox();
257257

258+
void updateSampleLocaleText();
259+
258260
protected:
259261
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
260262
QMap<QString, QVariant> mStyleSheetNewOpts;

src/ui/qgsoptionsbase.ui

+14-4
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
<x>0</x>
351351
<y>0</y>
352352
<width>843</width>
353-
<height>855</height>
353+
<height>885</height>
354354
</rect>
355355
</property>
356356
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -381,7 +381,7 @@
381381
<item row="2" column="0">
382382
<widget class="QLabel" name="label_52">
383383
<property name="text">
384-
<string>Locale (affects numbers representation)</string>
384+
<string>Locale (numbers, date and currency formats)</string>
385385
</property>
386386
</widget>
387387
</item>
@@ -417,6 +417,16 @@
417417
</property>
418418
</widget>
419419
</item>
420+
<item>
421+
<widget class="QLabel" name="lblLocaleSample">
422+
<property name="styleSheet">
423+
<string notr="true">QLabel {background-color: #ffffff; }</string>
424+
</property>
425+
<property name="text">
426+
<string>Sample text for locale formatting</string>
427+
</property>
428+
</widget>
429+
</item>
420430
</layout>
421431
</widget>
422432
</item>
@@ -1061,7 +1071,7 @@
10611071
<x>0</x>
10621072
<y>0</y>
10631073
<width>544</width>
1064-
<height>1096</height>
1074+
<height>1094</height>
10651075
</rect>
10661076
</property>
10671077
<layout class="QVBoxLayout" name="verticalLayout_22">
@@ -3194,7 +3204,7 @@
31943204
<x>0</x>
31953205
<y>0</y>
31963206
<width>613</width>
3197-
<height>646</height>
3207+
<height>636</height>
31983208
</rect>
31993209
</property>
32003210
<layout class="QVBoxLayout" name="verticalLayout_30">

0 commit comments

Comments
 (0)