Skip to content

Commit 7ee55a7

Browse files
authored
[pyqt5] Aliases for indistinguishable method overloads (#3099)
See https://www.riverbankcomputing.com/pipermail/pyqt/2016-May/037500.html
1 parent 3aff45c commit 7ee55a7

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

ci/travis/linux/qt5/blacklist.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PyQgsComposerPicture
2-
PyQgsGeometryTest
32
PyQgsJSONUtils
43
PyQgsLocalServer
54
PyQgsMapUnitScale

doc/api_break.dox

+5
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ None will need to be modified, as the method will return an empty geometry if th
507507
value instead of a pointer. The biggest impact with this change is that PyQGIS code should not compare a geometry
508508
result to None, but instead either use a boolean test (`if g.buffer(10):`) or explicitly use the isEmpty()
509509
method to determine if a geometry is valid.</li>
510+
<li>int addPart( const QList<QgsPoint> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPoints</li>
511+
<li>int addPart( const QList<QgsPointV2> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPointsV2</li>
512+
<li>static bool compare( const QgsPolyline& p1, const QgsPolyline& p2, double epsilon ) has been renamed to comparePolylines</li>
513+
<li>static bool compare( const QgsPolygon& p1, const QgsPolygon& p2, double epsilon ) has been renamed to comparePolygons</li>
514+
<li>static bool compare( const QgsMultiPolygon& p1, const QgsMultiPolygon& p2, double epsilon ) has been renamed to compareMultiPolygons</li>
510515
</ul>
511516

512517
\subsection qgis_api_break_3_0_QgsGeometryAnalyzer QgsGeometryAnalyzer

python/core/geometry/qgsgeometry.sip

+9
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ class QgsGeometry
312312
* not disjoint with existing polygons of the feature
313313
*/
314314
// TODO QGIS 3.0 returns an enum instead of a magic constant
315+
%If (!QT5_SUPPORT)
315316
int addPart( const QList<QgsPoint> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
317+
%End
318+
int addPart( const QList<QgsPoint> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry )/PyName=addPoints/;
316319

317320
/** Adds a new part to a the geometry.
318321
* @param points points describing part to add
@@ -321,7 +324,10 @@ class QgsGeometry
321324
* not disjoint with existing polygons of the feature
322325
*/
323326
// TODO QGIS 3.0 returns an enum instead of a magic constant
327+
%If (!QT5_SUPPORT)
324328
int addPart( const QList<QgsPointV2> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
329+
%End
330+
int addPart( const QList<QgsPointV2> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry )/PyName=addPointsV2/;
325331

326332
/** Adds a new part to this geometry.
327333
* @param part part to add (ownership is transferred)
@@ -737,6 +743,7 @@ class QgsGeometry
737743
* @note added in QGIS 2.9
738744
*/
739745
static bool compare( const QgsPolyline& p1, const QgsPolyline& p2, double epsilon = 4 * DBL_EPSILON );
746+
static bool compare( const QgsPolyline& p1, const QgsPolyline& p2, double epsilon = 4 * DBL_EPSILON )/PyName=comparePolylines/;
740747

741748
/** Compares two polygons for equality within a specified tolerance.
742749
* @param p1 first polygon
@@ -747,6 +754,7 @@ class QgsGeometry
747754
* @note added in QGIS 2.9
748755
*/
749756
static bool compare( const QgsPolygon& p1, const QgsPolygon& p2, double epsilon = 4 * DBL_EPSILON );
757+
static bool compare( const QgsPolygon& p1, const QgsPolygon& p2, double epsilon = 4 * DBL_EPSILON )/PyName=comparePolygons/;
750758

751759
/** Compares two multipolygons for equality within a specified tolerance.
752760
* @param p1 first multipolygon
@@ -758,6 +766,7 @@ class QgsGeometry
758766
* @note added in QGIS 2.9
759767
*/
760768
static bool compare( const QgsMultiPolygon& p1, const QgsMultiPolygon& p2, double epsilon = 4 * DBL_EPSILON );
769+
static bool compare( const QgsMultiPolygon& p1, const QgsMultiPolygon& p2, double epsilon = 4 * DBL_EPSILON )/PyName=compareMultiPolygons/;
761770

762771
/** Smooths a geometry by rounding off corners using the Chaikin algorithm. This operation
763772
* roughly doubles the number of vertices in a geometry.

tests/src/python/test_qgsgeometry.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1351,15 +1351,15 @@ def testAddPart(self):
13511351
points = [QgsPoint(0, 0), QgsPoint(1, 0)]
13521352

13531353
point = QgsGeometry.fromPoint(points[0])
1354-
self.assertEqual(point.addPart([points[1]]), 0)
1354+
self.assertEqual(point.addPoints([points[1]]), 0)
13551355
expwkt = "MultiPoint ((0 0), (1 0))"
13561356
wkt = point.exportToWkt()
13571357
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
13581358

13591359
# test adding a part with Z values
13601360
point = QgsGeometry.fromPoint(points[0])
13611361
point.geometry().addZValue(4.0)
1362-
self.assertEqual(point.addPart([QgsPointV2(QgsWkbTypes.PointZ, points[1][0], points[1][1], 3.0)]), 0)
1362+
self.assertEqual(point.addPointsV2([QgsPointV2(QgsWkbTypes.PointZ, points[1][0], points[1][1], 3.0)]), 0)
13631363
expwkt = "MultiPointZ ((0 0 4), (1 0 3))"
13641364
wkt = point.exportToWkt()
13651365
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
@@ -1373,14 +1373,14 @@ def testAddPart(self):
13731373
]
13741374

13751375
polyline = QgsGeometry.fromPolyline(points[0])
1376-
self.assertEqual(polyline.addPart(points[1][0:1]), 2, "addPart with one point line unexpectedly succeeded.")
1377-
self.assertEqual(polyline.addPart(points[1][0:2]), 0, "addPart with two point line failed.")
1376+
self.assertEqual(polyline.addPoints(points[1][0:1]), 2, "addPoints with one point line unexpectedly succeeded.")
1377+
self.assertEqual(polyline.addPoints(points[1][0:2]), 0, "addPoints with two point line failed.")
13781378
expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1))"
13791379
wkt = polyline.exportToWkt()
13801380
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
13811381

13821382
polyline = QgsGeometry.fromPolyline(points[0])
1383-
self.assertEqual(polyline.addPart(points[1]), 0, "addPart with %d point line failed." % len(points[1]))
1383+
self.assertEqual(polyline.addPoints(points[1]), 0, "addPoints with %d point line failed." % len(points[1]))
13841384
expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1, 5 1, 5 0, 6 0))"
13851385
wkt = polyline.exportToWkt()
13861386
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
@@ -1389,7 +1389,7 @@ def testAddPart(self):
13891389
polyline = QgsGeometry.fromPolyline(points[0])
13901390
polyline.geometry().addZValue(4.0)
13911391
points2 = [QgsPointV2(QgsWkbTypes.PointZ, p[0], p[1], 3.0) for p in points[1]]
1392-
self.assertEqual(polyline.addPart(points2), 0)
1392+
self.assertEqual(polyline.addPointsV2(points2), 0)
13931393
expwkt = "MultiLineStringZ ((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 0 4),(3 0 3, 3 1 3, 5 1 3, 5 0 3, 6 0 3))"
13941394
wkt = polyline.exportToWkt()
13951395
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
@@ -1406,12 +1406,12 @@ def testAddPart(self):
14061406

14071407
polygon = QgsGeometry.fromPolygon(points[0])
14081408

1409-
self.assertEqual(polygon.addPart(points[1][0][0:1]), 2, "addPart with one point ring unexpectedly succeeded.")
1410-
self.assertEqual(polygon.addPart(points[1][0][0:2]), 2, "addPart with two point ring unexpectedly succeeded.")
1411-
self.assertEqual(polygon.addPart(points[1][0][0:3]), 2, "addPart with unclosed three point ring unexpectedly succeeded.")
1412-
self.assertEqual(polygon.addPart([QgsPoint(4, 0), QgsPoint(5, 0), QgsPoint(4, 0)]), 2, "addPart with 'closed' three point ring unexpectedly succeeded.")
1409+
self.assertEqual(polygon.addPoints(points[1][0][0:1]), 2, "addPoints with one point ring unexpectedly succeeded.")
1410+
self.assertEqual(polygon.addPoints(points[1][0][0:2]), 2, "addPoints with two point ring unexpectedly succeeded.")
1411+
self.assertEqual(polygon.addPoints(points[1][0][0:3]), 2, "addPoints with unclosed three point ring unexpectedly succeeded.")
1412+
self.assertEqual(polygon.addPoints([QgsPoint(4, 0), QgsPoint(5, 0), QgsPoint(4, 0)]), 2, "addPoints with 'closed' three point ring unexpectedly succeeded.")
14131413

1414-
self.assertEqual(polygon.addPart(points[1][0]), 0, "addPart failed")
1414+
self.assertEqual(polygon.addPoints(points[1][0]), 0, "addPoints failed")
14151415
expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))"
14161416
wkt = polygon.exportToWkt()
14171417
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
@@ -1433,46 +1433,46 @@ def testAddPart(self):
14331433
polygon = QgsGeometry.fromPolygon(points[0])
14341434
polygon.geometry().addZValue(4.0)
14351435
points2 = [QgsPointV2(QgsWkbTypes.PointZ, pi[0], pi[1], 3.0) for pi in points[1][0]]
1436-
self.assertEqual(polygon.addPart(points2), 0)
1436+
self.assertEqual(polygon.addPointsV2(points2), 0)
14371437
expwkt = "MultiPolygonZ (((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 2 4, 0 2 4, 0 0 4)),((4 0 3, 5 0 3, 5 2 3, 3 2 3, 3 1 3, 4 1 3, 4 0 3)))"
14381438
wkt = polygon.exportToWkt()
14391439
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
14401440

14411441
# Test adding parts to empty geometry, should become first part
14421442
empty = QgsGeometry()
14431443
# if not default type specified, addPart should fail
1444-
result = empty.addPart([QgsPoint(4, 0)])
1444+
result = empty.addPoints([QgsPoint(4, 0)])
14451445
assert result != 0, 'Got return code {}'.format(result)
1446-
result = empty.addPart([QgsPoint(4, 0)], QgsWkbTypes.PointGeometry)
1446+
result = empty.addPoints([QgsPoint(4, 0)], QgsWkbTypes.PointGeometry)
14471447
self.assertEqual(result, 0, 'Got return code {}'.format(result))
14481448
wkt = empty.exportToWkt()
14491449
expwkt = 'MultiPoint ((4 0))'
14501450
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
1451-
result = empty.addPart([QgsPoint(5, 1)])
1451+
result = empty.addPoints([QgsPoint(5, 1)])
14521452
self.assertEqual(result, 0, 'Got return code {}'.format(result))
14531453
wkt = empty.exportToWkt()
14541454
expwkt = 'MultiPoint ((4 0),(5 1))'
14551455
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
14561456
# next try with lines
14571457
empty = QgsGeometry()
1458-
result = empty.addPart(points[0][0], QgsWkbTypes.LineGeometry)
1458+
result = empty.addPoints(points[0][0], QgsWkbTypes.LineGeometry)
14591459
self.assertEqual(result, 0, 'Got return code {}'.format(result))
14601460
wkt = empty.exportToWkt()
14611461
expwkt = 'MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))'
14621462
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
1463-
result = empty.addPart(points[1][0])
1463+
result = empty.addPoints(points[1][0])
14641464
self.assertEqual(result, 0, 'Got return code {}'.format(result))
14651465
wkt = empty.exportToWkt()
14661466
expwkt = 'MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0),(4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0))'
14671467
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
14681468
# finally try with polygons
14691469
empty = QgsGeometry()
1470-
result = empty.addPart(points[0][0], QgsWkbTypes.PolygonGeometry)
1470+
result = empty.addPoints(points[0][0], QgsWkbTypes.PolygonGeometry)
14711471
self.assertEqual(result, 0, 'Got return code {}'.format(result))
14721472
wkt = empty.exportToWkt()
14731473
expwkt = 'MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)))'
14741474
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
1475-
result = empty.addPart(points[1][0])
1475+
result = empty.addPoints(points[1][0])
14761476
self.assertEqual(result, 0, 'Got return code {}'.format(result))
14771477
wkt = empty.exportToWkt()
14781478
expwkt = 'MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))'

0 commit comments

Comments
 (0)