CurveSegmentFactory.hpp
1 #pragma once
2 
3 #include <score/model/Identifier.hpp>
4 #include <score/plugins/Interface.hpp>
6 #include <score/tools/Metadata.hpp>
7 
8 #include <QString>
9 #include <QVariant>
10 
11 #include <score_plugin_curve_export.h>
12 
13 class QObject;
14 struct VisitorVariant;
15 
16 namespace Curve
17 {
18 class Category_k;
19 class SegmentModel;
20 struct SegmentData;
21 class SCORE_PLUGIN_CURVE_EXPORT SegmentFactory : public score::InterfaceBase
22 {
23  SCORE_INTERFACE(SegmentFactory, "608ecec9-d8bc-4b6b-8e9e-31867a310f1e")
24 public:
25  virtual ~SegmentFactory();
26 
27  virtual QString prettyName() const = 0;
28  virtual QString category() const = 0;
29 
30  virtual SegmentModel* make(const Id<SegmentModel>&, QObject* parent) = 0;
31 
32  virtual SegmentModel* load(const VisitorVariant& data, QObject* parent) = 0;
33 
34  virtual SegmentModel* load(const SegmentData& data, QObject* parent) = 0;
35 
36  virtual QVariant makeCurveSegmentData() const = 0;
37 
38  virtual void serializeCurveSegmentData(
39  const QVariant& data, const VisitorVariant& visitor) const = 0;
40  virtual QVariant makeCurveSegmentData(const VisitorVariant& visitor) const = 0;
41 };
42 
43 template <typename T>
45 {
46 public:
47  virtual ~SegmentFactory_T() = default;
48 
49  SegmentModel* make(const Id<SegmentModel>& id, QObject* parent) override
50  {
51  return new T{id, parent};
52  }
53 
54  SegmentModel* load(const VisitorVariant& vis, QObject* parent) override
55  {
56  return score::deserialize_dyn(vis, [&](auto&& deserializer) {
57  return new T{deserializer, parent};
58  });
59  }
60 
61  SegmentModel* load(const SegmentData& dat, QObject* parent) override
62  {
63  return new T{dat, parent};
64  }
65 
66  QVariant makeCurveSegmentData() const override
67  {
68  return QVariant::fromValue(typename T::data_type{});
69  }
70 
71  void serializeCurveSegmentData(
72  const QVariant& data, const VisitorVariant& visitor) const override
73  {
74  score::serialize_dyn(visitor, data.value<typename T::data_type>());
75  }
76 
77  QVariant makeCurveSegmentData(const VisitorVariant& vis) const override
78  {
79  return QVariant::fromValue(score::deserialize_dyn<typename T::data_type>(vis));
80  }
81 
82  UuidKey<Curve::SegmentFactory> concreteKey() const noexcept override
83  {
85  }
86 
87  QString prettyName() const override { return Metadata<PrettyName_k, T>::get(); }
88  QString category() const override { return Metadata<Category_k, T>::get(); }
89 };
90 }
Metadata to categorize objects: curves, audio, etc.
Definition: lib/score/tools/Metadata.hpp:61
Definition: CurveSegmentFactory.hpp:45
Definition: CurveSegmentFactory.hpp:22
Definition: CurveSegmentModel.hpp:32
The id_base_t class.
Definition: Identifier.hpp:57
Base class for plug-in interfaces.
Definition: Interface.hpp:52
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: CurveSegmentData.hpp:63
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26