Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor tweaks
  • Loading branch information
nyalldawson committed Jan 8, 2020
1 parent 124df2d commit bc997f0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
Expand Up @@ -12,6 +12,11 @@

class QgsNumericFormatSelectorWidget : QgsPanelWidget
{
%Docstring
A widget which allows choice of numeric formats and the properties of them.

.. versionadded:: 3.12
%End

%TypeHeaderCode
#include "qgsnumericformatselectorwidget.h"
Expand Down
4 changes: 3 additions & 1 deletion src/core/numericformats/qgscurrencynumericformat.cpp
Expand Up @@ -22,6 +22,7 @@ QgsCurrencyNumericFormat::QgsCurrencyNumericFormat()
: mPrefix( QStringLiteral( "$" ) )
{
setNumberDecimalPlaces( 2 );
setShowTrailingZeros( true );
}

QString QgsCurrencyNumericFormat::id() const
Expand Down Expand Up @@ -65,8 +66,9 @@ QgsNumericFormat *QgsCurrencyNumericFormat::create( const QVariantMap &configura
res->mPrefix = configuration.value( QStringLiteral( "prefix" ), QStringLiteral( "$" ) ).toString();
res->mSuffix = configuration.value( QStringLiteral( "suffix" ), QString() ).toString();

// override base class default for number of decimal places -- we want to default to 2
// override base class default for number of decimal places -- we want to default to 2, showing trailing zeros
res->setNumberDecimalPlaces( configuration.value( QStringLiteral( "decimals" ), 2 ).toInt() );
res->setShowTrailingZeros( configuration.value( QStringLiteral( "show_trailing_zeros" ), true ).toBool() );

return res.release();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/numericformats/qgsnumericformatselectorwidget.cpp
Expand Up @@ -155,7 +155,7 @@ void QgsNumericFormatSelectorWidget::updateFormatWidget()
void QgsNumericFormatSelectorWidget::updateSampleText()
{
const double sampleValue = mCurrentFormat->suggestSampleValue();
mSampleLabel->setText( QStringLiteral( "%1 %2 %3" ).arg( mPreviewFormat->formatDouble( sampleValue, QgsNumericFormatContext() ) )
mSampleLabel->setText( QStringLiteral( "%1 %2 <b>%3</b>" ).arg( mPreviewFormat->formatDouble( sampleValue, QgsNumericFormatContext() ) )
.arg( QChar( 0x2192 ) )
.arg( mCurrentFormat->formatDouble( sampleValue, QgsNumericFormatContext() ) ) );
}
4 changes: 3 additions & 1 deletion src/gui/numericformats/qgsnumericformatselectorwidget.h
Expand Up @@ -27,7 +27,9 @@ class QgsBasicNumericFormat;

/**
* \ingroup gui
* \class QgsLayerPropertiesWidget
* \class QgsNumericFormatSelectorWidget
* A widget which allows choice of numeric formats and the properties of them.
* \since QGIS 3.12
*/
class GUI_EXPORT QgsNumericFormatSelectorWidget : public QgsPanelWidget, private Ui::QgsNumericFormatSelectorBase
{
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsnumericformat.py
Expand Up @@ -150,6 +150,7 @@ def testCurrencyFormat(self):
f = QgsCurrencyNumericFormat()
f.setPrefix('$')
context = QgsNumericFormatContext()
f.setShowTrailingZeros(False)
self.assertEqual(f.formatDouble(0, context), '$0')
self.assertEqual(f.formatDouble(5, context), '$5')
self.assertEqual(f.formatDouble(5.5, context), '$5.5')
Expand Down

0 comments on commit bc997f0

Please sign in to comment.