diff --git a/python/core/auto_generated/qgscoordinatetransformcontext.sip.in b/python/core/auto_generated/qgscoordinatetransformcontext.sip.in index 49ef713b346f..bc99c8503c0c 100644 --- a/python/core/auto_generated/qgscoordinatetransformcontext.sip.in +++ b/python/core/auto_generated/qgscoordinatetransformcontext.sip.in @@ -63,6 +63,7 @@ Copy constructor %End + bool operator==( const QgsCoordinateTransformContext &rhs ) const; void clear(); %Docstring diff --git a/src/core/qgscoordinatetransformcontext.cpp b/src/core/qgscoordinatetransformcontext.cpp index c816d900d59a..4abe9b5aaa2b 100644 --- a/src/core/qgscoordinatetransformcontext.cpp +++ b/src/core/qgscoordinatetransformcontext.cpp @@ -36,6 +36,19 @@ QgsCoordinateTransformContext &QgsCoordinateTransformContext::operator=( const Q return *this; } +bool QgsCoordinateTransformContext::operator==( const QgsCoordinateTransformContext &rhs ) const +{ + if ( d == rhs.d ) + return true; + + d->mLock.lockForRead(); + rhs.d->mLock.lockForRead(); + bool equal = d->mSourceDestDatumTransforms == rhs.d->mSourceDestDatumTransforms; + d->mLock.unlock(); + rhs.d->mLock.unlock(); + return equal; +} + void QgsCoordinateTransformContext::clear() { d.detach(); diff --git a/src/core/qgscoordinatetransformcontext.h b/src/core/qgscoordinatetransformcontext.h index 0838ff620936..d56c15deee0b 100644 --- a/src/core/qgscoordinatetransformcontext.h +++ b/src/core/qgscoordinatetransformcontext.h @@ -80,6 +80,7 @@ class CORE_EXPORT QgsCoordinateTransformContext */ QgsCoordinateTransformContext &operator=( const QgsCoordinateTransformContext &rhs ) SIP_SKIP; + bool operator==( const QgsCoordinateTransformContext &rhs ) const ; /** * Clears all stored transform information from the context. diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index 49d367d92fa8..1f62877a9400 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -278,6 +278,13 @@ QgsProjectProperty *addKey_( const QString &scope, return nullptr; } +/** + * Remove a given key + +\param scope scope of key +\param key key name +\param rootProperty is the property from which to start adding +*/ void removeKey_( const QString &scope, const QString &key, @@ -614,6 +621,9 @@ QgsCoordinateReferenceSystem QgsProject::crs() const void QgsProject::setCrs( const QgsCoordinateReferenceSystem &crs ) { + if ( crs == mCrs ) + return; + mCrs = crs; writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), crs.isValid() ? 1 : 0 ); setDirty( true ); @@ -631,7 +641,6 @@ QString QgsProject::ellipsoid() const void QgsProject::setEllipsoid( const QString &ellipsoid ) { writeEntry( QStringLiteral( "Measure" ), QStringLiteral( "/Ellipsoid" ), ellipsoid ); - setDirty( true ); emit ellipsoidChanged( ellipsoid ); } @@ -642,6 +651,9 @@ QgsCoordinateTransformContext QgsProject::transformContext() const void QgsProject::setTransformContext( const QgsCoordinateTransformContext &context ) { + if ( context == mTransformContext ) + return; + mTransformContext = context; emit transformContextChanged(); } @@ -834,7 +846,7 @@ void QgsProject::setSnappingConfig( const QgsSnappingConfig &snappingConfig ) return; mSnappingConfig = snappingConfig; - setDirty(); + setDirty( true ); emit snappingConfigChanged( mSnappingConfig ); } @@ -2084,9 +2096,11 @@ bool QgsProject::readBoolEntry( const QString &scope, const QString &key, bool d bool QgsProject::removeEntry( const QString &scope, const QString &key ) { - removeKey_( scope, key, mProperties ); - - setDirty( true ); + if ( findKey_( scope, key, mProperties ) ) + { + removeKey_( scope, key, mProperties ); + setDirty( true ); + } return !findKey_( scope, key, mProperties ); } @@ -2357,6 +2371,9 @@ bool QgsProject::evaluateDefaultValues() const void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues ) { + if ( evaluateDefaultValues == mEvaluateDefaultValues ) + return; + const QMap layers = mapLayers(); QMap::const_iterator layerIt = layers.constBegin(); for ( ; layerIt != layers.constEnd(); ++layerIt ) @@ -2848,6 +2865,9 @@ const QgsProjectMetadata &QgsProject::metadata() const void QgsProject::setMetadata( const QgsProjectMetadata &metadata ) { + if ( metadata == mMetadata ) + return; + mMetadata = metadata; emit metadataChanged(); diff --git a/tests/src/python/test_qgscoordinatetransformcontext.py b/tests/src/python/test_qgscoordinatetransformcontext.py index 7d0b6b898669..bb4a51a0d839 100644 --- a/tests/src/python/test_qgscoordinatetransformcontext.py +++ b/tests/src/python/test_qgscoordinatetransformcontext.py @@ -408,6 +408,19 @@ def testReadWriteSettings(self): {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1), ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)}) + def testEqualOperator(self): + context1 = QgsCoordinateTransformContext() + context2 = QgsCoordinateTransformContext() + self.assertTrue(context1 == context2) + + context1.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), + QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2) + self.assertFalse(context1 == context2) + + context2.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), + QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2) + self.assertTrue(context1 == context2) + if __name__ == '__main__': unittest.main() diff --git a/tests/src/python/test_qgsproject.py b/tests/src/python/test_qgsproject.py index 814efe9188c7..d8e803efe9d3 100644 --- a/tests/src/python/test_qgsproject.py +++ b/tests/src/python/test_qgsproject.py @@ -1121,7 +1121,7 @@ def testWriteEntry(self): self.assertTrue(ok) self.assertEqual(q, query) - def testWriteEntryDirtying(self): + def testDirtying(self): project = QgsProject() @@ -1140,6 +1140,27 @@ def testWriteEntryDirtying(self): self.assertTrue(project.writeEntry('myscope', 'myentry', False)) self.assertTrue(project.isDirty()) + # removing an existing entry should dirty the project + project.setDirty(False) + self.assertTrue(project.removeEntry('myscope', 'myentry')) + self.assertTrue(project.isDirty()) + + # removing a non-existing entry should _not_ dirty the project + project.setDirty(False) + self.assertTrue(project.removeEntry('myscope', 'myentry')) + self.assertFalse(project.isDirty()) + + # setting a project CRS with a new value should dirty the project + project.setCrs(QgsCoordinateReferenceSystem('EPSG:4326')) + project.setDirty(False) + project.setCrs(QgsCoordinateReferenceSystem('EPSG:3148')) + self.assertTrue(project.isDirty()) + + # setting a project CRS with the same project CRS should not dirty the project + project.setDirty(False) + project.setCrs(QgsCoordinateReferenceSystem('EPSG:3148')) + self.assertFalse(project.isDirty()) + if __name__ == '__main__': unittest.main()