Command.h header

#include <ew/core/Command.h>

Namespace ew::core

Command class

class ew::core::Command

A reversible mutation of the model. Every user edit is expressed as a Command so the CommandStack can apply and un-apply it to implement undo/redo.

Members

ew::core::undo::Command::Command()=default

Defaulted.

virtual ew::core::undo::Command::~Command()=default

Defaulted.

ew::core::undo::Command::Command(const Command &)=delete

Commands are owned by the stack via pointer: non-copyable and non-movable.

ew::core::undo::Command::Command(Command &&)=delete

Not movable.

Command & ew::core::undo::Command::operator=(const Command &)=delete

Not copyable.

Command & ew::core::undo::Command::operator=(Command &&)=delete

Not movable.

virtual void ew::core::undo::Command::apply()=0

Applies the change; also used to re-apply the command on redo.

virtual void ew::core::undo::Command::undo()=0

Reverses the change previously applied by apply().

virtual QString ew::core::undo::Command::description() const =0

Short, human-readable description for the undo/redo UI (e.g. "Add character").

virtual ew::core::foundation::OperationSubject ew::core::undo::Command::subject() const =0

What this command changes: the content object, taxonomy category, or project-level facet an operation journal names and a policy check asks about.

PURE VIRTUAL, WITH NO DEFAULT, DELIBERATELY. A base class cannot work this out: a command holds ids for its subject, for the new value it applies, AND for the state it snapshotted to undo with, and nothing distinguishes them by type. Four commands in this tree would have been given the wrong subject by any rule that guessed from members – silently, since a wrong-but-well-formed id looks exactly like a right one. Requiring each command to say so makes a missing answer a compile error instead.

The one command with no subject of its own is CompositeCommand, which returns the empty subject; its members carry the real ones.

virtual std::span< const std::unique_ptr< Command > > ew::core::undo::Command::children() const

The commands this one is composed of, in the order they apply. Empty for all but CompositeCommand.

DEFAULTED, unlike subject(), and the difference is not an inconsistency. A leaf command having no children is structurally true rather than a guess, so the default cannot be silently wrong; a subject is information only the command holds, so a default there WOULD be. Lets a journal walk a grouped edit down to the individual mutations without asking what concrete type it is holding.