QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
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
33class CORE_EXPORT QgsVectorLayerJoinInfo
34{
35 public:
36
38
40 void setJoinLayer( QgsVectorLayer *layer ) { mJoinLayerRef = QgsVectorLayerRef( layer ); }
42 QgsVectorLayer *joinLayer() const { return mJoinLayerRef.get(); }
43
45 void setJoinLayerId( const QString &layerId ) { mJoinLayerRef = QgsVectorLayerRef( layerId ); }
47 QString joinLayerId() const { return mJoinLayerRef.layerId; }
48
50 void setTargetFieldName( const QString &fieldName ) { mTargetFieldName = fieldName; }
52 QString targetFieldName() const { return mTargetFieldName; }
53
55 void setJoinFieldName( const QString &fieldName ) { mJoinFieldName = fieldName; }
57 QString joinFieldName() const { return mJoinFieldName; }
58
60 void setPrefix( const QString &prefix ) { mPrefix = prefix; }
62 QString prefix() const { return mPrefix; }
63
65 void setUsingMemoryCache( bool enabled );
66
71 bool isUsingMemoryCache() const;
72
77 bool isDynamicFormEnabled() const { return mDynamicForm; }
78
83 void setDynamicFormEnabled( bool enabled ) { mDynamicForm = enabled; }
84
89 bool isEditable() const { return mEditable; }
90
94 void setEditable( bool enabled );
95
100 bool hasUpsertOnEdit() const { return mUpsertOnEdit; }
101
106 void setUpsertOnEdit( bool enabled ) { mUpsertOnEdit = enabled; }
107
112 bool hasCascadedDelete() const { return mCascadedDelete; }
113
118 void setCascadedDelete( bool enabled ) { mCascadedDelete = enabled; }
119
125 QString prefixedFieldName( const QgsField &field ) const;
126
133 QgsFeature extractJoinedFeature( const QgsFeature &feature ) const;
134
140 Q_DECL_DEPRECATED void setJoinFieldNamesBlackList( const QStringList &blackList ) SIP_DEPRECATED { mBlockList = blackList; }
141
147 Q_DECL_DEPRECATED QStringList joinFieldNamesBlackList() const SIP_DEPRECATED { return mBlockList; }
148
155 void setJoinFieldNamesBlockList( const QStringList &list ) { mBlockList = list; }
156
163 QStringList joinFieldNamesBlockList() const { return mBlockList; }
164
170 bool hasSubset( bool blocklisted = true ) const;
171
180 static QStringList joinFieldNamesSubset( const QgsVectorLayerJoinInfo &info, bool blocklisted = true );
181
190 static QStringList joinFieldNamesSubset( const QgsVectorLayerJoinInfo &info, const QgsFields &joinLayerFields, bool blocklisted = true );
191
192 bool operator==( const QgsVectorLayerJoinInfo &other ) const
193 {
194 return mTargetFieldName == other.mTargetFieldName &&
195 mJoinLayerRef.layerId == other.mJoinLayerRef.layerId &&
196 mJoinFieldName == other.mJoinFieldName &&
197 mJoinFieldsSubset == other.mJoinFieldsSubset &&
198 mMemoryCache == other.mMemoryCache &&
199 mPrefix == other.mPrefix;
200 }
201
209 void setJoinFieldNamesSubset( QStringList *fieldNamesSubset SIP_TRANSFER ) { mJoinFieldsSubset = std::shared_ptr<QStringList>( fieldNamesSubset ); }
210
219 QStringList *joinFieldNamesSubset() const { return mJoinFieldsSubset.get(); }
220
221 protected:
228
232 QString mPrefix;
233
235 bool mMemoryCache = false;
236
238 std::shared_ptr<QStringList> mJoinFieldsSubset;
239
240 // caching support
241
244
246 bool cacheDirty = true;
247
248 bool mDynamicForm = false;
249
250 bool mEditable = false;
251
252 bool mUpsertOnEdit = false;
253
254 bool mCascadedDelete = false;
255
256 QStringList mBlockList;
257
259 QHash< QString, QgsAttributes> cachedAttributes;
260
261};
262
263
264#endif // QGSVECTORLAYERJOININFO_H
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
A feature iterator which iterates over features from a QgsVectorLayer.
Manages joined fields for a vector layer.
Defines left outer join from our vector layer to some other vector layer.
QStringList * joinFieldNamesSubset() const
Returns the subset of fields to be used from joined layer.
QgsVectorLayerJoinInfo()=default
void setDynamicFormEnabled(bool enabled)
Sets whether the form has to be dynamically updated with joined fields when a feature is being create...
bool hasCascadedDelete() const
Returns whether a feature deleted on the target layer has to impact the joined layer by deleting the ...
bool operator==(const QgsVectorLayerJoinInfo &other) const
void setJoinLayerId(const QString &layerId)
Sets ID of the joined layer. It will need to be overwritten by setJoinLayer() to a reference to real ...
Q_DECL_DEPRECATED void setJoinFieldNamesBlackList(const QStringList &blackList)
Sets a list of fields to ignore whatever happens.
std::shared_ptr< QStringList > mJoinFieldsSubset
Subset of fields to use from joined layer. nullptr = use all fields.
bool isDynamicFormEnabled() const
Returns whether the form has to be dynamically updated with joined fields when a feature is being cre...
bool hasUpsertOnEdit() const
Returns whether a feature created on the target layer has to impact the joined layer by creating a ne...
bool mMemoryCache
True if the join is cached in virtual memory.
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
QString mPrefix
An optional prefix.
void setCascadedDelete(bool enabled)
Sets whether a feature deleted on the target layer has to impact the joined layer by deleting the cor...
void setJoinFieldName(const QString &fieldName)
Sets name of the field of joined layer that will be used for join.
void setJoinFieldNamesBlockList(const QStringList &list)
Sets a list of fields to ignore whatever happens.
QString mJoinFieldName
Join field in the source layer.
QString prefix() const
Returns prefix of fields from the joined layer. If nullptr, joined layer's name will be used.
void setTargetFieldName(const QString &fieldName)
Sets name of the field of our layer that will be used for join.
QStringList joinFieldNamesBlockList() const
Returns the list of fields to ignore.
QString joinFieldName() const
Returns name of the field of joined layer that will be used for join.
void setUpsertOnEdit(bool enabled)
Sets whether a feature created on the target layer has to impact the joined layer by creating a new f...
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
QString joinLayerId() const
ID of the joined layer - may be used to resolve reference to the joined layer.
void setPrefix(const QString &prefix)
Sets prefix of fields from the joined layer. If nullptr, joined layer's name will be used.
QgsVectorLayerRef mJoinLayerRef
Weak reference to the joined layer.
void setJoinLayer(QgsVectorLayer *layer)
Sets weak reference to the joined layer.
Q_DECL_DEPRECATED QStringList joinFieldNamesBlackList() const
Returns the list of fields to ignore.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet)
QHash< QString, QgsAttributes > cachedAttributes
Cache for joined attributes to provide fast lookup (size is 0 if no memory caching)
QString mTargetFieldName
Join field in the target layer.
void setJoinFieldNamesSubset(QStringList *fieldNamesSubset)
Sets the subset of fields to be used from joined layer.
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFER
Definition qgis_sip.h:36
_LayerRef< QgsVectorLayer > QgsVectorLayerRef
QString layerId
Original layer ID.