QCAD
Open Source 2D CAD
RTransaction Class Reference

Transaction implementation. More...

#include <RTransaction.h>

Public Types

enum  Type {
  Generic = 0x0000, CurrentLayerChange = 0x0001, CurrentLayerSelectionChange = 0x0002, LayerLockStatusChange = 0x0004,
  LayerVisibilityStatusChange = 0x0008, SaveWorkingSet = 0x0010, ChangeDocumentSetting = 0x0020, Undo = 0x0040,
  Redo = 0x0080
}
 Transaction type for optimizations. More...
 

Public Member Functions

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. More...
 
void addAffectedObjects (const QSet< RObject::Id > &objectIds)
 Adds the given objects to the list of objects that are affected by this transaction. More...
 
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. More...
 
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. More...
 
void fail ()
 
QList< RObject::IdgetAffectedObjects () const
 
int getGroup () const
 
int getId () const
 
QMap< RObject::Id, QList< RPropertyChange > > getPropertyChanges () const
 
QList< RPropertyChangegetPropertyChanges (RObject::Id id) const
 
QSet< RObject::IdgetStatusChanges () const
 
QString getText () const
 
RTransaction::Types getTypes () const
 
bool hasOnlyChanges () const
 
bool hasStatusChange (RObject::Id id) const
 
bool isFailed () const
 
bool isPreview () const
 
bool isRedoing ()
 
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. More...
 
virtual void redo ()
 Redo undone changes. More...
 
 RTransaction ()
 Copyright (c) 2011-2018 by Andrew Mustun. More...
 
 RTransaction (RStorage &storage)
 Constructs an empty, invalid transaction. More...
 
 RTransaction (RStorage &storage, const QString &text, bool undoable=true)
 Constructor for new transactions. More...
 
 RTransaction (RStorage &storage, int transactionId, const QString &text, const QList< RObject::Id > &affectedObjectIds, const QMap< RObject::Id, QList< RPropertyChange > > &propertyChanges)
 Constructor for existing transactions. More...
 
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. More...
 
void setId (int id)
 Sets the ID of this transaction. More...
 
