Krita Source Code Documentation
Loading...
Searching...
No Matches
UndoStack Class Reference
+ Inheritance diagram for UndoStack:

Classes

struct  PostponedJob
 

Public Member Functions

void notifySetIndexChangedOneCommand () override
 
void redo () override
 
void setIndex (int idx) override
 
void undo () override
 
 UndoStack (KisDocument *doc)
 
- Public Member Functions inherited from KUndo2Stack
QAction * createRedoAction (KisKActionCollection *actionCollection, const QString &actionName=QString())
 
QAction * createUndoAction (KisKActionCollection *actionCollection, const QString &actionName=QString())
 
 KUndo2Stack (QObject *parent=0)
 
- Public Member Functions inherited from KUndo2QStack
QString actionText (int idx) const
 
void beginMacro (const KUndo2MagicString &text)
 
bool canRedo () const
 
bool canUndo () const
 
int cleanIndex () const
 
void clear ()
 
const KUndo2Commandcommand (int index) const
 
int count () const
 
QAction * createRedoAction (QObject *parent) const
 
QAction * createUndoAction (QObject *parent) const
 
KisCumulativeUndoData cumulativeUndoData ()
 
void endMacro ()
 
int index () const
 
bool isActive () const
 
bool isClean () const
 
 KUndo2QStack (QObject *parent=0)
 
void push (KUndo2Command *cmd)
 
QString redoText () const
 
void setCumulativeUndoData (const KisCumulativeUndoData &data)
 
void setUndoLimit (int limit)
 
void setUseCumulativeUndoRedo (bool value)
 
QString text (int idx) const
 
int undoLimit () const
 
QString undoText () const
 
bool useCumulativeUndoRedo () const
 
 ~KUndo2QStack () override
 

Private Member Functions

KisImageWSP image ()
 
void processPostponedJobs ()
 
void redoImpl ()
 
void setIndexImpl (int idx)
 
void undoImpl ()
 

Private Attributes

KisDocumentm_doc
 
QQueue< PostponedJobm_postponedJobs
 
int m_recursionCounter = 0
 

Additional Inherited Members

- Public Slots inherited from KUndo2QStack
void purgeRedoState ()
 
void setActive (bool active=true)
 
void setClean ()
 
- Signals inherited from KUndo2QStack
void canRedoChanged (bool canRedo)
 
void canUndoChanged (bool canUndo)
 
void cleanChanged (bool clean)
 
void indexChanged (int idx)
 
void redoTextChanged (const QString &redoActionText)
 
void undoTextChanged (const QString &undoActionText)
 
- Properties inherited from KUndo2QStack
bool active
 the active status of this stack.
 
int undoLimit
 the maximum number of commands on this stack.
 

Detailed Description

Definition at line 167 of file KisDocument.cpp.

Constructor & Destructor Documentation

◆ UndoStack()

UndoStack::UndoStack ( KisDocument * doc)
inline

Definition at line 170 of file KisDocument.cpp.

171 : KUndo2Stack(doc),
172 m_doc(doc)
173 {
174 }
KUndo2Stack(QObject *parent=0)
KisDocument * m_doc

Member Function Documentation

◆ image()

KisImageWSP UndoStack::image ( )
inlineprivate

Definition at line 207 of file KisDocument.cpp.

207 {
208 KisImageWSP currentImage = m_doc->image();
209 Q_ASSERT(currentImage);
210 return currentImage;
211 }
KisImageSP image

References KisDocument::image, and m_doc.

◆ notifySetIndexChangedOneCommand()

void UndoStack::notifySetIndexChangedOneCommand ( )
inlineoverridevirtual

Called by setIndex after every command execution. It is needed by Krita to insert barriers between different kind of commands

Some very weird commands may Q_EMIT blocking signals to the GUI (e.g. KisGuiContextCommand). Here is the best thing we can do to avoid the deadlock

Reimplemented from KUndo2QStack.

Definition at line 181 of file KisDocument.cpp.

181 {
182 KisImageWSP image = this->image();
183 image->unlock();
184
190 while(!image->tryBarrierLock()) {
191 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
192 }
193 }
void unlock()
Definition kis_image.cc:805
bool tryBarrierLock(bool readOnly=false)
Tries to lock the image without waiting for the jobs to finish.
Definition kis_image.cc:771
KisImageWSP image()

References image(), KisImage::tryBarrierLock(), and KisImage::unlock().

◆ processPostponedJobs()

void UndoStack::processPostponedJobs ( )
inlineprivate

Some undo commands may call QApplication::processEvents(), see notifySetIndexChangedOneCommand(). That may cause recursive calls to the undo stack methods when used from the Undo History docker. Here we try to handle that gracefully by accumulating all the requests and executing them at the topmost level of recursion.

Definition at line 246 of file KisDocument.cpp.

246 {
255 if (m_recursionCounter > 0) return;
256
258
259 while (!m_postponedJobs.isEmpty()) {
260 PostponedJob job = m_postponedJobs.dequeue();
261 switch (job.type) {
263 setIndexImpl(job.index);
264 break;
266 redoImpl();
267 break;
269 undoImpl();
270 break;
271 }
272 }
273
275 }
QQueue< PostponedJob > m_postponedJobs
int m_recursionCounter
void undoImpl()
void redoImpl()
void setIndexImpl(int idx)

References UndoStack::PostponedJob::index, m_postponedJobs, m_recursionCounter, UndoStack::PostponedJob::Redo, redoImpl(), UndoStack::PostponedJob::SetIndex, setIndexImpl(), UndoStack::PostponedJob::type, UndoStack::PostponedJob::Undo, and undoImpl().

◆ redo()

void UndoStack::redo ( )
inlineoverridevirtual

Redoes the current command by calling KUndo2Command::redo(). Increments the current command index.

If the stack is empty, or if the top command on the stack has already been redone, this function does nothing.

See also
undo() index()

Reimplemented from KUndo2QStack.

Definition at line 201 of file KisDocument.cpp.

201 {
204 }
void processPostponedJobs()

References m_postponedJobs, processPostponedJobs(), and UndoStack::PostponedJob::Redo.

◆ redoImpl()

void UndoStack::redoImpl ( )
inlineprivate

Definition at line 236 of file KisDocument.cpp.

236 {
237 KisImageWSP image = this->image();
239
240 if(image->tryBarrierLock()) {
242 image->unlock();
243 }
244 }
virtual void redo()
void requestRedoDuringStroke()

References image(), KUndo2QStack::redo(), KisImage::requestRedoDuringStroke(), KisImage::tryBarrierLock(), and KisImage::unlock().

◆ setIndex()

void UndoStack::setIndex ( int idx)
inlineoverridevirtual

Repeatedly calls undo() or redo() until the current command index reaches idx. This function can be used to roll the state of the document forwards of backwards. indexChanged() is emitted only once.

See also
index() count() undo() redo()

Reimplemented from KUndo2QStack.

Definition at line 176 of file KisDocument.cpp.

176 {
179 }

References m_postponedJobs, processPostponedJobs(), and UndoStack::PostponedJob::SetIndex.

◆ setIndexImpl()

void UndoStack::setIndexImpl ( int idx)
inlineprivate

Definition at line 213 of file KisDocument.cpp.

213 {
214 KisImageWSP image = this->image();
216 if(image->tryBarrierLock()) {
218 image->unlock();
219 }
220 }
virtual void setIndex(int idx)
void requestStrokeCancellation()

References image(), KisImage::requestStrokeCancellation(), KUndo2QStack::setIndex(), KisImage::tryBarrierLock(), and KisImage::unlock().

◆ undo()

void UndoStack::undo ( )
inlineoverridevirtual

Undoes the command below the current command by calling KUndo2Command::undo(). Decrements the current command index.

If the stack is empty, or if the bottom command on the stack has already been undone, this function does nothing.

See also
redo() index()

Reimplemented from KUndo2QStack.

Definition at line 195 of file KisDocument.cpp.

195 {
198 }

References m_postponedJobs, processPostponedJobs(), and UndoStack::PostponedJob::Undo.

◆ undoImpl()

void UndoStack::undoImpl ( )
inlineprivate

Definition at line 222 of file KisDocument.cpp.

222 {
223 KisImageWSP image = this->image();
225
227 return;
228 }
229
230 if(image->tryBarrierLock()) {
232 image->unlock();
233 }
234 }
virtual void undo()
UndoResult tryUndoUnfinishedLod0Stroke()
void requestUndoDuringStroke()

References image(), KisImage::requestUndoDuringStroke(), KisImage::tryBarrierLock(), KisImage::tryUndoUnfinishedLod0Stroke(), KUndo2QStack::undo(), UNDO_OK, and KisImage::unlock().

Member Data Documentation

◆ m_doc

KisDocument* UndoStack::m_doc
private

Definition at line 291 of file KisDocument.cpp.

◆ m_postponedJobs

QQueue<PostponedJob> UndoStack::m_postponedJobs
private

Definition at line 289 of file KisDocument.cpp.

◆ m_recursionCounter

int UndoStack::m_recursionCounter = 0
private

Definition at line 278 of file KisDocument.cpp.


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