Skip to content

Commit

Permalink
Merge pull request #4624 from nyalldawson/feature_source
Browse files Browse the repository at this point in the history
QgsFeatureSource
  • Loading branch information
nyalldawson committed May 26, 2017
2 parents 13e39da + 47ffb58 commit 9cfe70c
Show file tree
Hide file tree
Showing 30 changed files with 1,046 additions and 589 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions python/core/qgsfeaturesource.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 *
************************************************************************/
5 changes: 4 additions & 1 deletion python/core/qgsvectordataprovider.sip
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -753,6 +753,7 @@ SET(QGIS_CORE_HDRS
qgsfeatureiterator.h
qgsfeaturerequest.h
qgsfeaturesink.h
qgsfeaturesource.h
qgsfeaturestore.h
qgsfieldformatter.h
qgsfield_p.h
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsfeaturesink.h
Expand Up @@ -94,5 +94,6 @@ class CORE_EXPORT QgsProxyFeatureSink : public QgsFeatureSink
QgsFeatureSink *mSink;
};

Q_DECLARE_METATYPE( QgsFeatureSink * )

#endif // QGSFEATURESINK_H
86 changes: 86 additions & 0 deletions src/core/qgsfeaturesource.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
5 changes: 5 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Expand Up @@ -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();
Expand Down
13 changes: 8 additions & 5 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -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;
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -309,6 +309,11 @@ QString QgsVectorLayer::providerType() const
return mProviderKey;
}

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

void QgsVectorLayer::reload()
{
if ( mDataProvider )
Expand Down
13 changes: 8 additions & 5 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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().
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cfe70c

Please sign in to comment.