QGIS API Documentation 3.43.0-Master (b60ef06885e)
qgsvectorlayerutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerutils.h
3 ---------------------
4 Date : October 2016
5 Copyright : (C) 2016 by Nyall Dawson
6 Email : nyall dot dawson 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
16#ifndef QGSVECTORLAYERUTILS_H
17#define QGSVECTORLAYERUTILS_H
18
19#include "qgis_core.h"
20#include "qgsgeometry.h"
22#include "qgsfeaturesink.h"
23
25class QgsSymbolLayer;
27
28
29#ifndef SIP_RUN
30
32{
33 bool hasEffects = false;
34
35 // masked symbol layers
36 QSet<QString> symbolLayerIds;
37};
38
40typedef QHash<QString, QgsMaskedLayer> QgsMaskedLayers;
41
42#endif
43
49class CORE_EXPORT QgsVectorLayerUtils
50{
51 public:
52
59 {
60 public:
61
63
67 QList<QgsVectorLayer *> layers() const;
68
72 QgsFeatureIds duplicatedFeatures( QgsVectorLayer *layer ) const;
73
74
75 private:
76 QMap<QgsVectorLayer *, QgsFeatureIds> mDuplicatedFeatures;
77 friend class QgsVectorLayerUtils;
78
82 void setDuplicatedFeatures( QgsVectorLayer *layer, const QgsFeatureIds &ids );
83 };
84
92 class CORE_EXPORT QgsFeatureData
93 {
94 public:
95
99 QgsFeatureData( const QgsGeometry &geometry = QgsGeometry(), const QgsAttributeMap &attributes = QgsAttributeMap() );
100
102 QgsGeometry geometry() const;
103
105 QgsAttributeMap attributes() const;
106
107 private:
108 QgsGeometry mGeometry;
109 QgsAttributeMap mAttributes;
110 };
111
112 // SIP does not like "using", use legacy typedef
114 typedef QList<QgsVectorLayerUtils::QgsFeatureData> QgsFeaturesDataList;
115
124 static QgsFeatureIterator getValuesIterator( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly );
125
136 static QList< QVariant > getValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, QgsFeedback *feedback = nullptr );
137
150 static QList< double > getDoubleValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int *nullCount = nullptr, QgsFeedback *feedback = nullptr );
151
158 static bool valueExists( const QgsVectorLayer *layer, int fieldIndex, const QVariant &value, const QgsFeatureIds &ignoreIds = QgsFeatureIds() );
159
165 static QVariant createUniqueValue( const QgsVectorLayer *layer, int fieldIndex, const QVariant &seed = QVariant() );
166
173 static QVariant createUniqueValueFromCache( const QgsVectorLayer *layer, int fieldIndex, const QSet<QVariant> &existingValues, const QVariant &seed = QVariant() );
174
181 static bool attributeHasConstraints( const QgsVectorLayer *layer, int attributeIndex );
182
188 static bool validateAttribute( const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors SIP_OUT,
191
200 static QgsFeature createFeature( const QgsVectorLayer *layer,
201 const QgsGeometry &geometry = QgsGeometry(),
202 const QgsAttributeMap &attributes = QgsAttributeMap(),
203 QgsExpressionContext *context = nullptr );
204
212 static QgsFeatureList createFeatures( const QgsVectorLayer *layer,
213 const QgsFeaturesDataList &featuresData,
214 QgsExpressionContext *context = nullptr );
215
225 static QgsFeature duplicateFeature( QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, QgsDuplicateFeatureContext &duplicateFeatureContext SIP_OUT, const int maxDepth = 0, int depth SIP_PYARGREMOVE = 0, QList<QgsVectorLayer *> referencedLayersBranch SIP_PYARGREMOVE = QList<QgsVectorLayer *>() );
226
227
242 static std::unique_ptr<QgsVectorLayerFeatureSource> getFeatureSource( QPointer<QgsVectorLayer> layer, QgsFeedback *feedback = nullptr ) SIP_SKIP;
243
263 static void matchAttributesToFields( QgsFeature &feature, const QgsFields &fields );
264
286 static QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags() );
287
309 static QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags() );
310
319 static bool fieldIsEditable( const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature );
320
330 static bool fieldIsReadOnly( const QgsVectorLayer *layer, int fieldIndex );
331
341 static bool fieldEditabilityDependsOnFeature( const QgsVectorLayer *layer, int fieldIndex );
342
350 static QHash<QString, QgsMaskedLayers> labelMasks( const QgsVectorLayer * ) SIP_SKIP;
351
359 static QgsMaskedLayers symbolLayerMasks( const QgsVectorLayer * ) SIP_SKIP;
360
366 static QString getFeatureDisplayString( const QgsVectorLayer *layer, const QgsFeature &feature );
367
374 {
375 IgnoreAuxiliaryLayers = 1 << 1,
376 };
378
379
385 static bool impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsFeatureIds &fids, const QgsProject *project, QgsDuplicateFeatureContext &context SIP_OUT, QgsVectorLayerUtils::CascadedFeatureFlags flags = QgsVectorLayerUtils::CascadedFeatureFlags() );
386
387#ifndef SIP_RUN
388
409#else
410
428#endif
429 static QString guessFriendlyIdentifierField( const QgsFields &fields, bool *foundFriendly SIP_OUT = nullptr ) SIP_PYNAME( guessFriendlyIdentifierFieldV2 );
430
431#ifdef SIP_RUN
432
449 static QString guessFriendlyIdentifierField( const QgsFields &fields );
450#endif
451
452};
453
454
455#endif // QGSVECTORLAYERUTILS_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
Abstract base class for all 2D vector feature renderers.
An interface for objects which accept features via addFeature(s) methods.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
ConstraintStrength
Strength of constraints.
@ ConstraintStrengthNotSet
Constraint is not set.
ConstraintOrigin
Origin of constraints.
@ ConstraintOriginNotSet
Constraint is not set.
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
We may need stable references to symbol layers, when pointers to symbol layers are not usable (when a...
Abstract base class for symbol layers.
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds which list all the duplicated features...
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
Contains utility methods for working with QgsVectorLayers.
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
QFlags< CascadedFeatureFlag > CascadedFeatureFlags
CascadedFeatureFlag
Flags that can be used when determining cascaded features.
Represents a vector layer which manages a vector based dataset.
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_PYARGREMOVE
Definition qgis_sip.h:151
#define SIP_OUT
Definition qgis_sip.h:58
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QHash< QString, QgsMaskedLayer > QgsMaskedLayers
masked layers where key is the layer id
QSet< QString > symbolLayerIds