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;
112 mInitialFeatures << f;
114 sAddedIdLowWaterMark--;
115 mInitialFeatures.last().setId( sAddedIdLowWaterMark );
117 mFeatures = mInitialFeatures;
125 for (
const QgsFeature &f : std::as_const( mFeatures ) )
130 mFeatures = mInitialFeatures;
136 mFeatures = mInitialFeatures;
140 for (
const QgsFeature &f : std::as_const( mFeatures ) )
165 if ( mDeletedNewFeatures.contains( fid ) )
179 mDeletedNewFeatures.clear();
204 , mOldGeom( mBuffer->L->getFeature( mFid ).geometry() )
205 , mFirstChange( true )
209 mFirstChange =
false;
213 mFirstChange =
false;
226 else if ( mFirstChange )
241 geomMap.insert( mFid, mNewGeom );
263 if ( other->id() !=
id() )
270 if ( merge->mFid != mFid )
273 mNewGeom = merge->mNewGeom;
284 , mFieldIndex(
field )
285 , mNewValue( newValue )
286 , mOldValue( mBuffer->L->getFeature( mFid ).attribute(
field ) )
287 , mFirstChange( true )
295 if ( it.value().attribute( mFieldIndex ).isValid() )
297 mOldValue = it.value().attribute( mFieldIndex );
298 mFirstChange =
false;
304 mFirstChange =
false;
312 QVariant original = mOldValue;
319 it.value().setAttribute( mFieldIndex, mOldValue );
321 else if ( mFirstChange )
328 if ( !mOldValue.isValid() )
336 std::unique_ptr<QgsVectorLayer> layerClone(
layer()->clone() );
353 map.insert( mFieldIndex, mNewValue );
355 attribMap.insert( mFid, map );
363 it.value().setAttribute( mFieldIndex, mNewValue );
425 , mField( mBuffer->L->fields()[ attr ] )
426 , mOriginalFieldIndex( attr )
465 , mNewName( newName )
466 , mOldName( mBuffer->L->fields()[ mAttr ].name() )
475 map[ mAttr ] = mOldName;
491 map[ mAttr ] = mNewName;
506 , mTransaction( transaction )
559 , mNewValues( newValues )
560 , mOldValues( oldValues )
562 if ( mOldValues.isEmpty() )
565 for (
auto it = mNewValues.constBegin(); it != mNewValues.constEnd(); ++it )
567 mOldValues[ it.key() ] = oldAttrs[ it.key() ];
571 for (
auto it = mNewValues.constBegin(); it != mNewValues.constEnd(); ++it )
575 mFirstChanges[ it.key() ] =
false;
579 mFirstChanges[ it.key() ] =
false;
583 mFirstChanges[ it.key() ] =
true;
593 for (
auto it = mNewValues.constBegin(); it != mNewValues.constEnd(); ++it )
595 const auto fieldIndex { it.key() };
598 addedIt.value().setAttribute( fieldIndex, mOldValues[ it.key() ] );
600 else if ( mFirstChanges.contains( fieldIndex ) && mFirstChanges[ fieldIndex ] )
624 attribMap.insert( mFid, mNewValues );
629 for (
auto it = mNewValues.constBegin(); it != mNewValues.constEnd(); ++it )
631 const auto fieldIndex { it.key() };
635 addedIt.value().setAttribute( fieldIndex, it.value() );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Encapsulate a field in an attribute table or data source.
A geometry is the spatial representation of a feature.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
QList< QString > savePoints() const
returns savepoints
bool rollbackToSavepoint(const QString &name, QString &error)
rollback to save point, the save point is maintained and is "undertied"
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
void clearErrors()
Clear recorded errors.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features to the sink.
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
bool hasErrors() const
Provider has errors to report.
void attributeRenamed(int idx, const QString &newName)
Emitted when an attribute has been renamed.
QgsFeatureMap mAddedFeatures
New features which are not committed.
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not committed. The list is kept sorted.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed.
void featureDeleted(QgsFeatureId fid)
void attributeAdded(int idx)
void attributeDeleted(int idx)
void featureAdded(QgsFeatureId fid)
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
QList< QgsField > mAddedAttributes
Added attributes fields which are not committed.
Base class for undo commands within a QgsVectorLayerEditBuffer.
QgsVectorLayer * layer()
Returns the layer associated with the undo command.
QgsVectorLayerEditBuffer * mBuffer
Associated edit buffer.
QgsVectorLayerUndoPassthroughCommandAddAttribute(QgsVectorLayerEditBuffer *buffer, const QgsField &field)
Constructor for QgsVectorLayerUndoPassthroughCommandAddAttribute.
QgsFeatureList features() const
List of features (added feaures can be modified by default values from database)
QgsVectorLayerUndoPassthroughCommandAddFeatures(QgsVectorLayerEditBuffer *buffer, QgsFeatureList &features)
Constructor for QgsVectorLayerUndoPassthroughCommandAddFeatures.
QgsVectorLayerUndoPassthroughCommandChangeAttribute(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, int field, const QVariant &newValue)
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttribute.
QgsVectorLayerUndoPassthroughCommandChangeAttributes(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttributes.
Undo command for changing feature geometry from a vector layer in transaction group.
QgsVectorLayerUndoPassthroughCommandChangeGeometry(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, const QgsGeometry &geom)
Constructor for QgsVectorLayerUndoPassthroughCommandChangeGeometry.
bool mergeWith(const QUndoCommand *other) override
QgsVectorLayerUndoPassthroughCommandDeleteAttribute(QgsVectorLayerEditBuffer *buffer, int attr)
Constructor for QgsVectorLayerUndoCommandDeleteAttribute.
QgsVectorLayerUndoPassthroughCommandDeleteFeatures(QgsVectorLayerEditBuffer *buffer, const QgsFeatureIds &fids)
Constructor for QgsVectorLayerUndoPassthroughCommandDeleteFeatures.
QgsVectorLayerUndoPassthroughCommandRenameAttribute(QgsVectorLayerEditBuffer *buffer, int attr, const QString &newName)
Constructor for QgsVectorLayerUndoCommandRenameAttribute.
QgsVectorLayerUndoPassthroughCommandUpdate(QgsVectorLayerEditBuffer *buffer, QgsTransaction *transaction, const QString &sql, const QString &name)
Constructor for QgsVectorLayerUndoCommandUpdate.
Undo command for vector layer in transaction group mode.
QgsVectorLayerUndoPassthroughCommand(QgsVectorLayerEditBuffer *buffer, const QString &text, bool autocreate=true)
Constructor for QgsVectorLayerUndoPassthroughCommand.
QString errorMessage() const
Returns the error message or an empty string if there's none.
void setErrorMessage(const QString &errorMessage)
Sets the error message.
void setError()
Set error flag and append "failed" to text.
bool hasError() const
Returns error status.
bool setSavePoint(const QString &savePointId=QString())
Set the command savepoint or set error status.
bool rollBackToSavePoint()
Rollback command, release savepoint or set error status save point must be set prior to call error sa...
void layerModified()
Emitted when modifications has been done on layer.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
QMap< int, QString > QgsFieldNameMap
QMap< int, QVariant > QgsAttributeMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
QSet< int > QgsAttributeIds