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

#include <kis_saved_commands.h>

+ Inheritance diagram for KisSavedMacroCommand:

Classes

struct  Private
 

Public Member Functions

void addCommand (KUndo2CommandSP command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
 
bool canAnnihilateWith (const KUndo2Command *command) const override
 
void getCommandExecutionJobs (QVector< KisStrokeJobData * > *jobs, bool undo, bool shouldGoToHistory=true) const
 
int id () const override
 
 KisSavedMacroCommand (const KUndo2MagicString &name, KisStrokesFacade *strokesFacade)
 
bool mergeWith (const KUndo2Command *command) override
 
void setMacroId (int value)
 
void setOverrideInfo (const KisSavedMacroCommand *overriddenCommand, const QVector< const KUndo2Command * > &skipWhileOverride)
 
 ~KisSavedMacroCommand () override
 
- Public Member Functions inherited from KisSavedCommandBase
 KisSavedCommandBase (const KUndo2MagicString &name, KisStrokesFacade *strokesFacade)
 
void redo () override
 
void undo () override
 
 ~KisSavedCommandBase () override
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Protected Member Functions

void addCommands (KisStrokeId id, bool undo) override
 
- Protected Member Functions inherited from KisSavedCommandBase
KisStrokesFacadestrokesFacade ()
 

Private Attributes

Private *const m_d
 

Detailed Description

Definition at line 87 of file kis_saved_commands.h.

Constructor & Destructor Documentation

◆ KisSavedMacroCommand()

KisSavedMacroCommand::KisSavedMacroCommand ( const KUndo2MagicString & name,
KisStrokesFacade * strokesFacade )

Definition at line 162 of file kis_saved_commands.cpp.

165 m_d(new Private())
166{
167}
KisStrokesFacade * strokesFacade()
KisSavedCommandBase(const KUndo2MagicString &name, KisStrokesFacade *strokesFacade)

◆ ~KisSavedMacroCommand()

KisSavedMacroCommand::~KisSavedMacroCommand ( )
override

Definition at line 169 of file kis_saved_commands.cpp.

170{
171 delete m_d;
172}

References m_d.

Member Function Documentation

◆ addCommand()

Definition at line 298 of file kis_saved_commands.cpp.

301{
302 Private::SavedCommand item;
303 item.command = command;
304 item.sequentiality = sequentiality;
305 item.exclusivity = exclusivity;
306
307 m_d->commands.append(item);
308}

References KisSavedMacroCommand::Private::SavedCommand::command, KisSavedMacroCommand::Private::commands, KisSavedMacroCommand::Private::SavedCommand::exclusivity, m_d, and KisSavedMacroCommand::Private::SavedCommand::sequentiality.

◆ addCommands()

void KisSavedMacroCommand::addCommands ( KisStrokeId id,
bool undo )
overrideprotectedvirtual

Implements KisSavedCommandBase.

Definition at line 344 of file kis_saved_commands.cpp.

345{
348
349 Q_FOREACH (KisStrokeJobData *job, jobs) {
350 strokesFacade()->addJob(id, job);
351 }
352}
void getCommandExecutionJobs(QVector< KisStrokeJobData * > *jobs, bool undo, bool shouldGoToHistory=true) const
virtual void addJob(KisStrokeId id, KisStrokeJobData *data)=0

References KisStrokesFacade::addJob(), getCommandExecutionJobs(), KisSavedCommandBase::strokesFacade(), and KisSavedCommandBase::undo().

◆ canAnnihilateWith()

bool KisSavedMacroCommand::canAnnihilateWith ( const KUndo2Command * other) const
overridevirtual

Attempts to merge this command with command and checks if the two commands compensate each other. If the function returns true, both commands are removed from the stack.

If this function returns true, calling this command's redo() followed by other redo() must have no effect.

The function itself shouldn't do any changes to the command, because after returning true, the command will be deleted as a "noop"

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 259 of file kis_saved_commands.cpp.

260{
261 const KisSavedMacroCommand *other =
262 dynamic_cast<const KisSavedMacroCommand*>(command);
263
264 if (!other || other->id() != id() || id() < 0 || other->id() < 0) return false;
265
266 QVector<Private::SavedCommand> &otherCommands = other->m_d->commands;
267
268 if (other->m_d->overriddenCommand) return false;
269 if (m_d->commands.size() != otherCommands.size()) return false;
270
271 auto it = m_d->commands.constBegin();
272 auto end = m_d->commands.constEnd();
273
274 auto otherIt = otherCommands.constBegin();
275 auto otherEnd = otherCommands.constEnd();
276
277 bool sameCommands = true;
278 while (it != end && otherIt != otherEnd) {
279
280 if (!it->command->canAnnihilateWith(otherIt->command.data()) ||
281 it->command->id() < 0 || otherIt->command->id() < 0 ||
282 it->command->id() != otherIt->command->id() ||
283 it->sequentiality != otherIt->sequentiality ||
284 it->exclusivity != otherIt->exclusivity) {
285
286 sameCommands = false;
287 break;
288 }
289 ++it;
290 ++otherIt;
291 }
292
293 if (!sameCommands) return false;
294
295 return true;
296}
int id() const override
const KisSavedMacroCommand * overriddenCommand

References KisSavedMacroCommand::Private::commands, id(), m_d, and KisSavedMacroCommand::Private::overriddenCommand.

◆ getCommandExecutionJobs()

void KisSavedMacroCommand::getCommandExecutionJobs ( QVector< KisStrokeJobData * > * jobs,
bool undo,
bool shouldGoToHistory = true ) const

Definition at line 310 of file kis_saved_commands.cpp.

311{
313
314 if(!undo) {
315 for(it = m_d->commands.begin(); it != m_d->commands.end(); it++) {
316 *jobs << new KisStrokeStrategyUndoCommandBased::
317 Data(it->command,
318 undo,
319 it->sequentiality,
320 it->exclusivity,
321 shouldGoToHistory);
322 }
323 }
324 else {
325 for(it = m_d->commands.end(); it != m_d->commands.begin();) {
326 --it;
327
328 *jobs << new KisStrokeStrategyUndoCommandBased::
329 Data(it->command,
330 undo,
331 it->sequentiality,
332 it->exclusivity,
333 shouldGoToHistory);
334 }
335 }
336}

References KisSavedMacroCommand::Private::commands, m_d, and KisSavedCommandBase::undo().

◆ id()

int KisSavedMacroCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 179 of file kis_saved_commands.cpp.

References m_d, and KisSavedMacroCommand::Private::macroId.

◆ mergeWith()

bool KisSavedMacroCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 184 of file kis_saved_commands.cpp.

185{
186 const KisSavedMacroCommand *other =
187 dynamic_cast<const KisSavedMacroCommand*>(command);
188
189 if (!other || other->id() != id() || id() < 0 || other->id() < 0) return false;
190
191 QVector<Private::SavedCommand> &otherCommands = other->m_d->commands;
192
193 if (other->m_d->overriddenCommand == this) {
194 m_d->commands.clear();
195
196 Q_FOREACH (Private::SavedCommand cmd, other->m_d->commands) {
197 if (!other->m_d->skipWhenOverride.contains(cmd.command.data())) {
198 m_d->commands.append(cmd);
199 }
200 }
201
202 if (other->extraData()) {
203 setExtraData(other->extraData()->clone());
204 } else {
205 setExtraData(0);
206 }
207 return true;
208 }
209
210 if (m_d->commands.size() != otherCommands.size()) return false;
211
212 auto it = m_d->commands.constBegin();
213 auto end = m_d->commands.constEnd();
214
215 auto otherIt = otherCommands.constBegin();
216 auto otherEnd = otherCommands.constEnd();
217
218 bool sameCommands = true;
219 while (it != end && otherIt != otherEnd) {
221 dynamic_cast<KisAsynchronouslyMergeableCommandInterface*>(it->command.data());
222
223 if (!iface1 || !iface1->canMergeWith(otherIt->command.data()) ||
224 it->command->id() < 0 || otherIt->command->id() < 0 ||
225 it->command->id() != otherIt->command->id() ||
226 it->sequentiality != otherIt->sequentiality ||
227 it->exclusivity != otherIt->exclusivity) {
228
229 sameCommands = false;
230 break;
231 }
232 ++it;
233 ++otherIt;
234 }
235
236 if (!sameCommands) return false;
237
238 it = m_d->commands.constBegin();
239 otherIt = otherCommands.constBegin();
240
241 while (it != end && otherIt != otherEnd) {
242 if (it->command->id() != -1) {
243 bool result = it->command->mergeWith(otherIt->command.data());
244 KIS_ASSERT_RECOVER(result) { return false; }
245 }
246 ++it;
247 ++otherIt;
248 }
249
250 if (other->extraData()) {
251 setExtraData(other->extraData()->clone());
252 } else {
253 setExtraData(0);
254 }
255
256 return true;
257}
virtual KUndo2CommandExtraData * clone() const =0
KUndo2CommandExtraData * extraData() const
void setExtraData(KUndo2CommandExtraData *data)
virtual bool canMergeWith(const KUndo2Command *command) const =0
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55
QVector< const KUndo2Command * > skipWhenOverride

References KisAsynchronouslyMergeableCommandInterface::canMergeWith(), KUndo2CommandExtraData::clone(), KisSavedMacroCommand::Private::SavedCommand::command, KisSavedMacroCommand::Private::commands, KUndo2Command::extraData(), id(), KIS_ASSERT_RECOVER, m_d, KisSavedMacroCommand::Private::overriddenCommand, KUndo2Command::setExtraData(), and KisSavedMacroCommand::Private::skipWhenOverride.

◆ setMacroId()

void KisSavedMacroCommand::setMacroId ( int value)

Definition at line 174 of file kis_saved_commands.cpp.

175{
176 m_d->macroId = value;
177}
float value(const T *src, size_t ch)

References m_d, KisSavedMacroCommand::Private::macroId, and value().

◆ setOverrideInfo()

void KisSavedMacroCommand::setOverrideInfo ( const KisSavedMacroCommand * overriddenCommand,
const QVector< const KUndo2Command * > & skipWhileOverride )

Definition at line 338 of file kis_saved_commands.cpp.

339{
340 m_d->overriddenCommand = overriddenCommand;
341 m_d->skipWhenOverride = skipWhileOverride;
342}

References m_d, KisSavedMacroCommand::Private::overriddenCommand, and KisSavedMacroCommand::Private::skipWhenOverride.

Member Data Documentation

◆ m_d

Private* const KisSavedMacroCommand::m_d
private

Definition at line 111 of file kis_saved_commands.h.


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