Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

UndoManager Class Reference

UndoManager handles the undo stack. More...

#include <undomanager.h>

Collaboration diagram for UndoManager:

Collaboration graph
[legend]

List of all members.

Public Slots

void languageChange ()
 Updates strings when the GUI language is changed.
void action (UndoObject *target, UndoState *state, QPixmap *targetPixmap=0)
 Adds a new action to the undo stack.
void action (UndoObject *target, UndoState *state, const QString &targetName, QPixmap *targetPixmap=0)
 Adds a new action to the undo stack.
void undo (int steps)
 Informs UndoManager to perform undo.
void redo (int steps)
 Informs UndoManager to perform redo.
void showObject (int uid)
 Switches the state of UndoManager (global/object specific undo).
void setHistoryLength (int steps)
 Sets the length of the undo stack.
void setAllHistoryLengths (int steps)

Signals

void newAction (UndoObject *target, UndoState *state)
 Emitted when a new undo action is stored to the undo stack.
void undoSignal (int steps)
 Emitted when an undo action has been done.
void redoSignal (int steps)
 Emitted when a redo action has been done.
void clearRedo ()
 Emitted when a new actions comes in and UndoManager is in object.
void popBack ()
 This signal is used to notify registered UndoGui instances that.
void undoRedoDone ()
 This signal is emitted when all requested undo/redo actions have been done.

Public Member Functions

void setUndoEnabled (bool isEnabled)
 Sets the undo action tracking enabled or disabled.
UndoTransaction beginTransaction (const QString &targetName="", QPixmap *targetPixmap=0, const QString &actionName="", const QString &description="", QPixmap *actionPixmap=0)
 Start a transaction.
bool isTransactionMode ()
 Cancels the current transaction and deletes groupped UndoStates.
void registerGui (UndoGui *gui)
 Register an UndoGui to the UndoManager.
void removeGui (UndoGui *gui)
 Removes an UndoGui from UndoManager.
void switchStack (const QString &stackName)
 Changes the active undo stack.
void renameStack (const QString &newName)
 Rename the current stack.
void removeStack (const QString &stackName)
 Remove the stack with the name stackName.
void clearStack ()
bool hasUndoActions (int uid=-1)
 Returns true if there are actions that can be undone otherwise returns false.
bool hasRedoActions (int uid=-1)
 Returns true if there are actions that can be redone otherwise returns false.
UndoObjectreplaceObject (ulong uid, UndoObject *newUndoObject)
 Replace an UndoObject with the id uid with a new UndoObject new.
int getHistoryLength ()
 Returns the maximum length of the undostack.
bool isGlobalMode ()
 Returns true if in global mode and false if in object specific mode.

Static Public Member Functions

static UndoManagerinstance ()
 Returns a pointer to the UndoManager instance.
static void deleteInstance ()
 Deletes the UndoManager Instance.
static bool undoEnabled ()
 Returns true if undo actions are stored, if not will return false.

Static Public Attributes

static const int GLOBAL_UNDO_MODE = -1
 Marks for a global undo mode where ever UndoOjbect id is requested.
static const int NO_UNDO_STACK = -2
 When object specific mode is requested but no suitable object is selected.
Action strings
Strings describing undo actions

