QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
24 class QgsFeatureRenderer;
25 class QgsSymbolLayer;
26 
35 class CORE_EXPORT QgsVectorLayerUtils
36 {
37  public:
38 
46  class CORE_EXPORT QgsDuplicateFeatureContext
47  {
48  public:
49 
51  QgsDuplicateFeatureContext() = default;
52 
57  QList<QgsVectorLayer *> layers() const;
58 
63  QgsFeatureIds duplicatedFeatures( QgsVectorLayer *layer ) const;
64 
65 
66  private:
67  QMap<QgsVectorLayer *, QgsFeatureIds> mDuplicatedFeatures;
68  friend class QgsVectorLayerUtils;
69 
74  void setDuplicatedFeatures( QgsVectorLayer *layer, const QgsFeatureIds &ids );
75  };
76 
84  class CORE_EXPORT QgsFeatureData
85  {
86  public:
87 
91  QgsFeatureData( const QgsGeometry &geometry = QgsGeometry(), const QgsAttributeMap &attributes = QgsAttributeMap() );
92 
94  QgsGeometry geometry() const;
95 
97  QgsAttributeMap attributes() const;
98 
99  private:
100  QgsGeometry mGeometry;
101  QgsAttributeMap mAttributes;
102  };
103 
104  // SIP does not like "using", use legacy typedef
106  typedef QList<QgsVectorLayerUtils::QgsFeatureData> QgsFeaturesDataList;
107 
117  static QgsFeatureIterator getValuesIterator( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly );
118 
130  static QList< QVariant > getValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, QgsFeedback *feedback = nullptr );
131 
145  static QList< double > getDoubleValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int *nullCount = nullptr, QgsFeedback *feedback = nullptr );
146 
153  static bool valueExists( const QgsVectorLayer *layer, int fieldIndex, const QVariant &value, const QgsFeatureIds &ignoreIds = QgsFeatureIds() );
154 
160  static QVariant createUniqueValue( const QgsVectorLayer *layer, int fieldIndex, const QVariant &seed = QVariant() );
161 
168  static QVariant createUniqueValueFromCache( const QgsVectorLayer *layer, int fieldIndex, const QSet<QVariant> &existingValues, const QVariant &seed = QVariant() );
169 
175  static bool validateAttribute( const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors SIP_OUT,
178 
187  static QgsFeature createFeature( const QgsVectorLayer *layer,
188  const QgsGeometry &geometry = QgsGeometry(),
189  const QgsAttributeMap &attributes = QgsAttributeMap(),
190  QgsExpressionContext *context = nullptr );
191 
199  static QgsFeatureList createFeatures( const QgsVectorLayer *layer,
200  const QgsFeaturesDataList &featuresData,
201  QgsExpressionContext *context = nullptr );
202 
211  static QgsFeature duplicateFeature( QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, int depth, QgsDuplicateFeatureContext &duplicateFeatureContext SIP_OUT );
212 
227  static std::unique_ptr<QgsVectorLayerFeatureSource> getFeatureSource( QPointer<QgsVectorLayer> layer, QgsFeedback *feedback = nullptr ) SIP_SKIP;
228 
248  static void matchAttributesToFields( QgsFeature &feature, const QgsFields &fields );
249 
268  static QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer );
269 
288  static QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer );
289 
296  static bool fieldIsEditable( const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature );
297 
305  static QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> labelMasks( const QgsVectorLayer * ) SIP_SKIP;
306 
314  static QHash<QString, QSet<QgsSymbolLayerId>> symbolLayerMasks( const QgsVectorLayer * ) SIP_SKIP;
315 
321  static QString getFeatureDisplayString( const QgsVectorLayer *layer, const QgsFeature &feature );
322 };
323 
324 
325 #endif // QGSVECTORLAYERUTILS_H
Wrapper for iterator of features from vector data provider or vector layer.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds do list all the duplicated features...
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:571
ConstraintOrigin
Origin of constraints.
Container of fields for a vector layer.
Definition: qgsfields.h:42
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:45
#define SIP_SKIP
Definition: qgis_sip.h:126
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:91
Contains utility methods for working with QgsVectorLayers.
ConstraintStrength
Strength of constraints.
#define SIP_OUT
Definition: qgis_sip.h:58
Represents a vector layer which manages a vector based data sets.
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.