Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add equality operators for QgsTileXYZ
  • Loading branch information
nyalldawson committed May 9, 2023
1 parent 35e3d49 commit 171baf0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgstiles.sip.in
Expand Up @@ -47,6 +47,8 @@ Returns tile's zoom level (Z)
Returns tile coordinates in a formatted string
%End

bool operator==( const QgsTileXYZ &other ) const;
bool operator!=( const QgsTileXYZ &other ) const;

SIP_PYOBJECT __repr__();
%MethodCode
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgstiles.h
Expand Up @@ -53,6 +53,9 @@ class CORE_EXPORT QgsTileXYZ
//! Returns tile coordinates in a formatted string
QString toString() const { return QStringLiteral( "X=%1 Y=%2 Z=%3" ).arg( mColumn ).arg( mRow ).arg( mZoomLevel ); }

bool operator==( const QgsTileXYZ &other ) const { return mColumn == other.mColumn && mRow == other.mRow && mZoomLevel == other.mZoomLevel; }
bool operator!=( const QgsTileXYZ &other ) const { return !( *this == other ); }

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
Expand Down
11 changes: 11 additions & 0 deletions tests/src/python/test_qgstiles.py
Expand Up @@ -41,6 +41,17 @@ def testQgsTileXYZRepr(self):
tile = QgsTileXYZ(1, 2, 3)
self.assertEqual(str(tile), '<QgsTileXYZ: 1, 2, 3>')

def testQgsTileXYZEquality(self):
tile = QgsTileXYZ(1, 2, 3)
tile2 = QgsTileXYZ(1, 2, 3)
self.assertEqual(tile, tile2)
tile2 = QgsTileXYZ(1, 2, 4)
self.assertNotEqual(tile, tile2)
tile2 = QgsTileXYZ(1, 4, 3)
self.assertNotEqual(tile, tile2)
tile2 = QgsTileXYZ(4, 2, 3)
self.assertNotEqual(tile, tile2)

def testQgsTileRange(self):
range = QgsTileRange(1, 2, 3, 4)
self.assertEqual(range.startColumn(), 1)
Expand Down

0 comments on commit 171baf0

Please sign in to comment.