QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
37 class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject, public QgsFeatureSink
38 {
39  Q_OBJECT
40  public:
41  QgsVectorLayerJoinBuffer( QgsVectorLayer *layer = nullptr );
42 
48  bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
49 
54  bool removeJoin( const QString &joinLayerId );
55 
60  void updateFields( QgsFields &fields );
61 
63  void createJoinCaches();
64 
66  void writeXml( QDomNode &layer_node, QDomDocument &document ) const;
67 
72  void readXml( const QDomNode &layer_node );
73 
78  void resolveReferences( QgsProject *project );
79 
81  bool containsJoins() const { return !mVectorJoins.isEmpty(); }
82 
83  const QgsVectorJoinList &vectorJoins() const { return mVectorJoins; }
84 
92  const QgsVectorLayerJoinInfo *joinForFieldIndex( int index, const QgsFields &fields, int &sourceFieldIndex SIP_OUT ) const;
93 
98  int joinedFieldsOffset( const QgsVectorLayerJoinInfo *info, const QgsFields &fields );
99 
104  static QVector<int> joinSubsetIndices( QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset );
105 
112  QList<const QgsVectorLayerJoinInfo *> joinsWhereFieldIsId( const QgsField &field ) const;
113 
120  QgsFeature joinedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
121 
128  QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
129 
139  bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
140 
145  QgsVectorLayerJoinBuffer *clone() const SIP_FACTORY;
146 
161  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
162 
178  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
179 
194  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap() );
195 
207  bool deleteFeature( QgsFeatureId fid, QgsVectorLayer::DeleteContext *context = nullptr ) const;
208 
220  bool deleteFeatures( const QgsFeatureIds &fids, QgsVectorLayer::DeleteContext *context = nullptr ) const;
221 
222  signals:
223 
228  void joinedFieldsChanged();
229 
230  private slots:
231  void joinedLayerUpdatedFields();
232 
233  void joinedLayerModified();
234 
235  void joinedLayerWillBeDeleted();
236 
237  private:
238  void connectJoinedLayer( QgsVectorLayer *vl );
239 
240  private:
241 
242  QgsVectorLayer *mLayer = nullptr;
243 
245  QgsVectorJoinList mVectorJoins;
246 
248  void cacheJoinLayer( QgsVectorLayerJoinInfo &joinInfo );
249 
251  QMutex mMutex;
252 };
253 
254 #endif // QGSVECTORLAYERJOINBUFFER_H
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
qgsfeaturesink.h
field
const QgsField & field
Definition: qgsfield.h:456
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
qgsvectorlayerjoininfo.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsVectorJoinList
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList
Definition: qgsvectorlayerjoinbuffer.h:30
QgsVectorLayerJoinBuffer
Manages joined fields for a vector layer.
Definition: qgsvectorlayerjoinbuffer.h:38
qgis_sip.h
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
QgsAttributeMap
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
QgsVectorLayerJoinBuffer::vectorJoins
const QgsVectorJoinList & vectorJoins() const
Definition: qgsvectorlayerjoinbuffer.h:83
QgsVectorLayerJoinInfo
Defines left outer join from our vector layer to some other vector layer.
Definition: qgsvectorlayerjoininfo.h:34
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsVectorLayerJoinBuffer::containsJoins
bool containsJoins() const
Quick way to test if there is any join at all.
Definition: qgsvectorlayerjoinbuffer.h:81
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.
Definition: qgsfeaturesink.h:34
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50