QGIS API Documentation  2.99.0-Master (7705179)
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | 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]

Public Types

enum  EditResult {
  Success = 0, EmptyGeometry = 1, EditFailed = 2, FetchFeatureFailed = 3,
  InvalidLayer = 4
}
 Result of an edit operation. More...
 
enum  SelectBehavior { SetSelection, AddToSelection, IntersectSelection, RemoveFromSelection }
 Selection behavior. More...
 
enum  VertexMarkerType { SemiTransparentCircle, Cross, NoMarker }
 Editing vertex markers. More...
 
- Public Types inherited from QgsMapLayer
enum  LayerType { VectorLayer, RasterLayer, PluginLayer }
 Types of layers that can be added to a map. More...
 
- Public Types inherited from QgsFeatureSink
enum  Flag { FastInsert = 1 << 1 }
 Flags controlling how features are added to a sink. More...
 

Public Slots

void deselect (const QgsFeatureId featureId)
 Deselect feature by its ID. More...
 
void deselect (const QgsFeatureIds &featureIds)
 Deselect features by their ID. More...
 
bool isEditCommandActive () const
 Test if an edit command is active. More...
 
void removeSelection ()
 Clear selection. More...
 
void select (QgsFeatureId featureId)
 Select feature by its ID. More...
 
void select (const QgsFeatureIds &featureIds)
 Select features by their ID. More...
 
bool startEditing ()
 Make layer editable. More...
 
virtual void updateExtents (bool force=false)
 Update the extents for the layer. More...
 
- Public Slots inherited from QgsMapLayer
void emitStyleChanged ()
 Triggers an emission of the styleChanged() signal. More...
 
bool isRefreshOnNotifyEnabled () const
 Returns true if the refresh on provider nofification is enabled. More...
 
QString refreshOnNotifyMessage () const
 Returns the message that should be notified by the provider to triggerRepaint. More...
 
