Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use unique_ptr
  • Loading branch information
nyalldawson committed Feb 8, 2021
1 parent 98c927c commit cd2df66
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
Expand Up @@ -33,6 +33,7 @@ Constructor for QgsVectorLayerFeatureSource.
:param layer: source layer
%End


~QgsVectorLayerFeatureSource();

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() );
Expand Down Expand Up @@ -70,7 +71,8 @@ Returns the layer id of the source layer.




private:
QgsVectorLayerFeatureSource( const QgsVectorLayerFeatureSource &other );
};


Expand Down Expand Up @@ -181,6 +183,7 @@ The currently selected feature IDs are stored, so change to the layer selection
the QgsVectorLayerSelectedFeatureSource will not be reflected.
%End


virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const;

virtual QgsCoordinateReferenceSystem sourceCrs() const;
Expand All @@ -198,6 +201,8 @@ the QgsVectorLayerSelectedFeatureSource will not be reflected.
virtual SpatialIndexPresence hasSpatialIndex() const;


private:
QgsVectorLayerSelectedFeatureSource( const QgsVectorLayerSelectedFeatureSource &other );
};


Expand Down
13 changes: 4 additions & 9 deletions src/core/vector/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -31,17 +31,17 @@
QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( const QgsVectorLayer *layer )
{
QMutexLocker locker( &layer->mFeatureSourceConstructorMutex );
mProviderFeatureSource = layer->dataProvider()->featureSource();
mProviderFeatureSource.reset( layer->dataProvider()->featureSource() );
mFields = layer->fields();
mId = layer->id();

// update layer's join caches if necessary
if ( layer->mJoinBuffer->containsJoins() )
layer->mJoinBuffer->createJoinCaches();

mJoinBuffer = layer->mJoinBuffer->clone();
mJoinBuffer.reset( layer->mJoinBuffer->clone() );

mExpressionFieldBuffer = new QgsExpressionFieldBuffer( *layer->mExpressionFieldBuffer );
mExpressionFieldBuffer.reset( new QgsExpressionFieldBuffer( *layer->mExpressionFieldBuffer ) );
mCrs = layer->crs();

mHasEditBuffer = layer->editBuffer();
Expand Down Expand Up @@ -86,12 +86,7 @@ QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( const QgsVectorLayer *
mLayerScope = *layerScope;
}

QgsVectorLayerFeatureSource::~QgsVectorLayerFeatureSource()
{
delete mJoinBuffer;
delete mExpressionFieldBuffer;
delete mProviderFeatureSource;
}
QgsVectorLayerFeatureSource::~QgsVectorLayerFeatureSource() = default;

QgsFeatureIterator QgsVectorLayerFeatureSource::getFeatures( const QgsFeatureRequest &request )
{
Expand Down
27 changes: 22 additions & 5 deletions src/core/vector/qgsvectorlayerfeatureiterator.h
Expand Up @@ -58,6 +58,11 @@ class CORE_EXPORT QgsVectorLayerFeatureSource : public QgsAbstractFeatureSource
*/
explicit QgsVectorLayerFeatureSource( const QgsVectorLayer *layer );

//! QgsVectorLayerFeatureSource cannot be copied
QgsVectorLayerFeatureSource( const QgsVectorLayerFeatureSource &other ) = delete;
//! QgsVectorLayerFeatureSource cannot be copied
QgsVectorLayerFeatureSource &operator==( const QgsVectorLayerFeatureSource &other ) = delete;

~QgsVectorLayerFeatureSource() override;

QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) override;
Expand Down Expand Up @@ -87,11 +92,9 @@ class CORE_EXPORT QgsVectorLayerFeatureSource : public QgsAbstractFeatureSource

protected:

QgsAbstractFeatureSource *mProviderFeatureSource = nullptr;

QgsVectorLayerJoinBuffer *mJoinBuffer = nullptr;

QgsExpressionFieldBuffer *mExpressionFieldBuffer = nullptr;
std::unique_ptr< QgsAbstractFeatureSource > mProviderFeatureSource;
std::unique_ptr< QgsVectorLayerJoinBuffer > mJoinBuffer;
std::unique_ptr< QgsExpressionFieldBuffer > mExpressionFieldBuffer;

QgsFields mFields;

Expand All @@ -112,6 +115,11 @@ class CORE_EXPORT QgsVectorLayerFeatureSource : public QgsAbstractFeatureSource
QgsAttributeList mDeletedAttributeIds;

QgsCoordinateReferenceSystem mCrs;

private:
#ifdef SIP_RUN
QgsVectorLayerFeatureSource( const QgsVectorLayerFeatureSource &other );
#endif
};

/**
Expand Down Expand Up @@ -312,6 +320,11 @@ class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource,
*/
QgsVectorLayerSelectedFeatureSource( QgsVectorLayer *layer );

//! QgsVectorLayerSelectedFeatureSource cannot be copied
QgsVectorLayerSelectedFeatureSource( const QgsVectorLayerSelectedFeatureSource &other ) = delete;
//! QgsVectorLayerSelectedFeatureSource cannot be copied
QgsVectorLayerSelectedFeatureSource &operator==( const QgsVectorLayerSelectedFeatureSource &other ) = delete;

QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
QgsCoordinateReferenceSystem sourceCrs() const override;
QgsFields fields() const override;
Expand All @@ -323,6 +336,10 @@ class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource,

private:

#ifdef SIP_RUN
QgsVectorLayerSelectedFeatureSource( const QgsVectorLayerSelectedFeatureSource &other );
#endif

// ideally this wouldn't be mutable, but QgsVectorLayerFeatureSource has non-const getFeatures()
mutable QgsVectorLayerFeatureSource mSource;
QgsFeatureIds mSelectedFeatureIds;
Expand Down

0 comments on commit cd2df66

Please sign in to comment.