34 , mSavePointId( ( mBuffer->L->isEditCommandActive() && !mBuffer->L->dataProvider()->transaction()->savePoints().isEmpty() )
36 ? mBuffer->L->dataProvider()->transaction()->savePoints().last()
37 : mBuffer->L->dataProvider()->transaction()->createSavepoint( mError ) )
38 , mHasError( !mError.isEmpty() )
39 , mRecreateSavePoint( mBuffer->L->isEditCommandActive()
40 ? !mBuffer->L->dataProvider()->transaction()->lastSavePointIsDirty()
53 setText( text() +
" " + QObject::tr(
"failed" ) );
72 if ( savePointId.isEmpty() )
78 if ( mSavePointId.isEmpty() )
86 mSavePointId = savePointId;
109 static int sAddedIdLowWaterMark = -1;
110 for (
const QgsFeature &f : qgis::as_const( features ) )
112 mInitialFeatures << f;
114 sAddedIdLowWaterMark--;
115 mInitialFeatures.last().setId( sAddedIdLowWaterMark );
117 mFeatures = mInitialFeatures;
124 for (
const QgsFeature &f : qgis::as_const( mFeatures ) )
128 mFeatures = mInitialFeatures;
134 mFeatures = mInitialFeatures;
137 for (
const QgsFeature &f : qgis::as_const( mFeatures ) )
184 , mOldGeom(
mBuffer->L->getFeature( mFid ).geometry() )
199 geomMap.insert( mFid, mNewGeom );
214 , mNewValue( newValue )
215 , mOldValue(
mBuffer->L->getFeature( mFid ).attribute( field ) )
230 map.insert( mField, mNewValue );
232 attribMap.insert( mFid, map );
281 , mField(
mBuffer->L->fields()[ attr ] )
318 , mNewName( newName )
319 , mOldName(
mBuffer->L->fields()[ mAttr ].name() )
328 map[ mAttr ] = mOldName;
343 map[ mAttr ] = mNewName;
357 , mTransaction( transaction )
385 if ( errorMessage.isEmpty() )
389 if ( mTransaction->
executeSql( mSql, errorMessage ) )
410 , mNewValues( newValues )
411 , mOldValues( oldValues )
419 for (
auto it = mNewValues.constBegin(); it != mNewValues.constEnd(); ++it )
429 attribMap.insert( mFid, mNewValues );
432 for (
auto it = mNewValues.constBegin(); it != mNewValues.constEnd(); ++it )
QgsVectorLayerUndoPassthroughCommandAddAttribute(QgsVectorLayerEditBuffer *buffer, const QgsField &field)
Constructor for QgsVectorLayerUndoPassthroughCommandAddAttribute.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
void setErrorMessage(const QString &errorMessage)
Sets the error message.
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
QSet< QgsFeatureId > QgsFeatureIds
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
void attributeDeleted(int idx)
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink.
QList< QgsFeature > QgsFeatureList
void setError()
Set error flag and append "failed" to text.
bool setSavePoint(const QString &savePointId=QString())
Set the command savepoint or set error status.
QgsVectorLayerUndoPassthroughCommandDeleteAttribute(QgsVectorLayerEditBuffer *buffer, int attr)
Constructor for QgsVectorLayerUndoCommandDeleteAttribute.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
QgsVectorLayerEditBuffer * mBuffer
Associated edit buffer.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
Base class for undo commands within a QgsVectorLayerEditBuffer.
A geometry is the spatial representation of a feature.
Undo command for vector layer in transaction group mode.
bool rollbackToSavepoint(const QString &name, QString &error)
rollback to save point, the save point is maintained and is "undertied"
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
QgsVectorLayerUndoPassthroughCommand(QgsVectorLayerEditBuffer *buffer, const QString &text, bool autocreate=true)
Constructor for QgsVectorLayerUndoPassthroughCommand.
void featureAdded(QgsFeatureId fid)
QSet< int > QgsAttributeIds
QgsVectorLayerUndoPassthroughCommandAddFeatures(QgsVectorLayerEditBuffer *buffer, QgsFeatureList &features)
Constructor for QgsVectorLayerUndoPassthroughCommandAddFeatures.
void attributeAdded(int idx)
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
QMap< int, QVariant > QgsAttributeMap
bool rollBackToSavePoint()
Rollback command, release savepoint or set error status save point must be set prior to call error sa...
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
Encapsulate a field in an attribute table or data source.
QgsVectorLayerUndoPassthroughCommandChangeGeometry(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, const QgsGeometry &geom)
Constructor for QgsVectorLayerUndoPassthroughCommandChangeGeometry.
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
void attributeRenamed(int idx, const QString &newName)
Emitted when an attribute has been renamed.
QMap< int, QString > QgsFieldNameMap
QgsVectorLayerUndoPassthroughCommandUpdate(QgsVectorLayerEditBuffer *buffer, QgsTransaction *transaction, const QString &sql, const QString &name)
Constructor for QgsVectorLayerUndoCommandUpdate.
QgsVectorLayerUndoPassthroughCommandDeleteFeatures(QgsVectorLayerEditBuffer *buffer, const QgsFeatureIds &fids)
Constructor for QgsVectorLayerUndoPassthroughCommandDeleteFeatures.
bool hasError() const
Returns error status.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
This class allows including a set of layers in a database-side transaction, provided the layer data p...
QgsVectorLayerUndoPassthroughCommandChangeAttribute(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, int field, const QVariant &newValue)
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttribute.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
QgsVectorLayerUndoPassthroughCommandRenameAttribute(QgsVectorLayerEditBuffer *buffer, int attr, const QString &newName)
Constructor for QgsVectorLayerUndoCommandRenameAttribute.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
QgsVectorLayerUndoPassthroughCommandChangeAttributes(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttributes.
QString errorMessage() const
Returns the error message or an empty string if there's none.
void layerModified()
Emitted when modifications has been done on layer.
QList< QString > savePoints() const
returns savepoints
void featureDeleted(QgsFeatureId fid)