Skip to content

Commit

Permalink
Use unique_ptrs in provider feature sources
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 23, 2017
1 parent 8c1584f commit 706b5a8
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/providers/db2/qgsdb2featureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ QgsDb2FeatureIterator::QgsDb2FeatureIterator( QgsDb2FeatureSource *source, bool
: QgsAbstractFeatureIteratorFromSource<QgsDb2FeatureSource>( source, ownSource, request )
{
mClosed = false;
mQuery = nullptr;
mFetchCount = 0;

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

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

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

if ( mDatabase.isOpen() )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/db2/qgsdb2featureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -517,8 +517,6 @@ QgsDelimitedTextFeatureSource::QgsDelimitedTextFeatureSource( const QgsDelimited
QgsDelimitedTextFeatureSource::~QgsDelimitedTextFeatureSource()
{
delete mSubsetExpression;
delete mSpatialIndex;
delete mFile;
}

QgsFeatureIterator QgsDelimitedTextFeatureSource::getFeatures( const QgsFeatureRequest &request )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/providers/memory/qgsmemoryfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
3 changes: 1 addition & 2 deletions src/providers/memory/qgsmemoryfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 3 additions & 9 deletions src/providers/mssql/qgsmssqlfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ QgsMssqlFeatureIterator::QgsMssqlFeatureIterator( QgsMssqlFeatureSource *source,
, mOrderByCompiled( false )
{
mClosed = false;
mQuery = nullptr;

mParser.IsGeography = mSource->mIsGeography;

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

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

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

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

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

if ( mDatabase.isOpen() )
mDatabase.close();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ QgsVirtualLayerFeatureSource::QgsVirtualLayerFeatureSource( const QgsVirtualLaye
{
}

QgsVirtualLayerFeatureSource::~QgsVirtualLayerFeatureSource()
{
}

QgsFeatureIterator QgsVirtualLayerFeatureSource::getFeatures( const QgsFeatureRequest &request )
{
return QgsFeatureIterator( new QgsVirtualLayerFeatureIterator( this, false, request ) );
Expand Down
1 change: 0 additions & 1 deletion src/providers/virtual/qgsvirtuallayerfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class QgsVirtualLayerFeatureSource : public QgsAbstractFeatureSource
{
public:
QgsVirtualLayerFeatureSource( const QgsVirtualLayerProvider *p );
~QgsVirtualLayerFeatureSource();

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override;

Expand Down

0 comments on commit 706b5a8

Please sign in to comment.