18 #ifndef QGSVECTORLAYER_H
19 #define QGSVECTORLAYER_H
22 #include "qgis_core.h"
26 #include <QStringList>
60 class QgsGeometryVertexIndex;
395 Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
396 Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
397 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
398 Q_PROPERTY(
QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
399 Q_PROPERTY(
bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
400 Q_PROPERTY(
bool supportsEditing READ supportsEditing NOTIFY supportsEditingChanged )
415 bool readExtentFromXml =
false )
416 : loadDefaultStyle( loadDefaultStyle )
417 , readExtentFromXml( readExtentFromXml )
425 bool loadDefaultStyle =
true,
426 bool readExtentFromXml =
false
428 : loadDefaultStyle( loadDefaultStyle )
429 , readExtentFromXml( readExtentFromXml )
430 , transformContext( transformContext )
434 bool loadDefaultStyle =
true;
440 bool readExtentFromXml =
false;
487 bool skipCrsValidation =
false;
509 QList<QgsVectorLayer *> handledLayers(
bool includeAuxiliaryLayers =
true )
const;
516 QMap<QgsVectorLayer *, QgsFeatureIds> mHandledFeatures
SIP_SKIP;
534 explicit QgsVectorLayer(
const QString &path = QString(),
const QString &baseName = QString(),
545 SIP_PYOBJECT __repr__();
547 QString
str = QStringLiteral(
"<QgsVectorLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral(
"Invalid" ) );
548 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
566 QString storageType() const;
571 QString capabilitiesString() const;
583 bool isSqlQuery() const;
591 Qgis::VectorLayerTypeFlags vectorLayerTypeFlags() const;
597 QString dataComment() const;
606 QString displayField() const;
615 void setDisplayExpression( const QString &displayExpression );
623 QString displayExpression() const;
641 void setProviderEncoding( const QString &encoding );
644 void setCoordinateSystem();
657 bool removeJoin( const QString &joinLayerId );
671 const QList<QgsVectorLayerJoinInfo> vectorJoins()
const;
681 bool setDependencies(
const QSet<QgsMapLayerDependency> &layers )
FINAL;
690 QSet<QgsMapLayerDependency> dependencies() const
FINAL;
702 int addExpressionField( const QString &exp, const
QgsField &fld );
711 void removeExpressionField(
int index );
722 QString expressionField(
int index ) const;
733 void updateExpressionField(
int index, const QString &exp );
755 int selectedFeatureCount()
const;
806 Q_INVOKABLE
void invertSelection();
809 Q_INVOKABLE
void selectAll();
818 Q_INVOKABLE
void invertSelectionInRectangle(
QgsRectangle &rect );
870 bool labelsEnabled()
const;
881 void setLabelsEnabled(
bool enabled );
888 bool diagramsEnabled()
const;
942 void removeFeatureRendererGenerator(
const QString &
id );
951 QList< const QgsFeatureRendererGenerator * > featureRendererGenerators()
const;
960 QString sourceName() const
FINAL;
975 QString decodedSource( const QString &source, const QString &provider, const
QgsReadWriteContext &context ) const
FINAL;
999 virtual
void saveStyleToDatabase( const QString &name, const QString &description,
1000 bool useAsDefault, const QString &uiFileContent,
1013 virtual
int listStylesInDatabase( QStringList &ids
SIP_OUT, QStringList &names
SIP_OUT,
1019 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError
SIP_OUT );
1028 virtual
bool deleteStyleFromDatabase( const QString &styleId, QString &msgError
SIP_OUT );
1037 virtual QString loadNamedStyle( const QString &theURI,
bool &resultFlag
SIP_OUT,
bool loadFromLocalDb,
1044 QString loadNamedStyle( const QString &theURI,
bool &resultFlag
SIP_OUT,
1060 bool loadAuxiliaryLayer( const
QgsAuxiliaryStorage &storage, const QString &key = QString() );
1087 bool readSymbology( const QDomNode &layerNode, QString &errorMessage,
1089 bool readStyle( const QDomNode &node, QString &errorMessage,
1091 bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1093 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1104 bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
1106 bool readSld( const QDomNode &node, QString &errorMessage )
FINAL;
1113 long long featureCount( const QString &legendKey ) const;
1121 QgsFeatureIds symbolFeatureIds( const QString &legendKey ) const;
1133 FeatureAvailability hasFeatures() const
FINAL;
1136 QString loadDefaultStyle(
bool &resultFlag
SIP_OUT )
FINAL;
1160 virtual
bool setSubsetString( const QString &subset );
1166 virtual QString subsetString() const;
1216 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
FINAL;
1243 bool updateFeature(
QgsFeature &feature,
bool skipDefaultValues = false );
1256 bool insertVertex(
double x,
double y,
QgsFeatureId atFeatureId,
int beforeVertex );
1281 bool moveVertex(
double x,
double y,
QgsFeatureId atFeatureId,
int atVertex );
1314 Q_INVOKABLE
bool deleteSelectedFeatures(
int *deletedCount =
nullptr,
QgsVectorLayer::DeleteContext *context =
nullptr );
1403 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1469 Q_INVOKABLE
int translateFeature(
QgsFeatureId featureId,
double dx,
double dy );
1512 Q_INVOKABLE
Qgis::GeometryOperationResult splitParts( const
QgsPointSequence &splitLine,
bool topologicalEditing = false );
1534 Q_DECL_DEPRECATED
Qgis::GeometryOperationResult splitFeatures( const QVector<
QgsPointXY> &splitLine,
bool topologicalEditing = false )
SIP_DEPRECATED;
1555 Q_INVOKABLE
Qgis::GeometryOperationResult splitFeatures( const
QgsPointSequence &splitLine,
bool topologicalEditing = false );
1579 Q_INVOKABLE
Qgis::GeometryOperationResult splitFeatures( const
QgsCurve *curve,
QgsPointSequence &topologyTestPoints
SIP_OUT,
bool preserveCircular = false,
bool topologicalEditing = false );
1594 int addTopologicalPoints( const
QgsGeometry &geom );
1630 int addTopologicalPoints( const
QgsPoint &p );
1673 bool isEditable() const
FINAL;
1676 bool isSpatial() const
FINAL;
1679 bool isModified() const override;
1687 bool isAuxiliaryField(
int index,
int &srcIndex ) const;
1690 void reload()
FINAL;
1724 long long featureCount() const
FINAL;
1730 bool setReadOnly(
bool readonly = true );
1737 bool supportsEditing() const override;
1791 bool changeAttributeValue(
QgsFeatureId fid,
int field, const QVariant &newValue, const QVariant &oldValue = QVariant(),
bool skipDefaultValues = false );
1846 void setFieldAlias(
int index, const QString &aliasString );
1853 void removeFieldAlias(
int index );
1865 bool renameAttribute(
int index, const QString &newName );
1873 QString attributeAlias(
int index ) const;
1876 QString attributeDisplayName(
int index ) const;
1885 Q_DECL_DEPRECATED QSet<QString> excludeAttributesWms() const
SIP_DEPRECATED;
1891 Q_DECL_DEPRECATED
void setExcludeAttributesWms( const QSet<QString> &att )
SIP_DEPRECATED;
1897 Q_DECL_DEPRECATED QSet<QString> excludeAttributesWfs() const
SIP_DEPRECATED;
1903 Q_DECL_DEPRECATED
void setExcludeAttributesWfs( const QSet<QString> &att )
SIP_DEPRECATED;
1913 virtual
bool deleteAttribute(
int attr );
1922 bool deleteAttributes( const QList<
int> &attrs );
1936 bool deleteFeature(
QgsFeatureId fid, DeleteContext *context =
nullptr );
1951 bool deleteFeatures( const
QgsFeatureIds &fids, DeleteContext *context =
nullptr );
1976 Q_INVOKABLE
bool commitChanges(
bool stopEditing = true );
1983 QStringList commitErrors() const;
1994 Q_INVOKABLE
bool rollBack(
bool deleteBuffer = true );
2002 QList<
QgsRelation> referencingRelations(
int idx ) const;
2026 void beginEditCommand(
const QString &text );
2029 void endEditCommand();
2032 void destroyEditCommand();
2038 Q_DECL_DEPRECATED
static void drawVertexMarker(
double x,
double y, QPainter &p,
Qgis::VertexMarkerType type,
int vertexSize );
2048 void updateFields();
2078 void setDefaultValueDefinition(
int index,
const QgsDefaultValue &definition );
2099 QgsFieldConstraints::Constraints fieldConstraints(
int fieldIndex )
const;
2106 QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength(
int fieldIndex )
const;
2134 QString constraintExpression(
int index )
const;
2143 QString constraintDescription(
int index )
const;
2153 void setConstraintExpression(
int index,
const QString &expression,
const QString &description = QString() );
2160 void setFieldConfigurationFlags(
int index, QgsField::ConfigurationFlags flags )
SIP_SKIP;
2173 QgsField::ConfigurationFlags fieldConfigurationFlags(
int index )
const SIP_SKIP;
2199 QSet<QVariant> uniqueValues(
int fieldIndex,
int limit = -1 ) const
FINAL;
2214 QStringList uniqueStringsMatching(
int index, const QString &substring,
int limit = -1,
2231 QVariant minimumValue(
int index ) const
FINAL;
2247 QVariant maximumValue(
int index ) const
FINAL;
2269 void minimumAndMaximumValue(
int index, QVariant &minimum
SIP_OUT, QVariant &maximum
SIP_OUT ) const;
2286 const QString &fieldOrExpression,
2295 void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2297 QPainter::CompositionMode featureBlendMode() const;
2299 QString htmlMetadata() const
FINAL;
2348 QString mapTipTemplate()
const;
2357 void setMapTipTemplate(
const QString &mapTipTemplate );
2387 void setReadExtentFromXml(
bool readExtentFromXml );
2396 bool readExtentFromXml() const;
2403 bool isEditCommandActive()
const {
return mEditCommandActive; }
2448 void setAllowCommit(
bool allowCommit )
SIP_SKIP;
2493 Q_INVOKABLE
void deselect(
const QgsFeatureIds &featureIds );
2501 Q_INVOKABLE
void removeSelection();
2521 virtual void updateExtents(
bool force =
false );
2537 Q_INVOKABLE
bool startEditing();
2566 void allowCommitChanged();
2569 void beforeModifiedCheck()
const;
2572 void beforeEditingStarted();
2579 void beforeCommitChanges(
bool stopEditing );
2582 void beforeRollBack();
2588 void afterCommitChanges();
2594 void afterRollBack();
2604 void attributeAdded(
int idx );
2612 void beforeAddingExpressionField(
const QString &fieldName );
2622 void attributeDeleted(
int idx );
2630 void beforeRemovingExpressionField(
int idx );
2664 void updatedFields();
2670 void subsetStringChanged();
2680 void attributeValueChanged(
QgsFeatureId fid,
int idx,
const QVariant &value );
2692 void committedAttributesDeleted(
const QString &layerId,
const QgsAttributeList &deletedAttributes );
2694 void committedAttributesAdded(
const QString &layerId,
const QList<QgsField> &addedAttributes );
2696 void committedFeaturesAdded(
const QString &layerId,
const QgsFeatureList &addedFeatures );
2698 void committedFeaturesRemoved(
const QString &layerId,
const QgsFeatureIds &deletedFeatureIds );
2700 void committedAttributeValuesChanges(
const QString &layerId,
const QgsChangedAttributesMap &changedAttributesValues );
2702 void committedGeometriesChanges(
const QString &layerId,
const QgsGeometryMap &changedGeometries );
2705 void labelingFontNotFound(
QgsVectorLayer *layer,
const QString &fontfamily );
2708 void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2715 void editCommandStarted(
const QString &text );
2722 void editCommandEnded();
2729 void editCommandDestroyed();
2740 void readCustomSymbology(
const QDomElement &element, QString &errorMessage );
2751 void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage )
const;
2758 void mapTipTemplateChanged();
2765 void displayExpressionChanged();
2770 void raiseError(
const QString &msg );
2777 void editFormConfigChanged();
2785 void readOnlyChanged();
2792 void supportsEditingChanged();
2799 void symbolFeatureCountMapChanged();
2806 void invalidateSymbolCountedFlag();
2807 void onFeatureCounterCompleted();
2808 void onFeatureCounterTerminated();
2809 void onJoinedFieldsChanged();
2811 void onRelationsLoaded();
2812 void onSymbolsCounted();
2813 void onDirtyTransaction(
const QString &sql,
const QString &name );
2814 void emitDataChanged();
2815 void onAfterCommitChangesDependency();
2823 bool isReadOnly() const
FINAL;
2844 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const
QgsDataProvider::ProviderOptions &options,
QgsDataProvider::ReadFlags flags ) override;
2847 void readSldLabeling( const QDomNode &node );
2855 bool deleteFeatureCascade(
QgsFeatureId fid, DeleteContext *context =
nullptr );
2860 void minimumOrMaximumValue(
int index, QVariant *minimum, QVariant *maximum )
const;
2863 void createEditBuffer();
2864 void clearEditBuffer();
2877 QString mDisplayExpression;
2879 QString mMapTipTemplate;
2885 bool mReadOnly =
false;
2906 QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2909 QSet<int> mDefaultValueOnUpdateFields;
2912 QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2918 QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2920 QMap< QString, QgsField::ConfigurationFlags > mFieldConfigurationFlags;
2921 QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2939 bool mLabelsEnabled =
false;
2942 bool mLabelFontNotFoundNotified =
false;
2945 QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2948 bool mVertexMarkerOnlyForSelection =
false;
2950 QStringList mCommitErrors;
2970 mutable bool mValidExtent =
false;
2971 mutable bool mLazyExtent =
true;
2974 std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2977 QString mAuxiliaryLayerKey;
2980 bool mSymbolFeatureCounted =
false;
2983 QHash<QString, long long> mSymbolFeatureCountMap;
2984 QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2987 bool mEditCommandActive =
false;
2990 bool mCommitChangesActive =
false;
2992 bool mReadExtentFromXml;
2999 mutable QMutex mFeatureSourceConstructorMutex;
3003 std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
3005 bool mAllowCommit =
true;
3013 bool mDataChangedFired =
false;
3015 QList<QgsWeakRelation> mWeakRelations;
3017 bool mSetLegendFromStyle =
false;
3019 QList< QgsFeatureRendererGenerator * > mRendererGenerators;
3022 QTimer *mRefreshRendererTimer =
nullptr;