Skip to content
Permalink
Browse files

Minor tweaks

  • Loading branch information
nyalldawson committed Jan 7, 2020
1 parent 124df2d commit bc997f077d4f976eda65b49e3d7b121b033e7745
@@ -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"
@@ -22,6 +22,7 @@ QgsCurrencyNumericFormat::QgsCurrencyNumericFormat()
: mPrefix( QStringLiteral( "$" ) )
{
setNumberDecimalPlaces( 2 );
setShowTrailingZeros( true );
}

QString QgsCurrencyNumericFormat::id() const
@@ -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();
}
@@ -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() ) ) );
}
@@ -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
{
@@ -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')

0 comments on commit bc997f0

Please sign in to comment.
You can’t perform that action at this time.