static QString AddVGuide = ""
static QString AddHGuide = ""
static QString DelVGuide = ""
static QString DelHGuide = ""
static QString DelVAGuide = ""
static QString DelHAGuide = ""
static QString MoveVGuide = ""
static QString MoveHGuide = ""
static QString RemoveAllGuides = ""
static QString RemoveAllPageGuides = ""
static QString LockGuides = ""
static QString UnlockGuides = ""
static QString Move = ""
static QString Resize = ""
static QString Rotate = ""
static QString MoveFromTo = ""
static QString ResizeFromTo = ""
static QString ImageOffset = ""
static QString ImageScale = ""
static QString ImageOffsetFromTo = ""
static QString ImageScaleFromTo = ""
static QString Selection = ""
static QString Group = ""
static QString SelectionGroup = ""
static QString Create = ""
static QString CreateTo = ""
static QString AlignDistribute = ""
static QString ItemsInvolved = ""
static QString Cancel = ""
static QString SetFill = ""
static QString ColorFromTo = ""
static QString SetShade = ""
static QString SetLineColor = ""
static QString SetLineShade = ""
static QString FlipH = ""
static QString FlipV = ""
static QString Lock = ""
static QString UnLock = ""
static QString SizeLock = ""
static QString SizeUnLock = ""
static QString EnablePrint = ""
static QString DisablePrint = ""
static QString Ungroup = ""
static QString Delete = ""
static QString Rename = ""
static QString FromTo = ""
static QString ApplyMasterPage = ""
static QString Paste = ""
static QString Cut = ""
static QString Transparency = ""
static QString LineTransparency = ""
static QString LineStyle = ""
static QString LineEnd = ""
static QString LineJoin = ""
static QString LineWidth = ""
static QString NoStyle = ""
static QString CustomLineStyle = ""
static QString NoLineStyle = ""
static QString StartArrow = ""
static QString EndArrow = ""
static QString StartAndEndArrow = ""
static QString CreateTable = ""
static QString RowsCols = ""
static QString SetFont = ""
static QString SetFontSize = ""
static QString SetFontWidth = ""
static QString SetFontHeight = ""
static QString SetFontFill = ""
static QString SetFontStroke = ""
static QString SetFontFillShade = ""
static QString SetFontStrokeShade = ""
static QString SetKerning = ""
static QString SetLineSpacing = ""
static QString SetStyle = ""
static QString SetLanguage = ""
static QString AlignText = ""
static QString SetFontEffect = ""
static QString ImageFrame = ""
static QString TextFrame = ""
static QString LatexFrame = ""
static QString Polygon = ""
static QString BezierCurve = ""
static QString Polyline = ""
static QString PathText = ""
static QString ConvertTo = ""
static QString ImportSVG = ""
static QString ImportEPS = ""
static QString ImportOOoDraw = ""
static QString ScratchSpace = ""
static QString ObjectFrame = ""
static QString BoundingBox = ""
static QString ContourLine = ""
static QString ImageClip = ""
static QString NoTextFlow = ""
static QString NoObjectFrame = ""
static QString NoBoundingBox = ""
static QString NoContourLine = ""
static QString PageNmbr = ""
static QString ImageScaling = ""
static QString FrameSize = ""
static QString FreeScaling = ""
static QString KeepRatio = ""
static QString BreakRatio = ""
static QString EditContourLine = ""
static QString EditShape = ""
static QString ResetContourLine = ""
static QString AddPage = ""
static QString AddPages = ""
static QString DeletePage = ""
static QString DeletePages = ""
static QString AddLayer = ""
static QString DeleteLayer = ""
static QString RenameLayer = ""
static QString RaiseLayer = ""
static QString LowerLayer = ""
static QString SendToLayer = ""
static QString PrintLayer = ""
static QString DoNotPrintLayer = ""
static QString SetLayerName = ""
static QString GetImage = ""
static QString ChangeFormula = ""
static QString MultipleDuplicate = ""
static QString ApplyTextStyle = ""
static QString MenuUndo = ""
static QString MenuUndoEmpty = ""
static QString MenuRedo = ""
static QString MenuRedoEmpty = ""
static QString EditContour = ""
static QString ResetControlPoint = ""
static QString ResetControlPoints = ""
static QString ImageEffects = ""
static QString InsertFrame = ""
static QString AdjustFrameToImage = ""
static QString Copy = ""
static QString CopyPage = ""
static QString ToOutlines = ""
Action icons
Icons for undo actions

