QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsvectorlayerjoininfo.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerjoininfo.h
3  ---------------------
4  begin : January 2017
5  copyright : (C) 2017 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSVECTORLAYERJOININFO_H
16 #define QGSVECTORLAYERJOININFO_H
17 
18 #include <QHash>
19 #include <QString>
20 #include <QStringList>
21 
22 #include "qgsfeature.h"
23 
24 #include "qgsvectorlayerref.h"
25 
33 class CORE_EXPORT QgsVectorLayerJoinInfo
34 {
35  public:
36 
40  QgsVectorLayerJoinInfo() = default;
41 
43  void setJoinLayer( QgsVectorLayer *layer ) { mJoinLayerRef = QgsVectorLayerRef( layer ); }
45  QgsVectorLayer *joinLayer() const { return mJoinLayerRef.get(); }
46 
48  void setJoinLayerId( const QString &layerId ) { mJoinLayerRef = QgsVectorLayerRef( layerId ); }
50  QString joinLayerId() const { return mJoinLayerRef.layerId; }
51 
53  void setTargetFieldName( const QString &fieldName ) { mTargetFieldName = fieldName; }
55  QString targetFieldName() const { return mTargetFieldName; }
56 
58  void setJoinFieldName( const QString &fieldName ) { mJoinFieldName = fieldName; }
60  QString joinFieldName() const { return mJoinFieldName; }
61 
63  void setPrefix( const QString &prefix ) { mPrefix = prefix; }
65  QString prefix() const { return mPrefix; }
66 
68  void setUsingMemoryCache( bool enabled ) { mMemoryCache = enabled; }
70  bool isUsingMemoryCache() const { return mMemoryCache; }
71 
77  bool isDynamicFormEnabled() const { return mDynamicForm; }
78 
84  void setDynamicFormEnabled( bool enabled ) { mDynamicForm = enabled; }
85 
91  bool isEditable() const { return mEditable; }
92 
97  void setEditable( bool enabled );
98 
104  bool hasUpsertOnEdit() const { return mUpsertOnEdit; }
105 
111  void setUpsertOnEdit( bool enabled ) { mUpsertOnEdit = enabled; }
112 
118  bool hasCascadedDelete() const { return mCascadedDelete; }
119 
125  void setCascadedDelete( bool enabled ) { mCascadedDelete = enabled; }
126 
133  QString prefixedFieldName( const QgsField &field ) const;
134 
142  QgsFeature extractJoinedFeature( const QgsFeature &feature ) const;
143 
149  void setJoinFieldNamesBlackList( const QStringList &blackList ) { mBlackList = blackList; }
150 
156  QStringList joinFieldNamesBlackList() const { return mBlackList; }
157 
164  bool hasSubset( bool blacklisted = true ) const;
165 
172  static QStringList joinFieldNamesSubset( const QgsVectorLayerJoinInfo &info, bool blacklisted = true );
173 
174  bool operator==( const QgsVectorLayerJoinInfo &other ) const
175  {
176  return mTargetFieldName == other.mTargetFieldName &&
177  mJoinLayerRef.layerId == other.mJoinLayerRef.layerId &&
178  mJoinFieldName == other.mJoinFieldName &&
179  mJoinFieldsSubset == other.mJoinFieldsSubset &&
180  mMemoryCache == other.mMemoryCache &&
181  mPrefix == other.mPrefix;
182  }
183 
192  void setJoinFieldNamesSubset( QStringList *fieldNamesSubset SIP_TRANSFER ) { mJoinFieldsSubset = std::shared_ptr<QStringList>( fieldNamesSubset ); }
193 
203  QStringList *joinFieldNamesSubset() const { return mJoinFieldsSubset.get(); }
204 
205  protected:
211  QString mJoinFieldName;
212 
217  QString mPrefix;
218 
220  bool mMemoryCache = false;
221 
223  std::shared_ptr<QStringList> mJoinFieldsSubset;
224 
225  // caching support
226 
229 
231  bool cacheDirty = true;
232 
233  bool mDynamicForm = false;
234 
235  bool mEditable = false;
236 
237  bool mUpsertOnEdit = false;
238 
239  bool mCascadedDelete = false;
240 
241  QStringList mBlackList;
242 
244  QHash< QString, QgsAttributes> cachedAttributes;
245 
246 };
247 
248 
249 #endif // QGSVECTORLAYERJOININFO_H
void setJoinLayer(QgsVectorLayer *layer)
Sets weak reference to the joined layer.
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
bool mMemoryCache
True if the join is cached in virtual memory.
QString mTargetFieldName
Join field in the target layer.
void setJoinFieldName(const QString &fieldName)
Sets name of the field of joined layer that will be used for join.
void setDynamicFormEnabled(bool enabled)
Sets whether the form has to be dynamically updated with joined fields when a feature is being create...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
std::shared_ptr< QStringList > mJoinFieldsSubset
Subset of fields to use from joined layer. nullptr = use all fields.
bool operator==(const QgsVectorLayerJoinInfo &other) const
QHash< QString, QgsAttributes > cachedAttributes
Cache for joined attributes to provide fast lookup (size is 0 if no memory caching) ...
Manages joined fields for a vector layer.
void setUpsertOnEdit(bool enabled)
Sets whether a feature created on the target layer has to impact the joined layer by creating a new f...
QgsVectorLayerRef mJoinLayerRef
Weak reference to the joined layer.
QString layerId
Original layer ID.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet) ...
Defines left outer join from our vector layer to some other vector layer.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
void setUsingMemoryCache(bool enabled)
Sets whether values from the joined layer should be cached in memory to speed up lookups.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
void setTargetFieldName(const QString &fieldName)
Sets name of the field of our layer that will be used for join.
QString mJoinFieldName
Join field in the source layer.
void setPrefix(const QString &prefix)
Sets prefix of fields from the joined layer. If nullptr, joined layer&#39;s name will be used...
_LayerRef< QgsVectorLayer > QgsVectorLayerRef
bool isUsingMemoryCache() const
Returns whether values from the joined layer should be cached in memory to speed up lookups...
void setCascadedDelete(bool enabled)
Sets whether a feature deleted on the target layer has to impact the joined layer by deleting the cor...
bool hasCascadedDelete() const
Returns whether a feature deleted on the target layer has to impact the joined layer by deleting the ...
void setJoinFieldNamesBlackList(const QStringList &blackList)
Sets a list of fields to ignore whatever happens.
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer. ...
bool hasUpsertOnEdit() const
Returns whether a feature created on the target layer has to impact the joined layer by creating a ne...
Represents a vector layer which manages a vector based data sets.
QString joinFieldName() const
Returns name of the field of joined layer that will be used for join.
bool isDynamicFormEnabled() const
Returns whether the form has to be dynamically updated with joined fields when a feature is being cre...
QString mPrefix
An optional prefix.
void setJoinFieldNamesSubset(QStringList *fieldNamesSubset)
Sets the subset of fields to be used from joined layer.
QStringList * joinFieldNamesSubset() const
Returns the subset of fields to be used from joined layer.
void setJoinLayerId(const QString &layerId)
Sets ID of the joined layer. It will need to be overwritten by setJoinLayer() to a reference to real ...
QString prefix() const
Returns prefix of fields from the joined layer. If nullptr, joined layer&#39;s name will be used...
QStringList joinFieldNamesBlackList() const
Returns the list of fields to ignore.
QString joinLayerId() const
ID of the joined layer - may be used to resolve reference to the joined layer.