Skip to content

Commit

Permalink
add __repr__ for more geometry classes and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 19, 2018
1 parent ac4f508 commit cc3e29b
Show file tree
Hide file tree
Showing 44 changed files with 191 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgscircle.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscircle.h
QgsCircle.__repr__ = lambda self: '<QgsPoint {}>'.format(self.toString())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgscircularstring.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscircularstring.h
QgsCircularString.__repr__ = lambda self: '<QgsCircularString {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgscompoundcurve.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscompoundcurve.h
QgsCompoundCurve.__repr__ = lambda self: '<QgsCompoundCurve {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgscurvepolygon.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscurvepolygon.h
QgsCurvePolygon.__repr__ = lambda self: '<QgsCurvePolygon {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgsellipse.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsellipse.h
QgsEllipse.__repr__ = lambda self: '<QgsEllipse {}>'.format(self.toString())
1 change: 1 addition & 0 deletions python/core/auto_additions/qgsgeometry.py
Expand Up @@ -2,3 +2,4 @@
QgsGeometry.BufferSide.baseClass = QgsGeometry QgsGeometry.BufferSide.baseClass = QgsGeometry
QgsGeometry.EndCapStyle.baseClass = QgsGeometry QgsGeometry.EndCapStyle.baseClass = QgsGeometry
QgsGeometry.JoinStyle.baseClass = QgsGeometry QgsGeometry.JoinStyle.baseClass = QgsGeometry
QgsGeometry.__repr__ = lambda self: '<QgsGeometry {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgslinestring.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgslinestring.h
QgsLineString.__repr__ = lambda self: '<QgsLineString {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgsmulticurve.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmulticurve.h
QgsMultiCurve.__repr__ = lambda self: '<QgsMulitCurve {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgsmultilinestring.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmultilinestring.h
QgsMultiLineString.__repr__ = lambda self: '<QgsMultiLineString {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgsmultipoint.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmultipoint.h
QgsMultiPoint.__repr__ = lambda self: '<QgsMultiPoint {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgsmultipolygon.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmultipolygon.h
QgsMultiPolygon.__repr__ = lambda self: '<QgsMultiPolygon {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgspolygon.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgspolygon.h
QgsPolygon.__repr__ = lambda self: '<QgsPolygon {}>'.format(self.asWkt())
2 changes: 2 additions & 0 deletions python/core/auto_additions/qgsrectangle.py
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsrectangle.h
QgsRectangle.__repr__ = lambda self: '<QgsRectangle {}>'.format(self.asWktCoordinates())
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgscircle.sip.in
Expand Up @@ -253,6 +253,7 @@ 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;





}; };


