Skip to content

Commit cc3e29b

Browse files
committed
add __repr__ for more geometry classes and add test
1 parent ac4f508 commit cc3e29b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+191
-3
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgscircle.h
2+
QgsCircle.__repr__ = lambda self: '<QgsPoint {}>'.format(self.toString())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgscircularstring.h
2+
QgsCircularString.__repr__ = lambda self: '<QgsCircularString {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgscompoundcurve.h
2+
QgsCompoundCurve.__repr__ = lambda self: '<QgsCompoundCurve {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgscurvepolygon.h
2+
QgsCurvePolygon.__repr__ = lambda self: '<QgsCurvePolygon {}>'.format(self.asWkt())
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgsellipse.h
2+
QgsEllipse.__repr__ = lambda self: '<QgsEllipse {}>'.format(self.toString())

python/core/auto_additions/qgsgeometry.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
QgsGeometry.BufferSide.baseClass = QgsGeometry
33
QgsGeometry.EndCapStyle.baseClass = QgsGeometry
44
QgsGeometry.JoinStyle.baseClass = QgsGeometry
5+
QgsGeometry.__repr__ = lambda self: '<QgsGeometry {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgslinestring.h
2+
QgsLineString.__repr__ = lambda self: '<QgsLineString {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgsmulticurve.h
2+
QgsMultiCurve.__repr__ = lambda self: '<QgsMulitCurve {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgsmultilinestring.h
2+
QgsMultiLineString.__repr__ = lambda self: '<QgsMultiLineString {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgsmultipoint.h
2+
QgsMultiPoint.__repr__ = lambda self: '<QgsMultiPoint {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgsmultipolygon.h
2+
QgsMultiPolygon.__repr__ = lambda self: '<QgsMultiPolygon {}>'.format(self.asWkt())
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgspolygon.h
2+
QgsPolygon.__repr__ = lambda self: '<QgsPolygon {}>'.format(self.asWkt())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The following has been generated automatically from src/core/geometry/qgsrectangle.h
2+
QgsRectangle.__repr__ = lambda self: '<QgsRectangle {}>'.format(self.asWktCoordinates())

python/core/auto_generated/geometry/qgscircle.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Returns true if the circle contains the ``point``.
253253
virtual QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const;
254254

255255

256+
256257
};
257258

258259
/************************************************************************

python/core/auto_generated/geometry/qgscircularstring.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ Sets the circular string's points
162162
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
163163

164164

165+
165166
protected:
166167

167168
virtual QgsRectangle calculateBoundingBox() const;

python/core/auto_generated/geometry/qgscompoundcurve.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Appends first point if not already closed.
166166
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;
167167

168168

169+
169170
protected:
170171

171172
virtual QgsRectangle calculateBoundingBox() const;

python/core/auto_generated/geometry/qgscurvepolygon.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
216216
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;
217217

218218

219+
219220
protected:
220221

221222
virtual int childCount() const;

python/core/auto_generated/geometry/qgsellipse.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ returns a string representation of the ellipse.
248248
Members will be truncated to the specified precision.
249249
%End
250250

251+
251252
protected:
252253

253254
};

python/core/auto_generated/geometry/qgsgeometry.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ Exports the geometry to WKT
12901290
precision parameter added in QGIS 2.4
12911291
%End
12921292

1293+
12931294
QString asJson( int precision = 17 ) const;
12941295
%Docstring
12951296
Exports the geometry to a GeoJSON string.

python/core/auto_generated/geometry/qgslinestring.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ of the curve.
317317
virtual QgsLineString *createEmptyWithSameType() const /Factory/;
318318

319319

320+
320321
protected:
321322

322323
virtual QgsRectangle calculateBoundingBox() const;

python/core/auto_generated/geometry/qgsmulticurve.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Returns a copy of the multi curve, where each component curve has had its line d
5757

5858

5959

60+
6061
};
6162

6263

python/core/auto_generated/geometry/qgsmultilinestring.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
5353
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;
5454

5555

56+
5657
protected:
5758

5859
virtual bool wktOmitChildType() const;

python/core/auto_generated/geometry/qgsmultipoint.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Multi point geometry collection.
5555
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;
5656

5757

58+
5859
protected:
5960

6061
virtual bool wktOmitChildType() const;

python/core/auto_generated/geometry/qgsmultipolygon.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
5454
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;
5555

5656

57+
5758
protected:
5859

5960
virtual bool wktOmitChildType() const;

python/core/auto_generated/geometry/qgspolygon.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ negative if the point lies outside the polygon.
6565
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;
6666

6767

68+
6869
protected:
6970

7071

python/core/auto_generated/geometry/qgsrectangle.sip.in

+1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ Converts the rectangle to a 3D box, with the specified
322322

323323
operator QVariant() const;
324324

325+
325326
};
326327

327328

python/core/auto_generated/qgspointxy.sip.in

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ Returns a string representation of the point (x, y) with a preset ``precision``.
122122
If ``precision`` is -1, then a default precision will be used.
123123
%End
124124

125-
126125
QString asWkt() const;
127126
%Docstring
128127
Returns the well known text representation for the point (e.g. "POINT(x y)").

scripts/sipify_all.sh

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ count=0
3939

4040
modules=(core gui analysis server)
4141
for module in "${modules[@]}"; do
42+
43+
# clean auto_additions and auto_generated folders
44+
rm -rf python/${module}/auto_additions/*.py
45+
rm -rf python/${module}/auto_generated/*.py
46+
# put back __init__.py
47+
echo '"""
48+
This folder is completed using sipify.pl script
49+
It is not aimed to be manually edited
50+
"""' > python/${module}/auto_additions/__init__.py
51+
4252
while read -r sipfile; do
4353
echo "$sipfile.in"
4454
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)

src/core/geometry/qgscircle.h

+2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
247247

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

250+
SIP_PYTHON_SPECIAL_REPR( "'<QgsPoint {}>'.format(self.toString())" )
251+
250252
};
251253

252254
#endif // QGSCIRCLE_H

src/core/geometry/qgscircularstring.h

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
146146

147147
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;
148148

149+
SIP_PYTHON_SPECIAL_REPR( "'<QgsCircularString {}>'.format(self.asWkt())" )
150+
149151
protected:
150152

151153
QgsRectangle calculateBoundingBox() const override;

src/core/geometry/qgscompoundcurve.h

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
146146

147147
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;
148148

149+
SIP_PYTHON_SPECIAL_REPR( "'<QgsCompoundCurve {}>'.format(self.asWkt())" )
150+
149151
protected:
150152

151153
QgsRectangle calculateBoundingBox() const override;

src/core/geometry/qgscurvepolygon.h

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
204204

205205
QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;
206206

207+
SIP_PYTHON_SPECIAL_REPR( "'<QgsCurvePolygon {}>'.format(self.asWkt())" )
208+
207209
protected:
208210

209211
int childCount() const override;

src/core/geometry/qgsellipse.h

+2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ class CORE_EXPORT QgsEllipse
240240
*/
241241
virtual QString toString( int pointPrecision = 17, int axisPrecision = 17, int azimuthPrecision = 2 ) const;
242242

