QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RTransaction Class Reference

Transaction implementation. More...

#include <RTransaction.h>

List of all members.

Public Member Functions

void addAffectedObject (RObject::Id objectId)
 Adds the given object to the list of objects that are affected by this transaction.
void addAffectedObject (QSharedPointer< RObject > object)
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 (RObject::Id objectId, RDocument *document)
void deleteObject (QSharedPointer< RObject > object, RDocument *document)
void end ()
 Previews this transaction (as it would be applied) by exporting the result to the given exporter.
void endCycle ()
 Ends the current transaction cycle.
void fail ()
QList< RObject::IdgetAffectedObjects () const
int getId () const
QMap< RObject::Id, QList
< RPropertyChange > > 
getPropertyChanges () const
QSet< RObject::IdgetStatusChanges () const
QString getText () const
bool hasOnlyChanges () const
bool isFailed () const
bool isUndoable () const
bool overwriteBlock (QSharedPointer< RBlock > block)
 Overwrites a potentially existing block with the given block.
virtual void redo (RDocument *objectContainer=NULL)
 Applies this command to the document.
 RTransaction ()
 Copyright (c) 2011-2013 by Andrew Mustun.
 RTransaction (RStorage &storage)
 Constructs an empty, invalid transaction.
 RTransaction (RStorage &storage, int transactionId, const QString &text, const QList< RObject::Id > &affectedObjectIds, const QMap< RObject::Id, QList< RPropertyChange > > &propertyChanges)
 Constructor for existing transactions.
 RTransaction (RStorage &storage, const QString &text, bool undoable=true)
 Constructor for new transactions.
void setAllowAll (bool on)
void setAllowInvisible (bool on)
void setBlockRecursionDetectionDisabled (bool on)
void setExistingBlockDetectionDisabled (bool on)
void setExistingLayerDetectionDisabled (bool on)
void setId (int id)
 Sets the ID of this transaction.
void setKeepHandles (bool on)
void setRecordAffectedObjects (bool on)
void setSpatialIndexDisabled (bool on)
virtual void undo (RDocument *objectContainer=NULL)
 Reverts a change to the document.
void updateOverwrittenBlockReferences ()
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.
void commit ()
 Saves this command to the storage of the document.
void rollback ()

Protected Attributes

QList< RObject::IdaffectedObjectIds
 List of IDs of all objects that are affected by this transaction.
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::IdcloneIds
bool existingBlockDetectionDisabled
 True to disable detection of existing blocks (performance gain).
bool existingLayerDetectionDisabled
 True to disable detection of existing layers (performance gain).
bool failed
 True if this transaction failed.
bool keepHandles
 True to keep existing object handles (importers).
bool onlyChanges
 True if this transaction only changed objects, no additions, no deletes.
QList< RObject::IdoverwrittenBlockReferences
 List of IDs of all block references that need to be .
QMap< RObject::Id, QList
< RPropertyChange > > 
propertyChanges
 Map of properties that are changed by this transaction.
bool recordAffectedObjects
 True if caller is intereseted in list of objects that are affected by this transaction.
bool spatialIndexDisabled
 True to ignore spatial index.
QSet< RObject::IdstatusChanges
 Contains affected objects that have been created or deleted in this transaction.
RStoragestorage
 A transaction always belongs to the storage of a document.
QString text
 Log entry for this transaction.
int transactionId
 Unique ID of this transaction.
bool undoable
 Child transactions of this transaction.

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.

Scriptable:
This class is wrapped for script environments.
Copyable:
Script wrappers of this class should pass objects by reference.

Constructor & Destructor Documentation

RTransaction::RTransaction ( )

Copyright (c) 2011-2013 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::RTransaction ( RStorage storage)

Constructs an empty, invalid transaction.

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::RTransaction ( RStorage storage,
const QString &  text,
bool  undoable = true 
)

Constructor for new transactions.

RTransaction::~RTransaction ( )
virtual

