QGIS/python/core/qgstransaction.sip
Vincent Mora f63c302420 [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
2017-09-15 14:55:43 +02:00

176 lines
5.1 KiB
Plaintext

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstransaction.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsTransaction : QObject /Abstract/
{
%Docstring
This class allows including a set of layers in a database-side transaction,
provided the layer data providers support transactions and are compatible
with each other.
Only layers which are not in edit mode can be included in a transaction,
and all layers need to be in read-only mode for a transaction to be committed
or rolled back.
Layers cannot only be included in one transaction at a time.
When editing layers which are part of a transaction group, all changes are
sent directly to the data provider (bypassing the undo/redo stack), and the
changes can either be committed or rolled back on the database side via the
QgsTransaction.commit and QgsTransaction.rollback methods.
As long as the transaction is active, the state of all layer features reflects
the current state in the transaction.
Edits on features can get rejected if another conflicting transaction is active.
%End
%TypeHeaderCode
#include "qgstransaction.h"
%End
public:
static QgsTransaction *create( const QString &connString, const QString &providerKey ) /Factory/;
%Docstring
Create a transaction for the specified connection string ``connString``
and provider with ``providerKey``.
:rtype: QgsTransaction
%End
static QgsTransaction *create( const QStringList &layerIds ) /Factory/;
%Docstring
Create a transaction which includes the layers specified with
``layerIds``.
All layers are expected to have the same connection string and data
provider.
:rtype: QgsTransaction
%End
virtual ~QgsTransaction();
bool addLayer( const QString &layerId );
%Docstring
Add the layer with ``layerId`` to the transaction. The layer must not be
in edit mode and the connection string must match.
:rtype: bool
%End
bool addLayer( QgsVectorLayer *layer );
%Docstring
Add the ``layer`` to the transaction. The layer must not be
in edit mode and the connection string must match.
:rtype: bool
%End
bool begin( QString &errorMsg /Out/, int statementTimeout = 20 );
%Docstring
Begin transaction
The ``statementTimeout`` (in seconds) specifies how long an sql statement
is allowed to block QGIS before it is aborted.
Statements can block, if multiple transactions are active and a
statement would produce a conflicting state. In these cases, the
statements block until the conflicting transaction is committed or
rolled back.
Some providers might not honour the statement timeout.
:rtype: bool
%End
bool commit( QString &errorMsg /Out/ );
%Docstring
Commit transaction.
:rtype: bool
%End
bool rollback( QString &errorMsg /Out/ );
%Docstring
Roll back transaction.
:rtype: bool
%End
virtual bool executeSql( const QString &sql, QString &error /Out/ ) = 0;
%Docstring
Execute the ``sql`` string. The result must not be a tuple, so running a
``SELECT`` query will return an error.
:rtype: bool
%End
static bool supportsTransaction( const QgsVectorLayer *layer );
%Docstring
Checks if a the provider of a given ``layer`` supports transactions.
:rtype: bool
%End
QString createSavepoint( QString &error /Out/ );
%Docstring
creates a save point
returns empty string on error
returns the last created savepoint if it's not dirty
.. versionadded:: 3.0
:rtype: str
%End
QString createSavepoint( const QString &savePointId, QString &error /Out/ );
%Docstring
creates a save point
returns empty string on error
.. versionadded:: 3.0
:rtype: str
%End
bool rollbackToSavepoint( const QString &name, QString &error /Out/ );
%Docstring
rollback to save point, the save point is maintained and is "undertied"
.. versionadded:: 3.0
:rtype: bool
%End
void dirtyLastSavePoint();
%Docstring
dirty save point such that next call to createSavepoint will create a new one
.. versionadded:: 3.0
%End
QList< QString > savePoints() const;
%Docstring
returns savepoints
.. versionadded:: 3.0
:rtype: list of str
%End
bool lastSavePointIsDirty() const;
%Docstring
returns the last created savepoint
.. versionadded:: 3.0
:rtype: bool
%End
signals:
void afterRollback();
%Docstring
Emitted after a rollback
%End
protected:
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstransaction.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/