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