Skip to content

Commit

Permalink
QgsVectorLayerJoinBuffer inherits from QgsFeatureSink
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Aug 28, 2017
1 parent f27764d commit 1fb88a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 44 deletions.
22 changes: 4 additions & 18 deletions python/core/qgsvectorlayerjoinbuffer.sip
Expand Up @@ -14,7 +14,7 @@
typedef QList< QgsVectorLayerJoinInfo > QgsVectorJoinList;


class QgsVectorLayerJoinBuffer : QObject
class QgsVectorLayerJoinBuffer : QObject, QgsFeatureSink
{
%Docstring
Manages joined fields for a vector layer*
Expand Down Expand Up @@ -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.

\param feature The feature added in the target layer.

:return: false if an error happened, true otherwise

.. versionadded:: 3.0
:rtype: bool
%End
virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 );

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
Expand All @@ -157,14 +142,15 @@ 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

.. versionadded:: 3.0
: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
Expand Down
10 changes: 2 additions & 8 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 4 additions & 18 deletions src/core/qgsvectorlayerjoinbuffer.h
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1fb88a7

Please sign in to comment.