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 KUndo2Command * command (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

KisDocument * m_doc
 
QQueue< PostponedJob > m_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 169 of file KisDocument.cpp.

Constructor & Destructor Documentation

◆ UndoStack()

UndoStack::UndoStack ( KisDocument * doc)
inline

Definition at line 172 of file KisDocument.cpp.

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

Member Function Documentation

◆ image()

KisImageWSP UndoStack::image ( )
inlineprivate

Definition at line 209 of file KisDocument.cpp.

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

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

248 {
257 if (m_recursionCounter > 0) return;
258
260
261 while (!m_postponedJobs.isEmpty()) {
262 PostponedJob job = m_postponedJobs.dequeue();
263 switch (job.type) {
265 setIndexImpl(job.index);
266 break;
268 redoImpl();
269 break;
271 undoImpl();
272 break;
273 }
274 }
275
277 }
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 203 of file KisDocument.cpp.

203 {
206 }
void processPostponedJobs()

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

◆ redoImpl()

void UndoStack::redoImpl ( )
inlineprivate

Definition at line 238 of file KisDocument.cpp.

238 {
239 KisImageWSP image = this->image();
241
242 if(image->tryBarrierLock()) {
244 image->unlock();
245 }
246 }
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 178 of file KisDocument.cpp.

178 {
181 }

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

◆ setIndexImpl()

void UndoStack::setIndexImpl ( int idx)
inlineprivate

Definition at line 215 of file KisDocument.cpp.

215 {
216 KisImageWSP image = this->image();
218 if(image->tryBarrierLock()) {
220 image->unlock();
221 }
222 }
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 197 of file KisDocument.cpp.

197 {
200 }

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

◆ undoImpl()

void UndoStack::undoImpl ( )
inlineprivate

Definition at line 224 of file KisDocument.cpp.

224 {
225 KisImageWSP image = this->image();
227
229 return;
230 }
231
232 if(image->tryBarrierLock()) {
234 image->unlock();
235 }
236 }
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 293 of file KisDocument.cpp.

◆ m_postponedJobs

QQueue<PostponedJob> UndoStack::m_postponedJobs
private

Definition at line 291 of file KisDocument.cpp.

◆ m_recursionCounter

int UndoStack::m_recursionCounter = 0
private

Definition at line 280 of file KisDocument.cpp.


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