Thread safety for feature counter

Make sure that results from a feature counter will only be delivered on
the main thread and that they will be discarded if the layer is deleted
meanwhile.
This commit is contained in:
Matthias Kuhn 2017-09-05 10:16:10 +02:00
parent b5bb7df7eb
commit 4ea4478bad
3 changed files with 16 additions and 10 deletions

View File

@ -1787,10 +1787,6 @@ Returns the current blending mode for features
:rtype: bool
%End
protected slots:
void invalidateSymbolCountedFlag();
signals:
void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, const bool clearAndSelect );

View File

@ -770,8 +770,8 @@ bool QgsVectorLayer::countSymbolFeatures()
if ( !mFeatureCounter )
{
mFeatureCounter = new QgsVectorLayerFeatureCounter( this );
connect( mFeatureCounter, &QgsTask::taskCompleted, [ = ]() { onSymbolsCounted(); mFeatureCounter = nullptr; } );
connect( mFeatureCounter, &QgsTask::taskTerminated, [ = ]() { mFeatureCounter = nullptr; } );
connect( mFeatureCounter, &QgsTask::taskCompleted, this, &QgsVectorLayer::onFeatureCounterCompleted );
connect( mFeatureCounter, &QgsTask::taskTerminated, this, &QgsVectorLayer::onFeatureCounterTerminated );
QgsApplication::taskManager()->addTask( mFeatureCounter );
}
@ -4034,6 +4034,17 @@ void QgsVectorLayer::invalidateSymbolCountedFlag()
mSymbolFeatureCounted = false;
}
void QgsVectorLayer::onFeatureCounterCompleted()
{
onSymbolsCounted();
mFeatureCounter = nullptr;
}
void QgsVectorLayer::onFeatureCounterTerminated()
{
mFeatureCounter = nullptr;
}
void QgsVectorLayer::onJoinedFieldsChanged()
{
// some of the fields of joined layers have changed -> we need to update this layer's fields too

View File

@ -1662,10 +1662,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
bool startEditing();
protected slots:
void invalidateSymbolCountedFlag();
signals:
/**
@ -1901,6 +1897,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
void symbolFeatureCountMapChanged();
private slots:
void invalidateSymbolCountedFlag();
void onFeatureCounterCompleted();
void onFeatureCounterTerminated();
void onJoinedFieldsChanged();
void onFeatureDeleted( QgsFeatureId fid );
void onRelationsLoaded();