Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_stroke_strategy_undo_command_based.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QMutexLocker>
13
14
16{
17 // acts as a key function
18}
19
39
43 m_undo(false),
44 m_initCommand(rhs.m_initCommand),
45 m_finishCommand(rhs.m_finishCommand),
46 m_undoFacade(rhs.m_undoFacade),
47 m_macroCommand(0)
48{
50 !rhs.m_undo &&
51 "After the stroke has been started, no copying must happen");
52}
53
59
61{
62 if(!command) return;
63
64 if (MutatedCommandInterface *mutatedCommand = dynamic_cast<MutatedCommandInterface*>(command.data())) {
65 mutatedCommand->setRunnableJobsInterface(this->runnableJobsInterface());
66 }
67
68 if(undo) {
69 command->undo();
70 } else {
71 command->redo();
72 }
73}
74
86
102
109
111{
112 QMutexLocker locker(&m_mutex);
113 if(m_macroCommand) {
115
116 delete m_macroCommand;
117 m_macroCommand = 0;
118 }
119}
120
122{
123 Data *d = dynamic_cast<Data*>(data);
124
125 if (d) {
126 executeCommand(d->command, d->undo);
127 if (d->shouldGoToHistory) {
128 notifyCommandDone(d->command,
129 d->sequentiality(),
130 d->exclusivity());
131 }
132 } else {
134 }
135
136}
137
141{
142 if (!command) return;
143
144 executeCommand(command, false);
145 notifyCommandDone(command, sequentiality, exclusivity);
146}
147
151{
152 if(!command) return;
153
154 QMutexLocker locker(&m_mutex);
155 if(m_macroCommand) {
156 m_macroCommand->addCommand(command, sequentiality, exclusivity);
157 }
158}
159
161{
163 warnKrita << "WARNING: KisStrokeStrategyUndoCommandBased::setCommandExtraData():"
164 << "the extra data is set while the stroke has already been started!"
165 << "The result is undefined, continued actions may not work!";
166 }
167
168 m_commandExtraData.reset(data);
169}
170
175
177{
178 if (m_commandExtraData) {
179 command->setExtraData(m_commandExtraData.take());
180 }
181
182 KisSavedMacroCommand *savedCommand = dynamic_cast<KisSavedMacroCommand*>(command);
183 if (savedCommand) {
184 savedCommand->setMacroId(m_macroId);
185 }
186}
187
float value(const T *src, size_t ch)
void setExtraData(KUndo2CommandExtraData *data)
void addMacro(KisSavedMacroCommand *macro)
KisSavedMacroCommand * createMacro(const KUndo2MagicString &macroName)
KisRunnableStrokeJobsInterface * runnableJobsInterface() const
void doStrokeCallback(KisStrokeJobData *data) override
void getCommandExecutionJobs(QVector< KisStrokeJobData * > *jobs, bool undo, bool shouldGoToHistory=true) const
void addCommand(KUndo2CommandSP command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
void enableJob(JobType type, bool enable=true, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
virtual void postProcessToplevelCommand(KUndo2Command *command)
Applies some modifications (e.g. assigning extra data) to the toplevel command.
QScopedPointer< KUndo2CommandExtraData > m_commandExtraData
void notifyCommandDone(KUndo2CommandSP command, KisStrokeJobData::Sequentiality sequentiality, KisStrokeJobData::Exclusivity exclusivity)
void runAndSaveCommand(KUndo2CommandSP command, KisStrokeJobData::Sequentiality sequentiality, KisStrokeJobData::Exclusivity exclusivity)
KisStrokeStrategyUndoCommandBased(const KUndo2MagicString &name, bool undo, KisStrokeUndoFacade *undoFacade, KUndo2CommandSP initCommand=KUndo2CommandSP(0), KUndo2CommandSP finishCommand=KUndo2CommandSP(0))
void doStrokeCallback(KisStrokeJobData *data) override
void executeCommand(KUndo2CommandSP command, bool undo)
void cancelStrokeCallbackImpl(QVector< KisStrokeJobData * > &mutatedJobs)
void setAsynchronouslyCancellable(bool value)
void addMutatedJobs(const QVector< KisStrokeJobData * > list)
void setClearsRedoOnStart(bool value)
KUndo2MagicString name() const
virtual KisPostExecutionUndoAdapter * postExecutionUndoAdapter() const =0
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97
#define warnKrita
Definition kis_debug.h:87