QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 = QgsFeatureSink::Flags() ) 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 
206  bool deleteFeature( QgsFeatureId fid, QgsVectorLayer::DeleteContext *context = nullptr ) const;
207 
219  bool deleteFeatures( const QgsFeatureIds &fids, QgsVectorLayer::DeleteContext *context = nullptr ) const;
220 
221  signals:
222 
227  void joinedFieldsChanged();
228 
229  private slots:
230  void joinedLayerUpdatedFields();
231 
232  void joinedLayerModified();
233 
234  void joinedLayerWillBeDeleted();
235 
236  private:
237  void connectJoinedLayer( QgsVectorLayer *vl );
238 
239  private:
240 
241  QgsVectorLayer *mLayer = nullptr;
242 
244  QgsVectorJoinList mVectorJoins;
245 
247  void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
248 
250  QMutex mMutex;
251 };
252 
253 #endif // QGSVECTORLAYERJOINBUFFER_H
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsFields
Definition: qgsfields.h:44
qgsfeaturesink.h
QgsProject
Definition: qgsproject.h:92
qgsvectorlayerjoininfo.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsVectorJoinList
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList
Definition: qgsvectorlayerjoinbuffer.h:30
QgsVectorLayerJoinBuffer
Definition: qgsvectorlayerjoinbuffer.h:36
qgis_sip.h
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:572
QgsAttributeMap
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
QgsVectorLayerJoinBuffer::vectorJoins
const QgsVectorJoinList & vectorJoins() const
Definition: qgsvectorlayerjoinbuffer.h:82
QgsVectorLayerJoinInfo
Definition: qgsvectorlayerjoininfo.h:33
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsVectorLayerJoinBuffer::containsJoins
bool containsJoins() const
Quick way to test if there is any join at all.
Definition: qgsvectorlayerjoinbuffer.h:80
QgsFeature
Definition: qgsfeature.h:55
QgsFeatureSink
Definition: qgsfeaturesink.h:33
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
QgsField
Definition: qgsfield.h:49