From 1fb88a778c5a72450fa14eb7cd0d576e9cf91dce Mon Sep 17 00:00:00 2001 From: Blottiere Paul Date: Fri, 25 Aug 2017 07:56:48 +0100 Subject: [PATCH] QgsVectorLayerJoinBuffer inherits from QgsFeatureSink --- python/core/qgsvectorlayerjoinbuffer.sip | 22 ++++------------------ src/core/qgsvectorlayerjoinbuffer.cpp | 10 ++-------- src/core/qgsvectorlayerjoinbuffer.h | 22 ++++------------------ 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/python/core/qgsvectorlayerjoinbuffer.sip b/python/core/qgsvectorlayerjoinbuffer.sip index 0484c3eab3e..cd182d3f616 100644 --- a/python/core/qgsvectorlayerjoinbuffer.sip +++ b/python/core/qgsvectorlayerjoinbuffer.sip @@ -14,7 +14,7 @@ typedef QList< QgsVectorLayerJoinInfo > QgsVectorJoinList; -class QgsVectorLayerJoinBuffer : QObject +class QgsVectorLayerJoinBuffer : QObject, QgsFeatureSink { %Docstring Manages joined fields for a vector layer* @@ -132,23 +132,8 @@ Quick way to test if there is any join at all :rtype: QgsVectorLayerJoinBuffer %End - bool addFeature( const QgsFeature &feature ) const; -%Docstring - Adds a feature in joined layers. The feature given in parameter is the - one added in target layer. If a corresponding joined feature yet exists - in a joined layer, then this feature is just updated. Note that if a - corresponding joined feature has only empty fields, then it's not - created nor added. + virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 ); - \param feature The feature added in the target layer. - - :return: false if an error happened, true otherwise - -.. versionadded:: 3.0 - :rtype: bool -%End - - bool addFeatures( const QgsFeatureList &features ) const; %Docstring Adds a list of features in joined layers. Features given in parameter are those added in target layer. If a corresponding joined feature yet @@ -157,6 +142,7 @@ Quick way to test if there is any join at all created nor added. \param features The list of features added in the target layer + \param flags Unused parameter :return: false if an error happened, true otherwise @@ -164,7 +150,7 @@ Quick way to test if there is any join at all :rtype: bool %End - bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() ) const; + bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() ); %Docstring Changes attribute value in joined layers. The feature id given in parameter is the one added in target layer. If the corresponding joined diff --git a/src/core/qgsvectorlayerjoinbuffer.cpp b/src/core/qgsvectorlayerjoinbuffer.cpp index 1f1d8134872..cdc566d5c71 100644 --- a/src/core/qgsvectorlayerjoinbuffer.cpp +++ b/src/core/qgsvectorlayerjoinbuffer.cpp @@ -135,7 +135,6 @@ void QgsVectorLayerJoinBuffer::cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo QgsFeatureRequest request; request.setFlags( QgsFeatureRequest::NoGeometry ); - // maybe user requested just a subset of layer's attributes // so we do not have to cache everything bool hasSubset = joinInfo.joinFieldNamesSubset(); @@ -518,12 +517,7 @@ void QgsVectorLayerJoinBuffer::connectJoinedLayer( QgsVectorLayer *vl ) connect( vl, &QgsVectorLayer::willBeDeleted, this, &QgsVectorLayerJoinBuffer::joinedLayerWillBeDeleted, Qt::UniqueConnection ); } -bool QgsVectorLayerJoinBuffer::addFeature( const QgsFeature &feature ) const -{ - return addFeatures( QgsFeatureList() << feature ); -} - -bool QgsVectorLayerJoinBuffer::addFeatures( const QgsFeatureList &features ) const +bool QgsVectorLayerJoinBuffer::addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags ) { if ( !containsJoins() ) return false; @@ -598,7 +592,7 @@ bool QgsVectorLayerJoinBuffer::addFeatures( const QgsFeatureList &features ) con return true; } -bool QgsVectorLayerJoinBuffer::changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue ) const +bool QgsVectorLayerJoinBuffer::changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue ) { if ( mLayer->fields().fieldOrigin( field ) != QgsFields::OriginJoin ) return false; diff --git a/src/core/qgsvectorlayerjoinbuffer.h b/src/core/qgsvectorlayerjoinbuffer.h index e38dcefe704..ac67767a55e 100644 --- a/src/core/qgsvectorlayerjoinbuffer.h +++ b/src/core/qgsvectorlayerjoinbuffer.h @@ -31,7 +31,7 @@ typedef QList< QgsVectorLayerJoinInfo > QgsVectorJoinList; /** \ingroup core * Manages joined fields for a vector layer*/ -class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject +class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject, public QgsFeatureSink { Q_OBJECT public: @@ -109,21 +109,6 @@ class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject //! \since QGIS 2.6 QgsVectorLayerJoinBuffer *clone() const SIP_FACTORY; - /** - * Adds a feature in joined layers. The feature given in parameter is the - * one added in target layer. If a corresponding joined feature yet exists - * in a joined layer, then this feature is just updated. Note that if a - * corresponding joined feature has only empty fields, then it's not - * created nor added. - * - * \param feature The feature added in the target layer. - * - * \returns false if an error happened, true otherwise - * - * \since QGIS 3.0 - */ - bool addFeature( const QgsFeature &feature ) const; - /** * Adds a list of features in joined layers. Features given in parameter * are those added in target layer. If a corresponding joined feature yet @@ -132,12 +117,13 @@ class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject * created nor added. * * \param features The list of features added in the target layer + * \param flags Unused parameter * * \returns false if an error happened, true otherwise * * \since QGIS 3.0 */ - bool addFeatures( const QgsFeatureList &features ) const; + bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 ) override; /** * Changes attribute value in joined layers. The feature id given in @@ -154,7 +140,7 @@ class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject * * \since QGIS 3.0 */ - bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() ) const; + bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() ); /** * Deletes a feature from joined layers. The feature id given in