QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Classes | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Properties | Friends | List of all members
QgsVectorLayer Class Reference

Represents a vector layer which manages a vector based data sets. More...

#include <qgsvectorlayer.h>

Inheritance diagram for QgsVectorLayer:
Inheritance graph
[legend]

Classes

struct  DeleteContext
 Context for cascade delete features. More...
 
struct  LayerOptions
 Setting options for loading vector layers. More...
 

Public Slots

bool accept (QgsStyleEntityVisitorInterface *visitor) const override
 
Q_INVOKABLE void deselect (const QgsFeatureIds &featureIds)
 Deselects features by their ID.
 
void deselect (QgsFeatureId featureId)
 Deselects feature by its ID.
 
QgsFeatureSource::SpatialIndexPresence hasSpatialIndex () const override
 
Q_INVOKABLE void removeSelection ()
 Clear selection.
 
void reselect ()
 Reselects the previous set of selected features.
 
Q_INVOKABLE void select (const QgsFeatureIds &featureIds)
 Selects features by their ID.
 
void select (QgsFeatureId featureId)
 Selects feature by its ID.
 
virtual void setTransformContext (const QgsCoordinateTransformContext &transformContext) override
 Sets the coordinate transform context to transformContext.
 
Q_INVOKABLE bool startEditing ()
 Makes the layer editable.
 
virtual void updateExtents (bool force=false)
 Update the extents for the layer.
 
- Public Slots inherited from QgsMapLayer
void emitStyleChanged ()
 Triggers an emission of the styleChanged() signal.
 
QgsProjectproject () const
 Returns the parent project if this map layer is added to a project.
 