static QPixmap * IImageFrame = 0
static QPixmap * ITextFrame = 0
static QPixmap * ILatexFrame = 0
static QPixmap * ILine = 0
static QPixmap * IPolygon = 0
static QPixmap * IPolyline = 0
static QPixmap * IPathText = 0
static QPixmap * IGroup = 0
static QPixmap * ILayer = 0
static QPixmap * IMove = 0
static QPixmap * IResize = 0
static QPixmap * IRotate = 0
static QPixmap * IGuides = 0
static QPixmap * ILockGuides = 0
static QPixmap * IAlignDistribute = 0
static QPixmap * IFill = 0
static QPixmap * IShade = 0
static QPixmap * IFlipH = 0
static QPixmap * IFlipV = 0
static QPixmap * ILock = 0
static QPixmap * IUnLock = 0
static QPixmap * IEnablePrint = 0
static QPixmap * IDisablePrint = 0
static QPixmap * IDelete = 0
static QPixmap * ICreate = 0
static QPixmap * IPaste = 0
static QPixmap * ICut = 0
static QPixmap * ITransparency = 0
static QPixmap * ILineStyle = 0
static QPixmap * IArrow = 0
static QPixmap * ITable = 0
static QPixmap * IFont = 0
static QPixmap * ISVG = 0
static QPixmap * IEPS = 0
static QPixmap * IImportOOoDraw = 0
static QPixmap * IImageScaling = 0
static QPixmap * IBorder = 0
static QPixmap * IDocument = 0
static QPixmap * ILayerAction = 0
static QPixmap * IUp = 0
static QPixmap * IDown = 0
static QPixmap * IPrint = 0
static QPixmap * IGetImage = 0
static QPixmap * IChangeFormula = 0
static QPixmap * IMultipleDuplicate = 0

Protected Member Functions

 UndoManager ()
 Creates a new UndoManager instance.
 ~UndoManager ()
 Destroys the UndoManager instance.

Private Member Functions

void setState (UndoGui *gui, int uid=-1)
 Initializes the UndoGui.
void connectGuis ()
 Disconnect all attached UndoGui instances from signals provided by this.
void disconnectGuis ()
 Connect all attached UndoGui instances to signals provided by this.
void initIcons ()
 Load icons needed for Action History window.
void setTexts ()

Private Attributes

PrefsContextprefs_
QString currentDoc_
 Doc to which the currently active stack belongs.
int currentUndoObjectId_
 Id number of the object for what the object specific undo is shown.
std::vector< TransactionData * > transactions_
 Stores the transactions which are currently started but not.
std::vector< UndoGui * > undoGuis_
 UndoGuis attached to this UndoManager.
StackMap stacks_
 Undo stacks for all open document.

Static Private Attributes

static UndoManagerinstance_ = 0
 The only instance of UndoManager available.
static bool undoEnabled_ = true
 Should undo states be stored or ignored.
static int undoEnabledCounter_ = 0
 Tracks the state of _undoEnabled.

Friends

class UndoTransaction


Detailed Description

UndoManager handles the undo stack.

UndoManager is the engine of the undo/redo handling. When ever an undoable action happens an UndoState object will be sent to the UndoManager which then stores the state in the undo stack. When an undo is requested the state is send back to it's creator which is then responsible for doing the actual undo or redo.

UndoManager also handles the UndoGuis by linking them together and reporting all undo/redo actions to the guis for them to update the visual representation. For this to work all UndoGuis need to be registered to the UndoManager with the registerGui() method.

Author:
Riku Leino tsoots@gmail.com
Date:
December 2004

Definition at line 158 of file undomanager.h.


Constructor & Destructor Documentation

UndoManager::UndoManager (  )  [protected]

UndoManager::~UndoManager (  )  [protected]

Destroys the UndoManager instance.

Definition at line 666 of file undomanager.cpp.

References stacks_.


Member Function Documentation

UndoManager * UndoManager::instance (  )  [static]

void UndoManager::deleteInstance (  )  [static]

Deletes the UndoManager Instance.

Must be called when UndoManager is no more needed.

Definition at line 659 of file undomanager.cpp.

References instance_.

Referenced by ScribusMainWindow::closeEvent().

void UndoManager::setUndoEnabled ( bool  isEnabled  ) 

bool UndoManager::undoEnabled (  )  [static]

Returns true if undo actions are stored, if not will return false.

Returns:
true if undo actions are stored, if not will return false

Definition at line 93 of file undomanager.cpp.

References undoEnabled_.

Referenced by GuideManagerCore::addHorizontal(), ScribusDoc::addLayer(), ScribusMainWindow::addNewPages(), GuideManagerCore::addVertical(), ScribusDoc::applyMasterPage(), ScribusDoc::changeLayerName(), GuideManagerCore::clearHorizontals(), GuideManagerCore::clearVerticals(), ScribusDoc::convertItemTo(), GuideManagerCore::deleteHorizontal(), ScribusDoc::deleteLayer(), ScribusMainWindow::DeletePage(), GuideManagerCore::deleteVertical(), SVGImportPlugin::import(), OODrawImportPlugin::import(), ImportPSPlugin::import(), ScribusDoc::itemAdd(), ScribusDoc::itemSelection_ApplyArrowHead(), ScribusDoc::itemSelection_DeleteItem(), ScribusDoc::itemSelection_MultipleDuplicate(), ScribusDoc::itemSelection_SendToLayer(), ScribusDoc::itemSelection_SetImageOffset(), ScribusDoc::itemSelection_SetImageScale(), ScribusDoc::itemSelection_SetImageScaleAndOffset(), ScribusDoc::lockGuides(), ScribusDoc::lowerLayerByLevel(), ScribusDoc::MirrorPolyH(), ScribusDoc::MirrorPolyV(), LegacyMode::mouseReleaseEvent(), FreehandMode::mouseReleaseEvent(), CreateMode::mouseReleaseEvent(), GuideManagerCore::moveHorizontal(), GuideManagerCore::moveVertical(), ScribusView::PasteToPage(), ScribusDoc::raiseLayerByLevel(), NodePalette::ResetContour(), PageItem_LatexFrame::setFormula(), ScribusDoc::setLayerPrintable(), ScribusMainWindow::slotEditCut(), ScribusMainWindow::slotEditPaste(), and ScribusView::TransformPoly().

UndoTransaction UndoManager::beginTransaction ( const QString &  targetName = "",
QPixmap *  targetPixmap = 0,
const QString &  actionName = "",
const QString &  description = "",
QPixmap *  actionPixmap = 0 
)

Start a transaction.

After this method has been invoked UndoManager will switch to the transaction (silent) mode where it does not report actions to the attached UndoGui widgets but stores all incoming UndoState objects into the transaction container which after call to the method commit() will be sent to the guis as a single undo action. Transaction can be named when starting it or naming can be done when commiting it.

Parameters:
targetName name for the target of this transaction (f.e. "Selection")
targetPixmap Icon for the target on which this transaction works. this icon will be drawn first when the action is presented in Action History window and icon for the action will be drawn over this one.
name name for the transaction (f.e. "Move" would make with the above "Move Selection") The result can only be used for initializing a Transaction object, eg. on the stack: Transaction groupTransaction(undoManger->beginTransaction(...)); or the heap: Transaction* groupTransactionPtr = new Transaction(undoManger->beginTransaction(...));
description description for the transaction
actionPixmap icon for the action performed by the transaction
See also:
commit()

Dummy object for storing transaction target's name

Definition at line 110 of file undomanager.cpp.

References UndoState::setDescription(), UndoState::setName(), UndoState::setPixmap(), UndoObject::setUName(), UndoObject::setUPixmap(), TransactionData::stackLevel, TransactionData::transactionObject, transactions_, TransactionData::transactionState, TransactionData::UM, undoEnabled_, and UndoTransaction.

