Skip to content
Permalink
Browse files
Use unique_ptrs in provider feature sources
  • Loading branch information
nyalldawson committed Apr 23, 2017
1 parent 8c1584f commit 706b5a8537d8ce385eb59fd632998ef8d197b978
@@ -32,7 +32,6 @@ QgsDb2FeatureIterator::QgsDb2FeatureIterator( QgsDb2FeatureSource *source, bool
: QgsAbstractFeatureIteratorFromSource<QgsDb2FeatureSource>( source, ownSource, request )
{
mClosed = false;
mQuery = nullptr;
mFetchCount = 0;

BuildStatement( request );
@@ -48,7 +47,7 @@ QgsDb2FeatureIterator::QgsDb2FeatureIterator( QgsDb2FeatureSource *source, bool
}

// create sql query
mQuery = new QSqlQuery( mDatabase );
mQuery.reset( new QSqlQuery( mDatabase ) );

// start selection
rewind();
@@ -428,7 +427,7 @@ bool QgsDb2FeatureIterator::close()
{
mQuery->finish();
}
delete mQuery;
mQuery.reset();
}

if ( mDatabase.isOpen() )
@@ -85,7 +85,7 @@ class QgsDb2FeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsDb2
QString mOrderByClause;

// The current sql query
QSqlQuery *mQuery = nullptr;
std::unique_ptr< QSqlQuery > mQuery;

// The current sql statement
QString mStatement;
@@ -271,7 +271,7 @@ bool QgsDelimitedTextFeatureIterator::nextFeatureInternal( QgsFeature &feature )
{
QStringList tokens;

QgsDelimitedTextFile *file = mSource->mFile;
QgsDelimitedTextFile *file = mSource->mFile.get();

// If the iterator is not scanning the file, then it will have requested a specific
// record, so only need to load that one.
@@ -506,7 +506,7 @@ QgsDelimitedTextFeatureSource::QgsDelimitedTextFeatureSource( const QgsDelimited
url.removeQueryItem( QStringLiteral( "watchFile" ) );
}

mFile = new QgsDelimitedTextFile();
mFile.reset( new QgsDelimitedTextFile() );
mFile->setFromUrl( url );

mExpressionContext << QgsExpressionContextUtils::globalScope()
@@ -517,8 +517,6 @@ QgsDelimitedTextFeatureSource::QgsDelimitedTextFeatureSource( const QgsDelimited
QgsDelimitedTextFeatureSource::~QgsDelimitedTextFeatureSource()
{
delete mSubsetExpression;
delete mSpatialIndex;
delete mFile;
}

QgsFeatureIterator QgsDelimitedTextFeatureSource::getFeatures( const QgsFeatureRequest &request )
@@ -36,10 +36,10 @@ class QgsDelimitedTextFeatureSource : public QgsAbstractFeatureSource
QgsExpressionContext mExpressionContext;
QgsRectangle mExtent;
bool mUseSpatialIndex;
QgsSpatialIndex *mSpatialIndex = nullptr;
std::unique_ptr< QgsSpatialIndex > mSpatialIndex;
bool mUseSubsetIndex;
QList<quintptr> mSubsetIndex;
QgsDelimitedTextFile *mFile = nullptr;
std::unique_ptr< QgsDelimitedTextFile > mFile;
QgsFields mFields;
int mFieldCount; // Note: this includes field count for wkt field
int mXFieldIndex;
@@ -221,11 +221,6 @@ QgsMemoryFeatureSource::QgsMemoryFeatureSource( const QgsMemoryProvider *p )
mExpressionContext.setFields( mFields );
}

QgsMemoryFeatureSource::~QgsMemoryFeatureSource()
{
delete mSpatialIndex;
}

QgsFeatureIterator QgsMemoryFeatureSource::getFeatures( const QgsFeatureRequest &request )
{
return QgsFeatureIterator( new QgsMemoryFeatureIterator( this, false, request ) );
@@ -31,14 +31,13 @@ class QgsMemoryFeatureSource : public QgsAbstractFeatureSource
{
public:
explicit QgsMemoryFeatureSource( const QgsMemoryProvider *p );
~QgsMemoryFeatureSource();

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override;

private:
QgsFields mFields;
QgsFeatureMap mFeatures;
QgsSpatialIndex *mSpatialIndex = nullptr;
std::unique_ptr< QgsSpatialIndex > mSpatialIndex;
QString mSubsetString;
QgsExpressionContext mExpressionContext;

@@ -32,7 +32,6 @@ QgsMssqlFeatureIterator::QgsMssqlFeatureIterator( QgsMssqlFeatureSource *source,
, mOrderByCompiled( false )
{
mClosed = false;
mQuery = nullptr;

mParser.IsGeography = mSource->mIsGeography;

@@ -49,7 +48,7 @@ QgsMssqlFeatureIterator::QgsMssqlFeatureIterator( QgsMssqlFeatureSource *source,
}

// create sql query
mQuery = new QSqlQuery( mDatabase );
mQuery.reset( new QSqlQuery( mDatabase ) );

// start selection
rewind();
@@ -399,8 +398,7 @@ bool QgsMssqlFeatureIterator::rewind()
if ( !result )
{
QgsDebugMsg( mQuery->lastError().text() );
delete mQuery;
mQuery = nullptr;
mQuery.reset();
if ( mDatabase.isOpen() )
mDatabase.close();

@@ -429,11 +427,7 @@ bool QgsMssqlFeatureIterator::close()
mQuery->finish();
}

if ( mQuery )
{
delete mQuery;
mQuery = nullptr;
}
mQuery.reset();

if ( mDatabase.isOpen() )
mDatabase.close();
@@ -95,7 +95,7 @@ class QgsMssqlFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsM
QSqlDatabase mDatabase;

// The current sql query
QSqlQuery *mQuery = nullptr;
std::unique_ptr< QSqlQuery > mQuery;

// The current sql statement
QString mStatement;
@@ -262,10 +262,6 @@ QgsVirtualLayerFeatureSource::QgsVirtualLayerFeatureSource( const QgsVirtualLaye
{
}

QgsVirtualLayerFeatureSource::~QgsVirtualLayerFeatureSource()
{
}

QgsFeatureIterator QgsVirtualLayerFeatureSource::getFeatures( const QgsFeatureRequest &request )
{
return QgsFeatureIterator( new QgsVirtualLayerFeatureIterator( this, false, request ) );
@@ -27,7 +27,6 @@ class QgsVirtualLayerFeatureSource : public QgsAbstractFeatureSource
{
public:
QgsVirtualLayerFeatureSource( const QgsVirtualLayerProvider *p );
~QgsVirtualLayerFeatureSource();

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override;

0 comments on commit 706b5a8

Please sign in to comment.