Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m-kuhn committed Sep 5, 2017
1 parent b5bb7df commit 4ea4478
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 0 additions & 4 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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 );
Expand Down
15 changes: 13 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1662,10 +1662,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
bool startEditing();


protected slots:
void invalidateSymbolCountedFlag();

signals:

/**
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4ea4478

Please sign in to comment.