Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add percentage numeric formatter
- Loading branch information
1 parent
d0b5a01
commit 8bcba47
Showing
11 changed files
with
347 additions
and
1 deletion.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
python/core/auto_generated/numericformats/qgspercentagenumericformat.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,73 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/numericformats/qgspercentagenumericformat.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
class QgsPercentageNumericFormat : QgsBasicNumericFormat | ||
{ | ||
%Docstring | ||
A numeric formatter which returns a text representation of a percentage value. | ||
|
||
.. versionadded:: 3.12 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgspercentagenumericformat.h" | ||
%End | ||
public: | ||
|
||
enum InputValues | ||
{ | ||
ValuesArePercentage, | ||
ValuesAreFractions, | ||
}; | ||
|
||
QgsPercentageNumericFormat(); | ||
%Docstring | ||
Default constructor | ||
%End | ||
|
||
|
||
virtual QString id() const; | ||
|
||
%Docstring | ||
QgsPercentageNumericFormat 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; | ||
|
||
|
||
InputValues inputValues() const; | ||
%Docstring | ||
Returns the format of the incoming values. | ||
|
||
.. seealso:: :py:func:`setInputValues` | ||
%End | ||
|
||
void setInputValues( const InputValues &format ); | ||
%Docstring | ||
Sets the ``format`` of the incoming values. | ||
|
||
.. seealso:: :py:func:`inputValues` | ||
%End | ||
|
||
private: | ||
QgsPercentageNumericFormat( const QgsPercentageNumericFormat &other ); | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/numericformats/qgspercentagenumericformat.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
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,73 @@ | ||
/*************************************************************************** | ||
qgspercentagenumericformat.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 "qgspercentagenumericformat.h" | ||
#include "qgis.h" | ||
|
||
|
||
QgsPercentageNumericFormat::QgsPercentageNumericFormat() | ||
{ | ||
} | ||
|
||
QString QgsPercentageNumericFormat::id() const | ||
{ | ||
return QStringLiteral( "percentage" ); | ||
} | ||
|
||
QString QgsPercentageNumericFormat::formatDouble( double value, const QgsNumericFormatContext &context ) const | ||
{ | ||
switch ( mInputValues ) | ||
{ | ||
case ValuesArePercentage: | ||
break; | ||
|
||
case ValuesAreFractions: | ||
value *= 100; | ||
break; | ||
} | ||
|
||
return QgsBasicNumericFormat::formatDouble( value, context ) + '%'; | ||
} | ||
|
||
QgsNumericFormat *QgsPercentageNumericFormat::clone() const | ||
{ | ||
return create( configuration() ); | ||
} | ||
|
||
QgsNumericFormat *QgsPercentageNumericFormat::create( const QVariantMap &configuration ) const | ||
{ | ||
std::unique_ptr< QgsPercentageNumericFormat > res = qgis::make_unique< QgsPercentageNumericFormat >(); | ||
res->setConfiguration( configuration ); | ||
res->mInputValues = static_cast< InputValues >( configuration.value( QStringLiteral( "input_values" ), static_cast< int >( ValuesArePercentage ) ).toInt() ); | ||
return res.release(); | ||
} | ||
|
||
QVariantMap QgsPercentageNumericFormat::configuration() const | ||
{ | ||
QVariantMap res = QgsBasicNumericFormat::configuration(); | ||
res.insert( QStringLiteral( "input_values" ), static_cast< int >( mInputValues ) ); | ||
return res; | ||
} | ||
|
||
QgsPercentageNumericFormat::InputValues QgsPercentageNumericFormat::inputValues() const | ||
{ | ||
return mInputValues; | ||
} | ||
|
||
void QgsPercentageNumericFormat::setInputValues( const InputValues &inputValues ) | ||
{ | ||
mInputValues = inputValues; | ||
} |
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,79 @@ | ||
/*************************************************************************** | ||
qgspercentagenumericformat.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 QGSPERCENTAGENUMERICFORMAT_H | ||
#define QGSPERCENTAGENUMERICFORMAT_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis_sip.h" | ||
#include "qgsbasicnumericformat.h" | ||
|
||
/** | ||
* \ingroup core | ||
* A numeric formatter which returns a text representation of a percentage value. | ||
* | ||
* \since QGIS 3.12 | ||
*/ | ||
class CORE_EXPORT QgsPercentageNumericFormat : public QgsBasicNumericFormat | ||
{ | ||
public: | ||
|
||
//! Input value format, which specifies the format of the incoming values | ||
enum InputValues | ||
{ | ||
ValuesArePercentage, //!< Incoming values are percentage values (e.g. 50 for 50%) | ||
ValuesAreFractions, //!< Incoming values are numeric fractions (e.g. 0.5 for 50%) | ||
}; | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
QgsPercentageNumericFormat(); | ||
|
||
//! QgsPercentageNumericFormat cannot be copied | ||
QgsPercentageNumericFormat( const QgsPercentageNumericFormat & ) = delete; | ||
//! QgsPercentageNumericFormat cannot be copied | ||
QgsPercentageNumericFormat &operator=( const QgsPercentageNumericFormat & ) = 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 format of the incoming values. | ||
* | ||
* \see setInputValues() | ||
*/ | ||
InputValues inputValues() const; | ||
|
||
/** | ||
* Sets the \a format of the incoming values. | ||
* | ||
* \see inputValues() | ||
*/ | ||
void setInputValues( const InputValues &format ); | ||
|
||
private: | ||
|
||
#ifdef SIP_RUN | ||
QgsPercentageNumericFormat( const QgsPercentageNumericFormat &other ); | ||
#endif | ||
|
||
InputValues mInputValues = ValuesArePercentage; | ||
|
||
}; | ||
|
||
#endif // QGSPERCENTAGENUMERICFORMAT_H |
Oops, something went wrong.