Skip to content

Commit

Permalink
use SIP to define Python __repr__ rather than injections
Browse files Browse the repository at this point in the history
because it's a bit more clever!
  • Loading branch information
3nids committed Jun 19, 2018
1 parent a719605 commit 763dfd2
Show file tree
Hide file tree
Showing 45 changed files with 170 additions and 51 deletions.
2 changes: 0 additions & 2 deletions python/core/auto_additions/qgscircle.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgscircularstring.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgscompoundcurve.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgscurvepolygon.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgsellipse.py

This file was deleted.

1 change: 0 additions & 1 deletion python/core/auto_additions/qgsgeometry.py
Expand Up @@ -2,4 +2,3 @@
QgsGeometry.BufferSide.baseClass = QgsGeometry
QgsGeometry.EndCapStyle.baseClass = QgsGeometry
QgsGeometry.JoinStyle.baseClass = QgsGeometry
QgsGeometry.__repr__ = lambda self: '<QgsGeometry {}>'.format(self.asWkt())
2 changes: 0 additions & 2 deletions python/core/auto_additions/qgslinestring.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgsmulticurve.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgsmultilinestring.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgsmultipoint.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgsmultipolygon.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgspoint.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgspointxy.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgspolygon.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgsrectangle.py

This file was deleted.

6 changes: 5 additions & 1 deletion python/core/auto_generated/geometry/qgscircle.sip.in
Expand Up @@ -253,7 +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 = QString( "<QgsCircle %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End
};

/************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgscircularstring.sip.in
Expand Up @@ -162,6 +162,11 @@ Sets the circular string's points
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgscompoundcurve.sip.in
Expand Up @@ -166,6 +166,11 @@ Appends first point if not already closed.
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgscurvepolygon.sip.in
Expand Up @@ -216,6 +216,11 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgsellipse.sip.in
Expand Up @@ -248,6 +248,11 @@ returns a string representation of the ellipse.
Members will be truncated to the specified precision.
%End

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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -1290,6 +1290,11 @@ Exports the geometry to WKT
precision parameter added in QGIS 2.4
%End

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

QString asJson( int precision = 17 ) const;
%Docstring
Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -317,6 +317,11 @@ of the curve.
virtual QgsLineString *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
6 changes: 5 additions & 1 deletion python/core/auto_generated/geometry/qgsmulticurve.sip.in
Expand Up @@ -56,7 +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 = QString( "<QgsMulitCurve %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

};

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgsmultilinestring.sip.in
Expand Up @@ -53,6 +53,11 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgsmultipoint.sip.in
Expand Up @@ -55,6 +55,11 @@ Multi point geometry collection.
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgsmultipolygon.sip.in
Expand Up @@ -54,6 +54,11 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgspoint.sip.in
Expand Up @@ -426,6 +426,11 @@ Angle undefined. Always returns 0.0
virtual QgsPoint *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgspolygon.sip.in
Expand Up @@ -65,6 +65,11 @@ negative if the point lies outside the polygon.
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;


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

protected:

Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/geometry/qgsrectangle.sip.in
Expand Up @@ -322,6 +322,11 @@ Converts the rectangle to a 3D box, with the specified

operator QVariant() const;

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QString( "<QgsRectangle %1>" ).arg( sipCpp->asWktCoordinates() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

};

Expand Down
3 changes: 1 addition & 2 deletions python/core/auto_generated/qgspointxy.sip.in
Expand Up @@ -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 = QString( "<QgsPointXY %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

Expand Down
9 changes: 7 additions & 2 deletions src/core/geometry/qgscircle.h
Expand Up @@ -247,8 +247,13 @@ class CORE_EXPORT QgsCircle : public QgsEllipse

QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const override;

SIP_PYTHON_SPECIAL_REPR( "'<QgsPoint {}>'.format(self.toString())" )

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

#endif // QGSCIRCLE_H
8 changes: 7 additions & 1 deletion src/core/geometry/qgscircularstring.h
Expand Up @@ -146,7 +146,13 @@ class CORE_EXPORT QgsCircularString: public QgsCurve

QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsCircularString {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCircularString %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgscompoundcurve.h
Expand Up @@ -146,7 +146,13 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve

QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsCompoundCurve {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCompoundCurve %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgscurvepolygon.h
Expand Up @@ -204,7 +204,13 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface

QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsCurvePolygon {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsCurvePolygon %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgsellipse.h
Expand Up @@ -240,7 +240,13 @@ class CORE_EXPORT QgsEllipse
*/
virtual QString toString( int pointPrecision = 17, int axisPrecision = 17, int azimuthPrecision = 2 ) const;

SIP_PYTHON_SPECIAL_REPR( "'<QgsEllipse {}>'.format(self.toString())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsEllipse %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:
QgsPoint mCenter;
Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -1248,7 +1248,13 @@ class CORE_EXPORT QgsGeometry
*/
QString asWkt( int precision = 17 ) const;

SIP_PYTHON_SPECIAL_REPR( "'<QgsGeometry {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsGeometry %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

/**
* Exports the geometry to a GeoJSON string.
Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgslinestring.h
Expand Up @@ -346,7 +346,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve

QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsLineString {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsLineString %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down
9 changes: 7 additions & 2 deletions src/core/geometry/qgsmulticurve.h
Expand Up @@ -73,8 +73,13 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection

QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMulitCurve {}>'.format(self.asWkt())" )

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

};

Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgsmultilinestring.h
Expand Up @@ -65,7 +65,13 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve

QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiLineString {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMultiLineString %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgsmultipoint.h
Expand Up @@ -66,7 +66,13 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection

QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiPoint {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMultiPoint %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down
8 changes: 7 additions & 1 deletion src/core/geometry/qgsmultipolygon.h
Expand Up @@ -65,7 +65,13 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface

QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiPolygon {}>'.format(self.asWkt())" )
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QString( "<QgsMultiPolygon %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

protected:

Expand Down

0 comments on commit 763dfd2

Please sign in to comment.