void setMaximumScale (double scale)
 Sets the maximum map scale (i.e. More...
 
void setMinimumScale (double scale)
 Sets the minimum map scale (i.e. More...
 
void setRefreshOnNofifyMessage (const QString &message)
 Set the notification message that triggers repaine If refresh on notification is enabled, the notification will triggerRepaint only if the notification message is equal to. More...
 
void setRefreshOnNotifyEnabled (bool enabled)
 Set whether provider notification is connected to triggerRepaint. More...
 
void setScaleBasedVisibility (const bool enabled)
 Sets whether scale based visibility is enabled for the layer. More...
 
void triggerRepaint (bool deferredUpdate=false)
 Will advise the map canvas (and any other interested party) that this layer requires to be repainted. More...
 

Signals

void attributeAdded (int idx)
 Will be emitted, when a new attribute has been added to this vector layer. More...
 
void attributeDeleted (int idx)
 Will be emitted, when an attribute has been deleted from this vector layer. More...
 
void attributeValueChanged (QgsFeatureId fid, int idx, const QVariant &value)
 Is emitted whenever an attribute value change is done in the edit buffer. More...
 
void beforeAddingExpressionField (const QString &fieldName)
 Will be emitted, when an expression field is going to be added to this vector layer. More...
 
void beforeCommitChanges ()
 Is emitted, before changes are committed to the data provider. More...
 
void beforeEditingStarted ()
 Is emitted, before editing on this layer is started. More...
 
void beforeModifiedCheck () const
 Is emitted, when layer is checked for modifications. Use for last-minute additions. More...
 
void beforeRemovingExpressionField (int idx)
 Will be emitted, when an expression field is going to be deleted from this vector layer. More...
 
void beforeRollBack ()
 Is emitted, before changes are rolled back. More...
 
void committedAttributesAdded (const QString &layerId, const QList< QgsField > &addedAttributes)
 This signal is emitted, when attributes are added to the provider. More...
 
void committedAttributesDeleted (const QString &layerId, const QgsAttributeList &deletedAttributes)
 This signal is emitted, when attributes are deleted from the provider. More...
 
void committedAttributeValuesChanges (const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
 This signal is emitted, when attribute value changes are saved to the provider. More...
 
void committedFeaturesAdded (const QString &layerId, const QgsFeatureList &addedFeatures)
 This signal is emitted, when features are added to the provider. More...
 
void committedFeaturesRemoved (const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
 This signal is emitted, when features are deleted from the provider. More...
 
void committedGeometriesChanges (const QString &layerId, const QgsGeometryMap &changedGeometries)
 This signal is emitted, when geometry changes are saved to the provider. More...
 
void displayExpressionChanged ()
 Emitted when the display expression changes. More...
 
void editCommandDestroyed ()
 Signal emitted, whan an edit command is destroyed. More...
 
void editCommandEnded ()
 Signal emitted, when an edit command successfully ended. More...
 
void editCommandStarted (const QString &text)
 Signal emitted when a new edit command has been started. More...
 
void editFormConfigChanged ()
 Will be emitted whenever the edit form configuration of this layer changes. More...
 
void editingStarted ()
 Is emitted, when editing on this layer has started. More...
 
void editingStopped ()
 Is emitted, when edited changes successfully have been written to the data provider. More...
 
void featureAdded (QgsFeatureId fid)
 Emitted when a new feature has been added to the layer. More...
 
void featureBlendModeChanged (QPainter::CompositionMode blendMode)
 Signal emitted when setFeatureBlendMode() is called. More...
 
void featureDeleted (QgsFeatureId fid)
 Emitted when a feature has been deleted. More...
 
void featuresDeleted (const QgsFeatureIds &fids)
 Emitted when features have been deleted. More...
 
void geometryChanged (QgsFeatureId fid, const QgsGeometry &geometry)
 Is emitted whenever a geometry change is done in the edit buffer. More...
 
void labelingFontNotFound (QgsVectorLayer *layer, const QString &fontfamily)
 Emitted when the font family defined for labeling layer is not found on system. More...
 
void layerModified ()
 This signal is emitted when modifications has been done on layer. More...
 
void mapTipTemplateChanged ()
 Emitted when the map tip changes. More...
 
void opacityChanged (double opacity)
 Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (opaque). More...
 
void raiseError (const QString &msg)
 Signals an error related to this vector layer. More...
 
void readCustomSymbology (const QDomElement &element, QString &errorMessage)
 Signal emitted whenever the symbology (QML-file) for this layer is being read. More...
 
void readOnlyChanged ()
 Emitted when the read only state of this layer is changed. More...
 
void selectionChanged (const QgsFeatureIds &selected, const QgsFeatureIds &deselected, const bool clearAndSelect)
 This signal is emitted when selection was changed. More...
 
void symbolFeatureCountMapChanged ()
 Emitted when the feature count for symbols on this layer has been recalculated. More...
 
void updatedFields ()
 Is emitted, whenever the fields available from this layer have been changed. More...
 
void writeCustomSymbology (QDomElement &element, QDomDocument &doc, QString &errorMessage) const
 Signal emitted whenever the symbology (QML-file) for this layer is being written. More...
 
- Signals inherited from QgsMapLayer
void autoRefreshIntervalChanged (int interval)
 Emitted when the auto refresh interval changes. More...
 
void blendModeChanged (QPainter::CompositionMode blendMode)
 Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode() More...
 
void configChanged ()
 Emitted whenever the configuration is changed. More...
 
void crsChanged ()
 Emit a signal that layer's CRS has been reset. More...
 
void dataChanged ()
 Data of layer changed. More...
 
void dependenciesChanged ()
 Emitted when dependencies are changed. More...
 
void legendChanged ()
 Signal emitted when legend of the layer has changed. More...
 
void metadataChanged ()
 Emitted when the layer's metadata is changed. More...
 
void nameChanged ()
 Emitted when the name has been changed. More...
 
void recalculateExtents () const
 This is used to send a request that any mapcanvas using this layer update its extents. More...
 
void rendererChanged ()
 Signal emitted when renderer is changed. More...
 
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. More...
 
void statusChanged (const QString &status)
 Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar) More...
 
void styleChanged ()
 Signal emitted whenever a change affects the layer's style. More...
 
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. More...
 

Public Member Functions

 QgsVectorLayer (const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="ogr", bool loadDefaultStyleFlag=true, bool readExtentFromXml=false)
 Constructor - creates a vector layer. More...
 
 QgsVectorLayer (const QgsVectorLayer &rhs)=delete
 QgsVectorLayer cannot be copied. More...
 
virtual ~QgsVectorLayer ()
 
QgsActionManageractions ()
 Get all layer actions defined on this layer. More...
 
const QgsActionManageractions () const
 Get all layer actions defined on this layer. More...
 
bool addAttribute (const QgsField &field)
 Add an attribute field (but does not commit it) returns true if the field was added. More...
 
int addExpressionField (const QString &exp, const QgsField &fld)
 Add a new field which is calculated by the expression specified. More...
 
bool addFeature (QgsFeature &feature, QgsFeatureSink::Flags flags=0) override
 Adds a single feature to the sink. More...
 
bool addFeatures (QgsFeatureList &features, QgsFeatureSink::Flags flags=0) override
 Adds a list of features to the sink. More...
 
bool addJoin (const QgsVectorLayerJoinInfo &joinInfo)
 Joins another vector layer to this layer. More...
 
int addPart (const QList< QgsPointXY > &ring)
 Adds a new part polygon to a multipart feature. More...
 
int addPart (const QgsPointSequence &ring)
 Adds a new part polygon to a multipart feature. More...
 
int addPart (QgsCurve *ring)
 
int addRing (const QList< QgsPointXY > &ring, QgsFeatureId *featureId=nullptr)
 Adds a ring to polygon/multipolygon features. More...
 
int addRing (QgsCurve *ring, QgsFeatureId *featureId=nullptr)
 Adds a ring to polygon/multipolygon features (takes ownership) More...
 
int addTopologicalPoints (const QgsGeometry &geom)
 Adds topological points for every vertex of the geometry. More...
 
int addTopologicalPoints (const QgsPointXY &p)
 Adds a vertex to segments which intersect point p but don't already have a vertex there. More...
 
QVariant aggregate (QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression, const QgsAggregateCalculator::AggregateParameters &parameters=QgsAggregateCalculator::AggregateParameters(), QgsExpressionContext *context=nullptr, bool *ok=nullptr) const
 Calculates an aggregated value from the layer's features. More...
 
QString attributeAlias (int index) const
 Returns the alias of an attribute name or a null string if there is no alias. More...
 
QgsStringMap attributeAliases () const
 Returns a map of field name to attribute alias. More...
 
QString attributeDisplayName (int index) const
 Convenience function that returns the attribute alias if defined or the field name else. More...
 
QgsAttributeList attributeList () const
 Returns list of attribute indexes. More...
 
QgsAttributeTableConfig attributeTableConfig () const
 Get the attribute table configuration object. More...
 
void beginEditCommand (const QString &text)
 Create edit command for undo/redo operations. More...
 
QgsRectangle boundingBoxOfSelected () const
 Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned. More...
 
QString capabilitiesString () const
 Capabilities for this layer, comma separated and translated. More...
 
bool changeAttributeValue (QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
 Changes an attribute value (but does not commit it) More...
 
bool changeGeometry (QgsFeatureId fid, const QgsGeometry &geom)
 Change feature's geometry. More...
 
virtual QgsVectorLayerclone () const override
 Returns a new instance equivalent to this one. More...
 
bool commitChanges ()
 Attempts to commit any changes to disk. More...
 
QStringList commitErrors () const
 Returns a list containing any error messages generated when attempting to commit changes to the layer. More...
 
QgsConditionalLayerStylesconditionalStyles () const
 Return the conditional styles that are set for this layer. More...
 
QString constraintDescription (int index) const
 Returns the descriptive name for the constraint expression for a specified field index. More...
 
QString constraintExpression (int index) const
 Returns the constraint expression for for a specified field index, if set. More...
 
QgsVectorLayerFeatureCountercountSymbolFeatures ()
 Count features for symbols. More...
 
QgsExpressionContext createExpressionContext () const override
 This method needs to be reimplemented in all classes which implement this interface and return an expression context. More...
 
virtual QgsMapLayerRenderercreateMapRenderer (QgsRenderContext &rendererContext) override
 Return new instance of QgsMapLayerRenderer that will be used for rendering of given context. More...
 
QString dataComment () const
 Returns a description for this layer as defined in the data provider. More...
 
QgsVectorDataProviderdataProvider () override
 Returns the layer's data provider. More...
 
const QgsVectorDataProviderdataProvider () const override
 Returns the layer's data provider in a const-correct manner. More...
 
QVariant defaultValue (int index, const QgsFeature &feature=QgsFeature(), QgsExpressionContext *context=nullptr) const
 Returns the calculated default value for the specified field index. More...
 
QString defaultValueExpression (int index) const
 Returns the expression used when calculating the default value for a field. More...
 
bool deleteAttribute (int attr)
 Delete an attribute field (but does not commit it) More...
 
bool deleteAttributes (QList< int > attrs)
 Deletes a list of attribute fields (but does not commit it) More...
 
bool deleteFeature (QgsFeatureId fid)
 Delete a feature from the layer (but does not commit it) More...
 
bool deleteFeatures (const QgsFeatureIds &fids)
 Deletes a set of features from the layer (but does not commit it) More...
 
bool deleteSelectedFeatures (int *deletedCount=nullptr)
 Deletes the selected features. More...
 
virtual bool deleteStyleFromDatabase (const QString &styleId, QString &msgError)
 Delete a style from the database. More...
 
EditResult deleteVertex (QgsFeatureId featureId, int vertex)
 Deletes a vertex from a feature. More...
 
virtual QSet< QgsMapLayerDependencydependencies () const override
 Gets the list of dependencies. More...
 
void destroyEditCommand ()
 Destroy active command and reverts all changes in it. More...
 
const QgsDiagramLayerSettingsdiagramLayerSettings () const
 
const QgsDiagramRendererdiagramRenderer () const
 
bool diagramsEnabled () const
 Returns whether the layer contains diagrams which are enabled and should be drawn. More...
 
QString displayExpression () const
 Get the preview expression, used to create a human readable preview string. More...
 
QString displayField () const
 This is a shorthand for accessing the displayExpression if it is a simple field. More...
 
QgsVectorLayerEditBuffereditBuffer ()
 Buffer with uncommitted editing operations. Only valid after editing has been turned on. More...
 
const QgsVectorLayerEditBuffereditBuffer () const
 Buffer with uncommitted editing operations. More...
 
QgsEditFormConfig editFormConfig () const
 Get the configuration of the form used to represent this vector layer. More...
 
QgsEditorWidgetSetup editorWidgetSetup (int index) const
 The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field at index. More...
 
void endEditCommand ()
 Finish edit command and add it to undo/redo stack. More...
 
QSet< QString > excludeAttributesWfs () const
 A set of attributes that are not advertised in WFS requests with QGIS server. More...
 
QSet< QString > excludeAttributesWms () const
 A set of attributes that are not advertised in WMS requests with QGIS server. More...
 
QString expressionField (int index) const
 Returns the expression used for a given expression field. More...
 
QgsRectangle extent () const override
 Returns the extent of the layer. More...
 
QPainter::CompositionMode featureBlendMode () const
 Returns the current blending mode for features. More...
 
long featureCount (const QString &legendKey) const
 Number of features rendered with specified legend key. More...
 
long featureCount () const override
 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. More...
 
QgsFieldConstraints::Constraints fieldConstraints (int fieldIndex) const
 Returns any constraints which are present for a specified field index. More...
 
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrengthfieldConstraintsAndStrength (int fieldIndex) const
 Returns a map of constraint with their strength for a specific field of the layer. More...
 
QgsFields fields () const override
 Returns the list of fields of this layer. More...
 
QgsWkbTypes::GeometryType geometryType () const
 Returns point, line or polygon. More...
 
QList< double > getDoubleValues (const QString &fieldOrExpression, bool &ok, bool selectedOnly=false, int *nullCount=nullptr, QgsFeedback *feedback=nullptr) const
 Fetches all double values from a specified field name or expression. More...
 
QgsFeature getFeature (QgsFeatureId fid) const
 Query the layer for the feature with the given id. More...
 
QgsFeatureIterator getFeatures (const QgsFeatureRequest &request=QgsFeatureRequest()) const override
 Query the layer for features specified in request. More...
 
QgsFeatureIterator getFeatures (const QString &expression)
 Query the layer for features matching a given expression. More...
 
QgsFeatureIterator getFeatures (const QgsFeatureIds &fids)
 Query the layer for the features with the given ids. More...
 
QgsFeatureIterator getFeatures (const QgsRectangle &rectangle)
 Query the layer for the features which intersect the specified rectangle. More...
 
QgsFeatureIterator getSelectedFeatures (QgsFeatureRequest request=QgsFeatureRequest()) const
 Get an iterator of the selected features. More...
 
virtual QString getStyleFromDatabase (const QString &styleId, QString &msgError)
 Will return the named style corresponding to style id provided. More...
 
QList< QVariant > getValues (const QString &fieldOrExpression, bool &ok, bool selectedOnly=false, QgsFeedback *feedback=nullptr) const
 Fetches all values from a specified field name or expression. More...
 
QString htmlMetadata () const override
 Obtain a formatted HTML string containing assorted metadata for this layer. More...
 
bool insertVertex (double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
 Insert 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. More...
 
bool insertVertex (const QgsPoint &point, QgsFeatureId atFeatureId, int beforeVertex)
 Insert 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. More...
 
void invertSelection ()
 Select not selected features and deselect selected ones. More...
 
void invertSelectionInRectangle (QgsRectangle &rect)
 Invert selection of features found within the search rectangle (in layer's coordinates) More...
 
virtual bool isEditable () const override
 Returns true if the provider is in editing mode. More...
 
virtual bool isModified () const
 Returns true if the provider has been modified since the last commit. More...
 
virtual bool isSpatial () const override
 Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry. More...
 
QgsVectorLayerJoinBufferjoinBuffer ()
 Accessor to the join buffer object. More...
 
const QgsAbstractVectorLayerLabelinglabeling () const
 Access to labeling configuration. More...
 
bool labelsEnabled () const
 Returns whether the layer contains labels which are enabled and should be drawn. More...
 
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. More...
 
virtual QString loadNamedStyle (const QString &theURI, bool &resultFlag, bool loadFromLocalDb)
 Load a named style from file/local db/datasource db. More...
 
virtual QString loadNamedStyle (const QString &theURI, bool &resultFlag) override
 Calls loadNamedStyle( theURI, resultFlag, false ); Retained for backward compatibility. More...
 
QString mapTipTemplate () const
 The mapTip is a pretty, html representation for feature information. More...
 
QVariant maximumValue (int index) const override
 Returns the maximum value for an attribute column or an invalid variant in case of error. More...
 
QVariant minimumValue (int index) const override
 Returns the minimum value for an attribute column or an invalid variant in case of error. More...
 
void modifySelection (const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds)
 Modifies the current selection on this layer. More...
 
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. More...
 
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. More...
 
double opacity () const
 Returns the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque). More...
 
QgsVectorLayeroperator= (QgsVectorLayer const &rhs)=delete
 QgsVectorLayer cannot be copied. More...
 
QgsAttributeList pendingAllAttributesList () const
 Returns list of attribute indexes. More...
 
long pendingFeatureCount () const
 Returns feature count including changes which have not yet been committed Alias for featureCount() More...
 
QgsFields pendingFields () const
 Returns the list of fields of this layer. More...
 
QgsAttributeList pendingPkAttributesList () const
 Returns list of attributes making up the primary key Alias for pkAttributeList() More...
 
QgsAttributeList pkAttributeList () const
 Returns list of attributes making up the primary key. More...
 
QString providerType () const
 Return the provider type for this layer. More...
 
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. More...
 
bool readSld (const QDomNode &node, QString &errorMessage) override
 
bool readStyle (const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context) override
 Read the style for the current layer from the Dom node supplied. More...
 
bool readSymbology (const QDomNode &layerNode, QString &errorMessage, const QgsReadWriteContext &context) override
 Read the symbology for the current layer from the Dom node supplied. More...
 
virtual bool readXml (const QDomNode &layer_node, const QgsReadWriteContext &context) override
 Reads vector layer specific state from project file Dom node. More...
 
QList< QgsRelationreferencingRelations (int idx) const
 Get relations, where the foreign key is on this layer. More...
 
virtual void reload () override
 Synchronises with changes in the datasource. More...
 
void removeExpressionField (int index)
 Remove an expression field. More...
 
void removeFieldAlias (int index)
 Removes an alias (a display name) for attributes to display in dialogs. More...
 
void removeFieldConstraint (int index, QgsFieldConstraints::Constraint constraint)
 Removes a constraint for a specified field index. More...
 
bool removeJoin (const QString &joinLayerId)
 Removes a vector layer join. More...
 
bool renameAttribute (int index, const QString &newName)
 Renames an attribute field (but does not commit it). More...
 
QgsFeatureRendererrenderer ()
 Return renderer. More...
 
const QgsFeatureRendererrenderer () const
 Return const renderer. More...
 
void resolveReferences (QgsProject *project)
 Resolve references to other layers (kept as layer IDs after reading XML) into layer objects. More...
 
bool rollBack (bool deleteBuffer=true)
 Stop editing and discard the edits. More...
 
virtual void saveStyleToDatabase (const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError)
 Save named and sld style of the layer to the style table in the db. More...
 
void selectAll ()
 Select all the features. More...
 
void selectByExpression (const QString &expression, SelectBehavior behavior=SetSelection)
 Select matching features using an expression. More...
 
void selectByIds (const QgsFeatureIds &ids, SelectBehavior behavior=SetSelection)
 Select matching features using a list of feature IDs. More...
 
void selectByRect (QgsRectangle &rect, SelectBehavior behavior=SetSelection)
 Select features found within the search rectangle (in layer's coordinates) More...
 
int selectedFeatureCount () const
 The number of features that are selected in this layer. More...
 
const QgsFeatureIdsselectedFeatureIds () const
 Return reference to identifiers of selected features. More...
 
QgsFeatureList selectedFeatures () const
 Get a copy of the user-selected features. More...
 
void setAttributeTableConfig (const QgsAttributeTableConfig &attributeTableConfig)
 Set the attribute table configuration object. More...
 
void setConstraintExpression (int index, const QString &expression, const QString &description=QString())
 Set the constraint expression for the specified field index. More...
 
void setCoordinateSystem ()
 Setup the coordinate system transformation for the layer. More...
 
void setDataSource (const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
 Update the data source of the layer. More...
 
void setDefaultValueExpression (int index, const QString &expression)
 Sets an expression to use when calculating the default value for a field. More...
 
virtual bool setDependencies (const QSet< QgsMapLayerDependency > &layers) override
 Sets the list of dependencies. More...
 
void setDiagramLayerSettings (const QgsDiagramLayerSettings &s)
 
void setDiagramRenderer (QgsDiagramRenderer *r)
 Sets diagram rendering object (takes ownership) More...
 
void setDisplayExpression (const QString &displayExpression)
 Set the preview expression, used to create a human readable preview string. More...
 
void setEditFormConfig (const QgsEditFormConfig &editFormConfig)
 Get the configuration of the form used to represent this vector layer. More...
 
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. More...
 
void setExcludeAttributesWfs (const QSet< QString > &att)
 A set of attributes that are not advertised in WFS requests with QGIS server. More...
 
void setExcludeAttributesWms (const QSet< QString > &att)
 A set of attributes that are not advertised in WMS requests with QGIS server. More...
 
void setFeatureBlendMode (QPainter::CompositionMode blendMode)
 Set the blending mode used for rendering each feature. More...
 
void setFieldAlias (int index, const QString &aliasString)
 Sets an alias (a display name) for attributes to display in dialogs. More...
 
void setFieldConstraint (int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthHard)
 Sets a constraint for a specified field index. More...
 
void setLabeling (QgsAbstractVectorLayerLabeling *labeling)
 Set labeling configuration. More...
 
void setMapTipTemplate (const QString &mapTipTemplate)
 The mapTip is a pretty, html representation for feature information. More...
 
void setOpacity (double opacity)
 Sets the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque). More...
 
void setProviderEncoding (const QString &encoding)
 Sets the textencoding of the data provider. More...
 
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. More...
 
bool setReadOnly (bool readonly=true)
 Make layer read-only (editing disabled) or not. More...
 
void setRenderer (QgsFeatureRenderer *r)
 Set renderer which will be invoked to represent this layer. More...
 
void setSimplifyMethod (const QgsVectorSimplifyMethod &simplifyMethod)
 Set the simplification settings for fast rendering of features. More...
 
virtual bool setSubsetString (const QString &subset)
 Set the string (typically sql) used to define a subset of the layer. More...
 
bool simplifyDrawingCanbeApplied (const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
 Returns whether the VectorLayer can apply the specified simplification hint. More...
 
const QgsVectorSimplifyMethodsimplifyMethod () const
 Returns the simplification settings for fast rendering of features. More...
 
QgsCoordinateReferenceSystem sourceCrs () const override
 Returns the coordinate reference system for features in the source. More...
 
QgsRectangle sourceExtent () const override
 Returns the extent of all geometries from the source. More...
 
QString sourceName () const override
 Returns a friendly display name for the source. More...
 
int splitFeatures (const QList< QgsPointXY > &splitLine, bool topologicalEditing=false)
 Splits features cut by the given line. More...
 
int splitParts (const QList< QgsPointXY > &splitLine, bool topologicalEditing=false)
 Splits parts cut by the given line. More...
 
QString storageType () const
 Returns the permanent storage type for this layer as a friendly name. More...
 
virtual QString subsetString () const
 Get the string (typically sql) used to define a subset of the layer. More...
 
int translateFeature (QgsFeatureId featureId, double dx, double dy)
 Translates feature by dx, dy. More...
 
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. More...
 
QSet< QVariant > uniqueValues (int fieldIndex, int limit=-1) const override
 Calculates a list of unique values contained within an attribute in the layer. More...
 
void updateExpressionField (int index, const QString &exp)
 Changes the expression used to define an expression based (virtual) field. More...
 
bool updateFeature (QgsFeature &f)
 Updates an existing feature. More...
 
void updateFields ()
 Assembles mUpdatedFields considering provider fields, joined fields and added fields. More...
 
const QList< QgsVectorLayerJoinInfovectorJoins () const
 
QgsWkbTypes::Type wkbType () const override
 Returns the WKBType or WKBUnknown in case of error. More...
 
bool writeSld (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
 Writes the symbology of the layer into the document provided in SLD 1.1 format. More...
 
bool writeStyle (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
 Write just the style information for the layer into the document. More...
 
bool writeSymbology (QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
 Write the symbology for the layer into the docment provided. More...
 
virtual bool writeXml (QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
 Write vector layer specific state to project file Dom node. More...
 
- Public Member Functions inherited from QgsMapLayer
 QgsMapLayer (QgsMapLayer::LayerType type=VectorLayer, const QString &name=QString(), const QString &source=QString())
 Constructor for QgsMapLayer. More...
 
 QgsMapLayer (QgsMapLayer const &)=delete
 QgsMapLayer cannot be copied. More...
 
virtual ~QgsMapLayer ()
 
QString abstract () const
 Returns the abstract of the layer used by QGIS Server in GetCapabilities request. More...
 
QString attribution () const
 Returns the attribution of the layer used by QGIS Server in GetCapabilities request. More...
 
QString attributionUrl () const
 Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request. More...
 
int autoRefreshInterval () const
 Returns the auto refresh interval (in milliseconds). More...
 
QPainter::CompositionMode blendMode () const
 Returns the current blending mode for a layer. More...
 
QgsCoordinateReferenceSystem crs () const
 Returns the layer's spatial reference system. More...
 
QVariant customProperty (const QString &value, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer. More...
 
QStringList customPropertyKeys () const
 Returns list of all keys within custom properties. More...
 
QString dataUrl () const
 Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request. More...
 
QString dataUrlFormat () const
 Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request. More...
 
virtual QgsError error () const
 Get current status error. More...
 
virtual void exportNamedStyle (QDomDocument &doc, QString &errorMsg) const
 Export the properties of this layer as named style in a QDomDocument. More...
 
virtual void exportSldStyle (QDomDocument &doc, QString &errorMsg) const
 Export the properties of this layer as SLD style in a QDomDocument. More...
 
bool hasAutoRefreshEnabled () const
 Returns true if auto refresh is enabled for the layer. More...
 
bool hasScaleBasedVisibility () const
 Returns whether scale based visibility is enabled for the layer. More...
 
QString id () const
 Returns the layer's unique ID, which is used to access this layer from QgsProject. More...
 
virtual bool importNamedStyle (QDomDocument &doc, QString &errorMsg)
 Import the properties of this layer from a QDomDocument. More...
 
bool isInScaleRange (double scale) const
 Tests whether the layer should be visible at the specified scale. More...
 
bool isValid () const
 Return the status of the layer. More...
 
QString keywordList () const
 Returns the keyword list of the layer used by QGIS Server in GetCapabilities request. More...
 
QgsMapLayerLegendlegend () const
 Can be null. More...
 
QString legendUrl () const
 Returns the URL for the layer's legend. More...
 
QString legendUrlFormat () const
 Returns the format for a URL based layer legend. More...
 
virtual QString loadDefaultStyle (bool &resultFlag)
 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) More...
 
virtual bool loadNamedStyleFromDatabase (const QString &db, const QString &uri, QString &qml)
 Retrieve a named style for this layer from a sqlite database. More...
 
virtual QString loadSldStyle (const QString &uri, bool &resultFlag)
 Attempts to style the layer using the formatting from an SLD type file. More...
 
double maximumScale () const
 Returns the maximum map scale (i.e. More...
 
virtual const QgsLayerMetadatametadata () const
 Returns a reference to the layer's metadata store. More...
 
QString metadataUrl () const
 Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request. More...
 
QString metadataUrlFormat () const
 Returns the metadata format of the layer used by QGIS Server in GetCapabilities request. More...
 
QString metadataUrlType () const
 Returns the metadata type of the layer used by QGIS Server in GetCapabilities request. More...
 
double minimumScale () const
 Returns the minimum map scale (i.e. More...
 
QString name () const
 Returns the display name of the layer. More...
 
QgsMapLayeroperator= (QgsMapLayer const &)=delete
 QgsMapLayer cannot be copied. More...
 
QString originalName () const
 Returns the original name of the layer. More...
 
QString publicSource () const
 Gets a version of the internal layer definition that has sensitive bits removed (for example, the password). More...
 
bool readLayerXml (const QDomElement &layerElement, const QgsReadWriteContext &context)
 Sets state from Dom document. More...
 
bool readOnly () const
 Returns if this layer is read only. More...
 
void removeCustomProperty (const QString &key)
 Remove a custom property from layer. More...
 
virtual 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) More...
 
virtual QString saveNamedStyle (const QString &uri, bool &resultFlag)
 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) More...
 
virtual QString saveSldStyle (const QString &uri, bool &resultFlag) const
 Saves the properties of this layer to an SLD format file. More...
 
void setAbstract (const QString &abstract)
 Sets the abstract of the layer used by QGIS Server in GetCapabilities request. More...
 
void setAttribution (const QString &attrib)
 Sets the attribution of the layer used by QGIS Server in GetCapabilities request. More...
 
void setAttributionUrl (const QString &attribUrl)
 Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request. More...
 
void setAutoRefreshEnabled (bool enabled)
 Sets whether auto refresh is enabled for the layer. More...
 
void setAutoRefreshInterval (int interval)
 Sets the auto refresh interval (in milliseconds) for the layer. More...
 
void setBlendMode (QPainter::CompositionMode blendMode)
 Set the blending mode used for rendering a layer. More...
 
void setCrs (const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
 Sets layer's spatial reference system. More...
 
void setCustomProperties (const QgsObjectCustomProperties &properties)
 Set custom properties for layer. More...
 
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for layer. More...
 
void setDataUrl (const QString &dataUrl)
 Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request. More...
 
void setDataUrlFormat (const QString &dataUrlFormat)
 Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request. More...
 
void setKeywordList (const QString &keywords)
 Sets the keyword list of the layer used by QGIS Server in GetCapabilities request. More...
 
virtual void setLayerOrder (const QStringList &layers)
 Reorders the previously selected sublayers of this layer from bottom to top. More...
 
void setLegend (QgsMapLayerLegend *legend)
 Assign a legend controller to the map layer. More...
 
void setLegendUrl (const QString &legendUrl)
 Sets the URL for the layer's legend. More...
 
void setLegendUrlFormat (const QString &legendUrlFormat)
 Sets the format for a URL based layer legend. More...
 
virtual void setMetadata (const QgsLayerMetadata &metadata)
 Sets the layer's metadata store. More...
 
void setMetadataUrl (const QString &metaUrl)
 Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request. More...
 
void setMetadataUrlFormat (const QString &metaUrlFormat)
 Sets the metadata format of the layer used by QGIS Server in GetCapabilities request. More...
 
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. More...
 
void setName (const QString &name)
 Set the display name of the layer. More...
 
void setShortName (const QString &shortName)
 Sets the short name of the layer used by QGIS Server to identify the layer. More...
 
virtual void setSubLayerVisibility (const QString &name, bool visible)
 Set the visibility of the given sublayer name. More...
 
void setTitle (const QString &title)
 Sets the title of the layer used by QGIS Server in GetCapabilities request. More...
 
QString shortName () const
 Returns the short name of the layer used by QGIS Server to identify the layer. More...
 
QString source () const
 Returns the source for the layer. More...
 
QgsMapLayerStyleManagerstyleManager () const
 Get access to the layer's style manager. More...
 
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) More...
 
virtual QStringList subLayers () const
 Returns the sublayers of this layer. More...
 
virtual QDateTime timestamp () const
 Time stamp of data source in the moment when data/metadata were loaded by provider. More...
 
QString title () const
 Returns the title of the layer used by QGIS Server in GetCapabilities request. More...
 
QgsMapLayer::LayerType type () const
 Returns the type of the layer. More...
 
QUndoStack * undoStack ()
 Return pointer to layer's undo stack. More...
 
QUndoStack * undoStackStyles ()
 Return pointer to layer's style undo stack. More...
 
bool writeLayerXml (QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
 Stores state in Dom node. More...
 
- Public Member Functions inherited from QgsExpressionContextGenerator
virtual ~QgsExpressionContextGenerator ()=default
 
- Public Member Functions inherited from QgsFeatureSink
virtual ~QgsFeatureSink ()=default
 
virtual bool addFeatures (QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=0)
 Adds all features from the specified iterator to the sink. More...
 
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. More...
 
- 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. More...
 

Static Public Member Functions

static void drawVertexMarker (double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
 Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.) More...
 
- Static Public Member Functions inherited from QgsMapLayer
static QString capitalizeLayerName (const QString &name)
 A convenience function to (un)capitalize the layer name. More...
 

Protected Member Functions

void setExtent (const QgsRectangle &rect) override
 Set the extent. More...
 
- Protected Member Functions inherited from QgsMapLayer
void appendError (const QgsErrorMessage &error)
 Add error message. More...
 
void clone (QgsMapLayer *layer) const
 Copies attributes like name, short name, ... More...
 
bool hasDependencyCycle (const QSet< QgsMapLayerDependency > &layers) const
 Checks whether a new set of dependencies will introduce a cycle. More...
 
void readCustomProperties (const QDomNode &layerNode, const QString &keyStartsWith=QString())
 Read custom properties from project file. More...
 
void readStyleManager (const QDomNode &layerNode)
 Read style manager's configuration (if any). To be called by subclasses. More...
 
void setError (const QgsError &error)
 Set error message. More...
 
void setValid (bool valid)
 Set whether layer is valid or not - should be used in constructor. More...
 
void writeCustomProperties (QDomNode &layerNode, QDomDocument &doc) const
 Write custom properties to project file. More...
 
void writeStyleManager (QDomNode &layerNode, QDomDocument &doc) const
 Write style manager's configuration (if exists). To be called by subclasses. More...
 

Properties

QString displayExpression
 
QgsEditFormConfig editFormConfig
 
QString mapTipTemplate
 
double opacity
 
bool readOnly
 
- Properties inherited from QgsMapLayer
int autoRefreshInterval
 
QgsLayerMetadata metadata
 
QString name
 

Friends

class QgsVectorLayerEditBuffer
 
class QgsVectorLayerFeatureSource
 

Additional Inherited Members

- Protected Attributes inherited from QgsMapLayer
QString mAbstract
 Description of the layer. More...
 
QString mAttribution
 Attribution of the layer. More...
 
QString mAttributionUrl
 
QString mDataSource
 Data source description string, varies by layer type. More...
 
QString mDataUrl
 DataUrl of the layer. More...
 
QString mDataUrlFormat
 
QSet< QgsMapLayerDependencymDependencies
 List of layers that may modify this layer on modification. More...
 
QgsError mError
 Error. More...
 
QgsRectangle mExtent
 Extent of the layer. More...
 
bool mIsRefreshOnNofifyEnabled = false
 
QString mKeywordList
 
QString mLayerName
 Name of the layer - used for display. More...
 
QString mLayerOrigName
 Original name of the layer. More...
 
QString mLegendUrl
 WMS legend. More...
 
QString mLegendUrlFormat
 
QString mMetadataUrl
 MetadataUrl of the layer. More...
 
QString mMetadataUrlFormat
 
QString mMetadataUrlType
 
QString mRefreshOnNofifyMessage
 
QString mShortName
 
QString mTitle
 
bool mValid
 Indicates if the layer is valid and can be drawn. More...
 

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.

Sample usage of the QgsVectorLayer class:

QString uri = "point?crs=epsg:4326&field=id:integer";
QgsVectorLayer *scratchLayer = new QgsVectorLayer(uri, "Scratch point layer", "memory");

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"

OGR data provider (ogr)

Accesses data using the OGR drivers (http://www.gdal.org/ogr/ogr_formats.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, starting with QGIS 2.16, a URI constructed using the QgsDataSourceUri class with the following parameters :

The ‘FILTER’ query string parameter can be used to filter the WFS feature type. 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.

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:

-subsetIndex=(yes|no)

Determines whether the provider generates an index to improve the efficiency of subsets. The default is yes

-spatialIndex=(yes|no)

Determines whether the provider generates a spatial index. The default is no.

-watchFile=(yes|no)

Defines whether the file will be monitored for changes. The default is to monitor for changes.

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.

TODO QGIS3: Remove virtual from non-inherited methods (like isModified)

See also
QgsVectorLayerUtils()

Definition at line 350 of file qgsvectorlayer.h.

Member Enumeration Documentation

◆ EditResult

Result of an edit operation.

Enumerator
Success 

Edit operation was successful.

EmptyGeometry 

Edit operation resulted in an empty geometry.

EditFailed 

Edit operation failed.

FetchFeatureFailed 

Unable to fetch requested feature.

InvalidLayer 

Edit failed due to invalid layer.

Definition at line 363 of file qgsvectorlayer.h.

◆ SelectBehavior

Selection behavior.

Enumerator
SetSelection 

Set selection, removing any existing selection.

AddToSelection 

Add selection to current selection.

IntersectSelection 

Modify current selection to include only select features which match.

RemoveFromSelection 

Remove from current selection.

Definition at line 373 of file qgsvectorlayer.h.

◆ VertexMarkerType

Editing vertex markers.

Enumerator
SemiTransparentCircle 
Cross 
NoMarker 

Definition at line 1302 of file qgsvectorlayer.h.

Constructor & Destructor Documentation

◆ QgsVectorLayer() [1/2]

QgsVectorLayer::QgsVectorLayer ( const QString &  path = QString(),
const QString &  baseName = QString(),
const QString &  providerLib = "ogr",
bool  loadDefaultStyleFlag = true,
bool  readExtentFromXml = false 
)

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"
loadDefaultStyleFlagwhether to load the default style
readExtentFromXmlRead extent from XML if true or let provider determine it if false

Definition at line 135 of file qgsvectorlayer.cpp.

◆ ~QgsVectorLayer()

QgsVectorLayer::~QgsVectorLayer ( )
virtual

Definition at line 179 of file qgsvectorlayer.cpp.

◆ QgsVectorLayer() [2/2]

QgsVectorLayer::QgsVectorLayer ( const QgsVectorLayer rhs)
delete

QgsVectorLayer cannot be copied.

Member Function Documentation

◆ actions() [1/2]

QgsActionManager* QgsVectorLayer::actions ( )
inline

Get 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 550 of file qgsvectorlayer.h.

◆ actions() [2/2]

const QgsActionManager* QgsVectorLayer::actions ( ) const
inline

Get all layer actions defined on this layer.

The pointer which is returned is const.

Definition at line 557 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.

Definition at line 2311 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 2866 of file qgsvectorlayer.cpp.

◆ addFeature()

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

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 935 of file qgsvectorlayer.cpp.

◆ addFeatures()

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

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 2654 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 2850 of file qgsvectorlayer.cpp.

◆ addPart() [1/3]

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

Adds a new part polygon to a multipart feature.

Returns
0 in case of success, 1 if selected feature is not multipart, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing rings, 4 if no feature was selected, 5 if several features are selected, 6 if selected geometry not found 7 layer not editable

Definition at line 1156 of file qgsvectorlayer.cpp.

◆ addPart() [2/3]

int QgsVectorLayer::addPart ( const QgsPointSequence ring)

Adds a new part polygon to a multipart feature.

Returns
0 in case of success, 1 if selected feature is not multipart, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing rings, 4 if no feature was selected, 5 if several features are selected, 6 if selected geometry not found 7 layer not editable
Note
available in Python bindings as addPartV2

Definition at line 1182 of file qgsvectorlayer.cpp.

◆ addPart() [3/3]

int QgsVectorLayer::addPart ( QgsCurve ring)
Note
available in Python as addCurvedPart

Definition at line 1208 of file qgsvectorlayer.cpp.

◆ addRing() [1/2]

int QgsVectorLayer::addRing ( const QList< 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
0 in case of success, 1 problem with feature type, 2 ring not closed, 3 ring not valid, 4 ring crosses existing rings, 5 no feature found where ring can be inserted 6 layer not editable

Definition at line 1095 of file qgsvectorlayer.cpp.

◆ addRing() [2/2]

int 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
0 in case of success 1 problem with feature type 2 ring not closed 6 layer not editable
Note
available in Python as addCurvedRing

Definition at line 1118 of file qgsvectorlayer.cpp.

◆ addTopologicalPoints() [1/2]

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
Note
geom is not going to be modified by the function
Returns
0 in case of success

Definition at line 1265 of file qgsvectorlayer.cpp.

◆ addTopologicalPoints() [2/2]

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
0 in case of success

Definition at line 1274 of file qgsvectorlayer.cpp.

◆ aggregate()

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

Calculates an aggregated value from the layer's features.

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
Returns
calculated aggregate value
Since
QGIS 2.16

Definition at line 3461 of file qgsvectorlayer.cpp.

◆ 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 2387 of file qgsvectorlayer.cpp.

◆ attributeAliases()

QgsStringMap QgsVectorLayer::attributeAliases ( ) const

Returns a map of field name to attribute alias.

Definition at line 2403 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 2395 of file qgsvectorlayer.cpp.

◆ attributeList()

QgsAttributeList QgsVectorLayer::attributeList ( ) const
inline

Returns list of attribute indexes.

i.e. a list from 0 ... fieldCount() Alias for attributeList()

Definition at line 1116 of file qgsvectorlayer.h.

◆ attributeTableConfig()

QgsAttributeTableConfig QgsVectorLayer::attributeTableConfig ( ) const

Get the attribute table configuration object.

This defines the appearance of the attribute table.

Definition at line 3879 of file qgsvectorlayer.cpp.

◆ attributeValueChanged

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

Is 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

◆ 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 ( )
signal

Is emitted, before changes are committed to the data provider.

◆ beforeEditingStarted

void QgsVectorLayer::beforeEditingStarted ( )
signal

Is emitted, before editing on this layer is started.

◆ beforeModifiedCheck

void QgsVectorLayer::beforeModifiedCheck ( ) const
signal

Is emitted, when 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

Is 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 2805 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 606 of file qgsvectorlayer.cpp.

◆ capabilitiesString()

QString QgsVectorLayer::capabilitiesString ( ) const

Capabilities for this layer, comma separated and translated.

Definition at line 286 of file qgsvectorlayer.cpp.

◆ changeAttributeValue()

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

Changes an attribute value (but does not commit it)

Parameters
fidThe feature id of the feature to be changed
fieldThe index of the field to be updated
newValueThe value which will be assigned to the field
oldValueThe previous value to restore on undo (will otherwise be retrieved)
Returns
true in case of success

Definition at line 2287 of file qgsvectorlayer.cpp.

◆ changeGeometry()

bool QgsVectorLayer::changeGeometry ( QgsFeatureId  fid,
const QgsGeometry geom 
)

Change feature's geometry.

Definition at line 2270 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 identicals.

Returns
a new layer instance
Since
QGIS 3.0

Implements QgsMapLayer.

Definition at line 202 of file qgsvectorlayer.cpp.

◆ commitChanges()

bool QgsVectorLayer::commitChanges ( )

Attempts to commit any changes to disk.

Returns the result of the attempt. If a commit fails, the in-memory changes are left alone.

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's difficult to roll back cleanly. Therefore any error message also includes which stage failed so that the user has some chance of repairing the damage cleanly.

See also
commitErrors()

Definition at line 2512 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 2554 of file qgsvectorlayer.cpp.

◆ committedAttributesAdded

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

This signal is emitted, when attributes are added to the provider.

◆ committedAttributesDeleted

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

This signal is emitted, when attributes are deleted from the provider.

◆ committedAttributeValuesChanges

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

This signal is emitted, when attribute value changes are saved to the provider.

◆ committedFeaturesAdded

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

This signal is emitted, when features are added to the provider.

◆ committedFeaturesRemoved

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

This signal is emitted, when features are deleted from the provider.

◆ committedGeometriesChanges

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

This signal is emitted, when geometry changes are saved to the provider.

◆ conditionalStyles()

QgsConditionalLayerStyles * QgsVectorLayer::conditionalStyles ( ) const

Return 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 922 of file qgsvectorlayer.cpp.

◆ constraintDescription()

QString QgsVectorLayer::constraintDescription ( int  index) const

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

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

Definition at line 4359 of file qgsvectorlayer.cpp.

◆ constraintExpression()

QString QgsVectorLayer::constraintExpression ( int  index) const

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

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

Definition at line 4351 of file qgsvectorlayer.cpp.

◆ countSymbolFeatures()

QgsVectorLayerFeatureCounter * QgsVectorLayer::countSymbolFeatures ( )

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.

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 730 of file qgsvectorlayer.cpp.

◆ createExpressionContext()

QgsExpressionContext QgsVectorLayer::createExpressionContext ( ) const
overridevirtual

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 3898 of file qgsvectorlayer.cpp.

◆ createMapRenderer()

QgsMapLayerRenderer * QgsVectorLayer::createMapRenderer ( QgsRenderContext rendererContext)
overridevirtual

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

Since
QGIS 2.4

Implements QgsMapLayer.

Definition at line 329 of file qgsvectorlayer.cpp.

◆ dataComment()

QString QgsVectorLayer::dataComment ( ) const

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

Definition at line 295 of file qgsvectorlayer.cpp.

◆ dataProvider() [1/2]

QgsVectorDataProvider * QgsVectorLayer::dataProvider ( )
overridevirtual

Returns the layer's data provider.

Reimplemented from QgsMapLayer.

Definition at line 553 of file qgsvectorlayer.cpp.

◆ dataProvider() [2/2]

const QgsVectorDataProvider * QgsVectorLayer::dataProvider ( ) const
overridevirtual

Returns the layer's data provider in a const-correct manner.

Note
not available in Python bindings

Reimplemented from QgsMapLayer.

Definition at line 558 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 setDefaultValueExpression()) 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
Since
QGIS 3.0
See also
setDefaultValueExpression()

Definition at line 3011 of file qgsvectorlayer.cpp.

◆ defaultValueExpression()

QString QgsVectorLayer::defaultValueExpression ( int  index) const

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

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

Definition at line 3073 of file qgsvectorlayer.cpp.

◆ deleteAttribute()

bool QgsVectorLayer::deleteAttribute ( int  attr)

Delete an attribute field (but does not commit it)

Definition at line 2414 of file qgsvectorlayer.cpp.

◆ deleteAttributes()

bool QgsVectorLayer::deleteAttributes ( 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 2431 of file qgsvectorlayer.cpp.

◆ deleteFeature()

bool QgsVectorLayer::deleteFeature ( QgsFeatureId  fid)

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

Definition at line 2451 of file qgsvectorlayer.cpp.

◆ deleteFeatures()

bool QgsVectorLayer::deleteFeatures ( const QgsFeatureIds fids)

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

Parameters
fidsThe feature ids to delete
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

Definition at line 2469 of file qgsvectorlayer.cpp.

◆ deleteSelectedFeatures()

bool QgsVectorLayer::deleteSelectedFeatures ( int *  deletedCount = nullptr)

Deletes the selected features.

Returns
true in case of success and false otherwise

Definition at line 1063 of file qgsvectorlayer.cpp.

◆ deleteStyleFromDatabase()

bool QgsVectorLayer::deleteStyleFromDatabase ( const QString &  styleId,
QString &  msgError 
)
virtual

Delete a style from the database.

Since
QGIS 3.0
Parameters
styleIdthe provider's layer_styles table id of the style to delete
msgErrorreference to string that will be updated with any error messages
Returns
true in case of success

Definition at line 4130 of file qgsvectorlayer.cpp.

◆ deleteVertex()

QgsVectorLayer::EditResult 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
Since
QGIS 2.14

Definition at line 1049 of file qgsvectorlayer.cpp.

◆ dependencies()

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

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 4220 of file qgsvectorlayer.cpp.

◆ deselect [1/2]

void QgsVectorLayer::deselect ( const QgsFeatureId  featureId)
slot

Deselect feature by its ID.

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

Definition at line 365 of file qgsvectorlayer.cpp.

◆ deselect [2/2]

void QgsVectorLayer::deselect ( const QgsFeatureIds featureIds)
slot

Deselect features by their ID.

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

Definition at line 372 of file qgsvectorlayer.cpp.

◆ destroyEditCommand()

void QgsVectorLayer::destroyEditCommand ( )

Destroy active command and reverts all changes in it.

Definition at line 2837 of file qgsvectorlayer.cpp.

◆ diagramLayerSettings()

const QgsDiagramLayerSettings* QgsVectorLayer::diagramLayerSettings ( ) const
inline

Definition at line 678 of file qgsvectorlayer.h.

◆ diagramRenderer()

const QgsDiagramRenderer* QgsVectorLayer::diagramRenderer ( ) const
inline

Definition at line 675 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 670 of file qgsvectorlayer.cpp.

◆ displayExpression()

QString QgsVectorLayer::displayExpression ( ) const

Get 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

◆ 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 2689 of file qgsvectorlayer.cpp.

◆ drawVertexMarker()

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

Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)

Definition at line 335 of file qgsvectorlayer.cpp.

◆ editBuffer() [1/2]

QgsVectorLayerEditBuffer* QgsVectorLayer::editBuffer ( )
inline

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

Definition at line 1283 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 1287 of file qgsvectorlayer.h.

◆ editCommandDestroyed

void QgsVectorLayer::editCommandDestroyed ( )
signal

Signal emitted, whan 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

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

This is a writable configuration that can directly be changed in place.

Returns
The configuration of this layers' form
Since
QGIS 2.14

◆ editFormConfigChanged

void QgsVectorLayer::editFormConfigChanged ( )
signal

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

Since
QGIS 3.0

◆ editingStarted

void QgsVectorLayer::editingStarted ( )
signal

Is emitted, when editing on this layer has started.

◆ editingStopped

void QgsVectorLayer::editingStopped ( )
signal

Is emitted, when edited changes successfully have been written to the data provider.

◆ 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 4395 of file qgsvectorlayer.cpp.

◆ endEditCommand()

void QgsVectorLayer::endEditCommand ( )

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

Definition at line 2821 of file qgsvectorlayer.cpp.

◆ excludeAttributesWfs()

QSet<QString> QgsVectorLayer::excludeAttributesWfs ( ) const
inline

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

Definition at line 1212 of file qgsvectorlayer.h.

◆ excludeAttributesWms()

QSet<QString> QgsVectorLayer::excludeAttributesWms ( ) const
inline

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

Definition at line 1202 of file qgsvectorlayer.h.

◆ 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 2885 of file qgsvectorlayer.cpp.

◆ extent()

QgsRectangle QgsVectorLayer::extent ( ) const
overridevirtual

Returns the extent of the layer.

Reimplemented from QgsMapLayer.

Definition at line 778 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 3606 of file qgsvectorlayer.cpp.

◆ featureBlendModeChanged

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

Signal emitted when setFeatureBlendMode() is called.

◆ featureCount() [1/2]

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 683 of file qgsvectorlayer.cpp.

◆ featureCount() [2/2]

long QgsVectorLayer::featureCount ( ) const
overridevirtual

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.

Implements QgsFeatureSource.

Definition at line 2506 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

◆ 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.

◆ 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.

Since
QGIS 3.0
See also
setFieldConstraint()

Definition at line 4280 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 4296 of file qgsvectorlayer.cpp.

◆ fields()

QgsFields QgsVectorLayer::fields ( ) const
inlineoverridevirtual

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 1095 of file qgsvectorlayer.h.

◆ geometryChanged

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

Is 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

◆ geometryType()

QgsWkbTypes::GeometryType QgsVectorLayer::geometryType ( ) const

Returns point, line or polygon.

Definition at line 580 of file qgsvectorlayer.cpp.

◆ getDoubleValues()

QList< double > QgsVectorLayer::getDoubleValues ( const QString &  fieldOrExpression,
bool &  ok,
bool  selectedOnly = false,
int *  nullCount = nullptr,
QgsFeedback feedback = nullptr 
) const

Fetches all double values from a specified field name or expression.

Null values or invalid expression results are skipped.

Parameters
fieldOrExpressionfield name or an expression string evaluating to a double value
okwill be set to false if field or expression is invalid, otherwise true
selectedOnlyset to true to get values from selected features only
nullCountoptional pointer to integer to store number of null values encountered in
feedbackoptional feedback object to allow cancelation
Returns
list of fetched values
Since
QGIS 2.9
See also
getValues

Definition at line 3567 of file qgsvectorlayer.cpp.

◆ getFeature()

QgsFeature QgsVectorLayer::getFeature ( QgsFeatureId  fid) const
inline

Query the layer for the feature with the given id.

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

Definition at line 885 of file qgsvectorlayer.h.

◆ getFeatures() [1/4]

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

Query 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 927 of file qgsvectorlayer.cpp.

◆ getFeatures() [2/4]

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

Query the layer for features matching a given expression.

Definition at line 876 of file qgsvectorlayer.h.

◆ getFeatures() [3/4]

QgsFeatureIterator QgsVectorLayer::getFeatures ( const QgsFeatureIds fids)
inline

Query the layer for the features with the given ids.

Definition at line 895 of file qgsvectorlayer.h.

◆ getFeatures() [4/4]

QgsFeatureIterator QgsVectorLayer::getFeatures ( const QgsRectangle rectangle)
inline

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

Definition at line 903 of file qgsvectorlayer.h.

◆ getSelectedFeatures()

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

Get 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
See also
selectedFeatureIds()
selectedFeatures()

Definition at line 2638 of file qgsvectorlayer.cpp.

◆ getStyleFromDatabase()

QString QgsVectorLayer::getStyleFromDatabase ( const QString &  styleId,
QString &  msgError 
)
virtual

Will return the named style corresponding to style id provided.

Definition at line 4111 of file qgsvectorlayer.cpp.

◆ getValues()

QList< QVariant > QgsVectorLayer::getValues ( const QString &  fieldOrExpression,
bool &  ok,
bool  selectedOnly = false,
QgsFeedback feedback = nullptr 
) const

Fetches all values from a specified field name or expression.

Parameters
fieldOrExpressionfield name or an expression string
okwill be set to false if field or expression is invalid, otherwise true
selectedOnlyset to true to get values from selected features only
feedbackoptional feedback object to allow cancelation
Returns
list of fetched values
Since
QGIS 2.9
See also
getDoubleValues

Definition at line 3499 of file qgsvectorlayer.cpp.

◆ htmlMetadata()

QString QgsVectorLayer::htmlMetadata ( ) const
overridevirtual

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

Since
QGIS 3.0

Reimplemented from QgsMapLayer.

Definition at line 3910 of file qgsvectorlayer.cpp.

◆ insertVertex() [1/2]

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

Insert 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.

Definition at line 997 of file qgsvectorlayer.cpp.

◆ insertVertex() [2/2]

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

Insert 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.

Definition at line 1010 of file qgsvectorlayer.cpp.

◆ invertSelection()

void QgsVectorLayer::invertSelection ( )

Select not selected features and deselect selected ones.

Definition at line 504 of file qgsvectorlayer.cpp.

◆ invertSelectionInRectangle()

void QgsVectorLayer::invertSelectionInRectangle ( QgsRectangle rect)

Invert 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 516 of file qgsvectorlayer.cpp.

◆ isEditable()

bool QgsVectorLayer::isEditable ( ) const
overridevirtual

Returns true if the provider is in editing mode.

Reimplemented from QgsMapLayer.

Definition at line 2755 of file qgsvectorlayer.cpp.

◆ isEditCommandActive

bool QgsVectorLayer::isEditCommandActive ( ) const
inlineslot

Test if an edit command is active.

Since
QGIS 3.0

Definition at line 1697 of file qgsvectorlayer.h.

◆ isModified()

bool QgsVectorLayer::isModified ( ) const
virtual

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

Definition at line 2782 of file qgsvectorlayer.cpp.

◆ isSpatial()

bool QgsVectorLayer::isSpatial ( ) const
overridevirtual

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

Reimplemented from QgsMapLayer.

Definition at line 2760 of file qgsvectorlayer.cpp.

◆ joinBuffer()

QgsVectorLayerJoinBuffer* QgsVectorLayer::joinBuffer ( )
inline

Accessor to the join buffer object.

Since
QGIS 2.14.7

Definition at line 479 of file qgsvectorlayer.h.

◆ labeling()

const QgsAbstractVectorLayerLabeling* QgsVectorLayer::labeling ( ) const
inline

Access to labeling configuration.

May be null if labeling is not used.

Since
QGIS 3.0

Definition at line 1062 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
Since
QGIS 2.9

Definition at line 665 of file qgsvectorlayer.cpp.

◆ layerModified

void QgsVectorLayer::layerModified ( )
signal

This signal is emitted when modifications has been done on layer.

◆ listStylesInDatabase()

int QgsVectorLayer::listStylesInDatabase ( QStringList &  ids,
QStringList &  names,
QStringList &  descriptions,
QString &  msgError 
)
virtual

Lists all the style in db split into related to the layer and not related to.

Parameters
idsthe list in which will be stored the style db ids
namesthe list in which will be stored the style names
descriptionsthe list in which will be stored the style descriptions
msgError
Returns
the number of styles related to current layer

Definition at line 4092 of file qgsvectorlayer.cpp.

◆ loadNamedStyle() [1/2]

QString QgsVectorLayer::loadNamedStyle ( const QString &  theURI,
bool &  resultFlag,
bool  loadFromLocalDb 
)
virtual

Load a named style from file/local db/datasource db.

Parameters
theURIthe URI of the style or the URI of the layer
resultFlagwill be set to true if a named style is correctly loaded
loadFromLocalDbif true forces to load from local db instead of datasource one

Definition at line 4193 of file qgsvectorlayer.cpp.

◆ loadNamedStyle() [2/2]

QString QgsVectorLayer::loadNamedStyle ( const QString &  theURI,
bool &  resultFlag 
)
overridevirtual

Calls loadNamedStyle( theURI, resultFlag, false ); Retained for backward compatibility.

Reimplemented from QgsMapLayer.

Definition at line 4188 of file qgsvectorlayer.cpp.

◆ mapTipTemplate()

QString QgsVectorLayer::mapTipTemplate ( ) const

The mapTip is a pretty, html representation for feature information.

It may also contain embedded expressions.

Since
QGIS 3.0

◆ mapTipTemplateChanged

void QgsVectorLayer::mapTipTemplateChanged ( )
signal

Emitted when the map tip changes.

Since
QGIS 3.0

◆ maximumValue()

QVariant QgsVectorLayer::maximumValue ( int  index) const
overridevirtual

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

Note that 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).

See also
minimumValue()
uniqueValues()

Reimplemented from QgsFeatureSource.

Definition at line 3376 of file qgsvectorlayer.cpp.

◆ minimumValue()

QVariant QgsVectorLayer::minimumValue ( int  index) const
overridevirtual

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

Note that 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).

See also
maximumValue()
uniqueValues()

Reimplemented from QgsFeatureSource.

Definition at line 3288 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
select(QgsFeatureIds)
select(QgsFeatureId)
deselect(QgsFeatureIds)
deselect(QgsFeatureId)
selectByExpression()

Definition at line 490 of file qgsvectorlayer.cpp.

◆ moveVertex() [1/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.

Definition at line 1023 of file qgsvectorlayer.cpp.

◆ moveVertex() [2/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

Definition at line 1036 of file qgsvectorlayer.cpp.

◆ opacity()

double QgsVectorLayer::opacity ( ) const

Returns the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).

See also
setOpacity()
opacityChanged()
Since
QGIS 3.0

◆ opacityChanged

void QgsVectorLayer::opacityChanged ( double  opacity)
signal

Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (opaque).

Since
QGIS 3.0
See also
setOpacity()
opacity()

◆ operator=()

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

QgsVectorLayer cannot be copied.

◆ pendingAllAttributesList()

QgsAttributeList QgsVectorLayer::pendingAllAttributesList ( ) const
inline

Returns list of attribute indexes.

i.e. a list from 0 ... fieldCount() Alias for attributeList()

Definition at line 1110 of file qgsvectorlayer.h.

◆ pendingFeatureCount()

long QgsVectorLayer::pendingFeatureCount ( ) const
inline

Returns feature count including changes which have not yet been committed Alias for featureCount()

Definition at line 1131 of file qgsvectorlayer.h.

◆ pendingFields()

QgsFields QgsVectorLayer::pendingFields ( ) const
inline

Returns the list of fields of this layer.

This also includes fields which have not yet been saved to the provider. Alias for fields()

Returns
A list of fields

Definition at line 1104 of file qgsvectorlayer.h.

◆ pendingPkAttributesList()

QgsAttributeList QgsVectorLayer::pendingPkAttributesList ( ) const
inline

Returns list of attributes making up the primary key Alias for pkAttributeList()

Definition at line 1122 of file qgsvectorlayer.h.

◆ pkAttributeList()

QgsAttributeList QgsVectorLayer::pkAttributeList ( ) const

Returns list of attributes making up the primary key.

Definition at line 2491 of file qgsvectorlayer.cpp.

◆ providerType()

QString QgsVectorLayer::providerType ( ) const

Return the provider type for this layer.

Definition at line 305 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 4434 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.

Since
QGIS 3.0

◆ readSld()

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

Reimplemented from QgsMapLayer.

Definition at line 2209 of file qgsvectorlayer.cpp.

◆ readStyle()

bool QgsVectorLayer::readStyle ( const QDomNode &  node,
QString &  errorMessage,
const QgsReadWriteContext context 
)
overridevirtual

Read the style for the current layer from the Dom node supplied.

Parameters
nodenode that will contain the style definition for this layer.
errorMessagereference to string that will be updated with any error messages
contextreading context (used for transform from relative to absolute paths)
Returns
true in case of success.

Reimplemented from QgsMapLayer.

Definition at line 1852 of file qgsvectorlayer.cpp.

◆ readSymbology()

bool QgsVectorLayer::readSymbology ( const QDomNode &  layerNode,
QString &  errorMessage,
const QgsReadWriteContext context 
)
overridevirtual

Read the symbology for the current layer from the Dom node supplied.

Parameters
layerNodenode that will contain the symbology definition for this layer.
errorMessagereference to string that will be updated with any error messages
contextreading context (used for transform from relative to absolute paths)
Returns
true in case of success.

Implements QgsMapLayer.

Definition at line 1666 of file qgsvectorlayer.cpp.

◆ readXml()

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

Reads vector layer specific state from project file Dom node.

Note
Called by QgsMapLayer::readXml().

Reimplemented from QgsMapLayer.

Definition at line 1352 of file qgsvectorlayer.cpp.

◆ referencingRelations()

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

Get 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 4087 of file qgsvectorlayer.cpp.

◆ reload()

void QgsVectorLayer::reload ( )
overridevirtual

Synchronises with changes in the datasource.

Reimplemented from QgsMapLayer.

Definition at line 320 of file qgsvectorlayer.cpp.

◆ removeExpressionField()

void QgsVectorLayer::removeExpressionField ( int  index)

Remove an expression field.

Parameters
indexThe index of the field
Since
QGIS 2.6

Definition at line 2876 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 2319 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.

Since
QGIS 3.0
See also
fieldConstraints()
setFieldConstraint()

Definition at line 4334 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 2856 of file qgsvectorlayer.cpp.

◆ removeSelection

void QgsVectorLayer::removeSelection ( )
slot

Clear selection.

See also
selectByIds()

Definition at line 545 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
Since
QGIS 2.16

Definition at line 2335 of file qgsvectorlayer.cpp.

◆ renderer() [1/2]

QgsFeatureRenderer* QgsVectorLayer::renderer ( )
inline

Return renderer.

Definition at line 681 of file qgsvectorlayer.h.

◆ renderer() [2/2]

const QgsFeatureRenderer* QgsVectorLayer::renderer ( ) const
inline

Return const renderer.

Note
not available in Python bindings

Definition at line 686 of file qgsvectorlayer.h.

◆ resolveReferences()

void QgsVectorLayer::resolveReferences ( QgsProject project)

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

Since
QGIS 3.0

Definition at line 1660 of file qgsvectorlayer.cpp.

◆ rollBack()

bool QgsVectorLayer::rollBack ( bool  deleteBuffer = true)

Stop editing and discard the edits.

Parameters
deleteBufferwhether to delete editing buffer

Definition at line 2559 of file qgsvectorlayer.cpp.

◆ saveStyleToDatabase()

void QgsVectorLayer::saveStyleToDatabase ( const QString &  name,
const QString &  description,
bool  useAsDefault,
const QString &  uiFileContent,
QString &  msgError 
)
virtual

Save named and sld style of the layer to the style table in the db.

Parameters
name
description
useAsDefault
uiFileContent
msgError

Definition at line 4148 of file qgsvectorlayer.cpp.

◆ select [1/2]

void QgsVectorLayer::select ( QgsFeatureId  featureId)
slot

Select feature by its ID.

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

Definition at line 351 of file qgsvectorlayer.cpp.

◆ select [2/2]

void QgsVectorLayer::select ( const QgsFeatureIds featureIds)
slot

Select features by their ID.

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

Definition at line 358 of file qgsvectorlayer.cpp.

◆ selectAll()

void QgsVectorLayer::selectAll ( )

Select all the features.

Definition at line 511 of file qgsvectorlayer.cpp.

◆ selectByExpression()

void QgsVectorLayer::selectByExpression ( const QString &  expression,
QgsVectorLayer::SelectBehavior  behavior = SetSelection 
)

Select matching features using an expression.

Parameters
expressionexpression to evaluate to select features
behaviorselection type, allows adding to current selection, removing from selection, etc.
Since
QGIS 2.16
See also
selectByRect()
selectByIds()

Definition at line 401 of file qgsvectorlayer.cpp.

◆ selectByIds()

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

Select 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.
Since
QGIS 2.16
See also
selectByRect()
selectByExpression()

Definition at line 461 of file qgsvectorlayer.cpp.

◆ selectByRect()

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

Select 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 379 of file qgsvectorlayer.cpp.

◆ selectedFeatureCount()

int QgsVectorLayer::selectedFeatureCount ( ) const

The number of features that are selected in this layer.

Returns
See description

Definition at line 2600 of file qgsvectorlayer.cpp.

◆ selectedFeatureIds()

const QgsFeatureIds & QgsVectorLayer::selectedFeatureIds ( ) const

Return reference to identifiers of selected features.

Returns
A list of QgsFeatureId
See also
selectedFeatures()

Definition at line 2605 of file qgsvectorlayer.cpp.

◆ selectedFeatures()

QgsFeatureList QgsVectorLayer::selectedFeatures ( ) const

Get a copy of the user-selected features.

Returns
A list of QgsFeature
See also
selectedFeatureIds()
getSelectedFeatures() which is more memory friendly when handling large selections

Definition at line 2610 of file qgsvectorlayer.cpp.

◆ selectionChanged

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

This signal is 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

◆ setAttributeTableConfig()

void QgsVectorLayer::setAttributeTableConfig ( const QgsAttributeTableConfig attributeTableConfig)

Set the attribute table configuration object.

This defines the appearance of the attribute table.

Definition at line 3889 of file qgsvectorlayer.cpp.

◆ setConstraintExpression()

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

Set 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.

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

Definition at line 4367 of file qgsvectorlayer.cpp.

◆ setCoordinateSystem()

void QgsVectorLayer::setCoordinateSystem ( )

Setup the coordinate system transformation for the layer.

Definition at line 2668 of file qgsvectorlayer.cpp.

◆ setDataSource()

void QgsVectorLayer::setDataSource ( const QString &  dataSource,
const QString &  baseName,
const QString &  provider,
bool  loadDefaultStyleFlag = false 
)

Update the data source of the layer.

The layer's renderer and legend will be preserved only if the geometry type of the new data source matches the current geometry type of the layer.

Parameters
dataSourcenew layer data source
baseNamebase name of the layer
providerprovider string
loadDefaultStyleFlagset to true to reset the layer's style to the default for the data source
Since
QGIS 2.10

Definition at line 1439 of file qgsvectorlayer.cpp.

◆ setDefaultValueExpression()

void QgsVectorLayer::setDefaultValueExpression ( int  index,
const QString &  expression 
)

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

Parameters
indexfield index
expressionexpression to evaluate when calculating default values for field. Pass an empty expression to clear the default.
Since
QGIS 3.0
See also
defaultValue()
defaultValueExpression()

Definition at line 3057 of file qgsvectorlayer.cpp.

◆ setDependencies()

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

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 4227 of file qgsvectorlayer.cpp.

◆ setDiagramLayerSettings()

void QgsVectorLayer::setDiagramLayerSettings ( const QgsDiagramLayerSettings s)

Definition at line 3903 of file qgsvectorlayer.cpp.

◆ setDiagramRenderer()

void QgsVectorLayer::setDiagramRenderer ( QgsDiagramRenderer r)

Sets diagram rendering object (takes ownership)

Definition at line 572 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 2700 of file qgsvectorlayer.cpp.

◆ setEditFormConfig()

void QgsVectorLayer::setEditFormConfig ( const QgsEditFormConfig editFormConfig)

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

This is a writable configuration that can directly be changed in place.

Returns
The configuration of this layers' form
Since
QGIS 3.0

Definition at line 3855 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 4383 of file qgsvectorlayer.cpp.

◆ setExcludeAttributesWfs()

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

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

Definition at line 1217 of file qgsvectorlayer.h.

◆ setExcludeAttributesWms()

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

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

Definition at line 1207 of file qgsvectorlayer.h.

◆ setExtent()

void QgsVectorLayer::setExtent ( const QgsRectangle rect)
overrideprotectedvirtual

Set the extent.

Reimplemented from QgsMapLayer.

Definition at line 772 of file qgsvectorlayer.cpp.

◆ setFeatureBlendMode()

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

Set the blending mode used for rendering each feature.

Definition at line 3599 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 2374 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.

Since
QGIS 3.0
See also
fieldConstraints()
removeFieldConstraint()

Definition at line 4317 of file qgsvectorlayer.cpp.

◆ setLabeling()

void QgsVectorLayer::setLabeling ( QgsAbstractVectorLayerLabeling labeling)

Set labeling configuration.

Takes ownership of the object.

Since
QGIS 3.0

Definition at line 1283 of file qgsvectorlayer.cpp.

◆ setMapTipTemplate()

void QgsVectorLayer::setMapTipTemplate ( const QString &  mapTipTemplate)

The mapTip is a pretty, html representation for feature information.

It may also contain embedded expressions.

Since
QGIS 3.0

Definition at line 3870 of file qgsvectorlayer.cpp.

◆ setOpacity()

void QgsVectorLayer::setOpacity ( double  opacity)

Sets the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).

See also
opacity()
opacityChanged()
Since
QGIS 3.0

Definition at line 3611 of file qgsvectorlayer.cpp.

◆ setProviderEncoding()

void QgsVectorLayer::setProviderEncoding ( const QString &  encoding)

Sets the textencoding of the data provider.

Definition at line 563 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 4429 of file qgsvectorlayer.cpp.

◆ setReadOnly()

bool QgsVectorLayer::setReadOnly ( bool  readonly = true)

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

Returns
false if the layer is in editing yet

Definition at line 2771 of file qgsvectorlayer.cpp.

◆ setRenderer()

void QgsVectorLayer::setRenderer ( QgsFeatureRenderer r)

Set renderer which will be invoked to represent this layer.

Ownership is transferred.

Definition at line 2788 of file qgsvectorlayer.cpp.

◆ setSimplifyMethod()

void QgsVectorLayer::setSimplifyMethod ( const QgsVectorSimplifyMethod simplifyMethod)
inline

Set the simplification settings for fast rendering of features.

Since
QGIS 2.2

Definition at line 1540 of file qgsvectorlayer.h.

◆ setSubsetString()

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

Set 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 889 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 910 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 1545 of file qgsvectorlayer.h.

◆ sourceCrs()

QgsCoordinateReferenceSystem QgsVectorLayer::sourceCrs ( ) const
overridevirtual

Returns the coordinate reference system for features in the source.

Implements QgsFeatureSource.

Definition at line 310 of file qgsvectorlayer.cpp.

◆ sourceExtent()

QgsRectangle QgsVectorLayer::sourceExtent ( ) const
overridevirtual

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 874 of file qgsvectorlayer.cpp.

◆ sourceName()

QString QgsVectorLayer::sourceName ( ) const
overridevirtual

Returns a friendly display name for the source.

The returned value can be an empty string.

Implements QgsFeatureSource.

Definition at line 315 of file qgsvectorlayer.cpp.

◆ splitFeatures()

int QgsVectorLayer::splitFeatures ( const QList< 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
0 in case of success, 4 if there is a selection but no feature split

Definition at line 1256 of file qgsvectorlayer.cpp.

◆ splitParts()

int QgsVectorLayer::splitParts ( const QList< 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
0 in case of success, 4 if there is a selection but no feature split

Definition at line 1247 of file qgsvectorlayer.cpp.

◆ startEditing

bool QgsVectorLayer::startEditing ( )
slot

Make 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().

Definition at line 1292 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 276 of file qgsvectorlayer.cpp.

◆ subsetString()

QString QgsVectorLayer::subsetString ( ) const
virtual

Get 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 879 of file qgsvectorlayer.cpp.

◆ symbolFeatureCountMapChanged

void QgsVectorLayer::symbolFeatureCountMapChanged ( )
signal

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

Since
QGIS 3.0

◆ 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

Definition at line 1234 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 3187 of file qgsvectorlayer.cpp.

◆ uniqueValues()

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

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 3081 of file qgsvectorlayer.cpp.

◆ updatedFields

void QgsVectorLayer::updatedFields ( )
signal

Is 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 2894 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 765 of file qgsvectorlayer.cpp.

◆ updateFeature()

bool QgsVectorLayer::updateFeature ( QgsFeature f)

Updates an existing feature.

This method needs to query the datasource on every call. Consider using changeAttributeValue() or changeGeometry() instead.

Parameters
fFeature to update
Returns
True in case of success and False in case of error

Definition at line 953 of file qgsvectorlayer.cpp.

◆ updateFields()

void QgsVectorLayer::updateFields ( )

Assembles mUpdatedFields considering provider fields, joined fields and added fields.

Definition at line 2900 of file qgsvectorlayer.cpp.

◆ vectorJoins()

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

Definition at line 2861 of file qgsvectorlayer.cpp.

◆ wkbType()

QgsWkbTypes::Type QgsVectorLayer::wkbType ( ) const
overridevirtual

Returns the WKBType or WKBUnknown in case of error.

Implements QgsFeatureSource.

Definition at line 601 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 QgsStringMap props = QgsStringMap() 
) 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 2232 of file qgsvectorlayer.cpp.

◆ writeStyle()

bool QgsVectorLayer::writeStyle ( QDomNode &  node,
QDomDocument &  doc,
QString &  errorMessage,
const QgsReadWriteContext context 
) const
overridevirtual

Write just the style information for the layer into the document.

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
contextwriting context (used for transform from absolute to relative paths)
Returns
true in case of success.

Reimplemented from QgsMapLayer.

Definition at line 2151 of file qgsvectorlayer.cpp.

◆ writeSymbology()

bool QgsVectorLayer::writeSymbology ( QDomNode &  node,
QDomDocument &  doc,
QString &  errorMessage,
const QgsReadWriteContext context 
) const
overridevirtual

Write the symbology for the layer into the docment provided.

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
contextwriting context (used for transform from absolute to relative paths)
Returns
true in case of success.

Implements QgsMapLayer.

Definition at line 2013 of file qgsvectorlayer.cpp.

◆ writeXml()

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

Write vector layer specific state to project file Dom node.

Note
Called by QgsMapLayer::writeXml().

Reimplemented from QgsMapLayer.

Definition at line 1593 of file qgsvectorlayer.cpp.

Friends And Related Function Documentation

◆ QgsVectorLayerEditBuffer

friend class QgsVectorLayerEditBuffer
friend

Definition at line 2052 of file qgsvectorlayer.h.

◆ QgsVectorLayerFeatureSource

friend class QgsVectorLayerFeatureSource
friend

Definition at line 2089 of file qgsvectorlayer.h.

Property Documentation

◆ displayExpression

QString QgsVectorLayer::displayExpression
readwrite

Definition at line 354 of file qgsvectorlayer.h.

◆ editFormConfig

QgsEditFormConfig QgsVectorLayer::editFormConfig
readwrite

Definition at line 356 of file qgsvectorlayer.h.

◆ mapTipTemplate

QString QgsVectorLayer::mapTipTemplate
readwrite

Definition at line 355 of file qgsvectorlayer.h.

◆ opacity

double QgsVectorLayer::opacity
readwrite

Definition at line 358 of file qgsvectorlayer.h.

◆ readOnly

bool QgsVectorLayer::readOnly
readwrite

Definition at line 357 of file qgsvectorlayer.h.


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