QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
23 #include "qgsfeaturesink.h"
24 
25 class QgsFeatureRenderer;
26 class QgsSymbolLayer;
27 
36 class CORE_EXPORT QgsVectorLayerUtils
37 {
38  public:
39 
47  class CORE_EXPORT QgsDuplicateFeatureContext
48  {
49  public:
50 
53 
58  QList<QgsVectorLayer *> layers() const;
59 
64  QgsFeatureIds duplicatedFeatures( QgsVectorLayer *layer ) const;
65 
66 
67  private:
68  QMap<QgsVectorLayer *, QgsFeatureIds> mDuplicatedFeatures;
69  friend class QgsVectorLayerUtils;
70 
75  void setDuplicatedFeatures( QgsVectorLayer *layer, const QgsFeatureIds &ids );
76  };
77 
85  class CORE_EXPORT QgsFeatureData
86  {
87  public:
88 
92  QgsFeatureData( const QgsGeometry &geometry = QgsGeometry(), const QgsAttributeMap &attributes = QgsAttributeMap() );
93 
95  QgsGeometry geometry() const;
96 
98  QgsAttributeMap attributes() const;
99 
100  private:
101  QgsGeometry mGeometry;
102  QgsAttributeMap mAttributes;
103  };
104 
105  // SIP does not like "using", use legacy typedef
107  typedef QList<QgsVectorLayerUtils::QgsFeatureData> QgsFeaturesDataList;
108 
118  static QgsFeatureIterator getValuesIterator( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly );
119 
131  static QList< QVariant > getValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, QgsFeedback *feedback = nullptr );
132 
146  static QList< double > getDoubleValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int *nullCount = nullptr, QgsFeedback *feedback = nullptr );
147 
154  static bool valueExists( const QgsVectorLayer *layer, int fieldIndex, const QVariant &value, const QgsFeatureIds &ignoreIds = QgsFeatureIds() );
155 
161  static QVariant createUniqueValue( const QgsVectorLayer *layer, int fieldIndex, const QVariant &seed = QVariant() );
162 
169  static QVariant createUniqueValueFromCache( const QgsVectorLayer *layer, int fieldIndex, const QSet<QVariant> &existingValues, const QVariant &seed = QVariant() );
170 
176  static bool validateAttribute( const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors SIP_OUT,
179 
188  static QgsFeature createFeature( const QgsVectorLayer *layer,
189  const QgsGeometry &geometry = QgsGeometry(),
190  const QgsAttributeMap &attributes = QgsAttributeMap(),
191  QgsExpressionContext *context = nullptr );
192 
200  static QgsFeatureList createFeatures( const QgsVectorLayer *layer,
201  const QgsFeaturesDataList &featuresData,
202  QgsExpressionContext *context = nullptr );
203 
212  static QgsFeature duplicateFeature( QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, int depth, QgsDuplicateFeatureContext &duplicateFeatureContext SIP_OUT );
213 
228  static std::unique_ptr<QgsVectorLayerFeatureSource> getFeatureSource( QPointer<QgsVectorLayer> layer, QgsFeedback *feedback = nullptr ) SIP_SKIP;
229 
249  static void matchAttributesToFields( QgsFeature &feature, const QgsFields &fields );
250 
272  static QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags() );
273 
295  static QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags() );
296 
303  static bool fieldIsEditable( const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature );
304 
312  static QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> labelMasks( const QgsVectorLayer * ) SIP_SKIP;
313 
321  static QHash<QString, QSet<QgsSymbolLayerId>> symbolLayerMasks( const QgsVectorLayer * ) SIP_SKIP;
322 
328  static QString getFeatureDisplayString( const QgsVectorLayer *layer, const QgsFeature &feature );
329 
336  {
337  IgnoreAuxiliaryLayers = 1 << 1,
338  };
339  Q_DECLARE_FLAGS( CascadedFeatureFlags, CascadedFeatureFlag )
340 
341 
347  static bool impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsFeatureIds &fids, const QgsProject *project, QgsDuplicateFeatureContext &context SIP_OUT, QgsVectorLayerUtils::CascadedFeatureFlags flags = QgsVectorLayerUtils::CascadedFeatureFlags() );
348 
349 };
350 
351 
352 #endif // QGSVECTORLAYERUTILS_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsVectorLayerUtils::QgsDuplicateFeatureContext::QgsDuplicateFeatureContext
QgsDuplicateFeatureContext()=default
Constructor for QgsDuplicateFeatureContext.
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
qgsfeaturesink.h
QgsVectorLayerUtils::QgsFeatureData
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
Definition: qgsvectorlayerutils.h:86
qgssymbollayerreference.h
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsVectorLayerUtils::CascadedFeatureFlag
CascadedFeatureFlag
Flags that can be used when determining cascaded features.
Definition: qgsvectorlayerutils.h:336
QgsSymbolLayer
Definition: qgssymbollayer.h:53
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsVectorLayerUtils::QgsFeaturesDataList
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
Definition: qgsvectorlayerutils.h:107
QgsFieldConstraints::ConstraintOrigin
ConstraintOrigin
Origin of constraints.
Definition: qgsfieldconstraints.h:55
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsVectorLayerUtils::QgsDuplicateFeatureContext
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds do list all the duplicated features.
Definition: qgsvectorlayerutils.h:48
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
QgsAttributeMap
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
QgsFieldConstraints::ConstraintStrengthNotSet
@ ConstraintStrengthNotSet
Constraint is not set.
Definition: qgsfieldconstraints.h:66
qgsvectorlayerfeatureiterator.h
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QgsFieldConstraints::ConstraintOriginNotSet
@ ConstraintOriginNotSet
Constraint is not set.
Definition: qgsfieldconstraints.h:56
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:103
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsSymbolLayerId
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
Definition: qgssymbollayerreference.h:54
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsVectorLayerUtils
Contains utility methods for working with QgsVectorLayers.
Definition: qgsvectorlayerutils.h:37
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:65
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:265
QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.
Definition: qgsfeaturesink.h:34
symbolLayerMasks
QList< QPair< QgsSymbolLayerId, QList< QgsSymbolLayerReference > > > symbolLayerMasks(const QgsVectorLayer *layer)
Symbol layer masks collector.
Definition: qgsmaskingwidget.cpp:150