QGIS API Documentation 3.99.0-Master (752b475928d)
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
144 using QgsFeatureSink::addFeatures;
158 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
159
174 bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
175
189 bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
190
201 bool deleteFeature( QgsFeatureId fid, QgsVectorLayer::DeleteContext *context = nullptr ) const;
202
213 bool deleteFeatures( const QgsFeatureIds &fids, QgsVectorLayer::DeleteContext *context = nullptr ) const;
214
215 signals:
216
221
222 private slots:
223 void joinedLayerUpdatedFields();
224
225 void joinedLayerModified();
226
227 void joinedLayerWillBeDeleted();
228
229 private:
230 void connectJoinedLayer( QgsVectorLayer *vl );
231
232 private:
233
234 QgsVectorLayer *mLayer = nullptr;
235
237 QgsVectorJoinList mVectorJoins;
238
240 void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
241
243 QMutex mMutex;
244};
245
246#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