Skip to content
Permalink
Browse files
Merge pull request #4624 from nyalldawson/feature_source
QgsFeatureSource
  • Loading branch information
nyalldawson committed May 26, 2017
2 parents 13e39da + 47ffb58 commit 9cfe70c058d315d2c85367b0e88c5e997406572e
Showing with 1,046 additions and 589 deletions.
  1. +1 −0 python/core/core.sip
  2. +81 −0 python/core/qgsfeaturesource.sip
  3. +4 −1 python/core/qgsvectordataprovider.sip
  4. +11 −5 python/core/qgsvectorlayer.sip
  5. +1 −0 src/core/CMakeLists.txt
  6. +1 −0 src/core/qgsfeaturesink.h
  7. +86 −0 src/core/qgsfeaturesource.h
  8. +5 −0 src/core/qgsvectordataprovider.cpp
  9. +8 −5 src/core/qgsvectordataprovider.h
  10. +5 −0 src/core/qgsvectorlayer.cpp
  11. +8 −5 src/core/qgsvectorlayer.h
  12. +12 −0 src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
  13. +13 −0 src/providers/ogr/qgsogrfeatureiterator.cpp
  14. +13 −0 src/providers/postgres/qgspostgresfeatureiterator.cpp
  15. +12 −1 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  16. +11 −0 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
  17. +15 −0 src/providers/wfs/qgswfsfeatureiterator.cpp
  18. +605 −0 tests/src/python/featuresourcetestbase.py
  19. +62 −542 tests/src/python/providertestbase.py
  20. +1 −1 tests/src/python/test_provider_db2.py
  21. +3 −3 tests/src/python/test_provider_memory.py
  22. +1 −1 tests/src/python/test_provider_mssql.py
  23. +3 −3 tests/src/python/test_provider_oracle.py
  24. +15 −12 tests/src/python/test_provider_postgres.py
  25. +5 −2 tests/src/python/test_provider_shapefile.py
  26. +5 −2 tests/src/python/test_provider_spatialite.py
  27. +1 −1 tests/src/python/test_provider_virtual.py
  28. +5 −1 tests/src/python/test_provider_wfs.py
  29. +2 −2 tests/src/python/test_qgsdelimitedtextprovider.py
  30. +51 −2 tests/src/python/test_qgsvectorlayer.py
