RTransaction
Class in Core Module
Header: #include <src/core/RTransaction.h>
Description
Section titled “Description”Transaction implementation.
A transaction encapsulates a change of state of a document. Every change of a drawing document is wrapped in a transaction and handled by the QCAD Application Framework as one change. A transaction might add one or multiple objects, modify existing objects or delete objects. Combinations in the same transaction are also possible.
Each transactions should contain a locical change to a drawing. For example if a selection is moved from one place to another, all entities that are part of the selection are moved in the same transaction. This is important for the undo / redo mechanism of QCAD. If each entity would be moved in a separate transaction, the user would have to issue an undo command for each entity to get back to the state before the entities were moved.
Transactions can be applied to a document and are handled by an RTransactionStack for undo / redo functionality. Transactions are stored in a storage.
Transactions in the QCAD Application Framework are a low level concept. They are unaware of graphics views or widgets that need to be updated.
Transaction listeners may be used to intercept, complete or inspect transactions: RTransactionListener, RInterTransactionListener.
Scriptable: This class is available in script environments.
Copyable: Objects are cleaned up automatically by the garbage collector of the script engine.
Public Types
Section titled “Public Types”| enum | Type { Generic, CurrentLayerChange, CurrentLayerSelectionChange, LayerLockStatusChange, LayerVisibilityStatusChange, SaveWorkingSet, ChangeDocumentSetting, Undo, Redo, LayerCollapseStatusChange }Transaction type for optimizations. |
Public Functions
Section titled “Public Functions”RTransaction() |
|
RTransaction(RStorage &storage)Constructs an empty, invalid transaction. |
|
RTransaction(RStorage &storage, const QString &text, bool undoable=true)Constructor for new transactions. |
|
RTransaction(RStorage &storage, int transactionId, const QString &text, const QList< RObject::Id > &affectedObjectIds, const QMap< RObject::Id, QList< RPropertyChange > > &propertyChanges)Constructor for existing transactions. |
|
| virtual | ~RTransaction() |
| void | addAffectedObject(QSharedPointer< RObject > object) |
| void | addAffectedObject(RObject::Id objectId)Adds the given object to the list of objects that are affected by this transaction. |
| void | addAffectedObjects(const QSet< RObject::Id > &objectIds)Adds the given objects to the list of objects that are affected by this transaction. |
| bool | addObject(QSharedPointer< RObject > obj, bool useCurrentAttributes=true, bool forceNew=false, const QSet< RPropertyTypeId > &modifiedPropertyTypeIds=RDEFAULT_QSET_RPROPERTYTYPEID)Adds the given object to the transaction. |
| void | deleteObject(QSharedPointer< RObject > object, bool force=false) |
| void | deleteObject(RObject::Id objectId, bool force=false) |
| void | end() |
| void | endCycle()Ends the current transaction cycle. |
| void | fail() |
| QList< RObject::Id > | getAffectedObjects() const |
| int | getGroup() const |
| int | getId() const |
| RObject::Id | getNewObjectId(RObject::Id oldId) const |
| QMap< RObject::Id, QList< RPropertyChange > > | getPropertyChanges() const |
| QList< RPropertyChange > | getPropertyChanges(RObject::Id id) const |
| QSet< RObject::Id > | getStatusChanges() const |
| QString | getText() const |
| QSet< RObject::Id > | getTranslatedObjectIds() const |
| RVector | getTranslation() const |
| RTransaction::Types | getTypes() const |
| bool | hasOnlyChanges() const |
| bool | hasPropertyChanges(const RPropertyTypeId &propertyTypeId) const |
| bool | hasStatusChange(RObject::Id id) const |
| bool | isFailed() const |
| bool | isPreview() const |
| bool | isRedoing() |
| bool | isTranslation() const |
| bool | isType(RTransaction::Type type) const |
| bool | isUndoable() const |
| bool | isUndoing() |
| bool | overwriteBlock(QSharedPointer< RBlock > block)Overwrites a potentially existing block with the given block. |
| virtual void | redo()Redo undone changes. |
| void | setAllowAll(bool on) |
| void | setAllowInvisible(bool on) |
| void | setBlockRecursionDetectionDisabled(bool on) |
| void | setExistingBlockDetectionDisabled(bool on) |
| void | setExistingLayerDetectionDisabled(bool on) |
| void | setExistingLinetypeDetectionDisabled(bool on) |
| void | setGroup(int group)Set group. |
| void | setId(int id)Sets the ID of this transaction. |
| void | setKeepChildren(bool on)Keep child entities (e.g. |
| void | setKeepHandles(bool on) |
| void | setRecordAffectedObjects(bool on) |
| void | setSpatialIndexDisabled(bool on) |
| void | setTranslation(const RVector &offset)Marks this transaction as a pure translation of entities by the given offset. |
| void | setType(RTransaction::Type type, bool on=true) |
| void | setTypes(RTransaction::Types t) |
| virtual void | undo()Reverts a change to the document. |
| void | updateAffectedBlockReferences() |
Protected Functions
Section titled “Protected Functions”| bool | addPropertyChange(RObject::Id objectId, const RPropertyChange &propertyChange)Adds the given property change for the given object to this transaction. |
| void | commit()Saves this command to the storage of the document. |
| void | rollback() |
Protected Attributes
Section titled “Protected Attributes”| QSet< RObject::Id > | affectedBlockReferenceIds List of IDs of all block references that need to be updated. |
| QList< RObject::Id > | affectedObjectIds List of IDs of all objects that are affected by this transaction. |
| QSet< RObject::Id > | affectedObjectIdsSet |
| bool | allowAll True if all transactions are allowed, even transactions on locked or invisible layers. |
| bool | allowInvisible True if all transactions on invisible entities are allowed, typically transactions on invisible layers. |
| bool | blockRecursionDetectionDisabled True to disable block recursion detection (performance gain for loading). |
| QMap< RObject::Id, RObject::Id > | cloneIds |
| bool | deletingBlock True if a block is being deleted to prevent recursion in deleteObject. |
| bool | existingBlockDetectionDisabled True to disable detection of existing blocks (performance gain). |
| bool | existingLayerDetectionDisabled True to disable detection of existing layers (performance gain). |
| bool | existingLinetypeDetectionDisabled True to disable detection of existing linetypes (performance gain). |
| bool | failed True if this transaction failed. |
| bool | keepChildren True to keep and not delete child entities (block attributes for block references). |
| bool | keepHandles True to keep existing object handles (importers). |
| bool | onlyChanges True if this transaction only changed objects, no additions, no deletes. |
| QMap< RObject::Id, QList< RPropertyChange > > | propertyChanges Map of properties that are changed by this transaction. |
| bool | recordAffectedObjects True if caller is interested in list of objects that are affected by this transaction. |
| bool | recordingTranslation True while objects added to this transaction are recorded as translated objects. |
| bool | redoing |
| bool | spatialIndexDisabled True to ignore spatial index. |
| QSet< RObject::Id > | statusChanges Contains affected objects that have been created or deleted in this transaction. |
| RStorage * | storage A transaction always belongs to the storage of a document. |
| QString | text Log entry for this transaction. |
| int | transactionGroup Transaction group or -1. |
| int | transactionId Unique ID of this transaction. |
| QSet< RObject::Id > | translatedObjectIds IDs of objects that have been purely translated by this transaction. |
| RVector | translation Translation offset if this transaction is a pure translation, invalid vector otherwise. |
| RTransaction::Types | types |
| bool | undoable Child transactions of this transaction. |
| bool | undoing |
| QStringList | usedBlockNames List of block names that have been already used in this transaction. |
Member Documentation
Section titled “Member Documentation”enum TypeTransaction type for optimizations.
RTransaction
Section titled “RTransaction”RTransaction::RTransaction()All rights reserved.
This file is part of the QCAD project.
QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with QCAD.
RTransaction
Section titled “RTransaction”RTransaction::RTransaction(RStorage &storage)Constructs an empty, invalid transaction.
RTransaction
Section titled “RTransaction”RTransaction::RTransaction(RStorage &storage, const QString &text, bool undoable=true)Constructor for new transactions.
RTransaction
Section titled “RTransaction”RTransaction::RTransaction(RStorage &storage, int transactionId, const QString &text, const QList< RObject::Id > &affectedObjectIds, const QMap< RObject::Id, QList< RPropertyChange > > &propertyChanges)Constructor for existing transactions.
This is used by storage implementations to instantiate transactions from a storage (e.g. DB).
~RTransaction
Section titled “~RTransaction”virtual RTransaction::~RTransaction()virtual
addAffectedObject
Section titled “addAffectedObject”void RTransaction::addAffectedObject(QSharedPointer< RObject > object)addAffectedObject
Section titled “addAffectedObject”void RTransaction::addAffectedObject(RObject::Id objectId)Adds the given object to the list of objects that are affected by this transaction.
addAffectedObjects
Section titled “addAffectedObjects”void RTransaction::addAffectedObjects(const QSet< RObject::Id > &objectIds)Adds the given objects to the list of objects that are affected by this transaction.
addObject
Section titled “addObject”bool RTransaction::addObject(QSharedPointer< RObject > obj, bool useCurrentAttributes=true, bool forceNew=false, const QSet< RPropertyTypeId > &modifiedPropertyTypeIds=RDEFAULT_QSET_RPROPERTYTYPEID)Adds the given object to the transaction.
Adding an object to a transaction means that this transaction modifies or adds the object. Entities that are added with an invalid layer or block ID are placed on the current layer / block.
Parameters:
modifiedPropertyTypeId: Property IDs that have changed if known by caller, empty set otherwise.
deleteObject
Section titled “deleteObject”void RTransaction::deleteObject(QSharedPointer< RObject > object, bool force=false)deleteObject
Section titled “deleteObject”void RTransaction::deleteObject(RObject::Id objectId, bool force=false)void RTransaction::end()endCycle
Section titled “endCycle”void RTransaction::endCycle()Ends the current transaction cycle.
A cycle typcially creates one copy of a selection. This function is necessary to fix IDs in parent / child related entities (block references / attributes).
void RTransaction::fail()getAffectedObjects
Section titled “getAffectedObjects”QList< RObject::Id > RTransaction::getAffectedObjects() constinline const
Returns: List of object IDs of objects that are affected by this transaction.
getGroup
Section titled “getGroup”int RTransaction::getGroup() constinline const
Returns: Group of this transaction.
int RTransaction::getId() constinline const
Returns: Unique ID of this transaction.
getNewObjectId
Section titled “getNewObjectId”RObject::Id RTransaction::getNewObjectId(RObject::Id oldId) constconst
getPropertyChanges
Section titled “getPropertyChanges”QMap< RObject::Id, QList< RPropertyChange > > RTransaction::getPropertyChanges() constinline const
Returns: Map of properties that are changed by this transaction.
getPropertyChanges
Section titled “getPropertyChanges”QList< RPropertyChange > RTransaction::getPropertyChanges(RObject::Id id) constconst
Returns: List of property changes by this transaction for the given object.
getStatusChanges
Section titled “getStatusChanges”QSet< RObject::Id > RTransaction::getStatusChanges() constinline const
Returns: Set of object IDs of objects that have been created or deleted by this transaction.
getText
Section titled “getText”QString RTransaction::getText() constinline const
Returns: Logged text for this transaction.
getTranslatedObjectIds
Section titled “getTranslatedObjectIds”QSet< RObject::Id > RTransaction::getTranslatedObjectIds() constinline const
Returns: Set of IDs of existing objects that have been translated by this transaction (see setTranslation).
getTranslation
Section titled “getTranslation”RVector RTransaction::getTranslation() constinline const
Returns: Translation offset of this transaction or an invalid vector if this transaction is not a pure translation.
getTypes
Section titled “getTypes”RTransaction::Types RTransaction::getTypes() constinline const
hasOnlyChanges
Section titled “hasOnlyChanges”bool RTransaction::hasOnlyChanges() constinline const
hasPropertyChanges
Section titled “hasPropertyChanges”bool RTransaction::hasPropertyChanges(const RPropertyTypeId &propertyTypeId) constconst
Returns: True if this transaction contains at least one change of the given property for any object.
hasStatusChange
Section titled “hasStatusChange”bool RTransaction::hasStatusChange(RObject::Id id) constinline const
isFailed
Section titled “isFailed”bool RTransaction::isFailed() constinline const
isPreview
Section titled “isPreview”bool RTransaction::isPreview() constconst
isRedoing
Section titled “isRedoing”bool RTransaction::isRedoing()inline
isTranslation
Section titled “isTranslation”bool RTransaction::isTranslation() constinline const
Returns: True if this transaction is a pure translation of the objects returned by getTranslatedObjectIds.
isType
Section titled “isType”bool RTransaction::isType(RTransaction::Type type) constconst
isUndoable
Section titled “isUndoable”bool RTransaction::isUndoable() constinline const
Returns: True if this transaction should store undo / redo information for later undo / redo functionality.
isUndoing
Section titled “isUndoing”bool RTransaction::isUndoing()inline
overwriteBlock
Section titled “overwriteBlock”bool RTransaction::overwriteBlock(QSharedPointer< RBlock > block)Overwrites a potentially existing block with the given block.
virtual void RTransaction::redo()virtual
Redo undone changes.
(Re-)applies this transaction to the document.
setAllowAll
Section titled “setAllowAll”void RTransaction::setAllowAll(bool on)inline
setAllowInvisible
Section titled “setAllowInvisible”void RTransaction::setAllowInvisible(bool on)inline
setBlockRecursionDetectionDisabled
Section titled “setBlockRecursionDetectionDisabled”void RTransaction::setBlockRecursionDetectionDisabled(bool on)inline
setExistingBlockDetectionDisabled
Section titled “setExistingBlockDetectionDisabled”void RTransaction::setExistingBlockDetectionDisabled(bool on)inline
setExistingLayerDetectionDisabled
Section titled “setExistingLayerDetectionDisabled”void RTransaction::setExistingLayerDetectionDisabled(bool on)inline
setExistingLinetypeDetectionDisabled
Section titled “setExistingLinetypeDetectionDisabled”void RTransaction::setExistingLinetypeDetectionDisabled(bool on)inline
setGroup
Section titled “setGroup”void RTransaction::setGroup(int group)inline
Set group.
void RTransaction::setId(int id)inline
Sets the ID of this transaction.
Typically called by a storage which manages transaction IDs.
setKeepChildren
Section titled “setKeepChildren”void RTransaction::setKeepChildren(bool on)inline
Keep child entities (e.g.
keep block attributes when deleting block references)
setKeepHandles
Section titled “setKeepHandles”void RTransaction::setKeepHandles(bool on)inline
setRecordAffectedObjects
Section titled “setRecordAffectedObjects”void RTransaction::setRecordAffectedObjects(bool on)inline
setSpatialIndexDisabled
Section titled “setSpatialIndexDisabled”void RTransaction::setSpatialIndexDisabled(bool on)inline
setTranslation
Section titled “setTranslation”void RTransaction::setTranslation(const RVector &offset)Marks this transaction as a pure translation of entities by the given offset.
Objects added to the transaction after this call and before the transaction is committed are recorded as translated (see getTranslatedObjectIds). Objects that are modified later (e.g. by inter transaction listeners) are removed from that set. Graphics scenes can use this information to translate cached graphical representations instead of regenerating them.
setType
Section titled “setType”void RTransaction::setType(RTransaction::Type type, bool on=true)setTypes
Section titled “setTypes”void RTransaction::setTypes(RTransaction::Types t)inline
virtual void RTransaction::undo()virtual
Reverts a change to the document.
Undoes this transaction.
After undo() is called, the state of the document should be the same as before redo() was called.
updateAffectedBlockReferences
Section titled “updateAffectedBlockReferences”void RTransaction::updateAffectedBlockReferences()addPropertyChange
Section titled “addPropertyChange”bool RTransaction::addPropertyChange(RObject::Id objectId, const RPropertyChange &propertyChange)protected
Adds the given property change for the given object to this transaction.
commit
Section titled “commit”void RTransaction::commit()protected
Saves this command to the storage of the document.
rollback
Section titled “rollback”void RTransaction::rollback()protected
affectedBlockReferenceIds
Section titled “affectedBlockReferenceIds”QSet<RObject::Id> RTransaction::affectedBlockReferenceIdsprotected
List of IDs of all block references that need to be updated.
affectedObjectIds
Section titled “affectedObjectIds”QList<RObject::Id> RTransaction::affectedObjectIdsprotected
List of IDs of all objects that are affected by this transaction.
Needs to be in order (not a set):
affectedObjectIdsSet
Section titled “affectedObjectIdsSet”QSet<RObject::Id> RTransaction::affectedObjectIdsSetprotected
allowAll
Section titled “allowAll”bool RTransaction::allowAllprotected
True if all transactions are allowed, even transactions on locked or invisible layers.
Typically the case for importers.
allowInvisible
Section titled “allowInvisible”bool RTransaction::allowInvisibleprotected
True if all transactions on invisible entities are allowed, typically transactions on invisible layers.
Used to move entities to an invisible layer.
blockRecursionDetectionDisabled
Section titled “blockRecursionDetectionDisabled”bool RTransaction::blockRecursionDetectionDisabledprotected
True to disable block recursion detection (performance gain for loading).
cloneIds
Section titled “cloneIds”QMap<RObject::Id, RObject::Id> RTransaction::cloneIdsprotected
deletingBlock
Section titled “deletingBlock”bool RTransaction::deletingBlockprotected
True if a block is being deleted to prevent recursion in deleteObject.
existingBlockDetectionDisabled
Section titled “existingBlockDetectionDisabled”bool RTransaction::existingBlockDetectionDisabledprotected
True to disable detection of existing blocks (performance gain).
existingLayerDetectionDisabled
Section titled “existingLayerDetectionDisabled”bool RTransaction::existingLayerDetectionDisabledprotected
True to disable detection of existing layers (performance gain).
existingLinetypeDetectionDisabled
Section titled “existingLinetypeDetectionDisabled”bool RTransaction::existingLinetypeDetectionDisabledprotected
True to disable detection of existing linetypes (performance gain).
failed
Section titled “failed”bool RTransaction::failedprotected
True if this transaction failed.
keepChildren
Section titled “keepChildren”bool RTransaction::keepChildrenprotected
True to keep and not delete child entities (block attributes for block references).
keepHandles
Section titled “keepHandles”bool RTransaction::keepHandlesprotected
True to keep existing object handles (importers).
onlyChanges
Section titled “onlyChanges”bool RTransaction::onlyChangesprotected
True if this transaction only changed objects, no additions, no deletes.
propertyChanges
Section titled “propertyChanges”QMap<RObject::Id, QList<RPropertyChange> > RTransaction::propertyChangesprotected
Map of properties that are changed by this transaction.
For every undoable, a whole list of properties might have changed in a fixed order.
recordAffectedObjects
Section titled “recordAffectedObjects”bool RTransaction::recordAffectedObjectsprotected
True if caller is interested in list of objects that are affected by this transaction.
recordingTranslation
Section titled “recordingTranslation”bool RTransaction::recordingTranslationprotected
True while objects added to this transaction are recorded as translated objects.
redoing
Section titled “redoing”bool RTransaction::redoingprotected
spatialIndexDisabled
Section titled “spatialIndexDisabled”bool RTransaction::spatialIndexDisabledprotected
True to ignore spatial index.
Used for importers which regenerate the spatial index in the end.
statusChanges
Section titled “statusChanges”QSet<RObject::Id> RTransaction::statusChangesprotected
Contains affected objects that have been created or deleted in this transaction.
storage
Section titled “storage”RStorage* RTransaction::storageprotected
A transaction always belongs to the storage of a document.
QString RTransaction::textprotected
Log entry for this transaction.
transactionGroup
Section titled “transactionGroup”int RTransaction::transactionGroupprotected
Transaction group or -1.
Transaction groups are undone / redone together.
transactionId
Section titled “transactionId”int RTransaction::transactionIdprotected
Unique ID of this transaction.
translatedObjectIds
Section titled “translatedObjectIds”QSet<RObject::Id> RTransaction::translatedObjectIdsprotected
IDs of objects that have been purely translated by this transaction.
translation
Section titled “translation”RVector RTransaction::translationprotected
Translation offset if this transaction is a pure translation, invalid vector otherwise.
RTransaction::Types RTransaction::typesprotected
undoable
Section titled “undoable”bool RTransaction::undoableprotected
Child transactions of this transaction.
True if this transaction can be undone.
undoing
Section titled “undoing”bool RTransaction::undoingprotected
usedBlockNames
Section titled “usedBlockNames”QStringList RTransaction::usedBlockNamesprotected
List of block names that have been already used in this transaction.