void setKeepChildren (bool on)
 Keep child entities (e.g. More...
 
void setKeepHandles (bool on)
 
void setRecordAffectedObjects (bool on)
 
void setSpatialIndexDisabled (bool on)
 
void setType (RTransaction::Type type, bool on=true)
 
void setTypes (RTransaction::Types t)
 
virtual void undo ()
 Reverts a change to the document. More...
 
void updateAffectedBlockReferences ()
 
virtual ~RTransaction ()
 

Protected Member Functions

bool addPropertyChange (RObject::Id objectId, const RPropertyChange &propertyChange)
 Adds the given property change for the given object to this transaction. More...
 
void commit ()
 Saves this command to the storage of the document. More...
 
void rollback ()
 

Protected Attributes

QSet< RObject::IdaffectedBlockReferenceIds
 List of IDs of all block references that need to be updated. More...
 
QList< RObject::IdaffectedObjectIds
 List of IDs of all objects that are affected by this transaction. More...
 
QSet< RObject::IdaffectedObjectIdsSet
 
bool allowAll
 True if all transactions are allowed, even transactions on locked or invisible layers. More...
 
bool allowInvisible
 True if all transactions on invisible entities are allowed, typically transactions on invisible layers. More...
 
bool blockRecursionDetectionDisabled
 True to disable block recursion detection (performance gain for loading). More...
 
QMap< RObject::Id, RObject::IdcloneIds
 
bool existingBlockDetectionDisabled
 True to disable detection of existing blocks (performance gain). More...
 
bool existingLayerDetectionDisabled
 True to disable detection of existing layers (performance gain). More...
 
bool existingLinetypeDetectionDisabled
 True to disable detection of existing linetypes (performance gain). More...
 
bool failed
 True if this transaction failed. More...
 
bool keepChildren
 True to keep and not delete child entities (block attributes for block references). More...
 
bool keepHandles
 True to keep existing object handles (importers). More...
 
bool onlyChanges
 True if this transaction only changed objects, no additions, no deletes. More...
 
QMap< RObject::Id, QList< RPropertyChange > > propertyChanges
 Map of properties that are changed by this transaction. More...
 
bool recordAffectedObjects
 True if caller is interested in list of objects that are affected by this transaction. More...
 
bool redoing
 
bool spatialIndexDisabled
 True to ignore spatial index. More...
 
QSet< RObject::IdstatusChanges
 Contains affected objects that have been created or deleted in this transaction. More...
 
RStoragestorage
 A transaction always belongs to the storage of a document. More...
 
QString text
 Log entry for this transaction. More...
 
int transactionGroup
 Transaction group or -1. More...
 
int transactionId
 Unique ID of this transaction. More...
 
RTransaction::Types types
 
bool undoable
 Child transactions of this transaction. More...
 
bool undoing
 

Detailed 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:\nThis class is available in script environments.\n
Copyable:\nObjects are cleaned up automatically by the garbage collector of the script engine.\n

Member Enumeration Documentation

◆ Type

Transaction type for optimizations.

Enumerator
Generic 
CurrentLayerChange 
CurrentLayerSelectionChange 
LayerLockStatusChange 
LayerVisibilityStatusChange 
SaveWorkingSet 
ChangeDocumentSetting 
Undo 
Redo 

Constructor & Destructor Documentation

◆ RTransaction() [1/4]

RTransaction::RTransaction ( )

Copyright (c) 2011-2018 by Andrew Mustun.

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() [2/4]

RTransaction::RTransaction ( RStorage storage)

Constructs an empty, invalid transaction.

◆ RTransaction() [3/4]

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() [4/4]

RTransaction::RTransaction ( RStorage storage,
const QString &  text,
bool  undoable = true 
)

Constructor for new transactions.

◆ ~RTransaction()

RTransaction::~RTransaction ( )
virtual

Member Function Documentation

◆ addAffectedObject() [1/2]

void RTransaction::addAffectedObject ( QSharedPointer< RObject object)

◆ addAffectedObject() [2/2]

void RTransaction::addAffectedObject ( RObject::Id  objectId)

Adds the given object to the list of objects that are affected by this transaction.

◆ 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()

bool RTransaction::addObject ( QSharedPointer< RObject object,
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
modifiedPropertyTypeIdProperty IDs that have changed if known by caller, empty set otherwise.

◆ addPropertyChange()

bool RTransaction::addPropertyChange ( RObject::Id  objectId,
const RPropertyChange propertyChange 
)
protected

Adds the given property change for the given object to this transaction.

◆ commit()

void RTransaction::commit ( )
protected

Saves this command to the storage of the document.

◆ deleteObject() [1/2]

void RTransaction::deleteObject ( QSharedPointer< RObject object,
bool  force = false 
)

◆ deleteObject() [2/2]

void RTransaction::deleteObject ( RObject::Id  objectId,
bool  force = false 
)

◆ end()

void RTransaction::end ( )

◆ 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).

◆ fail()

void RTransaction::fail ( )

◆ getAffectedObjects()

QList<RObject::Id> RTransaction::getAffectedObjects ( ) const
inline
Returns
List of object IDs of objects that are affected by this transaction.

◆ getGroup()

int RTransaction::getGroup ( ) const
inline
Returns
Group of this transaction.

◆ getId()

int RTransaction::getId ( ) const
inline
Returns
Unique ID of this transaction.

◆ getPropertyChanges() [1/2]

QMap<RObject::Id, QList<RPropertyChange> > RTransaction::getPropertyChanges ( ) const
inline
Returns
Map of properties that are changed by this transaction.

◆ getPropertyChanges() [2/2]

QList< RPropertyChange > RTransaction::getPropertyChanges ( RObject::Id  id) const
Returns
List of property changes by this transaction for the given object.

◆ getStatusChanges()

QSet<RObject::Id> RTransaction::getStatusChanges ( ) const
inline
Returns
Set of object IDs of objects that have been created or deleted by this transaction.

◆ getText()

QString RTransaction::getText ( ) const
inline
Returns
Logged text for this transaction.

◆ getTypes()

RTransaction::Types RTransaction::getTypes ( ) const
inline

◆ hasOnlyChanges()

bool RTransaction::hasOnlyChanges ( ) const
inline

◆ hasStatusChange()

bool RTransaction::hasStatusChange ( RObject::Id  id) const
inline

◆ isFailed()

bool RTransaction::isFailed ( ) const
inline

◆ isPreview()

bool RTransaction::isPreview ( ) const

◆ isRedoing()

bool RTransaction::isRedoing ( )
inline

◆ isType()

bool RTransaction::isType ( RTransaction::Type  type) const

◆ isUndoable()

bool RTransaction::isUndoable ( ) const
inline
Returns
True if this transaction should store undo / redo information for later undo / redo functionality.

◆ isUndoing()

bool RTransaction::isUndoing ( )
inline

◆ overwriteBlock()

bool RTransaction::overwriteBlock ( QSharedPointer< RBlock block)

Overwrites a potentially existing block with the given block.

◆ redo()

void RTransaction::redo ( )
virtual

Redo undone changes.

(Re-)applies this transaction to the document.

◆ rollback()

void RTransaction::rollback ( )
protected

◆ setAllowAll()

void RTransaction::setAllowAll ( bool  on)
inline

◆ setAllowInvisible()

void RTransaction::setAllowInvisible ( bool  on)
inline

◆ setBlockRecursionDetectionDisabled()

void RTransaction::setBlockRecursionDetectionDisabled ( bool  on)
inline

◆ setExistingBlockDetectionDisabled()

void RTransaction::setExistingBlockDetectionDisabled ( bool  on)
inline

◆ setExistingLayerDetectionDisabled()

void RTransaction::setExistingLayerDetectionDisabled ( bool  on)
inline

◆ setExistingLinetypeDetectionDisabled()

void RTransaction::setExistingLinetypeDetectionDisabled ( bool  on)
inline

◆ setGroup()

void RTransaction::setGroup ( int  group)
inline

Set group.

◆ setId()

void RTransaction::setId ( int  id)
inline

Sets the ID of this transaction.

Typically called by a storage which manages transaction IDs.

◆ setKeepChildren()

void RTransaction::setKeepChildren ( bool  on)
inline

Keep child entities (e.g.

keep block attributes when deleting block references)

◆ setKeepHandles()

void RTransaction::setKeepHandles ( bool  on)
inline

◆ setRecordAffectedObjects()

void RTransaction::setRecordAffectedObjects ( bool  on)
inline

◆ setSpatialIndexDisabled()

void RTransaction::setSpatialIndexDisabled ( bool  on)
inline

◆ setType()

void RTransaction::setType ( RTransaction::Type  type,
bool  on = true 
)

◆ setTypes()

void RTransaction::setTypes ( RTransaction::Types  t)
inline

◆ undo()

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()

void RTransaction::updateAffectedBlockReferences ( )

Member Data Documentation

◆ affectedBlockReferenceIds

QSet<RObject::Id> RTransaction::affectedBlockReferenceIds
protected

List of IDs of all block references that need to be updated.

◆ affectedObjectIds

QList<RObject::Id> RTransaction::affectedObjectIds
protected

List of IDs of all objects that are affected by this transaction.

Needs to be in order (not a set):

◆ affectedObjectIdsSet

QSet<RObject::Id> RTransaction::affectedObjectIdsSet
protected

◆ allowAll

bool RTransaction::allowAll
protected

True if all transactions are allowed, even transactions on locked or invisible layers.

Typically the case for importers.

◆ allowInvisible

bool RTransaction::allowInvisible
protected

True if all transactions on invisible entities are allowed, typically transactions on invisible layers.

Used to move entities to an invisible layer.

◆ blockRecursionDetectionDisabled

bool RTransaction::blockRecursionDetectionDisabled
protected

True to disable block recursion detection (performance gain for loading).

◆ cloneIds

QMap<RObject::Id, RObject::Id> RTransaction::cloneIds
protected

◆ existingBlockDetectionDisabled

bool RTransaction::existingBlockDetectionDisabled
protected

True to disable detection of existing blocks (performance gain).

◆ existingLayerDetectionDisabled

bool RTransaction::existingLayerDetectionDisabled
protected

True to disable detection of existing layers (performance gain).

◆ existingLinetypeDetectionDisabled

bool RTransaction::existingLinetypeDetectionDisabled
protected

True to disable detection of existing linetypes (performance gain).

◆ failed

bool RTransaction::failed
protected

True if this transaction failed.

◆ keepChildren

bool RTransaction::keepChildren
protected

True to keep and not delete child entities (block attributes for block references).

◆ keepHandles

bool RTransaction::keepHandles
protected

True to keep existing object handles (importers).

◆ onlyChanges

bool RTransaction::onlyChanges
protected

True if this transaction only changed objects, no additions, no deletes.

◆ propertyChanges

QMap<RObject::Id, QList<RPropertyChange> > RTransaction::propertyChanges
protected

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

bool RTransaction::recordAffectedObjects
protected

True if caller is interested in list of objects that are affected by this transaction.

◆ redoing

bool RTransaction::redoing
protected

◆ spatialIndexDisabled

bool RTransaction::spatialIndexDisabled
protected

True to ignore spatial index.

Used for importers which regenerate the spatial index in the end.

◆ statusChanges

QSet<RObject::Id> RTransaction::statusChanges
protected

Contains affected objects that have been created or deleted in this transaction.

◆ storage

RStorage* RTransaction::storage
protected

A transaction always belongs to the storage of a document.

◆ text

QString RTransaction::text
protected

Log entry for this transaction.

◆ transactionGroup

int RTransaction::transactionGroup
protected

Transaction group or -1.

Transaction groups are undone / redone together.

◆ transactionId

int RTransaction::transactionId
protected

Unique ID of this transaction.

◆ types

RTransaction::Types RTransaction::types
protected

◆ undoable

bool RTransaction::undoable
protected

Child transactions of this transaction.

True if this transaction can be undone.

◆ undoing

bool RTransaction::undoing
protected

The documentation for this class was generated from the following files: