QgsVectorLayerJoinBuffer class

Manages joined fields for a vector layer.

Base classes

class QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.

Public static functions

static auto joinSubsetIndices(QgsVectorLayer* joinLayer, const QStringList& joinFieldsSubset) -> QVector<int>
Returns a vector of indices for use in join based on field names from the layer.

Public functions

auto addFeatures(QgsFeatureList& features, QgsFeatureSink::Flags flags = nullptr) -> bool override
Adds a list of features in joined layers.
auto addJoin(const QgsVectorLayerJoinInfo& joinInfo) -> bool
Joins another vector layer to this layer.
auto changeAttributeValue(QgsFeatureId fid, int field, const QVariant& newValue, const QVariant& oldValue = QVariant()) -> bool
Changes attribute value in joined layers.
auto changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap& newValues, const QgsAttributeMap& oldValues = QgsAttributeMap()) -> bool
Changes attributes' values in joined layers.
auto clone() const -> QgsVectorLayerJoinBuffer*
Create a copy of the join buffer.
auto containsJoins() const -> bool
Quick way to test if there is any join at all.
void createJoinCaches()
Calls cacheJoinLayer() for all vector joins.
auto deleteFeature(QgsFeatureId fid) const -> bool
Deletes a feature from joined layers.
auto deleteFeatures(const QgsFeatureIds& fids) const -> bool
Deletes a list of features from joined layers.
auto isAuxiliaryJoin(const QgsVectorLayerJoinInfo& info) const -> bool
Returns true if the join information is about auxiliary layer, false otherwise.
auto joinedFeatureOf(const QgsVectorLayerJoinInfo* info, const QgsFeature& feature) const -> QgsFeature
Returns the joined feature corresponding to the feature.
auto joinedFieldsOffset(const QgsVectorLayerJoinInfo* info, const QgsFields& fields) -> int
Find out what is the first index of the join within fields.
auto joinForFieldIndex(int index, const QgsFields& fields, int& sourceFieldIndex) const -> const QgsVectorLayerJoinInfo*
Finds the vector join for a layer field index.
auto joinsWhereFieldIsId(const QgsField& field) const -> QList<const QgsVectorLayerJoinInfo*>
Returns joins where the field of a target layer is considered as an id.
void readXml(const QDomNode& layer_node)
Reads joins from project file.
auto removeJoin(const QString& joinLayerId) -> bool
Removes a vector layer join.
void resolveReferences(QgsProject* project)
Resolves layer IDs of joined layers using given project's available layers.
auto targetedFeatureOf(const QgsVectorLayerJoinInfo* info, const QgsFeature& feature) const -> QgsFeature
Returns the targeted feature corresponding to the joined feature.
void updateFields(QgsFields& fields)
Updates field map with joined attributes.
void writeXml(QDomNode& layer_node, QDomDocument& document) const
Saves mVectorJoins to xml under the layer node.

Signals

void joinedFieldsChanged()
Emitted whenever the list of joined fields changes (e.g.

Function documentation

static QVector<int> QgsVectorLayerJoinBuffer::joinSubsetIndices(QgsVectorLayer* joinLayer, const QStringList& joinFieldsSubset)

Returns a vector of indices for use in join based on field names from the layer.

bool QgsVectorLayerJoinBuffer::addFeatures(QgsFeatureList& features, QgsFeatureSink::Flags flags = nullptr) override

Adds a list of features in joined layers.

Parameters
features The list of features added in the target layer
flags Unused parameter
Returns false if an error happened, true otherwise

Features given in parameter are those 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.

bool QgsVectorLayerJoinBuffer::addJoin(const QgsVectorLayerJoinInfo& joinInfo)

Joins another vector layer to this layer.

Parameters
joinInfo join object containing join layer id, target and source field
Returns (since 2.6) whether the join was successfully added

bool QgsVectorLayerJoinBuffer::changeAttributeValue(QgsFeatureId fid, int field, const QVariant& newValue, const QVariant& oldValue = QVariant())

Changes attribute value in joined layers.

Parameters
fid The feature id
field The field to update
newValue The new value of the attribute
oldValue The old value of the attribute
Returns false if an error happened, true otherwise

The feature id given in parameter is the one added in target layer. If the corresponding joined feature does not exist in a joined layer, then it's automatically created if its fields are not empty.

bool QgsVectorLayerJoinBuffer::changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap& newValues, const QgsAttributeMap& oldValues = QgsAttributeMap())