void setMaximumScale (double scale)
 Sets the maximum map scale (i.e.
 
void setMinimumScale (double scale)
 Sets the minimum map scale (i.e.
 
void setRefreshOnNofifyMessage (const QString &message)
 Set the notification message that triggers repaint If refresh on notification is enabled, the notification will triggerRepaint only if the notification message is equal to.
 
void setRefreshOnNotifyEnabled (bool enabled)
 Set whether provider notification is connected to triggerRepaint.
 
void setScaleBasedVisibility (bool enabled)
 Sets whether scale based visibility is enabled for the layer.
 
virtual void setTransformContext (const QgsCoordinateTransformContext &transformContext)=0
 Sets the coordinate transform context to transformContext.
 
void trigger3DUpdate ()
 Will advise any 3D maps that this layer requires to be updated in the scene.
 
void triggerRepaint (bool deferredUpdate=false)
 Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
 

Signals

void afterCommitChanges ()
 Emitted after changes are committed to the data provider.
 
void afterRollBack ()
 Emitted after changes are rolled back.
 
void allowCommitChanged ()
 Emitted whenever the allowCommitChanged() property of this layer changes.
 
void attributeAdded (int idx)
 Will be emitted, when a new attribute has been added to this vector layer.
 
void attributeDeleted (int idx)
 Will be emitted, when an attribute has been deleted from this vector layer.
 
void attributeValueChanged (QgsFeatureId fid, int idx, const QVariant &value)
 Emitted whenever an attribute value change is done in the edit buffer.
 
void beforeAddingExpressionField (const QString &fieldName)
 Will be emitted, when an expression field is going to be added to this vector layer.
 
void beforeCommitChanges (bool stopEditing)
 Emitted before changes are committed to the data provider.
 
void beforeEditingStarted ()
 Emitted before editing on this layer is started.
 
void beforeModifiedCheck () const
 Emitted when the layer is checked for modifications. Use for last-minute additions.
 
void beforeRemovingExpressionField (int idx)
 Will be emitted, when an expression field is going to be deleted from this vector layer.
 
void beforeRollBack ()
 Emitted before changes are rolled back.
 
void committedAttributesAdded (const QString &layerId, const QList< QgsField > &addedAttributes)
 Emitted when attributes are added to the provider if not in transaction mode.
 
void committedAttributesDeleted (const QString &layerId, const QgsAttributeList &deletedAttributes)
 Emitted when attributes are deleted from the provider if not in transaction mode.
 
void committedAttributeValuesChanges (const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
 Emitted when attribute value changes are saved to the provider if not in transaction mode.
 
void committedFeaturesAdded (const QString &layerId, const QgsFeatureList &addedFeatures)
 Emitted when features are added to the provider if not in transaction mode.
 
void committedFeaturesRemoved (const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
 Emitted when features are deleted from the provider if not in transaction mode.
 
void committedGeometriesChanges (const QString &layerId, const QgsGeometryMap &changedGeometries)
 Emitted when geometry changes are saved to the provider if not in transaction mode.
 
void displayExpressionChanged ()
 Emitted when the display expression changes.
 
void editCommandDestroyed ()
 Signal emitted, when an edit command is destroyed.
 
void editCommandEnded ()
 Signal emitted, when an edit command successfully ended.
 
void editCommandStarted (const QString &text)
 Signal emitted when a new edit command has been started.
 
void editFormConfigChanged ()
 Will be emitted whenever the edit form configuration of this layer changes.
 
void featureAdded (QgsFeatureId fid)
 Emitted when a new feature has been added to the layer.
 
void featureBlendModeChanged (QPainter::CompositionMode blendMode)
 Signal emitted when setFeatureBlendMode() is called.
 
void featureDeleted (QgsFeatureId fid)
 Emitted when a feature has been deleted.
 
void featuresDeleted (const QgsFeatureIds &fids)
 Emitted when features have been deleted.
 
void geometryChanged (QgsFeatureId fid, const QgsGeometry &geometry)
 Emitted whenever a geometry change is done in the edit buffer.
 
void labelingFontNotFound (QgsVectorLayer *layer, const QString &fontfamily)
 Emitted when the font family defined for labeling layer is not found on system.
 
void raiseError (const QString &msg)
 Signals an error related to this vector layer.
 
void readCustomSymbology (const QDomElement &element, QString &errorMessage)
 Signal emitted whenever the symbology (QML-file) for this layer is being read.
 
void readOnlyChanged ()
 Emitted when the read only state of this layer is changed.
 
void selectionChanged (const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
 Emitted when selection was changed.
 
void subsetStringChanged ()
 Emitted when the layer's subset string has changed.
 
void supportsEditingChanged ()
 Emitted when the read only state or the data provider of this layer is changed.
 
void symbolFeatureCountMapChanged ()
 Emitted when the feature count for symbols on this layer has been recalculated.
 
void updatedFields ()
 Emitted whenever the fields available from this layer have been changed.
 
void writeCustomSymbology (QDomElement &element, QDomDocument &doc, QString &errorMessage) const
 Signal emitted whenever the symbology (QML-file) for this layer is being written.
 
- Signals inherited from QgsMapLayer
void autoRefreshIntervalChanged (int interval)
 Emitted when the auto refresh interval changes.
 
void beforeResolveReferences (QgsProject *project)
 Emitted when all layers are loaded and references can be resolved, just before the references of this layer are resolved.
 
void blendModeChanged (QPainter::CompositionMode blendMode)
 Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode()
 
void configChanged ()
 Emitted whenever the configuration is changed.
 
void crsChanged ()
 Emit a signal that layer's CRS has been reset.
 
void customPropertyChanged (const QString &key)
 Emitted when a custom property of the layer has been changed or removed.
 
void dataChanged ()
 Data of layer changed.
 
void dataSourceChanged ()
 Emitted whenever the layer's data source has been changed.
 
void dependenciesChanged ()
 Emitted when dependencies are changed.
 
void editingStarted ()
 Emitted when editing on this layer has started.
 
void editingStopped ()
 Emitted when edited changes have been successfully written to the data provider.
 
void flagsChanged ()
 Emitted when layer's flags have been modified.
 
void isValidChanged ()
 Emitted when the validity of this layer changed.
 
void layerModified ()
 Emitted when modifications has been done on layer.
 
void legendChanged ()
 Signal emitted when legend of the layer has changed.
 
void mapTipsEnabledChanged ()
 Emitted when map tips are enabled or disabled for the layer.
 
void mapTipTemplateChanged ()
 Emitted when the map tip template changes.
 
void metadataChanged ()
 Emitted when the layer's metadata is changed.
 
void nameChanged ()
 Emitted when the name has been changed.
 
void opacityChanged (double opacity)
 Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (opaque).
 
void recalculateExtents () const
 This is used to send a request that any mapcanvas using this layer update its extents.
 
void renderer3DChanged ()
 Signal emitted when 3D renderer associated with the layer has changed.
 
void rendererChanged ()
 Signal emitted when renderer is changed.
 
void repaintRequested (bool deferredUpdate=false)
 By emitting this signal the layer tells that either appearance or content have been changed and any view showing the rendered layer should refresh itself.
 
void request3DUpdate ()
 Signal emitted when a layer requires an update in any 3D maps.
 
void statusChanged (const QString &status)
 Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
 
void styleChanged ()
 Signal emitted whenever a change affects the layer's style.
 
void styleLoaded (QgsMapLayer::StyleCategories categories)
 Emitted when a style has been loaded.
 
void willBeDeleted ()
 Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid state: the last chance for other pieces of code for some cleanup if they use the layer.
 

Public Member Functions

 QgsVectorLayer (const QgsVectorLayer &rhs)=delete
 QgsVectorLayer cannot be copied.
 
 QgsVectorLayer (const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="ogr", const QgsVectorLayer::LayerOptions &options=QgsVectorLayer::LayerOptions())
 Constructor - creates a vector layer.
 
 ~QgsVectorLayer () override
 
QgsActionManageractions ()
 Returns all layer actions defined on this layer.
 
const QgsActionManageractions () const
 Returns all layer actions defined on this layer.
 
bool addAttribute (const QgsField &field)
 Add an attribute field (but does not commit it) returns true if the field was added.
 
int addExpressionField (const QString &exp, const QgsField &fld)
 Add a new field which is calculated by the expression specified.
 
bool addFeature (QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
 Adds a single feature to the sink.
 
void addFeatureRendererGenerator (QgsFeatureRendererGenerator *generator)
 Adds a new feature renderer generator to the layer.
 
bool addFeatures (QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
 Adds a list of features to the sink.
 
bool addJoin (const QgsVectorLayerJoinInfo &joinInfo)
 Joins another vector layer to this layer.
 
Q_INVOKABLE Qgis::GeometryOperationResult addPart (const QgsPointSequence &ring)
 Adds a new part polygon to a multipart feature.
 
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart (const QList< QgsPointXY > &ring)
 Adds a new part polygon to a multipart feature.
 
Q_INVOKABLE Qgis::GeometryOperationResult addPart (QgsCurve *ring)
 
Q_INVOKABLE Qgis::GeometryOperationResult addRing (const QgsPointSequence &ring, QgsFeatureId *featureId=nullptr)
 Adds a ring to polygon/multipolygon features.
 
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addRing (const QVector< QgsPointXY > &ring, QgsFeatureId *featureId=nullptr)
 Adds a ring to polygon/multipolygon features.
 
Q_INVOKABLE Qgis::GeometryOperationResult addRing (QgsCurve *ring, QgsFeatureId *featureId=nullptr)
 Adds a ring to polygon/multipolygon features (takes ownership)
 
int addTopologicalPoints (const QgsGeometry &geom)
 Adds topological points for every vertex of the geometry.
 
int addTopologicalPoints (const QgsPoint &p)
 Adds a vertex to segments which intersect point p but don't already have a vertex there.
 
int addTopologicalPoints (const QgsPointSequence &ps)
 Adds a vertex to segments which intersect any of the points p but don't already have a vertex there.
 
Q_DECL_DEPRECATED int addTopologicalPoints (const QgsPointXY &p)
 Adds a vertex to segments which intersect point p but don't already have a vertex there.
 
QVariant aggregate (QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression, const QgsAggregateCalculator::AggregateParameters &parameters=QgsAggregateCalculator::AggregateParameters(), QgsExpressionContext *context=nullptr, bool *ok=nullptr, QgsFeatureIds *fids=nullptr, QgsFeedback *feedback=nullptr, QString *error=nullptr) const
 Calculates an aggregated value from the layer's features.
 
bool allowCommit () const
 Controls, if the layer is allowed to commit changes.
 
QString attributeAlias (int index) const
 Returns the alias of an attribute name or a null string if there is no alias.
 
QgsStringMap attributeAliases () const
 Returns a map of field name to attribute alias.
 
QString attributeDisplayName (int index) const
 Convenience function that returns the attribute alias if defined or the field name else.
 
QgsAttributeList attributeList () const
 Returns list of attribute indexes.
 
QgsAttributeTableConfig attributeTableConfig () const
 Returns the attribute table configuration object.
 
QgsAuxiliaryLayerauxiliaryLayer ()
 Returns the current auxiliary layer.
 
const QgsAuxiliaryLayerauxiliaryLayer () const
 Returns the current const auxiliary layer.
 
void beginEditCommand (const QString &text)
 Create edit command for undo/redo operations.
 
Q_INVOKABLE QgsRectangle boundingBoxOfSelected () const
 Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned.
 
QString capabilitiesString () const
 Capabilities for this layer, comma separated and translated.
 
bool changeAttributeValue (QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false)
 Changes an attribute value for a feature (but does not immediately commit the changes).
 
bool changeAttributeValues (QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap(), bool skipDefaultValues=false)
 Changes attributes' values for a feature (but does not immediately commit the changes).
 
bool changeGeometry (QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue=false)
 Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the changes).
 
QgsVectorLayerclone () const override
 Returns a new instance equivalent to this one.
 
Q_INVOKABLE bool commitChanges (bool stopEditing=true)
 Attempts to commit to the underlying data provider any buffered changes made since the last to call to startEditing().
 
QStringList commitErrors () const
 Returns a list containing any error messages generated when attempting to commit changes to the layer.
 
QgsConditionalLayerStylesconditionalStyles () const
 Returns the conditional styles that are set for this layer.
 
QString constraintDescription (int index) const
 Returns the descriptive name for the constraint expression for a specified field index.
 
QString constraintExpression (int index) const
 Returns the constraint expression for for a specified field index, if set.
 
QgsVectorLayerFeatureCountercountSymbolFeatures (bool storeSymbolFids=false)
 Count features for symbols.
 
QgsExpressionContext createExpressionContext () const FINAL
 This method needs to be reimplemented in all classes which implement this interface and return an expression context.
 
QgsExpressionContextScopecreateExpressionContextScope () const FINAL
 This method needs to be reimplemented in all classes which implement this interface and return an expression context scope.
 
QgsMapLayerRenderercreateMapRenderer (QgsRenderContext &rendererContext) FINAL
 Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
 
QgsAbstractProfileGeneratorcreateProfileGenerator (const QgsProfileRequest &request) override
 Given a profile request, returns a new profile generator ready for generating elevation profiles.
 
QString dataComment () const
 Returns a description for this layer as defined in the data provider.
 
const QgsVectorDataProviderdataProvider () const FINAL
 Returns the layer's data provider in a const-correct manner, it may be nullptr.
 
QgsVectorDataProviderdataProvider () FINAL
 Returns the layer's data provider, it may be nullptr.
 
QString decodedSource (const QString &source, const QString &provider, const QgsReadWriteContext &context) const FINAL
 Called by readLayerXML(), used by derived classes to decode provider's specific data source from project files.
 
QVariant defaultValue (int index, const QgsFeature &feature=QgsFeature(), QgsExpressionContext *context=nullptr) const
 Returns the calculated default value for the specified field index.
 
QgsDefaultValue defaultValueDefinition (int index) const
 Returns the definition of the expression used when calculating the default value for a field.
 
virtual bool deleteAttribute (int attr)
 Deletes an attribute field (but does not commit it).
 
bool deleteAttributes (const QList< int > &attrs)
 Deletes a list of attribute fields (but does not commit it)
 
bool deleteFeature (QgsFeatureId fid, DeleteContext *context=nullptr)
 Deletes a feature from the layer (but does not commit it).
 
bool deleteFeatures (const QgsFeatureIds &fids, DeleteContext *context=nullptr)
 Deletes a set of features from the layer (but does not commit it)
 
Q_INVOKABLE bool deleteSelectedFeatures (int *deletedCount=nullptr, QgsVectorLayer::DeleteContext *context=nullptr)
 Deletes the selected features.
 
Qgis::VectorEditResult deleteVertex (QgsFeatureId featureId, int vertex)
 Deletes a vertex from a feature.
 
QSet< QgsMapLayerDependencydependencies () const FINAL
 Gets the list of dependencies.
 
void destroyEditCommand ()
 Destroy active command and reverts all changes in it.
 
const QgsDiagramLayerSettingsdiagramLayerSettings () const
 
const QgsDiagramRendererdiagramRenderer () const
 
bool diagramsEnabled () const
 Returns whether the layer contains diagrams which are enabled and should be drawn.
 
QString displayExpression () const
 Returns the preview expression, used to create a human readable preview string.
 
QString displayField () const
 This is a shorthand for accessing the displayExpression if it is a simple field.
 
Q_INVOKABLE QgsVectorLayerEditBuffereditBuffer ()
 Buffer with uncommitted editing operations. Only valid after editing has been turned on.
 
const QgsVectorLayerEditBuffereditBuffer () const
 Buffer with uncommitted editing operations.
 
QgsEditFormConfig editFormConfig () const
 Returns the configuration of the form used to represent this vector layer.
 
QgsEditorWidgetSetup editorWidgetSetup (int index) const
 The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field at index.
 
QgsMapLayerElevationPropertieselevationProperties () override
 Returns the layer's elevation properties.
 
QString encodedSource (const QString &source, const QgsReadWriteContext &context) const FINAL
 Called by writeLayerXML(), used by derived classes to encode provider's specific data source to project files.
 
void endEditCommand ()
 Finish edit command and add it to undo/redo stack.
 
Q_DECL_DEPRECATED QSet< QString > excludeAttributesWfs () const
 A set of attributes that are not advertised in WFS requests with QGIS server.
 
Q_DECL_DEPRECATED QSet< QString > excludeAttributesWms () const
 A set of attributes that are not advertised in WMS requests with QGIS server.
 
QString expressionField (int index) const
 Returns the expression used for a given expression field.
 
QgsRectangle extent () const FINAL
 Returns the extent of the layer.
 
QPainter::CompositionMode featureBlendMode () const
 Returns the current blending mode for features.
 
long long featureCount () const FINAL
 Returns feature count including changes which have not yet been committed If you need only the count of committed features call this method on this layer's provider.
 
long long featureCount (const QString &legendKey) const
 Number of features rendered with specified legend key.
 
QList< const QgsFeatureRendererGenerator * > featureRendererGenerators () const
 Returns a list of the feature renderer generators owned by the layer.
 
Qgis::FieldConfigurationFlags fieldConfigurationFlags (int index) const
 Returns the configuration flags of the field at given index.
 
QgsFieldConstraints::Constraints fieldConstraints (int fieldIndex) const
 Returns any constraints which are present for a specified field index.
 
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrengthfieldConstraintsAndStrength (int fieldIndex) const
 Returns a map of constraint with their strength for a specific field of the layer.
 
QgsFields fields () const FINAL
 Returns the list of fields of this layer.
 
QgsGeometryOptionsgeometryOptions () const
 Configuration and logic to apply automatically on any edit happening on this layer.
 
Q_INVOKABLE Qgis::GeometryType geometryType () const
 Returns point, line or polygon.
 
QgsFeature getFeature (QgsFeatureId fid) const
 Queries the layer for the feature with the given id.
 
QgsFeatureIterator getFeatures (const QgsFeatureIds &fids)
 Queries the layer for the features with the given ids.
 
QgsFeatureIterator getFeatures (const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
 Queries the layer for features specified in request.
 
QgsFeatureIterator getFeatures (const QgsRectangle &rectangle)
 Queries the layer for the features which intersect the specified rectangle.
 
QgsFeatureIterator getFeatures (const QString &expression)
 Queries the layer for features matching a given expression.
 
QgsGeometry getGeometry (QgsFeatureId fid) const
 Queries the layer for the geometry at the given id.
 
QgsFeatureIterator getSelectedFeatures (QgsFeatureRequest request=QgsFeatureRequest()) const
 Returns an iterator of the selected features.
 
FeatureAvailability hasFeatures () const FINAL
 Determines if this vector layer has features.
 
bool hasMapTips () const FINAL
 Returns true if the layer contains map tips.
 
QString htmlMetadata () const FINAL
 Obtain a formatted HTML string containing assorted metadata for this layer.
 
bool insertVertex (const QgsPoint &point, QgsFeatureId atFeatureId, int beforeVertex)
 Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature.
 
bool insertVertex (double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
 Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature.
 
Q_INVOKABLE void invertSelection ()
 Selects not selected features and deselects selected ones.
 
Q_INVOKABLE void invertSelectionInRectangle (QgsRectangle &rect)
 Inverts selection of features found within the search rectangle (in layer's coordinates)
 
bool isAuxiliaryField (int index, int &srcIndex) const
 Returns true if the field comes from the auxiliary layer, false otherwise.
 
bool isEditable () const FINAL
 Returns true if the provider is in editing mode.
 
bool isEditCommandActive () const
 Tests if an edit command is active.
 
bool isModified () const override
 Returns true if the provider has been modified since the last commit.
 
bool isSpatial () const FINAL
 Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry.
 
bool isSqlQuery () const
 Returns true if the layer is a query (SQL) layer.
 
QgsVectorLayerJoinBufferjoinBuffer ()
 Returns the join buffer object.
 
const QgsVectorLayerJoinBufferjoinBuffer () const
 Returns a const pointer on join buffer object.
 
QgsAbstractVectorLayerLabelinglabeling ()
 Access to labeling configuration.
 
const QgsAbstractVectorLayerLabelinglabeling () const
 Access to const labeling configuration.
 
bool labelsEnabled () const
 Returns whether the layer contains labels which are enabled and should be drawn.
 
bool loadAuxiliaryLayer (const QgsAuxiliaryStorage &storage, const QString &key=QString())
 Loads the auxiliary layer for this vector layer.
 
QString loadDefaultStyle (bool &resultFlag) FINAL
 Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)
 
QVariant maximumValue (int index) const FINAL
 Returns the maximum value for an attribute column or an invalid variant in case of error.
 
void minimumAndMaximumValue (int index, QVariant &minimum, QVariant &maximum) const
 Calculates both the minimum and maximum value for an attribute column.
 
QVariant minimumValue (int index) const FINAL
 Returns the minimum value for an attribute column or an invalid variant in case of error.
 
Q_INVOKABLE void modifySelection (const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds)
 Modifies the current selection on this layer.
 
bool moveVertex (const QgsPoint &p, QgsFeatureId atFeatureId, int atVertex)
 Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates.
 
bool moveVertex (double x, double y, QgsFeatureId atFeatureId, int atVertex)
 Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates.
 
QgsVectorLayeroperator= (QgsVectorLayer const &rhs)=delete
 QgsVectorLayer cannot be copied.
 
QgsAttributeList primaryKeyAttributes () const
 Returns the list of attributes which make up the layer's primary keys.
 
bool readExtentFromXml () const
 Returns true if the extent is read from the XML document when data source has no metadata, false if it's the data provider which determines it.
 
bool readSld (const QDomNode &node, QString &errorMessage) FINAL
 
bool readStyle (const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) FINAL
 
bool readSymbology (const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) FINAL
 
bool readXml (const QDomNode &layer_node, QgsReadWriteContext &context) FINAL
 Reads vector layer specific state from project file Dom node.
 
QList< QgsRelationreferencingRelations (int idx) const
 Returns the layer's relations, where the foreign key is on this layer.
 
void reload () FINAL
 Synchronises with changes in the datasource.
 
void removeExpressionField (int index)
 Removes an expression field.
 
void removeFeatureRendererGenerator (const QString &id)
 Removes the feature renderer with matching id from the layer.
 
void removeFieldAlias (int index)
 Removes an alias (a display name) for attributes to display in dialogs.
 
void removeFieldConstraint (int index, QgsFieldConstraints::Constraint constraint)
 Removes a constraint for a specified field index.
 
bool removeJoin (const QString &joinLayerId)
 Removes a vector layer join.
 
bool renameAttribute (int index, const QString &newName)
 Renames an attribute field (but does not commit it).
 
QgsFeatureRendererrenderer ()
 Returns the feature renderer used for rendering the features in the layer in 2D map views.
 
const QgsFeatureRendererrenderer () const
 Returns the feature renderer used for rendering the features in the layer in 2D map views.
 
void resolveReferences (QgsProject *project) FINAL
 Resolves references to other layers (kept as layer IDs after reading XML) into layer objects.
 
Q_INVOKABLE bool rollBack (bool deleteBuffer=true)
 Stops a current editing operation and discards any uncommitted edits.
 
Q_INVOKABLE void selectAll ()
 Select all the features.
 
Q_INVOKABLE void selectByExpression (const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
 Selects matching features using an expression.
 
Q_INVOKABLE void selectByIds (const QgsFeatureIds &ids, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
 Selects matching features using a list of feature IDs.
 
Q_INVOKABLE void selectByRect (QgsRectangle &rect, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
 Selects features found within the search rectangle (in layer's coordinates)
 
int selectedFeatureCount () const
 Returns the number of features that are selected in this layer.
 
Q_INVOKABLE const QgsFeatureIdsselectedFeatureIds () const
 Returns a list of the selected features IDs in this layer.
 
Q_INVOKABLE QgsFeatureList selectedFeatures () const
 Returns a copy of the user-selected features.
 
QgsMapLayerSelectionPropertiesselectionProperties () override
 Returns the layer's selection properties.
 
void setAllowCommit (bool allowCommit)
 Controls, if the layer is allowed to commit changes.
 
void setAttributeTableConfig (const QgsAttributeTableConfig &attributeTableConfig)
 Sets the attribute table configuration object.
 
void setAuxiliaryLayer (QgsAuxiliaryLayer *layer=nullptr)
 Sets the current auxiliary layer.
 
void setConstraintExpression (int index, const QString &expression, const QString &description=QString())
 Sets the constraint expression for the specified field index.
 
void setCoordinateSystem ()
 Setup the coordinate system transformation for the layer.
 
void setDefaultValueDefinition (int index, const QgsDefaultValue &definition)
 Sets the definition of the expression to use when calculating the default value for a field.
 
bool setDependencies (const QSet< QgsMapLayerDependency > &layers) FINAL
 Sets the list of dependencies.
 
void setDiagramLayerSettings (const QgsDiagramLayerSettings &s)
 
void setDiagramRenderer (QgsDiagramRenderer *r)
 Sets diagram rendering object (takes ownership)
 
void setDisplayExpression (const QString &displayExpression)
 Set the preview expression, used to create a human readable preview string.
 
void setEditFormConfig (const QgsEditFormConfig &editFormConfig)
 Sets the editFormConfig (configuration) of the form used to represent this vector layer.
 
void setEditorWidgetSetup (int index, const QgsEditorWidgetSetup &setup)
 The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field at index.
 
Q_DECL_DEPRECATED void setExcludeAttributesWfs (const QSet< QString > &att)
 A set of attributes that are not advertised in WFS requests with QGIS server.
 
Q_DECL_DEPRECATED void setExcludeAttributesWms (const QSet< QString > &att)
 A set of attributes that are not advertised in WMS requests with QGIS server.
 
void setFeatureBlendMode (QPainter::CompositionMode blendMode)
 Sets the blending mode used for rendering each feature.
 
void setFieldAlias (int index, const QString &aliasString)
 Sets an alias (a display name) for attributes to display in dialogs.
 
void setFieldConfigurationFlag (int index, Qgis::FieldConfigurationFlag flag, bool active)
 Sets the given configuration flag for the field at given index to be active or not.
 
void setFieldConfigurationFlags (int index, Qgis::FieldConfigurationFlags flags)
 Sets the configuration flags of the field at given index.
 
void setFieldConstraint (int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthHard)
 Sets a constraint for a specified field index.
 
void setFieldSplitPolicy (int index, Qgis::FieldDomainSplitPolicy policy)
 Sets a split policy for the field with the specified index.
 
void setLabeling (QgsAbstractVectorLayerLabeling *labeling)
 Sets labeling configuration.
 
void setLabelsEnabled (bool enabled)
 Sets whether labels should be enabled for the layer.
 
void setProviderEncoding (const QString &encoding)
 Sets the text encoding of the data provider.
 
void setReadExtentFromXml (bool readExtentFromXml)
 Flag allowing to indicate if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it.
 
bool setReadOnly (bool readonly=true)
 Makes layer read-only (editing disabled) or not.
 
void setRenderer (QgsFeatureRenderer *r)
 Sets the feature renderer which will be invoked to represent this layer in 2D map views.
 
void setSimplifyMethod (const QgsVectorSimplifyMethod &simplifyMethod)
 Sets the simplification settings for fast rendering of features.
 
virtual bool setSubsetString (const QString &subset)
 Sets the string (typically sql) used to define a subset of the layer.
 
void setWeakRelations (const QList< QgsWeakRelation > &relations)
 Sets the layer's weak relations.
 
bool simplifyDrawingCanbeApplied (const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
 Returns whether the VectorLayer can apply the specified simplification hint.
 
const QgsVectorSimplifyMethodsimplifyMethod () const
 Returns the simplification settings for fast rendering of features.
 
QgsCoordinateReferenceSystem sourceCrs () const FINAL
 Returns the coordinate reference system for features in the source.
 
QgsRectangle sourceExtent () const FINAL
 Returns the extent of all geometries from the source.
 
QString sourceName () const FINAL
 Returns a friendly display name for the source.
 
Q_INVOKABLE Qgis::GeometryOperationResult splitFeatures (const QgsCurve *curve, QgsPointSequence &topologyTestPoints, bool preserveCircular=false, bool topologicalEditing=false)
 Splits features cut by the given curve.
 
Q_INVOKABLE Qgis::GeometryOperationResult splitFeatures (const QgsPointSequence &splitLine, bool topologicalEditing=false)
 Splits features cut by the given line.
 
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitFeatures (const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
 Splits features cut by the given line.
 
Q_INVOKABLE Qgis::GeometryOperationResult splitParts (const QgsPointSequence &splitLine, bool topologicalEditing=false)
 Splits parts cut by the given line.
 
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitParts (const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
 Splits parts cut by the given line.
 
QString storageType () const
 Returns the permanent storage type for this layer as a friendly name.
 
QgsStoredExpressionManagerstoredExpressionManager ()
 Returns the manager of the stored expressions for this layer.
 
virtual QString subsetString () const
 Returns the string (typically sql) used to define a subset of the layer.
 
bool supportsEditing () const override
 Returns whether the layer supports editing or not.
 
QgsFeatureIds symbolFeatureIds (const QString &legendKey) const
 Ids of features rendered with specified legend key.
 
QgsMapLayerTemporalPropertiestemporalProperties () override
 Returns the layer's temporal properties.
 
Q_INVOKABLE int translateFeature (QgsFeatureId featureId, double dx, double dy)
 Translates feature by dx, dy.
 
QStringList uniqueStringsMatching (int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
 Returns unique string values of an attribute which contain a specified subset string.
 
QSet< QVariant > uniqueValues (int fieldIndex, int limit=-1) const FINAL
 Calculates a list of unique values contained within an attribute in the layer.
 
void updateExpressionField (int index, const QString &exp)
 Changes the expression used to define an expression based (virtual) field.
 
bool updateFeature (QgsFeature &feature, bool skipDefaultValues=false)
 Updates an existing feature in the layer, replacing the attributes and geometry for the feature with matching QgsFeature::id() with the attributes and geometry from feature.
 
void updateFields ()
 Will regenerate the fields property of this layer by obtaining all fields from the dataProvider, joined fields and virtual fields.
 
const QList< QgsVectorLayerJoinInfovectorJoins () const
 
Qgis::VectorLayerTypeFlags vectorLayerTypeFlags () const
 Returns the vector layer type flags.
 
QList< QgsWeakRelationweakRelations () const
 Returns the layer's weak relations as specified in the layer's style.
 
Q_INVOKABLE Qgis::WkbType wkbType () const FINAL
 Returns the WKBType or WKBUnknown in case of error.
 
bool writeSld (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
 Writes the symbology of the layer into the document provided in SLD 1.1 format.
 
bool writeStyle (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const FINAL
 
bool writeSymbology (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const FINAL
 
bool writeXml (QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const FINAL
 Writes vector layer specific state to project file Dom node.
 
- Public Member Functions inherited from QgsMapLayer
 QgsMapLayer (Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
 Constructor for QgsMapLayer.
 
 QgsMapLayer (QgsMapLayer const &)=delete
 QgsMapLayer cannot be copied.
 
 ~QgsMapLayer () override
 
QString abstract () const
 Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
 
virtual bool accept (QgsStyleEntityVisitorInterface *visitor) const
 Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
 
QString attribution () const
 Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
 
QString attributionUrl () const
 Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
 
int autoRefreshInterval () const
 Returns the auto refresh interval (in milliseconds).
 
Qgis::AutoRefreshMode autoRefreshMode () const
 Returns the layer's automatical refresh mode.
 
QPainter::CompositionMode blendMode () const
 Returns the current blending mode for a layer.
 
QgsCoordinateReferenceSystem crs () const
 Returns the layer's spatial reference system.
 
template<class T >
customEnumProperty (const QString &key, const T &defaultValue)
 Returns the property value for a property based on an enum.
 
template<class T >
customFlagProperty (const QString &key, const T &defaultValue)
 Returns the property value for a property based on a flag.
 
const QgsObjectCustomPropertiescustomProperties () const
 Read all custom properties from layer.
 
Q_INVOKABLE QVariant customProperty (const QString &value, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer.
 
Q_INVOKABLE QStringList customPropertyKeys () const
 Returns list of all keys within custom properties.
 
QString dataUrl () const
 Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
 
QString dataUrlFormat () const
 Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
 
virtual bool deleteStyleFromDatabase (const QString &styleId, QString &msgError)
 Deletes a style from the database.
 
virtual QgsError error () const
 Gets current status error.
 
void exportNamedMetadata (QDomDocument &doc, QString &errorMsg) const
 Export the current metadata of this layer as named metadata in a QDomDocument.
 
virtual void exportNamedStyle (QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
 Export the properties of this layer as named style in a QDomDocument.
 
virtual void exportSldStyle (QDomDocument &doc, QString &errorMsg) const
 Export the properties of this layer as SLD style in a QDomDocument.
 
virtual void exportSldStyleV2 (QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext) const
 Export the properties of this layer as SLD style in a QDomDocument.
 
QgsMapLayer::LayerFlags flags () const
 Returns the flags for this layer.
 
virtual QString getStyleFromDatabase (const QString &styleId, QString &msgError)
 Returns the named style corresponding to style id provided.
 
Q_DECL_DEPRECATED bool hasAutoRefreshEnabled () const
 Returns true if auto refresh is enabled for the layer.
 
bool hasScaleBasedVisibility () const
 Returns whether scale based visibility is enabled for the layer.
 
QString id () const
 Returns the layer's unique ID, which is used to access this layer from QgsProject.
 
bool importNamedMetadata (QDomDocument &document, QString &errorMessage)
 Import the metadata of this layer from a QDomDocument.
 
virtual bool importNamedStyle (QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
 Import the properties of this layer from a QDomDocument.
 
bool isInScaleRange (double scale) const
 Tests whether the layer should be visible at the specified scale.
 
bool isRefreshOnNotifyEnabled () const
 Returns true if the refresh on provider nofification is enabled.
 
virtual bool isTemporary () const
 Returns true if the layer is considered a temporary layer.
 
bool isValid () const
 Returns the status of the layer.
 
QString keywordList () const
 Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
 
QgsMapLayerLegendlegend () const
 Can be nullptr.
 
QString legendPlaceholderImage () const
 Returns path to the placeholder image or an empty string if a generated legend is shown.
 
QString legendUrl () const
 Returns the URL for the layer's legend.
 
QString legendUrlFormat () const
 Returns the format for a URL based layer legend.
 
virtual int listStylesInDatabase (QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError)
 Lists all the style in db split into related to the layer and not related to.
 
virtual QString loadDefaultMetadata (bool &resultFlag)
 Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a record in the users metadata table in their personal qgis.db)
 
virtual QString loadNamedMetadata (const QString &uri, bool &resultFlag)
 Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)
 
bool loadNamedMetadataFromDatabase (const QString &db, const QString &uri, QString &qmd)
 Retrieve a named metadata for this layer from a sqlite database.
 
virtual QString loadNamedStyle (const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
 Loads a named style from file/local db/datasource db.
 
virtual QString loadNamedStyle (const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
 Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)
 
virtual bool loadNamedStyleFromDatabase (const QString &db, const QString &uri, QString &qml)
 Retrieve a named style for this layer from a sqlite database.
 
virtual QString loadSldStyle (const QString &uri, bool &resultFlag)
 Attempts to style the layer using the formatting from an SLD type file.
 
bool mapTipsEnabled () const
 Returns true if map tips are enabled for this layer.
 
QString mapTipTemplate () const
 The mapTip is a pretty, html representation for feature information.
 
double maximumScale () const
 Returns the maximum map scale (i.e.
 
virtual const QgsLayerMetadatametadata () const
 Returns a reference to the layer's metadata store.
 
virtual QString metadataUri () const
 Retrieve the metadata URI for this layer (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)
 
Q_DECL_DEPRECATED QString metadataUrl () const
 Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
 
Q_DECL_DEPRECATED QString metadataUrlFormat () const
 Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
 
Q_DECL_DEPRECATED QString metadataUrlType () const
 Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
 
double minimumScale () const
 Returns the minimum map scale (i.e.
 
QString name () const
 Returns the display name of the layer.
 
virtual double opacity () const
 Returns the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).
 
QgsMapLayeroperator= (QgsMapLayer const &)=delete
 QgsMapLayer cannot be copied.
 
QString originalXmlProperties () const
 Returns the XML properties of the original layer as they were when the layer was first read from the project file.
 
virtual Qgis::MapLayerProperties properties () const
 Returns the map layer properties of this layer.
 
QString providerType () const
 Returns the provider type (provider key) for this layer.
 
QString publicSource (bool hidePassword=false) const
 Gets a version of the internal layer definition that has sensitive bits removed (for example, the password).
 
bool readLayerXml (const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider=nullptr)
 Sets state from DOM document.
 
bool readOnly () const
 Returns if this layer is read only.
 
virtual bool readStyle (const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
 Read the style for the current layer from the DOM node supplied.
 
virtual bool readSymbology (const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
 Read the symbology for the current layer from the DOM node supplied.
 
QString refreshOnNotifyMessage () const
 Returns the message that should be notified by the provider to triggerRepaint.
 
void removeCustomProperty (const QString &key)
 Remove a custom property from layer.
 
QgsAbstract3DRendererrenderer3D () const
 Returns 3D renderer associated with the layer.
 
virtual QString saveDefaultMetadata (bool &resultFlag)
 Save the current metadata of this layer as the default metadata (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)
 
virtual Q_DECL_DEPRECATED QString saveDefaultStyle (bool &resultFlag)
 Save the properties of this layer as the default style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)
 
virtual QString saveDefaultStyle (bool &resultFlag, StyleCategories categories)
 Save the properties of this layer as the default style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)
 
QString saveNamedMetadata (const QString &uri, bool &resultFlag)
 Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)
 
virtual QString saveNamedStyle (const QString &uri, bool &resultFlag, StyleCategories categories=AllStyleCategories)
 Save the properties of this layer as a named style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)
 
virtual QString saveSldStyle (const QString &uri, bool &resultFlag) const
 Saves the properties of this layer to an SLD format file.
 
virtual QString saveSldStyleV2 (bool &resultFlag, const QgsSldExportContext &exportContext) const
 Saves the properties of this layer to an SLD format file.
 
virtual void saveStyleToDatabase (const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
 Saves named and sld style of the layer to the style table in the db.
 
QgsMapLayerServerPropertiesserverProperties ()
 Returns QGIS Server Properties for the map layer.
 
const QgsMapLayerServerPropertiesserverProperties () const
 Returns QGIS Server Properties const for the map layer.
 
void setAbstract (const QString &abstract)
 Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
 
void setAttribution (const QString &attrib)
 Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
 
void setAttributionUrl (const QString &attribUrl)
 Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
 
Q_DECL_DEPRECATED void setAutoRefreshEnabled (bool enabled)
 Sets whether auto refresh is enabled for the layer.
 
void setAutoRefreshInterval (int interval)
 Sets the auto refresh interval (in milliseconds) for the layer.
 
void setAutoRefreshMode (Qgis::AutoRefreshMode mode)
 Sets the automatic refresh mode for the layer.
 
void setBlendMode (QPainter::CompositionMode blendMode)
 Set the blending mode used for rendering a layer.
 
void setCrs (const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
 Sets layer's spatial reference system.
 
template<class T >
void setCustomEnumProperty (const QString &key, const T &value)
 Set the value of a property based on an enum.
 
template<class T >
void setCustomFlagProperty (const QString &key, const T &value)
 Set the value of a property based on a flag.
 
void setCustomProperties (const QgsObjectCustomProperties &properties)
 Set custom properties for layer.
 
Q_INVOKABLE void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for layer.
 
void setDataSource (const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
 Updates the data source of the layer.
 
void setDataSource (const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false)
 Updates the data source of the layer.
 
void setDataSource (const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags)
 Updates the data source of the layer.
 
void setDataUrl (const QString &dataUrl)
 Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
 
void setDataUrlFormat (const QString &dataUrlFormat)
 Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
 
void setFlags (QgsMapLayer::LayerFlags flags)
 Returns the flags for this layer.
 
void setKeywordList (const QString &keywords)
 Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
 
virtual void setLayerOrder (const QStringList &layers)
 Reorders the previously selected sublayers of this layer from bottom to top.
 
void setLegend (QgsMapLayerLegend *legend)
 Assign a legend controller to the map layer.
 
void setLegendPlaceholderImage (const QString &imgPath)
 Set placeholder image for legend.
 
void setLegendUrl (const QString &legendUrl)
 Sets the URL for the layer's legend.
 
void setLegendUrlFormat (const QString &legendUrlFormat)
 Sets the format for a URL based layer legend.
 
void setMapTipsEnabled (bool enabled)
 Enable or disable map tips for this layer.
 
void setMapTipTemplate (const QString &mapTipTemplate)
 The mapTip is a pretty, html representation for feature information.
 
virtual void setMetadata (const QgsLayerMetadata &metadata)
 Sets the layer's metadata store.
 
Q_DECL_DEPRECATED void setMetadataUrl (const QString &metaUrl)
 Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
 
Q_DECL_DEPRECATED void setMetadataUrlFormat (const QString &metaUrlFormat)
 Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
 
Q_DECL_DEPRECATED void setMetadataUrlType (const QString &metaUrlType)
 Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType indicates the standard to which the metadata complies.
 
void setName (const QString &name)
 Set the display name of the layer.
 
virtual void setOpacity (double opacity)
 Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).
 
void setOriginalXmlProperties (const QString &originalXmlProperties)
 Sets the original XML properties for the layer to originalXmlProperties.
 
void setRenderer3D (QgsAbstract3DRenderer *renderer)
 Sets 3D renderer for the layer.
 
void setShortName (const QString &shortName)
 Sets the short name of the layer used by QGIS Server to identify the layer.
 
virtual void setSubLayerVisibility (const QString &name, bool visible)
 Set the visibility of the given sublayer name.
 
void setTitle (const QString &title)
 Sets the title of the layer used by QGIS Server in GetCapabilities request.
 
QString shortName () const
 Returns the short name of the layer used by QGIS Server to identify the layer.
 
QString source () const
 Returns the source for the layer.
 
QgsMapLayerStyleManagerstyleManager () const
 Gets access to the layer's style manager.
 
virtual QString styleURI () const
 Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)
 
virtual QStringList subLayers () const
 Returns the sublayers of this layer.
 
virtual QDateTime timestamp () const
 Time stamp of data source in the moment when data/metadata were loaded by provider.
 
QString title () const
 Returns the title of the layer used by QGIS Server in GetCapabilities request.
 
QgsCoordinateTransformContext transformContext () const
 Returns the layer data provider coordinate transform context or a default transform context if the layer does not have a valid data provider.
 
Qgis::LayerType type () const
 Returns the type of the layer.
 
QUndoStack * undoStack ()
 Returns pointer to layer's undo stack.
 
QUndoStack * undoStackStyles ()
 Returns pointer to layer's style undo stack.
 
QgsRectangle wgs84Extent (bool forceRecalculate=false) const
 Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag::FlagTrustLayerMetadata.
 
bool writeLayerXml (QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
 Stores state in DOM node.
 
virtual bool writeStyle (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
 Write just the symbology information for the layer into the document.
 
virtual bool writeSymbology (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
 Write the style for the layer into the document provided.
 
- Public Member Functions inherited from QgsExpressionContextGenerator
virtual ~QgsExpressionContextGenerator ()=default
 
- Public Member Functions inherited from QgsExpressionContextScopeGenerator
virtual ~QgsExpressionContextScopeGenerator ()=default
 
- Public Member Functions inherited from QgsFeatureSink
virtual ~QgsFeatureSink ()=default
 
virtual bool addFeatures (QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
 Adds all features from the specified iterator to the sink.
 
virtual bool flushBuffer ()
 Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination.
 
virtual QString lastError () const
 Returns the most recent error encountered by the sink, e.g.
 
- Public Member Functions inherited from QgsFeatureSource
virtual ~QgsFeatureSource ()=default
 
virtual QgsFeatureIds allFeatureIds () const
 Returns a list of all feature IDs for features present in the source.
 
virtual SpatialIndexPresence hasSpatialIndex () const
 Returns an enum value representing the presence of a valid spatial index on the source, if it can be determined.
 
QgsVectorLayermaterialize (const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
 Materializes a request (query) made against this feature source, by running it over the source and returning a new memory based vector layer containing the result.
 
- Public Member Functions inherited from QgsAbstractProfileSource
virtual ~QgsAbstractProfileSource ()
 

Static Public Member Functions

static Q_DECL_DEPRECATED void drawVertexMarker (double x, double y, QPainter &p, Qgis::VertexMarkerType type, int vertexSize)
 Draws a vertex symbol at (screen) coordinates x, y.
 
- Static Public Member Functions inherited from QgsMapLayer
static QString extensionPropertyType (PropertyType type)
 Returns the extension of a Property.
 
static QString formatLayerName (const QString &name)
 A convenience function to capitalize and format a layer name.
 
static QString generateId (const QString &layerName)
 Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
 
static QgsDataProvider::ReadFlags providerReadFlags (const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags)
 Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that describes a layer (corresponding to `‘maplayer’' tag in a DOM document project file read by QgsProject).
 

Static Public Attributes

static const QgsSettingsEntryEnumFlag< QgsVectorSimplifyMethod::SimplifyAlgorithm > * settingsSimplifyAlgorithm = new QgsSettingsEntryEnumFlag<QgsVectorSimplifyMethod::SimplifyAlgorithm>( QStringLiteral( "simplifyAlgorithm" ), QgsSettingsTree::sTreeQgis, QgsVectorSimplifyMethod::SimplifyAlgorithm::Distance )
 
static const QgsSettingsEntryEnumFlag< QgsVectorSimplifyMethod::SimplifyHints > * settingsSimplifyDrawingHints = new QgsSettingsEntryEnumFlag<QgsVectorSimplifyMethod::SimplifyHints>( QStringLiteral( "simplifyDrawingHints" ), QgsSettingsTree::sTreeQgis, QgsVectorSimplifyMethod::SimplifyHint::NoSimplification )
 
static const QgsSettingsEntryDoublesettingsSimplifyDrawingTol = new QgsSettingsEntryDouble( QStringLiteral( "simplifyDrawingTol" ), QgsSettingsTree::sTreeQgis, Qgis::DEFAULT_MAPTOPIXEL_THRESHOLD )
 
static const QgsSettingsEntryBoolsettingsSimplifyLocal = new QgsSettingsEntryBool( QStringLiteral( "simplifyLocal" ), QgsSettingsTree::sTreeQgis, true )
 
static const QgsSettingsEntryDoublesettingsSimplifyMaxScale = new QgsSettingsEntryDouble( QStringLiteral( "simplifyMaxScale" ), QgsSettingsTree::sTreeQgis, 1.0 )
 

Protected Member Functions

void setExtent (const QgsRectangle &rect) FINAL
 Sets the extent.
 
- Protected Member Functions inherited from QgsMapLayer
void appendError (const QgsErrorMessage &error)
 Add error message.
 
void clone (QgsMapLayer *layer) const
 Copies attributes like name, short name, ... into another layer.
 
QString crsHtmlMetadata () const
 Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
 
QString generalHtmlMetadata () const
 Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() method.
 
Q_DECL_DEPRECATED bool hasDependencyCycle (const QSet< QgsMapLayerDependency > &) const
 Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and always return false, because circular dependencies are now correctly managed.
 
void invalidateWgs84Extent ()
 Invalidates the WGS84 extent.
 
void readCommonStyle (const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
 Read style data common to all layer types.
 
void readCustomProperties (const QDomNode &layerNode, const QString &keyStartsWith=QString())
 Read custom properties from project file.
 
void readStyleManager (const QDomNode &layerNode)
 Read style manager's configuration (if any). To be called by subclasses.
 
void setError (const QgsError &error)
 Sets error message.
 
void setProviderType (const QString &providerType)
 Sets the providerType (provider key)
 
void setValid (bool valid)
 Sets whether layer is valid or not.
 
void writeCommonStyle (QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
 Write style data common to all layer types.
 
void writeCustomProperties (QDomNode &layerNode, QDomDocument &doc) const
 Write custom properties to project file.
 
void writeStyleManager (QDomNode &layerNode, QDomDocument &doc) const
 Write style manager's configuration (if exists). To be called by subclasses.
 

Properties

QString displayExpression
 
QgsEditFormConfig editFormConfig
 
bool readOnly
 
QString subsetString
 
bool supportsEditing
 
- Properties inherited from QgsMapLayer
int autoRefreshInterval
 
QgsCoordinateReferenceSystem crs
 
bool isValid
 
bool mapTipsEnabled
 
QString mapTipTemplate
 
QgsLayerMetadata metadata
 
QString name
 
double opacity
 
Qgis::LayerType type
 

Friends

class QgsVectorLayerEditBuffer
 
class QgsVectorLayerEditBufferGroup
 
class QgsVectorLayerEditPassthrough
 
class QgsVectorLayerFeatureSource
 

Additional Inherited Members

- Public Types inherited from QgsMapLayer
enum  LayerFlag { Identifiable = 1 << 0 , Removable = 1 << 1 , Searchable = 1 << 2 , Private = 1 << 3 }
 Flags for the map layer. More...
 
enum  PropertyType { Style = 0 , Metadata }
 Maplayer has a style and a metadata property. More...
 
enum  ReadFlag { FlagDontResolveLayers = 1 << 0 , FlagTrustLayerMetadata = 1 << 1 , FlagReadExtentFromXml = 1 << 2 , FlagForceReadOnly = 1 << 3 }
 Flags which control project read behavior. More...
 
enum  StyleCategory {
  LayerConfiguration = 1 << 0 , Symbology = 1 << 1 , Symbology3D = 1 << 2 , Labeling = 1 << 3 ,
  Fields = 1 << 4 , Forms = 1 << 5 , Actions = 1 << 6 , MapTips = 1 << 7 ,
  Diagrams = 1 << 8 , AttributeTable = 1 << 9 , Rendering = 1 << 10 , CustomProperties = 1 << 11 ,
  GeometryOptions = 1 << 12 , Relations = 1 << 13 , Temporal = 1 << 14 , Legend = 1 << 15 ,
  Elevation = 1 << 16 , Notes = 1 << 17 , AllStyleCategories
}
 Categories of style to distinguish appropriate sections for import/export. More...
 
- Public Types inherited from QgsFeatureSink
enum  Flag { FastInsert = 1 << 1 , RollBackOnErrors = 1 << 2 }
 Flags controlling how features are added to a sink. More...
 
enum  SinkFlag { RegeneratePrimaryKey = 1 << 1 }
 Flags that can be set on a QgsFeatureSink. More...
 
- Public Types inherited from QgsFeatureSource
enum  FeatureAvailability { NoFeaturesAvailable , FeaturesAvailable , FeaturesMaybeAvailable }
 Possible return value for hasFeatures() to determine if a source is empty. More...
 
enum  SpatialIndexPresence { SpatialIndexUnknown = 0 , SpatialIndexNotPresent = 1 , SpatialIndexPresent = 2 }
 Enumeration of spatial index presence states. More...
 
- Protected Attributes inherited from QgsMapLayer
QString mAbstract
 Description of the layer.
 
QString mAttribution
 Attribution of the layer.
 
QString mAttributionUrl
 
int mBlockStyleChangedSignal = 0
 If non-zero, the styleChanged signal should not be emitted.
 
QString mDataSource
 Data source description string, varies by layer type.
 
QString mDataUrl
 DataUrl of the layer.
 
QString mDataUrlFormat
 
QSet< QgsMapLayerDependencymDependencies
 List of layers that may modify this layer on modification.
 
QgsError mError
 Error.
 
bool mIsRefreshOnNofifyEnabled = false
 
QString mKeywordList
 
QString mLayerName
 Name of the layer - used for display.
 
double mLayerOpacity = 1.0
 Layer opacity.
 
QString mLegendUrl
 WMS legend.
 
QString mLegendUrlFormat
 
std::unique_ptr< QgsDataProvidermPreloadedProvider
 Optionally used when loading a project, it is released when the layer is effectively created.
 
QString mProviderKey
 Data provider key (name of the data provider)
 
QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags()
 Read flags. It's up to the subclass to respect these when restoring state from XML.
 
QString mRefreshOnNofifyMessage
 
QString mShortName
 
bool mShouldValidateCrs = true
 true if the layer's CRS should be validated and invalid CRSes are not permitted.
 
QString mTitle
 
bool mValid = false
 Indicates if the layer is valid and can be drawn.
 

Detailed Description

Represents a vector layer which manages a vector based data sets.

The QgsVectorLayer is instantiated by specifying the name of a data provider, such as postgres or wfs, and url defining the specific data set to connect to. The vector layer constructor in turn instantiates a QgsVectorDataProvider subclass corresponding to the provider type, and passes it the url. The data provider connects to the data source.

The QgsVectorLayer provides a common interface to the different data types. It also manages editing transactions by buffering layer edits until they are written to the underlying QgsVectorDataProvider. Before edits can be made a call to startEditing() is required. Any edits made to a QgsVectorLayer are then held in memory only, and are not written to the underlying QgsVectorDataProvider until a call to commitChanges() is made. Buffered edits can be rolled back and discarded without altering the underlying provider by calling rollBack().

Sample usage of the QgsVectorLayer class:

uri = "point?crs=epsg:4326&field=id:integer"
scratchLayer = QgsVectorLayer(uri, "Scratch point layer", "memory")
Represents a vector layer which manages a vector based data sets.

The main data providers supported by QGIS are listed below.

Vector data providers

Memory data providerType (memory)

The memory data provider is used to construct in memory data, for example scratch data or data generated from spatial operations such as contouring. There is no inherent persistent storage of the data. The data source uri is constructed. The url specifies the geometry type ("point", "linestring", "polygon", "multipoint","multilinestring","multipolygon"), optionally followed by url parameters as follows:

An example url is "Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes"

Since QGIS 3.4 when closing a project, the application shows a warning about potential data loss if there are any non-empty memory layers present. If your memory layer should not trigger such warning, it is possible to suppress that by setting the following custom variable:

layer.setCustomProperty("skipMemoryLayersCheck", 1)

OGR data provider (ogr)

Accesses data using the OGR drivers (https://gdal.org/drivers/vector/index.html). The url is the OGR connection string. A wide variety of data formats can be accessed using this driver, including file based formats used by many GIS systems, database formats, and web services. Some of these formats are also supported by custom data providers listed below.

SpatiaLite data provider (spatialite)

Access data in a SpatiaLite database. The url defines the connection parameters, table, geometry column, and other attributes. The url can be constructed using the QgsDataSourceUri class.

PostgreSQL data provider (postgres)

Connects to a PostgreSQL database. The url defines the connection parameters, table, geometry column, and other attributes. The url can be constructed using the QgsDataSourceUri class.

Microsoft SQL server data provider (mssql)

Connects to a Microsoft SQL server database. The url defines the connection parameters, table, geometry column, and other attributes. The url can be constructed using the QgsDataSourceUri class.

WFS (web feature service) data provider (wfs)

Used to access data provided by a web feature service.

The url can be a HTTP url to a WFS server (legacy, e.g. http://foobar/wfs?TYPENAME=xxx&SRSNAME=yyy[&FILTER=zzz]), or a URI constructed using the QgsDataSourceUri class with the following parameters (note that parameter keys are case sensitive):

The ‘filter’ key value can either be a QGIS expression or an OGC XML filter. If the value is set to a QGIS expression the driver will turn it into OGC XML filter before passing it to the WFS server. Beware the QGIS expression filter only supports” =, !=, <, >, <=, >=, AND, OR, NOT, LIKE, IS NULL” attribute operators, “BBOX, Disjoint, Intersects, Touches, Crosses, Contains, Overlaps, Within” spatial binary operators and the QGIS local “geomFromWKT, geomFromGML” geometry constructor functions.

OGC API Features data provider (oapif)

Used to access data provided by a OGC API - Features server.

The URI should be constructed using the QgsDataSourceUri class with the following parameters:

Also note:

Delimited text file data provider (delimitedtext)

Accesses data in a delimited text file, for example CSV files generated by spreadsheets. The contents of the file are split into columns based on specified delimiter characters. Each record may be represented spatially either by an X and Y coordinate column, or by a WKT (well known text) formatted columns.

The url defines the filename, the formatting options (how the text in the file is divided into data fields, and which fields contain the X,Y coordinates or WKT text definition. The options are specified as url query items.

At its simplest the url can just be the filename, in which case it will be loaded as a CSV formatted file.

The url may include the following items:

GPX data provider (gpx)

Provider reads tracks, routes, and waypoints from a GPX file. The url defines the name of the file, and the type of data to retrieve from it ("track", "route", or "waypoint").

An example url is "/home/user/data/holiday.gpx?type=route"

Grass data provider (grass)

Provider to display vector data in a GRASS GIS layer.

See also
QgsVectorLayerUtils()

Definition at line 399 of file qgsvectorlayer.h.

Constructor & Destructor Documentation

◆ QgsVectorLayer() [1/2]

QgsVectorLayer::QgsVectorLayer ( const QString &  path = QString(),
const QString &  baseName = QString(),
const QString &  providerLib = "ogr",
const QgsVectorLayer::LayerOptions options = QgsVectorLayer::LayerOptions() 
)
explicit

Constructor - creates a vector layer.

The QgsVectorLayer is constructed by instantiating a data provider. The provider interprets the supplied path (url) of the data source to connect to and access the data.

Parameters
pathThe path or url of the parameter. Typically this encodes parameters used by the data provider as url query items.
baseNameThe name used to represent the layer in the legend
providerLibThe name of the data provider, e.g., "memory", "postgres"
optionslayer load options

Definition at line 162 of file qgsvectorlayer.cpp.

◆ ~QgsVectorLayer()

QgsVectorLayer::~QgsVectorLayer ( )
override

Definition at line 249 of file qgsvectorlayer.cpp.

◆ QgsVectorLayer() [2/2]

QgsVectorLayer::QgsVectorLayer ( const QgsVectorLayer rhs)
delete

QgsVectorLayer cannot be copied.

Member Function Documentation

◆ accept

bool QgsVectorLayer::accept ( QgsStyleEntityVisitorInterface visitor) const
overrideslot

Definition at line 1728 of file qgsvectorlayer.cpp.

◆ actions() [1/2]

QgsActionManager * QgsVectorLayer::actions ( )
inline

Returns all layer actions defined on this layer.

The pointer which is returned directly points to the actions object which is used by the layer, so any changes are immediately applied.

Definition at line 784 of file qgsvectorlayer.h.

◆ actions() [2/2]

const QgsActionManager * QgsVectorLayer::actions ( ) const
inline

Returns all layer actions defined on this layer.

The pointer which is returned is const.

Definition at line 791 of file qgsvectorlayer.h.

◆ addAttribute()

bool QgsVectorLayer::addAttribute ( const QgsField field)

Add an attribute field (but does not commit it) returns true if the field was added.

Note
Calls to addAttribute() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 3312 of file qgsvectorlayer.cpp.

◆ addExpressionField()

int QgsVectorLayer::addExpressionField ( const QString &  exp,
const QgsField fld 
)

Add a new field which is calculated by the expression specified.

Parameters
expThe expression which calculates the field
fldThe field to calculate
Returns
The index of the new field
Since
QGIS 2.9

Definition at line 4223 of file qgsvectorlayer.cpp.

◆ addFeature()

bool QgsVectorLayer::addFeature ( QgsFeature feature,
QgsFeatureSink::Flags  flags = QgsFeatureSink::Flags() 
)
virtual

Adds a single feature to the sink.

Feature addition behavior is controlled by the specified flags.

See also
addFeatures()
Returns
true in case of success and false in case of failure

Reimplemented from QgsFeatureSink.

Definition at line 1203 of file qgsvectorlayer.cpp.

◆ addFeatureRendererGenerator()

void QgsVectorLayer::addFeatureRendererGenerator ( QgsFeatureRendererGenerator generator)

Adds a new feature renderer generator to the layer.

Ownership of generator is transferred to the layer.

See also
removeFeatureRendererGenerator()
featureRendererGenerators()
Since
QGIS 3.18

Definition at line 4103 of file qgsvectorlayer.cpp.

◆ addFeatures()

bool QgsVectorLayer::addFeatures ( QgsFeatureList features,
QgsFeatureSink::Flags  flags = QgsFeatureSink::Flags() 
)
virtual

Adds a list of features to the sink.

Feature addition behavior is controlled by the specified flags.

See also
addFeature()
Returns
true in case of success and false in case of failure

Implements QgsFeatureSink.

Definition at line 3895 of file qgsvectorlayer.cpp.

◆ addJoin()

bool QgsVectorLayer::addJoin ( const QgsVectorLayerJoinInfo joinInfo)

Joins another vector layer to this layer.

Parameters
joinInfojoin object containing join layer id, target and source field
Note
since 2.6 returns bool indicating whether the join can be added

Definition at line 4202 of file qgsvectorlayer.cpp.

◆ addPart() [1/3]

Qgis::GeometryOperationResult QgsVectorLayer::addPart ( const QgsPointSequence ring)

Adds a new part polygon to a multipart feature.

Returns
Qgis::GeometryOperationResult
  • Success
  • LayerNotEditable
  • SelectionIsEmpty
  • SelectionIsGreaterThanOne
  • AddPartSelectedGeometryNotFound
  • AddPartNotMultiGeometry
  • InvalidBaseGeometry
  • InvalidInputGeometryType
Note
available in Python bindings as addPartV2
Calls to addPart() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1507 of file qgsvectorlayer.cpp.

◆ addPart() [2/3]

Qgis::GeometryOperationResult QgsVectorLayer::addPart ( const QList< QgsPointXY > &  ring)

Adds a new part polygon to a multipart feature.

Returns
Qgis::GeometryOperationResult
  • Success
  • LayerNotEditable
  • SelectionIsEmpty
  • SelectionIsGreaterThanOne
  • AddPartSelectedGeometryNotFound
  • AddPartNotMultiGeometry
  • InvalidBaseGeometry
  • InvalidInputGeometryType
Note
Calls to addPart() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Deprecated:
since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

Definition at line 1485 of file qgsvectorlayer.cpp.

◆ addPart() [3/3]

Qgis::GeometryOperationResult QgsVectorLayer::addPart ( QgsCurve ring)
Note
available in Python as addCurvedPart
Calls to addPart() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1535 of file qgsvectorlayer.cpp.

◆ addRing() [1/3]

Qgis::GeometryOperationResult QgsVectorLayer::addRing ( const QgsPointSequence ring,
QgsFeatureId featureId = nullptr 
)

Adds a ring to polygon/multipolygon features.

Parameters
ringring to add
featureIdif specified, feature ID for feature ring was added to will be stored in this parameter
Returns
Qgis::GeometryOperationResult
  • Success
  • LayerNotEditable
  • AddRingNotInExistingFeature
  • InvalidInputGeometryType
  • AddRingNotClosed
  • AddRingNotValid
  • AddRingCrossesExistingRings
Note
Calls to addRing() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1420 of file qgsvectorlayer.cpp.

◆ addRing() [2/3]

Qgis::GeometryOperationResult QgsVectorLayer::addRing ( const QVector< QgsPointXY > &  ring,
QgsFeatureId featureId = nullptr 
)

Adds a ring to polygon/multipolygon features.

Parameters
ringring to add
featureIdif specified, feature ID for feature ring was added to will be stored in this parameter
Returns
Qgis::GeometryOperationResult
  • Success
  • LayerNotEditable
  • AddRingNotInExistingFeature
  • InvalidInputGeometryType
  • AddRingNotClosed
  • AddRingNotValid
  • AddRingCrossesExistingRings
Note
Calls to addRing() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Deprecated:
since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

Definition at line 1413 of file qgsvectorlayer.cpp.

◆ addRing() [3/3]

Qgis::GeometryOperationResult QgsVectorLayer::addRing ( QgsCurve ring,
QgsFeatureId featureId = nullptr 
)

Adds a ring to polygon/multipolygon features (takes ownership)

Parameters
ringring to add
featureIdif specified, feature ID for feature ring was added to will be stored in this parameter
Returns
Qgis::GeometryOperationResult
  • Success
  • LayerNotEditable
  • AddRingNotInExistingFeature
  • InvalidInputGeometryType
  • AddRingNotClosed
  • AddRingNotValid
  • AddRingCrossesExistingRings
Note
available in Python as addCurvedRing
Calls to addRing() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1445 of file qgsvectorlayer.cpp.

◆ addTopologicalPoints() [1/4]

int QgsVectorLayer::addTopologicalPoints ( const QgsGeometry geom)

Adds topological points for every vertex of the geometry.

Parameters
geomthe geometry where each vertex is added to segments of other features
Returns
-1 in case of layer error (invalid or non editable)
0 in case of success
1 in case of geometry error (non spatial or null geometry)
2 in case no vertices needed to be added
Note
geom is not going to be modified by the function
Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1625 of file qgsvectorlayer.cpp.

◆ addTopologicalPoints() [2/4]

int QgsVectorLayer::addTopologicalPoints ( const QgsPoint p)

Adds a vertex to segments which intersect point p but don't already have a vertex there.

If a feature already has a vertex at position p, no additional vertex is inserted. This method is useful for topological editing.

Parameters
pposition of the vertex
Returns
-1 in case of layer error (invalid or non editable)
0 in case of success
1 in case of geometry error (non spatial or null geometry)
2 in case no vertices needed to be added
Note
Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Since
3.10

Definition at line 1643 of file qgsvectorlayer.cpp.

◆ addTopologicalPoints() [3/4]

int QgsVectorLayer::addTopologicalPoints ( const QgsPointSequence ps)

Adds a vertex to segments which intersect any of the points p but don't already have a vertex there.

If a feature already has a vertex at position p, no additional vertex is inserted. This method is useful for topological editing.

Parameters
pspoint sequence of the vertices
Returns
-1 in case of layer error (invalid or non editable)
0 in case of success
1 in case of geometry error (non spatial or null geometry)
2 in case no vertices needed to be added
Note
Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Since
3.16

Definition at line 1654 of file qgsvectorlayer.cpp.

◆ addTopologicalPoints() [4/4]

int QgsVectorLayer::addTopologicalPoints ( const QgsPointXY p)

Adds a vertex to segments which intersect point p but don't already have a vertex there.

If a feature already has a vertex at position p, no additional vertex is inserted. This method is useful for topological editing.

Parameters
pposition of the vertex
Returns
-1 in case of layer error (invalid or non editable)
0 in case of success
1 in case of geometry error (non spatial or null geometry)
2 in case no vertices needed to be added
Note
Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Deprecated:
since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

Definition at line 1636 of file qgsvectorlayer.cpp.

◆ afterCommitChanges

void QgsVectorLayer::afterCommitChanges ( )
signal

Emitted after changes are committed to the data provider.

Since
QGIS 3.16

◆ afterRollBack

void QgsVectorLayer::afterRollBack ( )
signal

Emitted after changes are rolled back.

Since
QGIS 3.4

◆ aggregate()

QVariant QgsVectorLayer::aggregate ( QgsAggregateCalculator::Aggregate  aggregate,
const QString &  fieldOrExpression,
const QgsAggregateCalculator::AggregateParameters parameters = QgsAggregateCalculator::AggregateParameters(),
QgsExpressionContext context = nullptr,
bool *  ok = nullptr,
QgsFeatureIds fids = nullptr,
QgsFeedback feedback = nullptr,
QString *  error = nullptr 
) const

Calculates an aggregated value from the layer's features.

Currently any filtering expression provided will override filters in the FeatureRequest.

Parameters
aggregateaggregate to calculate
fieldOrExpressionsource field or expression to use as basis for aggregated values.
parametersparameters controlling aggregate calculation
contextexpression context for expressions and filters
okif specified, will be set to true if aggregate calculation was successful
fidslist of fids to filter, otherwise will use all fids
feedbackoptional feedback argument for early cancellation (since QGIS 3.22)
erroroptional storage for error messages (not available in Python bindings)
Returns
calculated aggregate value
Since
QGIS 2.16

Definition at line 4880 of file qgsvectorlayer.cpp.

◆ allowCommit()

bool QgsVectorLayer::allowCommit ( ) const

Controls, if the layer is allowed to commit changes.

If this is set to false it will not be possible to commit changes on this layer. This can be used to define checks on a layer that need to be pass before the layer can be saved. If you use this API, make sure that:

  • the user is visibly informed that his changes were not saved and what he needs to do in order to be able to save the changes.
  • to set the property back to true, once the user has fixed his data.

When calling

See also
commitChanges() this flag is checked just after the
beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 6155 of file qgsvectorlayer.cpp.

◆ allowCommitChanged

void QgsVectorLayer::allowCommitChanged ( )
signal

Emitted whenever the allowCommitChanged() property of this layer changes.

Since
QGIS 3.4

◆ attributeAdded

void QgsVectorLayer::attributeAdded ( int  idx)
signal

Will be emitted, when a new attribute has been added to this vector layer.

Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression

Parameters
idxThe index of the new attribute
See also
updatedFields()

◆ attributeAlias()

QString QgsVectorLayer::attributeAlias ( int  index) const

Returns the alias of an attribute name or a null string if there is no alias.

See also
{attributeDisplayName( int attributeIndex )} which returns the field name if no alias is defined.

Definition at line 3396 of file qgsvectorlayer.cpp.

◆ attributeAliases()

QgsStringMap QgsVectorLayer::attributeAliases ( ) const

Returns a map of field name to attribute alias.

Definition at line 3416 of file qgsvectorlayer.cpp.

◆ attributeDeleted

void QgsVectorLayer::attributeDeleted ( int  idx)
signal

Will be emitted, when an attribute has been deleted from this vector layer.

Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression

Parameters
idxThe index of the deleted attribute
See also
updatedFields()

◆ attributeDisplayName()

QString QgsVectorLayer::attributeDisplayName ( int  index) const

Convenience function that returns the attribute alias if defined or the field name else.

Definition at line 3406 of file qgsvectorlayer.cpp.

◆ attributeList()

QgsAttributeList QgsVectorLayer::attributeList ( ) const
inline

Returns list of attribute indexes.

i.e. a list from 0 ... fieldCount()

Definition at line 1691 of file qgsvectorlayer.h.

◆ attributeTableConfig()

QgsAttributeTableConfig QgsVectorLayer::attributeTableConfig ( ) const

Returns the attribute table configuration object.

This defines the appearance of the attribute table.

Definition at line 5523 of file qgsvectorlayer.cpp.

◆ attributeValueChanged

void QgsVectorLayer::attributeValueChanged ( QgsFeatureId  fid,
int  idx,
const QVariant &  value 
)
signal

Emitted whenever an attribute value change is done in the edit buffer.

Note that at this point the attribute change is not yet saved to the provider.

Parameters
fidThe id of the changed feature
idxThe attribute index of the changed attribute
valueThe new value of the attribute

◆ auxiliaryLayer() [1/2]

QgsAuxiliaryLayer * QgsVectorLayer::auxiliaryLayer ( )

Returns the current auxiliary layer.

Since
QGIS 3.0

Definition at line 5859 of file qgsvectorlayer.cpp.

◆ auxiliaryLayer() [2/2]

const QgsAuxiliaryLayer * QgsVectorLayer::auxiliaryLayer ( ) const

Returns the current const auxiliary layer.

Since
QGIS 3.0

Definition at line 5852 of file qgsvectorlayer.cpp.

◆ beforeAddingExpressionField

void QgsVectorLayer::beforeAddingExpressionField ( const QString &  fieldName)
signal

Will be emitted, when an expression field is going to be added to this vector layer.

Applies only to types QgsFields::OriginExpression

Parameters
fieldNameThe name of the attribute to be added

◆ beforeCommitChanges

void QgsVectorLayer::beforeCommitChanges ( bool  stopEditing)
signal

Emitted before changes are committed to the data provider.

The stopEditing flag specifies if the editing mode shall be left after this commit.

◆ beforeEditingStarted

void QgsVectorLayer::beforeEditingStarted ( )
signal

Emitted before editing on this layer is started.

◆ beforeModifiedCheck

void QgsVectorLayer::beforeModifiedCheck ( ) const
signal

Emitted when the layer is checked for modifications. Use for last-minute additions.

◆ beforeRemovingExpressionField

void QgsVectorLayer::beforeRemovingExpressionField ( int  idx)
signal

Will be emitted, when an expression field is going to be deleted from this vector layer.

Applies only to types QgsFields::OriginExpression

Parameters
idxThe index of the attribute to be deleted

◆ beforeRollBack

void QgsVectorLayer::beforeRollBack ( )
signal

Emitted before changes are rolled back.

◆ beginEditCommand()

void QgsVectorLayer::beginEditCommand ( const QString &  text)

Create edit command for undo/redo operations.

Parameters
texttext which is to be displayed in undo window

Definition at line 4138 of file qgsvectorlayer.cpp.

◆ boundingBoxOfSelected()

QgsRectangle QgsVectorLayer::boundingBoxOfSelected ( ) const

Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned.

Definition at line 823 of file qgsvectorlayer.cpp.

◆ capabilitiesString()

QString QgsVectorLayer::capabilitiesString ( ) const

Capabilities for this layer, comma separated and translated.

Definition at line 399 of file qgsvectorlayer.cpp.

◆ changeAttributeValue()

bool QgsVectorLayer::changeAttributeValue ( QgsFeatureId  fid,
int  field,
const QVariant &  newValue,
const QVariant &  oldValue = QVariant(),
bool  skipDefaultValues = false 
)

Changes an attribute value for a feature (but does not immediately commit the changes).

The fid argument specifies the ID of the feature to be changed.

The field argument must specify a valid field index for the layer (where an index of 0 corresponds to the first field).

The new value to be assigned to the field is given by newValue.

If a valid QVariant is specified for oldValue, it will be used as the field value in the case of an undo operation corresponding to this attribute value change. If an invalid QVariant is used (the default behavior), then the feature's current value will be automatically retrieved and used. Note that this involves a feature request to the underlying data provider, so it is more efficient to explicitly pass an oldValue if it is already available.

If skipDefaultValues is set to true, default field values will not be updated. This can be used to override default field value expressions.

Returns
true if the feature's attribute was successfully changed.
Note
Calls to changeAttributeValue() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
See also
startEditing()
commitChanges()
changeGeometry()
updateFeature()

Definition at line 3216 of file qgsvectorlayer.cpp.

◆ changeAttributeValues()

bool QgsVectorLayer::changeAttributeValues ( QgsFeatureId  fid,
const QgsAttributeMap newValues,
const QgsAttributeMap oldValues = QgsAttributeMap(),
bool  skipDefaultValues = false 
)

Changes attributes' values for a feature (but does not immediately commit the changes).

The fid argument specifies the ID of the feature to be changed.

The new values to be assigned to the fields are given by newValues.

If a valid QVariant is specified for a field in oldValues, it will be used as the field value in the case of an undo operation corresponding to this attribute value change. If an invalid QVariant is used (the default behavior), then the feature's current value will be automatically retrieved and used. Note that this involves a feature request to the underlying data provider, so it is more efficient to explicitly pass an oldValue if it is already available.

If skipDefaultValues is set to true, default field values will not be updated. This can be used to override default field value expressions.

Returns
true if feature's attributes was successfully changed.
Note
Calls to changeAttributeValues() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
See also
startEditing()
commitChanges()
changeGeometry()
updateFeature()
changeAttributeValue()
Since
QGIS 3.0

Definition at line 3249 of file qgsvectorlayer.cpp.

◆ changeGeometry()

bool QgsVectorLayer::changeGeometry ( QgsFeatureId  fid,
QgsGeometry geometry,
bool  skipDefaultValue = false 
)

Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the changes).

The fid argument specifies the ID of the feature to be changed.

If skipDefaultValue is set to true, default field values will not be updated. This can be used to override default field value expressions.

Returns
true if the feature's geometry was successfully changed.
Note
Calls to changeGeometry() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
See also
startEditing()
commitChanges()
changeAttributeValue()
updateFeature()

Definition at line 3190 of file qgsvectorlayer.cpp.

◆ clone()

QgsVectorLayer * QgsVectorLayer::clone ( ) const
overridevirtual

Returns a new instance equivalent to this one.

A new provider is created for the same data source and renderers for features and diagrams are cloned too. Moreover, each attributes (transparency, extent, selected features and so on) are identical.

Returns
a new layer instance
Since
QGIS 3.0

Implements QgsMapLayer.

Definition at line 275 of file qgsvectorlayer.cpp.

◆ commitChanges()

bool QgsVectorLayer::commitChanges ( bool  stopEditing = true)

Attempts to commit to the underlying data provider any buffered changes made since the last to call to startEditing().

Returns the result of the attempt. If a commit fails (i.e. false is returned), the in-memory changes are left untouched and are not discarded. This allows editing to continue if the commit failed on e.g. a disallowed value in a Postgres database - the user can re-edit and try again.

The commits occur in distinct stages, (add attributes, add features, change attribute values, change geometries, delete features, delete attributes) so if a stage fails, it can be difficult to roll back cleanly. Therefore any error message returned by commitErrors() also includes which stage failed so that the user has some chance of repairing the damage cleanly.

By setting stopEditing to false, the layer will stay in editing mode. Otherwise the layer editing mode will be disabled if the commit is successful.

See also
startEditing()
commitErrors()
rollBack()

Definition at line 3707 of file qgsvectorlayer.cpp.

◆ commitErrors()

QStringList QgsVectorLayer::commitErrors ( ) const

Returns a list containing any error messages generated when attempting to commit changes to the layer.

See also
commitChanges()

Definition at line 3783 of file qgsvectorlayer.cpp.

◆ committedAttributesAdded

void QgsVectorLayer::committedAttributesAdded ( const QString &  layerId,
const QList< QgsField > &  addedAttributes 
)
signal

Emitted when attributes are added to the provider if not in transaction mode.

◆ committedAttributesDeleted

void QgsVectorLayer::committedAttributesDeleted ( const QString &  layerId,
const QgsAttributeList deletedAttributes 
)
signal

Emitted when attributes are deleted from the provider if not in transaction mode.

◆ committedAttributeValuesChanges

void QgsVectorLayer::committedAttributeValuesChanges ( const QString &  layerId,
const QgsChangedAttributesMap changedAttributesValues 
)
signal

Emitted when attribute value changes are saved to the provider if not in transaction mode.

◆ committedFeaturesAdded

void QgsVectorLayer::committedFeaturesAdded ( const QString &  layerId,
const QgsFeatureList addedFeatures 
)
signal

Emitted when features are added to the provider if not in transaction mode.

◆ committedFeaturesRemoved

void QgsVectorLayer::committedFeaturesRemoved ( const QString &  layerId,
const QgsFeatureIds deletedFeatureIds 
)
signal

Emitted when features are deleted from the provider if not in transaction mode.

◆ committedGeometriesChanges

void QgsVectorLayer::committedGeometriesChanges ( const QString &  layerId,
const QgsGeometryMap changedGeometries 
)
signal

Emitted when geometry changes are saved to the provider if not in transaction mode.

◆ conditionalStyles()

QgsConditionalLayerStyles * QgsVectorLayer::conditionalStyles ( ) const

Returns the conditional styles that are set for this layer.

Style information is used to render conditional formatting in the attribute table.

Returns
Return a QgsConditionalLayerStyles object holding the conditional attribute style information. Style information is generic and can be used for anything.
Since
QGIS 2.12

Definition at line 1173 of file qgsvectorlayer.cpp.

◆ constraintDescription()

QString QgsVectorLayer::constraintDescription ( int  index) const

Returns the descriptive name for the constraint expression for a specified field index.

See also
fieldConstraints()
constraintExpression()
setConstraintExpression()
Since
QGIS 3.0

Definition at line 6043 of file qgsvectorlayer.cpp.

◆ constraintExpression()

QString QgsVectorLayer::constraintExpression ( int  index) const

Returns the constraint expression for for a specified field index, if set.

See also
fieldConstraints()
constraintDescription()
setConstraintExpression()
Since
QGIS 3.0

Definition at line 6033 of file qgsvectorlayer.cpp.

◆ countSymbolFeatures()

QgsVectorLayerFeatureCounter * QgsVectorLayer::countSymbolFeatures ( bool  storeSymbolFids = false)

Count features for symbols.

The method will return the feature counter task. You will need to connect to the symbolFeatureCountMapChanged() signal to be notified when the freshly updated feature counts are ready.

Parameters
storeSymbolFidsIf true will gather the feature ids (fids) per symbol, otherwise only the count. Default false.
Note
If the count features for symbols has been already done a nullptr is returned. If you need to wait for the results, you can call waitForFinished() on the feature counter.
Since
This is asynchronous since QGIS 3.0

Definition at line 934 of file qgsvectorlayer.cpp.

◆ createExpressionContext()

QgsExpressionContext QgsVectorLayer::createExpressionContext ( ) const
virtual

This method needs to be reimplemented in all classes which implement this interface and return an expression context.

Since
QGIS 3.0

Implements QgsExpressionContextGenerator.

Definition at line 5546 of file qgsvectorlayer.cpp.

◆ createExpressionContextScope()

QgsExpressionContextScope * QgsVectorLayer::createExpressionContextScope ( ) const
virtual

This method needs to be reimplemented in all classes which implement this interface and return an expression context scope.

Since
QGIS 3.0

Implements QgsExpressionContextScopeGenerator.

Definition at line 5554 of file qgsvectorlayer.cpp.

◆ createMapRenderer()

QgsMapLayerRenderer * QgsVectorLayer::createMapRenderer ( QgsRenderContext rendererContext)
virtual

Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.

Since
QGIS 2.4

Implements QgsMapLayer.

Definition at line 461 of file qgsvectorlayer.cpp.

◆ createProfileGenerator()

QgsAbstractProfileGenerator * QgsVectorLayer::createProfileGenerator ( const QgsProfileRequest request)
overridevirtual

Given a profile request, returns a new profile generator ready for generating elevation profiles.

The caller takes ownership of the returned generator.

May return nullptr if the source cannot generate a profile at this time.

Implements QgsAbstractProfileSource.

Definition at line 778 of file qgsvectorlayer.cpp.

◆ dataComment()

QString QgsVectorLayer::dataComment ( ) const

Returns a description for this layer as defined in the data provider.

Definition at line 424 of file qgsvectorlayer.cpp.

◆ dataProvider() [1/2]

const QgsVectorDataProvider * QgsVectorLayer::dataProvider ( ) const
virtual

Returns the layer's data provider in a const-correct manner, it may be nullptr.

Note
not available in Python bindings

Reimplemented from QgsMapLayer.

Definition at line 748 of file qgsvectorlayer.cpp.

◆ dataProvider() [2/2]

QgsVectorDataProvider * QgsVectorLayer::dataProvider ( )
virtual

Returns the layer's data provider, it may be nullptr.

Reimplemented from QgsMapLayer.

Definition at line 740 of file qgsvectorlayer.cpp.

◆ decodedSource()

QString QgsVectorLayer::decodedSource ( const QString &  source,
const QString &  dataProvider,
const QgsReadWriteContext context 
) const
virtual

Called by readLayerXML(), used by derived classes to decode provider's specific data source from project files.

Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes ("HDF5:")

Parameters
sourcedata source to decode, typically read from layer's DOM element "datasource"
dataProviderstring identification of data provider (e.g. "ogr"), typically read from layer's DOM element
contextreading context (e.g. for conversion between relative and absolute paths)
Returns
decoded source, typically to be used as the layer's datasource
Since
QGIS 3.2

Reimplemented from QgsMapLayer.

Definition at line 2258 of file qgsvectorlayer.cpp.

◆ defaultValue()

QVariant QgsVectorLayer::defaultValue ( int  index,
const QgsFeature feature = QgsFeature(),
QgsExpressionContext context = nullptr 
) const

Returns the calculated default value for the specified field index.

The default value may be taken from a client side default value expression (see setDefaultValueDefinition()) or taken from the underlying data provider.

Parameters
indexfield index
featureoptional feature to use for default value evaluation. If passed, then properties from the feature (such as geometry) can be used when calculating the default value.
contextoptional expression context to evaluate expressions again. If not specified, a default context will be created
Returns
calculated default value
See also
setDefaultValueDefinition()
Since
QGIS 3.0

Definition at line 4406 of file qgsvectorlayer.cpp.

◆ defaultValueDefinition()

QgsDefaultValue QgsVectorLayer::defaultValueDefinition ( int  index) const

Returns the definition of the expression used when calculating the default value for a field.

Parameters
indexfield index
Returns
definition of the default value with the expression evaluated when calculating default values for field, or definition with an empty string if no default is set
See also
defaultValue()
setDefaultValueDefinition()
Since
QGIS 3.0

Definition at line 4472 of file qgsvectorlayer.cpp.

◆ deleteAttribute()

bool QgsVectorLayer::deleteAttribute ( int  attr)
virtual

Deletes an attribute field (but does not commit it).

Note
Calls to deleteAttribute() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Reimplemented in QgsAuxiliaryLayer.

Definition at line 3494 of file qgsvectorlayer.cpp.

◆ deleteAttributes()

bool QgsVectorLayer::deleteAttributes ( const QList< int > &  attrs)

Deletes a list of attribute fields (but does not commit it)

Parameters
attrsthe indices of the attributes to delete
Returns
true if at least one attribute has been deleted

Definition at line 3513 of file qgsvectorlayer.cpp.

◆ deleteFeature()

bool QgsVectorLayer::deleteFeature ( QgsFeatureId  fid,
QgsVectorLayer::DeleteContext context = nullptr 
)

Deletes a feature from the layer (but does not commit it).

Parameters
fidThe feature id to delete
contextThe chain of features who will be deleted for feedback and to avoid endless recursions
Note
Calls to deleteFeature() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 3606 of file qgsvectorlayer.cpp.

◆ deleteFeatures()

bool QgsVectorLayer::deleteFeatures ( const QgsFeatureIds fids,
QgsVectorLayer::DeleteContext context = nullptr 
)

Deletes a set of features from the layer (but does not commit it)

Parameters
fidsThe feature ids to delete
contextThe chain of features who will be deleted for feedback and to avoid endless recursions
Returns
false if the layer is not in edit mode or does not support deleting in case of an active transaction depends on the provider implementation
Note
Calls to deleteFeatures() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 3623 of file qgsvectorlayer.cpp.

◆ deleteSelectedFeatures()

bool QgsVectorLayer::deleteSelectedFeatures ( int *  deletedCount = nullptr,
QgsVectorLayer::DeleteContext context = nullptr 
)

Deletes the selected features.

Parameters
deletedCountThe number of successfully deleted features
contextThe chain of features who will be deleted for feedback and to avoid endless recursions
Returns
true in case of success and false otherwise

Definition at line 1367 of file qgsvectorlayer.cpp.

◆ deleteVertex()

Qgis::VectorEditResult QgsVectorLayer::deleteVertex ( QgsFeatureId  featureId,
int  vertex 
)

Deletes a vertex from a feature.

Parameters
featureIdID of feature to remove vertex from
vertexindex of vertex to delete
Note
Calls to deleteVertex() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Since
QGIS 2.14

Definition at line 1351 of file qgsvectorlayer.cpp.

◆ dependencies()

QSet< QgsMapLayerDependency > QgsVectorLayer::dependencies ( ) const
virtual

Gets the list of dependencies.

This includes data dependencies set by the user (

See also
setDataDependencies) as well as dependencies given by the provider
Returns
a set of QgsMapLayerDependency
Since
QGIS 3.0

Reimplemented from QgsMapLayer.

Definition at line 5866 of file qgsvectorlayer.cpp.

◆ deselect [1/2]

void QgsVectorLayer::deselect ( const QgsFeatureIds featureIds)
slot

Deselects features by their ID.

Parameters
featureIdsThe ids of the features to deselect
See also
deselect(const QgsFeatureId)

Definition at line 521 of file qgsvectorlayer.cpp.

◆ deselect [2/2]

void QgsVectorLayer::deselect ( QgsFeatureId  featureId)
slot

Deselects feature by its ID.

Parameters
featureIdThe id of the feature to deselect
See also
deselect(const QgsFeatureIds&)

Definition at line 511 of file qgsvectorlayer.cpp.

◆ destroyEditCommand()

void QgsVectorLayer::destroyEditCommand ( )

Destroy active command and reverts all changes in it.

Definition at line 4178 of file qgsvectorlayer.cpp.

◆ diagramLayerSettings()

const QgsDiagramLayerSettings * QgsVectorLayer::diagramLayerSettings ( ) const
inline

Definition at line 938 of file qgsvectorlayer.h.

◆ diagramRenderer()

const QgsDiagramRenderer * QgsVectorLayer::diagramRenderer ( ) const
inline

Definition at line 935 of file qgsvectorlayer.h.

◆ diagramsEnabled()

bool QgsVectorLayer::diagramsEnabled ( ) const

Returns whether the layer contains diagrams which are enabled and should be drawn.

Returns
true if layer contains enabled diagrams
Since
QGIS 2.9

Definition at line 899 of file qgsvectorlayer.cpp.

◆ displayExpression()

QString QgsVectorLayer::displayExpression ( ) const

Returns the preview expression, used to create a human readable preview string.

Uses QgsExpression

Returns
The expression which will be used to preview features for this layer

Definition at line 3953 of file qgsvectorlayer.cpp.

◆ displayExpressionChanged

void QgsVectorLayer::displayExpressionChanged ( )
signal

Emitted when the display expression changes.

Since
QGIS 3.0

◆ displayField()

QString QgsVectorLayer::displayField ( ) const

This is a shorthand for accessing the displayExpression if it is a simple field.

If the displayExpression is more complex than a simple field, a null string will be returned.

See also
displayExpression

Definition at line 3929 of file qgsvectorlayer.cpp.

◆ drawVertexMarker()

void QgsVectorLayer::drawVertexMarker ( double  x,
double  y,
QPainter &  p,
Qgis::VertexMarkerType  type,
int  vertexSize 
)
static

Draws a vertex symbol at (screen) coordinates x, y.

(Useful to assist vertex editing.)

Deprecated:
Use the equivalent QgsSymbolLayerUtils::drawVertexMarker function instead

Definition at line 470 of file qgsvectorlayer.cpp.

◆ editBuffer() [1/2]

Q_INVOKABLE QgsVectorLayerEditBuffer * QgsVectorLayer::editBuffer ( )
inline

Buffer with uncommitted editing operations. Only valid after editing has been turned on.

Definition at line 2038 of file qgsvectorlayer.h.

◆ editBuffer() [2/2]

const QgsVectorLayerEditBuffer * QgsVectorLayer::editBuffer ( ) const
inline

Buffer with uncommitted editing operations.

Only valid after editing has been turned on.

Note
not available in Python bindings

Definition at line 2044 of file qgsvectorlayer.h.

◆ editCommandDestroyed

void QgsVectorLayer::editCommandDestroyed ( )
signal

Signal emitted, when an edit command is destroyed.

Note
This is not a rollback, it is only related to the current edit command. See beforeRollBack()

◆ editCommandEnded

void QgsVectorLayer::editCommandEnded ( )
signal

Signal emitted, when an edit command successfully ended.

Note
This does not mean it is also committed, only that it is written to the edit buffer. See beforeCommitChanges()

◆ editCommandStarted

void QgsVectorLayer::editCommandStarted ( const QString &  text)
signal

Signal emitted when a new edit command has been started.

Parameters
textDescription for this edit command

◆ editFormConfig()

QgsEditFormConfig QgsVectorLayer::editFormConfig ( ) const

Returns the configuration of the form used to represent this vector layer.

Returns
The configuration of this layers' form
Since
QGIS 2.14

Definition at line 5504 of file qgsvectorlayer.cpp.

◆ editFormConfigChanged

void QgsVectorLayer::editFormConfigChanged ( )
signal

Will be emitted whenever the edit form configuration of this layer changes.

Since
QGIS 3.0

◆ editorWidgetSetup()

QgsEditorWidgetSetup QgsVectorLayer::editorWidgetSetup ( int  index) const

The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field at index.

Since
QGIS 3.0

Definition at line 6117 of file qgsvectorlayer.cpp.

◆ elevationProperties()

QgsMapLayerElevationProperties * QgsVectorLayer::elevationProperties ( )
overridevirtual

Returns the layer's elevation properties.

This may be nullptr, depending on the layer type.

Since
QGIS 3.18

Reimplemented from QgsMapLayer.

Definition at line 771 of file qgsvectorlayer.cpp.

◆ encodedSource()

QString QgsVectorLayer::encodedSource ( const QString &  source,
const QgsReadWriteContext context 
) const
virtual

Called by writeLayerXML(), used by derived classes to encode provider's specific data source to project files.

Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes ("HDF5:")

Parameters
sourcedata source to encode, typically QgsMapLayer::source()
contextwriting context (e.g. for conversion between relative and absolute paths)
Returns
encoded source, typically to be written in the DOM element "datasource"
Since
QGIS 3.2

Reimplemented from QgsMapLayer.

Definition at line 2245 of file qgsvectorlayer.cpp.

◆ endEditCommand()

void QgsVectorLayer::endEditCommand ( )

Finish edit command and add it to undo/redo stack.

Definition at line 4156 of file qgsvectorlayer.cpp.

◆ excludeAttributesWfs()

QSet< QString > QgsVectorLayer::excludeAttributesWfs ( ) const

A set of attributes that are not advertised in WFS requests with QGIS server.

Deprecated:
since QGIS 3.16, use fields().configurationFlags() instead

Definition at line 3466 of file qgsvectorlayer.cpp.

◆ excludeAttributesWms()

QSet< QString > QgsVectorLayer::excludeAttributesWms ( ) const

A set of attributes that are not advertised in WMS requests with QGIS server.

Deprecated:
since QGIS 3.16, use fields().configurationFlags() instead

Definition at line 3438 of file qgsvectorlayer.cpp.

◆ expressionField()

QString QgsVectorLayer::expressionField ( int  index) const

Returns the expression used for a given expression field.

Parameters
indexAn index of an epxression based (virtual) field
Returns
The expression for the field at index
Since
QGIS 2.9

Definition at line 4246 of file qgsvectorlayer.cpp.

◆ extent()

QgsRectangle QgsVectorLayer::extent ( ) const
virtual

Returns the extent of the layer.

Reimplemented from QgsMapLayer.

Definition at line 1009 of file qgsvectorlayer.cpp.

◆ featureAdded

void QgsVectorLayer::featureAdded ( QgsFeatureId  fid)
signal

Emitted when a new feature has been added to the layer.

Parameters
fidThe id of the new feature

◆ featureBlendMode()

QPainter::CompositionMode QgsVectorLayer::featureBlendMode ( ) const

Returns the current blending mode for features.

Definition at line 4947 of file qgsvectorlayer.cpp.

◆ featureBlendModeChanged

void QgsVectorLayer::featureBlendModeChanged ( QPainter::CompositionMode  blendMode)
signal

Signal emitted when setFeatureBlendMode() is called.

◆ featureCount() [1/2]

long long QgsVectorLayer::featureCount ( ) const
virtual

Returns feature count including changes which have not yet been committed If you need only the count of committed features call this method on this layer's provider.

Returns
the number of features on this layer or -1 if unknown.

Implements QgsFeatureSource.

Definition at line 3676 of file qgsvectorlayer.cpp.

◆ featureCount() [2/2]

long long QgsVectorLayer::featureCount ( const QString &  legendKey) const

Number of features rendered with specified legend key.

Features must be first calculated by countSymbolFeatures()

Returns
number of features rendered by symbol or -1 if failed or counts are not available

Definition at line 915 of file qgsvectorlayer.cpp.

◆ featureDeleted

void QgsVectorLayer::featureDeleted ( QgsFeatureId  fid)
signal

Emitted when a feature has been deleted.

If you do expensive operations in a slot connected to this, you should prefer to use featuresDeleted( const QgsFeatureIds& ).

Parameters
fidThe id of the feature which has been deleted

◆ featureRendererGenerators()

QList< const QgsFeatureRendererGenerator * > QgsVectorLayer::featureRendererGenerators ( ) const

Returns a list of the feature renderer generators owned by the layer.

See also
addFeatureRendererGenerator()
removeFeatureRendererGenerator()
Since
QGIS 3.18

Definition at line 4127 of file qgsvectorlayer.cpp.

◆ featuresDeleted

void QgsVectorLayer::featuresDeleted ( const QgsFeatureIds fids)
signal

Emitted when features have been deleted.

If features are deleted within an edit command, this will only be emitted once at the end to allow connected slots to minimize the overhead. If features are deleted outside of an edit command, this signal will be emitted once per feature.

Parameters
fidsThe feature ids that have been deleted.

◆ fieldConfigurationFlags()

Qgis::FieldConfigurationFlags QgsVectorLayer::fieldConfigurationFlags ( int  index) const

Returns the configuration flags of the field at given index.

See also
QgsField::setConfigurationFlags()
Since
QGIS 3.16

Definition at line 6093 of file qgsvectorlayer.cpp.

◆ fieldConstraints()

QgsFieldConstraints::Constraints QgsVectorLayer::fieldConstraints ( int  fieldIndex) const

Returns any constraints which are present for a specified field index.

These constraints may be inherited from the layer's data provider or may be set manually on the vector layer from within QGIS.

See also
setFieldConstraint()
Since
QGIS 3.0

Definition at line 5954 of file qgsvectorlayer.cpp.

◆ fieldConstraintsAndStrength()

QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > QgsVectorLayer::fieldConstraintsAndStrength ( int  fieldIndex) const

Returns a map of constraint with their strength for a specific field of the layer.

Parameters
fieldIndexfield index
Since
QGIS 3.0

Definition at line 5972 of file qgsvectorlayer.cpp.

◆ fields()

QgsFields QgsVectorLayer::fields ( ) const
virtual

Returns the list of fields of this layer.

This also includes fields which have not yet been saved to the provider.

Returns
A list of fields

Implements QgsFeatureSource.

Definition at line 3649 of file qgsvectorlayer.cpp.

◆ geometryChanged

void QgsVectorLayer::geometryChanged ( QgsFeatureId  fid,
const QgsGeometry geometry 
)
signal

Emitted whenever a geometry change is done in the edit buffer.

Note that at this point the geometry change is not yet saved to the provider.

Parameters
fidThe id of the changed feature
geometryThe new geometry

◆ geometryOptions()

QgsGeometryOptions * QgsVectorLayer::geometryOptions ( ) const

Configuration and logic to apply automatically on any edit happening on this layer.

Since
QGIS 3.4

Definition at line 6173 of file qgsvectorlayer.cpp.

◆ geometryType()

Qgis::GeometryType QgsVectorLayer::geometryType ( ) const

Returns point, line or polygon.

Definition at line 808 of file qgsvectorlayer.cpp.

◆ getFeature()

QgsFeature QgsVectorLayer::getFeature ( QgsFeatureId  fid) const
inline

Queries the layer for the feature with the given id.

If there is no such feature, the returned feature will be invalid.

Definition at line 1166 of file qgsvectorlayer.h.

◆ getFeatures() [1/4]

QgsFeatureIterator QgsVectorLayer::getFeatures ( const QgsFeatureIds fids)
inline

Queries the layer for the features with the given ids.

Definition at line 1182 of file qgsvectorlayer.h.

◆ getFeatures() [2/4]

QgsFeatureIterator QgsVectorLayer::getFeatures ( const QgsFeatureRequest request = QgsFeatureRequest()) const
virtual

Queries the layer for features specified in request.

Parameters
requestfeature request describing parameters of features to return
Returns
iterator for matching features from provider

Implements QgsFeatureSource.

Definition at line 1180 of file qgsvectorlayer.cpp.

◆ getFeatures() [3/4]

QgsFeatureIterator QgsVectorLayer::getFeatures ( const QgsRectangle rectangle)
inline

Queries the layer for the features which intersect the specified rectangle.

Definition at line 1190 of file qgsvectorlayer.h.

◆ getFeatures() [4/4]

QgsFeatureIterator QgsVectorLayer::getFeatures ( const QString &  expression)
inline

Queries the layer for features matching a given expression.

Definition at line 1157 of file qgsvectorlayer.h.

◆ getGeometry()

QgsGeometry QgsVectorLayer::getGeometry ( QgsFeatureId  fid) const

Queries the layer for the geometry at the given id.

If there is no such feature, the returned geometry will be invalid.

Definition at line 1191 of file qgsvectorlayer.cpp.

◆ getSelectedFeatures()

QgsFeatureIterator QgsVectorLayer::getSelectedFeatures ( QgsFeatureRequest  request = QgsFeatureRequest()) const

Returns an iterator of the selected features.

Parameters
requestYou may specify a request, e.g. to limit the set of requested attributes. Any filter on the request will be discarded.
Returns
Iterator over the selected features
Warning
Calling this method returns an iterator for all attributes and geometry for the selected features. Consider using the much more efficient selectedFeatureIds() or selectedFeatureCount() if you do not require access to the feature attributes or geometry.
See also
selectedFeatureIds()
selectedFeatures()

Definition at line 3877 of file qgsvectorlayer.cpp.

◆ hasFeatures()

QgsFeatureSource::FeatureAvailability QgsVectorLayer::hasFeatures ( ) const
virtual

Determines if this vector layer has features.

Warning
when a layer is editable and some features have been deleted, this will return QgsFeatureSource::FeatureAvailability::FeaturesMayBeAvailable to avoid a potentially expensive call to the dataprovider.
Since
QGIS 3.4

Reimplemented from QgsFeatureSource.

Definition at line 3686 of file qgsvectorlayer.cpp.

◆ hasMapTips()

bool QgsVectorLayer::hasMapTips ( ) const
virtual

Returns true if the layer contains map tips.

See also
mapTipTemplate()
setMapTipTemplate()

Reimplemented from QgsMapLayer.

Definition at line 3975 of file qgsvectorlayer.cpp.

◆ hasSpatialIndex

QgsFeatureSource::SpatialIndexPresence QgsVectorLayer::hasSpatialIndex ( ) const
overrideslot

Definition at line 1721 of file qgsvectorlayer.cpp.

◆ htmlMetadata()

QString QgsVectorLayer::htmlMetadata ( ) const
virtual

Obtain a formatted HTML string containing assorted metadata for this layer.

Since
QGIS 3.0

Reimplemented from QgsMapLayer.

Definition at line 5570 of file qgsvectorlayer.cpp.

◆ insertVertex() [1/2]

bool QgsVectorLayer::insertVertex ( const QgsPoint point,
QgsFeatureId  atFeatureId,
int  beforeVertex 
)

Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature.

Not meaningful for Point geometries

Note
Calls to insertVertex() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1306 of file qgsvectorlayer.cpp.

◆ insertVertex() [2/2]

bool QgsVectorLayer::insertVertex ( double  x,
double  y,
QgsFeatureId  atFeatureId,
int  beforeVertex 
)

Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature.

Not meaningful for Point geometries

Note
Calls to insertVertex() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1291 of file qgsvectorlayer.cpp.

◆ invertSelection()

void QgsVectorLayer::invertSelection ( )

Selects not selected features and deselects selected ones.

Definition at line 671 of file qgsvectorlayer.cpp.

◆ invertSelectionInRectangle()

void QgsVectorLayer::invertSelectionInRectangle ( QgsRectangle rect)

Inverts selection of features found within the search rectangle (in layer's coordinates)

Parameters
rectThe rectangle in which the selection of features will be inverted
See also
invertSelection()

Definition at line 687 of file qgsvectorlayer.cpp.

◆ isAuxiliaryField()

bool QgsVectorLayer::isAuxiliaryField ( int  index,
int &  srcIndex 
) const

Returns true if the field comes from the auxiliary layer, false otherwise.

Since
QGIS 3.0

Definition at line 4044 of file qgsvectorlayer.cpp.

◆ isEditable()

bool QgsVectorLayer::isEditable ( ) const
virtual

Returns true if the provider is in editing mode.

Reimplemented from QgsMapLayer.

Definition at line 3983 of file qgsvectorlayer.cpp.

◆ isEditCommandActive()

bool QgsVectorLayer::isEditCommandActive ( ) const
inline

Tests if an edit command is active.

Since
QGIS 3.0

Definition at line 2409 of file qgsvectorlayer.h.

◆ isModified()

bool QgsVectorLayer::isModified ( ) const
overridevirtual

Returns true if the provider has been modified since the last commit.

Reimplemented from QgsMapLayer.

Definition at line 4036 of file qgsvectorlayer.cpp.

◆ isSpatial()

bool QgsVectorLayer::isSpatial ( ) const
virtual

Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry.

Reimplemented from QgsMapLayer.

Definition at line 3990 of file qgsvectorlayer.cpp.

◆ isSqlQuery()

bool QgsVectorLayer::isSqlQuery ( ) const

Returns true if the layer is a query (SQL) layer.

Note
this is simply a shortcut to check if the SqlQuery flag is set.
See also
vectorLayerTypeFlags()
Since
QGIS 3.24

Definition at line 410 of file qgsvectorlayer.cpp.

◆ joinBuffer() [1/2]

QgsVectorLayerJoinBuffer * QgsVectorLayer::joinBuffer ( )
inline

Returns the join buffer object.

Since
QGIS 2.14.7

Definition at line 706 of file qgsvectorlayer.h.

◆ joinBuffer() [2/2]

const QgsVectorLayerJoinBuffer * QgsVectorLayer::joinBuffer ( ) const
inline

Returns a const pointer on join buffer object.

Since
QGIS 3.10

Definition at line 712 of file qgsvectorlayer.h.

◆ labeling() [1/2]

QgsAbstractVectorLayerLabeling * QgsVectorLayer::labeling ( )
inline

Access to labeling configuration.

May be nullptr if labeling is not used.

Note
Labels will only be rendered if labelsEnabled() returns true.
See also
labelsEnabled()
Since
QGIS 3.0

Definition at line 1643 of file qgsvectorlayer.h.

◆ labeling() [2/2]

const QgsAbstractVectorLayerLabeling * QgsVectorLayer::labeling ( ) const
inline

Access to const labeling configuration.

May be nullptr if labeling is not used.

Note
Labels will only be rendered if labelsEnabled() returns true.
See also
labelsEnabled()
Since
QGIS 3.0

Definition at line 1635 of file qgsvectorlayer.h.

◆ labelingFontNotFound

void QgsVectorLayer::labelingFontNotFound ( QgsVectorLayer layer,
const QString &  fontfamily 
)
signal

Emitted when the font family defined for labeling layer is not found on system.

◆ labelsEnabled()

bool QgsVectorLayer::labelsEnabled ( ) const

Returns whether the layer contains labels which are enabled and should be drawn.

Returns
true if layer contains enabled labels
See also
setLabelsEnabled()
Since
QGIS 2.9

Definition at line 884 of file qgsvectorlayer.cpp.

◆ loadAuxiliaryLayer()

bool QgsVectorLayer::loadAuxiliaryLayer ( const QgsAuxiliaryStorage storage,
const QString &  key = QString() 
)

Loads the auxiliary layer for this vector layer.

If there's no corresponding table in the database, then nothing happens and false is returned. The key is optional because if this layer has been read from a XML document, then the key read in this document is used by default.

Parameters
storageThe auxiliary storage where to look for the table
keyThe key to use for joining.
Returns
true if the auxiliary layer is well loaded, false otherwise
Since
QGIS 3.0

Definition at line 5796 of file qgsvectorlayer.cpp.

◆ loadDefaultStyle()

QString QgsVectorLayer::loadDefaultStyle ( bool &  resultFlag)
virtual

Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Parameters
resultFlaga reference to a flag that will be set to false if we did not manage to load the default style.
Returns
a QString with any status messages
See also
loadNamedStyle()

Reimplemented from QgsMapLayer.

Definition at line 1950 of file qgsvectorlayer.cpp.

◆ maximumValue()

QVariant QgsVectorLayer::maximumValue ( int  index) const
virtual

Returns the maximum value for an attribute column or an invalid variant in case of error.

Note
In some circumstances when unsaved changes are present for the layer then the returned value may be outdated (for instance when the attribute value in a saved feature has been changed inside the edit buffer then the previous saved value may be returned as the maximum).
If both the minimum and maximum value are required it is more efficient to call minimumAndMaximumValue() instead of separate calls to minimumValue() and maximumValue().
See also
minimumValue()
minimumAndMaximumValue()
uniqueValues()

Reimplemented from QgsFeatureSource.

Definition at line 4704 of file qgsvectorlayer.cpp.

◆ minimumAndMaximumValue()

void QgsVectorLayer::minimumAndMaximumValue ( int  index,
QVariant &  minimum,
QVariant &  maximum 
) const

Calculates both the minimum and maximum value for an attribute column.

This is more efficient then calling both minimumValue() and maximumValue() when both the minimum and maximum values are required.

Parameters
indexindex of field to calculate minimum and maximum value for.
minimumwill be set to minimum attribute value or an invalid variant in case of error.
maximumwill be set to maximum attribute value or an invalid variant in case of error.
Note
In some circumstances when unsaved changes are present for the layer then the calculated values may be outdated (for instance when the attribute value in a saved feature has been changed inside the edit buffer then the previous saved value may be returned as the maximum).
See also
minimumValue()
maximumValue()
Since
QGIS 3.20

Definition at line 4713 of file qgsvectorlayer.cpp.

◆ minimumValue()

QVariant QgsVectorLayer::minimumValue ( int  index) const
virtual

Returns the minimum value for an attribute column or an invalid variant in case of error.

Note
In some circumstances when unsaved changes are present for the layer then the returned value may be outdated (for instance when the attribute value in a saved feature has been changed inside the edit buffer then the previous saved value may be returned as the minimum).
If both the minimum and maximum value are required it is more efficient to call minimumAndMaximumValue() instead of separate calls to minimumValue() and maximumValue().
See also
maximumValue()
minimumAndMaximumValue()
uniqueValues()

Reimplemented from QgsFeatureSource.

Definition at line 4695 of file qgsvectorlayer.cpp.

◆ modifySelection()

void QgsVectorLayer::modifySelection ( const QgsFeatureIds selectIds,
const QgsFeatureIds deselectIds 
)

Modifies the current selection on this layer.

Parameters
selectIdsSelect these ids
deselectIdsDeselect these ids
See also
selectByIds
deselect(const QgsFeatureIds&)
deselect(const QgsFeatureId)
selectByExpression()

Definition at line 654 of file qgsvectorlayer.cpp.

◆ moveVertex() [1/2]

bool QgsVectorLayer::moveVertex ( const QgsPoint p,
QgsFeatureId  atFeatureId,
int  atVertex 
)

Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates.

Note
available in Python as moveVertexV2
Calls to moveVertex() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1336 of file qgsvectorlayer.cpp.

◆ moveVertex() [2/2]

bool QgsVectorLayer::moveVertex ( double  x,
double  y,
QgsFeatureId  atFeatureId,
int  atVertex 
)

Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates.

Note
Calls to moveVertex() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1321 of file qgsvectorlayer.cpp.

◆ operator=()

QgsVectorLayer & QgsVectorLayer::operator= ( QgsVectorLayer const &  rhs)
delete

QgsVectorLayer cannot be copied.

◆ primaryKeyAttributes()

QgsAttributeList QgsVectorLayer::primaryKeyAttributes ( ) const

Returns the list of attributes which make up the layer's primary keys.

Definition at line 3657 of file qgsvectorlayer.cpp.

◆ raiseError

void QgsVectorLayer::raiseError ( const QString &  msg)
signal

Signals an error related to this vector layer.

◆ readCustomSymbology

void QgsVectorLayer::readCustomSymbology ( const QDomElement &  element,
QString &  errorMessage 
)
signal

Signal emitted whenever the symbology (QML-file) for this layer is being read.

If there is custom style information saved in the file, you can connect to this signal and update the layer style accordingly.

Parameters
elementThe XML layer style element.
errorMessageWrite error messages into this string.

◆ readExtentFromXml()

bool QgsVectorLayer::readExtentFromXml ( ) const

Returns true if the extent is read from the XML document when data source has no metadata, false if it's the data provider which determines it.

Since
QGIS 3.0

Definition at line 6187 of file qgsvectorlayer.cpp.

◆ readOnlyChanged

void QgsVectorLayer::readOnlyChanged ( )
signal

Emitted when the read only state of this layer is changed.

Only applies to manually set readonly state, not to the edit mode.

See also
setReadOnly()
Since
QGIS 3.0

◆ readSld()

bool QgsVectorLayer::readSld ( const QDomNode &  node,
QString &  errorMessage 
)
virtual

Reimplemented from QgsMapLayer.

Definition at line 3118 of file qgsvectorlayer.cpp.

◆ readStyle()

bool QgsVectorLayer::readStyle ( const QDomNode &  node,
QString &  errorMessage,
QgsReadWriteContext context,
QgsMapLayer::StyleCategories  categories = QgsMapLayer::AllStyleCategories 
)

Definition at line 2593 of file qgsvectorlayer.cpp.

◆ readSymbology()

bool QgsVectorLayer::readSymbology ( const QDomNode &  layerNode,
QString &  errorMessage,
QgsReadWriteContext context,
QgsMapLayer::StyleCategories  categories = QgsMapLayer::AllStyleCategories 
)

Definition at line 2276 of file qgsvectorlayer.cpp.

◆ readXml()

bool QgsVectorLayer::readXml ( const QDomNode &  layer_node,
QgsReadWriteContext context 
)
virtual

Reads vector layer specific state from project file Dom node.

Note
Called by QgsMapLayer::readXml().

Reimplemented from QgsMapLayer.

Definition at line 1743 of file qgsvectorlayer.cpp.

◆ referencingRelations()

QList< QgsRelation > QgsVectorLayer::referencingRelations ( int  idx) const

Returns the layer's relations, where the foreign key is on this layer.

Parameters
idxOnly get relations, where idx forms part of the foreign key
Returns
A list of relations

Definition at line 5775 of file qgsvectorlayer.cpp.

◆ reload()

void QgsVectorLayer::reload ( )
virtual

Synchronises with changes in the datasource.

Reimplemented from QgsMapLayer.

Definition at line 449 of file qgsvectorlayer.cpp.

◆ removeExpressionField()

void QgsVectorLayer::removeExpressionField ( int  index)

Removes an expression field.

Parameters
indexThe index of the field
Since
QGIS 2.6

Definition at line 4235 of file qgsvectorlayer.cpp.

◆ removeFeatureRendererGenerator()

void QgsVectorLayer::removeFeatureRendererGenerator ( const QString &  id)

Removes the feature renderer with matching id from the layer.

The corresponding generator will be deleted.

See also
addFeatureRendererGenerator()
featureRendererGenerators()
Since
QGIS 3.18

Definition at line 4113 of file qgsvectorlayer.cpp.

◆ removeFieldAlias()

void QgsVectorLayer::removeFieldAlias ( int  index)

Removes an alias (a display name) for attributes to display in dialogs.

Since
QGIS 3.0

Definition at line 3322 of file qgsvectorlayer.cpp.

◆ removeFieldConstraint()

void QgsVectorLayer::removeFieldConstraint ( int  index,
QgsFieldConstraints::Constraint  constraint 
)

Removes a constraint for a specified field index.

Any constraints inherited from the layer's data provider will be kept intact and cannot be removed.

See also
fieldConstraints()
setFieldConstraint()
Since
QGIS 3.0

Definition at line 6014 of file qgsvectorlayer.cpp.

◆ removeJoin()

bool QgsVectorLayer::removeJoin ( const QString &  joinLayerId)

Removes a vector layer join.

Returns
true if join was found and successfully removed

Definition at line 4209 of file qgsvectorlayer.cpp.

◆ removeSelection

void QgsVectorLayer::removeSelection ( )
slot

Clear selection.

See also
selectByIds()
reselect()

Definition at line 718 of file qgsvectorlayer.cpp.

◆ renameAttribute()

bool QgsVectorLayer::renameAttribute ( int  index,
const QString &  newName 
)

Renames an attribute field (but does not commit it).

Parameters
indexattribute index
newNamenew name of field
Note
Calls to renameAttribute() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Since
QGIS 2.16

Definition at line 3340 of file qgsvectorlayer.cpp.

◆ renderer() [1/2]

QgsFeatureRenderer * QgsVectorLayer::renderer ( )
inline

Returns the feature renderer used for rendering the features in the layer in 2D map views.

See also
setRenderer()

Definition at line 946 of file qgsvectorlayer.h.

◆ renderer() [2/2]

const QgsFeatureRenderer * QgsVectorLayer::renderer ( ) const
inline

Returns the feature renderer used for rendering the features in the layer in 2D map views.

See also
setRenderer()
Note
not available in Python bindings

Definition at line 955 of file qgsvectorlayer.h.

◆ reselect

void QgsVectorLayer::reselect ( )
slot

Reselects the previous set of selected features.

This is only applicable after a prior call to removeSelection().

Any other modifications to the selection following a call to removeSelection() clears memory of the previous selection and consequently calling reselect() has no impact.

See also
removeSelection()
Since
QGIS 3.10

Definition at line 730 of file qgsvectorlayer.cpp.

◆ resolveReferences()

void QgsVectorLayer::resolveReferences ( QgsProject project)
virtual

Resolves references to other layers (kept as layer IDs after reading XML) into layer objects.

Since
QGIS 3.0

Reimplemented from QgsMapLayer.

Definition at line 2267 of file qgsvectorlayer.cpp.

◆ rollBack()

bool QgsVectorLayer::rollBack ( bool  deleteBuffer = true)

Stops a current editing operation and discards any uncommitted edits.

If deleteBuffer is true the editing buffer will be completely deleted (the default behavior).

See also
startEditing()
commitChanges()

Definition at line 3790 of file qgsvectorlayer.cpp.

◆ select [1/2]

void QgsVectorLayer::select ( const QgsFeatureIds featureIds)
slot

Selects features by their ID.

Parameters
featureIdsThe ids of the features to select
See also
select(QgsFeatureId)

Definition at line 501 of file qgsvectorlayer.cpp.

◆ select [2/2]

void QgsVectorLayer::select ( QgsFeatureId  featureId)
slot

Selects feature by its ID.

Parameters
featureIdThe id of the feature to select
See also
select( const QgsFeatureIds& )

Definition at line 491 of file qgsvectorlayer.cpp.

◆ selectAll()

void QgsVectorLayer::selectAll ( )

Select all the features.

Definition at line 680 of file qgsvectorlayer.cpp.

◆ selectByExpression()

void QgsVectorLayer::selectByExpression ( const QString &  expression,
Qgis::SelectBehavior  behavior = Qgis::SelectBehavior::SetSelection,
QgsExpressionContext context = nullptr 
)

Selects matching features using an expression.

Parameters
expressionexpression to evaluate to select features
behaviorselection type, allows adding to current selection, removing from selection, etc.
contextsince QGIS 3.26, specifies an optional expression context to use when selecting features. If not specified a default one will be built.
See also
selectByRect()
selectByIds()
Since
QGIS 2.16

Definition at line 555 of file qgsvectorlayer.cpp.

◆ selectByIds()

void QgsVectorLayer::selectByIds ( const QgsFeatureIds ids,
Qgis::SelectBehavior  behavior = Qgis::SelectBehavior::SetSelection 
)

Selects matching features using a list of feature IDs.

Will emit the selectionChanged() signal with the clearAndSelect flag set.

Parameters
idsfeature IDs to select
behaviorselection type, allows adding to current selection, removing from selection, etc.
See also
selectByRect()
selectByExpression()
Since
QGIS 2.16

Definition at line 622 of file qgsvectorlayer.cpp.

◆ selectByRect()

void QgsVectorLayer::selectByRect ( QgsRectangle rect,
Qgis::SelectBehavior  behavior = Qgis::SelectBehavior::SetSelection 
)

Selects features found within the search rectangle (in layer's coordinates)

Parameters
rectsearch rectangle
behaviorselection type, allows adding to current selection, removing from selection, etc.
See also
invertSelectionInRectangle(QgsRectangle & rect)
selectByExpression()
selectByIds()

Definition at line 531 of file qgsvectorlayer.cpp.

◆ selectedFeatureCount()

int QgsVectorLayer::selectedFeatureCount ( ) const

Returns the number of features that are selected in this layer.

See also
selectedFeatureIds()

Definition at line 3844 of file qgsvectorlayer.cpp.

◆ selectedFeatureIds()

const QgsFeatureIds & QgsVectorLayer::selectedFeatureIds ( ) const

Returns a list of the selected features IDs in this layer.

See also
selectedFeatures()
selectedFeatureCount()
selectByIds()

Definition at line 3851 of file qgsvectorlayer.cpp.

◆ selectedFeatures()

QgsFeatureList QgsVectorLayer::selectedFeatures ( ) const

Returns a copy of the user-selected features.

Warning
Calling this method triggers a request for all attributes and geometry for the selected features. Consider using the much more efficient selectedFeatureIds() or selectedFeatureCount() if you do not require access to the feature attributes or geometry.
Returns
A list of QgsFeature
See also
selectedFeatureIds()
getSelectedFeatures() which is more memory friendly when handling large selections

Definition at line 3859 of file qgsvectorlayer.cpp.

◆ selectionChanged

void QgsVectorLayer::selectionChanged ( const QgsFeatureIds selected,
const QgsFeatureIds deselected,
bool  clearAndSelect 
)
signal

Emitted when selection was changed.

Parameters
selectedNewly selected feature ids
deselectedIds of all features which have previously been selected but are not any more
clearAndSelectIn case this is set to true, the old selection was dismissed and the new selection corresponds to selected

◆ selectionProperties()

QgsMapLayerSelectionProperties * QgsVectorLayer::selectionProperties ( )
overridevirtual

Returns the layer's selection properties.

This may be nullptr, depending on the layer type.

Since
QGIS 3.34

Reimplemented from QgsMapLayer.

Definition at line 756 of file qgsvectorlayer.cpp.

◆ setAllowCommit()

void QgsVectorLayer::setAllowCommit ( bool  allowCommit)

Controls, if the layer is allowed to commit changes.

If this is set to false it will not be possible to commit changes on this layer. This can be used to define checks on a layer that need to be pass before the layer can be saved. If you use this API, make sure that:

  • the user is visibly informed that his changes were not saved and what he needs to do in order to be able to save the changes.
  • to set the property back to true, once the user has fixed his data.

When calling

See also
commitChanges() this flag is checked just after the
beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 6162 of file qgsvectorlayer.cpp.

◆ setAttributeTableConfig()

void QgsVectorLayer::setAttributeTableConfig ( const QgsAttributeTableConfig attributeTableConfig)

Sets the attribute table configuration object.

This defines the appearance of the attribute table.

Definition at line 5535 of file qgsvectorlayer.cpp.

◆ setAuxiliaryLayer()

void QgsVectorLayer::setAuxiliaryLayer ( QgsAuxiliaryLayer layer = nullptr)

Sets the current auxiliary layer.

The auxiliary layer is automatically put in editable mode and fields are updated. Moreover, a join is created between the current layer and the auxiliary layer. Ownership is transferred.

Since
QGIS 3.0

Definition at line 5827 of file qgsvectorlayer.cpp.

◆ setConstraintExpression()

void QgsVectorLayer::setConstraintExpression ( int  index,
const QString &  expression,
const QString &  description = QString() 
)

Sets the constraint expression for the specified field index.

An optional descriptive name for the constraint can also be set. Setting an empty expression will clear any existing expression constraint.

See also
constraintExpression()
constraintDescription()
fieldConstraints()
Since
QGIS 3.0

Definition at line 6053 of file qgsvectorlayer.cpp.

◆ setCoordinateSystem()

void QgsVectorLayer::setCoordinateSystem ( )

Setup the coordinate system transformation for the layer.

Definition at line 3921 of file qgsvectorlayer.cpp.

◆ setDefaultValueDefinition()

void QgsVectorLayer::setDefaultValueDefinition ( int  index,
const QgsDefaultValue definition 
)

Sets the definition of the expression to use when calculating the default value for a field.

Parameters
indexfield index
definitiondefault value definition to use and evaluate when calculating default values for field. Pass an empty expression to clear the default.
See also
defaultValue()
defaultValueDefinition()
Since
QGIS 3.0

Definition at line 4454 of file qgsvectorlayer.cpp.

◆ setDependencies()

bool QgsVectorLayer::setDependencies ( const QSet< QgsMapLayerDependency > &  layers)
virtual

Sets the list of dependencies.

See also
dependencies()
Parameters
layersset of QgsMapLayerDependency. Only user-defined dependencies will be added
Returns
false if a dependency cycle has been detected
Since
QGIS 3.0

Reimplemented from QgsMapLayer.

Definition at line 5898 of file qgsvectorlayer.cpp.

◆ setDiagramLayerSettings()

void QgsVectorLayer::setDiagramLayerSettings ( const QgsDiagramLayerSettings s)

Definition at line 5561 of file qgsvectorlayer.cpp.

◆ setDiagramRenderer()

void QgsVectorLayer::setDiagramRenderer ( QgsDiagramRenderer r)

Sets diagram rendering object (takes ownership)

Definition at line 798 of file qgsvectorlayer.cpp.

◆ setDisplayExpression()

void QgsVectorLayer::setDisplayExpression ( const QString &  displayExpression)

Set the preview expression, used to create a human readable preview string.

Used e.g. in the attribute table feature list. Uses QgsExpression.

Parameters
displayExpressionThe expression which will be used to preview features for this layer

Definition at line 3942 of file qgsvectorlayer.cpp.

◆ setEditFormConfig()

void QgsVectorLayer::setEditFormConfig ( const QgsEditFormConfig editFormConfig)

Sets the editFormConfig (configuration) of the form used to represent this vector layer.

See also
editFormConfig()
Since
QGIS 3.0

Definition at line 5511 of file qgsvectorlayer.cpp.

◆ setEditorWidgetSetup()

void QgsVectorLayer::setEditorWidgetSetup ( int  index,
const QgsEditorWidgetSetup setup 
)

The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field at index.

Since
QGIS 3.0

Definition at line 6103 of file qgsvectorlayer.cpp.

◆ setExcludeAttributesWfs()

void QgsVectorLayer::setExcludeAttributesWfs ( const QSet< QString > &  att)

A set of attributes that are not advertised in WFS requests with QGIS server.

Deprecated:
since QGIS 3.16, use setFieldConfigurationFlag instead

Definition at line 3482 of file qgsvectorlayer.cpp.

◆ setExcludeAttributesWms()

void QgsVectorLayer::setExcludeAttributesWms ( const QSet< QString > &  att)

A set of attributes that are not advertised in WMS requests with QGIS server.

Deprecated:
since QGIS 3.16, use setFieldConfigurationFlag instead

Definition at line 3454 of file qgsvectorlayer.cpp.

◆ setExtent()

void QgsVectorLayer::setExtent ( const QgsRectangle rect)
protectedvirtual

Sets the extent.

Reimplemented from QgsMapLayer.

Definition at line 980 of file qgsvectorlayer.cpp.

◆ setFeatureBlendMode()

void QgsVectorLayer::setFeatureBlendMode ( QPainter::CompositionMode  blendMode)

Sets the blending mode used for rendering each feature.

Definition at line 4935 of file qgsvectorlayer.cpp.

◆ setFieldAlias()

void QgsVectorLayer::setFieldAlias ( int  index,
const QString &  aliasString 
)

Sets an alias (a display name) for attributes to display in dialogs.

Since
QGIS 3.0

Definition at line 3381 of file qgsvectorlayer.cpp.

◆ setFieldConfigurationFlag()

void QgsVectorLayer::setFieldConfigurationFlag ( int  index,
Qgis::FieldConfigurationFlag  flag,
bool  active 
)

Sets the given configuration flag for the field at given index to be active or not.

Since
QGIS 3.16

Definition at line 6082 of file qgsvectorlayer.cpp.

◆ setFieldConfigurationFlags()

void QgsVectorLayer::setFieldConfigurationFlags ( int  index,
Qgis::FieldConfigurationFlags  flags 
)

Sets the configuration flags of the field at given index.

See also
QgsField::configurationFlags()
Since
QGIS 3.16

Definition at line 6071 of file qgsvectorlayer.cpp.

◆ setFieldConstraint()

void QgsVectorLayer::setFieldConstraint ( int  index,
QgsFieldConstraints::Constraint  constraint,
QgsFieldConstraints::ConstraintStrength  strength = QgsFieldConstraints::ConstraintStrengthHard 
)

Sets a constraint for a specified field index.

Any constraints inherited from the layer's data provider will be kept intact and cannot be modified. Ie, calling this method only allows for new constraints to be added on top of the existing provider constraints.

See also
fieldConstraints()
removeFieldConstraint()
Since
QGIS 3.0

Definition at line 5995 of file qgsvectorlayer.cpp.

◆ setFieldSplitPolicy()

void QgsVectorLayer::setFieldSplitPolicy ( int  index,
Qgis::FieldDomainSplitPolicy  policy 
)

Sets a split policy for the field with the specified index.

Since
QGIS 3.30

Definition at line 3423 of file qgsvectorlayer.cpp.

◆ setLabeling()

void QgsVectorLayer::setLabeling ( QgsAbstractVectorLayerLabeling labeling)

Sets labeling configuration.

Takes ownership of the object.

Since
QGIS 3.0

Definition at line 1665 of file qgsvectorlayer.cpp.

◆ setLabelsEnabled()

void QgsVectorLayer::setLabelsEnabled ( bool  enabled)

Sets whether labels should be enabled for the layer.

Note
Labels will only be rendered if labelsEnabled() is true and a labeling object is returned by labeling().
See also
labelsEnabled()
labeling()

Definition at line 892 of file qgsvectorlayer.cpp.

◆ setProviderEncoding()

void QgsVectorLayer::setProviderEncoding ( const QString &  encoding)

Sets the text encoding of the data provider.

An empty encoding string indicates that the provider should automatically select the most appropriate encoding.

Warning
Support for setting the provider encoding depends on the underlying data provider. Check dataProvider().capabilities() for the QgsVectorDataProvider::SelectEncoding capability in order to determine if the provider supports this ability.

Definition at line 787 of file qgsvectorlayer.cpp.

◆ setReadExtentFromXml()

void QgsVectorLayer::setReadExtentFromXml ( bool  readExtentFromXml)

Flag allowing to indicate if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it.

Since
QGIS 3.0

Definition at line 6180 of file qgsvectorlayer.cpp.

◆ setReadOnly()

bool QgsVectorLayer::setReadOnly ( bool  readonly = true)

Makes layer read-only (editing disabled) or not.

Returns
false if the layer is in editing yet or if the data source is in read-only mode
See also
readOnlyChanged()

Definition at line 4006 of file qgsvectorlayer.cpp.

◆ setRenderer()

void QgsVectorLayer::setRenderer ( QgsFeatureRenderer r)

Sets the feature renderer which will be invoked to represent this layer in 2D map views.

Ownership is transferred.

See also
renderer()

Definition at line 4065 of file qgsvectorlayer.cpp.

◆ setSimplifyMethod()

void QgsVectorLayer::setSimplifyMethod ( const QgsVectorSimplifyMethod simplifyMethod)
inline

Sets the simplification settings for fast rendering of features.

Since
QGIS 2.2

Definition at line 2329 of file qgsvectorlayer.h.

◆ setSubsetString()

bool QgsVectorLayer::setSubsetString ( const QString &  subset)
virtual

Sets the string (typically sql) used to define a subset of the layer.

Parameters
subsetThe subset string. This may be the where clause of a sql statement or other definition string specific to the underlying dataprovider and data store.
Returns
true, when setting the subset string was successful, false otherwise

Definition at line 1123 of file qgsvectorlayer.cpp.

◆ setTransformContext

void QgsVectorLayer::setTransformContext ( const QgsCoordinateTransformContext transformContext)
overridevirtualslot

Sets the coordinate transform context to transformContext.

Since
QGIS 3.8

Definition at line 1713 of file qgsvectorlayer.cpp.

◆ setWeakRelations()

void QgsVectorLayer::setWeakRelations ( const QList< QgsWeakRelation > &  relations)

Sets the layer's weak relations.

Note
Not available in Python bindings.
See also
weakRelations()
Since
QGIS 3.28

Definition at line 5789 of file qgsvectorlayer.cpp.

◆ simplifyDrawingCanbeApplied()

bool QgsVectorLayer::simplifyDrawingCanbeApplied ( const QgsRenderContext renderContext,
QgsVectorSimplifyMethod::SimplifyHint  simplifyHint 
) const

Returns whether the VectorLayer can apply the specified simplification hint.

Note
Do not use in 3rd party code - may be removed in future version!
Since
QGIS 2.2

Definition at line 1158 of file qgsvectorlayer.cpp.

◆ simplifyMethod()

const QgsVectorSimplifyMethod & QgsVectorLayer::simplifyMethod ( ) const
inline

Returns the simplification settings for fast rendering of features.

Since
QGIS 2.2

Definition at line 2335 of file qgsvectorlayer.h.

◆ sourceCrs()

QgsCoordinateReferenceSystem QgsVectorLayer::sourceCrs ( ) const
virtual

Returns the coordinate reference system for features in the source.

Implements QgsFeatureSource.

Definition at line 435 of file qgsvectorlayer.cpp.

◆ sourceExtent()

QgsRectangle QgsVectorLayer::sourceExtent ( ) const
virtual

Returns the extent of all geometries from the source.

The base class implementation uses a non-optimised approach of looping through all features in the source.

Reimplemented from QgsFeatureSource.

Definition at line 1104 of file qgsvectorlayer.cpp.

◆ sourceName()

QString QgsVectorLayer::sourceName ( ) const
virtual

Returns a friendly display name for the source.

The returned value can be an empty string.

Implements QgsFeatureSource.

Definition at line 442 of file qgsvectorlayer.cpp.

◆ splitFeatures() [1/3]

Qgis::GeometryOperationResult QgsVectorLayer::splitFeatures ( const QgsCurve curve,
QgsPointSequence topologyTestPoints,
bool  preserveCircular = false,
bool  topologicalEditing = false 
)

Splits features cut by the given curve.

Parameters
curvecurve that splits the layer features
[out]topologyTestPointstopological points to be tested against other layers
preserveCircularwhether circular strings are preserved after splitting
topologicalEditingtrue if topological editing is enabled
Returns
Qgis::GeometryOperationResult
  • Success
  • NothingHappened
  • LayerNotEditable
  • InvalidInputGeometryType
  • InvalidBaseGeometry
  • GeometryEngineError
  • SplitCannotSplitPoint
Note
Calls to splitFeatures() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Since
QGIS 3.16

Definition at line 1614 of file qgsvectorlayer.cpp.

◆ splitFeatures() [2/3]

Qgis::GeometryOperationResult QgsVectorLayer::splitFeatures ( const QgsPointSequence splitLine,
bool  topologicalEditing = false 
)

Splits features cut by the given line.

Parameters
splitLineline that splits the layer features
topologicalEditingtrue if topological editing is enabled
Returns
Qgis::GeometryOperationResult
  • Success
  • NothingHappened
  • LayerNotEditable
  • InvalidInputGeometryType
  • InvalidBaseGeometry
  • GeometryEngineError
  • SplitCannotSplitPoint
Note
Calls to splitFeatures() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1604 of file qgsvectorlayer.cpp.

◆ splitFeatures() [3/3]

Qgis::GeometryOperationResult QgsVectorLayer::splitFeatures ( const QVector< QgsPointXY > &  splitLine,
bool  topologicalEditing = false 
)

Splits features cut by the given line.

Parameters
splitLineline that splits the layer features
topologicalEditingtrue if topological editing is enabled
Returns
Qgis::GeometryOperationResult
  • Success
  • NothingHappened
  • LayerNotEditable
  • InvalidInputGeometryType
  • InvalidBaseGeometry
  • GeometryEngineError
  • SplitCannotSplitPoint
Note
Calls to splitFeatures() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Deprecated:
since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

Definition at line 1597 of file qgsvectorlayer.cpp.

◆ splitParts() [1/2]

Qgis::GeometryOperationResult QgsVectorLayer::splitParts ( const QgsPointSequence splitLine,
bool  topologicalEditing = false 
)

Splits parts cut by the given line.

Parameters
splitLineline that splits the layer features
topologicalEditingtrue if topological editing is enabled
Returns
Qgis::GeometryOperationResult
  • Success
  • NothingHappened
  • LayerNotEditable
  • InvalidInputGeometryType
  • InvalidBaseGeometry
  • GeometryEngineError
  • SplitCannotSplitPoint
Note
Calls to splitParts() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1586 of file qgsvectorlayer.cpp.

◆ splitParts() [2/2]

Qgis::GeometryOperationResult QgsVectorLayer::splitParts ( const QVector< QgsPointXY > &  splitLine,
bool  topologicalEditing = false 
)

Splits parts cut by the given line.

Parameters
splitLineline that splits the layer features
topologicalEditingtrue if topological editing is enabled
Returns
Qgis::GeometryOperationResult
  • Success
  • NothingHappened
  • LayerNotEditable
  • InvalidInputGeometryType
  • InvalidBaseGeometry
  • GeometryEngineError
  • SplitCannotSplitPoint
Note
Calls to splitParts() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Deprecated:
since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

Definition at line 1579 of file qgsvectorlayer.cpp.

◆ startEditing

bool QgsVectorLayer::startEditing ( )
slot

Makes the layer editable.

This starts an edit session on this layer. Changes made in this edit session will not be made persistent until commitChanges() is called, and can be reverted by calling rollBack().

Returns
true if the layer was successfully made editable, or false if the operation failed (e.g. due to an underlying read-only data source, or lack of edit support by the backend data provider).
See also
commitChanges()
rollBack()

Definition at line 1676 of file qgsvectorlayer.cpp.

◆ storageType()

QString QgsVectorLayer::storageType ( ) const

Returns the permanent storage type for this layer as a friendly name.

This is obtained from the data provider and does not follow any standard.

Definition at line 387 of file qgsvectorlayer.cpp.

◆ storedExpressionManager()

QgsStoredExpressionManager * QgsVectorLayer::storedExpressionManager ( )
inline

Returns the manager of the stored expressions for this layer.

Since
QGIS 3.10

Definition at line 2461 of file qgsvectorlayer.h.

◆ subsetString()

QString QgsVectorLayer::subsetString ( ) const
virtual

Returns the string (typically sql) used to define a subset of the layer.

Returns
The subset string or null QString if not implemented by the provider

Definition at line 1111 of file qgsvectorlayer.cpp.

◆ subsetStringChanged

void QgsVectorLayer::subsetStringChanged ( )
signal

Emitted when the layer's subset string has changed.

Since
QGIS 3.2

◆ supportsEditing()

bool QgsVectorLayer::supportsEditing ( ) const
overridevirtual

Returns whether the layer supports editing or not.

Returns
false if the layer is read only or the data provider has no editing capabilities
Since
QGIS 3.18

Reimplemented from QgsMapLayer.

Definition at line 4023 of file qgsvectorlayer.cpp.

◆ supportsEditingChanged

void QgsVectorLayer::supportsEditingChanged ( )
signal

Emitted when the read only state or the data provider of this layer is changed.

Since
QGIS 3.18

◆ symbolFeatureCountMapChanged

void QgsVectorLayer::symbolFeatureCountMapChanged ( )
signal

Emitted when the feature count for symbols on this layer has been recalculated.

Since
QGIS 3.0

◆ symbolFeatureIds()

QgsFeatureIds QgsVectorLayer::symbolFeatureIds ( const QString &  legendKey) const

Ids of features rendered with specified legend key.

Features must be first calculated by countSymbolFeatures()

Returns
Ids of features rendered by symbol or -1 if failed or Ids are not available
Since
QGIS 3.10

Definition at line 925 of file qgsvectorlayer.cpp.

◆ temporalProperties()

QgsMapLayerTemporalProperties * QgsVectorLayer::temporalProperties ( )
overridevirtual

Returns the layer's temporal properties.

This may be nullptr, depending on the layer type.

Since
QGIS 3.14

Reimplemented from QgsMapLayer.

Definition at line 764 of file qgsvectorlayer.cpp.

◆ translateFeature()

int QgsVectorLayer::translateFeature ( QgsFeatureId  featureId,
double  dx,
double  dy 
)

Translates feature by dx, dy.

Parameters
featureIdid of the feature to translate
dxtranslation of x-coordinate
dytranslation of y-coordinate
Returns
0 in case of success
Note
Calls to translateFeature() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().

Definition at line 1564 of file qgsvectorlayer.cpp.

◆ uniqueStringsMatching()

QStringList QgsVectorLayer::uniqueStringsMatching ( int  index,
const QString &  substring,
int  limit = -1,
QgsFeedback feedback = nullptr 
) const

Returns unique string values of an attribute which contain a specified subset string.

Subset matching is done in a case-insensitive manner. Note that in some circumstances when unsaved changes are present for the layer then the returned list may contain outdated values (for instance when the attribute value in a saved feature has been changed inside the edit buffer then the previous saved value will be included in the returned list).

Parameters
indexcolumn index for attribute
substringsubstring to match (case insensitive)
limitmaxmum number of the values to return, or -1 to return all unique values
feedbackoptional feedback object for canceling request
Returns
list of unique strings containing substring

Definition at line 4592 of file qgsvectorlayer.cpp.

◆ uniqueValues()

QSet< QVariant > QgsVectorLayer::uniqueValues ( int  fieldIndex,
int  limit = -1 
) const
virtual

Calculates a list of unique values contained within an attribute in the layer.

Note that in some circumstances when unsaved changes are present for the layer then the returned list may contain outdated values (for instance when the attribute value in a saved feature has been changed inside the edit buffer then the previous saved value will be included in the returned list).

Parameters
fieldIndexcolumn index for attribute
limitmaximum number of values to return (or -1 if unlimited)
See also
minimumValue()
maximumValue()

Reimplemented from QgsFeatureSource.

Definition at line 4482 of file qgsvectorlayer.cpp.

◆ updatedFields

void QgsVectorLayer::updatedFields ( )
signal

Emitted whenever the fields available from this layer have been changed.

This can be due to manually adding attributes or due to a join.

◆ updateExpressionField()

void QgsVectorLayer::updateExpressionField ( int  index,
const QString &  exp 
)

Changes the expression used to define an expression based (virtual) field.

Parameters
indexThe index of the expression to change
expThe new expression to set
Since
QGIS 2.9

Definition at line 4260 of file qgsvectorlayer.cpp.

◆ updateExtents

void QgsVectorLayer::updateExtents ( bool  force = false)
virtualslot

Update the extents for the layer.

This is necessary if features are added/deleted or the layer has been subsetted.

Parameters
forcetrue to update layer extent even if it's read from xml by default, false otherwise

Definition at line 971 of file qgsvectorlayer.cpp.

◆ updateFeature()

bool QgsVectorLayer::updateFeature ( QgsFeature feature,
bool  skipDefaultValues = false 
)

Updates an existing feature in the layer, replacing the attributes and geometry for the feature with matching QgsFeature::id() with the attributes and geometry from feature.

Changes are not immediately committed to the layer.

If skipDefaultValue is set to true, default field values will not be updated. This can be used to override default field value expressions.

Returns true if the feature's attribute was successfully changed.

Note
Calls to updateFeature() are only valid for layers in which edits have been enabled by a call to startEditing(). Changes made to features using this method are not committed to the underlying data provider until a commitChanges() call is made. Any uncommitted changes can be discarded by calling rollBack().
Warning
This method needs to query the underlying data provider to fetch the feature with matching QgsFeature::id() on every call. Depending on the underlying data source this can be slow to execute. Consider using the more efficient changeAttributeValue() or changeGeometry() methods instead.
See also
startEditing()
commitChanges()
changeGeometry()
changeAttributeValue()

Definition at line 1231 of file qgsvectorlayer.cpp.

◆ updateFields()

void QgsVectorLayer::updateFields ( )

Will regenerate the fields property of this layer by obtaining all fields from the dataProvider, joined fields and virtual fields.

It will also take any changes made to default values into consideration.

Note
Unless the fields on the provider have directly been modified, there is no reason to call this method.

Definition at line 4268 of file qgsvectorlayer.cpp.

◆ vectorJoins()

const QList< QgsVectorLayerJoinInfo > QgsVectorLayer::vectorJoins ( ) const

Definition at line 4216 of file qgsvectorlayer.cpp.

◆ vectorLayerTypeFlags()

Qgis::VectorLayerTypeFlags QgsVectorLayer::vectorLayerTypeFlags ( ) const

Returns the vector layer type flags.

See also
isSqlQuery()
Since
QGIS 3.24

Definition at line 417 of file qgsvectorlayer.cpp.

◆ weakRelations()

QList< QgsWeakRelation > QgsVectorLayer::weakRelations ( ) const

Returns the layer's weak relations as specified in the layer's style.

Returns
A list of weak relations
Note
not available in Python bindings
See also
setWeakRelations()
Since
QGIS 3.12

Definition at line 5782 of file qgsvectorlayer.cpp.

◆ wkbType()

Qgis::WkbType QgsVectorLayer::wkbType ( ) const
virtual

Returns the WKBType or WKBUnknown in case of error.

Implements QgsFeatureSource.

Definition at line 816 of file qgsvectorlayer.cpp.

◆ writeCustomSymbology

void QgsVectorLayer::writeCustomSymbology ( QDomElement &  element,
QDomDocument &  doc,
QString &  errorMessage 
) const
signal

Signal emitted whenever the symbology (QML-file) for this layer is being written.

If there is custom style information you want to save to the file, you can connect to this signal and update the element accordingly.

Parameters
elementThe XML element where you can add additional style information to.
docThe XML document that you can use to create new XML nodes.
errorMessageWrite error messages into this string.

◆ writeSld()

bool QgsVectorLayer::writeSld ( QDomNode &  node,
QDomDocument &  doc,
QString &  errorMessage,
const QVariantMap &  props = QVariantMap() 
) const

Writes the symbology of the layer into the document provided in SLD 1.1 format.

Parameters
nodethe node that will have the style element added to it.
docthe document that will have the QDomNode added.
errorMessagereference to string that will be updated with any error messages
propsa open ended set of properties that can drive/inform the SLD encoding
Returns
true in case of success

Definition at line 3150 of file qgsvectorlayer.cpp.

◆ writeStyle()

bool QgsVectorLayer::writeStyle ( QDomNode &  node,
QDomDocument &  doc,
QString &  errorMessage,
const QgsReadWriteContext context,
QgsMapLayer::StyleCategories  categories = QgsMapLayer::AllStyleCategories 
) const

Definition at line 3026 of file qgsvectorlayer.cpp.

◆ writeSymbology()

bool QgsVectorLayer::writeSymbology ( QDomNode &  node,
QDomDocument &  doc,
QString &  errorMessage,
const QgsReadWriteContext context,
QgsMapLayer::StyleCategories  categories = QgsMapLayer::AllStyleCategories 
) const

Definition at line 2814 of file qgsvectorlayer.cpp.

◆ writeXml()

bool QgsVectorLayer::writeXml ( QDomNode &  layer_node,
QDomDocument &  doc,
const QgsReadWriteContext context 
) const
virtual

Writes vector layer specific state to project file Dom node.

Note
Called by QgsMapLayer::writeXml().

Reimplemented from QgsMapLayer.

Definition at line 2163 of file qgsvectorlayer.cpp.

Friends And Related Symbol Documentation

◆ QgsVectorLayerEditBuffer

friend class QgsVectorLayerEditBuffer
friend

Definition at line 2966 of file qgsvectorlayer.h.

◆ QgsVectorLayerEditBufferGroup

friend class QgsVectorLayerEditBufferGroup
friend

Definition at line 2967 of file qgsvectorlayer.h.

◆ QgsVectorLayerEditPassthrough

friend class QgsVectorLayerEditPassthrough
friend

Definition at line 2968 of file qgsvectorlayer.h.

◆ QgsVectorLayerFeatureSource

friend class QgsVectorLayerFeatureSource
friend

Definition at line 3022 of file qgsvectorlayer.h.

Member Data Documentation

◆ settingsSimplifyAlgorithm

Definition at line 415 of file qgsvectorlayer.h.

◆ settingsSimplifyDrawingHints

const QgsSettingsEntryEnumFlag< QgsVectorSimplifyMethod::SimplifyHints > * QgsVectorLayer::settingsSimplifyDrawingHints = new QgsSettingsEntryEnumFlag<QgsVectorSimplifyMethod::SimplifyHints>( QStringLiteral( "simplifyDrawingHints" ), QgsSettingsTree::sTreeQgis, QgsVectorSimplifyMethod::SimplifyHint::NoSimplification )
static

Definition at line 416 of file qgsvectorlayer.h.

◆ settingsSimplifyDrawingTol

const QgsSettingsEntryDouble * QgsVectorLayer::settingsSimplifyDrawingTol = new QgsSettingsEntryDouble( QStringLiteral( "simplifyDrawingTol" ), QgsSettingsTree::sTreeQgis, Qgis::DEFAULT_MAPTOPIXEL_THRESHOLD )
static

Definition at line 414 of file qgsvectorlayer.h.

◆ settingsSimplifyLocal

const QgsSettingsEntryBool * QgsVectorLayer::settingsSimplifyLocal = new QgsSettingsEntryBool( QStringLiteral( "simplifyLocal" ), QgsSettingsTree::sTreeQgis, true )
static

Definition at line 411 of file qgsvectorlayer.h.

◆ settingsSimplifyMaxScale

const QgsSettingsEntryDouble * QgsVectorLayer::settingsSimplifyMaxScale = new QgsSettingsEntryDouble( QStringLiteral( "simplifyMaxScale" ), QgsSettingsTree::sTreeQgis, 1.0 )
static

Definition at line 413 of file qgsvectorlayer.h.

Property Documentation

◆ displayExpression

QString QgsVectorLayer::displayExpression
readwrite

Definition at line 404 of file qgsvectorlayer.h.

◆ editFormConfig

QgsEditFormConfig QgsVectorLayer::editFormConfig
readwrite

Definition at line 405 of file qgsvectorlayer.h.

◆ readOnly

bool QgsVectorLayer::readOnly
readwrite

Definition at line 406 of file qgsvectorlayer.h.

◆ subsetString

QString QgsVectorLayer::subsetString
readwrite

Definition at line 403 of file qgsvectorlayer.h.

◆ supportsEditing

bool QgsVectorLayer::supportsEditing
read

Definition at line 407 of file qgsvectorlayer.h.


The documentation for this class was generated from the following files: