Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDocumentUndoStore Class Reference

#include <kis_document_undo_store.h>

+ Inheritance diagram for KisDocumentUndoStore:

Public Member Functions

void addCommand (KUndo2Command *cmd) override
 
void beginMacro (const KUndo2MagicString &macroName) override
 
void endMacro () override
 
 KisDocumentUndoStore (KisDocument *doc)
 
const KUndo2CommandpresentCommand () override
 
void purgeRedoState () override
 
void undoLastCommand () override
 
- Public Member Functions inherited from KisUndoStore
 KisUndoStore ()
 
virtual ~KisUndoStore ()
 

Private Attributes

KisDocumentm_doc
 

Additional Inherited Members

- Signals inherited from KisUndoStore
void historyStateChanged ()
 

Detailed Description

Definition at line 15 of file kis_document_undo_store.h.

Constructor & Destructor Documentation

◆ KisDocumentUndoStore()

KisDocumentUndoStore::KisDocumentUndoStore ( KisDocument * doc)

The thread of the document should be the same as the store to avoid incorrect signal delivery

Definition at line 17 of file kis_document_undo_store.cpp.

18 : m_doc(doc)
19{
22 KIS_SAFE_ASSERT_RECOVER_NOOP(doc->thread() == this->thread());
23
24 // Use direct connection to avoid queueing the signal forwarding (BUG:447985)
25 connect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SIGNAL(historyStateChanged()), Qt::DirectConnection);
26}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KUndo2Stack * undoStack
void historyStateChanged()
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References connect(), KisUndoStore::historyStateChanged(), KIS_SAFE_ASSERT_RECOVER_NOOP, and KisDocument::undoStack.

Member Function Documentation

◆ addCommand()

void KisDocumentUndoStore::addCommand ( KUndo2Command * cmd)
overridevirtual

Implements KisUndoStore.

Definition at line 51 of file kis_document_undo_store.cpp.

52{
53 if(!command) return;
54 m_doc->undoStack()->push(command);
55}
void push(KUndo2Command *cmd)

References m_doc, KUndo2QStack::push(), and KisDocument::undoStack.

◆ beginMacro()

void KisDocumentUndoStore::beginMacro ( const KUndo2MagicString & macroName)
overridevirtual

Implements KisUndoStore.

Definition at line 57 of file kis_document_undo_store.cpp.

58{
59 m_doc->undoStack()->beginMacro(macroName);
60}
void beginMacro(const KUndo2MagicString &text)

References KUndo2QStack::beginMacro(), m_doc, and KisDocument::undoStack.

◆ endMacro()

void KisDocumentUndoStore::endMacro ( )
overridevirtual

Implements KisUndoStore.

Definition at line 62 of file kis_document_undo_store.cpp.

63{
65}

References KUndo2QStack::endMacro(), m_doc, and KisDocument::undoStack.

◆ presentCommand()

const KUndo2Command * KisDocumentUndoStore::presentCommand ( )
overridevirtual

WARNING: All these methods are not considered as thread-safe

Implements KisUndoStore.

Definition at line 28 of file kis_document_undo_store.cpp.

29{
30 return m_doc->undoStack()->command(m_doc->undoStack()->index() - 1);
31}
int index() const
const KUndo2Command * command(int index) const

References KUndo2QStack::command(), KUndo2QStack::index(), m_doc, and KisDocument::undoStack.

◆ purgeRedoState()

void KisDocumentUndoStore::purgeRedoState ( )
overridevirtual

Implements KisUndoStore.

Definition at line 67 of file kis_document_undo_store.cpp.

68{
70}
void purgeRedoState()

References m_doc, KUndo2QStack::purgeRedoState(), and KisDocument::undoStack.

◆ undoLastCommand()

void KisDocumentUndoStore::undoLastCommand ( )
overridevirtual

FIXME: Added as a workaround for being able to cancel creation of the new adjustment mask (or any other mask whose creation can be cancelled).

Ideally, we should use "addToIndex-commit" technique like git does. When a user presses Create button, we call command->redo() and save this command in a cache. When the user confirms creation of the layer with "OK" button, we "commit" the command to the undoStack. If the user changes his mind and presses Cancel, we just call command->undo() and remove the cache without committing it to the undoStack

Implements KisUndoStore.

Definition at line 33 of file kis_document_undo_store.cpp.

34{
48 m_doc->undoStack()->undo();
49}
virtual void undo()

References m_doc, KUndo2QStack::undo(), and KisDocument::undoStack.

Member Data Documentation

◆ m_doc

KisDocument* KisDocumentUndoStore::m_doc
private

Definition at line 28 of file kis_document_undo_store.h.


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