QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
31 class CORE_EXPORT QgsVectorLayerUtils
32 {
33  public:
34 
42  class CORE_EXPORT QgsDuplicateFeatureContext
43  {
44  public:
45 
47  QgsDuplicateFeatureContext() = default;
48 
53  QList<QgsVectorLayer *> layers() const;
54 
59  QgsFeatureIds duplicatedFeatures( QgsVectorLayer *layer ) const;
60 
61 
62  private:
63  QMap<QgsVectorLayer *, QgsFeatureIds> mDuplicatedFeatures;
64  friend class QgsVectorLayerUtils;
65 
70  void setDuplicatedFeatures( QgsVectorLayer *layer, const QgsFeatureIds &ids );
71  };
72 
80  class CORE_EXPORT QgsFeatureData
81  {
82  public:
83 
87  QgsFeatureData( const QgsGeometry &geometry = QgsGeometry(), const QgsAttributeMap &attributes = QgsAttributeMap() );
88 
90  QgsGeometry geometry() const;
91 
93  QgsAttributeMap attributes() const;
94 
95  private:
96  QgsGeometry mGeometry;
97  QgsAttributeMap mAttributes;
98  };
99 
100  // SIP does not like "using", use legacy typedef
102  typedef QList<QgsVectorLayerUtils::QgsFeatureData> QgsFeaturesDataList;
103 
113  static QgsFeatureIterator getValuesIterator( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly );
114 
126  static QList< QVariant > getValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, QgsFeedback *feedback = nullptr );
127 
141  static QList< double > getDoubleValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int *nullCount = nullptr, QgsFeedback *feedback = nullptr );
142 
149  static bool valueExists( const QgsVectorLayer *layer, int fieldIndex, const QVariant &value, const QgsFeatureIds &ignoreIds = QgsFeatureIds() );
150 
156  static QVariant createUniqueValue( const QgsVectorLayer *layer, int fieldIndex, const QVariant &seed = QVariant() );
157 
164  static QVariant createUniqueValueFromCache( const QgsVectorLayer *layer, int fieldIndex, const QSet<QVariant> &existingValues, const QVariant &seed = QVariant() );
165 
171  static bool validateAttribute( const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors SIP_OUT,
174 
183  static QgsFeature createFeature( const QgsVectorLayer *layer,
184  const QgsGeometry &geometry = QgsGeometry(),
185  const QgsAttributeMap &attributes = QgsAttributeMap(),
186  QgsExpressionContext *context = nullptr );
187 
195  static QgsFeatureList createFeatures( const QgsVectorLayer *layer,
196  const QgsFeaturesDataList &featuresData,
197  QgsExpressionContext *context = nullptr );
198 
207  static QgsFeature duplicateFeature( QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, int depth, QgsDuplicateFeatureContext &duplicateFeatureContext SIP_OUT );
208 
223  static std::unique_ptr<QgsVectorLayerFeatureSource> getFeatureSource( QPointer<QgsVectorLayer> layer, QgsFeedback *feedback = nullptr ) SIP_SKIP;
224 
244  static void matchAttributesToFields( QgsFeature &feature, const QgsFields &fields );
245 
264  static QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer );
265 
284  static QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer );
285 
286 };
287 
288 
289 #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:111
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:44
#define SIP_SKIP
Definition: qgis_sip.h:119
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.
void seed(uint32_t value)
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
Reads and writes project states.
Definition: qgsproject.h:89
Contains utility methods for working with QgsVectorLayers.
ConstraintStrength
Strength of constraints.
#define SIP_OUT
Definition: qgis_sip.h:51
Represents a vector layer which manages a vector based data sets.
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.