Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add 'Custom Expression' numeric format #58492

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The following has been generated automatically from src/core/numericformats/qgsexpressionbasednumericformat.h
try:
QgsExpressionBasedNumericFormat.__group__ = ['numericformats']
except NameError:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/numericformats/qgsexpressionbasednumericformat.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/


class QgsExpressionBasedNumericFormat : QgsNumericFormat
{
%Docstring(signature="appended")
A numeric formatter which uses a :py:class:`QgsExpression` to calculate the text representation of a value.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsexpressionbasednumericformat.h"
%End
public:

QgsExpressionBasedNumericFormat();

virtual QString id() const;

virtual QString visibleName() const;

virtual int sortKey();

virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const;

virtual QgsNumericFormat *clone() const /Factory/;

virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const /Factory/;

virtual QVariantMap configuration( const QgsReadWriteContext &context ) const;


void setExpression( const QString &expression );
%Docstring
Sets the ``expression`` used to calculate the text representation of a value.

The expression can utilize `@value` to retrieve the numeric value to represent.

.. seealso:: :py:func:`expression`
%End

QString expression() const;
%Docstring
Returns the expression used to calculate the text representation of a value.

.. seealso:: :py:func:`setExpression`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/numericformats/qgsexpressionbasednumericformat.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Constructor for QgsNumericFormatContext.
The context will be populated based on the user's current locale settings.
%End


QChar thousandsSeparator() const;
%Docstring
Returns the thousands separator character.
Expand Down Expand Up @@ -155,6 +154,24 @@ Sets the ``interpretation`` of the numbers being converted.
.. seealso:: :py:func:`interpretation`

.. versionadded:: 3.26
%End

QgsExpressionContext expressionContext() const;
%Docstring
Returns the expression context to use when evaluating :py:class:`QgsExpressions`.

.. seealso:: :py:func:`setExpressionContext`

.. versionadded:: 3.40
%End

void setExpressionContext( const QgsExpressionContext &context );
%Docstring
Sets the expression ``context`` to use when evaluating :py:class:`QgsExpressions`.

.. seealso:: :py:func:`expressionContext`

.. versionadded:: 3.40
%End

};
Expand All @@ -167,6 +184,7 @@ Sets the ``interpretation`` of the numbers being converted.
#include <qgspercentagenumericformat.h>
#include <qgsscientificnumericformat.h>
#include <qgscoordinatenumericformat.h>
#include <qgsexpressionbasednumericformat.h>
%End

class QgsNumericFormat
Expand Down Expand Up @@ -201,6 +219,8 @@ This is an abstract base class and will always need to be subclassed.
sipType = sipType_QgsBasicNumericFormat;
else if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
sipType = sipType_QgsFractionNumericFormat;
else if ( dynamic_cast< QgsExpressionBasedNumericFormat * >( sipCpp ) )
sipType = sipType_QgsExpressionBasedNumericFormat;
else
sipType = NULL;
%End
Expand Down
1 change: 1 addition & 0 deletions python/PyQt6/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@
%Include auto_generated/numericformats/qgsbearingnumericformat.sip
%Include auto_generated/numericformats/qgscoordinatenumericformat.sip
%Include auto_generated/numericformats/qgscurrencynumericformat.sip
%Include auto_generated/numericformats/qgsexpressionbasednumericformat.sip
%Include auto_generated/numericformats/qgsfallbacknumericformat.sip
%Include auto_generated/numericformats/qgsfractionnumericformat.sip
%Include auto_generated/numericformats/qgsnumericformat.sip
Expand Down
4 changes: 4 additions & 0 deletions python/PyQt6/gui/auto_additions/qgsnumericformatwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
QgsFractionNumericFormatWidget.__group__ = ['numericformats']
except NameError:
pass
try:
QgsExpressionBasedNumericFormatWidget.__group__ = ['numericformats']
except NameError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ Constructor for QgsBasicNumericFormatWidget, initially showing the specified ``f
%End
~QgsBasicNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );


virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};

