Skip to content
Permalink
Browse files

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 4ea4478bad555876984c873c9b03b26b02b6ec40
Showing with 16 additions and 10 deletions.
  1. +0 −4 python/core/qgsvectorlayer.sip
  2. +13 −2 src/core/qgsvectorlayer.cpp
  3. +3 −4 src/core/qgsvectorlayer.h
@@ -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 );
@@ -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
@@ -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();

0 comments on commit 4ea4478

Please sign in to comment.
You can’t perform that action at this time.