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

#include <kis_saved_commands.h>

+ Inheritance diagram for KisSavedCommand:

Public Member Functions

bool canAnnihilateWith (const KUndo2Command *command) const override
 
QTime endTime () const override
 
int id () const override
 
bool isMerged () const override
 
 KisSavedCommand (KUndo2CommandSP command, KisStrokesFacade *strokesFacade)
 
QVector< KUndo2Command * > mergeCommandsVector () const override
 
bool mergeWith (const KUndo2Command *command) override
 
void setEndTime (const QTime &time) override
 
void setTime (const QTime &time) override
 
void setTimedID (int timedID) override
 
QTime time () const override
 
int timedId () const override
 
bool timedMergeWith (KUndo2Command *other) 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
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
KUndo2MagicString text () const
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Static Public Member Functions

template<typename Command , typename Func >
static auto unwrap (Command *cmd, Func &&func) -> decltype(func(static_cast< Command * >(nullptr)))
 

Protected Member Functions

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

Private Attributes

KUndo2CommandSP m_command
 

Detailed Description

Definition at line 40 of file kis_saved_commands.h.

Constructor & Destructor Documentation

◆ KisSavedCommand()

KisSavedCommand::KisSavedCommand ( KUndo2CommandSP command,
KisStrokesFacade * strokesFacade )

Definition at line 69 of file kis_saved_commands.cpp.

71 : KisSavedCommandBase(command->text(), strokesFacade),
72 m_command(command)
73{
74}
KisStrokesFacade * strokesFacade()
KisSavedCommandBase(const KUndo2MagicString &name, KisStrokesFacade *strokesFacade)
KUndo2CommandSP m_command

Member Function Documentation

◆ addCommands()

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

◆ canAnnihilateWith()

bool KisSavedCommand::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 88 of file kis_saved_commands.cpp.

89{
90 return unwrap(command, [this] (const KUndo2Command *cmd) {
91 return m_command->canAnnihilateWith(cmd);
92 });
93}
static auto unwrap(Command *cmd, Func &&func) -> decltype(func(static_cast< Command * >(nullptr)))

References m_command, and unwrap().

◆ endTime()

QTime KisSavedCommand::endTime ( ) const
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 136 of file kis_saved_commands.cpp.

137{
138 return m_command->endTime();
139}

References m_command.

◆ id()

int KisSavedCommand::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 76 of file kis_saved_commands.cpp.

77{
78 return m_command->id();
79}

References m_command.

◆ isMerged()

bool KisSavedCommand::isMerged ( ) const
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 140 of file kis_saved_commands.cpp.

141{
142 return m_command->isMerged();
143}

References m_command.

◆ mergeCommandsVector()

QVector< KUndo2Command * > KisSavedCommand::mergeCommandsVector ( ) const
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 118 of file kis_saved_commands.cpp.

119{
120 return m_command->mergeCommandsVector();
121}

References m_command.

◆ mergeWith()

bool KisSavedCommand::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 81 of file kis_saved_commands.cpp.

82{
83 return unwrap(command, [this] (const KUndo2Command *cmd) {
84 return m_command->mergeWith(cmd);
85 });
86}

References m_command, and unwrap().

◆ setEndTime()

void KisSavedCommand::setEndTime ( const QTime & time)
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 131 of file kis_saved_commands.cpp.

132{
133 m_command->setEndTime(time);
134}
QTime time() const override

References m_command, and time().

◆ setTime()

void KisSavedCommand::setTime ( const QTime & time)
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 122 of file kis_saved_commands.cpp.

123{
124 m_command->setTime(time);
125}

References m_command, and time().

◆ setTimedID()

void KisSavedCommand::setTimedID ( int timedID)
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 104 of file kis_saved_commands.cpp.

105{
106 m_command->setTimedID(timedID);
107}

References m_command.

◆ time()

QTime KisSavedCommand::time ( ) const
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 127 of file kis_saved_commands.cpp.

128{
129 return m_command->time();
130}

References m_command.

◆ timedId()

int KisSavedCommand::timedId ( ) const
overridevirtual

Reimplemented from KUndo2Command.

Definition at line 100 of file kis_saved_commands.cpp.

101{
102 return m_command->timedId();
103}

References m_command.

◆ timedMergeWith()

bool KisSavedCommand::timedMergeWith ( KUndo2Command * other)
overridevirtual

Since we are saving the actual command inside another command, so we cannot unwrap the command here. Otherwise the shared pointer in other will destroy the merged command some time later.

Reimplemented from KUndo2Command.

Definition at line 109 of file kis_saved_commands.cpp.

110{
115
116 return m_command->timedMergeWith(other);
117}

References m_command.

◆ unwrap()

template<typename Command , typename Func >
static auto KisSavedCommand::unwrap ( Command * cmd,
Func && func ) -> decltype(func(static_cast<Command*>(nullptr)))
inlinestatic

The function lazily unwraps a saved command cmd and passes the internal command to the the function func. If passed cmd command is not a saved command, then it is passed to the function directly.

Definition at line 67 of file kis_saved_commands.h.

68 {
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 }
QAction * forward(const QObject *recvr, const char *slot, QObject *parent)
typename copy_const< Src, Dst >::type copy_const_t

Member Data Documentation

◆ m_command

KUndo2CommandSP KisSavedCommand::m_command
private

Definition at line 84 of file kis_saved_commands.h.


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