Mapper  0.9.0
API documentation
Classes | Signals | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | List of all members
OpenOrienteering::UndoManager Class Reference

Manages the history of steps for undoing and redoing changes to a map. More...

#include <undo_manager.h>

Inheritance diagram for OpenOrienteering::UndoManager:
Inheritance graph
[legend]
Collaboration diagram for OpenOrienteering::UndoManager:
Collaboration graph
[legend]

Classes

struct  State
 Keeps the state of an UndoManager. More...
 

Signals

void canUndoChanged (bool can_undo)
 This signal is emitted whenever the value of canUndo() changes. More...
 
void canRedoChanged (bool can_redo)
 This signal is emitted whenever the value of canRedo() changes. More...
 
void cleanChanged (bool clean)
 This signal is emitted whenever the value of isClean() changes. More...
 
void loadedChanged (bool loaded)
 This signal is emitted whenever the value of isLoaded() changes. More...
 

Public Member Functions

 UndoManager (Map *map)
 Constructs an empty undo manager. More...
 
 ~UndoManager () override
 Destroys the undo manager, deleting all managed steps. More...
 
void clear ()
 Deletes all undo and redo steps. More...
 
void push (std::unique_ptr< UndoStep > &&step)
 Adds a new undo step to the manager. More...
 
bool canUndo () const
 Returns true iff valid undo steps are available. More...
 
bool undo (QWidget *dialog_parent=nullptr)
 Executes the current undo step. More...
 
bool canRedo () const
 Returns true iff valid redo steps are available. More...
 
bool redo (QWidget *dialog_parent=nullptr)
 Executes the current redo step. More...
 
bool isClean () const
 Returns true iff the current state is the clean state. More...
 
void setClean ()
 Marks the current state as the clean state. More...
 
bool isLoaded () const
 Returns true iff the current state is the loaded state. More...
 
void setLoaded ()
 Marks the current state as the loaded state. More...
 
int undoStepCount () const
 Returns the current number of undo steps. More...
 
UndoStepnextUndoStep () const
 Returns the step performed by the next call to undo(). More...
 
int redoStepCount () const
 Returns the current number of redo steps. More...
 
UndoStepnextRedoStep () const
 Returns the step performed by the next call to redo(). More...
 
void saveUndo (QXmlStreamWriter &xml) const
 Saves the undo steps to the file in xml format. More...
 
void saveRedo (QXmlStreamWriter &xml) const
 Saves the undo steps to the file in xml format. More...
 
void loadUndo (QXmlStreamReader &xml, SymbolDictionary &symbol_dict)
 Loads the undo steps from the file in xml format. More...
 
void loadRedo (QXmlStreamReader &xml, SymbolDictionary &symbol_dict)
 Loads the redo steps from the file in xml format. More...
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
 QObject (QObject *parent)
 
virtual ~QObject ()
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 Q_CLASSINFO (Name, Value)
 
 Q_INTERFACES (...)
 
 Q_PROPERTY (...)
 
 Q_ENUMS (...)
 
 Q_FLAGS (...)
 
 Q_ENUM (...)
 
 Q_FLAG (...)
 
 Q_ENUM_NS (...)
 
 Q_FLAG_NS (...)
 
 Q_OBJECT Q_OBJECT
 
 Q_GADGET Q_GADGET
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SLOTS Q_SLOTS
 
 Q_SLOT Q_SLOT
 
 Q_EMIT Q_EMIT
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 

Static Public Attributes

static constexpr std::size_t max_undo_steps = 128
 The maximum number of steps kept for undo() and redo(), respectively. More...
 

Protected Types

using StepList = std::vector< std::unique_ptr< UndoStep > >
 A list of UndoSteps. More...
 

Protected Member Functions

void clearRedoSteps ()
 Deletes all redo steps and removes them from undo_steps. More...
 
void validateUndoSteps ()
 Validates the list of steps available for undo(). More...
 
void validateRedoSteps ()
 Validates the list of steps available for redo(). More...
 
void emitChangedSignals (UndoManager::State const &old_state)
 Emits "changed" signals for all properties which are different from old_state. More...
 
void updateMapState (const UndoStep *step) const
 Set the map's current part and selection from the given undo step. More...
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Manages the history of steps for undoing and redoing changes to a map.

This API is intentionally similar to QUndoStack. (QUndoStack is part of Qt since 4.2 and available under the GPL3.)

Member Typedef Documentation

◆ StepList

using OpenOrienteering::UndoManager::StepList = std::vector<std::unique_ptr<UndoStep> >
protected

A list of UndoSteps.

Constructor & Destructor Documentation

◆ UndoManager()

OpenOrienteering::UndoManager::UndoManager ( Map map)

Constructs an empty undo manager.

◆ ~UndoManager()

OpenOrienteering::UndoManager::~UndoManager ( )
override

Destroys the undo manager, deleting all managed steps.

Member Function Documentation

◆ canRedo()

bool OpenOrienteering::UndoManager::canRedo ( ) const

Returns true iff valid redo steps are available.

◆ canRedoChanged

void OpenOrienteering::UndoManager::canRedoChanged ( bool  can_redo)
signal

This signal is emitted whenever the value of canRedo() changes.

◆ canUndo()

bool OpenOrienteering::UndoManager::canUndo ( ) const

Returns true iff valid undo steps are available.

◆ canUndoChanged

void OpenOrienteering::UndoManager::canUndoChanged ( bool  can_undo)
signal

