QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 "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 
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 
77  void resolveReferences( QgsProject *project );
78 
80  bool containsJoins() const { return !mVectorJoins.isEmpty(); }
81 
82  const QgsVectorJoinList &vectorJoins() const { return mVectorJoins; }
83 
91  const QgsVectorLayerJoinInfo *joinForFieldIndex( int index, const QgsFields &fields, int &sourceFieldIndex SIP_OUT ) const;
92 
97  int joinedFieldsOffset( const QgsVectorLayerJoinInfo *info, const QgsFields &fields );
98 
103  static QVector<int> joinSubsetIndices( QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset );
104 
111  QList<const QgsVectorLayerJoinInfo *> joinsWhereFieldIsId( const QgsField &field ) const;
112 
119  QgsFeature joinedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
120 
127  QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
128 
138  bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
139 
144  QgsVectorLayerJoinBuffer *clone() const SIP_FACTORY;
145 
160  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override;
161 
177  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
178 
193  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
194 
205  bool deleteFeature( QgsFeatureId fid ) const;
206 
217  bool deleteFeatures( const QgsFeatureIds &fids ) const;
218 
219  signals:
220 
225  void joinedFieldsChanged();
226 
227  private slots:
228  void joinedLayerUpdatedFields();
229 
230  void joinedLayerModified();
231 
232  void joinedLayerWillBeDeleted();
233 
234  private:
235  void connectJoinedLayer( QgsVectorLayer *vl );
236 
237  private:
238 
239  QgsVectorLayer *mLayer = nullptr;
240 
242  QgsVectorJoinList mVectorJoins;
243 
245  void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
246 
248  QMutex mMutex;
249 };
250 
251 #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.