-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add undo and redo on transaction groups (#4765)
* [FEATURE] adds undo/redo for transaction groups [needs-docs] the undo/redo now works with transcation groups. Just check that there is no restriction in the transaction groups doc concerning undo. related to #14799 The undo/redo is implemented using SAVEPOINT. The QgsTransaction interface has been enlarged to allow savepoints creation and management. The savepoint is destroyed on rollbackToSavepoint to have the same behavior has the sql ROLLBACK TO SAVEPPOINT. To avoid the creation of a savepoint for each feature modified in bulk editing (e.g. paste, field calculator) the logic is a bit complicated: the savepoint is created on QgsVectorLayer::editCommandStarted and the first actual undo command (QgsVectorLayerUndoPassthroughCommand) is responsible for the re-creation of the savepoint in case of undo-redo. Since the behavior must be different in case edition doesn't take place inside an edit command, a member function has been added to QgsVectorLayer to expose the mEditCommandActive state. Another (commented) tricky bit is the modification of the database structure on add/delete attributes. On undo, the attribute is removed before the rollback to savepoint, i.e. there is a useless ALTER TABLE issued to restore the structure just before restoring it with the ROLLBACK TO SAVEPOINT. This is necessary to make the provider aware of the change of structure. It could be nicer/cleaner to have a way to reload providers metadata. The editPaste function has also been modified to use addFeatures instead of addFeature (plural/singular), this is at the expense of an additional "cpy" of the clipboard in memory, but it should improve perf with postgis provider. * fixup operator aliases
- Loading branch information
Showing
21 changed files
with
1,091 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsvectorlayerundopassthroughcommand.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommand : QgsVectorLayerUndoCommand | ||
{ | ||
%Docstring | ||
Undo command for vector layer in transaction group mode. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommand( QgsVectorLayerEditBuffer *buffer, const QString &text ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoPassthroughCommand | ||
\param buffer associated edit buffer | ||
\param text text associated with command | ||
%End | ||
|
||
bool hasError() const; | ||
%Docstring | ||
Returns error status | ||
:rtype: bool | ||
%End | ||
|
||
protected: | ||
|
||
bool rollBackToSavePoint(); | ||
%Docstring | ||
Rollback command, release savepoint or set error status | ||
save point must be set prior to call | ||
error satus should be false prior to call | ||
:rtype: bool | ||
%End | ||
|
||
bool setSavePoint(); | ||
%Docstring | ||
Set the command savepoint or set error status | ||
error satus should be false prior to call | ||
:rtype: bool | ||
%End | ||
|
||
void setError(); | ||
%Docstring | ||
Set error flag and append "failed" to text | ||
%End | ||
|
||
}; | ||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandAddFeatures : QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for adding a feature to a vector layer in transaction group mode. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandAddFeatures( QgsVectorLayerEditBuffer *buffer /Transfer/, QgsFeatureList &features ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoPassthroughCommandAddFeatures | ||
\param buffer associated edit buffer | ||
\param features features to add to layer | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
QgsFeatureList features() const; | ||
%Docstring | ||
List of features (added feaures can be modified by default values from database) | ||
:rtype: QgsFeatureList | ||
%End | ||
|
||
}; | ||
|
||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandDeleteFeatures : QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for deleting features from a vector layer in transaction group. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandDeleteFeatures( QgsVectorLayerEditBuffer *buffer /Transfer/, const QgsFeatureIds &fids ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoPassthroughCommandDeleteFeatures | ||
\param buffer associated edit buffer | ||
\param fids feature IDs of features to delete from layer | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
}; | ||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandChangeGeometry : QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for changing feature geometry from a vector layer in transaction group. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandChangeGeometry( QgsVectorLayerEditBuffer *buffer /Transfer/, const QgsFeatureId &fid, const QgsGeometry &geom ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoPassthroughCommandChangeGeometry | ||
\param buffer associated edit buffer | ||
\param fid feature ID of feature to change | ||
\param geom new geometru | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
}; | ||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandChangeAttribute: QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for changing attr value from a vector layer in transaction group. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandChangeAttribute( QgsVectorLayerEditBuffer *buffer /Transfer/, QgsFeatureId fid, int field, const QVariant &newValue ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoPassthroughCommandChangeAttribute | ||
\param buffer associated edit buffer | ||
\param fid feature ID of feature | ||
\param field | ||
\param newValue | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
}; | ||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandAddAttribute : QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for adding attri to a vector layer in transaction group. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandAddAttribute( QgsVectorLayerEditBuffer *buffer /Transfer/, const QgsField &field ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoPassthroughCommandAddAttribute | ||
\param buffer associated edit buffer | ||
\param field | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
}; | ||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandDeleteAttribute : QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for deleting attri of a vector layer in transaction group. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandDeleteAttribute( QgsVectorLayerEditBuffer *buffer /Transfer/, int attr ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoCommandDeleteAttribute | ||
\param buffer associated edit buffer | ||
\param attr | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
}; | ||
|
||
|
||
class QgsVectorLayerUndoPassthroughCommandRenameAttribute : QgsVectorLayerUndoPassthroughCommand | ||
{ | ||
%Docstring | ||
Undo command for deleting attri of a vector layer in transaction group. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerundopassthroughcommand.h" | ||
%End | ||
public: | ||
|
||
QgsVectorLayerUndoPassthroughCommandRenameAttribute( QgsVectorLayerEditBuffer *buffer /Transfer/, int attr, const QString &newName ); | ||
%Docstring | ||
Constructor for QgsVectorLayerUndoCommandRenameAttribute | ||
\param buffer associated edit buffer | ||
\param attr | ||
\param newName | ||
%End | ||
|
||
virtual void undo(); | ||
virtual void redo(); | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsvectorlayerundopassthroughcommand.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.