Changes attributes' values in joined layers.

Parameters
fid The feature id
newValues The new values for attributes
oldValues The old values for attributes
Returns false if an error happened, true otherwise

The feature id given in parameter is the one added in target layer. If the corresponding joined feature does not exist in a joined layer, then it's automatically created if its fields are not empty.

QgsVectorLayerJoinBuffer* QgsVectorLayerJoinBuffer::clone() const

Create a copy of the join buffer.

bool QgsVectorLayerJoinBuffer::deleteFeature(QgsFeatureId fid) const

Deletes a feature from joined layers.

Parameters
fid The feature id from the target layer to delete
Returns false if an error happened, true otherwise

The feature id given in parameter is the one coming from the target layer.

bool QgsVectorLayerJoinBuffer::deleteFeatures(const QgsFeatureIds& fids) const

Deletes a list of features from joined layers.

Parameters
fids Feature ids from the target layer to delete
Returns false if an error happened, true otherwise

Feature ids given in a parameter are those coming from the target layer.

bool QgsVectorLayerJoinBuffer::isAuxiliaryJoin(const QgsVectorLayerJoinInfo& info) const

Returns true if the join information is about auxiliary layer, false otherwise.

Parameters
info The join information
Returns true if the join information is about auxiliary layer, false otherwise

QgsFeature QgsVectorLayerJoinBuffer::joinedFeatureOf(const QgsVectorLayerJoinInfo* info, const QgsFeature& feature) const

Returns the joined feature corresponding to the feature.

Parameters
info the vector join information
feature the feature of the target layer

int QgsVectorLayerJoinBuffer::joinedFieldsOffset(const QgsVectorLayerJoinInfo* info, const QgsFields& fields)

Find out what is the first index of the join within fields.

Returns -1 if join is not present

const QgsVectorLayerJoinInfo* QgsVectorLayerJoinBuffer::joinForFieldIndex(int index, const QgsFields& fields, int& sourceFieldIndex) const

Finds the vector join for a layer field index.

Parameters
index this layers attribute index
fields fields of the vector layer (including joined fields)
sourceFieldIndex Output: field's index in source layer
Returns the vector layer join info

QList<const QgsVectorLayerJoinInfo*> QgsVectorLayerJoinBuffer::joinsWhereFieldIsId(const QgsField& field) const

Returns joins where the field of a target layer is considered as an id.

Parameters
field the field of a target layer
Returns a list of vector joins

void QgsVectorLayerJoinBuffer::readXml(const QDomNode& layer_node)

Reads joins from project file.

Does not resolve layer IDs to layers - call resolveReferences() afterwards

bool QgsVectorLayerJoinBuffer::removeJoin(const QString& joinLayerId)

Removes a vector layer join.

Returns true if join was found and successfully removed

void QgsVectorLayerJoinBuffer::resolveReferences(QgsProject* project)

Resolves layer IDs of joined layers using given project's available layers.

QgsFeature QgsVectorLayerJoinBuffer::targetedFeatureOf(const QgsVectorLayerJoinInfo* info, const QgsFeature& feature) const

Returns the targeted feature corresponding to the joined feature.

Parameters
info the vector join information
feature the feature of the joined layer

void QgsVectorLayerJoinBuffer::updateFields(QgsFields& fields)

Updates field map with joined attributes.

Parameters
fields map to append joined attributes

void QgsVectorLayerJoinBuffer::joinedFieldsChanged() signal

Emitted whenever the list of joined fields changes (e.g.

added join or joined layer's fields change)