QGIS API Documentation  3.17.0-Master (fba5093f18)
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 
388 {
389  Q_OBJECT
390 
391  Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
392  Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
393  Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
394  Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
395  Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
396  Q_PROPERTY( bool supportsEditing READ supportsEditing NOTIFY supportsEditingChanged )
397 
398  public:
399 
402  {
403  Success = 0,
404  EmptyGeometry = 1,
405  EditFailed = 2,
406  FetchFeatureFailed = 3,
407  InvalidLayer = 4,
408  };
409  Q_ENUM( EditResult )
410 
411 
413  {
418  };
419  Q_ENUM( SelectBehavior )
420 
421 
426  {
427 
431  explicit LayerOptions( bool loadDefaultStyle = true,
432  bool readExtentFromXml = false )
433  : loadDefaultStyle( loadDefaultStyle )
434  , readExtentFromXml( readExtentFromXml )
435  {}
436 
441  explicit LayerOptions( const QgsCoordinateTransformContext &transformContext,
442  bool loadDefaultStyle = true,
443  bool readExtentFromXml = false
444  )
445  : loadDefaultStyle( loadDefaultStyle )
446  , readExtentFromXml( readExtentFromXml )
447  , transformContext( transformContext )
448  {}
449 
451  bool loadDefaultStyle = true;
452 
457  bool readExtentFromXml = false;
458 
464 
477 
490 
504  bool skipCrsValidation = false;
505 
506  };
507 
512  struct CORE_EXPORT DeleteContext
513  {
514 
518  explicit DeleteContext( bool cascade = false, QgsProject *project = nullptr ): cascade( cascade ), project( project ) {}
519 
526  QList<QgsVectorLayer *> handledLayers( bool includeAuxiliaryLayers = true ) const;
527 
531  QgsFeatureIds handledFeatures( QgsVectorLayer *layer ) const;
532 
533  QMap<QgsVectorLayer *, QgsFeatureIds> mHandledFeatures SIP_SKIP;
534  bool cascade;
536  };
537 
551  explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(),
552  const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() );
553 
554  ~QgsVectorLayer() override;
555 
557  QgsVectorLayer( const QgsVectorLayer &rhs ) = delete;
559  QgsVectorLayer &operator=( QgsVectorLayer const &rhs ) = delete;
560 
561 #ifdef SIP_RUN
562  SIP_PYOBJECT __repr__();
563  % MethodCode
564  QString str = QStringLiteral( "<QgsVectorLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
565  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
566  % End
567 #endif
568 
577  QgsVectorLayer *clone() const override SIP_FACTORY;
578 
583  QString storageType() const;
584 
588  QString capabilitiesString() const;
589 
593  QString dataComment() const;
594 
602  QString displayField() const;
603 
611  void setDisplayExpression( const QString &displayExpression );
612 
619  QString displayExpression() const;
620 
621  QgsVectorDataProvider *dataProvider() FINAL;
622  const QgsVectorDataProvider *dataProvider() const FINAL SIP_SKIP;
623 
627  QgsMapLayerTemporalProperties *temporalProperties() override;
628 
639  void setProviderEncoding( const QString &encoding );
640 
642  void setCoordinateSystem();
643 
649  bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
650 
655  bool removeJoin( const QString &joinLayerId );
656 
661  QgsVectorLayerJoinBuffer *joinBuffer() { return mJoinBuffer; }
662 
667  const QgsVectorLayerJoinBuffer *joinBuffer() const { return mJoinBuffer; } SIP_SKIP;
668 
669  const QList<QgsVectorLayerJoinInfo> vectorJoins() const;
670 
679  bool setDependencies( const QSet<QgsMapLayerDependency> &layers ) FINAL;
680 
688  QSet<QgsMapLayerDependency> dependencies() const FINAL;
689 
700  int addExpressionField( const QString &exp, const QgsField &fld );
701 
709  void removeExpressionField( int index );
710 
720  QString expressionField( int index ) const;
721 
731  void updateExpressionField( int index, const QString &exp );
732 
739  QgsActionManager *actions() { return mActions; }
740 
746  const QgsActionManager *actions() const SIP_SKIP { return mActions; }
747 
752  QgsVectorLayerServerProperties *serverProperties() const { return mServerProperties.get(); }
753 
759  int selectedFeatureCount() const;
760 
770  Q_INVOKABLE void selectByRect( QgsRectangle &rect, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
771 
781  Q_INVOKABLE void selectByExpression( const QString &expression, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
782 
793  Q_INVOKABLE void selectByIds( const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
794 
806  Q_INVOKABLE void modifySelection( const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds );
807 
809  Q_INVOKABLE void invertSelection();
810 
812  Q_INVOKABLE void selectAll();
813 
821  Q_INVOKABLE void invertSelectionInRectangle( QgsRectangle &rect );
822 
835  Q_INVOKABLE QgsFeatureList selectedFeatures() const;
836 
852  QgsFeatureIterator getSelectedFeatures( QgsFeatureRequest request = QgsFeatureRequest() ) const;
853 
861  Q_INVOKABLE const QgsFeatureIds &selectedFeatureIds() const;
862 
864  Q_INVOKABLE QgsRectangle boundingBoxOfSelected() const;
865 
873  bool labelsEnabled() const;
874 
884  void setLabelsEnabled( bool enabled );
885 
891  bool diagramsEnabled() const;
892 
894  void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER );
895  const QgsDiagramRenderer *diagramRenderer() const { return mDiagramRenderer; }
896 
897  void setDiagramLayerSettings( const QgsDiagramLayerSettings &s );
898  const QgsDiagramLayerSettings *diagramLayerSettings() const { return mDiagramLayerSettings; }
899 
906  QgsFeatureRenderer *renderer() { return mRenderer; }
907 
915  const QgsFeatureRenderer *renderer() const SIP_SKIP { return mRenderer; }
916 
923  void setRenderer( QgsFeatureRenderer *r SIP_TRANSFER );
924 
934  void addFeatureRendererGenerator( QgsFeatureRendererGenerator *generator SIP_TRANSFER );
935 
945  void removeFeatureRendererGenerator( const QString &id );
946 
954  QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const;
955 
957  Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const;
958 
960  Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL;
961 
962  QgsCoordinateReferenceSystem sourceCrs() const FINAL;
963  QString sourceName() const FINAL;
964 
969  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) FINAL;
970 
975  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const FINAL;
976 
977  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const FINAL;
978  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const FINAL;
979 
984  void resolveReferences( QgsProject *project ) FINAL;
985 
994  virtual void saveStyleToDatabase( const QString &name, const QString &description,
995  bool useAsDefault, const QString &uiFileContent,
996  QString &msgError SIP_OUT );
997 
1007  virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
1008  QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
1009 
1013  virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
1014 
1022  virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
1023 
1031  virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
1032  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1033 
1038  QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT,
1039  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1040 
1054  bool loadAuxiliaryLayer( const QgsAuxiliaryStorage &storage, const QString &key = QString() );
1055 
1065  void setAuxiliaryLayer( QgsAuxiliaryLayer *layer SIP_TRANSFER = nullptr );
1066 
1072  QgsAuxiliaryLayer *auxiliaryLayer();
1073 
1079  const QgsAuxiliaryLayer *auxiliaryLayer() const SIP_SKIP;
1080 
1081  bool readSymbology( const QDomNode &layerNode, QString &errorMessage,
1082  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1083  bool readStyle( const QDomNode &node, QString &errorMessage,
1084  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1085  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1086  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const FINAL;
1087  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1088  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const FINAL;
1089 
1098  bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
1099 
1100  bool readSld( const QDomNode &node, QString &errorMessage ) FINAL;
1101 
1107  long featureCount( const QString &legendKey ) const;
1108 
1115  QgsFeatureIds symbolFeatureIds( const QString &legendKey ) const;
1116 
1127  FeatureAvailability hasFeatures() const FINAL;
1128 
1140  Q_DECL_DEPRECATED void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ) SIP_DEPRECATED;
1141 
1154  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;
1155 
1156  QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
1157 
1171  QgsVectorLayerFeatureCounter *countSymbolFeatures( bool storeSymbolFids = false );
1172 
1180  virtual bool setSubsetString( const QString &subset );
1181 
1186  virtual QString subsetString() const;
1187 
1193  QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const FINAL;
1194 
1198  inline QgsFeatureIterator getFeatures( const QString &expression )
1199  {
1200  return getFeatures( QgsFeatureRequest( expression ) );
1201  }
1202 
1207  inline QgsFeature getFeature( QgsFeatureId fid ) const
1208  {
1209  QgsFeature feature;
1210  getFeatures( QgsFeatureRequest( fid ) ).nextFeature( feature );
1211  return feature;
1212  }
1213 
1218  QgsGeometry getGeometry( QgsFeatureId fid ) const;
1219 
1224  {
1225  return getFeatures( QgsFeatureRequest( fids ) );
1226  }
1227 
1231  inline QgsFeatureIterator getFeatures( const QgsRectangle &rectangle )
1232  {
1233  return getFeatures( QgsFeatureRequest( rectangle ) );
1234  }
1235 
1236  bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1237 
1263  bool updateFeature( QgsFeature &feature, bool skipDefaultValues = false );
1264 
1276  bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
1277 
1289  bool insertVertex( const QgsPoint &point, QgsFeatureId atFeatureId, int beforeVertex );
1290 
1301  bool moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex );
1302 
1313  bool moveVertex( const QgsPoint &p, QgsFeatureId atFeatureId, int atVertex ) SIP_PYNAME( moveVertexV2 );
1314 
1325  EditResult deleteVertex( QgsFeatureId featureId, int vertex );
1326 
1334  Q_INVOKABLE bool deleteSelectedFeatures( int *deletedCount = nullptr, DeleteContext *context = nullptr );
1335 
1356  Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr ) SIP_DEPRECATED;
1357 
1358 
1378  Q_INVOKABLE QgsGeometry::OperationResult addRing( const QgsPointSequence &ring, QgsFeatureId *featureId = nullptr );
1379 
1400  Q_INVOKABLE QgsGeometry::OperationResult addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
1401 
1421  Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring ) SIP_DEPRECATED;
1422 
1443  Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QVector<QgsPointXY> &ring ) SIP_PYNAME( addPartV2 ) SIP_DEPRECATED;
1444 
1464  Q_INVOKABLE QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
1465 
1473  Q_INVOKABLE QgsGeometry::OperationResult addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
1474 
1486  Q_INVOKABLE int translateFeature( QgsFeatureId featureId, double dx, double dy );
1487 
1508  Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1509 
1529  Q_INVOKABLE QgsGeometry::OperationResult splitParts( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1530 
1551  Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1552 
1572  Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1573 
1596  Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsCurve *curve, QgsPointSequence &topologyTestPoints SIP_OUT, bool preserveCircular = false, bool topologicalEditing = false );
1597 
1608  int addTopologicalPoints( const QgsGeometry &geom );
1609 
1623  Q_DECL_DEPRECATED int addTopologicalPoints( const QgsPointXY &p ) SIP_DEPRECATED;
1624 
1638  int addTopologicalPoints( const QgsPoint &p );
1639 
1653  int addTopologicalPoints( const QgsPointSequence &ps );
1654 
1661  const QgsAbstractVectorLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
1662 
1669  QgsAbstractVectorLayerLabeling *labeling() { return mLabeling; }
1670 
1675  void setLabeling( QgsAbstractVectorLayerLabeling *labeling SIP_TRANSFER );
1676 
1678  bool isEditable() const FINAL;
1679 
1681  bool isSpatial() const FINAL;
1682 
1684  virtual bool isModified() const;
1685 
1692  bool isAuxiliaryField( int index, int &srcIndex ) const;
1693 
1695  void reload() FINAL;
1696 
1701  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) FINAL SIP_FACTORY;
1702 
1703  QgsRectangle extent() const FINAL;
1704  QgsRectangle sourceExtent() const FINAL;
1705 
1712  QgsFields fields() const FINAL;
1713 
1717  inline QgsAttributeList attributeList() const { return mFields.allAttributesList(); }
1718 
1722  QgsAttributeList primaryKeyAttributes() const;
1723 
1729  long featureCount() const FINAL;
1730 
1735  bool setReadOnly( bool readonly = true );
1736 
1742  bool supportsEditing();
1743 
1764  bool changeGeometry( QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue = false );
1765 
1796  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false );
1797 
1833  bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false );
1834 
1844  bool addAttribute( const QgsField &field );
1845 
1851  void setFieldAlias( int index, const QString &aliasString );
1852 
1858  void removeFieldAlias( int index );
1859 
1870  bool renameAttribute( int index, const QString &newName );
1871 
1878  QString attributeAlias( int index ) const;
1879 
1881  QString attributeDisplayName( int index ) const;
1882 
1884  QgsStringMap attributeAliases() const;
1885 
1890  Q_DECL_DEPRECATED QSet<QString> excludeAttributesWms() const SIP_DEPRECATED;
1891 
1896  Q_DECL_DEPRECATED void setExcludeAttributesWms( const QSet<QString> &att ) SIP_DEPRECATED;
1897 
1902  Q_DECL_DEPRECATED QSet<QString> excludeAttributesWfs() const SIP_DEPRECATED;
1903 
1908  Q_DECL_DEPRECATED void setExcludeAttributesWfs( const QSet<QString> &att ) SIP_DEPRECATED;
1909 
1918  virtual bool deleteAttribute( int attr );
1919 
1927  bool deleteAttributes( const QList<int> &attrs );
1928 
1929  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1930 
1941  bool deleteFeature( QgsFeatureId fid, DeleteContext *context = nullptr );
1942 
1956  bool deleteFeatures( const QgsFeatureIds &fids, DeleteContext *context = nullptr );
1957 
1981  Q_INVOKABLE bool commitChanges( bool stopEditing = true );
1982 
1988  QStringList commitErrors() const;
1989 
1999  Q_INVOKABLE bool rollBack( bool deleteBuffer = true );
2000 
2007  QList<QgsRelation> referencingRelations( int idx ) const;
2008 
2015  QList<QgsWeakRelation> weakRelations( ) const SIP_SKIP;
2016 
2017 
2019  Q_INVOKABLE QgsVectorLayerEditBuffer *editBuffer() { return mEditBuffer; }
2020 
2025  const QgsVectorLayerEditBuffer *editBuffer() const SIP_SKIP { return mEditBuffer; }
2026 
2031  void beginEditCommand( const QString &text );
2032 
2034  void endEditCommand();
2035 
2037  void destroyEditCommand();
2038 
2041  {
2044  NoMarker
2045  };
2046 
2051  Q_DECL_DEPRECATED static void drawVertexMarker( double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
2052 
2061  void updateFields();
2062 
2077  QVariant defaultValue( int index, const QgsFeature &feature = QgsFeature(),
2078  QgsExpressionContext *context = nullptr ) const;
2079 
2091  void setDefaultValueDefinition( int index, const QgsDefaultValue &definition );
2092 
2103  QgsDefaultValue defaultValueDefinition( int index ) const;
2104 
2112  QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
2113 
2119  QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength( int fieldIndex ) const;
2120 
2130 
2138  void removeFieldConstraint( int index, QgsFieldConstraints::Constraint constraint );
2139 
2147  QString constraintExpression( int index ) const;
2148 
2156  QString constraintDescription( int index ) const;
2157 
2166  void setConstraintExpression( int index, const QString &expression, const QString &description = QString() );
2167 
2173  void setFieldConfigurationFlags( int index, QgsField::ConfigurationFlags flags ) SIP_SKIP;
2174 
2179  void setFieldConfigurationFlag( int index, QgsField::ConfigurationFlag flag, bool active ) SIP_SKIP;
2180 
2186  QgsField::ConfigurationFlags fieldConfigurationFlags( int index ) const SIP_SKIP;
2187 
2191  void setEditorWidgetSetup( int index, const QgsEditorWidgetSetup &setup );
2192 
2199  QgsEditorWidgetSetup editorWidgetSetup( int index ) const;
2200 
2212  QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const FINAL;
2213 
2227  QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
2228  QgsFeedback *feedback = nullptr ) const;
2229 
2238  QVariant minimumValue( int index ) const FINAL;
2239 
2248  QVariant maximumValue( int index ) const FINAL;
2249 
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 ) const;
2268 
2270  void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2272  QPainter::CompositionMode featureBlendMode() const;
2273 
2274  QString htmlMetadata() const FINAL;
2275 
2280  void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mSimplifyMethod = simplifyMethod; }
2281 
2286  inline const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
2287 
2293  bool simplifyDrawingCanbeApplied( const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;
2294 
2302  QgsConditionalLayerStyles *conditionalStyles() const;
2303 
2308  QgsAttributeTableConfig attributeTableConfig() const;
2309 
2314  void setAttributeTableConfig( const QgsAttributeTableConfig &attributeTableConfig );
2315 
2323  QString mapTipTemplate() const;
2324 
2332  void setMapTipTemplate( const QString &mapTipTemplate );
2333 
2334  QgsExpressionContext createExpressionContext() const FINAL;
2335 
2336  QgsExpressionContextScope *createExpressionContextScope() const FINAL SIP_FACTORY;
2337 
2345  QgsEditFormConfig editFormConfig() const;
2346 
2353  void setEditFormConfig( const QgsEditFormConfig &editFormConfig );
2354 
2362  void setReadExtentFromXml( bool readExtentFromXml );
2363 
2371  bool readExtentFromXml() const;
2372 
2378  bool isEditCommandActive() const { return mEditCommandActive; }
2379 
2385  QgsGeometryOptions *geometryOptions() const;
2386 
2404  bool allowCommit() const SIP_SKIP;
2405 
2423  void setAllowCommit( bool allowCommit ) SIP_SKIP;
2424 
2430  QgsStoredExpressionManager *storedExpressionManager() { return mStoredExpressionManager; }
2431 
2432  public slots:
2433 
2441  void select( QgsFeatureId featureId );
2442 
2450  Q_INVOKABLE void select( const QgsFeatureIds &featureIds );
2451 
2459  void deselect( QgsFeatureId featureId );
2460 
2468  Q_INVOKABLE void deselect( const QgsFeatureIds &featureIds );
2469 
2476  Q_INVOKABLE void removeSelection();
2477 
2488  void reselect();
2489 
2496  virtual void updateExtents( bool force = false );
2497 
2512  Q_INVOKABLE bool startEditing();
2513 
2519  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
2520 
2521  SpatialIndexPresence hasSpatialIndex() const override;
2522 
2523  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
2524 
2525  signals:
2526 
2534  void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );
2535 
2537  void layerModified();
2538 
2544  void allowCommitChanged();
2545 
2547  void beforeModifiedCheck() const;
2548 
2550  void beforeEditingStarted();
2551 
2553  void editingStarted();
2554 
2556  void editingStopped();
2557 
2563  void beforeCommitChanges( bool stopEditing );
2564 
2566  void beforeRollBack();
2567 
2572  void afterCommitChanges();
2573 
2578  void afterRollBack();
2579 
2588  void attributeAdded( int idx );
2589 
2596  void beforeAddingExpressionField( const QString &fieldName );
2597 
2606  void attributeDeleted( int idx );
2607 
2614  void beforeRemovingExpressionField( int idx );
2615 
2621  void featureAdded( QgsFeatureId fid );
2622 
2631  void featureDeleted( QgsFeatureId fid );
2632 
2642  void featuresDeleted( const QgsFeatureIds &fids );
2643 
2648  void updatedFields();
2649 
2654  void subsetStringChanged();
2655 
2664  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
2665 
2673  void geometryChanged( QgsFeatureId fid, const QgsGeometry &geometry );
2674 
2676  void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
2678  void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
2680  void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
2682  void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
2684  void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
2686  void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
2687 
2689  void labelingFontNotFound( QgsVectorLayer *layer, const QString &fontfamily );
2690 
2692  void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2693 
2699  void editCommandStarted( const QString &text );
2700 
2706  void editCommandEnded();
2707 
2713  void editCommandDestroyed();
2714 
2724  void readCustomSymbology( const QDomElement &element, QString &errorMessage );
2725 
2735  void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage ) const;
2736 
2742  void mapTipTemplateChanged();
2743 
2749  void displayExpressionChanged();
2750 
2754  void raiseError( const QString &msg );
2755 
2761  void editFormConfigChanged();
2762 
2769  void readOnlyChanged();
2770 
2776  void supportsEditingChanged();
2777 
2783  void symbolFeatureCountMapChanged();
2784 
2785  protected:
2787  void setExtent( const QgsRectangle &rect ) FINAL;
2788 
2789  private slots:
2790  void invalidateSymbolCountedFlag();
2791  void onFeatureCounterCompleted();
2792  void onFeatureCounterTerminated();
2793  void onJoinedFieldsChanged();
2794  void onFeatureDeleted( QgsFeatureId fid );
2795  void onRelationsLoaded();
2796  void onSymbolsCounted();
2797  void onDirtyTransaction( const QString &sql, const QString &name );
2798  void emitDataChanged();
2799  void onAfterCommitChangesDependency();
2800 
2801  private:
2802  void updateDefaultValues( QgsFeatureId fid, QgsFeature feature = QgsFeature() );
2803 
2807  bool isReadOnly() const FINAL;
2808 
2815  bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
2816 
2818  void readSldLabeling( const QDomNode &node );
2819 
2821  bool readSldTextSymbolizer( const QDomNode &node, QgsPalLayerSettings &settings ) const;
2822 
2824  QgsAbstractVectorLayerLabeling *readLabelingFromCustomProperties();
2825 
2826  bool deleteFeatureCascade( QgsFeatureId fid, DeleteContext *context = nullptr );
2827 
2828 #ifdef SIP_RUN
2829  QgsVectorLayer( const QgsVectorLayer &rhs );
2830 #endif
2831  QVariant minimumOrMaximumValue( int index, bool minimum ) const;
2833 
2834  private: // Private attributes
2835  QgsConditionalLayerStyles *mConditionalStyles = nullptr;
2836 
2838  QgsVectorDataProvider *mDataProvider = nullptr;
2839 
2841  QgsVectorLayerTemporalProperties *mTemporalProperties = nullptr;
2842 
2844  QString mDisplayExpression;
2845 
2846  QString mMapTipTemplate;
2847 
2849  QgsActionManager *mActions = nullptr;
2850 
2852  bool mReadOnly = false;
2853 
2859  QgsFeatureIds mSelectedFeatureIds;
2860 
2864  QgsFeatureIds mPreviousSelectedFeatureIds;
2865 
2867  QgsFields mFields;
2868 
2870  QgsStringMap mAttributeAliasMap;
2871 
2873  QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2874 
2876  QSet<int> mDefaultValueOnUpdateFields;
2877 
2879  QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2880 
2882  QMap< QPair< QString, QgsFieldConstraints::Constraint >, QgsFieldConstraints::ConstraintStrength > mFieldConstraintStrength;
2883 
2885  QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2886 
2887  QMap< QString, QgsField::ConfigurationFlags > mFieldConfigurationFlags;
2888  QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2889 
2891  QgsEditFormConfig mEditFormConfig;
2892 
2895 
2897  QgsFeatureRenderer *mRenderer = nullptr;
2898 
2900  QgsVectorSimplifyMethod mSimplifyMethod;
2901 
2903  QgsAbstractVectorLayerLabeling *mLabeling = nullptr;
2904 
2906  bool mLabelsEnabled = false;
2907 
2909  bool mLabelFontNotFoundNotified = false;
2910 
2912  QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2913 
2915  bool mVertexMarkerOnlyForSelection = false;
2916 
2917  QStringList mCommitErrors;
2918 
2920  QgsVectorLayerEditBuffer *mEditBuffer = nullptr;
2923 
2924  //stores information about joined layers
2925  QgsVectorLayerJoinBuffer *mJoinBuffer = nullptr;
2926 
2928  std::unique_ptr< QgsVectorLayerServerProperties > mServerProperties;
2929 
2931  QgsExpressionFieldBuffer *mExpressionFieldBuffer = nullptr;
2932 
2933  //diagram rendering object. 0 if diagram drawing is disabled
2934  QgsDiagramRenderer *mDiagramRenderer = nullptr;
2935 
2936  //stores infos about diagram placement (placement type, priority, position distance)
2937  QgsDiagramLayerSettings *mDiagramLayerSettings = nullptr;
2938 
2939  mutable bool mValidExtent = false;
2940  mutable bool mLazyExtent = true;
2941 
2943  std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2944 
2946  QString mAuxiliaryLayerKey;
2947 
2948  // Features in renderer classes counted
2949  bool mSymbolFeatureCounted = false;
2950 
2951  // Feature counts for each renderer legend key
2952  QHash<QString, long> mSymbolFeatureCountMap;
2953  QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2954 
2956  bool mEditCommandActive = false;
2957 
2958  bool mReadExtentFromXml;
2959  QgsRectangle mXmlExtent;
2960 
2961  QgsFeatureIds mDeletedFids;
2962 
2963  QgsAttributeTableConfig mAttributeTableConfig;
2964 
2965  mutable QMutex mFeatureSourceConstructorMutex;
2966 
2967  QgsVectorLayerFeatureCounter *mFeatureCounter = nullptr;
2968 
2969  std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
2970 
2971  bool mAllowCommit = true;
2972 
2974  QgsStoredExpressionManager *mStoredExpressionManager = nullptr;
2975 
2977 
2979  bool mDataChangedFired = false;
2980 
2981  QList<QgsWeakRelation> mWeakRelations;
2982 
2983  bool mSetLegendFromStyle = false;
2984 
2985  QList< QgsFeatureRendererGenerator * > mRendererGenerators;
2986 };
2987 
2988 
2989 
2990 // clazy:excludeall=qstring-allocations
2991 
2992 #endif
QgsActionManager * actions()
Returns all layer actions defined on this layer.
The class is used as a container of context for various read/write operations on other objects...
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:609
DeleteContext(bool cascade=false, QgsProject *project=nullptr)
Constructor for DeleteContext.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:84
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
Implementation of map layer temporal properties for vector layers.
The QgsGeometryOptions class contains options to automatically adjust geometries to constraints on a ...
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
FeatureAvailability
Possible return value for hasFeatures() to determine if a source is empty.
The QgsDefaultValue class provides a container for managing client side default values for fields...
Constraint
Constraints which may be present on a field.
Setting options for loading vector layers.
Class allowing to manage the auxiliary storage for a vector layer.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:614
Manages an editor widget Widget and wrapper share the same parent.
Counts the features in a QgsVectorLayer in task.
LayerOptions(bool loadDefaultStyle=true, bool readExtentFromXml=false)
Constructor for LayerOptions.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
QgsStoredExpressionManager * storedExpressionManager()
Returns the manager of the stored expressions for this layer.
VertexMarkerType
Editing vertex markers.
An interface for objects which accept features via addFeature(s) methods.
QgsAbstractVectorLayerLabeling * labeling()
Access to labeling configuration.
Remove from current selection.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
SimplifyHint
Simplification flags for fast rendering of features.
Class providing some utility methods to manage auxiliary storage.
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
Container of fields for a vector layer.
Definition: qgsfields.h:44
An interface for objects which generate feature renderers for vector layers.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:123
The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields...
bool isEditCommandActive() const
Tests if an edit command is active.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
An interface for classes which can visit style entity (e.g.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:759
OperationResult
Success or failure of a geometry operation.
Definition: qgsgeometry.h:135
Manages joined fields for a vector layer.
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
Definition: qgsfield.h:81
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:43
const QgsVectorLayerJoinBuffer * joinBuffer() const
Returns a const pointer on join buffer object.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
LayerOptions(const QgsCoordinateTransformContext &transformContext, bool loadDefaultStyle=true, bool readExtentFromXml=false)
Constructor for LayerOptions.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
#define SIP_SKIP
Definition: qgis_sip.h:126
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsFeatureIterator getFeatures(const QString &expression)
Queries the layer for features matching a given expression.
Defines left outer join from our vector layer to some other vector layer.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsVectorLayerServerProperties * serverProperties() const
Returns QGIS Server Properties of the vector layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:98
Storage and management of actions associated with a layer.
QgsAttributeList attributeList() const
Returns list of attribute indexes.
Manages QGIS Server properties for a vector layer.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views...
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
#define SIP_FACTORY
Definition: qgis_sip.h:76
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:49
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Contains information about the context in which a coordinate transform is executed.
Add selection to current selection.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
const QgsDiagramRenderer * diagramRenderer() const
Abstract interface for generating an expression context.
Partial snapshot of vector layer&#39;s state (only the members necessary for access to features) ...
Set selection, removing any existing selection.
QgsFeatureIterator getFeatures(const QgsRectangle &rectangle)
Queries the layer for the features which intersect the specified rectangle.
Stores the settings for rendering of all diagrams for a layer.
QVector< QgsPoint > QgsPointSequence
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
Modify current selection to include only select features which match.
SelectBehavior
Selection behavior.
Base class for storage of map layer temporal properties.
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
Buffers information about expression fields for a vector layer.
#define FINAL
Definition: qgis_sip.h:228
Context for cascade delete features.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:600
Abstract interface for generating an expression context scope.
An interface for objects which provide features via a getFeatures method.
const QgsDiagramLayerSettings * diagramLayerSettings() const
ConstraintStrength
Strength of constraints.
Holder for the widget type and its configuration for a field.
This class manages a set of relations between layers.
#define SIP_OUT
Definition: qgis_sip.h:58
The QgsConditionalLayerStyles class holds conditional style information for a layer.
This class represents a coordinate reference system (CRS).
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Base class for utility classes that encapsulate information necessary for rendering of map layers...
SpatialIndexPresence
Enumeration of spatial index presence states.
const QgsFeatureRenderer * renderer() const
Returns the feature renderer used for rendering the features in the layer in 2D map views...
QSet< int > QgsAttributeIds
QList< int > QgsAttributeList
Definition: qgsfield.h:26
This is a container for configuration of the attribute table.
This is the base class for vector data providers.
QList< int > QgsAttributeList
QgsCoordinateReferenceSystem fallbackCrs
Fallback layer coordinate reference system.
const QgsActionManager * actions() const
Returns all layer actions defined on this layer.
Represents a vector layer which manages a vector based data sets.
const QgsVectorLayerEditBuffer * editBuffer() const
Buffer with uncommitted editing operations.
EditResult
Result of an edit operation.
QgsFeatureIterator getFeatures(const QgsFeatureIds &fids)
Queries the layer for the features with the given ids.
Constraint must be honored before feature can be accepted.
const QgsField & field
Definition: qgsfield.h:471
Manages stored expressions regarding creation, modification and storing in the project.
Abstract base class for simplify geometries using a specific algorithm.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81