Skip to content

Commit 05a713f

Browse files
committed
Fix compatibility with older sip versions
1 parent 964d9ac commit 05a713f

6 files changed

+40
-14
lines changed

python/core/qgsvectorlayerfeaturecounter.sip

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ class QgsVectorLayerFeatureCounter : QgsTask
3131

3232
virtual bool run();
3333

34+
3435
signals:
35-
void symbolsCounted( const QHash<QString, long> &symbolFeatureCountMap );
36+
37+
void symbolsCounted();
38+
%Docstring
39+
Emitted when the symbols have been counted.
40+
%End
3641

3742
};
3843

src/core/layertree/qgslayertreemodellegendnode.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ QgsSymbolLegendNode::QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const Qg
135135
, mIconSize( 16, 16 )
136136
{
137137
updateLabel();
138+
connect( qobject_cast<QgsVectorLayer*>( nodeLayer->layer() ), &QgsVectorLayer::symbolFeatureCountMapChanged, this, &QgsSymbolLegendNode::updateLabel );
138139

139140
if ( mItem.symbol() )
140141
mSymbolUsesMapUnits = ( mItem.symbol()->outputUnit() != QgsUnitTypes::RenderMillimeters );

src/core/qgsvectorlayer.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,12 @@ bool QgsVectorLayer::countSymbolFeatures()
702702

703703
if ( !mFeatureCounter )
704704
{
705-
mFeatureCounter.reset( new QgsVectorLayerFeatureCounter( this ) );
706-
connect( mFeatureCounter.get(), &QgsVectorLayerFeatureCounter::symbolsCounted, this, &QgsVectorLayer::onSymbolsCounted );
707-
connect( mFeatureCounter.get(), &QgsTask::taskCompleted, [ = ]() { mFeatureCounter.reset(); } );
708-
connect( mFeatureCounter.get(), &QgsTask::taskTerminated, [ = ]() { mFeatureCounter.reset(); } );
705+
mFeatureCounter = new QgsVectorLayerFeatureCounter( this );
706+
connect( mFeatureCounter, &QgsVectorLayerFeatureCounter::symbolsCounted, this, &QgsVectorLayer::onSymbolsCounted );
707+
connect( mFeatureCounter, &QgsTask::taskCompleted, [ = ]() { mFeatureCounter = nullptr; } );
708+
connect( mFeatureCounter, &QgsTask::taskTerminated, [ = ]() { mFeatureCounter = nullptr; } );
709709

710-
QgsApplication::taskManager()->addTask( mFeatureCounter.get() );
710+
QgsApplication::taskManager()->addTask( mFeatureCounter );
711711
}
712712

713713
return true;
@@ -3899,11 +3899,14 @@ void QgsVectorLayer::onRelationsLoaded()
38993899
mEditFormConfig.onRelationsLoaded();
39003900
}
39013901

3902-
void QgsVectorLayer::onSymbolsCounted( const QHash<QString, long> &symbolFeatureCountMap )
3902+
void QgsVectorLayer::onSymbolsCounted()
39033903
{
3904-
mSymbolFeatureCountMap = symbolFeatureCountMap;
3905-
mSymbolFeatureCounted = true;
3906-
emit symbolFeatureCountMapChanged();
3904+
if ( mFeatureCounter )
3905+
{
3906+
mSymbolFeatureCountMap = mFeatureCounter->symbolFeatureCountMap();
3907+
mSymbolFeatureCounted = true;
3908+
emit symbolFeatureCountMapChanged();
3909+
}
39073910
}
39083911

39093912
QList<QgsRelation> QgsVectorLayer::referencingRelations( int idx ) const

src/core/qgsvectorlayer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
18581858
void onJoinedFieldsChanged();
18591859
void onFeatureDeleted( QgsFeatureId fid );
18601860
void onRelationsLoaded();
1861-
void onSymbolsCounted( const QHash<QString, long> &symbolFeatureCountMap );
1861+
void onSymbolsCounted();
18621862

18631863
protected:
18641864
//! Set the extent
@@ -2008,7 +2008,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
20082008

20092009
mutable QMutex mFeatureSourceConstructorMutex;
20102010

2011-
std::unique_ptr<QgsVectorLayerFeatureCounter> mFeatureCounter;
2011+
QgsVectorLayerFeatureCounter *mFeatureCounter = nullptr;
20122012

20132013
friend class QgsVectorLayerFeatureSource;
20142014
};

src/core/qgsvectorlayerfeaturecounter.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ bool QgsVectorLayerFeatureCounter::run()
6464
mRenderer->stopRender( renderContext );
6565
setProgress( 100 );
6666

67-
emit symbolsCounted( mSymbolFeatureCountMap );
67+
emit symbolsCounted();
6868
return true;
6969
}
70+
71+
QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
72+
{
73+
return mSymbolFeatureCountMap;
74+
}

src/core/qgsvectorlayerfeaturecounter.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,20 @@ class CORE_EXPORT QgsVectorLayerFeatureCounter : public QgsTask
2828

2929
virtual bool run() override;
3030

31+
/**
32+
* Get the count for each symbol. Only valid after the symbolsCounted()
33+
* signal has been emitted.
34+
*
35+
* \note Not available in Python bindings.
36+
*/
37+
QHash<QString, long> symbolFeatureCountMap() const SIP_SKIP;
38+
3139
signals:
32-
void symbolsCounted( const QHash<QString, long> &symbolFeatureCountMap );
40+
41+
/**
42+
* Emitted when the symbols have been counted.
43+
*/
44+
void symbolsCounted();
3345

3446
private:
3547
std::unique_ptr<QgsVectorLayerFeatureSource> mSource;

0 commit comments

Comments
 (0)