18 #ifndef QGSVECTORLAYER_H 19 #define QGSVECTORLAYER_H 22 #include "qgis_core.h" 26 #include <QStringList> 60 class QgsGeometryVertexIndex;
390 Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
391 Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
392 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
393 Q_PROPERTY(
QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
394 Q_PROPERTY(
bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
395 Q_PROPERTY(
double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
405 FetchFeatureFailed = 3,
431 bool readExtentFromXml =
false )
432 : loadDefaultStyle( loadDefaultStyle )
433 , readExtentFromXml( readExtentFromXml )
441 bool loadDefaultStyle =
true,
442 bool readExtentFromXml =
false 444 : loadDefaultStyle( loadDefaultStyle )
445 , readExtentFromXml( readExtentFromXml )
446 , transformContext( transformContext )
450 bool loadDefaultStyle =
true;
456 bool readExtentFromXml =
false;
503 bool skipCrsValidation =
false;
520 explicit QgsVectorLayer(
const QString &path = QString(),
const QString &baseName = QString(),
544 QString storageType() const;
549 QString capabilitiesString() const;
554 QString dataComment() const;
563 QString displayField() const;
572 void setDisplayExpression( const QString &displayExpression );
580 QString displayExpression() const;
595 void setProviderEncoding( const QString &encoding );
598 void setCoordinateSystem();
611 bool removeJoin( const QString &joinLayerId );
625 const QList<QgsVectorLayerJoinInfo> vectorJoins()
const;
656 int addExpressionField(
const QString &exp,
const QgsField &fld );
665 void removeExpressionField(
int index );
676 QString expressionField(
int index )
const;
687 void updateExpressionField(
int index,
const QString &exp );
715 int selectedFeatureCount()
const;
765 Q_INVOKABLE
void invertSelection();
768 Q_INVOKABLE
void selectAll();
777 Q_INVOKABLE
void invertSelectionInRectangle(
QgsRectangle &rect );
829 bool labelsEnabled()
const;
840 void setLabelsEnabled(
bool enabled );
847 bool diagramsEnabled()
const;
909 virtual void saveStyleToDatabase(
const QString &name,
const QString &description,
910 bool useAsDefault,
const QString &uiFileContent,
922 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
923 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
928 virtual QString getStyleFromDatabase(
const QString &styleId, QString &msgError SIP_OUT );
937 virtual bool deleteStyleFromDatabase(
const QString &styleId, QString &msgError SIP_OUT );
946 virtual QString
loadNamedStyle(
const QString &theURI,
bool &resultFlag SIP_OUT,
bool loadFromLocalDb,
953 QString
loadNamedStyle(
const QString &theURI,
bool &resultFlag SIP_OUT,
969 bool loadAuxiliaryLayer(
const QgsAuxiliaryStorage &storage,
const QString &key = QString() );
1004 bool readSymbology(
const QDomNode &layerNode, QString &errorMessage,
1015 bool readStyle(
const QDomNode &node, QString &errorMessage,
1027 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1039 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1050 bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsStringMap &props =
QgsStringMap() )
const;
1052 bool readSld(
const QDomNode &node, QString &errorMessage )
FINAL;
1067 QgsFeatureIds symbolFeatureIds(
const QString &legendKey )
const;
1092 Q_DECL_DEPRECATED
void setDataSource(
const QString &dataSource,
const QString &baseName,
const QString &provider,
bool loadDefaultStyleFlag =
false )
SIP_DEPRECATED;
1132 virtual bool setSubsetString(
const QString &subset );
1138 virtual QString subsetString()
const;
1215 bool updateFeature(
QgsFeature &feature,
bool skipDefaultValues =
false );
1228 bool insertVertex(
double x,
double y,
QgsFeatureId atFeatureId,
int beforeVertex );
1253 bool moveVertex(
double x,
double y,
QgsFeatureId atFeatureId,
int atVertex );
1283 Q_INVOKABLE
bool deleteSelectedFeatures(
int *deletedCount =
nullptr );
1426 Q_INVOKABLE
int translateFeature(
QgsFeatureId featureId,
double dx,
double dy );
1516 int addTopologicalPoints(
const QgsGeometry &geom );
1546 int addTopologicalPoints(
const QgsPoint &p );
1577 virtual bool isModified()
const;
1585 bool isAuxiliaryField(
int index,
int &srcIndex )
const;
1628 bool setReadOnly(
bool readonly =
true );
1682 bool changeAttributeValue(
QgsFeatureId fid,
int field,
const QVariant &newValue,
const QVariant &oldValue = QVariant(),
bool skipDefaultValues =
false );
1730 bool addAttribute(
const QgsField &field );
1737 void setFieldAlias(
int index,
const QString &aliasString );
1744 void removeFieldAlias(
int index );
1756 bool renameAttribute(
int index,
const QString &newName );
1764 QString attributeAlias(
int index )
const;
1767 QString attributeDisplayName(
int index )
const;
1800 virtual bool deleteAttribute(
int attr );
1809 bool deleteAttributes(
const QList<int> &attrs );
1857 Q_INVOKABLE
bool commitChanges();
1864 QStringList commitErrors()
const;
1875 Q_INVOKABLE
bool rollBack(
bool deleteBuffer =
true );
1883 QList<QgsRelation> referencingRelations(
int idx )
const;
1891 QList<QgsWeakRelation> weakRelations( )
const SIP_SKIP;
1907 void beginEditCommand(
const QString &text );
1910 void endEditCommand();
1913 void destroyEditCommand();
1937 void updateFields();
1967 void setDefaultValueDefinition(
int index,
const QgsDefaultValue &definition );
1988 QgsFieldConstraints::Constraints fieldConstraints(
int fieldIndex )
const;
1995 QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength(
int fieldIndex )
const;
2023 QString constraintExpression(
int index )
const;
2032 QString constraintDescription(
int index )
const;
2042 void setConstraintExpression(
int index,
const QString &expression,
const QString &description = QString() );
2068 QSet<QVariant>
uniqueValues(
int fieldIndex,
int limit = -1 ) const FINAL;
2083 QStringList uniqueStringsMatching(
int index, const QString &substring,
int limit = -1,
2094 QVariant minimumValue(
int index ) const FINAL;
2104 QVariant maximumValue(
int index ) const FINAL;
2119 const QString &fieldOrExpression,
2126 void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2128 QPainter::CompositionMode featureBlendMode() const;
2137 void setOpacity(
double opacity );
2146 double opacity() const;
2148 QString htmlMetadata() const FINAL;
2197 QString mapTipTemplate()
const;
2206 void setMapTipTemplate(
const QString &mapTipTemplate );
2236 void setReadExtentFromXml(
bool readExtentFromXml );
2245 bool readExtentFromXml()
const;
2299 void setAllowCommit(
bool allowCommit )
SIP_SKIP;
2352 void removeSelection();
2372 virtual void updateExtents(
bool force =
false );
2388 Q_INVOKABLE
bool startEditing();
2413 void layerModified();
2420 void allowCommitChanged();
2423 void beforeModifiedCheck()
const;
2426 void beforeEditingStarted();
2429 void editingStarted();
2432 void editingStopped();
2435 void beforeCommitChanges();
2438 void beforeRollBack();
2444 void afterRollBack();
2454 void attributeAdded(
int idx );
2462 void beforeAddingExpressionField(
const QString &fieldName );
2472 void attributeDeleted(
int idx );
2480 void beforeRemovingExpressionField(
int idx );
2514 void updatedFields();
2520 void subsetStringChanged();
2530 void attributeValueChanged(
QgsFeatureId fid,
int idx,
const QVariant &value );
2542 void committedAttributesDeleted(
const QString &layerId,
const QgsAttributeList &deletedAttributes );
2544 void committedAttributesAdded(
const QString &layerId,
const QList<QgsField> &addedAttributes );
2546 void committedFeaturesAdded(
const QString &layerId,
const QgsFeatureList &addedFeatures );
2548 void committedFeaturesRemoved(
const QString &layerId,
const QgsFeatureIds &deletedFeatureIds );
2550 void committedAttributeValuesChanges(
const QString &layerId,
const QgsChangedAttributesMap &changedAttributesValues );
2552 void committedGeometriesChanges(
const QString &layerId,
const QgsGeometryMap &changedGeometries );
2555 void labelingFontNotFound(
QgsVectorLayer *layer,
const QString &fontfamily );
2558 void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2567 void opacityChanged(
double opacity );
2574 void editCommandStarted(
const QString &text );
2581 void editCommandEnded();
2588 void editCommandDestroyed();
2599 void readCustomSymbology(
const QDomElement &element, QString &errorMessage );
2610 void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage )
const;
2617 void mapTipTemplateChanged();
2624 void displayExpressionChanged();
2629 void raiseError(
const QString &msg );
2636 void editFormConfigChanged();
2644 void readOnlyChanged();
2651 void symbolFeatureCountMapChanged();
2658 void invalidateSymbolCountedFlag();
2659 void onFeatureCounterCompleted();
2660 void onFeatureCounterTerminated();
2661 void onJoinedFieldsChanged();
2663 void onRelationsLoaded();
2664 void onSymbolsCounted();
2665 void onDirtyTransaction(
const QString &sql,
const QString &name );
2666 void emitDataChanged();
2674 bool isReadOnly()
const FINAL;
2684 void readSldLabeling(
const QDomNode &node );
2695 QVariant minimumOrMaximumValue(
int index,
bool minimum )
const;
2705 QString mDisplayExpression;
2707 QString mMapTipTemplate;
2713 bool mReadOnly =
false;
2734 QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2737 QSet<int> mDefaultValueOnUpdateFields;
2740 QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2746 QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2748 QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2754 QSet<QString> mExcludeAttributesWMS;
2757 QSet<QString> mExcludeAttributesWFS;
2772 bool mLabelsEnabled =
false;
2775 bool mLabelFontNotFoundNotified =
false;
2778 QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2781 double mLayerOpacity = 1.0;
2784 bool mVertexMarkerOnlyForSelection =
false;
2786 QStringList mCommitErrors;
2797 std::unique_ptr< QgsVectorLayerServerProperties > mServerProperties;
2808 mutable bool mValidExtent =
false;
2809 mutable bool mLazyExtent =
true;
2812 std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2815 QString mAuxiliaryLayerKey;
2818 bool mSymbolFeatureCounted =
false;
2821 QHash<QString, long> mSymbolFeatureCountMap;
2822 QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2825 bool mEditCommandActive =
false;
2827 bool mReadExtentFromXml;
2834 mutable QMutex mFeatureSourceConstructorMutex;
2838 std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
2840 bool mAllowCommit =
true;
2848 bool mDataChangedFired =
false;
2850 QList<QgsWeakRelation> mWeakRelations;
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
The class is used as a container of context for various read/write operations on other objects...
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
virtual QgsRectangle sourceExtent() const
Returns the extent of all geometries from the source.
A rectangle specified with double values.
Base class for all map layer types.
QSet< QgsFeatureId > QgsFeatureIds
void setExcludeAttributesWms(const QSet< QString > &att)
A set of attributes that are not advertised in WMS requests with QGIS server.
virtual QgsFields fields() const =0
Returns the fields associated with features in the source.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
The QgsGeometryOptions class contains options to automatically adjust geometries to constraints on a ...
Abstract base class for all rendered symbols.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
QSet< QString > excludeAttributesWms() const
A set of attributes that are not advertised in WMS requests with QGIS server.
FeatureAvailability
Possible return value for hasFeatures() to determine if a source is empty.
The QgsDefaultValue class provides a container for managing client side default values for fields...
Constraint
Constraints which may be present on a field.
QSet< QString > excludeAttributesWfs() const
A set of attributes that are not advertised in WFS requests with QGIS server.
Setting options for loading vector layers.
Class allowing to manage the auxiliary storage for a vector layer.
QList< QgsFeature > QgsFeatureList
Counts the features in a QgsVectorLayer in task.
LayerOptions(bool loadDefaultStyle=true, bool readExtentFromXml=false)
Constructor for LayerOptions.
A class to represent a 2D point.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
virtual QgsWkbTypes::Type wkbType() const =0
Returns the geometry type for features returned by this source.
QgsStoredExpressionManager * storedExpressionManager()
Returns the manager of the stored expressions for this layer.
virtual void reload()
Synchronises with changes in the datasource.
VertexMarkerType
Editing vertex markers.
An interface for objects which accept features via addFeature(s) methods.
QgsAbstractVectorLayerLabeling * labeling()
Access to labeling configuration.
Remove from current selection.
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects...
SimplifyHint
Simplification flags for fast rendering of features.
Class providing some utility methods to manage auxiliary storage.
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files...
Container of fields for a vector layer.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer...
A geometry is the spatial representation of a feature.
The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields...
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
bool isEditCommandActive() const
Tests if an edit command is active.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
An interface for classes which can visit style entity (e.g.
QMap< QString, QString > QgsStringMap
OperationResult
Success or failure of a geometry operation.
virtual QgsRectangle extent() const
Returns the extent of the layer.
Manages joined fields for a vector layer.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
const QgsVectorLayerJoinBuffer * joinBuffer() const
Returns a const pointer on join buffer object.
Perform transforms between map coordinates and device coordinates.
void setExcludeAttributesWfs(const QSet< QString > &att)
A set of attributes that are not advertised in WFS requests with QGIS server.
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
LayerOptions(const QgsCoordinateTransformContext &transformContext, bool loadDefaultStyle=true, bool readExtentFromXml=false)
Constructor for LayerOptions.
Type
The WKB type describes the number of dimensions a geometry has.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsMapLayer & operator=(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
QgsFeatureIterator getFeatures(const QString &expression)
Queries the layer for features matching a given expression.
Defines left outer join from our vector layer to some other vector layer.
QMap< int, QVariant > QgsAttributeMap
QgsVectorLayerServerProperties * serverProperties() const
Returns QGIS Server Properties of the vector layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual bool isEditable() const
Returns true if the layer can be edited.
virtual SpatialIndexPresence hasSpatialIndex() const
Returns an enum value representing the presence of a valid spatial index on the source, if it can be determined.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Storage and management of actions associated with a layer.
QgsAttributeList attributeList() const
Returns list of attribute indexes.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr)
Adds a single feature to the sink.
Manages QGIS Server properties for a vector layer.
QgsFeatureRenderer * renderer()
Returns renderer.
Abstract base class for curved geometry type.
Encapsulate a field in an attribute table or data source.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Contains information about the context in which a coordinate transform is executed.
Add selection to current selection.
Point geometry type, with support for z-dimension and m-values.
virtual QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const
Returns the set of unique values contained within the specified fieldIndex from this source...
virtual bool readSld(const QDomNode &node, QString &errorMessage)
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files...
const QgsDiagramRenderer * diagramRenderer() const
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr)=0
Adds a list of features to the sink.
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
Abstract interface for generating an expression context.
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
Set selection, removing any existing selection.
QgsFeatureIterator getFeatures(const QgsRectangle &rectangle)
Queries the layer for the features which intersect the specified rectangle.
Stores the settings for rendering of all diagrams for a layer.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the docment provided.
QVector< QgsPoint > QgsPointSequence
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
Modify current selection to include only select features which match.
SelectBehavior
Selection behavior.
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...
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
virtual QgsExpressionContextScope * createExpressionContextScope() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Buffers information about expression fields for a vector layer.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Abstract interface for generating an expression context scope.
An interface for objects which provide features via a getFeatures method.
const QgsDiagramLayerSettings * diagramLayerSettings() const
ConstraintStrength
Strength of constraints.
This class manages a set of relations between layers.
The QgsConditionalLayerStyles class holds conditional style information for a layer.
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
This class represents a coordinate reference system (CRS).
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Base class for utility classes that encapsulate information necessary for rendering of map layers...
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
SpatialIndexPresence
Enumeration of spatial index presence states.
virtual void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
const QgsFeatureRenderer * renderer() const
Returns const renderer.
QSet< int > QgsAttributeIds
QList< int > QgsAttributeList
bool nextFeature(QgsFeature &f)
This is a container for configuration of the attribute table.
This is the base class for vector data providers.
virtual QString sourceName() const =0
Returns a friendly display name for the source.
QList< int > QgsAttributeList
QgsCoordinateReferenceSystem fallbackCrs
Fallback layer coordinate reference system.
const QgsActionManager * actions() const
Returns all layer actions defined on this layer.
Represents a vector layer which manages a vector based data sets.
virtual FeatureAvailability hasFeatures() const
Determines if there are any features available in the source.
const QgsVectorLayerEditBuffer * editBuffer() const
Buffer with uncommitted editing operations.
EditResult
Result of an edit operation.
QgsFeatureIterator getFeatures(const QgsFeatureIds &fids)
Queries the layer for the features with the given ids.
Constraint must be honored before feature can be accepted.
Manages stored expressions regarding creation, modification and storing in the project.
Abstract base class for simplify geometries using a specific algorithm.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown...
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.