Skip to content
Permalink
Browse files

Use unique_ptr

  • Loading branch information
nyalldawson committed Feb 8, 2021
1 parent 98c927c commit cd2df66674108ac6de7451d44de7ecd9a18ca2ce
@@ -33,6 +33,7 @@ Constructor for QgsVectorLayerFeatureSource.
:param layer: source layer
%End


~QgsVectorLayerFeatureSource();

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




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


@@ -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;
@@ -198,6 +201,8 @@ the QgsVectorLayerSelectedFeatureSource will not be reflected.
virtual SpatialIndexPresence hasSpatialIndex() const;


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


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

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

QgsCoordinateReferenceSystem mCrs;

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

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

0 comments on commit cd2df66

Please sign in to comment.