Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Python repr for QgsVertexId
  • Loading branch information
nyalldawson committed May 22, 2020
1 parent eec8ca4 commit 93648dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Expand Up @@ -838,6 +838,13 @@ Returns ``True`` if the vertex id is valid
int ring;
int vertex;
VertexType type;

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsVertexId: %1,%2,%3%4>" ).arg( sipCpp->part ).arg( sipCpp->ring ).arg( sipCpp->vertex ).arg( sipCpp->type == QgsVertexId::CurveVertex ? QStringLiteral( " CurveVertex" ) : QString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

};


Expand Down
9 changes: 9 additions & 0 deletions src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -1063,6 +1063,15 @@ struct CORE_EXPORT QgsVertexId
int ring;
int vertex;
VertexType type;

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsVertexId: %1,%2,%3%4>" ).arg( sipCpp->part ).arg( sipCpp->ring ).arg( sipCpp->vertex ).arg( sipCpp->type == QgsVertexId::CurveVertex ? QStringLiteral( " CurveVertex" ) : QString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

};

#ifndef SIP_RUN
Expand Down
11 changes: 10 additions & 1 deletion tests/src/python/test_python_repr.py
Expand Up @@ -18,7 +18,8 @@
QgsCurvePolygon, QgsEllipse, QgsLineString, QgsMultiCurve, QgsRectangle, QgsExpression, QgsField, QgsError,\
QgsMimeDataUtils, QgsVector, QgsVector3D, QgsVectorLayer, QgsReferencedPointXY, QgsReferencedRectangle,\
QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject, QgsClassificationRange, QgsBookmark, \
QgsLayoutMeasurement, QgsLayoutPoint, QgsLayoutSize, QgsUnitTypes, QgsConditionalStyle, QgsTableCell, QgsProperty
QgsLayoutMeasurement, QgsLayoutPoint, QgsLayoutSize, QgsUnitTypes, QgsConditionalStyle, QgsTableCell, QgsProperty, \
QgsVertexId

start_app()

Expand Down Expand Up @@ -241,6 +242,14 @@ def testQgsProperty(self):
p = QgsProperty()
self.assertEqual(p.__repr__(), '<QgsProperty: invalid>')

def testQgsVertexId(self):
v = QgsVertexId()
self.assertEqual(v.__repr__(), '<QgsVertexId: -1,-1,-1>')
v = QgsVertexId(1, 2, 3)
self.assertEqual(v.__repr__(), '<QgsVertexId: 1,2,3>')
v = QgsVertexId(1, 2, 3, _type=QgsVertexId.CurveVertex)
self.assertEqual(v.__repr__(), '<QgsVertexId: 1,2,3 CurveVertex>')


if __name__ == "__main__":
unittest.main()

0 comments on commit 93648dd

Please sign in to comment.