Referenced by ScribusMainWindow::addNewPages(), NodeEditContext::beginTransaction(), ScribusDoc::ChLineArt(), ScribusDoc::ChLineEnd(), ScribusDoc::ChLineJoin(), ScribusDoc::ChLineWidth(), ScribusView::contentsDropEvent(), ScribusDoc::convertItemTo(), ScribusDoc::copyPage(), ScribusDoc::deleteLayer(), ScribusMainWindow::DeletePage(), ScribusMainWindow::doPasteRecent(), ScribusDoc::itemAdd(), ScribusDoc::itemAddUserFrame(), ScribusDoc::ItemBrush(), ScribusDoc::ItemBrushShade(), ScribusDoc::ItemPen(), ScribusDoc::ItemPenShade(), ScribusDoc::itemSelection_adjustFrametoImageSize(), ScribusDoc::itemSelection_ApplyArrowHead(), ScribusDoc::itemSelection_ApplyCharStyle(), ScribusDoc::itemSelection_ApplyParagraphStyle(), ScribusDoc::itemSelection_DeleteItem(), ScribusDoc::itemSelection_EraseCharStyle(), ScribusDoc::itemSelection_EraseParagraphStyle(), ScribusDoc::itemSelection_FlipH(), ScribusDoc::itemSelection_FlipV(), ScribusDoc::itemSelection_MultipleDuplicate(), ScribusDoc::itemSelection_SendToLayer(), ScribusDoc::itemSelection_SetCharStyle(), ScribusDoc::itemSelection_SetEffects(), ScribusDoc::itemSelection_SetImageOffset(), ScribusDoc::itemSelection_SetImageScale(), ScribusDoc::itemSelection_SetImageScaleAndOffset(), ScribusDoc::itemSelection_SetNamedLineStyle(), ScribusDoc::itemSelection_SetParagraphStyle(), ScribusDoc::itemSelection_ToggleLock(), ScribusDoc::itemSelection_TogglePrintEnabled(), ScribusDoc::itemSelection_ToggleSizeLock(), LegacyMode::mouseReleaseEvent(), FreehandMode::mouseReleaseEvent(), CreateMode::mouseReleaseEvent(), ScribusView::PasteToPage(), ScribusMainWindow::slotEditCut(), ScribusMainWindow::slotEditPaste(), ScribusDoc::startAlign(), and ScribusView::startGroupTransaction().

bool UndoManager::isTransactionMode (  ) 

Cancels the current transaction and deletes groupped UndoStates.

Nothing from canceled transaction will be sent to the undo gui widgets. Commit the current transaction.

Current transaction will be commited and UndoManager will be switched to the normal mode. Commited transaction will be sent to the attached undo gui widgets and it will show up there as a single undo action. Details used as a parameter will be details shown in the gui widgets.

Parameters:
targetName name for the target of this transaction (f.e. "Selection")
targetPixmap Icon for the target on which this transaction works. this icon will be drawn first when the action is presented in Action History window and icon for the action will be drawn over this one.
name name for the action
description description for the action
actionPixmap icon for the action performed by the transaction
See also:
beginTransaction() Returns true if in transaction mode if not will return false.
Returns:
true if in transaction mode if not will return false

Definition at line 272 of file undomanager.cpp.

References transactions_.

Referenced by action().

void UndoManager::registerGui ( UndoGui gui  ) 

Register an UndoGui to the UndoManager.

After registering a gui to the manager the gui will be updated with the undo action information received by the UndoManager. Actions done with the UndoGui to be registered are also handled after registering.

Parameters:
gui A pointer to the UndoGui that is wanted to be registered.

Definition at line 277 of file undomanager.cpp.

References setState(), setUndoEnabled(), and undoGuis_.

Referenced by ScribusMainWindow::initPalettes(), and ScribusMainWindow::initToolBars().

void UndoManager::removeGui ( UndoGui gui  ) 

Removes an UndoGui from UndoManager.

Parameters:
gui UndoGui to be removed from the UndoManager.

Definition at line 399 of file undomanager.cpp.

References undoGuis_.

void UndoManager::switchStack ( const QString &  stackName  ) 

Changes the active undo stack.

Sets the stack connected to the name stackName active. Calling this method will send clear() signal to the attached UndoGuis and will update their undo stack representations.

Parameters:
stackName Name of the stack to be used

Definition at line 412 of file undomanager.cpp.

References currentDoc_, PrefsContext::getInt(), prefs_, setState(), setTexts(), stacks_, and undoGuis_.

Referenced by ScribusMainWindow::doFileNew(), ScribusMainWindow::loadDoc(), and ScribusMainWindow::newActWin().

void UndoManager::renameStack ( const QString &  newName  ) 

Rename the current stack.

Parameters:
newName New name for the current stack.

Definition at line 427 of file undomanager.cpp.

References currentDoc_, and stacks_.

