QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
Signals | Public Member Functions | Static Public Member Functions | List of all members
QgsVectorLayerJoinBuffer Class Reference

Manages joined fields for a vector layer. More...

#include <qgsvectorlayerjoinbuffer.h>

Inheritance diagram for QgsVectorLayerJoinBuffer:
Inheritance graph
[legend]

Signals

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

Public Member Functions

 QgsVectorLayerJoinBuffer (QgsVectorLayer *layer=nullptr)
 
bool addFeatures (QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
 Adds a list of features in joined layers.
 
bool addJoin (const QgsVectorLayerJoinInfo &joinInfo)
 Joins another vector layer to this layer.
 
bool changeAttributeValue (QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
 Changes attribute value in joined layers.
 
bool changeAttributeValues (QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
 Changes attributes' values in joined layers.
 
QgsVectorLayerJoinBufferclone () const
 Create a copy of the join buffer.
 
bool containsJoins () const
 Quick way to test if there is any join at all.
 
void createJoinCaches ()
 Calls cacheJoinLayer() for all vector joins.
 
bool deleteFeature (QgsFeatureId fid, QgsVectorLayer::DeleteContext *context=nullptr) const
 Deletes a feature from joined layers.
 
bool deleteFeatures (const QgsFeatureIds &fids, QgsVectorLayer::DeleteContext *context=nullptr) const
 Deletes a list of features from joined layers.
 
bool isAuxiliaryJoin (const QgsVectorLayerJoinInfo &info) const
 Returns true if the join information is about auxiliary layer, false otherwise.
 
QgsFeature joinedFeatureOf (const QgsVectorLayerJoinInfo *info, const QgsFeature &feature) const
 Returns the joined feature corresponding to the feature.
 
int joinedFieldsOffset (const QgsVectorLayerJoinInfo *info, const QgsFields &fields)
 Find out what is the first index of the join within fields.
 
const QgsVectorLayerJoinInfojoinForFieldIndex (int index, const QgsFields &fields, int &sourceFieldIndex) const
 Finds the vector join for a layer field index.
 
QList< const QgsVectorLayerJoinInfo * > joinsWhereFieldIsId (const QgsField &field) const
 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.
 
bool removeJoin (const QString &joinLayerId)
 Removes a vector layer join.
 
void resolveReferences (QgsProject *project)
 Resolves layer IDs of joined layers using given project's available layers.
 
QgsFeature targetedFeatureOf (const QgsVectorLayerJoinInfo *info, const QgsFeature &feature) const
 Returns the targeted feature corresponding to the joined feature.
 
void updateFields (QgsFields &fields)
 Updates field map with joined attributes.
 
const QgsVectorJoinListvectorJoins () const
 
void writeXml (QDomNode &layer_node, QDomDocument &document) const
 Saves mVectorJoins to xml under the layer node.
 
- Public Member Functions inherited from QgsFeatureSink
virtual ~QgsFeatureSink ()=default
 
virtual bool addFeature (QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
 Adds a single feature to the sink.
 
virtual bool addFeatures (QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
 Adds all features from the specified iterator to the sink.
 
virtual bool flushBuffer ()
 Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination.
 
virtual QString lastError () const
 Returns the most recent error encountered by the sink, e.g.
 

Static Public Member Functions

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

Additional Inherited Members

- Public Types inherited from QgsFeatureSink
enum  Flag { FastInsert = 1 << 1 , RollBackOnErrors = 1 << 2 }
 Flags controlling how features are added to a sink. More...
 
typedef QFlags< FlagFlags
 
enum  SinkFlag { RegeneratePrimaryKey = 1 << 1 }
 Flags that can be set on a QgsFeatureSink. More...
 
typedef QFlags< SinkFlagSinkFlags
 

Detailed Description

Manages joined fields for a vector layer.

Definition at line 37 of file qgsvectorlayerjoinbuffer.h.

Constructor & Destructor Documentation

◆ QgsVectorLayerJoinBuffer()

QgsVectorLayerJoinBuffer::QgsVectorLayerJoinBuffer ( QgsVectorLayer layer = nullptr)

Definition at line 29 of file qgsvectorlayerjoinbuffer.cpp.

Member Function Documentation

◆ addFeatures()

bool QgsVectorLayerJoinBuffer::addFeatures ( QgsFeatureList features,
QgsFeatureSink::Flags  flags = QgsFeatureSink::Flags() 
)
overridevirtual

Adds a list of features in joined layers.

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.

Parameters
featuresThe list of features added in the target layer
flagsUnused parameter
Returns
false if an error happened, true otherwise

Implements QgsFeatureSink.

Definition at line 560 of file qgsvectorlayerjoinbuffer.cpp.

◆ addJoin()

bool QgsVectorLayerJoinBuffer::addJoin ( const QgsVectorLayerJoinInfo joinInfo)

Joins another vector layer to this layer.

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

Definition at line 65 of file qgsvectorlayerjoinbuffer.cpp.

◆ changeAttributeValue()

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

Changes attribute value in joined layers.

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.

Parameters
fidThe feature id
fieldThe field to update
newValueThe new value of the attribute
oldValueThe old value of the attribute
Returns
false if an error happened, true otherwise

Definition at line 647 of file qgsvectorlayerjoinbuffer.cpp.

◆ changeAttributeValues()

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

Changes attributes' values in joined layers.

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.

Parameters
fidThe feature id
newValuesThe new values for attributes
oldValuesThe old values for attributes
Returns
false if an error happened, true otherwise

Definition at line 675 of file qgsvectorlayerjoinbuffer.cpp.

◆ clone()

QgsVectorLayerJoinBuffer * QgsVectorLayerJoinBuffer::clone ( ) const

Create a copy of the join buffer.

Definition at line 502 of file qgsvectorlayerjoinbuffer.cpp.

◆ containsJoins()

bool QgsVectorLayerJoinBuffer::containsJoins ( ) const
inline

Quick way to test if there is any join at all.

Definition at line 80 of file qgsvectorlayerjoinbuffer.h.

◆ createJoinCaches()

void QgsVectorLayerJoinBuffer::createJoinCaches ( )

Calls cacheJoinLayer() for all vector joins.

Definition at line 283 of file qgsvectorlayerjoinbuffer.cpp.

◆ deleteFeature()

bool QgsVectorLayerJoinBuffer::deleteFeature ( QgsFeatureId  fid,
QgsVectorLayer::DeleteContext context = nullptr 
) const

Deletes a feature from joined layers.

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

Parameters
fidThe feature id from the target layer to delete
contextThe chain of features which will be deleted for feedback and to avoid infinite recursions. Can be nullptr.
Returns
false if an error happened, true otherwise

Definition at line 694 of file qgsvectorlayerjoinbuffer.cpp.

◆ deleteFeatures()

bool QgsVectorLayerJoinBuffer::deleteFeatures ( const QgsFeatureIds fids,
QgsVectorLayer::DeleteContext context = nullptr 
) const

Deletes a list of features from joined layers.

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

Parameters
fidsFeature ids from the target layer to delete
contextThe chain of features who will be deleted for feedback and to avoid infinite recursions. Can be nullptr.
Returns
false if an error happened, true otherwise

Definition at line 699 of file qgsvectorlayerjoinbuffer.cpp.

◆ isAuxiliaryJoin()

bool QgsVectorLayerJoinBuffer::isAuxiliaryJoin ( const QgsVectorLayerJoinInfo info) const

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

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

Definition at line 722 of file qgsvectorlayerjoinbuffer.cpp.

◆ joinedFeatureOf()

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

Returns the joined feature corresponding to the feature.

Parameters
infothe vector join information
featurethe feature of the target layer

Definition at line 458 of file qgsvectorlayerjoinbuffer.cpp.

◆ joinedFieldsChanged

void QgsVectorLayerJoinBuffer::joinedFieldsChanged ( )
signal

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

added join or joined layer's fields change)

◆ joinedFieldsOffset()

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

Definition at line 406 of file qgsvectorlayerjoinbuffer.cpp.

◆ joinForFieldIndex()

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

Finds the vector join for a layer field index.

Parameters
indexthis layers attribute index
fieldsfields of the vector layer (including joined fields)
sourceFieldIndexOutput: field's index in source layer
Returns
the vector layer join info

Definition at line 426 of file qgsvectorlayerjoinbuffer.cpp.

◆ joinSubsetIndices() [1/2]

QVector< int > QgsVectorLayerJoinBuffer::joinSubsetIndices ( const QgsFields joinLayerFields,
const QStringList &  joinFieldsSubset 
)
static

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

Since
QGIS 3.20

Definition at line 213 of file qgsvectorlayerjoinbuffer.cpp.

◆ joinSubsetIndices() [2/2]

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

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

Definition at line 208 of file qgsvectorlayerjoinbuffer.cpp.

◆ joinsWhereFieldIsId()

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

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

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

Definition at line 441 of file qgsvectorlayerjoinbuffer.cpp.

◆ readXml()

void QgsVectorLayerJoinBuffer::readXml ( const QDomNode &  layer_node)

Reads joins from project file.

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

Definition at line 344 of file qgsvectorlayerjoinbuffer.cpp.

◆ removeJoin()

bool QgsVectorLayerJoinBuffer::removeJoin ( const QString &  joinLayerId)

Removes a vector layer join.

Returns
true if join was found and successfully removed

Definition at line 105 of file qgsvectorlayerjoinbuffer.cpp.

◆ resolveReferences()

void QgsVectorLayerJoinBuffer::resolveReferences ( QgsProject project)

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

Definition at line 386 of file qgsvectorlayerjoinbuffer.cpp.

◆ targetedFeatureOf()

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

Returns the targeted feature corresponding to the joined feature.

Parameters
infothe vector join information
featurethe feature of the joined layer

Definition at line 482 of file qgsvectorlayerjoinbuffer.cpp.

◆ updateFields()

void QgsVectorLayerJoinBuffer::updateFields ( QgsFields fields)

Updates field map with joined attributes.

Parameters
fieldsmap to append joined attributes

Definition at line 233 of file qgsvectorlayerjoinbuffer.cpp.

◆ vectorJoins()

const QgsVectorJoinList & QgsVectorLayerJoinBuffer::vectorJoins ( ) const
inline

Definition at line 82 of file qgsvectorlayerjoinbuffer.h.

◆ writeXml()

void QgsVectorLayerJoinBuffer::writeXml ( QDomNode &  layer_node,
QDomDocument &  document 
) const

Saves mVectorJoins to xml under the layer node.

Definition at line 295 of file qgsvectorlayerjoinbuffer.cpp.


The documentation for this class was generated from the following files: