QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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() );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsVectorLayerUndoPassthroughCommand(QgsVectorLayerEditBuffer *buffer, const QString &text, bool autocreate=true)
Constructor for QgsVectorLayerUndoPassthroughCommand.
QList< QString > savePoints() const
returns savepoints
QSet< int > QgsAttributeIds
QList< QgsField > mAddedAttributes
Added attributes fields which are not committed.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
QgsVectorLayerEditBuffer * mBuffer
Associated edit buffer.
bool hasErrors() const
Provider has errors to report.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsVectorLayerUndoPassthroughCommandAddFeatures(QgsVectorLayerEditBuffer *buffer, QgsFeatureList &features)
Constructor for QgsVectorLayerUndoPassthroughCommandAddFeatures.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed.
bool rollBackToSavePoint()
Rollback command, release savepoint or set error status save point must be set prior to call error sa...
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not committed. The list is kept sorted.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
Undo command for changing feature geometry from a vector layer in transaction group.
QgsFeatureList features() const
List of features (added feaures can be modified by default values from database)
This class allows including a set of layers in a database-side transaction, provided the layer data p...
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Undo command for vector layer in transaction group mode.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QList< int > QgsAttributeList
QgsVectorLayerUndoPassthroughCommandChangeAttributes(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttributes.
bool hasError() const
Returns error status.
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
QString errorMessage() const
Returns the error message or an empty string if there's none.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets the feature ID that should be fetched.
QgsVectorLayerUndoPassthroughCommandAddAttribute(QgsVectorLayerEditBuffer *buffer, const QgsField &field)
Constructor for QgsVectorLayerUndoPassthroughCommandAddAttribute.
bool setSavePoint(const QString &savePointId=QString())
Set the command savepoint or set error status.
QgsVectorLayer * layer()
Returns the layer associated with the undo command.
QgsVectorLayerUndoPassthroughCommandChangeGeometry(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, const QgsGeometry &geom)
Constructor for QgsVectorLayerUndoPassthroughCommandChangeGeometry.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsVectorLayerUndoPassthroughCommandChangeAttribute(QgsVectorLayerEditBuffer *buffer, QgsFeatureId fid, int field, const QVariant &newValue)
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttribute.
QgsFeatureMap mAddedFeatures
New features which are not committed.
void featureDeleted(QgsFeatureId fid)
virtual bool rollbackToSavepoint(const QString &name, QString &error)
rollback to save point, the save point is maintained and is "undertied"
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
void featureAdded(QgsFeatureId fid)
QgsVectorLayerUndoPassthroughCommandUpdate(QgsVectorLayerEditBuffer *buffer, QgsTransaction *transaction, const QString &sql, const QString &name)
Constructor for QgsVectorLayerUndoCommandUpdate.
QgsVectorLayerUndoPassthroughCommandDeleteAttribute(QgsVectorLayerEditBuffer *buffer, int attr)
Constructor for QgsVectorLayerUndoCommandDeleteAttribute.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
QList< QgsFeature > QgsFeatureList
QMap< int, QVariant > QgsAttributeMap
void attributeDeleted(int idx)
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setError()
Set error flag and append "failed" to text.
void attributeRenamed(int idx, const QString &newName)
Emitted when an attribute has been renamed.
void attributeAdded(int idx)
void layerModified()
Emitted when modifications has been done on layer.
bool mergeWith(const QUndoCommand *other) override
QSet< QgsFeatureId > QgsFeatureIds
void clearErrors()
Clear recorded errors.
Base class for undo commands within a QgsVectorLayerEditBuffer.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features to the sink.
QgsVectorLayerUndoPassthroughCommandRenameAttribute(QgsVectorLayerEditBuffer *buffer, int attr, const QString &newName)
Constructor for QgsVectorLayerUndoCommandRenameAttribute.
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
QMap< int, QString > QgsFieldNameMap
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QgsVectorLayerUndoPassthroughCommandDeleteFeatures(QgsVectorLayerEditBuffer *buffer, const QgsFeatureIds &fids)
Constructor for QgsVectorLayerUndoPassthroughCommandDeleteFeatures.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
Wrapper for iterator of features from vector data provider or vector layer.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
void setErrorMessage(const QString &errorMessage)
Sets the error message.
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Encapsulate a field in an attribute table or data source.