Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #5672 from nyalldawson/provider_fixes2
Add tests/fixes for some provider issues
  • Loading branch information
nyalldawson committed Nov 20, 2017
2 parents af5b2a7 + 8243598 commit eb2ef6a
Show file tree
Hide file tree
Showing 24 changed files with 393 additions and 276 deletions.
7 changes: 2 additions & 5 deletions src/core/providers/memory/qgsmemoryfeatureiterator.cpp
Expand Up @@ -39,13 +39,13 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource *sour
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}

if ( !mSource->mSubsetString.isEmpty() )
{
mSubsetExpression = new QgsExpression( mSource->mSubsetString );
mSubsetExpression = qgis::make_unique< QgsExpression >( mSource->mSubsetString );
mSubsetExpression->prepare( &mSource->mExpressionContext );
}

Expand Down Expand Up @@ -82,11 +82,8 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource *sour
QgsMemoryFeatureIterator::~QgsMemoryFeatureIterator()
{
close();

delete mSubsetExpression;
}


bool QgsMemoryFeatureIterator::fetchFeature( QgsFeature &feature )
{
feature.setValid( false );
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/memory/qgsmemoryfeatureiterator.h
Expand Up @@ -75,7 +75,7 @@ class QgsMemoryFeatureIterator : public QgsAbstractFeatureIteratorFromSource<Qgs
bool mUsingFeatureIdList = false;
QList<QgsFeatureId> mFeatureIdList;
QList<QgsFeatureId>::const_iterator mFeatureIdListIterator;
QgsExpression *mSubsetExpression = nullptr;
std::unique_ptr< QgsExpression > mSubsetExpression;
QgsCoordinateTransform mTransform;

};
Expand Down
25 changes: 22 additions & 3 deletions src/core/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -275,12 +275,30 @@ QgsRectangle QgsMemoryProvider::extent() const
if ( mExtent.isEmpty() && !mFeatures.isEmpty() )
{
mExtent.setMinimal();
Q_FOREACH ( const QgsFeature &feat, mFeatures )
if ( mSubsetString.isEmpty() )
{
if ( feat.hasGeometry() )
mExtent.combineExtentWith( feat.geometry().boundingBox() );
// fast way - iterate through all features
Q_FOREACH ( const QgsFeature &feat, mFeatures )
{
if ( feat.hasGeometry() )
mExtent.combineExtentWith( feat.geometry().boundingBox() );
}
}
else
{
QgsFeature f;
QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
while ( fi.nextFeature( f ) )
{
if ( f.hasGeometry() )
mExtent.combineExtentWith( f.geometry().boundingBox() );
}
}
}
else if ( mFeatures.isEmpty() )
{
mExtent.setMinimal();
}

return mExtent;
}
Expand Down Expand Up @@ -511,6 +529,7 @@ bool QgsMemoryProvider::setSubsetString( const QString &theSQL, bool updateFeatu

mSubsetString = theSQL;
clearMinMaxCache();
mExtent.setMinimal();

emit dataChanged();
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscachedfeatureiterator.cpp
Expand Up @@ -32,7 +32,7 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
if ( !mFilterRect.isNull() )
Expand Down Expand Up @@ -118,7 +118,7 @@ QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator( QgsVectorLayerCa
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
if ( !mFilterRect.isNull() )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgscoordinatetransform.cpp
Expand Up @@ -426,6 +426,12 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r
}
}

if ( bb_rect.isNull() )
{
// something bad happened when reprojecting the filter rect... no finite points were left!
throw QgsCsException( QObject::tr( "Could not transform bounding box to target CRS" ) );
}

if ( handle180Crossover )
{
//subtract temporary addition of 360 degrees from longitudes
Expand Down
6 changes: 0 additions & 6 deletions src/core/qgsfeatureiterator.cpp
Expand Up @@ -21,12 +21,6 @@

QgsAbstractFeatureIterator::QgsAbstractFeatureIterator( const QgsFeatureRequest &request )
: mRequest( request )
, mClosed( false )
, mZombie( false )
, refs( 0 )
, mFetchedCount( 0 )
, mCompileStatus( NoCompilation )
, mUseCachedFeatures( false )
{
}

Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsfeatureiterator.h
Expand Up @@ -159,7 +159,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
QgsFeatureRequest mRequest;

//! Set to true, as soon as the iterator is closed.
bool mClosed;
bool mClosed = false;

/**
* A feature iterator may be closed already but still be serving features from the cache.
Expand All @@ -168,24 +168,24 @@ class CORE_EXPORT QgsAbstractFeatureIterator
* In such a scenario, all resources have been released (mClosed is true) but the deads
* are still alive.
*/
bool mZombie;
bool mZombie = false;

/**
* reference counting (to allow seamless copying of QgsFeatureIterator instances)
* TODO QGIS3: make this private
*/
int refs;
int refs = 0;
//! Add reference
void ref();
//! Remove reference, delete if refs == 0
void deref();
friend class QgsFeatureIterator;

//! Number of features already fetched by iterator
long mFetchedCount;
long mFetchedCount = 0;

//! Status of compilation of filter expression
CompileStatus mCompileStatus;
CompileStatus mCompileStatus = NoCompilation;

//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod &simplifyMethod );
Expand All @@ -201,7 +201,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
bool mValid = true;

private:
bool mUseCachedFeatures;
bool mUseCachedFeatures = false;
QList<QgsIndexedFeature> mCachedFeatures;
QList<QgsIndexedFeature>::ConstIterator mFeatureIterator;

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -124,7 +124,7 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
if ( !mFilterRect.isNull() )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsfeatureiterator.cpp
Expand Up @@ -50,7 +50,7 @@ QgsAfsFeatureIterator::QgsAfsFeatureIterator( QgsAfsFeatureSource *source, bool
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/db2/qgsdb2featureiterator.cpp
Expand Up @@ -45,7 +45,7 @@ QgsDb2FeatureIterator::QgsDb2FeatureIterator( QgsDb2FeatureSource *source, bool
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ QgsDelimitedTextFeatureIterator::QgsDelimitedTextFeatureIterator( QgsDelimitedTe
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}

Expand Down Expand Up @@ -536,7 +536,6 @@ QgsDelimitedTextFeatureSource::QgsDelimitedTextFeatureSource( const QgsDelimited

QgsDelimitedTextFeatureSource::~QgsDelimitedTextFeatureSource()
{
delete mSubsetExpression;
}

QgsFeatureIterator QgsDelimitedTextFeatureSource::getFeatures( const QgsFeatureRequest &request )
Expand Down
Expand Up @@ -32,7 +32,7 @@ class QgsDelimitedTextFeatureSource : public QgsAbstractFeatureSource

private:
QgsDelimitedTextProvider::GeomRepresentationType mGeomRep;
QgsExpression *mSubsetExpression = nullptr;
std::unique_ptr< QgsExpression > mSubsetExpression;
QgsExpressionContext mExpressionContext;
QgsRectangle mExtent;
bool mUseSpatialIndex;
Expand Down

0 comments on commit eb2ef6a

Please sign in to comment.