QGIS API Documentation  3.21.0-Master (af9a72eda6)
qgsvectorlayer.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  -------------------
4  begin : Oct 29, 2003
5  copyright : (C) 2003 by Gary E.Sherman
6  email : sherman at mrcc.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSVECTORLAYER_H
19 #define QGSVECTORLAYER_H
20 
21 
22 #include "qgis_core.h"
23 #include <QMap>
24 #include <QSet>
25 #include <QList>
26 #include <QStringList>
27 #include <QFont>
28 #include <QMutex>
29 
30 #include "qgis.h"
31 #include "qgsmaplayer.h"
32 #include "qgsfeature.h"
33 #include "qgsfeaturerequest.h"
34 #include "qgsfeaturesource.h"
35 #include "qgsfields.h"
36 #include "qgsvectordataprovider.h"
39 #include "qgseditformconfig.h"
41 #include "qgsaggregatecalculator.h"
42 #include "qgsfeatureiterator.h"
45 #include "qgsexpressioncontext.h"
46 
47 class QPainter;
48 class QImage;
49 
51 class QgsActionManager;
53 class QgsCurve;
55 class QgsDiagramRenderer;
58 class QgsFeatureRenderer;
59 class QgsGeometry;
60 class QgsGeometryVertexIndex;
61 class QgsMapToPixel;
62 class QgsRectangle;
63 class QgsRectangle;
64 class QgsRelation;
65 class QgsWeakRelation;
66 class QgsRelationManager;
69 class QgsSymbol;
76 class QgsPoint;
77 class QgsFeedback;
79 class QgsAuxiliaryLayer;
80 class QgsGeometryOptions;
84 
85 typedef QList<int> QgsAttributeList;
86 typedef QSet<int> QgsAttributeIds;
87 
88 // TODO QGIS4: Remove virtual from non-inherited methods (like isModified)
89 
393 {
394  Q_OBJECT
395 
396  Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
397  Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
398  Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
399  Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
400  Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
401  Q_PROPERTY( bool supportsEditing READ supportsEditing NOTIFY supportsEditingChanged )
402 
403  public:
404 
410  {
411 
415  explicit LayerOptions( bool loadDefaultStyle = true,
416  bool readExtentFromXml = false )
417  : loadDefaultStyle( loadDefaultStyle )
418  , readExtentFromXml( readExtentFromXml )
419  {}
420 
425  explicit LayerOptions( const QgsCoordinateTransformContext &transformContext,
426  bool loadDefaultStyle = true,
427  bool readExtentFromXml = false
428  )
429  : loadDefaultStyle( loadDefaultStyle )
430  , readExtentFromXml( readExtentFromXml )
431  , transformContext( transformContext )
432  {}
433 
435  bool loadDefaultStyle = true;
436 
441  bool readExtentFromXml = false;
442 
448 
461 
474 
488  bool skipCrsValidation = false;
489 
490  };
491 
496  struct CORE_EXPORT DeleteContext
497  {
498 
502  explicit DeleteContext( bool cascade = false, QgsProject *project = nullptr ): cascade( cascade ), project( project ) {}
503 
510  QList<QgsVectorLayer *> handledLayers( bool includeAuxiliaryLayers = true ) const;
511 
515  QgsFeatureIds handledFeatures( QgsVectorLayer *layer ) const;
516 
517  QMap<QgsVectorLayer *, QgsFeatureIds> mHandledFeatures SIP_SKIP;
518  bool cascade;
520  };
521 
535  explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(),
536  const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() );
537 
538  ~QgsVectorLayer() override;
539 
541  QgsVectorLayer( const QgsVectorLayer &rhs ) = delete;
543  QgsVectorLayer &operator=( QgsVectorLayer const &rhs ) = delete;
544 
545 #ifdef SIP_RUN
546  SIP_PYOBJECT __repr__();
547  % MethodCode
548  QString str = QStringLiteral( "<QgsVectorLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
549  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
550  % End
551 #endif
552 
561  QgsVectorLayer *clone() const override SIP_FACTORY;
562 
567  QString storageType() const;
568 
572  QString capabilitiesString() const;
573 
577  QString dataComment() const;
578 
586  QString displayField() const;
587 
595  void setDisplayExpression( const QString &displayExpression );
596 
603  QString displayExpression() const;
604 
605  QgsVectorDataProvider *dataProvider() FINAL;
606  const QgsVectorDataProvider *dataProvider() const FINAL SIP_SKIP;
607 
611  QgsMapLayerTemporalProperties *temporalProperties() override;
612 
623  void setProviderEncoding( const QString &encoding );
624 
626  void setCoordinateSystem();
627 
633  bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
634 
639  bool removeJoin( const QString &joinLayerId );
640 
645  QgsVectorLayerJoinBuffer *joinBuffer() { return mJoinBuffer; }
646 
651  const QgsVectorLayerJoinBuffer *joinBuffer() const { return mJoinBuffer; } SIP_SKIP;
652 
653  const QList<QgsVectorLayerJoinInfo> vectorJoins() const;
654 
663  bool setDependencies( const QSet<QgsMapLayerDependency> &layers ) FINAL;
664 
672  QSet<QgsMapLayerDependency> dependencies() const FINAL;
673 
684  int addExpressionField( const QString &exp, const QgsField &fld );
685 
693  void removeExpressionField( int index );
694 
704  QString expressionField( int index ) const;
705 
715  void updateExpressionField( int index, const QString &exp );
716 
723  QgsActionManager *actions() { return mActions; }
724 
730  const QgsActionManager *actions() const SIP_SKIP { return mActions; }
731 
736  QgsVectorLayerServerProperties *serverProperties() const { return mServerProperties.get(); }
737 
743  int selectedFeatureCount() const;
744 
754  Q_INVOKABLE void selectByRect( QgsRectangle &rect, Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection );
755 
765  Q_INVOKABLE void selectByExpression( const QString &expression, Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection );
766 
777  Q_INVOKABLE void selectByIds( const QgsFeatureIds &ids, Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection );
778 
790  Q_INVOKABLE void modifySelection( const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds );
791 
793  Q_INVOKABLE void invertSelection();
794 
796  Q_INVOKABLE void selectAll();
797 
805  Q_INVOKABLE void invertSelectionInRectangle( QgsRectangle &rect );
806 
819  Q_INVOKABLE QgsFeatureList selectedFeatures() const;
820 
836  QgsFeatureIterator getSelectedFeatures( QgsFeatureRequest request = QgsFeatureRequest() ) const;
837 
845  Q_INVOKABLE const QgsFeatureIds &selectedFeatureIds() const;
846 
848  Q_INVOKABLE QgsRectangle boundingBoxOfSelected() const;
849 
857  bool labelsEnabled() const;
858 
868  void setLabelsEnabled( bool enabled );
869 
875  bool diagramsEnabled() const;
876 
878  void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER );
879  const QgsDiagramRenderer *diagramRenderer() const { return mDiagramRenderer; }
880 
881  void setDiagramLayerSettings( const QgsDiagramLayerSettings &s );
882  const QgsDiagramLayerSettings *diagramLayerSettings() const { return mDiagramLayerSettings; }
883 
890  QgsFeatureRenderer *renderer() { return mRenderer; }
891 
899  const QgsFeatureRenderer *renderer() const SIP_SKIP { return mRenderer; }
900 
907  void setRenderer( QgsFeatureRenderer *r SIP_TRANSFER );
908 
918  void addFeatureRendererGenerator( QgsFeatureRendererGenerator *generator SIP_TRANSFER );
919 
929  void removeFeatureRendererGenerator( const QString &id );
930 
938  QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const;
939 
941  Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const;
942 
944  Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL;
945 
946  QgsCoordinateReferenceSystem sourceCrs() const FINAL;
947  QString sourceName() const FINAL;
948 
953  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) FINAL;
954 
959  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const FINAL;
960 
961  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const FINAL;
962  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const FINAL;
963 
968  void resolveReferences( QgsProject *project ) FINAL;
969 
978  virtual void saveStyleToDatabase( const QString &name, const QString &description,
979  bool useAsDefault, const QString &uiFileContent,
980  QString &msgError SIP_OUT );
981 
991  virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
992  QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
993 
997  virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
998 
1006  virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
1007 
1015  virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
1016  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1017 
1022  QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT,
1023  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1024 
1038  bool loadAuxiliaryLayer( const QgsAuxiliaryStorage &storage, const QString &key = QString() );
1039 
1049  void setAuxiliaryLayer( QgsAuxiliaryLayer *layer SIP_TRANSFER = nullptr );
1050 
1056  QgsAuxiliaryLayer *auxiliaryLayer();
1057 
1063  const QgsAuxiliaryLayer *auxiliaryLayer() const SIP_SKIP;
1064 
1065  bool readSymbology( const QDomNode &layerNode, QString &errorMessage,
1066  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1067  bool readStyle( const QDomNode &node, QString &errorMessage,
1068  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1069  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1070  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const FINAL;
1071  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1072  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const FINAL;
1073 
1082  bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
1083 
1084  bool readSld( const QDomNode &node, QString &errorMessage ) FINAL;
1085 
1091  long long featureCount( const QString &legendKey ) const;
1092 
1099  QgsFeatureIds symbolFeatureIds( const QString &legendKey ) const;
1100 
1111  FeatureAvailability hasFeatures() const FINAL;
1112 
1113 
1114  QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
1115 
1129  QgsVectorLayerFeatureCounter *countSymbolFeatures( bool storeSymbolFids = false );
1130 
1138  virtual bool setSubsetString( const QString &subset );
1139 
1144  virtual QString subsetString() const;
1145 
1151  QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const FINAL;
1152 
1156  inline QgsFeatureIterator getFeatures( const QString &expression )
1157  {
1158  return getFeatures( QgsFeatureRequest( expression ) );
1159  }
1160 
1165  inline QgsFeature getFeature( QgsFeatureId fid ) const
1166  {
1167  QgsFeature feature;
1168  getFeatures( QgsFeatureRequest( fid ) ).nextFeature( feature );
1169  return feature;
1170  }
1171 
1176  QgsGeometry getGeometry( QgsFeatureId fid ) const;
1177 
1182  {
1183  return getFeatures( QgsFeatureRequest( fids ) );
1184  }
1185 
1189  inline QgsFeatureIterator getFeatures( const QgsRectangle &rectangle )
1190  {
1191  return getFeatures( QgsFeatureRequest( rectangle ) );
1192  }
1193 
1194  bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1195 
1221  bool updateFeature( QgsFeature &feature, bool skipDefaultValues = false );
1222 
1234  bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
1235 
1247  bool insertVertex( const QgsPoint &point, QgsFeatureId atFeatureId, int beforeVertex );
1248 
1259  bool moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex );
1260 
1271  bool moveVertex( const QgsPoint &p, QgsFeatureId atFeatureId, int atVertex ) SIP_PYNAME( moveVertexV2 );
1272 
1283  Qgis::VectorEditResult deleteVertex( QgsFeatureId featureId, int vertex );
1284 
1292  Q_INVOKABLE bool deleteSelectedFeatures( int *deletedCount = nullptr, DeleteContext *context = nullptr );
1293 
1314  Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr ) SIP_DEPRECATED;
1315 
1316 
1336  Q_INVOKABLE QgsGeometry::OperationResult addRing( const QgsPointSequence &ring, QgsFeatureId *featureId = nullptr );
1337 
1358  Q_INVOKABLE QgsGeometry::OperationResult addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
1359 
1379  Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring ) SIP_DEPRECATED;
1380 
1381 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1382 
1403  Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QVector<QgsPointXY> &ring ) SIP_PYNAME( addPartV2 ) SIP_DEPRECATED;
1404 #endif
1405 
1425  Q_INVOKABLE QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
1426 
1434  Q_INVOKABLE QgsGeometry::OperationResult addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
1435 
1447  Q_INVOKABLE int translateFeature( QgsFeatureId featureId, double dx, double dy );
1448 
1469  Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1470 
1490  Q_INVOKABLE QgsGeometry::OperationResult splitParts( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1491 
1512  Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1513 
1533  Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1534 
1557  Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsCurve *curve, QgsPointSequence &topologyTestPoints SIP_OUT, bool preserveCircular = false, bool topologicalEditing = false );
1558 
1572  int addTopologicalPoints( const QgsGeometry &geom );
1573 
1590  Q_DECL_DEPRECATED int addTopologicalPoints( const QgsPointXY &p ) SIP_DEPRECATED;
1591 
1608  int addTopologicalPoints( const QgsPoint &p );
1609 
1626  int addTopologicalPoints( const QgsPointSequence &ps );
1627 
1634  const QgsAbstractVectorLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
1635 
1642  QgsAbstractVectorLayerLabeling *labeling() { return mLabeling; }
1643 
1648  void setLabeling( QgsAbstractVectorLayerLabeling *labeling SIP_TRANSFER );
1649 
1651  bool isEditable() const FINAL;
1652 
1654  bool isSpatial() const FINAL;
1655 
1657  bool isModified() const override;
1658 
1665  bool isAuxiliaryField( int index, int &srcIndex ) const;
1666 
1668  void reload() FINAL;
1669 
1674  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) FINAL SIP_FACTORY;
1675 
1676  QgsRectangle extent() const FINAL;
1677  QgsRectangle sourceExtent() const FINAL;
1678 
1685  QgsFields fields() const FINAL;
1686 
1690  inline QgsAttributeList attributeList() const { return mFields.allAttributesList(); }
1691 
1695  QgsAttributeList primaryKeyAttributes() const;
1696 
1702  long long featureCount() const FINAL;
1703 
1708  bool setReadOnly( bool readonly = true );
1709 
1715  bool supportsEditing() const override;
1716 
1737  bool changeGeometry( QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue = false );
1738 
1769  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false );
1770 
1806  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false );
1807 
1817  bool addAttribute( const QgsField &field );
1818 
1824  void setFieldAlias( int index, const QString &aliasString );
1825 
1831  void removeFieldAlias( int index );
1832 
1843  bool renameAttribute( int index, const QString &newName );
1844 
1851  QString attributeAlias( int index ) const;
1852 
1854  QString attributeDisplayName( int index ) const;
1855 
1857  QgsStringMap attributeAliases() const;
1858 
1863  Q_DECL_DEPRECATED QSet<QString> excludeAttributesWms() const SIP_DEPRECATED;
1864 
1869  Q_DECL_DEPRECATED void setExcludeAttributesWms( const QSet<QString> &att ) SIP_DEPRECATED;
1870 
1875  Q_DECL_DEPRECATED QSet<QString> excludeAttributesWfs() const SIP_DEPRECATED;
1876 
1881  Q_DECL_DEPRECATED void setExcludeAttributesWfs( const QSet<QString> &att ) SIP_DEPRECATED;
1882 
1891  virtual bool deleteAttribute( int attr );
1892 
1900  bool deleteAttributes( const QList<int> &attrs );
1901 
1902  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1903 
1914  bool deleteFeature( QgsFeatureId fid, DeleteContext *context = nullptr );
1915 
1929  bool deleteFeatures( const QgsFeatureIds &fids, DeleteContext *context = nullptr );
1930 
1954  Q_INVOKABLE bool commitChanges( bool stopEditing = true );
1955 
1961  QStringList commitErrors() const;
1962 
1972  Q_INVOKABLE bool rollBack( bool deleteBuffer = true );
1973 
1980  QList<QgsRelation> referencingRelations( int idx ) const;
1981 
1988  QList<QgsWeakRelation> weakRelations( ) const SIP_SKIP;
1989 
1990 
1992  Q_INVOKABLE QgsVectorLayerEditBuffer *editBuffer() { return mEditBuffer; }
1993 
1998  const QgsVectorLayerEditBuffer *editBuffer() const SIP_SKIP { return mEditBuffer; }
1999 
2004  void beginEditCommand( const QString &text );
2005 
2007  void endEditCommand();
2008 
2010  void destroyEditCommand();
2011 
2016  Q_DECL_DEPRECATED static void drawVertexMarker( double x, double y, QPainter &p, Qgis::VertexMarkerType type, int vertexSize );
2017 
2026  void updateFields();
2027 
2042  QVariant defaultValue( int index, const QgsFeature &feature = QgsFeature(),
2043  QgsExpressionContext *context = nullptr ) const;
2044 
2056  void setDefaultValueDefinition( int index, const QgsDefaultValue &definition );
2057 
2068  QgsDefaultValue defaultValueDefinition( int index ) const;
2069 
2077  QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
2078 
2084  QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength( int fieldIndex ) const;
2085 
2095 
2103  void removeFieldConstraint( int index, QgsFieldConstraints::Constraint constraint );
2104 
2112  QString constraintExpression( int index ) const;
2113 
2121  QString constraintDescription( int index ) const;
2122 
2131  void setConstraintExpression( int index, const QString &expression, const QString &description = QString() );
2132 
2138  void setFieldConfigurationFlags( int index, QgsField::ConfigurationFlags flags ) SIP_SKIP;
2139 
2144  void setFieldConfigurationFlag( int index, QgsField::ConfigurationFlag flag, bool active ) SIP_SKIP;
2145 
2151  QgsField::ConfigurationFlags fieldConfigurationFlags( int index ) const SIP_SKIP;
2152 
2156  void setEditorWidgetSetup( int index, const QgsEditorWidgetSetup &setup );
2157 
2164  QgsEditorWidgetSetup editorWidgetSetup( int index ) const;
2165 
2177  QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const FINAL;
2178 
2192  QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
2193  QgsFeedback *feedback = nullptr ) const;
2194 
2209  QVariant minimumValue( int index ) const FINAL;
2210 
2225  QVariant maximumValue( int index ) const FINAL;
2226 
2227 
2247  void minimumAndMaximumValue( int index, QVariant &minimum SIP_OUT, QVariant &maximum SIP_OUT ) const;
2248 
2262  QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
2263  const QString &fieldOrExpression,
2264  const QgsAggregateCalculator::AggregateParameters &parameters = QgsAggregateCalculator::AggregateParameters(),
2265  QgsExpressionContext *context = nullptr,
2266  bool *ok = nullptr,
2267  QgsFeatureIds *fids = nullptr,
2268  QgsFeedback *feedback = nullptr ) const;
2269 
2271  void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2273  QPainter::CompositionMode featureBlendMode() const;
2274 
2275  QString htmlMetadata() const FINAL;
2276 
2281  void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mSimplifyMethod = simplifyMethod; }
2282 
2287  inline const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
2288 
2294  bool simplifyDrawingCanbeApplied( const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;
2295 
2303  QgsConditionalLayerStyles *conditionalStyles() const;
2304 
2309  QgsAttributeTableConfig attributeTableConfig() const;
2310 
2315  void setAttributeTableConfig( const QgsAttributeTableConfig &attributeTableConfig );
2316 
2324  QString mapTipTemplate() const;
2325 
2333  void setMapTipTemplate( const QString &mapTipTemplate );
2334 
2336 
2337  QgsExpressionContextScope *createExpressionContextScope() const FINAL SIP_FACTORY;
2338 
2346  QgsEditFormConfig editFormConfig() const;
2347 
2354  void setEditFormConfig( const QgsEditFormConfig &editFormConfig );
2355 
2363  void setReadExtentFromXml( bool readExtentFromXml );
2364 
2372  bool readExtentFromXml() const;
2373 
2379  bool isEditCommandActive() const { return mEditCommandActive; }
2380 
2386  QgsGeometryOptions *geometryOptions() const;
2387 
2405  bool allowCommit() const SIP_SKIP;
2406 
2424  void setAllowCommit( bool allowCommit ) SIP_SKIP;
2425 
2431  QgsStoredExpressionManager *storedExpressionManager() { return mStoredExpressionManager; }
2432 
2433  public slots:
2434 
2442  void select( QgsFeatureId featureId );
2443 
2451  Q_INVOKABLE void select( const QgsFeatureIds &featureIds );
2452 
2460  void deselect( QgsFeatureId featureId );
2461 
2469  Q_INVOKABLE void deselect( const QgsFeatureIds &featureIds );
2470 
2477  Q_INVOKABLE void removeSelection();
2478 
2489  void reselect();
2490 
2497  virtual void updateExtents( bool force = false );
2498 
2513  Q_INVOKABLE bool startEditing();
2514 
2520  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
2521 
2522  SpatialIndexPresence hasSpatialIndex() const override;
2523 
2524  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
2525 
2526  signals:
2527 
2535  void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );
2536 
2543 
2545  void beforeModifiedCheck() const;
2546 
2549 
2555  void beforeCommitChanges( bool stopEditing );
2556 
2559 
2565 
2571 
2580  void attributeAdded( int idx );
2581 
2588  void beforeAddingExpressionField( const QString &fieldName );
2589 
2598  void attributeDeleted( int idx );
2599 
2607 
2614 
2624 
2634  void featuresDeleted( const QgsFeatureIds &fids );
2635 
2641 
2647 
2656  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
2657 
2665  void geometryChanged( QgsFeatureId fid, const QgsGeometry &geometry );
2666 
2668  void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
2670  void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
2672  void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
2674  void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
2676  void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
2678  void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
2679 
2681  void labelingFontNotFound( QgsVectorLayer *layer, const QString &fontfamily );
2682 
2684  void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2685 
2691  void editCommandStarted( const QString &text );
2692 
2699 
2706 
2716  void readCustomSymbology( const QDomElement &element, QString &errorMessage );
2717 
2727  void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage ) const;
2728 
2735 
2742 
2746  void raiseError( const QString &msg );
2747 
2754 
2762 
2769 
2776 
2777  protected:
2779  void setExtent( const QgsRectangle &rect ) FINAL;
2780 
2781  private slots:
2782  void invalidateSymbolCountedFlag();
2783  void onFeatureCounterCompleted();
2784  void onFeatureCounterTerminated();
2785  void onJoinedFieldsChanged();
2786  void onFeatureDeleted( QgsFeatureId fid );
2787  void onRelationsLoaded();
2788  void onSymbolsCounted();
2789  void onDirtyTransaction( const QString &sql, const QString &name );
2790  void emitDataChanged();
2791  void onAfterCommitChangesDependency();
2792 
2793  private:
2794  void updateDefaultValues( QgsFeatureId fid, QgsFeature feature = QgsFeature() );
2795 
2799  bool isReadOnly() const FINAL;
2800 
2807  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
2808 
2820  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
2821 
2823  void readSldLabeling( const QDomNode &node );
2824 
2826  bool readSldTextSymbolizer( const QDomNode &node, QgsPalLayerSettings &settings ) const;
2827 
2829  QgsAbstractVectorLayerLabeling *readLabelingFromCustomProperties();
2830 
2831  bool deleteFeatureCascade( QgsFeatureId fid, DeleteContext *context = nullptr );
2832 
2833 #ifdef SIP_RUN
2834  QgsVectorLayer( const QgsVectorLayer &rhs );
2835 #endif
2837  void minimumOrMaximumValue( int index, QVariant *minimum, QVariant *maximum ) const;
2838 
2839  QgsConditionalLayerStyles *mConditionalStyles = nullptr;
2840 
2842  QgsVectorDataProvider *mDataProvider = nullptr;
2843 
2845  QgsVectorLayerTemporalProperties *mTemporalProperties = nullptr;
2846 
2848  QString mDisplayExpression;
2849 
2850  QString mMapTipTemplate;
2851 
2853  QgsActionManager *mActions = nullptr;
2854 
2856  bool mReadOnly = false;
2857 
2863  QgsFeatureIds mSelectedFeatureIds;
2864 
2868  QgsFeatureIds mPreviousSelectedFeatureIds;
2869 
2871  QgsFields mFields;
2872 
2874  QgsStringMap mAttributeAliasMap;
2875 
2877  QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2878 
2880  QSet<int> mDefaultValueOnUpdateFields;
2881 
2883  QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2884 
2886  QMap< QPair< QString, QgsFieldConstraints::Constraint >, QgsFieldConstraints::ConstraintStrength > mFieldConstraintStrength;
2887 
2889  QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2890 
2891  QMap< QString, QgsField::ConfigurationFlags > mFieldConfigurationFlags;
2892  QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2893 
2895  QgsEditFormConfig mEditFormConfig;
2896 
2899 
2901  QgsFeatureRenderer *mRenderer = nullptr;
2902 
2904  QgsVectorSimplifyMethod mSimplifyMethod;
2905 
2907  QgsAbstractVectorLayerLabeling *mLabeling = nullptr;
2908 
2910  bool mLabelsEnabled = false;
2911 
2913  bool mLabelFontNotFoundNotified = false;
2914 
2916  QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2917 
2919  bool mVertexMarkerOnlyForSelection = false;
2920 
2921  QStringList mCommitErrors;
2922 
2924  QgsVectorLayerEditBuffer *mEditBuffer = nullptr;
2927 
2928  //stores information about joined layers
2929  QgsVectorLayerJoinBuffer *mJoinBuffer = nullptr;
2930 
2932  std::unique_ptr< QgsVectorLayerServerProperties > mServerProperties;
2933 
2935  QgsExpressionFieldBuffer *mExpressionFieldBuffer = nullptr;
2936 
2937  //diagram rendering object. 0 if diagram drawing is disabled
2938  QgsDiagramRenderer *mDiagramRenderer = nullptr;
2939 
2940  //stores infos about diagram placement (placement type, priority, position distance)
2941  QgsDiagramLayerSettings *mDiagramLayerSettings = nullptr;
2942 
2943  mutable bool mValidExtent = false;
2944  mutable bool mLazyExtent = true;
2945 
2947  std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2948 
2950  QString mAuxiliaryLayerKey;
2951 
2952  // Features in renderer classes counted
2953  bool mSymbolFeatureCounted = false;
2954 
2955  // Feature counts for each renderer legend key
2956  QHash<QString, long long> mSymbolFeatureCountMap;
2957  QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2958 
2960  bool mEditCommandActive = false;
2961 
2962  bool mReadExtentFromXml;
2963  QgsRectangle mXmlExtent;
2964 
2965  QgsFeatureIds mDeletedFids;
2966 
2967  QgsAttributeTableConfig mAttributeTableConfig;
2968 
2969  mutable QMutex mFeatureSourceConstructorMutex;
2970 
2971  QgsVectorLayerFeatureCounter *mFeatureCounter = nullptr;
2972 
2973  std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
2974 
2975  bool mAllowCommit = true;
2976 
2978  QgsStoredExpressionManager *mStoredExpressionManager = nullptr;
2979 
2981 
2983  bool mDataChangedFired = false;
2984 
2985  QList<QgsWeakRelation> mWeakRelations;
2986 
2987  bool mSetLegendFromStyle = false;
2988 
2989  QList< QgsFeatureRendererGenerator * > mRendererGenerators;
2990 };
2991 
2992 
2993 
2994 // clazy:excludeall=qstring-allocations
2995 
2996 #endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:63
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition: qgis.h:529
SelectBehavior
Specifies how a selection should be applied.
Definition: qgis.h:500
@ SetSelection
Set selection, removing any existing selection.
Abstract base class for simplify geometries using a specific algorithm.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Storage and management of actions associated with a layer.
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
This is a container for configuration of the attribute table.
Class allowing to manage the auxiliary storage for a vector layer.
Class providing some utility methods to manage auxiliary storage.
The QgsConditionalLayerStyles class holds conditional style information for a layer.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
Abstract base class for spatial data provider implementations.
The QgsDefaultValue class provides a container for managing client side default values for fields.
Stores the settings for rendering of all diagrams for a layer.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
Holder for the widget type and its configuration for a field.
Manages an editor widget Widget and wrapper share the same parent.
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Buffers information about expression fields for a vector layer.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
An interface for objects which generate feature renderers for vector layers.
This class wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which accept features via addFeature(s) methods.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
An interface for objects which provide features via a getFeatures method.
virtual QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const
Returns the set of unique values contained within the specified fieldIndex from this source.
virtual QgsWkbTypes::Type wkbType() const =0
Returns the geometry type for features returned by this source.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown.
virtual SpatialIndexPresence hasSpatialIndex() const
Returns an enum value representing the presence of a valid spatial index on the source,...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
ConstraintStrength
Strength of constraints.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
Constraint
Constraints which may be present on a field.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
Definition: qgsfield.h:80
Container of fields for a vector layer.
Definition: qgsfields.h:45
The QgsGeometryOptions class contains options to automatically adjust geometries to constraints on a ...
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
OperationResult
Success or failure of a geometry operation.
Definition: qgsgeometry.h:136
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Definition: qgsmaplayer.h:71
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
friend class QgsVectorLayer
Definition: qgsmaplayer.h:2059
virtual bool isEditable() const
Returns true if the layer can be edited.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
Contains settings for how a map layer will be labeled.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
This class manages a set of relations between layers.
Contains information about the context of a rendering operation.
Manages stored expressions regarding creation, modification and storing in the project.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
This is the base class for vector data providers.
Counts the features in a QgsVectorLayer in task.
Partial snapshot of vector layer's state (only the members necessary for access to features)
Manages joined fields for a vector layer.
Defines left outer join from our vector layer to some other vector layer.
Manages QGIS Server properties for a vector layer.
Implementation of map layer temporal properties for vector layers.
Represents a vector layer which manages a vector based data sets.
const QgsActionManager * actions() const
Returns all layer actions defined on this layer.
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
Emitted when features are added to the provider.
void labelingFontNotFound(QgsVectorLayer *layer, const QString &fontfamily)
Emitted when the font family defined for labeling layer is not found on system.
void featureBlendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when setFeatureBlendMode() is called.
QgsVectorLayerServerProperties * serverProperties() const
Returns QGIS Server Properties of the vector layer.
void beforeRemovingExpressionField(int idx)
Will be emitted, when an expression field is going to be deleted from this vector layer.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
Emitted when geometry changes are saved to the provider.
void beforeCommitChanges(bool stopEditing)
Emitted before changes are committed to the data provider.
void mapTipTemplateChanged()
Emitted when the map tip changes.
void attributeAdded(int idx)
Will be emitted, when a new attribute has been added to this vector layer.
void allowCommitChanged()
Emitted whenever the allowCommitChanged() property of this layer changes.
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
QgsVectorLayer & operator=(QgsVectorLayer const &rhs)=delete
QgsVectorLayer cannot be copied.
void editCommandDestroyed()
Signal emitted, when an edit command is destroyed.
QgsVectorLayer(const QgsVectorLayer &rhs)=delete
QgsVectorLayer cannot be copied.
const QgsDiagramLayerSettings * diagramLayerSettings() const
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
void subsetStringChanged()
Emitted when the layer's subset string has changed.
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
Emitted when features are deleted from the provider.
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
void writeCustomSymbology(QDomElement &element, QDomDocument &doc, QString &errorMessage) const
Signal emitted whenever the symbology (QML-file) for this layer is being written.
QgsAbstractVectorLayerLabeling * labeling()
Access to labeling configuration.
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
void beforeEditingStarted()
Emitted before editing on this layer is started.
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
Emitted when attribute value changes are saved to the provider.
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
Emitted when attributes are added to the provider.
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Emitted when attributes are deleted from the provider.
void displayExpressionChanged()
Emitted when the display expression changes.
void editFormConfigChanged()
Will be emitted whenever the edit form configuration of this layer changes.
void afterCommitChanges()
Emitted after changes are committed to the data provider.
const QgsFeatureRenderer * renderer() const
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
void raiseError(const QString &msg)
Signals an error related to this vector layer.
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
void supportsEditingChanged()
Emitted when the read only state or the data provider of this layer is changed.
void readOnlyChanged()
Emitted when the read only state of this layer is changed.
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Emitted whenever an attribute value change is done in the edit buffer.
QgsFeatureIterator getFeatures(const QgsFeatureIds &fids)
Queries the layer for the features with the given ids.
void afterRollBack()
Emitted after changes are rolled back.
const QgsVectorLayerJoinBuffer * joinBuffer() const
Returns a const pointer on join buffer object.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
void beforeAddingExpressionField(const QString &fieldName)
Will be emitted, when an expression field is going to be added to this vector layer.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer.
void featureDeleted(QgsFeatureId fid)
Emitted when a feature has been deleted.
void readCustomSymbology(const QDomElement &element, QString &errorMessage)
Signal emitted whenever the symbology (QML-file) for this layer is being read.
void beforeRollBack()
Emitted before changes are rolled back.
const QgsDiagramRenderer * diagramRenderer() const
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geometry)
Emitted whenever a geometry change is done in the edit buffer.
QgsFeatureIterator getFeatures(const QgsRectangle &rectangle)
Queries the layer for the features which intersect the specified rectangle.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
void beforeModifiedCheck() const
Emitted when the layer is checked for modifications. Use for last-minute additions.
const QgsVectorLayerEditBuffer * editBuffer() const
Buffer with uncommitted editing operations.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
This class contains information how to simplify geometries fetched from a vector layer.
SimplifyHint
Simplification flags for fast rendering of features.
The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
#define str(x)
Definition: qgis.cpp:37
QMap< QString, QString > QgsStringMap
Definition: qgis.h:1262
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define FINAL
Definition: qgis_sip.h:228
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
QVector< QgsPoint > QgsPointSequence
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:826
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:817
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:831
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QList< int > QgsAttributeList
Definition: qgsfield.h:26
const QgsField & field
Definition: qgsfield.h:463
QList< int > QgsAttributeList
QSet< int > QgsAttributeIds
Context for cascade delete features.
DeleteContext(bool cascade=false, QgsProject *project=nullptr)
Constructor for DeleteContext.
Setting options for loading vector layers.
LayerOptions(bool loadDefaultStyle=true, bool readExtentFromXml=false)
Constructor for LayerOptions.
LayerOptions(const QgsCoordinateTransformContext &transformContext, bool loadDefaultStyle=true, bool readExtentFromXml=false)
Constructor for LayerOptions.
QgsCoordinateReferenceSystem fallbackCrs
Fallback layer coordinate reference system.