Command.hpp
1 #pragma once
2 #include <score/command/CommandFactoryKey.hpp>
3 #include <score/plugins/StringFactoryKey.hpp>
4 
5 #include <QByteArray>
6 #include <QObject>
7 #include <QString>
8 
9 #include <score_lib_base_export.h>
10 
11 struct DataStreamInput;
12 struct DataStreamOutput;
13 namespace score
14 {
15 struct ApplicationContext;
16 struct DocumentContext;
33 class SCORE_LIB_BASE_EXPORT Command
34 {
35 public:
36  Command();
37  virtual ~Command();
38 
39  virtual void undo(const score::DocumentContext& ctx) const = 0;
40  virtual void redo(const score::DocumentContext& ctx) const = 0;
41 
42  virtual const CommandGroupKey& parentKey() const noexcept = 0;
43  virtual const CommandKey& key() const noexcept = 0;
44 
45  QByteArray serialize() const;
46  void deserialize(const QByteArray&);
47 
48  virtual QString description() const = 0;
49 
50 protected:
51  virtual void serializeImpl(DataStreamInput&) const = 0;
52  virtual void deserializeImpl(DataStreamOutput&) = 0;
53 };
54 }
55 
74 #define SCORE_COMMAND_DECL(parentNameFun, name, desc) \
75 public: \
76  name() noexcept { } \
77  const CommandGroupKey& parentKey() const noexcept override \
78  { \
79  return parentNameFun; \
80  } \
81  const CommandKey& key() const noexcept override \
82  { \
83  return static_key(); \
84  } \
85  QString description() const override \
86  { \
87  return QObject::tr(desc); \
88  } \
89  static const CommandKey& static_key() noexcept \
90  { \
91  static const CommandKey var{#name}; \
92  return var; \
93  } \
94  \
95 private:
96 
104 #define SCORE_COMMAND_DECL_T(name)
The Command class.
Definition: Command.hpp:34
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DataStreamHelpers.hpp:99
Definition: DataStreamHelpers.hpp:103
Definition: DocumentContext.hpp:18