QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
269  static QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer );
270 
290  static QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer );
291 
298  static bool fieldIsEditable( const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature );
299 
307  static QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> labelMasks( const QgsVectorLayer * ) SIP_SKIP;
308 
316  static QHash<QString, QSet<QgsSymbolLayerId>> symbolLayerMasks( const QgsVectorLayer * ) SIP_SKIP;
317 
323  static QString getFeatureDisplayString( const QgsVectorLayer *layer, const QgsFeature &feature );
324 
331  static bool impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsFeatureIds &fids, const QgsProject *project, QgsDuplicateFeatureContext &context SIP_OUT );
332 
333 };
334 
335 
336 #endif // QGSVECTORLAYERUTILS_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsFields
Definition: qgsfields.h:44
QgsVectorLayerUtils::QgsFeatureData
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
Definition: qgsvectorlayerutils.h:84
qgssymbollayerreference.h
QgsProject
Definition: qgsproject.h:92
QgsSymbolLayer
Definition: qgssymbollayer.h:52
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsVectorLayerUtils::QgsFeaturesDataList
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
Definition: qgsvectorlayerutils.h:106
QgsFieldConstraints::ConstraintOrigin
ConstraintOrigin
Origin of constraints.
Definition: qgsfieldconstraints.h:54
QgsFeedback
Definition: qgsfeedback.h:43
QgsVectorLayerUtils::QgsDuplicateFeatureContext
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds do list all the duplicated features.
Definition: qgsvectorlayerutils.h:46
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:572
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:34
QgsFieldConstraints::ConstraintOriginNotSet
@ ConstraintOriginNotSet
Constraint is not set.
Definition: qgsfieldconstraints.h:56
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsGeometry
Definition: qgsgeometry.h:122
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsSymbolLayerId
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
Definition: qgssymbollayerreference.h:53
QgsFeature
Definition: qgsfeature.h:55
QgsVectorLayerUtils
Contains utility methods for working with QgsVectorLayers.
Definition: qgsvectorlayerutils.h:35
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:64
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263
symbolLayerMasks
QList< QPair< QgsSymbolLayerId, QList< QgsSymbolLayerReference > > > symbolLayerMasks(const QgsVectorLayer *layer)
Symbol layer masks collector.
Definition: qgsmaskingwidget.cpp:150