Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_saved_commands.h
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
7#ifndef __KIS_SAVED_COMMANDS_H
8#define __KIS_SAVED_COMMANDS_H
9
10#include <kundo2command.h>
11#include "kis_types.h"
13#include "KisCppQuirks.h"
14
16
17
18class KRITAIMAGE_EXPORT KisSavedCommandBase : public KUndo2Command
19{
20public:
21 KisSavedCommandBase(const KUndo2MagicString &name, KisStrokesFacade *strokesFacade);
22 ~KisSavedCommandBase() override;
23
24
25 void undo() override;
26 void redo() override;
27
28protected:
29 virtual void addCommands(KisStrokeId id, bool undo) = 0;
30 KisStrokesFacade* strokesFacade();
31
32private:
33 void runStroke(bool undo);
34
35private:
38};
39
40class KRITAIMAGE_EXPORT KisSavedCommand : public KisSavedCommandBase
41{
42public:
43 KisSavedCommand(KUndo2CommandSP command, KisStrokesFacade *strokesFacade);
44 int timedId() const override;
45 void setTimedID(int timedID) override;
46
47 int id() const override;
48 bool mergeWith(const KUndo2Command* command) override;
49 bool canAnnihilateWith(const KUndo2Command *command) const override;
50
51 bool timedMergeWith(KUndo2Command *other) override;
53 void setTime(const QTime &time) override;
55 QTime time() const override;
56 void setEndTime(const QTime &time) override;
58 QTime endTime() const override;
59 bool isMerged() const override;
60
66 template <typename Command, typename Func>
67 static auto unwrap(Command *cmd, Func &&func)
68 -> decltype(func(static_cast<Command*>(nullptr))) {
69
71
72 SavedCommand *savedCommand =
73 dynamic_cast<SavedCommand*>(cmd);
74
75 return savedCommand ?
76 std::forward<Func>(func)(savedCommand->m_command.data()) :
77 std::forward<Func>(func)(cmd);
78 }
79
80protected:
81 void addCommands(KisStrokeId id, bool undo) override;
82
83private:
85};
86
87class KRITAIMAGE_EXPORT KisSavedMacroCommand : public KisSavedCommandBase
88{
89public:
90 KisSavedMacroCommand(const KUndo2MagicString &name, KisStrokesFacade *strokesFacade);
91 ~KisSavedMacroCommand() override;
92
93 int id() const override;
94 bool mergeWith(const KUndo2Command* command) override;
95 bool canAnnihilateWith(const KUndo2Command *command) const override;
96
97 void setMacroId(int value);
98
99 void addCommand(KUndo2CommandSP command,
102
103 void getCommandExecutionJobs(QVector<KisStrokeJobData*> *jobs, bool undo, bool shouldGoToHistory = true) const;
104
105 void setOverrideInfo(const KisSavedMacroCommand *overriddenCommand, const QVector<const KUndo2Command *> &skipWhileOverride);
106protected:
107 void addCommands(KisStrokeId id, bool undo) override;
108
109private:
110 struct Private;
111 Private * const m_d;
112};
113
114#endif /* __KIS_SAVED_COMMANDS_H */
float value(const T *src, size_t ch)
virtual bool mergeWith(const KUndo2Command *other)
virtual void undo()
virtual void redo()
virtual void setTimedID(int timedID)
virtual bool timedMergeWith(KUndo2Command *other)
virtual QTime time() const
virtual QTime endTime() const
virtual bool canAnnihilateWith(const KUndo2Command *other) const
virtual QVector< KUndo2Command * > mergeCommandsVector() const
virtual bool isMerged() const
virtual int id() const
virtual int timedId() const
KisStrokesFacade * m_strokesFacade
virtual void addCommands(KisStrokeId id, bool undo)=0
static auto unwrap(Command *cmd, Func &&func) -> decltype(func(static_cast< Command * >(nullptr)))
KUndo2CommandSP m_command
typename copy_const< Src, Dst >::type copy_const_t