Skip to content
Permalink
Browse files

Merge pull request #7171 from 3nids/sip_python_repr

create Python __repr__ methods for QgsPoint and QgsPointXY
  • Loading branch information
3nids committed Jun 19, 2018
2 parents 2aa2ef4 + ff1988f commit d36015070c7091a3abd50ee6be5bd8aaac5d2238
Showing with 358 additions and 12 deletions.
  1. +5 −0 python/core/auto_generated/geometry/qgscircle.sip.in
  2. +6 −0 python/core/auto_generated/geometry/qgscircularstring.sip.in
  3. +6 −0 python/core/auto_generated/geometry/qgscompoundcurve.sip.in
  4. +6 −0 python/core/auto_generated/geometry/qgscurvepolygon.sip.in
  5. +6 −0 python/core/auto_generated/geometry/qgsellipse.sip.in
  6. +6 −0 python/core/auto_generated/geometry/qgsgeometry.sip.in
  7. +6 −0 python/core/auto_generated/geometry/qgslinestring.sip.in
  8. +5 −0 python/core/auto_generated/geometry/qgsmulticurve.sip.in
  9. +6 −0 python/core/auto_generated/geometry/qgsmultilinestring.sip.in
  10. +6 −0 python/core/auto_generated/geometry/qgsmultipoint.sip.in
  11. +6 −0 python/core/auto_generated/geometry/qgsmultipolygon.sip.in
  12. +6 −0 python/core/auto_generated/geometry/qgspoint.sip.in
  13. +6 −0 python/core/auto_generated/geometry/qgspolygon.sip.in
  14. +6 −0 python/core/auto_generated/geometry/qgsrectangle.sip.in
  15. +1 −2 python/core/auto_generated/qgspointxy.sip.in
  16. +13 −4 scripts/sipify.pl
  17. +10 −0 scripts/sipify_all.sh
  18. +7 −0 src/core/geometry/qgscircle.h
  19. +8 −0 src/core/geometry/qgscircularstring.h
  20. +8 −0 src/core/geometry/qgscompoundcurve.h
  21. +8 −0 src/core/geometry/qgscurvepolygon.h
  22. +8 −0 src/core/geometry/qgsellipse.h
  23. +8 −0 src/core/geometry/qgsgeometry.h
  24. +8 −0 src/core/geometry/qgslinestring.h
  25. +7 −0 src/core/geometry/qgsmulticurve.h
  26. +8 −0 src/core/geometry/qgsmultilinestring.h
  27. +8 −0 src/core/geometry/qgsmultipoint.h
  28. +8 −0 src/core/geometry/qgsmultipolygon.h
  29. +8 −0 src/core/geometry/qgspoint.h
  30. +8 −0 src/core/geometry/qgspolygon.h
  31. +8 −0 src/core/geometry/qgsrectangle.h
  32. +13 −3 src/core/qgis_sip.h
  33. +1 −1 src/core/qgsdefaultvalue.h
  34. +1 −2 src/core/qgspointxy.h
  35. +9 −0 tests/code_layout/test_sipfiles_uptodate.sh
  36. +1 −0 tests/src/python/CMakeLists.txt
  37. +117 −0 tests/src/python/test_python_repr.py
@@ -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;


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/;


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

protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -166,6 +166,12 @@ Appends first point if not already closed.
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:

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/;


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

protected:

virtual int childCount() const;
@@ -248,6 +248,12 @@ returns a string representation of the ellipse.
Members will be truncated to the specified precision.
%End

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

protected:

};
@@ -1290,6 +1290,12 @@ Exports the geometry to WKT
precision parameter added in QGIS 2.4
%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;
%Docstring
Exports the geometry to a GeoJSON string.
@@ -317,6 +317,12 @@ of the curve.
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:

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/;


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/;


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

protected:

virtual bool wktOmitChildType() const;
@@ -55,6 +55,12 @@ Multi point geometry collection.
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:

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/;


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

protected:

virtual bool wktOmitChildType() const;
@@ -426,6 +426,12 @@ Angle undefined. Always returns 0.0
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:

virtual int childCount() const;
@@ -65,6 +65,12 @@ negative if the point lies outside the polygon.
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:


@@ -322,6 +322,12 @@ Converts the rectangle to a 3D box, with the specified

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__();
%MethodCode
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

@@ -694,7 +694,7 @@ sub detect_non_method_member{
}

# SIP_SKIP
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_OPERATOR_/ ){
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_SPECIAL_/ ){
dbg_info('SIP SKIP!');
# if multiline definition, remove previous lines
if ( $MULTILINE_DEFINITION != MULTILINE_NO){
@@ -711,9 +711,18 @@ sub detect_non_method_member{
detect_and_remove_following_body_or_initializerlist();
# line skipped, go to next iteration

if ($LINE =~ m/SIP_PYTHON_OPERATOR_(\w+)\(\s*(\w+)\s*\)/ ){
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: self.$2()";
dbg_info("PYTHON OPERATOR $pyop");
if ($LINE =~ m/SIP_PYTHON_SPECIAL_(\w+)\(\s*(".*"|\w+)\s*\)/ ){
my $method_or_code = $2;
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 ''){
push @OUTPUT_PYTHON, "$pyop\n";
}
@@ -39,6 +39,16 @@ count=0

modules=(core gui analysis server)
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
echo "$sipfile.in"
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;

#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
@@ -146,6 +146,14 @@ class CORE_EXPORT QgsCircularString: public QgsCurve

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:

QgsRectangle calculateBoundingBox() const override;
@@ -146,6 +146,14 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve

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:

QgsRectangle calculateBoundingBox() const override;
@@ -204,6 +204,14 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface

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:

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;

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

protected:
QgsPoint mCenter;
double mSemiMajorAxis = 0.0;
@@ -1248,6 +1248,14 @@ class CORE_EXPORT QgsGeometry
*/
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.
*/
@@ -346,6 +346,14 @@ class CORE_EXPORT QgsLineString: public QgsCurve

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:

QgsRectangle calculateBoundingBox() const override;
@@ -73,6 +73,13 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection

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;

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

protected:

bool wktOmitChildType() const override;
@@ -66,6 +66,14 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection

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:

bool wktOmitChildType() const override;

0 comments on commit d360150

Please sign in to comment.
You can’t perform that action at this time.