QGIS API Documentation  3.6.0-Noosa (5873452)
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 
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 
89  const QgsVectorLayerJoinInfo *joinForFieldIndex( int index, const QgsFields &fields, int &sourceFieldIndex SIP_OUT ) const;
90 
95  int joinedFieldsOffset( const QgsVectorLayerJoinInfo *info, const QgsFields &fields );
96 
101  static QVector<int> joinSubsetIndices( QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset );
102 
109  QList<const QgsVectorLayerJoinInfo *> joinsWhereFieldIsId( const QgsField &field ) const;
110 
117  QgsFeature joinedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
118 
125  QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
126 
136  bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
137 
142  QgsVectorLayerJoinBuffer *clone() const SIP_FACTORY;
143 
158  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override;
159 
175  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
176 
191  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
192 
203  bool deleteFeature( QgsFeatureId fid ) const;
204 
215  bool deleteFeatures( const QgsFeatureIds &fids ) const;
216 
217  signals:
218 
223  void joinedFieldsChanged();
224 
225  private slots:
226  void joinedLayerUpdatedFields();
227 
228  void joinedLayerModified();
229 
230  void joinedLayerWillBeDeleted();
231 
232  private:
233  void connectJoinedLayer( QgsVectorLayer *vl );
234 
235  private:
236 
237  QgsVectorLayer *mLayer = nullptr;
238 
240  QgsVectorJoinList mVectorJoins;
241 
243  void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
244 
246  QMutex mMutex;
247 };
248 
249 #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.