Fix compatibility with older sip versions

This commit is contained in:
Matthias Kuhn 2017-05-10 00:33:13 +02:00
parent 964d9ac70a
commit 05a713f444
6 changed files with 40 additions and 14 deletions

View File

@ -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
};

View File

@ -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 );

View File

@ -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;
@ -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

View File

@ -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
@ -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;
};

View File

@ -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;
}

View File

@ -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;