Skip to content
Permalink
Browse files
__repr__ for some QgsExpressionNode subclasses
  • Loading branch information
nyalldawson committed Jun 9, 2021
1 parent 409b221 commit 1bcb09abe62f7db273afd5031cca58821cec8cd3
@@ -32,6 +32,12 @@ A node unary operator is modifying the value of ``operand`` by negating it with
%End
~QgsExpressionNodeUnaryOperator();

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeUnaryOperator: %1>" ).arg( sipCpp->text() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

QgsExpressionNodeUnaryOperator::UnaryOperator op() const;
%Docstring
Returns the unary operator.
@@ -122,6 +128,12 @@ Binary combination of the left and the right with op.
%End
~QgsExpressionNodeBinaryOperator();

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeBinaryOperator: %1>" ).arg( sipCpp->text() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

QgsExpressionNodeBinaryOperator::BinaryOperator op() const;
%Docstring
Returns the binary operator.
@@ -311,6 +323,22 @@ a list of arguments that will be passed to it.

~QgsExpressionNodeFunction();

SIP_PYOBJECT __repr__();
%MethodCode
QString function;
if ( QgsExpressionFunction *fd = QgsExpression::QgsExpression::Functions()[sipCpp->fnIndex()] )
{
function = fd->name();
}
else
{
function = QString::number( sipCpp->fnIndex() );
}

QString str = QStringLiteral( "<QgsExpressionNodeFunction: %1>" ).arg( function );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

int fnIndex() const;
%Docstring
Returns the index of the node's function.
@@ -365,6 +393,12 @@ An expression node for literal values.
Constructor for QgsExpressionNodeLiteral, with the specified literal ``value``.
%End

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeLiteral: %1>" ).arg( sipCpp->valueAsString() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

QVariant value() const;
%Docstring
The value of the literal.
@@ -391,6 +425,13 @@ The value of the literal.
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;


QString valueAsString() const;
%Docstring
Returns a string representation of the node's literal value.

.. versionadded:: 3.20
%End

};

class QgsExpressionNodeColumnRef : QgsExpressionNode
@@ -410,6 +451,12 @@ Constructor for QgsExpressionNodeColumnRef, referencing the column
with the specified ``name``.
%End

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeColumnRef: \"%1\">" ).arg( sipCpp->name() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

QString name() const;
%Docstring
The name of the column.
@@ -1345,7 +1345,7 @@ bool QgsExpressionNodeLiteral::prepareNode( QgsExpression *parent, const QgsExpr
}


QString QgsExpressionNodeLiteral::dump() const
QString QgsExpressionNodeLiteral::valueAsString() const
{
if ( mValue.isNull() )
return QStringLiteral( "NULL" );
@@ -1367,6 +1367,11 @@ QString QgsExpressionNodeLiteral::dump() const
}
}

QString QgsExpressionNodeLiteral::dump() const
{
return valueAsString();
}

QSet<QString> QgsExpressionNodeLiteral::referencedColumns() const
{
return QSet<QString>();
@@ -47,6 +47,14 @@ class CORE_EXPORT QgsExpressionNodeUnaryOperator : public QgsExpressionNode
{}
~QgsExpressionNodeUnaryOperator() override { delete mOperand; }

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeUnaryOperator: %1>" ).arg( sipCpp->text() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

/**
* Returns the unary operator.
*/
@@ -140,6 +148,14 @@ class CORE_EXPORT QgsExpressionNodeBinaryOperator : public QgsExpressionNode
{}
~QgsExpressionNodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeBinaryOperator: %1>" ).arg( sipCpp->text() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

/**
* Returns the binary operator.
*/
@@ -325,6 +341,24 @@ class CORE_EXPORT QgsExpressionNodeFunction : public QgsExpressionNode

~QgsExpressionNodeFunction() override;

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString function;
if ( QgsExpressionFunction *fd = QgsExpression::QgsExpression::Functions()[sipCpp->fnIndex()] )
{
function = fd->name();
}
else
{
function = QString::number( sipCpp->fnIndex() );
}

QString str = QStringLiteral( "<QgsExpressionNodeFunction: %1>" ).arg( function );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

/**
* Returns the index of the node's function.
*/
@@ -372,6 +406,14 @@ class CORE_EXPORT QgsExpressionNodeLiteral : public QgsExpressionNode
: mValue( value )
{}

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeLiteral: %1>" ).arg( sipCpp->valueAsString() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

//! The value of the literal.
inline QVariant value() const { return mValue; }

@@ -389,6 +431,13 @@ class CORE_EXPORT QgsExpressionNodeLiteral : public QgsExpressionNode
QgsExpressionNode *clone() const override SIP_FACTORY;
bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;

/**
* Returns a string representation of the node's literal value.
*
* \since QGIS 3.20
*/
QString valueAsString() const;

private:
QVariant mValue;
};
@@ -410,6 +459,14 @@ class CORE_EXPORT QgsExpressionNodeColumnRef : public QgsExpressionNode
, mIndex( -1 )
{}

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsExpressionNodeColumnRef: \"%1\">" ).arg( sipCpp->name() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

//! The name of the column.
QString name() const { return mName; }

0 comments on commit 1bcb09a

Please sign in to comment.