@@ -56,6 +56,7 @@
%Include qgsfeatureiterator.sip
%Include qgsfeaturerequest.sip
%Include qgsfeaturesink.sip
%Include qgsfeaturesource.sip
%Include qgsfeedback.sip
%Include qgsfield.sip
%Include qgsfieldconstraints.sip
@@ -0,0 +1,81 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfeaturesource.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsFeatureSource
{
%Docstring
An interface for objects which provide features via a getFeatures method.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsfeaturesource.h"
%End
public:

virtual ~QgsFeatureSource();

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const = 0;
%Docstring
Returns an iterator for the features in the source.
An optional ``request`` can be used to optimise the returned
iterator, eg by restricting the returned attributes or geometry.
:rtype: QgsFeatureIterator
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const = 0;
%Docstring
Returns the coordinate reference system for features in the source.
:rtype: QgsCoordinateReferenceSystem
%End

virtual QgsFields fields() const = 0;
%Docstring
Returns the fields associated with features in the source.
:rtype: QgsFields
%End

virtual QgsWkbTypes::Type wkbType() const = 0;
%Docstring
Returns the geometry type for features returned by this source.
:rtype: QgsWkbTypes.Type
%End


int __len__() const;
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
:rtype: int
%End
%MethodCode
sipRes = sipCpp->featureCount();
%End

virtual long featureCount() const = 0;
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
:rtype: long
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfeaturesource.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -13,7 +13,7 @@ typedef QHash<int, QString> QgsAttrPalIndexNameHash;



class QgsVectorDataProvider : QgsDataProvider, QgsFeatureSink
class QgsVectorDataProvider : QgsDataProvider, QgsFeatureSink, QgsFeatureSource
{
%Docstring
This is the base class for vector data providers.
@@ -124,6 +124,9 @@ Bitmask of all provider's editing capabilities
:rtype: QgsFields
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const;


virtual QString dataComment() const;
%Docstring
Return a short comment for the data that this provider is
@@ -17,7 +17,7 @@ typedef QList<int> QgsAttributeList;
typedef QSet<int> QgsAttributeIds;


class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsFeatureSink
class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsFeatureSink, QgsFeatureSource
{
%Docstring
Represents a vector layer which manages a vector based data sets.
@@ -685,7 +685,8 @@ Returns true if this is a geometry layer and false in case of NoGeometry (table
:rtype: bool
%End

QgsWkbTypes::Type wkbType() const;
virtual QgsWkbTypes::Type wkbType() const;

%Docstring
Returns the WKBType or WKBUnknown in case of error
:rtype: QgsWkbTypes.Type
@@ -697,6 +698,9 @@ Return the provider type for this layer
:rtype: str
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const;


virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
%Docstring
Reads vector layer specific state from project file Dom node.
@@ -890,7 +894,8 @@ Return the provider type for this layer
:rtype: str
%End

QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const;
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const;

%Docstring
Query the layer for features specified in request.
\param request feature request describing parameters of features to return
@@ -1103,7 +1108,7 @@ Return the extent of the layer
:rtype: QgsRectangle
%End

QgsFields fields() const;
virtual QgsFields fields() const;
%Docstring
Returns the list of fields of this layer.
This also includes fields which have not yet been saved to the provider.
@@ -1156,7 +1161,8 @@ Returns list of attributes making up the primary key
:rtype: long
%End

long featureCount() const;
virtual long featureCount() const;

%Docstring
Returns feature count including changes which have not yet been committed
If you need only the count of committed features call this method on this layer's provider.
@@ -753,6 +753,7 @@ SET(QGIS_CORE_HDRS
qgsfeatureiterator.h
qgsfeaturerequest.h
qgsfeaturesink.h
qgsfeaturesource.h
qgsfeaturestore.h
qgsfieldformatter.h
qgsfield_p.h
@@ -94,5 +94,6 @@ class CORE_EXPORT QgsProxyFeatureSink : public QgsFeatureSink
QgsFeatureSink *mSink;
};

Q_DECLARE_METATYPE( QgsFeatureSink * )

#endif // QGSFEATURESINK_H
@@ -0,0 +1,86 @@
/***************************************************************************
qgsfeaturesource.h
----------------
begin : May 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSFEATURESOURCE_H
#define QGSFEATURESOURCE_H

#include "qgis_core.h"
#include "qgis.h"

class QgsFeatureIterator;
class QgsFeatureRequest;
class QgsCoordinateReferenceSystem;
class QgsFields;

/**
* \class QgsFeatureSource
* \ingroup core
* An interface for objects which provide features via a getFeatures method.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsFeatureSource
{
public:

virtual ~QgsFeatureSource() = default;

/**
* Returns an iterator for the features in the source.
* An optional \a request can be used to optimise the returned
* iterator, eg by restricting the returned attributes or geometry.
*/
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const = 0;

/**
* Returns the coordinate reference system for features in the source.
*/
virtual QgsCoordinateReferenceSystem sourceCrs() const = 0;

/**
* Returns the fields associated with features in the source.
*/
virtual QgsFields fields() const = 0;

/**
* Returns the geometry type for features returned by this source.
*/
virtual QgsWkbTypes::Type wkbType() const = 0;

#ifdef SIP_RUN

/**
* Returns the number of features contained in the source, or -1
* if the feature count is unknown.
*/
int __len__() const;
% MethodCode
sipRes = sipCpp->featureCount();
% End
#endif

/**
* Returns the number of features contained in the source, or -1
* if the feature count is unknown.
*/
virtual long featureCount() const = 0;

};

Q_DECLARE_METATYPE( QgsFeatureSource * )

#endif // QGSFEATURESOURCE_H
@@ -47,6 +47,11 @@ QString QgsVectorDataProvider::storageType() const
return QStringLiteral( "Generic vector file" );
}

QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
{
return crs();
}

QString QgsVectorDataProvider::dataComment() const
{
return QString();
@@ -31,6 +31,7 @@ class QTextCodec;
#include "qgsmaplayerdependency.h"
#include "qgsrelation.h"
#include "qgsfeaturesink.h"
#include "qgsfeaturesource.h"

typedef QList<int> QgsAttributeList SIP_SKIP;
typedef QSet<int> QgsAttributeIds SIP_SKIP;
@@ -50,7 +51,7 @@ class QgsFeedback;
*
*
*/
class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeatureSink
class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeatureSink, public QgsFeatureSource
{
Q_OBJECT

@@ -139,23 +140,25 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
* \param request feature request describing parameters of features to return
* \returns iterator for matching features from provider
*/
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const = 0;
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override = 0;

/**
* Returns the geometry type which is returned by this layer
*/
virtual QgsWkbTypes::Type wkbType() const = 0;
virtual QgsWkbTypes::Type wkbType() const override = 0;

/**
* Number of features in the layer
* \returns long containing number of features
*/
virtual long featureCount() const = 0;
virtual long featureCount() const override = 0;

/**
* Returns the fields associated with this data provider.
*/
virtual QgsFields fields() const = 0;
virtual QgsFields fields() const override = 0;

QgsCoordinateReferenceSystem sourceCrs() const override;

/**
* Return a short comment for the data that this provider is
@@ -309,6 +309,11 @@ QString QgsVectorLayer::providerType() const
return mProviderKey;
}

QgsCoordinateReferenceSystem QgsVectorLayer::sourceCrs() const
{
return crs();
}

void QgsVectorLayer::reload()
{
if ( mDataProvider )
@@ -31,6 +31,7 @@
#include "qgsmaplayer.h"
#include "qgsfeature.h"
#include "qgsfeaturerequest.h"
#include "qgsfeaturesource.h"
#include "qgsfields.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorsimplifymethod.h"
@@ -346,7 +347,7 @@ typedef QSet<int> QgsAttributeIds;
* TODO QGIS3: Remove virtual from non-inherited methods (like isModified)
* \see QgsVectorLayerUtils()
*/
class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionContextGenerator, public QgsFeatureSink
class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionContextGenerator, public QgsFeatureSink, public QgsFeatureSource
{
Q_OBJECT

@@ -690,11 +691,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
bool hasGeometryType() const;

//! Returns the WKBType or WKBUnknown in case of error
QgsWkbTypes::Type wkbType() const;
QgsWkbTypes::Type wkbType() const override;

//! Return the provider type for this layer
QString providerType() const;

QgsCoordinateReferenceSystem sourceCrs() const override;

/** Reads vector layer specific state from project file Dom node.
* \note Called by QgsMapLayer::readXml().
*/
@@ -859,7 +862,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param request feature request describing parameters of features to return
* \returns iterator for matching features from provider
*/
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const;
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;

/**
* Query the layer for features matching a given expression.
@@ -1082,7 +1085,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*
* \returns A list of fields
*/
inline QgsFields fields() const { return mFields; }
inline QgsFields fields() const override { return mFields; }

/**
* Returns the list of fields of this layer.
@@ -1124,7 +1127,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* Returns feature count including changes which have not yet been committed
* If you need only the count of committed features call this method on this layer's provider.
*/
long featureCount() const;
long featureCount() const override;

/** Make layer read-only (editing disabled) or not
* \returns false if the layer is in editing yet

0 comments on commit 9cfe70c

Please sign in to comment.