Member Function Documentation

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

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

void RTransaction::addAffectedObject ( QSharedPointer< RObject object)
void RTransaction::addAffectedObjects ( const QSet< RObject::Id > &  objectIds)

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

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:
modifiedPropertyTypeId,:Property ID that has changed if known by caller, NULL otherwise.
bool RTransaction::addPropertyChange ( RObject::Id  objectId,
const RPropertyChange propertyChange 
)
protected

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

void RTransaction::commit ( )
protected

Saves this command to the storage of the document.

void RTransaction::deleteObject ( RObject::Id  objectId,
RDocument document 
)
void RTransaction::deleteObject ( QSharedPointer< RObject object,
RDocument document 
)
void RTransaction::end ( )

Previews this transaction (as it would be applied) by exporting the result to the given exporter.

The exporter typically exports into the preview of a graphics scene.

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 ( )
QList<RObject::Id> RTransaction::getAffectedObjects ( ) const
inline
Returns:
Set of object IDs of objects that are affected by this transaction.
int RTransaction::getId ( ) const
inline
Returns:
Unique ID of this transaction.
QMap<RObject::Id, QList<RPropertyChange> > RTransaction::getPropertyChanges ( ) const
inline
Returns:
Map of properties that are changed by this transaction.
QSet<RObject::Id> RTransaction::getStatusChanges ( ) const
inline
Returns:
Set of object IDs of objects that have been created or deleted by this transaction.
QString RTransaction::getText ( ) const
inline
Returns:
Logged text for this transaction.
bool RTransaction::hasOnlyChanges ( ) const
inline
bool RTransaction::isFailed ( ) const
inline
bool RTransaction::isUndoable ( ) const
inline
Returns:
True if this transaction should store undo / redo information for later undo / redo functionality.
bool RTransaction::overwriteBlock ( QSharedPointer< RBlock block)

Overwrites a potentially existing block with the given block.

void RTransaction::redo ( RDocument objectContainer = NULL)
virtual

Applies this command to the document.

(Re-)applies this transaction to the document.

void RTransaction::rollback ( )
protected
void RTransaction::setAllowAll ( bool  on)
inline
void RTransaction::setAllowInvisible ( bool  on)
inline
void RTransaction::setBlockRecursionDetectionDisabled ( bool  on)
inline
void RTransaction::setExistingBlockDetectionDisabled ( bool  on)
inline
void RTransaction::setExistingLayerDetectionDisabled ( bool  on)
inline
void RTransaction::setId ( int  id)
inline

Sets the ID of this transaction.

Typically called by a storage which manages transaction IDs.

void RTransaction::setKeepHandles ( bool  on)
inline
void RTransaction::setRecordAffectedObjects ( bool  on)
inline
void RTransaction::setSpatialIndexDisabled ( bool  on)
inline
void RTransaction::undo ( RDocument objectContainer = NULL)
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.

void RTransaction::updateOverwrittenBlockReferences ( )

Member Data Documentation

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

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

bool RTransaction::allowAll
protected

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

Typically the case for importers.

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.

bool RTransaction::blockRecursionDetectionDisabled
protected

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

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

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

bool RTransaction::existingLayerDetectionDisabled
protected

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

bool RTransaction::failed
protected

True if this transaction failed.

bool RTransaction::keepHandles
protected

True to keep existing object handles (importers).

bool RTransaction::onlyChanges
protected

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

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

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

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.

bool RTransaction::recordAffectedObjects
protected

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

bool RTransaction::spatialIndexDisabled
protected

True to ignore spatial index.

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

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

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

RStorage* RTransaction::storage
protected

A transaction always belongs to the storage of a document.

QString RTransaction::text
protected

Log entry for this transaction.

int RTransaction::transactionId
protected

Unique ID of this transaction.

bool RTransaction::undoable
protected

Child transactions of this transaction.

True if this transaction can be undone.


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