genericcommand.h
Go to the documentation of this file.
1 #ifndef DNAI_COMMANDS_GENERICCOMMAND_H
2 #define DNAI_COMMANDS_GENERICCOMMAND_H
3 
4 #include <functional>
5 #include "command.h"
7 
8 namespace dnai
9 {
10  namespace commands
11  {
12  template<class ...Args>
13  class GenericCommand : public Command
14  {
17  std::function<void(interfaces::IEditorModel*)> dofunc,
18  std::function<void(interfaces::IEditorModel*)> undo, const QString &name, const bool save = false)
19  : Command(name, save), m_model(model), m_dofunc(std::move(dofunc)), m_undo(std::move(undo))
20  {}
21  protected:
22  void execute() const override
23  {
25  }
26  void executeSave() override
27  {
28  execute();
29  }
30  void unExcute() const override
31  {
32  m_undo(m_model);
33  }
34  QString infos() const override { return ""; }
35  bool isSave() const override { return true; }
36 
37  private:
39  std::function<void(interfaces::IEditorModel*)> m_dofunc;
40  std::function<void(interfaces::IEditorModel*)> m_undo;
41  };
42  }
43 }
44 
45 #endif //DNAI_COMMANDS_GENERICCOMMAND_H
Definition: genericcommand.h:13
void execute() const override
Execute the command.
Definition: genericcommand.h:22
bool isSave() const override
Is the command is in a save state.
Definition: genericcommand.h:35
GenericCommand(interfaces::IEditorModel *model, std::function< void(interfaces::IEditorModel *)> dofunc, std::function< void(interfaces::IEditorModel *)> undo, const QString &name, const bool save=false)
Definition: genericcommand.h:15
Definition: command.h:11
std::function< void(interfaces::IEditorModel *)> m_undo
Definition: genericcommand.h:40
void executeSave() override
Save current state of the command for the reverse unExcute()
Definition: genericcommand.h:26
Definition: api.h:13
interfaces::IEditorModel * m_model
Definition: genericcommand.h:38
void unExcute() const override
Reverse the execute() function.
Definition: genericcommand.h:30
QString infos() const override
Get display info for this command.
Definition: genericcommand.h:34
Definition: ieditormodel.h:11
const QString & name() const
Get the command name.
Definition: command.cpp:34
std::function< void(interfaces::IEditorModel *)> m_dofunc
Definition: genericcommand.h:39