Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add numeric formatter for currency values
- Loading branch information
1 parent
d445487
commit 7affde6
Showing
9 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
python/core/auto_generated/numericformats/qgscurrencynumericformat.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/numericformats/qgscurrencynumericformat.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
class QgsCurrencyNumericFormat : QgsBasicNumericFormat | ||
{ | ||
%Docstring | ||
A numeric formatter which returns a text representation of a currency value. | ||
|
||
.. versionadded:: 3.12 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgscurrencynumericformat.h" | ||
%End | ||
public: | ||
|
||
QgsCurrencyNumericFormat(); | ||
%Docstring | ||
Default constructor | ||
%End | ||
|
||
|
||
virtual QString id() const; | ||
|
||
%Docstring | ||
QgsCurrencyNumericFormat cannot be copied | ||
%End | ||
virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const; | ||
|
||
virtual QgsNumericFormat *clone() const /Factory/; | ||
|
||
virtual QgsNumericFormat *create( const QVariantMap &configuration ) const /Factory/; | ||
|
||
virtual QVariantMap configuration() const; | ||
|
||
|
||
QString prefix() const; | ||
%Docstring | ||
Returns the currency prefix, e.g. "$". | ||
|
||
.. seealso:: :py:func:`setPrefix` | ||
%End | ||
|
||
void setPrefix( const QString &prefix ); | ||
%Docstring | ||
Sets the currency ``prefix``, e.g. "$". | ||
|
||
.. seealso:: :py:func:`prefix` | ||
%End | ||
|
||
QString suffix() const; | ||
%Docstring | ||
Returns the currency suffix, e.g. "AUD". | ||
|
||
.. seealso:: :py:func:`setSuffix` | ||
%End | ||
|
||
void setSuffix( const QString &suffix ); | ||
%Docstring | ||
Sets the currency ``suffix``, e.g. "AUD". | ||
|
||
.. seealso:: :py:func:`suffix` | ||
%End | ||
|
||
private: | ||
QgsCurrencyNumericFormat( const QgsCurrencyNumericFormat &other ); | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/numericformats/qgscurrencynumericformat.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*************************************************************************** | ||
qgscurrencynumericformat.cpp | ||
---------------------------- | ||
begin : January 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgscurrencynumericformat.h" | ||
#include "qgis.h" | ||
|
||
|
||
QgsCurrencyNumericFormat::QgsCurrencyNumericFormat() | ||
: mPrefix( QStringLiteral( "$" ) ) | ||
{ | ||
} | ||
|
||
QString QgsCurrencyNumericFormat::id() const | ||
{ | ||
return QStringLiteral( "currency" ); | ||
} | ||
|
||
QString QgsCurrencyNumericFormat::formatDouble( double value, const QgsNumericFormatContext &context ) const | ||
{ | ||
QString res = QgsBasicNumericFormat::formatDouble( value, context ); | ||
if ( value < 0 || ( value > 0 && showPlusSign() ) ) | ||
return res.at( 0 ) + mPrefix + res.mid( 1 ) + mSuffix; | ||
else | ||
return mPrefix + res + mSuffix; | ||
} | ||
|
||
QgsNumericFormat *QgsCurrencyNumericFormat::clone() const | ||
{ | ||
return create( configuration() ); | ||
} | ||
|
||
QgsNumericFormat *QgsCurrencyNumericFormat::create( const QVariantMap &configuration ) const | ||
{ | ||
std::unique_ptr< QgsCurrencyNumericFormat > res = qgis::make_unique< QgsCurrencyNumericFormat >(); | ||
res->setConfiguration( configuration ); | ||
res->mPrefix = configuration.value( QStringLiteral( "prefix" ), QStringLiteral( "$" ) ).toString(); | ||
res->mSuffix = configuration.value( QStringLiteral( "suffix" ), QString() ).toString(); | ||
return res.release(); | ||
} | ||
|
||
QVariantMap QgsCurrencyNumericFormat::configuration() const | ||
{ | ||
QVariantMap res = QgsBasicNumericFormat::configuration(); | ||
res.insert( QStringLiteral( "prefix" ), mPrefix ); | ||
res.insert( QStringLiteral( "suffix" ), mSuffix ); | ||
return res; | ||
} | ||
|
||
QString QgsCurrencyNumericFormat::prefix() const | ||
{ | ||
return mPrefix; | ||
} | ||
|
||
void QgsCurrencyNumericFormat::setPrefix( const QString &prefix ) | ||
{ | ||
mPrefix = prefix; | ||
} | ||
|
||
QString QgsCurrencyNumericFormat::suffix() const | ||
{ | ||
return mSuffix; | ||
} | ||
|
||
void QgsCurrencyNumericFormat::setSuffix( const QString &suffix ) | ||
{ | ||
mSuffix = suffix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*************************************************************************** | ||
qgscurrencynumericformat.h | ||
---------------------------- | ||
begin : January 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSCURRENCYNUMERICFORMAT_H | ||
#define QGSCURRENCYNUMERICFORMAT_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis_sip.h" | ||
#include "qgsbasicnumericformat.h" | ||
|
||
/** | ||
* \ingroup core | ||
* A numeric formatter which returns a text representation of a currency value. | ||
* | ||
* \since QGIS 3.12 | ||
*/ | ||
class CORE_EXPORT QgsCurrencyNumericFormat : public QgsBasicNumericFormat | ||
{ | ||
public: | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
QgsCurrencyNumericFormat(); | ||
|
||
//! QgsCurrencyNumericFormat cannot be copied | ||
QgsCurrencyNumericFormat( const QgsCurrencyNumericFormat & ) = delete; | ||
//! QgsCurrencyNumericFormat cannot be copied | ||
QgsCurrencyNumericFormat &operator=( const QgsCurrencyNumericFormat & ) = delete; | ||
|
||
QString id() const override; | ||
QString formatDouble( double value, const QgsNumericFormatContext &context ) const override; | ||
QgsNumericFormat *clone() const override SIP_FACTORY; | ||
QgsNumericFormat *create( const QVariantMap &configuration ) const override SIP_FACTORY; | ||
QVariantMap configuration() const override; | ||
|
||
/** | ||
* Returns the currency prefix, e.g. "$". | ||
* \see setPrefix() | ||
*/ | ||
QString prefix() const; | ||
|
||
/** | ||
* Sets the currency \a prefix, e.g. "$". | ||
* \see prefix() | ||
*/ | ||
void setPrefix( const QString &prefix ); | ||
|
||
/** | ||
* Returns the currency suffix, e.g. "AUD". | ||
* \see setSuffix() | ||
*/ | ||
QString suffix() const; | ||
|
||
/** | ||
* Sets the currency \a suffix, e.g. "AUD". | ||
* \see suffix() | ||
*/ | ||
void setSuffix( const QString &suffix ); | ||
|
||
private: | ||
|
||
#ifdef SIP_RUN | ||
QgsCurrencyNumericFormat( const QgsCurrencyNumericFormat &other ); | ||
#endif | ||
|
||
QString mPrefix; | ||
QString mSuffix; | ||
|
||
}; | ||
|
||
#endif // QGSCURRENCYNUMERICFORMAT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.