QGIS API Documentation  2.99.0-Master (a411669)
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 
25 #include <QHash>
26 #include <QString>
27 
28 
29 typedef QList< QgsVectorLayerJoinInfo > QgsVectorJoinList;
30 
31 
35 class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject, public QgsFeatureSink
36 {
37  Q_OBJECT
38  public:
39  QgsVectorLayerJoinBuffer( QgsVectorLayer *layer = nullptr );
40 
45  bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
46 
50  bool removeJoin( const QString &joinLayerId );
51 
56  void updateFields( QgsFields &fields );
57 
59  void createJoinCaches();
60 
62  void writeXml( QDomNode &layer_node, QDomDocument &document ) const;
63 
68  void readXml( const QDomNode &layer_node );
69 
74  void resolveReferences( QgsProject *project );
75 
77  bool containsJoins() const { return !mVectorJoins.isEmpty(); }
78 
79  const QgsVectorJoinList &vectorJoins() const { return mVectorJoins; }
80 
86  const QgsVectorLayerJoinInfo *joinForFieldIndex( int index, const QgsFields &fields, int &sourceFieldIndex SIP_OUT ) const;
87 
92  int joinedFieldsOffset( const QgsVectorLayerJoinInfo *info, const QgsFields &fields );
93 
98  static QVector<int> joinSubsetIndices( QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset );
99 
106  QList<const QgsVectorLayerJoinInfo *> joinsWhereFieldIsId( const QgsField &field ) const;
107 
114  QgsFeature joinedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
115 
122  QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
123 
133  bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
134 
139  QgsVectorLayerJoinBuffer *clone() const SIP_FACTORY;
140 
155  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 ) override;
156 
172  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
173 
184  bool deleteFeature( QgsFeatureId fid ) const;
185 
196  bool deleteFeatures( const QgsFeatureIds &fids ) const;
197 
198  signals:
199 
204  void joinedFieldsChanged();
205 
206  private slots:
207  void joinedLayerUpdatedFields();
208 
209  void joinedLayerModified();
210 
211  void joinedLayerWillBeDeleted();
212 
213  private:
214  void connectJoinedLayer( QgsVectorLayer *vl );
215 
216  private:
217 
218  QgsVectorLayer *mLayer = nullptr;
219 
221  QgsVectorJoinList mVectorJoins;
222 
224  void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
225 
227  QMutex mMutex;
228 };
229 
230 #endif // QGSVECTORLAYERJOINBUFFER_H
bool containsJoins() const
Quick way to test if there is any join at all.
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=0)=0
Adds a list of features to the sink.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:549
An interface for objects which accept features via addFeature(s) methods.
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:62
Manages joined fields for a vector layer.
Defines left outer join from our vector layer to some other vector layer.
Reads and writes project states.
Definition: qgsproject.h:81
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
#define SIP_OUT
Definition: qgis_sip.h:51
qint64 QgsFeatureId
Definition: qgsfeature.h:37
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList
Represents a vector layer which manages a vector based data sets.