Skip to content

Commit

Permalink
Make QgsBookmark string output more explicit about it being EMPTY
Browse files Browse the repository at this point in the history
  • Loading branch information
strk authored and troopa81 committed Oct 16, 2023
1 parent edaa3dd commit 99d0f8a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion python/core/auto_generated/qgsbookmarkmanager.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ Returns a DOM element representing the bookmark's properties.

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsBookmark: '%1' (%2 - %3)>" ).arg( sipCpp->name(), sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() );
QString str = QStringLiteral( "<QgsBookmark: '%1' (%2)>" )
.arg( sipCpp->name() )
.arg(
sipCpp->extent().isNull() ?
QStringLiteral( "EMPTY" ) :
QStringLiteral( "%1 - %2" )
.arg( sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() )
);
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

Expand Down
9 changes: 8 additions & 1 deletion src/core/qgsbookmarkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ class CORE_EXPORT QgsBookmark
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsBookmark: '%1' (%2 - %3)>" ).arg( sipCpp->name(), sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() );
QString str = QStringLiteral( "<QgsBookmark: '%1' (%2)>" )
.arg( sipCpp->name() )
.arg(
sipCpp->extent().isNull() ?
QStringLiteral( "EMPTY" ) :
QStringLiteral( "%1 - %2" )
.arg( sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() )
);
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_python_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def testQgsProjectRepr(self):

def testQgsBookmark(self):
b = QgsBookmark()
self.assertEqual(b.__repr__(), "<QgsBookmark: '' (0 0, 0 0 - )>")
self.assertEqual(b.__repr__(), "<QgsBookmark: '' (EMPTY)>")
b.setName('test bookmark')
self.assertEqual(b.__repr__(), "<QgsBookmark: 'test bookmark' (0 0, 0 0 - )>")
self.assertEqual(b.__repr__(), "<QgsBookmark: 'test bookmark' (EMPTY)>")
b.setExtent(QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4), QgsCoordinateReferenceSystem('EPSG:3111')))
self.assertEqual(b.__repr__(), "<QgsBookmark: 'test bookmark' (1 2, 3 4 - EPSG:3111)>")

Expand Down

0 comments on commit 99d0f8a

Please sign in to comment.