Expand All @@ -102,11 +100,9 @@ Constructor for QgsBearingNumericFormatWidget, initially showing the specified `
%End
~QgsBearingNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );


virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};

Expand Down Expand Up @@ -160,11 +156,9 @@ Constructor for QgsGeographicCoordinateNumericFormatWidget, initially showing th
%End
~QgsGeographicCoordinateNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );


virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};

Expand Down Expand Up @@ -219,11 +213,9 @@ Constructor for QgsCurrencyNumericFormatWidget, initially showing the specified
%End
~QgsCurrencyNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );


virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};

Expand All @@ -249,11 +241,9 @@ Constructor for QgsPercentageNumericFormatWidget, initially showing the specifie
%End
~QgsPercentageNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );


virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};

Expand All @@ -280,11 +270,9 @@ Constructor for QgsScientificNumericFormatWidget, initially showing the specifie
%End
~QgsScientificNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );


virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};

Expand All @@ -309,11 +297,38 @@ Constructor for QgsFractionNumericFormatWidget, initially showing the specified
%End
~QgsFractionNumericFormatWidget();

virtual void setFormat( QgsNumericFormat *format );
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};



class QgsExpressionBasedNumericFormatWidget : QgsNumericFormatWidget, QgsExpressionContextGenerator
{
%Docstring(signature="appended")
A widget which allow control over the properties of a :py:class:`QgsExpressionBasedNumericFormat`.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsnumericformatwidget.h"
%End
public:

QgsExpressionBasedNumericFormatWidget( const QgsNumericFormat *format, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsExpressionBasedNumericFormatWidget, initially showing the specified ``format``.
%End
~QgsExpressionBasedNumericFormatWidget();

QgsExpressionContext createExpressionContext() const final;

virtual QgsNumericFormat *format() /Factory/;
void setFormat( QgsNumericFormat *format ) final;

QgsNumericFormat *format() final /Factory/;

};
/************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_additions/qgsexpressionbasednumericformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The following has been generated automatically from src/core/numericformats/qgsexpressionbasednumericformat.h
try:
QgsExpressionBasedNumericFormat.__group__ = ['numericformats']
except NameError:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/numericformats/qgsexpressionbasednumericformat.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/


class QgsExpressionBasedNumericFormat : QgsNumericFormat
{
%Docstring(signature="appended")
A numeric formatter which uses a :py:class:`QgsExpression` to calculate the text representation of a value.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsexpressionbasednumericformat.h"
%End
public:

QgsExpressionBasedNumericFormat();

virtual QString id() const;

virtual QString visibleName() const;

virtual int sortKey();

virtual QString formatDouble( double value, const QgsNumericFormatContext &context ) const;

virtual QgsNumericFormat *clone() const /Factory/;

virtual QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const /Factory/;

virtual QVariantMap configuration( const QgsReadWriteContext &context ) const;


void setExpression( const QString &expression );
%Docstring
Sets the ``expression`` used to calculate the text representation of a value.

The expression can utilize `@value` to retrieve the numeric value to represent.

.. seealso:: :py:func:`expression`
%End

QString expression() const;
%Docstring
Returns the expression used to calculate the text representation of a value.

.. seealso:: :py:func:`setExpression`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/numericformats/qgsexpressionbasednumericformat.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Constructor for QgsNumericFormatContext.
The context will be populated based on the user's current locale settings.
%End


QChar thousandsSeparator() const;
%Docstring
Returns the thousands separator character.
Expand Down Expand Up @@ -155,6 +154,24 @@ Sets the ``interpretation`` of the numbers being converted.
.. seealso:: :py:func:`interpretation`

.. versionadded:: 3.26
%End

QgsExpressionContext expressionContext() const;
%Docstring
Returns the expression context to use when evaluating :py:class:`QgsExpressions`.

.. seealso:: :py:func:`setExpressionContext`

.. versionadded:: 3.40
%End

void setExpressionContext( const QgsExpressionContext &context );
%Docstring
Sets the expression ``context`` to use when evaluating :py:class:`QgsExpressions`.

.. seealso:: :py:func:`expressionContext`

.. versionadded:: 3.40
%End

};
Expand All @@ -167,6 +184,7 @@ Sets the ``interpretation`` of the numbers being converted.
#include <qgspercentagenumericformat.h>
#include <qgsscientificnumericformat.h>
#include <qgscoordinatenumericformat.h>
#include <qgsexpressionbasednumericformat.h>
%End

class QgsNumericFormat
Expand Down Expand Up @@ -201,6 +219,8 @@ This is an abstract base class and will always need to be subclassed.
sipType = sipType_QgsBasicNumericFormat;
else if ( dynamic_cast< QgsFractionNumericFormat * >( sipCpp ) )
sipType = sipType_QgsFractionNumericFormat;
else if ( dynamic_cast< QgsExpressionBasedNumericFormat * >( sipCpp ) )
sipType = sipType_QgsExpressionBasedNumericFormat;
else
sipType = NULL;
%End
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@
%Include auto_generated/numericformats/qgsbearingnumericformat.sip
%Include auto_generated/numericformats/qgscoordinatenumericformat.sip
%Include auto_generated/numericformats/qgscurrencynumericformat.sip
%Include auto_generated/numericformats/qgsexpressionbasednumericformat.sip
%Include auto_generated/numericformats/qgsfallbacknumericformat.sip
%Include auto_generated/numericformats/qgsfractionnumericformat.sip
%Include auto_generated/numericformats/qgsnumericformat.sip
Expand Down
4 changes: 4 additions & 0 deletions python/gui/auto_additions/qgsnumericformatwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
QgsFractionNumericFormatWidget.__group__ = ['numericformats']
except NameError:
pass
try:
QgsExpressionBasedNumericFormatWidget.__group__ = ['numericformats']
except NameError:
pass
Loading
Loading