28 Q_ASSERT_X(
false,
"Commands",
"This command did not implement undo");
32 Q_ASSERT_X(
false,
"Commands",
"This command did not implement redo");
151 template<
typename T,
typename PropType, PropType (T::*PropGetter)()
const,
void (T::*PropSetter)(
156 explicit SetCmd(T *target, PropType new_value) : target_(target), new_value_(new_value) {
157 old_value_ = (target_->*PropGetter)();
161 qInfo() <<
"[Command] Undo set";
162 (target_->*PropSetter)(old_value_);
166 qInfo() <<
"[Command] Do set";
167 (target_->*PropSetter)(new_value_);
179 template<
typename T,
typename PropType,
const PropType &(T::*PropGetter)() const,
void (T::*PropSetter)(
184 explicit SetRefCmd(T *target, PropType new_value) : target_(target), new_value_(new_value) {
185 old_value_ = (target_->*PropGetter)();
189 qInfo() <<
"[Command] Undo setRef";
190 (target_->*PropSetter)(old_value_);
194 qInfo() <<
"[Command] Do setRef";
195 (target_->*PropSetter)(new_value_);
211 template<
typename T,
typename PropType, PropType (T::*PropGetter)()
const,
void (T::*PropSetter)(
214 return make_shared<SetCmd<T, PropType, PropGetter, PropSetter>>(target, new_value);
217 template<
typename T,
typename PropType,
const PropType &(T::*PropGetter)() const,
void (T::*PropSetter)(
220 return make_shared<SetRefCmd<T, PropType, PropGetter, PropSetter>>
227 &SetRef<Shape, QTransform, &Shape::transform, &Shape::setTransform>;
230 &Set<Shape, Shape *, &Shape::parent, &Shape::setParent>;
233 &Set<Shape, Layer *, &Shape::layer, &Shape::setLayer>;
236 &SetRef<TextShape, QFont, &TextShape::font, &TextShape::setFont>;
239 &Set<TextShape, float, &TextShape::lineHeight, &TextShape::setLineHeight>;
242 &Set<Shape, qreal, &TextShape::rotation, &TextShape::setRotation>;
252 template<
typename T,
typename PropType, PropType (T::*PropGetter)()
const,
void (T::*PropSetter)(
254 CmdPtr Set(T *target, PropType new_value);
256 template<
typename T,
typename PropType,
const PropType &(T::*PropGetter)() const,
void (T::*PropSetter)(
Command for adding layers.
Definition: command.h:43
LayerPtr layer_
Definition: command.h:51
void undo(Document *doc) override
Definition: command.cpp:19
void redo(Document *doc) override
Definition: command.cpp:24
AddLayerCmd(const LayerPtr &layer)
Definition: command.h:45
Command for adding shapes. The command needs to manage shapes' lifecycle, but doesn't need to manage ...
Definition: command.h:74
ShapePtr shape_
Definition: command.h:84
AddShapeCmd(Layer *layer, const ShapePtr &shape)
Definition: command.h:76
void redo(Document *doc) override
Definition: command.cpp:42
Layer * layer_
Definition: command.h:83
void undo(Document *doc) override
Definition: command.cpp:37
A class template for undoable commands, along with undo() / redo() implementation.
Definition: command.h:21
virtual void redo(Document *doc)
Definition: command.h:31
virtual void undo(Document *doc)
Definition: command.h:27
A group of commands that can be considered as a single step in undo/redo.
Definition: command.h:129
void undo(Document *doc) override
Definition: command.cpp:137
JoinedCmd(initializer_list< BaseCmd * > undo_events)
QList< CmdPtr > events
Definition: command.h:142
JoinedCmd(initializer_list< CmdPtr > undo_events)
void redo(Document *doc) override
Definition: command.cpp:143
Command for removing layers.
Definition: command.h:58
void undo(Document *doc) override
Definition: command.cpp:29
void redo(Document *doc) override
Definition: command.cpp:33
LayerPtr layer_
Definition: command.h:66
RemoveLayerCmd(const LayerPtr &layer)
Definition: command.h:60
Command for removing shapes. The command needs to manage shapes' lifecycle, but doesn't need to manag...
Definition: command.h:92
void undo(Document *doc) override
Definition: command.cpp:48
void redo(Document *doc) override
Definition: command.cpp:53
RemoveShapeCmd(const ShapePtr &shape)
Definition: command.h:94
Layer * layer_
Definition: command.h:104
RemoveShapeCmd(Layer *layer, const ShapePtr &shape)
Definition: command.h:97
ShapePtr shape_
Definition: command.h:105
Command for selection changes in document.
Definition: command.h:112
void redo(Document *doc) override
Definition: command.cpp:68
SelectCmd(Document *doc, const QList< ShapePtr > &new_selections_)
Definition: command.cpp:58
void undo(Document *doc) override
Definition: command.cpp:63
QList< ShapePtr > old_selections_
Definition: command.h:121
QList< ShapePtr > new_selections_
Definition: command.h:122
Command for changing objects' property, and the property can be "passed by value".
Definition: command.h:153
void redo(Document *doc) override
Definition: command.h:165
T * target_
Definition: command.h:168
void undo(Document *doc) override
Definition: command.h:160
PropType old_value_
Definition: command.h:172
PropType new_value_
Definition: command.h:171
SetCmd(T *target, PropType new_value)
Definition: command.h:156
Command for changing objects' property, and the property is usually "passed by reference".
Definition: command.h:181
void undo(Document *doc) override
Definition: command.h:188
void redo(Document *doc) override
Definition: command.h:193
PropType old_value_
Definition: command.h:200
T * target_
Definition: command.h:196
PropType new_value_
Definition: command.h:199
SetRefCmd(T *target, PropType new_value)
Definition: command.h:184
Document state store for layers, shapes, document specfic settings and current view state.
Definition: document.h:19
A base class for shape objects that contains transform and parent information.
Definition: shape.h:17
Definition: text-shape.h:6
Commands::CmdPtr CmdPtr
Definition: command.h:273
shared_ptr< Layer > LayerPtr
Definition: layer.h:127
Undoable commands.
Definition: command.h:9
JoinedPtr Joined()
Definition: command.cpp:125
CmdPtr AddLayer(const LayerPtr &layer)
Definition: command.cpp:117
shared_ptr< JoinedCmd > JoinedPtr
Definition: command.h:145
CmdPtr AddShape(Layer *layer, const ShapePtr &shape)
Definition: command.cpp:85
CmdPtr Set(T *target, PropType new_value)
Definition: command.h:213
CmdPtr RemoveLayer(const LayerPtr &layer)
Definition: command.cpp:121
constexpr CmdPtr(* SetLineHeight)(TextShape *, float)
Definition: command.h:238
CmdPtr RemoveShape(const ShapePtr &shape)
Definition: command.cpp:89
JoinedPtr operator+(const CmdPtr &a, const CmdPtr &b)
CmdPtr AddShapes(Layer *layer, const QList< ShapePtr > &shapes)
Definition: command.cpp:101
CmdPtr RemoveShapes(const QList< ShapePtr > &shapes)
Definition: command.cpp:109
constexpr CmdPtr(* SetTransform)(Shape *, QTransform)
Definition: command.h:226
shared_ptr< BaseCmd > CmdPtr
Definition: command.h:36
CmdPtr SetRef(T *target, PropType new_value)
Definition: command.h:219
constexpr CmdPtr(* SetFont)(TextShape *, QFont)
Definition: command.h:235
JoinedPtr & operator<<(JoinedPtr &a, const CmdPtr &b)
Definition: command.cpp:9
constexpr CmdPtr(* SetParent)(Shape *, Shape *)
Definition: command.h:229
constexpr CmdPtr(* SetLayer)(Shape *, Layer *)
Definition: command.h:232
CmdPtr Select(Document *doc, const QList< ShapePtr > &new_selections)
Definition: command.cpp:97
CmdPtr RemoveSelections(Document *doc)
Definition: command.cpp:77
constexpr CmdPtr(* SetRotation)(Shape *, qreal)
Definition: command.h:241
shared_ptr< Shape > ShapePtr
Definition: shape.h:137