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 168 of file KisDocument.cpp.

Constructor & Destructor Documentation

◆ UndoStack()

UndoStack::UndoStack ( KisDocument * doc)
inline

Definition at line 171 of file KisDocument.cpp.

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

Member Function Documentation

◆ image()

KisImageWSP UndoStack::image ( )
inlineprivate

Definition at line 208 of file KisDocument.cpp.

208 {
209 KisImageWSP currentImage = m_doc->image();
210 Q_ASSERT(currentImage);
211 return currentImage;
212 }
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 182 of file KisDocument.cpp.

182 {
183 KisImageWSP image = this->image();
184 image->unlock();
185
191 while(!image->tryBarrierLock()) {
192 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
193 }
194 }
void unlock()
Definition kis_image.cc:806
bool tryBarrierLock(bool readOnly=false)
Tries to lock the image without waiting for the jobs to finish.
Definition kis_image.cc:772
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 247 of file KisDocument.cpp.

247 {
256 if (m_recursionCounter > 0) return;
257
259
260 while (!m_postponedJobs.isEmpty()) {
261 PostponedJob job = m_postponedJobs.dequeue();
262 switch (job.type) {
264 setIndexImpl(job.index);
265 break;
267 redoImpl();
268 break;
270 undoImpl();
271 break;
272 }
273 }
274
276 }
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 202 of file KisDocument.cpp.

202 {
205 }
void processPostponedJobs()

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

◆ redoImpl()

void UndoStack::redoImpl ( )
inlineprivate

Definition at line 237 of file KisDocument.cpp.

237 {
238 KisImageWSP image = this->image();
240
241 if(image->tryBarrierLock()) {
243 image->unlock();
244 }
245 }
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 177 of file KisDocument.cpp.

177 {
180 }

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

◆ setIndexImpl()

void UndoStack::setIndexImpl ( int idx)
inlineprivate

Definition at line 214 of file KisDocument.cpp.

214 {
215 KisImageWSP image = this->image();
217 if(image->tryBarrierLock()) {
219 image->unlock();
220 }
221 }
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 196 of file KisDocument.cpp.

196 {
199 }

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

◆ undoImpl()

void UndoStack::undoImpl ( )
inlineprivate

Definition at line 223 of file KisDocument.cpp.

223 {
224 KisImageWSP image = this->image();
226
228 return;
229 }
230
231 if(image->tryBarrierLock()) {
233 image->unlock();
234 }
235 }
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 292 of file KisDocument.cpp.

◆ m_postponedJobs

QQueue<PostponedJob> UndoStack::m_postponedJobs
private

Definition at line 290 of file KisDocument.cpp.

◆ m_recursionCounter

int UndoStack::m_recursionCounter = 0
private

Definition at line 279 of file KisDocument.cpp.


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