QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
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 );
69 
74  bool isUsingMemoryCache() const;
75 
81  bool isDynamicFormEnabled() const { return mDynamicForm; }
82 
88  void setDynamicFormEnabled( bool enabled ) { mDynamicForm = enabled; }
89 
95  bool isEditable() const { return mEditable; }
96 
101  void setEditable( bool enabled );
102 
108  bool hasUpsertOnEdit() const { return mUpsertOnEdit; }
109 
115  void setUpsertOnEdit( bool enabled ) { mUpsertOnEdit = enabled; }
116 
122  bool hasCascadedDelete() const { return mCascadedDelete; }
123 
129  void setCascadedDelete( bool enabled ) { mCascadedDelete = enabled; }
130 
137  QString prefixedFieldName( const QgsField &field ) const;
138 
146  QgsFeature extractJoinedFeature( const QgsFeature &feature ) const;
147 
153  Q_DECL_DEPRECATED void setJoinFieldNamesBlackList( const QStringList &blackList ) SIP_DEPRECATED { mBlockList = blackList; }
154 
160  Q_DECL_DEPRECATED QStringList joinFieldNamesBlackList() const SIP_DEPRECATED { return mBlockList; }
161 
168  void setJoinFieldNamesBlockList( const QStringList &list ) { mBlockList = list; }
169 
176  QStringList joinFieldNamesBlockList() const { return mBlockList; }
177 
184  bool hasSubset( bool blocklisted = true ) const;
185 
192  static QStringList joinFieldNamesSubset( const QgsVectorLayerJoinInfo &info, bool blocklisted = true );
193 
194  bool operator==( const QgsVectorLayerJoinInfo &other ) const
195  {
196  return mTargetFieldName == other.mTargetFieldName &&
197  mJoinLayerRef.layerId == other.mJoinLayerRef.layerId &&
198  mJoinFieldName == other.mJoinFieldName &&
199  mJoinFieldsSubset == other.mJoinFieldsSubset &&
200  mMemoryCache == other.mMemoryCache &&
201  mPrefix == other.mPrefix;
202  }
203 
212  void setJoinFieldNamesSubset( QStringList *fieldNamesSubset SIP_TRANSFER ) { mJoinFieldsSubset = std::shared_ptr<QStringList>( fieldNamesSubset ); }
213 
223  QStringList *joinFieldNamesSubset() const { return mJoinFieldsSubset.get(); }
224 
225  protected:
231  QString mJoinFieldName;
232 
237  QString mPrefix;
238 
240  bool mMemoryCache = false;
241 
243  std::shared_ptr<QStringList> mJoinFieldsSubset;
244 
245  // caching support
246 
249 
251  bool cacheDirty = true;
252 
253  bool mDynamicForm = false;
254 
255  bool mEditable = false;
256 
257  bool mUpsertOnEdit = false;
258 
259  bool mCascadedDelete = false;
260 
261  QStringList mBlockList;
262 
264  QHash< QString, QgsAttributes> cachedAttributes;
265 
266 };
267 
268 
269 #endif // QGSVECTORLAYERJOININFO_H
QgsVectorLayerJoinInfo::isDynamicFormEnabled
bool isDynamicFormEnabled() const
Returns whether the form has to be dynamically updated with joined fields when a feature is being cre...
Definition: qgsvectorlayerjoininfo.h:81
QgsVectorLayerJoinInfo::mJoinFieldsSubset
std::shared_ptr< QStringList > mJoinFieldsSubset
Subset of fields to use from joined layer. nullptr = use all fields.
Definition: qgsvectorlayerjoininfo.h:243
QgsVectorLayerJoinInfo::joinFieldNamesBlackList
Q_DECL_DEPRECATED QStringList joinFieldNamesBlackList() const
Returns the list of fields to ignore.
Definition: qgsvectorlayerjoininfo.h:160
qgsfeature.h
QgsVectorLayerJoinInfo::mPrefix
QString mPrefix
An optional prefix.
Definition: qgsvectorlayerjoininfo.h:237
QgsVectorLayerJoinInfo::joinFieldNamesSubset
QStringList * joinFieldNamesSubset() const
Returns the subset of fields to be used from joined layer.
Definition: qgsvectorlayerjoininfo.h:223
QgsVectorLayerJoinInfo::setUpsertOnEdit
void setUpsertOnEdit(bool enabled)
Sets whether a feature created on the target layer has to impact the joined layer by creating a new f...
Definition: qgsvectorlayerjoininfo.h:115
field
const QgsField & field
Definition: qgsfield.h:456
QgsVectorLayerJoinInfo::joinLayerId
QString joinLayerId() const
ID of the joined layer - may be used to resolve reference to the joined layer.
Definition: qgsvectorlayerjoininfo.h:50
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsVectorLayerJoinInfo::targetFieldName
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
Definition: qgsvectorlayerjoininfo.h:55
_LayerRef::layerId
QString layerId
Original layer ID.
Definition: qgsmaplayerref.h:116
QgsVectorLayerJoinInfo::prefix
QString prefix() const
Returns prefix of fields from the joined layer. If nullptr, joined layer's name will be used.
Definition: qgsvectorlayerjoininfo.h:65
QgsVectorLayerJoinInfo::QgsVectorLayerJoinInfo
QgsVectorLayerJoinInfo()=default
Constructor for QgsVectorLayerJoinInfo.
QgsVectorLayerJoinInfo::mTargetFieldName
QString mTargetFieldName
Join field in the target layer.
Definition: qgsvectorlayerjoininfo.h:227
QgsVectorLayerJoinInfo::cachedAttributes
QHash< QString, QgsAttributes > cachedAttributes
Cache for joined attributes to provide fast lookup (size is 0 if no memory caching)
Definition: qgsvectorlayerjoininfo.h:264
QgsVectorLayerFeatureIterator
Definition: qgsvectorlayerfeatureiterator.h:121
QgsVectorLayerJoinInfo::setDynamicFormEnabled
void setDynamicFormEnabled(bool enabled)
Sets whether the form has to be dynamically updated with joined fields when a feature is being create...
Definition: qgsvectorlayerjoininfo.h:88
QgsVectorLayerJoinInfo::hasUpsertOnEdit
bool hasUpsertOnEdit() const
Returns whether a feature created on the target layer has to impact the joined layer by creating a ne...
Definition: qgsvectorlayerjoininfo.h:108
QgsVectorLayerJoinBuffer
Manages joined fields for a vector layer.
Definition: qgsvectorlayerjoinbuffer.h:38
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsVectorLayerJoinInfo::isEditable
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
Definition: qgsvectorlayerjoininfo.h:95
QgsVectorLayerJoinInfo::joinFieldName
QString joinFieldName() const
Returns name of the field of joined layer that will be used for join.
Definition: qgsvectorlayerjoininfo.h:60
QgsVectorLayerJoinInfo
Defines left outer join from our vector layer to some other vector layer.
Definition: qgsvectorlayerjoininfo.h:34
QgsVectorLayerJoinInfo::setTargetFieldName
void setTargetFieldName(const QString &fieldName)
Sets name of the field of our layer that will be used for join.
Definition: qgsvectorlayerjoininfo.h:53
QgsVectorLayerJoinInfo::setJoinFieldName
void setJoinFieldName(const QString &fieldName)
Sets name of the field of joined layer that will be used for join.
Definition: qgsvectorlayerjoininfo.h:58
QgsVectorLayerJoinInfo::mJoinFieldName
QString mJoinFieldName
Join field in the source layer.
Definition: qgsvectorlayerjoininfo.h:231
QgsVectorLayerJoinInfo::setJoinFieldNamesSubset
void setJoinFieldNamesSubset(QStringList *fieldNamesSubset)
Sets the subset of fields to be used from joined layer.
Definition: qgsvectorlayerjoininfo.h:212
QgsVectorLayerJoinInfo::setPrefix
void setPrefix(const QString &prefix)
Sets prefix of fields from the joined layer. If nullptr, joined layer's name will be used.
Definition: qgsvectorlayerjoininfo.h:63
QgsVectorLayerJoinInfo::setJoinFieldNamesBlockList
void setJoinFieldNamesBlockList(const QStringList &list)
Sets a list of fields to ignore whatever happens.
Definition: qgsvectorlayerjoininfo.h:168
qgsvectorlayerref.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsVectorLayerJoinInfo::setJoinFieldNamesBlackList
Q_DECL_DEPRECATED void setJoinFieldNamesBlackList(const QStringList &blackList)
Sets a list of fields to ignore whatever happens.
Definition: qgsvectorlayerjoininfo.h:153
QgsVectorLayerJoinInfo::joinLayer
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet)
Definition: qgsvectorlayerjoininfo.h:45
QgsVectorLayerJoinInfo::hasCascadedDelete
bool hasCascadedDelete() const
Returns whether a feature deleted on the target layer has to impact the joined layer by deleting the ...
Definition: qgsvectorlayerjoininfo.h:122
QgsVectorLayerJoinInfo::joinFieldNamesBlockList
QStringList joinFieldNamesBlockList() const
Returns the list of fields to ignore.
Definition: qgsvectorlayerjoininfo.h:176
QgsVectorLayerJoinInfo::operator==
bool operator==(const QgsVectorLayerJoinInfo &other) const
Definition: qgsvectorlayerjoininfo.h:194
QgsVectorLayerRef
_LayerRef< QgsVectorLayer > QgsVectorLayerRef
Definition: qgsvectorlayerref.h:23
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
_LayerRef< QgsVectorLayer >
QgsVectorLayerJoinInfo::mMemoryCache
bool mMemoryCache
True if the join is cached in virtual memory.
Definition: qgsvectorlayerjoininfo.h:240
QgsVectorLayerJoinInfo::setJoinLayer
void setJoinLayer(QgsVectorLayer *layer)
Sets weak reference to the joined layer.
Definition: qgsvectorlayerjoininfo.h:43
QgsVectorLayerJoinInfo::mBlockList
QStringList mBlockList
Definition: qgsvectorlayerjoininfo.h:261
QgsVectorLayerJoinInfo::setCascadedDelete
void setCascadedDelete(bool enabled)
Sets whether a feature deleted on the target layer has to impact the joined layer by deleting the cor...
Definition: qgsvectorlayerjoininfo.h:129
QgsVectorLayerJoinInfo::mJoinLayerRef
QgsVectorLayerRef mJoinLayerRef
Weak reference to the joined layer.
Definition: qgsvectorlayerjoininfo.h:229
QgsVectorLayerJoinInfo::setJoinLayerId
void setJoinLayerId(const QString &layerId)
Sets ID of the joined layer. It will need to be overwritten by setJoinLayer() to a reference to real ...
Definition: qgsvectorlayerjoininfo.h:48
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50