Skip to content

Commit c603cfb

Browse files
committed
Copy data for background threads
reduce requirements to run code on main thread which risks freezes because of deadlocks
1 parent 89e0ff9 commit c603cfb

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212

13-
1413
class QgsFeaturePool : QgsFeatureSink /Abstract/
1514
{
1615
%Docstring
@@ -76,6 +75,8 @@ The geometry type of this layer.
7675
The coordinate reference system of this layer.
7776
%End
7877

78+
QString layerName() const;
79+
7980
protected:
8081

8182
void insertFeature( const QgsFeature &feature );

src/analysis/vector/geometry_checker/qgsfeaturepool.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
QgsFeaturePool::QgsFeaturePool( QgsVectorLayer *layer )
3030
: mFeatureCache( CACHE_SIZE )
3131
, mLayer( layer )
32-
, mLayerId( layer->id() )
3332
, mGeometryType( layer->geometryType() )
34-
, mCrs( layer->crs() )
33+
, mFeatureSource( qgis::make_unique<QgsVectorLayerFeatureSource>( layer ) )
34+
, mLayerName( layer->name() )
3535
{
3636

3737
}
@@ -55,11 +55,9 @@ bool QgsFeaturePool::getFeature( QgsFeatureId id, QgsFeature &feature, QgsFeedba
5555
}
5656
else
5757
{
58-
std::unique_ptr<QgsVectorLayerFeatureSource> source = QgsVectorLayerUtils::getFeatureSource( mLayer, feedback );
59-
6058
// Feature not in cache, retrieve from layer
6159
// TODO: avoid always querying all attributes (attribute values are needed when merging by attribute)
62-
if ( !source || !source->getFeatures( QgsFeatureRequest( id ) ).nextFeature( feature ) )
60+
if ( !mFeatureSource->getFeatures( QgsFeatureRequest( id ) ).nextFeature( feature ) )
6361
{
6462
return false;
6563
}
@@ -150,12 +148,18 @@ void QgsFeaturePool::setFeatureIds( const QgsFeatureIds &ids )
150148

151149
bool QgsFeaturePool::isFeatureCached( QgsFeatureId fid )
152150
{
151+
QgsReadWriteLocker locker( mCacheLock, QgsReadWriteLocker::Read );
153152
return mFeatureCache.contains( fid );
154153
}
155154

155+
QString QgsFeaturePool::layerName() const
156+
{
157+
return mLayerName;
158+
}
159+
156160
QgsCoordinateReferenceSystem QgsFeaturePool::crs() const
157161
{
158-
return mCrs;
162+
return mFeatureSource->crs();
159163
}
160164

161165
QgsWkbTypes::GeometryType QgsFeaturePool::geometryType() const
@@ -165,5 +169,5 @@ QgsWkbTypes::GeometryType QgsFeaturePool::geometryType() const
165169

166170
QString QgsFeaturePool::layerId() const
167171
{
168-
return mLayerId;
172+
return mFeatureSource->id();
169173
}

src/analysis/vector/geometry_checker/qgsfeaturepool.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include "qgsfeature.h"
2626
#include "qgsspatialindex.h"
2727
#include "qgsfeaturesink.h"
28-
29-
class QgsVectorLayer;
28+
#include "qgsvectorlayerfeatureiterator.h"
3029

3130
/**
3231
* \ingroup analysis
@@ -121,6 +120,8 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
121120
*/
122121
QgsCoordinateReferenceSystem crs() const;
123122

123+
QString layerName() const;
124+
124125
protected:
125126

126127
/**
@@ -170,9 +171,9 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
170171
mutable QReadWriteLock mCacheLock;
171172
QgsFeatureIds mFeatureIds;
172173
QgsSpatialIndex mIndex;
173-
QString mLayerId;
174174
QgsWkbTypes::GeometryType mGeometryType;
175-
QgsCoordinateReferenceSystem mCrs;
175+
std::unique_ptr<QgsVectorLayerFeatureSource> mFeatureSource;
176+
QString mLayerName;
176177
};
177178

178179
#endif // QGS_FEATUREPOOL_H

src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ QgsGeometry QgsGeometryCheckerUtils::LayerFeature::geometry() const
7474

7575
QString QgsGeometryCheckerUtils::LayerFeature::id() const
7676
{
77-
return QStringLiteral( "%1:%2" ).arg( layer()->name() ).arg( mFeature.id() );
77+
return QStringLiteral( "%1:%2" ).arg( mFeaturePool->layerName() ).arg( mFeature.id() );
7878
}
7979

8080
bool QgsGeometryCheckerUtils::LayerFeature::operator==( const LayerFeature &other ) const
8181
{
82-
return layer()->id() == other.layer()->id() && feature().id() == other.feature().id();
82+
return layerId() == other.layerId() && mFeature.id() == other.mFeature.id();
8383
}
8484

8585
bool QgsGeometryCheckerUtils::LayerFeature::operator!=( const LayerFeature &other ) const
8686
{
87-
return layer()->id() != other.layer()->id() || feature().id() != other.feature().id();
87+
return layerId() != other.layerId() || mFeature.id() != other.mFeature.id();
8888
}
8989

9090
/////////////////////////////////////////////////////////////////////////////
@@ -197,7 +197,7 @@ bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextFeature( bool begin )
197197
QgsFeature feature;
198198
if ( featurePool->getFeature( *mFeatureIt, feature ) && !feature.geometry().isNull() )
199199
{
200-
mCurrentFeature.reset( new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mContext, mParent->mUseMapCrs ) );
200+
mCurrentFeature = qgis::make_unique<LayerFeature>( featurePool, feature, mParent->mContext, mParent->mUseMapCrs );
201201
return true;
202202
}
203203
++mFeatureIt;

0 commit comments

Comments
 (0)