Walls And Holes  1
undocommandfromfunctions.h
Go to the documentation of this file.
1 #ifndef UNDOCOMMANDFROMACTION_H
2 #define UNDOCOMMANDFROMACTION_H
3 
4 #include <QUndoCommand>
5 
6 // For std::function
7 #include <functional>
8 
14 class UndoCommandFromFunctions : public QUndoCommand
15 {
16 public:
22  template<typename Func1, typename Func2>
23  static UndoCommandFromFunctions *make(Func1 redo, Func2 undo, const QString &text = "", QUndoCommand *parent = nullptr)
24  {
26 
27  return cmd;
28  }
29 
30  void redo() override
31  {
32  mRedo();
33  }
34 
35  void undo() override
36  {
37  mUndo();
38  }
39 
40 private:
41 
42  UndoCommandFromFunctions(std::function<void()> redo, std::function<void()> undo, const QString &text = "", QUndoCommand *parent = nullptr)
43  : QUndoCommand(text, parent)
44  , mRedo(redo)
45  , mUndo(undo) {}
46 
47  std::function<void()> mRedo;
48  std::function<void()> mUndo;
49 };
50 
51 #endif // UNDOCOMMANDFROMACTION_H
static UndoCommandFromFunctions * make(Func1 redo, Func2 undo, const QString &text="", QUndoCommand *parent=nullptr)
performCommand Creates the command and performs it immediately.
Definition: undocommandfromfunctions.h:23
void undo() override
Definition: undocommandfromfunctions.h:35
Creates an undo command that invokes the provided functions on undo() and redo(). ...
Definition: undocommandfromfunctions.h:14
void redo() override
Definition: undocommandfromfunctions.h:30