Skip to content
Permalink
Browse files

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 eb2ef6a68140da0e021aa1c9f4f99070b2123731
@@ -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 );
}

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

delete mSubsetExpression;
}


bool QgsMemoryFeatureIterator::fetchFeature( QgsFeature &feature )
{
feature.setValid( false );
@@ -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;

};
@@ -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;
}
@@ -511,6 +529,7 @@ bool QgsMemoryProvider::setSubsetString( const QString &theSQL, bool updateFeatu

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

emit dataChanged();
return true;
@@ -32,7 +32,7 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
if ( !mFilterRect.isNull() )
@@ -118,7 +118,7 @@ QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator( QgsVectorLayerCa
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
if ( !mFilterRect.isNull() )
@@ -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
@@ -21,12 +21,6 @@

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

@@ -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.
@@ -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 );
@@ -201,7 +201,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
bool mValid = true;

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

@@ -124,7 +124,7 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
if ( !mFilterRect.isNull() )
@@ -50,7 +50,7 @@ QgsAfsFeatureIterator::QgsAfsFeatureIterator( QgsAfsFeatureSource *source, bool
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}
}
@@ -45,7 +45,7 @@ QgsDb2FeatureIterator::QgsDb2FeatureIterator( QgsDb2FeatureSource *source, bool
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
close();
return;
}

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

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

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

QgsFeatureIterator QgsDelimitedTextFeatureSource::getFeatures( const QgsFeatureRequest &request )
@@ -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;

0 comments on commit eb2ef6a

Please sign in to comment.
You can’t perform that action at this time.