Skip to content

Commit 0a325f1

Browse files
authored
Avoid signalling repaint / data signals when a setSubsetString doesn't actually change (#7217)
Behavior across providers harmonized & test added.
1 parent 6e3ee46 commit 0a325f1

File tree

9 files changed

+42
-3
lines changed

9 files changed

+42
-3
lines changed

src/core/providers/memory/qgsmemoryprovider.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ bool QgsMemoryProvider::setSubsetString( const QString &theSQL, bool updateFeatu
565565
return false;
566566
}
567567

568+
if ( theSQL == mSubsetString )
569+
return true;
570+
568571
mSubsetString = theSQL;
569572
clearMinMaxCache();
570573
mExtent.setMinimal();

src/core/qgsvectorlayer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,9 @@ bool QgsVectorLayer::setSubsetString( const QString &subset )
890890
return false;
891891
}
892892

893+
if ( subset == mDataProvider->subsetString() )
894+
return true;
895+
893896
bool res = mDataProvider->setSubsetString( subset );
894897

895898
// get the updated data source string from the provider

src/providers/oracle/qgsoracleprovider.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,9 @@ bool QgsOracleProvider::setSubsetString( const QString &theSQL, bool updateFeatu
20952095
if ( !mConnection )
20962096
return false;
20972097

2098+
if ( theSQL.trimmed() == mSqlWhereClause )
2099+
return true;
2100+
20982101
QString prevWhere = mSqlWhereClause;
20992102

21002103
mSqlWhereClause = theSQL.trimmed();

src/providers/postgres/qgspostgresprovider.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3098,6 +3098,9 @@ QgsVectorDataProvider::Capabilities QgsPostgresProvider::capabilities() const
30983098

30993099
bool QgsPostgresProvider::setSubsetString( const QString &theSQL, bool updateFeatureCount )
31003100
{
3101+
if ( theSQL.trimmed() == mSqlWhereClause )
3102+
return true;
3103+
31013104
QString prevWhere = mSqlWhereClause;
31023105

31033106
mSqlWhereClause = theSQL.trimmed();

src/providers/spatialite/qgsspatialiteprovider.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,10 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri, const Provider
604604
<< QgsVectorDataProvider::NativeType( tr( "Array of decimal numbers (double)" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "REAL" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::List, 0, 0, 0, 0, QVariant::Double )
605605
<< QgsVectorDataProvider::NativeType( tr( "Array of whole numbers (integer)" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "INTEGER" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::List, 0, 0, 0, 0, QVariant::LongLong )
606606
);
607+
607608
// Update extent and feature count
608609
if ( ! mSubsetString.isEmpty() )
609-
setSubsetString( mSubsetString, true );
610+
getTableSummary();
610611

611612
mValid = true;
612613
}
@@ -3450,6 +3451,9 @@ QString QgsSpatiaLiteProvider::subsetString() const
34503451

34513452
bool QgsSpatiaLiteProvider::setSubsetString( const QString &theSQL, bool updateFeatureCount )
34523453
{
3454+
if ( theSQL == mSubsetString )
3455+
return true;
3456+
34533457
QString prevSubsetString = mSubsetString;
34543458
mSubsetString = theSQL;
34553459

@@ -3461,6 +3465,7 @@ bool QgsSpatiaLiteProvider::setSubsetString( const QString &theSQL, bool updateF
34613465
// update feature count and extents
34623466
if ( updateFeatureCount && getTableSummary() )
34633467
{
3468+
emit dataChanged();
34643469
return true;
34653470
}
34663471

@@ -3473,8 +3478,6 @@ bool QgsSpatiaLiteProvider::setSubsetString( const QString &theSQL, bool updateF
34733478

34743479
getTableSummary();
34753480

3476-
emit dataChanged();
3477-
34783481
return false;
34793482
}
34803483

src/providers/virtual/qgsvirtuallayerprovider.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,16 @@ QString QgsVirtualLayerProvider::subsetString() const
503503

504504
bool QgsVirtualLayerProvider::setSubsetString( const QString &subset, bool updateFeatureCount )
505505
{
506+
if ( subset == mSubset )
507+
return true;
508+
506509
mSubset = subset;
507510
clearMinMaxCache();
508511
if ( updateFeatureCount )
509512
updateStatistics();
513+
514+
emit dataChanged();
515+
510516
return true;
511517
}
512518

src/providers/wfs/qgswfsprovider.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ bool QgsWFSProvider::setSubsetString( const QString &theSQL, bool updateFeatureC
679679
{
680680
QgsDebugMsg( QString( "theSql = '%1'" ).arg( theSQL ) );
681681

682+
if ( theSQL == mSubsetString )
683+
return true;
684+
682685
// Invalid and cancel current download before altering fields, etc...
683686
// (crashes might happen if not done at the beginning)
684687
mShared->invalidateCache();
@@ -710,13 +713,17 @@ bool QgsWFSProvider::setSubsetString( const QString &theSQL, bool updateFeatureC
710713
mShared->mURI.setSql( QString() );
711714
mShared->mURI.setFilter( theSQL );
712715
}
716+
713717
setDataSourceUri( mShared->mURI.uri() );
714718
QString errorMsg;
715719
if ( !mShared->computeFilter( errorMsg ) )
716720
QgsMessageLog::logMessage( errorMsg, tr( "WFS" ) );
717721
reloadData();
718722
if ( updateFeatureCount )
719723
featureCount();
724+
725+
emit dataChanged();
726+
720727
return true;
721728
}
722729

tests/src/python/provider_python.py

+3
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,13 @@ def subsetString(self):
373373
return self._subset_string
374374

375375
def setSubsetString(self, subsetString):
376+
if subsetString == self._subset_string:
377+
return True
376378
self._subset_string = subsetString
377379
self.updateExtents()
378380
self.clearMinMaxCache()
379381
self.dataChanged.emit()
382+
return True
380383

381384
def supportsSubsetString(self):
382385
return True

tests/src/python/providertestbase.py

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
QgsTestUtils,
3131
NULL
3232
)
33+
from qgis.PyQt.QtTest import QSignalSpy
3334

3435
from utilities import compareWkt
3536
from featuresourcetestbase import FeatureSourceTestCase
@@ -157,9 +158,16 @@ def testSubsetString(self):
157158
print('Provider does not support subset strings')
158159
return
159160

161+
changed_spy = QSignalSpy(self.source.dataChanged)
160162
subset = self.getSubsetString()
161163
self.source.setSubsetString(subset)
162164
self.assertEqual(self.source.subsetString(), subset)
165+
self.assertEqual(len(changed_spy), 1)
166+
167+
# No signal should be emitted if the subset string is not modified
168+
self.source.setSubsetString(subset)
169+
self.assertEqual(len(changed_spy), 1)
170+
163171
result = set([f['pk'] for f in self.source.getFeatures()])
164172
all_valid = (all(f.isValid() for f in self.source.getFeatures()))
165173
self.source.setSubsetString(None)

0 commit comments

Comments
 (0)