mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Merge pull request #7171 from 3nids/sip_python_repr
create Python __repr__ methods for QgsPoint and QgsPointXY
This commit is contained in:
commit
d36015070c
@ -253,6 +253,11 @@ Returns true if the circle contains the ``point``.
|
|||||||
virtual QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const;
|
virtual QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -162,6 +162,12 @@ Sets the circular string's points
|
|||||||
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
|
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual QgsRectangle calculateBoundingBox() const;
|
virtual QgsRectangle calculateBoundingBox() const;
|
||||||
|
@ -166,6 +166,12 @@ Appends first point if not already closed.
|
|||||||
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;
|
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual QgsRectangle calculateBoundingBox() const;
|
virtual QgsRectangle calculateBoundingBox() const;
|
||||||
|
@ -216,6 +216,12 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
|
|||||||
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;
|
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual int childCount() const;
|
virtual int childCount() const;
|
||||||
|
@ -248,6 +248,12 @@ returns a string representation of the ellipse.
|
|||||||
Members will be truncated to the specified precision.
|
Members will be truncated to the specified precision.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1290,6 +1290,12 @@ Exports the geometry to WKT
|
|||||||
precision parameter added in QGIS 2.4
|
precision parameter added in QGIS 2.4
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
QString asJson( int precision = 17 ) const;
|
QString asJson( int precision = 17 ) const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Exports the geometry to a GeoJSON string.
|
Exports the geometry to a GeoJSON string.
|
||||||
|
@ -317,6 +317,12 @@ of the curve.
|
|||||||
virtual QgsLineString *createEmptyWithSameType() const /Factory/;
|
virtual QgsLineString *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual QgsRectangle calculateBoundingBox() const;
|
virtual QgsRectangle calculateBoundingBox() const;
|
||||||
|
@ -56,6 +56,11 @@ Returns a copy of the multi curve, where each component curve has had its line d
|
|||||||
virtual QgsMultiCurve *createEmptyWithSameType() const /Factory/;
|
virtual QgsMultiCurve *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMulitCurve: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,6 +53,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
|
|||||||
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;
|
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool wktOmitChildType() const;
|
virtual bool wktOmitChildType() const;
|
||||||
|
@ -55,6 +55,12 @@ Multi point geometry collection.
|
|||||||
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;
|
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool wktOmitChildType() const;
|
virtual bool wktOmitChildType() const;
|
||||||
|
@ -54,6 +54,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
|
|||||||
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;
|
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool wktOmitChildType() const;
|
virtual bool wktOmitChildType() const;
|
||||||
|
@ -426,6 +426,12 @@ Angle undefined. Always returns 0.0
|
|||||||
virtual QgsPoint *createEmptyWithSameType() const /Factory/;
|
virtual QgsPoint *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual int childCount() const;
|
virtual int childCount() const;
|
||||||
|
@ -65,6 +65,12 @@ negative if the point lies outside the polygon.
|
|||||||
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;
|
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;
|
||||||
|
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
@ -322,6 +322,12 @@ Converts the rectangle to a 3D box, with the specified
|
|||||||
|
|
||||||
operator QVariant() const;
|
operator QVariant() const;
|
||||||
|
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
%MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,8 +230,7 @@ Multiply x and y by the given value
|
|||||||
|
|
||||||
SIP_PYOBJECT __repr__();
|
SIP_PYOBJECT __repr__();
|
||||||
%MethodCode
|
%MethodCode
|
||||||
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
|
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
|
||||||
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
|
|
||||||
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ while ($LINE_IDX < $LINE_COUNT){
|
|||||||
}
|
}
|
||||||
|
|
||||||
# SIP_SKIP
|
# SIP_SKIP
|
||||||
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_OPERATOR_/ ){
|
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_SPECIAL_/ ){
|
||||||
dbg_info('SIP SKIP!');
|
dbg_info('SIP SKIP!');
|
||||||
# if multiline definition, remove previous lines
|
# if multiline definition, remove previous lines
|
||||||
if ( $MULTILINE_DEFINITION != MULTILINE_NO){
|
if ( $MULTILINE_DEFINITION != MULTILINE_NO){
|
||||||
@ -711,9 +711,18 @@ while ($LINE_IDX < $LINE_COUNT){
|
|||||||
detect_and_remove_following_body_or_initializerlist();
|
detect_and_remove_following_body_or_initializerlist();
|
||||||
# line skipped, go to next iteration
|
# line skipped, go to next iteration
|
||||||
|
|
||||||
if ($LINE =~ m/SIP_PYTHON_OPERATOR_(\w+)\(\s*(\w+)\s*\)/ ){
|
if ($LINE =~ m/SIP_PYTHON_SPECIAL_(\w+)\(\s*(".*"|\w+)\s*\)/ ){
|
||||||
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: self.$2()";
|
my $method_or_code = $2;
|
||||||
dbg_info("PYTHON OPERATOR $pyop");
|
dbg_info("PYTHON SPECIAL method or code: $method_or_code");
|
||||||
|
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: ";
|
||||||
|
if ( $method_or_code =~ m/^"(.*)"$/ ){
|
||||||
|
$pyop .= $1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pyop .= "self.${method_or_code}()";
|
||||||
|
}
|
||||||
|
dbg_info("PYTHON SPECIAL $pyop");
|
||||||
if ($python_output ne ''){
|
if ($python_output ne ''){
|
||||||
push @OUTPUT_PYTHON, "$pyop\n";
|
push @OUTPUT_PYTHON, "$pyop\n";
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,16 @@ count=0
|
|||||||
|
|
||||||
modules=(core gui analysis server)
|
modules=(core gui analysis server)
|
||||||
for module in "${modules[@]}"; do
|
for module in "${modules[@]}"; do
|
||||||
|
|
||||||
|
# clean auto_additions and auto_generated folders
|
||||||
|
rm -rf python/${module}/auto_additions/*.py
|
||||||
|
rm -rf python/${module}/auto_generated/*.py
|
||||||
|
# put back __init__.py
|
||||||
|
echo '"""
|
||||||
|
This folder is completed using sipify.pl script
|
||||||
|
It is not aimed to be manually edited
|
||||||
|
"""' > python/${module}/auto_additions/__init__.py
|
||||||
|
|
||||||
while read -r sipfile; do
|
while read -r sipfile; do
|
||||||
echo "$sipfile.in"
|
echo "$sipfile.in"
|
||||||
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
|
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
|
||||||
|
@ -247,6 +247,13 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
|
|||||||
|
|
||||||
QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const override;
|
QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const override;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSCIRCLE_H
|
#endif // QGSCIRCLE_H
|
||||||
|
@ -146,6 +146,14 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
|
|||||||
|
|
||||||
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
QgsRectangle calculateBoundingBox() const override;
|
QgsRectangle calculateBoundingBox() const override;
|
||||||
|
@ -146,6 +146,14 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
|
|||||||
|
|
||||||
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
QgsRectangle calculateBoundingBox() const override;
|
QgsRectangle calculateBoundingBox() const override;
|
||||||
|
@ -204,6 +204,14 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
|
|||||||
|
|
||||||
QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
int childCount() const override;
|
int childCount() const override;
|
||||||
|
@ -240,6 +240,14 @@ class CORE_EXPORT QgsEllipse
|
|||||||
*/
|
*/
|
||||||
virtual QString toString( int pointPrecision = 17, int axisPrecision = 17, int azimuthPrecision = 2 ) const;
|
virtual QString toString( int pointPrecision = 17, int axisPrecision = 17, int azimuthPrecision = 2 ) const;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QgsPoint mCenter;
|
QgsPoint mCenter;
|
||||||
double mSemiMajorAxis = 0.0;
|
double mSemiMajorAxis = 0.0;
|
||||||
|
@ -1248,6 +1248,14 @@ class CORE_EXPORT QgsGeometry
|
|||||||
*/
|
*/
|
||||||
QString asWkt( int precision = 17 ) const;
|
QString asWkt( int precision = 17 ) const;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports the geometry to a GeoJSON string.
|
* Exports the geometry to a GeoJSON string.
|
||||||
*/
|
*/
|
||||||
|
@ -346,6 +346,14 @@ class CORE_EXPORT QgsLineString: public QgsCurve
|
|||||||
|
|
||||||
QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
QgsRectangle calculateBoundingBox() const override;
|
QgsRectangle calculateBoundingBox() const override;
|
||||||
|
@ -73,6 +73,13 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
|
|||||||
|
|
||||||
QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMulitCurve: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,6 +65,14 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
|
|||||||
|
|
||||||
QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool wktOmitChildType() const override;
|
bool wktOmitChildType() const override;
|
||||||
|
@ -66,6 +66,14 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
|
|||||||
|
|
||||||
QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool wktOmitChildType() const override;
|
bool wktOmitChildType() const override;
|
||||||
|
@ -65,6 +65,14 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
|
|||||||
|
|
||||||
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool wktOmitChildType() const override;
|
bool wktOmitChildType() const override;
|
||||||
|
@ -495,6 +495,14 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
|
|||||||
|
|
||||||
QgsPoint *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsPoint *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
int childCount() const override;
|
int childCount() const override;
|
||||||
|
@ -84,6 +84,14 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
|
|||||||
|
|
||||||
QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;
|
QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class QgsCurvePolygon;
|
friend class QgsCurvePolygon;
|
||||||
|
@ -541,6 +541,14 @@ class CORE_EXPORT QgsRectangle
|
|||||||
return QVariant::fromValue( *this );
|
return QVariant::fromValue( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SIP_RUN
|
||||||
|
SIP_PYOBJECT __repr__();
|
||||||
|
% MethodCode
|
||||||
|
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
|
||||||
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
|
% End
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
double mXmin = 0.0;
|
double mXmin = 0.0;
|
||||||
|
@ -198,9 +198,19 @@
|
|||||||
#define SIP_DOC_TEMPLATE
|
#define SIP_DOC_TEMPLATE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the __bool__ operator using the given method
|
* Define Python special method (bool, repr, etc.) using the given method or code
|
||||||
* sipify.pl will take care of creating the injection in qgis/{module}/__init__.py
|
* sipify.pl will create a dedicated python file named according to the class
|
||||||
|
* and located in python/{module}/auto_additions/{classname}.py
|
||||||
|
* a simple method name can be provided (e.g. isValid) and sipify will create the proper code
|
||||||
|
* or some Python code can be provided:
|
||||||
|
*
|
||||||
|
* SIP_PYTHON_SPECIAL_BOOL( isValid )
|
||||||
|
* => sipify => MyClass.__bool__ = lambda self: self.isValid()
|
||||||
|
*
|
||||||
|
* SIP_PYTHON_SPECIAL_REPR( "'<MyClass {}>'format(self.toString())'" )
|
||||||
|
* => sipify => MyClass.__repr__ = lambda self: '<MyClass {}>'format(self.toString())'
|
||||||
*/
|
*/
|
||||||
#define SIP_PYTHON_OPERATOR_BOOL(method)
|
#define SIP_PYTHON_SPECIAL_BOOL(method_or_code)
|
||||||
|
#define SIP_PYTHON_SPECIAL_REPR(method_or_code)
|
||||||
|
|
||||||
#endif // QGIS_SIP_H
|
#endif // QGIS_SIP_H
|
||||||
|
@ -95,7 +95,7 @@ class CORE_EXPORT QgsDefaultValue
|
|||||||
* Checks if a default value is set. Alias for isValid().
|
* Checks if a default value is set. Alias for isValid().
|
||||||
* \returns false if the expression is a null string.
|
* \returns false if the expression is a null string.
|
||||||
*/
|
*/
|
||||||
operator bool() const SIP_PYTHON_OPERATOR_BOOL( isValid );
|
operator bool() const SIP_PYTHON_SPECIAL_BOOL( isValid );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mExpression;
|
QString mExpression;
|
||||||
|
@ -297,8 +297,7 @@ class CORE_EXPORT QgsPointXY
|
|||||||
#ifdef SIP_RUN
|
#ifdef SIP_RUN
|
||||||
SIP_PYOBJECT __repr__();
|
SIP_PYOBJECT __repr__();
|
||||||
% MethodCode
|
% MethodCode
|
||||||
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
|
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
|
||||||
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
|
|
||||||
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
sipRes = PyUnicode_FromString( str.toUtf8().data() );
|
||||||
% End
|
% End
|
||||||
|
|
||||||
|
@ -16,6 +16,15 @@ modules=(core gui analysis server)
|
|||||||
|
|
||||||
code=0
|
code=0
|
||||||
for module in "${modules[@]}"; do
|
for module in "${modules[@]}"; do
|
||||||
|
# clean auto_additions and auto_generated folders
|
||||||
|
rm -rf python/${module}/auto_additions/*.py
|
||||||
|
rm -rf python/${module}/auto_generated/*.py
|
||||||
|
# put back __init__.py
|
||||||
|
echo '"""
|
||||||
|
This folder is completed using sipify.pl script
|
||||||
|
It is not aimed to be manually edited
|
||||||
|
"""' > python/${module}/auto_additions/__init__.py
|
||||||
|
|
||||||
module_init=${DIR}/python/${module}/__init__.py
|
module_init=${DIR}/python/${module}/__init__.py
|
||||||
cp ${module_init} ${DIR}/${module}.temp
|
cp ${module_init} ${DIR}/${module}.temp
|
||||||
while read -r sipfile; do
|
while read -r sipfile; do
|
||||||
|
@ -9,6 +9,7 @@ IF (WITH_SERVER)
|
|||||||
ENDIF (WITH_SERVER)
|
ENDIF (WITH_SERVER)
|
||||||
|
|
||||||
ADD_PYTHON_TEST(PyCoreAdittions test_core_additions.py)
|
ADD_PYTHON_TEST(PyCoreAdittions test_core_additions.py)
|
||||||
|
ADD_PYTHON_TEST(PyPythonRepr test_python_repr.py)
|
||||||
ADD_PYTHON_TEST(PyQgsActionManager test_qgsactionmanager.py)
|
ADD_PYTHON_TEST(PyQgsActionManager test_qgsactionmanager.py)
|
||||||
ADD_PYTHON_TEST(PyQgsAFSProvider test_provider_afs.py)
|
ADD_PYTHON_TEST(PyQgsAFSProvider test_provider_afs.py)
|
||||||
ADD_PYTHON_TEST(PyQgsPythonProvider test_provider_python.py)
|
ADD_PYTHON_TEST(PyQgsPythonProvider test_provider_python.py)
|
||||||
|
117
tests/src/python/test_python_repr.py
Normal file
117
tests/src/python/test_python_repr.py
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""QGIS Unit tests for core additions
|
||||||
|
|
||||||
|
.. note:: 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.
|
||||||
|
"""
|
||||||
|
__author__ = 'Denis Rouzaud'
|
||||||
|
__date__ = '05.06.2018'
|
||||||
|
__copyright__ = 'Copyright 2015, The QGIS Project'
|
||||||
|
# This will get replaced with a git SHA1 when you do a git archive
|
||||||
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
|
import qgis # NOQA
|
||||||
|
|
||||||
|
from qgis.testing import unittest, start_app
|
||||||
|
from qgis.core import QgsGeometry, QgsPoint, QgsPointXY, QgsCircle, QgsCircularString, QgsCompoundCurve,\
|
||||||
|
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle
|
||||||
|
|
||||||
|
start_app()
|
||||||
|
|
||||||
|
|
||||||
|
class TestPython__repr__(unittest.TestCase):
|
||||||
|
|
||||||
|
def TestQgsGeometryRepr(self):
|
||||||
|
p = QgsPointXY(123.456, 987.654)
|
||||||
|
g = QgsGeometry.fromPointXY(p)
|
||||||
|
self.assertTrue(g.__repr__().startswith('<QgsGeometry: Point (123.456)'))
|
||||||
|
|
||||||
|
def TestQgsPointRepr(self):
|
||||||
|
p = QgsPoint(123.456, 987.654, 100)
|
||||||
|
self.assertTrue(p.__repr__().startswith('<QgsPoint: PointZ (123.456)'))
|
||||||
|
|
||||||
|
def TestQgsPointXYRepr(self):
|
||||||
|
p = QgsPointXY(123.456, 987.654)
|
||||||
|
self.assertTrue(p.__repr__().startswith('<QgsPointXY: POINT(123.456'))
|
||||||
|
|
||||||
|
def TestQgsCircleRepr(self):
|
||||||
|
c = QgsCircle(QgsPoint(1, 1), 2.0)
|
||||||
|
self.assertEqual(c.__repr__(), '<QgsCircle: Circle (Center: Point (1 1), Radius: 2, Azimuth: 0)>')
|
||||||
|
|
||||||
|
def TestQgsCircularstringRepr(self):
|
||||||
|
cs = QgsCircularString(QgsPoint(1, 2), QgsPoint(2, 3), QgsPoint(3, 4))
|
||||||
|
self.assertEqual(cs.__repr__(), '<QgsCompoundCurve: CompoundCurve (CircularString (1 2, 2 3, 3 4))>')
|
||||||
|
|
||||||
|
def TestQgsCompoundcurveRepr(self):
|
||||||
|
cs = QgsCircularString(QgsPoint(1, 2), QgsPoint(2, 3), QgsPoint(3, 4))
|
||||||
|
cc = QgsCompoundCurve()
|
||||||
|
cc.addCurve(cs)
|
||||||
|
self.assertEqual(cc.__repr__(), '<QgsCompoundCurve: CompoundCurve (CircularString (1 2, 2 3, 3 4))>')
|
||||||
|
|
||||||
|
def TestQgsCurvepolygonRepr(self):
|
||||||
|
cp = QgsCurvePolygon()
|
||||||
|
cs = QgsCircularString(QgsPoint(1, 10), QgsPoint(2, 11), QgsPoint(1, 10))
|
||||||
|
cp.setExteriorRing(cs)
|
||||||
|
self.assertEqual(cp.__repr__(), '<QgsCurvePolygon: CurvePolygon (CircularString (1 10, 2 11, 1 10))>')
|
||||||
|
|
||||||
|
def TestQgsEllipseRepr(self):
|
||||||
|
e = QgsEllipse(QgsPoint(1, 2), 2.0, 3.0)
|
||||||
|
self.assertEqual(e.__repr__(), '<QgsEllipse: Ellipse (Center: Point (1 2), Semi-Major Axis: 3, Semi-Minor Axis: 2, Azimuth: 180)>')
|
||||||
|
|
||||||
|
def TestQgsLineStringRepr(self):
|
||||||
|
ls = QgsLineString([QgsPoint(10, 2), QgsPoint(10, 1), QgsPoint(5, 1)])
|
||||||
|
self.assertEqual(ls.__repr__(), '<QgsLineString: LineString (10 2, 10 1, 5 1)>')
|
||||||
|
|
||||||
|
def TestQgsMulticurveRepr(self):
|
||||||
|
mc = QgsMultiCurve()
|
||||||
|
cs = QgsCircularString(QgsPoint(1, 10), QgsPoint(2, 11), QgsPoint(3, 12))
|
||||||
|
mc.addGeometry(cs)
|
||||||
|
cs2 = QgsCircularString(QgsPoint(4, 20), QgsPoint(5, 22), QgsPoint(6, 24))
|
||||||
|
mc.addGeometry(cs2)
|
||||||
|
self.assertEqual(mc.__repr__(), '<QgsMulitCurve: MultiCurve (CircularString (1 10, 2 11, 3 12),CircularString (4 20, 5 22, 6 24))>')
|
||||||
|
|
||||||
|
def TestQgsMultilineStringRepr(self):
|
||||||
|
ml = QgsGeometry.fromMultiPolylineXY(
|
||||||
|
[
|
||||||
|
[QgsPointXY(0, 0), QgsPointXY(1, 0), QgsPointXY(1, 1), QgsPointXY(2, 1), QgsPointXY(2, 0), ],
|
||||||
|
[QgsPointXY(3, 0), QgsPointXY(3, 1), QgsPointXY(5, 1), QgsPointXY(5, 0), QgsPointXY(6, 0), ]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertEqual(ml.constGet().__repr__(), '<QgsMultiLineString: MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0),(3 0, 3 1, 5 1, 5 0, 6 0))>')
|
||||||
|
|
||||||
|
def TestQgsMultiPointRepr(self):
|
||||||
|
wkt = "MultiPoint ((10 30),(40 20),(30 10),(20 10))"
|
||||||
|
mp = QgsGeometry.fromWkt(wkt)
|
||||||
|
self.assertEqual(mp.constGet().__repr__(), '<QgsMultiPoint: MultiPoint ((10 30),(40 20),(30 10),(20 10))>')
|
||||||
|
|
||||||
|
def TestQgsMultipolygonRepr(self):
|
||||||
|
mp = QgsGeometry.fromMultiPolygonXY([
|
||||||
|
[[QgsPointXY(1, 1),
|
||||||
|
QgsPointXY(2, 2),
|
||||||
|
QgsPointXY(1, 2),
|
||||||
|
QgsPointXY(1, 1)]],
|
||||||
|
[[QgsPointXY(2, 2),
|
||||||
|
QgsPointXY(3, 3),
|
||||||
|
QgsPointXY(3, 1),
|
||||||
|
QgsPointXY(2, 2)]]
|
||||||
|
])
|
||||||
|
self.assertEqual(mp.constGet().__repr__(), '<QgsMultiPolygon: MultiPolygon (((1 1, 2 2, 1 2, 1 1)),((2 2, 3 3, 3 1, 2 2)))>')
|
||||||
|
|
||||||
|
def TestQgsPolygonRepr(self):
|
||||||
|
p = QgsGeometry.fromPolygonXY(
|
||||||
|
[[QgsPointXY(0, 0),
|
||||||
|
QgsPointXY(2, 0),
|
||||||
|
QgsPointXY(2, 2),
|
||||||
|
QgsPointXY(0, 2),
|
||||||
|
QgsPointXY(0, 0)]])
|
||||||
|
self.assertEqual(p.constGet().__repr__(), '<QgsPolygon: Polygon ((0 0, 2 0, 2 2, 0 2, 0 0))>')
|
||||||
|
|
||||||
|
def TestQgsRectangleRepr(self):
|
||||||
|
r = QgsRectangle(1, 2, 3, 4)
|
||||||
|
self.assertEqual(r.constGet().__repr__(), '<QgsRectangle: 1 2, 3 4>')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user