QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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.h"
23 #include "qgsvectorlayerjoininfo.h"
24 #include "qgsfeaturesink.h"
25 
26 #include <QHash>
27 #include <QString>
28 
29 
30 typedef QList< QgsVectorLayerJoinInfo > QgsVectorJoinList;
31 
32 
36 class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject, public QgsFeatureSink
37 {
38  Q_OBJECT
39  public:
40  QgsVectorLayerJoinBuffer( QgsVectorLayer *layer = nullptr );
41 
46  bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
47 
51  bool removeJoin( const QString &joinLayerId );
52 
57  void updateFields( QgsFields &fields );
58 
60  void createJoinCaches();
61 
63  void writeXml( QDomNode &layer_node, QDomDocument &document ) const;
64 
69  void readXml( const QDomNode &layer_node );
70 
75  void resolveReferences( QgsProject *project );
76 
78  bool containsJoins() const { return !mVectorJoins.isEmpty(); }
79 
80  const QgsVectorJoinList &vectorJoins() const { return mVectorJoins; }
81 
87  const QgsVectorLayerJoinInfo *joinForFieldIndex( int index, const QgsFields &fields, int &sourceFieldIndex SIP_OUT ) const;
88 
93  int joinedFieldsOffset( const QgsVectorLayerJoinInfo *info, const QgsFields &fields );
94 
99  static QVector<int> joinSubsetIndices( QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset );
100 
107  QList<const QgsVectorLayerJoinInfo *> joinsWhereFieldIsId( const QgsField &field ) const;
108 
115  QgsFeature joinedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
116 
123  QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
124 
134  bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
135 
140  QgsVectorLayerJoinBuffer *clone() const SIP_FACTORY;
141 
156  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override;
157 
173  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
174 
189  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
190 
201  bool deleteFeature( QgsFeatureId fid ) const;
202 
213  bool deleteFeatures( const QgsFeatureIds &fids ) const;
214 
215  signals:
216 
221  void joinedFieldsChanged();
222 
223  private slots:
224  void joinedLayerUpdatedFields();
225 
226  void joinedLayerModified();
227 
228  void joinedLayerWillBeDeleted();
229 
230  private:
231  void connectJoinedLayer( QgsVectorLayer *vl );
232 
233  private:
234 
235  QgsVectorLayer *mLayer = nullptr;
236 
238  QgsVectorJoinList mVectorJoins;
239 
241  void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
242 
244  QMutex mMutex;
245 };
246 
247 #endif // QGSVECTORLAYERJOINBUFFER_H
bool containsJoins() const
Quick way to test if there is any join at all.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:571
An interface for objects which accept features via addFeature(s) methods.
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
Container of fields for a vector layer.
Definition: qgsfields.h:42
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Manages joined fields for a vector layer.
Defines left outer join from our vector layer to some other vector layer.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
Reads and writes project states.
Definition: qgsproject.h:89
const QgsVectorJoinList & vectorJoins() const
#define SIP_FACTORY
Definition: qgis_sip.h:69
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr)=0
Adds a list of features to the sink.
#define SIP_OUT
Definition: qgis_sip.h:51
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList
Represents a vector layer which manages a vector based data sets.