Loading...
Searching...
No Matches
ChangeElementComments.hpp
1#pragma once
2#include <Scenario/Commands/ScenarioCommandFactory.hpp>
3
4#include <score/command/Command.hpp>
5#include <score/model/path/Path.hpp>
6#include <score/model/path/PathSerialization.hpp>
7
8namespace Scenario
9{
10namespace Command
11{
12template <class T>
14{
15 // No SCORE_COMMAND here since it's a template.
16public:
17 const CommandGroupKey& parentKey() const noexcept override
18 {
19 return CommandFactoryName();
20 }
21 static const CommandKey& static_key() noexcept
22 {
23 QString name = QString("ChangeElementComments_") + Metadata<ObjectKey_k, T>::get();
24 static const CommandKey kagi{std::move(name)};
25 return kagi;
26 }
27 const CommandKey& key() const noexcept override { return static_key(); }
28 QString description() const override
29 {
30 return QObject::tr("Change %1 comments").arg(Metadata<Description_k, T>::get());
31 }
32
33 ChangeElementComments() = default;
34
35 ChangeElementComments(const T& obj, QString newComments)
36 : m_path{obj}
37 , m_newComments{std::move(newComments)}
38 {
39 m_oldComments = obj.metadata().getComment();
40 }
41
42 void undo(const score::DocumentContext& ctx) const override
43 {
44 auto& obj = m_path.find(ctx);
45 obj.metadata().setComment(m_oldComments);
46 }
47
48 void redo(const score::DocumentContext& ctx) const override
49 {
50 auto& obj = m_path.find(ctx);
51 obj.metadata().setComment(m_newComments);
52 }
53
54protected:
55 void serializeImpl(DataStreamInput& s) const override
56 {
57 s << m_path << m_oldComments << m_newComments;
58 }
59
60 void deserializeImpl(DataStreamOutput& s) override
61 {
62 s >> m_path >> m_oldComments >> m_newComments;
63 }
64
65private:
66 Path<T> m_path;
67 QString m_oldComments;
68 QString m_newComments;
69};
70}
71}
72
73SCORE_COMMAND_DECL_T(ChangeElementComments<IntervalModel>)
74SCORE_COMMAND_DECL_T(ChangeElementComments<EventModel>)
75SCORE_COMMAND_DECL_T(ChangeElementComments<TimeSyncModel>)
76SCORE_COMMAND_DECL_T(ChangeElementComments<StateModel>)
77SCORE_COMMAND_DECL_T(ChangeElementComments<Process::ProcessModel>)
The Path class is a typesafe wrapper around ObjectPath.
Definition Path.hpp:52
Definition ChangeElementComments.hpp:14
The Command class.
Definition Command.hpp:34
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Definition DataStreamHelpers.hpp:99
Definition DataStreamHelpers.hpp:103
Static metadata implementation.
Definition lib/score/tools/Metadata.hpp:36
Definition DocumentContext.hpp:18