18 #ifndef QGSVECTORLAYER_H
19 #define QGSVECTORLAYER_H
22 #include "qgis_core.h"
26 #include <QStringList>
60 class QgsGeometryVertexIndex;
389 Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
390 Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
391 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
392 Q_PROPERTY(
QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
393 Q_PROPERTY(
bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
394 Q_PROPERTY(
double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
404 FetchFeatureFailed = 3,
417 Q_ENUM( SelectBehavior )
430 bool readExtentFromXml =
false )
431 : loadDefaultStyle( loadDefaultStyle )
432 , readExtentFromXml( readExtentFromXml )
440 bool loadDefaultStyle =
true,
441 bool readExtentFromXml =
false
443 : loadDefaultStyle( loadDefaultStyle )
444 , readExtentFromXml( readExtentFromXml )
445 , transformContext( transformContext )
449 bool loadDefaultStyle =
true;
455 bool readExtentFromXml =
false;
502 bool skipCrsValidation =
false;
518 QList<QgsVectorLayer *> handledLayers()
const;
521 QMap<QgsVectorLayer *, QgsFeatureIds> mHandledFeatures
SIP_SKIP;
539 explicit QgsVectorLayer(
const QString &path = QString(),
const QString &baseName = QString(),
563 QString storageType() const;
568 QString capabilitiesString() const;
573 QString dataComment() const;
582 QString displayField() const;
591 void setDisplayExpression( const QString &displayExpression );
599 QString displayExpression() const;
619 void setProviderEncoding( const QString &encoding );
622 void setCoordinateSystem();
635 bool removeJoin( const QString &joinLayerId );
649 const QList<QgsVectorLayerJoinInfo> vectorJoins()
const;
659 bool setDependencies(
const QSet<QgsMapLayerDependency> &layers )
FINAL;
668 QSet<QgsMapLayerDependency> dependencies() const
FINAL;
680 int addExpressionField( const QString &exp, const
QgsField &fld );
689 void removeExpressionField(
int index );
700 QString expressionField(
int index ) const;
711 void updateExpressionField(
int index, const QString &exp );
739 int selectedFeatureCount()
const;
789 Q_INVOKABLE
void invertSelection();
792 Q_INVOKABLE
void selectAll();
801 Q_INVOKABLE
void invertSelectionInRectangle(
QgsRectangle &rect );
853 bool labelsEnabled()
const;
864 void setLabelsEnabled(
bool enabled );
871 bool diagramsEnabled()
const;
902 QString sourceName() const
FINAL;
917 QString decodedSource( const QString &source, const QString &provider, const
QgsReadWriteContext &context ) const
FINAL;
933 virtual
void saveStyleToDatabase( const QString &name, const QString &description,
934 bool useAsDefault, const QString &uiFileContent,
946 virtual
int listStylesInDatabase( QStringList &ids
SIP_OUT, QStringList &names
SIP_OUT,
952 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError
SIP_OUT );
961 virtual
bool deleteStyleFromDatabase( const QString &styleId, QString &msgError
SIP_OUT );
970 virtual QString loadNamedStyle( const QString &theURI,
bool &resultFlag
SIP_OUT,
bool loadFromLocalDb,
977 QString loadNamedStyle( const QString &theURI,
bool &resultFlag
SIP_OUT,
993 bool loadAuxiliaryLayer( const
QgsAuxiliaryStorage &storage, const QString &key = QString() );
1028 bool readSymbology( const QDomNode &layerNode, QString &errorMessage,
1039 bool readStyle( const QDomNode &node, QString &errorMessage,
1051 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1063 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1074 bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const
QgsStringMap &props =
QgsStringMap() ) const;
1076 bool readSld( const QDomNode &node, QString &errorMessage )
FINAL;
1083 long featureCount( const QString &legendKey ) const;
1091 QgsFeatureIds symbolFeatureIds( const QString &legendKey ) const;
1103 FeatureAvailability hasFeatures() const
FINAL;
1116 Q_DECL_DEPRECATED
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
bool loadDefaultStyleFlag = false )
SIP_DEPRECATED;
1130 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const
QgsDataProvider::ProviderOptions &options,
bool loadDefaultStyleFlag = false ) override;
1132 QString loadDefaultStyle(
bool &resultFlag
SIP_OUT )
FINAL;
1156 virtual
bool setSubsetString( const QString &subset );
1162 virtual QString subsetString() const;
1212 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
FINAL;
1239 bool updateFeature(
QgsFeature &feature,
bool skipDefaultValues = false );
1252 bool insertVertex(
double x,
double y,
QgsFeatureId atFeatureId,
int beforeVertex );
1277 bool moveVertex(
double x,
double y,
QgsFeatureId atFeatureId,
int atVertex );
1301 EditResult deleteVertex(
QgsFeatureId featureId,
int vertex );
1310 Q_INVOKABLE
bool deleteSelectedFeatures(
int *deletedCount =
nullptr, DeleteContext *context =
nullptr );
1462 Q_INVOKABLE
int translateFeature(
QgsFeatureId featureId,
double dx,
double dy );
1560 int addTopologicalPoints( const
QgsGeometry &geom );
1590 int addTopologicalPoints( const
QgsPoint &p );
1615 bool isEditable() const
FINAL;
1618 bool isSpatial() const
FINAL;
1621 virtual
bool isModified() const;
1629 bool isAuxiliaryField(
int index,
int &srcIndex ) const;
1632 void reload()
FINAL;
1666 long featureCount() const
FINAL;
1672 bool setReadOnly(
bool readonly = true );
1726 bool changeAttributeValue(
QgsFeatureId fid,
int field, const QVariant &newValue, const QVariant &oldValue = QVariant(),
bool skipDefaultValues = false );
1774 bool addAttribute( const
QgsField &field );
1781 void setFieldAlias(
int index, const QString &aliasString );
1788 void removeFieldAlias(
int index );
1800 bool renameAttribute(
int index, const QString &newName );
1808 QString attributeAlias(
int index ) const;
1811 QString attributeDisplayName(
int index ) const;
1819 QSet<QString> excludeAttributesWms()
const {
return mExcludeAttributesWMS; }
1844 virtual bool deleteAttribute(
int attr );
1853 bool deleteAttributes(
const QList<int> &attrs );
1855 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
FINAL;
1867 bool deleteFeature(
QgsFeatureId fid, DeleteContext *context =
nullptr );
1882 bool deleteFeatures( const
QgsFeatureIds &fids, DeleteContext *context =
nullptr );
1904 Q_INVOKABLE
bool commitChanges();
1911 QStringList commitErrors() const;
1922 Q_INVOKABLE
bool rollBack(
bool deleteBuffer = true );
1930 QList<
QgsRelation> referencingRelations(
int idx ) const;
1954 void beginEditCommand(
const QString &text );
1957 void endEditCommand();
1960 void destroyEditCommand();
1984 void updateFields();
2014 void setDefaultValueDefinition(
int index,
const QgsDefaultValue &definition );
2035 QgsFieldConstraints::Constraints fieldConstraints(
int fieldIndex )
const;
2042 QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength(
int fieldIndex )
const;
2070 QString constraintExpression(
int index )
const;
2079 QString constraintDescription(
int index )
const;
2089 void setConstraintExpression(
int index,
const QString &expression,
const QString &description = QString() );
2115 QSet<QVariant> uniqueValues(
int fieldIndex,
int limit = -1 ) const
FINAL;
2130 QStringList uniqueStringsMatching(
int index, const QString &substring,
int limit = -1,
2141 QVariant minimumValue(
int index ) const
FINAL;
2151 QVariant maximumValue(
int index ) const
FINAL;
2166 const QString &fieldOrExpression,
2173 void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2175 QPainter::CompositionMode featureBlendMode() const;
2184 void setOpacity(
double opacity );
2193 double opacity() const;
2195 QString htmlMetadata() const
FINAL;
2244 QString mapTipTemplate()
const;
2253 void setMapTipTemplate(
const QString &mapTipTemplate );
2283 void setReadExtentFromXml(
bool readExtentFromXml );
2292 bool readExtentFromXml() const;
2299 bool isEditCommandActive()
const {
return mEditCommandActive; }
2344 void setAllowCommit(
bool allowCommit )
SIP_SKIP;
2389 Q_INVOKABLE
void deselect(
const QgsFeatureIds &featureIds );
2397 Q_INVOKABLE
void removeSelection();
2417 virtual void updateExtents(
bool force =
false );
2433 Q_INVOKABLE
bool startEditing();
2442 SpatialIndexPresence hasSpatialIndex()
const override;
2458 void layerModified();
2465 void allowCommitChanged();
2468 void beforeModifiedCheck()
const;
2471 void beforeEditingStarted();
2474 void editingStarted();
2477 void editingStopped();
2480 void beforeCommitChanges();
2483 void beforeRollBack();
2489 void afterRollBack();
2499 void attributeAdded(
int idx );
2507 void beforeAddingExpressionField(
const QString &fieldName );
2517 void attributeDeleted(
int idx );
2525 void beforeRemovingExpressionField(
int idx );
2559 void updatedFields();
2565 void subsetStringChanged();
2575 void attributeValueChanged(
QgsFeatureId fid,
int idx,
const QVariant &value );
2587 void committedAttributesDeleted(
const QString &layerId,
const QgsAttributeList &deletedAttributes );
2589 void committedAttributesAdded(
const QString &layerId,
const QList<QgsField> &addedAttributes );
2591 void committedFeaturesAdded(
const QString &layerId,
const QgsFeatureList &addedFeatures );
2593 void committedFeaturesRemoved(
const QString &layerId,
const QgsFeatureIds &deletedFeatureIds );
2595 void committedAttributeValuesChanges(
const QString &layerId,
const QgsChangedAttributesMap &changedAttributesValues );
2597 void committedGeometriesChanges(
const QString &layerId,
const QgsGeometryMap &changedGeometries );
2600 void labelingFontNotFound(
QgsVectorLayer *layer,
const QString &fontfamily );
2603 void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2612 void opacityChanged(
double opacity );
2619 void editCommandStarted(
const QString &text );
2626 void editCommandEnded();
2633 void editCommandDestroyed();
2644 void readCustomSymbology(
const QDomElement &element, QString &errorMessage );
2655 void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage )
const;
2662 void mapTipTemplateChanged();
2669 void displayExpressionChanged();
2674 void raiseError(
const QString &msg );
2681 void editFormConfigChanged();
2689 void readOnlyChanged();
2696 void symbolFeatureCountMapChanged();
2703 void invalidateSymbolCountedFlag();
2704 void onFeatureCounterCompleted();
2705 void onFeatureCounterTerminated();
2706 void onJoinedFieldsChanged();
2708 void onRelationsLoaded();
2709 void onSymbolsCounted();
2710 void onDirtyTransaction(
const QString &sql,
const QString &name );
2711 void emitDataChanged();
2719 bool isReadOnly() const
FINAL;
2726 bool setDataProvider( QString const &provider, const
QgsDataProvider::ProviderOptions &options );
2729 void readSldLabeling( const QDomNode &node );
2737 bool deleteFeatureCascade(
QgsFeatureId fid, DeleteContext *context =
nullptr );
2742 QVariant minimumOrMaximumValue(
int index,
bool minimum )
const;
2755 QString mDisplayExpression;
2757 QString mMapTipTemplate;
2763 bool mReadOnly =
false;
2784 QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2787 QSet<int> mDefaultValueOnUpdateFields;
2790 QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2796 QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2798 QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2804 QSet<QString> mExcludeAttributesWMS;
2807 QSet<QString> mExcludeAttributesWFS;
2822 bool mLabelsEnabled =
false;
2825 bool mLabelFontNotFoundNotified =
false;
2828 QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2831 double mLayerOpacity = 1.0;
2834 bool mVertexMarkerOnlyForSelection =
false;
2836 QStringList mCommitErrors;
2847 std::unique_ptr< QgsVectorLayerServerProperties > mServerProperties;
2858 mutable bool mValidExtent =
false;
2859 mutable bool mLazyExtent =
true;
2862 std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2865 QString mAuxiliaryLayerKey;
2868 bool mSymbolFeatureCounted =
false;
2871 QHash<QString, long> mSymbolFeatureCountMap;
2872 QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2875 bool mEditCommandActive =
false;
2877 bool mReadExtentFromXml;
2884 mutable QMutex mFeatureSourceConstructorMutex;
2888 std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
2890 bool mAllowCommit =
true;
2898 bool mDataChangedFired =
false;
2900 QList<QgsWeakRelation> mWeakRelations;