/************************************************************************ /************************************************************************
Expand Down
Expand Up @@ -162,6 +162,7 @@ Sets the circular string's points
virtual QgsCircularString *createEmptyWithSameType() const /Factory/; virtual QgsCircularString *createEmptyWithSameType() const /Factory/;





protected: protected:


virtual QgsRectangle calculateBoundingBox() const; virtual QgsRectangle calculateBoundingBox() const;
Expand Down
Expand Up @@ -166,6 +166,7 @@ Appends first point if not already closed.
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/; virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;





protected: protected:


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





protected: protected:


virtual int childCount() const; virtual int childCount() const;
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgsellipse.sip.in
Expand Up @@ -248,6 +248,7 @@ 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



protected: protected:


}; };
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -1290,6 +1290,7 @@ Exports the geometry to WKT
precision parameter added in QGIS 2.4 precision parameter added in QGIS 2.4
%End %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.
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -317,6 +317,7 @@ of the curve.
virtual QgsLineString *createEmptyWithSameType() const /Factory/; virtual QgsLineString *createEmptyWithSameType() const /Factory/;





protected: protected:


virtual QgsRectangle calculateBoundingBox() const; virtual QgsRectangle calculateBoundingBox() const;
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgsmulticurve.sip.in
Expand Up @@ -57,6 +57,7 @@ Returns a copy of the multi curve, where each component curve has had its line d







}; };




Expand Down
Expand Up @@ -53,6 +53,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/; virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;





protected: protected:


virtual bool wktOmitChildType() const; virtual bool wktOmitChildType() const;
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgsmultipoint.sip.in
Expand Up @@ -55,6 +55,7 @@ Multi point geometry collection.
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/; virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;





protected: protected:


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





protected: protected:


virtual bool wktOmitChildType() const; virtual bool wktOmitChildType() const;
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgspolygon.sip.in
Expand Up @@ -65,6 +65,7 @@ negative if the point lies outside the polygon.
virtual QgsPolygon *createEmptyWithSameType() const /Factory/; virtual QgsPolygon *createEmptyWithSameType() const /Factory/;





protected: protected:




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


operator QVariant() const; operator QVariant() const;



}; };




Expand Down
1 change: 0 additions & 1 deletion python/core/auto_generated/qgspointxy.sip.in
Expand Up @@ -122,7 +122,6 @@ Returns a string representation of the point (x, y) with a preset ``precision``.
If ``precision`` is -1, then a default precision will be used. If ``precision`` is -1, then a default precision will be used.
%End %End



QString asWkt() const; QString asWkt() const;
%Docstring %Docstring
Returns the well known text representation for the point (e.g. "POINT(x y)"). Returns the well known text representation for the point (e.g. "POINT(x y)").
Expand Down
10 changes: 10 additions & 0 deletions scripts/sipify_all.sh
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgscircle.h
Expand Up @@ -247,6 +247,8 @@ 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;


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

}; };


#endif // QGSCIRCLE_H #endif // QGSCIRCLE_H
2 changes: 2 additions & 0 deletions src/core/geometry/qgscircularstring.h
Expand Up @@ -146,6 +146,8 @@ class CORE_EXPORT QgsCircularString: public QgsCurve


QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY; QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


QgsRectangle calculateBoundingBox() const override; QgsRectangle calculateBoundingBox() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgscompoundcurve.h
Expand Up @@ -146,6 +146,8 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve


QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY; QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


QgsRectangle calculateBoundingBox() const override; QgsRectangle calculateBoundingBox() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgscurvepolygon.h
Expand Up @@ -204,6 +204,8 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface


QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY; QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


int childCount() const override; int childCount() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsellipse.h
Expand Up @@ -240,6 +240,8 @@ 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;


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

protected: protected:
QgsPoint mCenter; QgsPoint mCenter;
double mSemiMajorAxis = 0.0; double mSemiMajorAxis = 0.0;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -1248,6 +1248,8 @@ class CORE_EXPORT QgsGeometry
*/ */
QString asWkt( int precision = 17 ) const; QString asWkt( int precision = 17 ) const;


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

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


QgsLineString *createEmptyWithSameType() const override SIP_FACTORY; QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


QgsRectangle calculateBoundingBox() const override; QgsRectangle calculateBoundingBox() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsmulticurve.h
Expand Up @@ -73,6 +73,8 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection


QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY; QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;


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



}; };


Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsmultilinestring.h
Expand Up @@ -65,6 +65,8 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve


QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY; QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


bool wktOmitChildType() const override; bool wktOmitChildType() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsmultipoint.h
Expand Up @@ -66,6 +66,8 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection


QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY; QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


bool wktOmitChildType() const override; bool wktOmitChildType() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsmultipolygon.h
Expand Up @@ -65,6 +65,8 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface


QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY; QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


bool wktOmitChildType() const override; bool wktOmitChildType() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgspolygon.h
Expand Up @@ -84,6 +84,8 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon


QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY; QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;


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

protected: protected:


friend class QgsCurvePolygon; friend class QgsCurvePolygon;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geometry/qgsrectangle.h
Expand Up @@ -541,6 +541,8 @@ class CORE_EXPORT QgsRectangle
return QVariant::fromValue( *this ); return QVariant::fromValue( *this );
} }


SIP_PYTHON_SPECIAL_REPR( "'<QgsRectange {}>'.format(self.asWktCoordinates())" )

private: private:


double mXmin = 0.0; double mXmin = 0.0;
Expand Down
2 changes: 0 additions & 2 deletions src/core/qgspointxy.h
Expand Up @@ -156,8 +156,6 @@ class CORE_EXPORT QgsPointXY
*/ */
QString toString( int precision = -1 ) const; QString toString( int precision = -1 ) const;


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

/** /**
* Returns the well known text representation for the point (e.g. "POINT(x y)"). * Returns the well known text representation for the point (e.g. "POINT(x y)").
* The wkt is created without an SRID. * The wkt is created without an SRID.
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -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)
Expand Down

0 comments on commit cc3e29b

Please sign in to comment.