Referenced by CollectForOutput::collect(), ScribusMainWindow::DoFileSave(), and MenuNFT::RunNFTPlug().

void UndoManager::removeStack ( const QString &  stackName  ) 

Remove the stack with the name stackName.

Parameters:
stackName Name of the stack that is wanted to be removed

Definition at line 443 of file undomanager.cpp.

References currentDoc_, stacks_, and undoGuis_.

Referenced by ScribusMainWindow::DoFileClose().

void UndoManager::clearStack (  ) 

clear the current undo stack

Definition at line 458 of file undomanager.cpp.

References currentDoc_, setState(), stacks_, and undoGuis_.

Referenced by Preferences::setActionHistoryLength(), and TabDocument::slotUndo().

bool UndoManager::hasUndoActions ( int  uid = -1  ) 

Returns true if there are actions that can be undone otherwise returns false.

This is useful when undo/redo actions are handled with a gui that is not attached to the UndoManager (f.e. menu items) and when those gui items are wanted to set enabled or disabled depending on the status of the undo stack.

Returns:
true if there are actions that can be undone otherwise returns false

Definition at line 549 of file undomanager.cpp.

References currentDoc_, and stacks_.

Referenced by ContextMenu::createMenuItems_Selection().

bool UndoManager::hasRedoActions ( int  uid = -1  ) 

Returns true if there are actions that can be redone otherwise returns false.

Returns:
true if there are actions that can be redone otherwise returns false
See also:
UndoManager::hasUndoActions()

Definition at line 555 of file undomanager.cpp.

References currentDoc_, and stacks_.

Referenced by ContextMenu::createMenuItems_Selection().

UndoObject * UndoManager::replaceObject ( ulong  uid,
UndoObject newUndoObject 
)

Replace an UndoObject with the id uid with a new UndoObject new.

Parameters:
uid Id for the UndoObject that is wanted to be replaced.
newUndoObject UndoObject which will replace an old UndoObject in the stack.
Returns:
UndoObject which was replaced

Definition at line 578 of file undomanager.cpp.

References currentDoc_, UndoObject::getUId(), TransactionState::replace(), UndoState::setUndoObject(), stacks_, transactions_, and UndoState::undoObject().

Referenced by ScribusMainWindow::DeletePage().

int UndoManager::getHistoryLength (  ) 

Returns the maximum length of the undostack.

Returns:
the maximum length of the undostack

Definition at line 622 of file undomanager.cpp.

References currentDoc_, and stacks_.

Referenced by TabDocument::TabDocument().

bool UndoManager::isGlobalMode (  ) 

Returns true if in global mode and false if in object specific mode.

Returns:
true if in global mode and false if in object specific mode

Definition at line 629 of file undomanager.cpp.

References currentUndoObjectId_.

void UndoManager::setState ( UndoGui gui,
int  uid = -1 
) [private]

Initializes the UndoGui.

Parameters:
gui UndoGui to be initialized
uid UndoObject's id if in object specific mode or -1 to tell that global undo is used.

Definition at line 288 of file undomanager.cpp.

References UndoGui::clear(), TransactionState::containsOnly(), currentDoc_, UndoObject::getUId(), UndoGui::insertRedoItem(), UndoGui::insertUndoItem(), stacks_, state, and UndoState::undoObject().

Referenced by clearStack(), registerGui(), showObject(), and switchStack().

void UndoManager::connectGuis (  )  [private]

Disconnect all attached UndoGui instances from signals provided by this.

class and other UndoGui objects.

Definition at line 362 of file undomanager.cpp.

References clearRedo(), newAction(), popBack(), redo(), redoSignal(), undo(), undoGuis_, undoSignal(), and UndoGui::updateUndoActions().

Referenced by setUndoEnabled().

void UndoManager::disconnectGuis (  )  [private]

Connect all attached UndoGui instances to signals provided by this.

class and other UndoGui objects.

Definition at line 381 of file undomanager.cpp.

References clearRedo(), newAction(), popBack(), redo(), redoSignal(), undo(), undoGuis_, and undoSignal().

Referenced by setUndoEnabled().

void UndoManager::initIcons (  )  [private]