Skip to content

Commit 4e1d684

Browse files
committedNov 21, 2018
Avoid more needless project dirtying
1 parent 5171e4e commit 4e1d684

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed
 

‎python/core/auto_generated/qgscoordinatetransformcontext.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Copy constructor
6363
%End
6464

6565

66+
bool operator==( const QgsCoordinateTransformContext &rhs ) const;
6667

6768
void clear();
6869
%Docstring

‎src/core/qgscoordinatetransformcontext.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ QgsCoordinateTransformContext &QgsCoordinateTransformContext::operator=( const Q
3636
return *this;
3737
}
3838

39+
bool QgsCoordinateTransformContext::operator==( const QgsCoordinateTransformContext &rhs ) const
40+
{
41+
if ( d == rhs.d )
42+
return true;
43+
44+
d->mLock.lockForRead();
45+
rhs.d->mLock.lockForRead();
46+
bool equal = d->mSourceDestDatumTransforms == rhs.d->mSourceDestDatumTransforms;
47+
d->mLock.unlock();
48+
rhs.d->mLock.unlock();
49+
return equal;
50+
}
51+
3952
void QgsCoordinateTransformContext::clear()
4053
{
4154
d.detach();

‎src/core/qgscoordinatetransformcontext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CORE_EXPORT QgsCoordinateTransformContext
8080
*/
8181
QgsCoordinateTransformContext &operator=( const QgsCoordinateTransformContext &rhs ) SIP_SKIP;
8282

83+
bool operator==( const QgsCoordinateTransformContext &rhs ) const ;
8384

8485
/**
8586
* Clears all stored transform information from the context.

‎src/core/qgsproject.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ QgsProjectProperty *addKey_( const QString &scope,
278278
return nullptr;
279279
}
280280

281+
/**
282+
* Remove a given key
283+
284+
\param scope scope of key
285+
\param key key name
286+
\param rootProperty is the property from which to start adding
287+
*/
281288

282289
void removeKey_( const QString &scope,
283290
const QString &key,
@@ -628,6 +635,9 @@ QgsCoordinateReferenceSystem QgsProject::crs() const
628635

629636
void QgsProject::setCrs( const QgsCoordinateReferenceSystem &crs )
630637
{
638+
if ( crs == mCrs )
639+
return;
640+
631641
mCrs = crs;
632642
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), crs.isValid() ? 1 : 0 );
633643
setDirty( true );
@@ -645,7 +655,6 @@ QString QgsProject::ellipsoid() const
645655
void QgsProject::setEllipsoid( const QString &ellipsoid )
646656
{
647657
writeEntry( QStringLiteral( "Measure" ), QStringLiteral( "/Ellipsoid" ), ellipsoid );
648-
setDirty( true );
649658
emit ellipsoidChanged( ellipsoid );
650659
}
651660

@@ -656,6 +665,9 @@ QgsCoordinateTransformContext QgsProject::transformContext() const
656665

657666
void QgsProject::setTransformContext( const QgsCoordinateTransformContext &context )
658667
{
668+
if ( context == mTransformContext )
669+
return;
670+
659671
mTransformContext = context;
660672
emit transformContextChanged();
661673
}
@@ -848,7 +860,7 @@ void QgsProject::setSnappingConfig( const QgsSnappingConfig &snappingConfig )
848860
return;
849861

850862
mSnappingConfig = snappingConfig;
851-
setDirty();
863+
setDirty( true );
852864
emit snappingConfigChanged( mSnappingConfig );
853865
}
854866

@@ -2117,9 +2129,11 @@ bool QgsProject::readBoolEntry( const QString &scope, const QString &key, bool d
21172129

21182130
bool QgsProject::removeEntry( const QString &scope, const QString &key )
21192131
{
2120-
removeKey_( scope, key, mProperties );
2121-
2122-
setDirty( true );
2132+
if ( findKey_( scope, key, mProperties ) )
2133+
{
2134+
removeKey_( scope, key, mProperties );
2135+
setDirty( true );
2136+
}
21232137

21242138
return !findKey_( scope, key, mProperties );
21252139
}
@@ -2390,6 +2404,9 @@ bool QgsProject::evaluateDefaultValues() const
23902404

23912405
void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues )
23922406
{
2407+
if ( evaluateDefaultValues == mEvaluateDefaultValues )
2408+
return;
2409+
23932410
const QMap<QString, QgsMapLayer *> layers = mapLayers();
23942411
QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
23952412
for ( ; layerIt != layers.constEnd(); ++layerIt )
@@ -2886,6 +2903,9 @@ const QgsProjectMetadata &QgsProject::metadata() const
28862903

28872904
void QgsProject::setMetadata( const QgsProjectMetadata &metadata )
28882905
{
2906+
if ( metadata == mMetadata )
2907+
return;
2908+
28892909
mMetadata = metadata;
28902910
emit metadataChanged();
28912911

‎tests/src/python/test_qgscoordinatetransformcontext.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ def testReadWriteSettings(self):
408408
{('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
409409
('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})
410410

411+
def testEqualOperator(self):
412+
context1 = QgsCoordinateTransformContext()
413+
context2 = QgsCoordinateTransformContext()
414+
self.assertTrue(context1 == context2)
415+
416+
context1.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
417+
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)
418+
self.assertFalse(context1 == context2)
419+
420+
context2.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
421+
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)
422+
self.assertTrue(context1 == context2)
423+
411424

412425
if __name__ == '__main__':
413426
unittest.main()

‎tests/src/python/test_qgsproject.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ def testWriteEntry(self):
11291129
self.assertTrue(ok)
11301130
self.assertEqual(q, query)
11311131

1132-
def testWriteEntryDirtying(self):
1132+
def testDirtying(self):
11331133

11341134
project = QgsProject()
11351135

@@ -1148,6 +1148,27 @@ def testWriteEntryDirtying(self):
11481148
self.assertTrue(project.writeEntry('myscope', 'myentry', False))
11491149
self.assertTrue(project.isDirty())
11501150

1151+
# removing an existing entry should dirty the project
1152+
project.setDirty(False)
1153+
self.assertTrue(project.removeEntry('myscope', 'myentry'))
1154+
self.assertTrue(project.isDirty())
1155+
1156+
# removing a non-existing entry should _not_ dirty the project
1157+
project.setDirty(False)
1158+
self.assertTrue(project.removeEntry('myscope', 'myentry'))
1159+
self.assertFalse(project.isDirty())
1160+
1161+
# setting a project CRS with a new value should dirty the project
1162+
project.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
1163+
project.setDirty(False)
1164+
project.setCrs(QgsCoordinateReferenceSystem('EPSG:3148'))
1165+
self.assertTrue(project.isDirty())
1166+
1167+
# setting a project CRS with the same project CRS should not dirty the project
1168+
project.setDirty(False)
1169+
project.setCrs(QgsCoordinateReferenceSystem('EPSG:3148'))
1170+
self.assertFalse(project.isDirty())
1171+
11511172

11521173
if __name__ == '__main__':
11531174
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.