QGIS API Documentation  3.2.0-Bonn (bc43194)
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 = nullptr ) override;
156 
172  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
173 
188  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
189 
200  bool deleteFeature( QgsFeatureId fid ) const;
201 
212  bool deleteFeatures( const QgsFeatureIds &fids ) const;
213 
214  signals:
215 
220  void joinedFieldsChanged();
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
bool containsJoins() const
Quick way to test if there is any join at all.
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.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:39
Reads and writes project states.
Definition: qgsproject.h:85
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
qint64 QgsFeatureId
Definition: qgsfeature.h:37
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList
Represents a vector layer which manages a vector based data sets.