243+
SIP_PYTHON_SPECIAL_REPR( "'<QgsEllipse {}>'.format(self.toString())" )
244+
243245
protected:
244246
QgsPoint mCenter;
245247
double mSemiMajorAxis = 0.0;

src/core/geometry/qgsgeometry.h

+2
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,8 @@ class CORE_EXPORT QgsGeometry
12481248
*/
12491249
QString asWkt( int precision = 17 ) const;
12501250

1251+
SIP_PYTHON_SPECIAL_REPR( "'<QgsGeometry {}>'.format(self.asWkt())" )
1252+
12511253
/**
12521254
* Exports the geometry to a GeoJSON string.
12531255
*/

src/core/geometry/qgslinestring.h

+2
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ class CORE_EXPORT QgsLineString: public QgsCurve
346346

347347
QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;
348348

349+
SIP_PYTHON_SPECIAL_REPR( "'<QgsLineString {}>'.format(self.asWkt())" )
350+
349351
protected:
350352

351353
QgsRectangle calculateBoundingBox() const override;

src/core/geometry/qgsmulticurve.h

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
7373

7474
QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;
7575

76+
SIP_PYTHON_SPECIAL_REPR( "'<QgsMulitCurve {}>'.format(self.asWkt())" )
77+
7678

7779
};
7880

src/core/geometry/qgsmultilinestring.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
6565

6666
QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;
6767

68+
SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiLineString {}>'.format(self.asWkt())" )
69+
6870
protected:
6971

7072
bool wktOmitChildType() const override;

src/core/geometry/qgsmultipoint.h

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
6666

6767
QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;
6868

69+
SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiPoint {}>'.format(self.asWkt())" )
70+
6971
protected:
7072

7173
bool wktOmitChildType() const override;

src/core/geometry/qgsmultipolygon.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
6565

6666
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;
6767

68+
SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiPolygon {}>'.format(self.asWkt())" )
69+
6870
protected:
6971

7072
bool wktOmitChildType() const override;

src/core/geometry/qgspolygon.h

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
8484

8585
QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;
8686

87+
SIP_PYTHON_SPECIAL_REPR( "'<QgsPolygon {}>'.format(self.asWkt())" )
88+
8789
protected:
8890

8991
friend class QgsCurvePolygon;

src/core/geometry/qgsrectangle.h

+2
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ class CORE_EXPORT QgsRectangle
541541
return QVariant::fromValue( *this );
542542
}
543543

544+
SIP_PYTHON_SPECIAL_REPR( "'<QgsRectange {}>'.format(self.asWktCoordinates())" )
545+
544546
private:
545547

546548
double mXmin = 0.0;

src/core/qgspointxy.h

-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ class CORE_EXPORT QgsPointXY
156156
*/
157157
QString toString( int precision = -1 ) const;
158158

159-
SIP_PYTHON_SPECIAL_REPR( "'<QgsPointXY {}>'.format(self.toString())" )
160-
161159
/**
162160
* Returns the well known text representation for the point (e.g. "POINT(x y)").
163161
* The wkt is created without an SRID.

tests/src/python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ IF (WITH_SERVER)
99
ENDIF (WITH_SERVER)
1010

1111
ADD_PYTHON_TEST(PyCoreAdittions test_core_additions.py)
12+
ADD_PYTHON_TEST(PyPythonRepr test_python_repr.py)
1213
ADD_PYTHON_TEST(PyQgsActionManager test_qgsactionmanager.py)
1314
ADD_PYTHON_TEST(PyQgsAFSProvider test_provider_afs.py)
1415
ADD_PYTHON_TEST(PyQgsPythonProvider test_provider_python.py)

0 commit comments

Comments
 (0)