QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsvectorlayerjoinbuffer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerjoinbuffer.h
3 ---------------------------
4 begin : Feb 09, 2011
5 copyright : (C) 2011 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSVECTORLAYERJOINBUFFER_H
19#define QGSVECTORLAYERJOINBUFFER_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgsfeaturesink.h"
25
26#include <QHash>
27#include <QString>
28
29typedef QList< QgsVectorLayerJoinInfo > QgsVectorJoinList;
30
31
36class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject, public QgsFeatureSink
37{
38 Q_OBJECT
39 public:
40 QgsVectorLayerJoinBuffer( QgsVectorLayer *layer = nullptr );
41
47 bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
48
53 bool removeJoin( const QString &joinLayerId );
54
59 void updateFields( QgsFields &fields );
60
62 void createJoinCaches();
63
65 void writeXml( QDomNode &layer_node, QDomDocument &document ) const;
66
71 void readXml( const QDomNode &layer_node );
72
76 void resolveReferences( QgsProject *project );
77
79 bool containsJoins() const { return !mVectorJoins.isEmpty(); }
80
81 const QgsVectorJoinList &vectorJoins() const { return mVectorJoins; }
82
90 const QgsVectorLayerJoinInfo *joinForFieldIndex( int index, const QgsFields &fields, int &sourceFieldIndex SIP_OUT ) const;
91
95 int joinedFieldsOffset( const QgsVectorLayerJoinInfo *info, const QgsFields &fields );
96
100 static QVector<int> joinSubsetIndices( QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset );
101
106 static QVector<int> joinSubsetIndices( const QgsFields &joinLayerFields, const QStringList &joinFieldsSubset );
107
113 QList<const QgsVectorLayerJoinInfo *> joinsWhereFieldIsId( const QgsField &field ) const;
114
120 QgsFeature joinedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
121
127 QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
128
137 bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
138
143
157 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
158
173 bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
174
188 bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
189
200 bool deleteFeature( QgsFeatureId fid, QgsVectorLayer::DeleteContext *context = nullptr ) const;
201
212 bool deleteFeatures( const QgsFeatureIds &fids, QgsVectorLayer::DeleteContext *context = nullptr ) const;
213
214 signals:
215
220
221 private slots:
222 void joinedLayerUpdatedFields();
223
224 void joinedLayerModified();
225
226 void joinedLayerWillBeDeleted();
227
228 private:
229 void connectJoinedLayer( QgsVectorLayer *vl );
230
231 private:
232
233 QgsVectorLayer *mLayer = nullptr;
234
236 QgsVectorJoinList mVectorJoins;
237
239 void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
240
242 QMutex mMutex;
243};
244
245#endif // QGSVECTORLAYERJOINBUFFER_H
An interface for objects which accept features via addFeature(s) methods.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:54
Container of fields for a vector layer.
Definition qgsfields.h:46
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
Manages joined fields for a vector layer.
void resolveReferences(QgsProject *project)
Resolves layer IDs of joined layers using given project's available layers.
bool addJoin(const QgsVectorLayerJoinInfo &joinInfo)
Joins another vector layer to this layer.
void readXml(const QDomNode &layer_node)
Reads joins from project file.
QgsVectorLayerJoinBuffer(QgsVectorLayer *layer=nullptr)
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves mVectorJoins to xml under the layer node.
bool removeJoin(const QString &joinLayerId)
Removes a vector layer join.
bool containsJoins() const
Quick way to test if there is any join at all.
void joinedFieldsChanged()
Emitted whenever the list of joined fields changes (e.g.
void createJoinCaches()
Calls cacheJoinLayer() for all vector joins.
void updateFields(QgsFields &fields)
Updates field map with joined attributes.
const QgsVectorJoinList & vectorJoins() const
Defines left outer join from our vector layer to some other vector layer.
Represents a vector layer which manages a vector based dataset.
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList