Skip to content

Commit

Permalink
Fix compatibility with older sip versions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 11, 2017
1 parent 964d9ac commit 05a713f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
7 changes: 6 additions & 1 deletion python/core/qgsvectorlayerfeaturecounter.sip
Expand Up @@ -31,8 +31,13 @@ class QgsVectorLayerFeatureCounter : QgsTask

virtual bool run();


signals:
void symbolsCounted( const QHash<QString, long> &symbolFeatureCountMap );

void symbolsCounted();
%Docstring
Emitted when the symbols have been counted.
%End

};

Expand Down
1 change: 1 addition & 0 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -135,6 +135,7 @@ QgsSymbolLegendNode::QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const Qg
, mIconSize( 16, 16 )
{
updateLabel();
connect( qobject_cast<QgsVectorLayer*>( nodeLayer->layer() ), &QgsVectorLayer::symbolFeatureCountMapChanged, this, &QgsSymbolLegendNode::updateLabel );

if ( mItem.symbol() )
mSymbolUsesMapUnits = ( mItem.symbol()->outputUnit() != QgsUnitTypes::RenderMillimeters );
Expand Down
21 changes: 12 additions & 9 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -702,12 +702,12 @@ bool QgsVectorLayer::countSymbolFeatures()

if ( !mFeatureCounter )
{
mFeatureCounter.reset( new QgsVectorLayerFeatureCounter( this ) );
connect( mFeatureCounter.get(), &QgsVectorLayerFeatureCounter::symbolsCounted, this, &QgsVectorLayer::onSymbolsCounted );
connect( mFeatureCounter.get(), &QgsTask::taskCompleted, [ = ]() { mFeatureCounter.reset(); } );
connect( mFeatureCounter.get(), &QgsTask::taskTerminated, [ = ]() { mFeatureCounter.reset(); } );
mFeatureCounter = new QgsVectorLayerFeatureCounter( this );
connect( mFeatureCounter, &QgsVectorLayerFeatureCounter::symbolsCounted, this, &QgsVectorLayer::onSymbolsCounted );
connect( mFeatureCounter, &QgsTask::taskCompleted, [ = ]() { mFeatureCounter = nullptr; } );
connect( mFeatureCounter, &QgsTask::taskTerminated, [ = ]() { mFeatureCounter = nullptr; } );

QgsApplication::taskManager()->addTask( mFeatureCounter.get() );
QgsApplication::taskManager()->addTask( mFeatureCounter );
}

return true;
Expand Down Expand Up @@ -3899,11 +3899,14 @@ void QgsVectorLayer::onRelationsLoaded()
mEditFormConfig.onRelationsLoaded();
}

void QgsVectorLayer::onSymbolsCounted( const QHash<QString, long> &symbolFeatureCountMap )
void QgsVectorLayer::onSymbolsCounted()
{
mSymbolFeatureCountMap = symbolFeatureCountMap;
mSymbolFeatureCounted = true;
emit symbolFeatureCountMapChanged();
if ( mFeatureCounter )
{
mSymbolFeatureCountMap = mFeatureCounter->symbolFeatureCountMap();
mSymbolFeatureCounted = true;
emit symbolFeatureCountMapChanged();
}
}

QList<QgsRelation> QgsVectorLayer::referencingRelations( int idx ) const
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1858,7 +1858,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
void onJoinedFieldsChanged();
void onFeatureDeleted( QgsFeatureId fid );
void onRelationsLoaded();
void onSymbolsCounted( const QHash<QString, long> &symbolFeatureCountMap );
void onSymbolsCounted();

protected:
//! Set the extent
Expand Down Expand Up @@ -2008,7 +2008,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

mutable QMutex mFeatureSourceConstructorMutex;

std::unique_ptr<QgsVectorLayerFeatureCounter> mFeatureCounter;
QgsVectorLayerFeatureCounter *mFeatureCounter = nullptr;

friend class QgsVectorLayerFeatureSource;
};
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsvectorlayerfeaturecounter.cpp
Expand Up @@ -64,6 +64,11 @@ bool QgsVectorLayerFeatureCounter::run()
mRenderer->stopRender( renderContext );
setProgress( 100 );

emit symbolsCounted( mSymbolFeatureCountMap );
emit symbolsCounted();
return true;
}

QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
{
return mSymbolFeatureCountMap;
}
14 changes: 13 additions & 1 deletion src/core/qgsvectorlayerfeaturecounter.h
Expand Up @@ -28,8 +28,20 @@ class CORE_EXPORT QgsVectorLayerFeatureCounter : public QgsTask

virtual bool run() override;

/**
* Get the count for each symbol. Only valid after the symbolsCounted()
* signal has been emitted.
*
* \note Not available in Python bindings.
*/
QHash<QString, long> symbolFeatureCountMap() const SIP_SKIP;

signals:
void symbolsCounted( const QHash<QString, long> &symbolFeatureCountMap );

/**
* Emitted when the symbols have been counted.
*/
void symbolsCounted();

private:
std::unique_ptr<QgsVectorLayerFeatureSource> mSource;
Expand Down

0 comments on commit 05a713f

Please sign in to comment.