This signal is emitted whenever the value of canUndo() changes.

◆ cleanChanged

void OpenOrienteering::UndoManager::cleanChanged ( bool  clean)
signal

This signal is emitted whenever the value of isClean() changes.

◆ clear()

void OpenOrienteering::UndoManager::clear ( )

Deletes all undo and redo steps.

Can be necessary if changes are made to objects which are not tracked by the undo system but related to it.

◆ clearRedoSteps()

void OpenOrienteering::UndoManager::clearRedoSteps ( )
protected

Deletes all redo steps and removes them from undo_steps.

◆ emitChangedSignals()

void OpenOrienteering::UndoManager::emitChangedSignals ( UndoManager::State const &  old_state)
protected

Emits "changed" signals for all properties which are different from old_state.

◆ isClean()

bool OpenOrienteering::UndoManager::isClean ( ) const

Returns true iff the current state is the clean state.

◆ isLoaded()

bool OpenOrienteering::UndoManager::isLoaded ( ) const

Returns true iff the current state is the loaded state.

◆ loadedChanged

void OpenOrienteering::UndoManager::loadedChanged ( bool  loaded)
signal

This signal is emitted whenever the value of isLoaded() changes.

◆ loadRedo()

void OpenOrienteering::UndoManager::loadRedo ( QXmlStreamReader xml,
SymbolDictionary symbol_dict 
)

Loads the redo steps from the file in xml format.

Any existing redo steps will be deleted first, but undo steps are left untouched.

◆ loadUndo()

void OpenOrienteering::UndoManager::loadUndo ( QXmlStreamReader xml,
SymbolDictionary symbol_dict 
)

Loads the undo steps from the file in xml format.

Any existing undo steps and redo steps will be deleted first.

◆ nextRedoStep()

UndoStep * OpenOrienteering::UndoManager::nextRedoStep ( ) const

Returns the step performed by the next call to redo().

◆ nextUndoStep()

UndoStep * OpenOrienteering::UndoManager::nextUndoStep ( ) const

Returns the step performed by the next call to undo().

◆ push()

void OpenOrienteering::UndoManager::push ( std::unique_ptr< UndoStep > &&  step)

Adds a new undo step to the manager.

All recorded redo steps will be deleted.

◆ redo()

bool OpenOrienteering::UndoManager::redo ( QWidget dialog_parent = nullptr)

Executes the current redo step.

◆ redoStepCount()

int OpenOrienteering::UndoManager::redoStepCount ( ) const

Returns the current number of redo steps.

This figure may include invalid steps. So canRedo() may return false even if redoStepCount() is positive.

◆ saveRedo()

void OpenOrienteering::UndoManager::saveRedo ( QXmlStreamWriter xml) const

Saves the undo steps to the file in xml format.

◆ saveUndo()

void OpenOrienteering::UndoManager::saveUndo ( QXmlStreamWriter xml) const

Saves the undo steps to the file in xml format.

◆ setClean()

void OpenOrienteering::UndoManager::setClean ( )

Marks the current state as the clean state.

Whenever the manager returns to this state through the use of undo()/redo(), it emits the signal cleanChanged().

Emits cleanChanged(true) if the current state was not the clean state.

Call this when the currently edited file is loaded or saved.

◆ setLoaded()

void OpenOrienteering::UndoManager::setLoaded ( )

Marks the current state as the loaded state.

When calling undo() while in loaded state, an extra warning will be displayed.

Call this when the currently edited file is loaded.

◆ undo()

bool OpenOrienteering::UndoManager::undo ( QWidget dialog_parent = nullptr)

Executes the current undo step.

If the UndoManager is in loaded state, the user is offered the choice to cancel the operation.

Parameters
dialog_parentOptional QWidget parent for any dialogs shown by the method.
Returns
True if an undo step actually has been executed, false otherwise.

◆ undoStepCount()

int OpenOrienteering::UndoManager::undoStepCount ( ) const

Returns the current number of undo steps.

This figure may include invalid steps. So canUndo() may return false even if undoStepCount() is positive.

◆ updateMapState()

void OpenOrienteering::UndoManager::updateMapState ( const UndoStep step) const
protected

Set the map's current part and selection from the given undo step.

This method relies on the step already being applied to the map, i.e. all affected parts and objects do exist.

◆ validateRedoSteps()

void OpenOrienteering::UndoManager::validateRedoSteps ( )
protected

Validates the list of steps available for redo().

This method removes elements from undo_steps which are no longer reachable via valid steps, or which exceed the max_undo_steps limit, with invalid NoOpUndoStep objects, thus releasing the memory which was originally occupied by now obsolete undo steps.

◆ validateUndoSteps()

void OpenOrienteering::UndoManager::validateUndoSteps ( )
protected

Validates the list of steps available for undo().

In order to maintain the validness of current_index etc., this method does not remove elements from undo_steps. Instead, it replaces steps which are no longer reachable via valid steps, or which exceed the max_undo_steps limit, with invalid NoOpUndoStep objects, thus releasing the memory which was originally occupied by now obsolete undo steps.

Member Data Documentation

◆ max_undo_steps

constexpr std::size_t OpenOrienteering::UndoManager::max_undo_steps = 128
static

The maximum number of steps kept for undo() and redo(), respectively.

This limits the amount of memory occupied by undo steps.

Todo:
Make this configurable (maybe by used memory instead of step count)

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