PortFactory.hpp
1 #pragma once
2 #include <Process/Dataflow/Port.hpp>
3 
4 #include <score/graphics/TextItem.hpp>
5 #include <score/plugins/Interface.hpp>
6 #include <score/plugins/InterfaceList.hpp>
8 class QGraphicsItem;
9 namespace Inspector
10 {
11 class Layout;
12 }
13 namespace Dataflow
14 {
15 class PortItem;
16 }
17 namespace Process
18 {
19 struct Context;
21 {
22  QGraphicsItem* container{};
23  Dataflow::PortItem* port_item{};
24  QGraphicsItem* control{};
25  score::SimpleTextItem* label{};
26  // QRectF itemRect;
27 };
28 
29 class SCORE_LIB_PROCESS_EXPORT PortFactory : public score::InterfaceBase
30 {
31  SCORE_INTERFACE(Process::Port, "4d461658-5c27-4a12-ba97-3d9392561ece")
32 public:
33  ~PortFactory() override;
34 
35  virtual Process::Port* load(const VisitorVariant&, QObject* parent) = 0;
36 
37  // Just the port
38  virtual Dataflow::PortItem* makePortItem(
39  Process::Inlet& port, const Process::Context& ctx, QGraphicsItem* parent,
40  QObject* context);
41  virtual Dataflow::PortItem* makePortItem(
42  Process::Outlet& port, const Process::Context& ctx, QGraphicsItem* parent,
43  QObject* context);
44 
45  // Just the control
46  virtual QGraphicsItem* makeControlItem(
48  QGraphicsItem* parent, QObject* context);
49  virtual QGraphicsItem* makeControlItem(
51  QGraphicsItem* parent, QObject* context);
52 
53  // Port + control + text
54  ControlLayout makeFullItem(
55  Process::ControlInlet& port, const Process::Context& ctx, QGraphicsItem* parent,
56  QObject* context);
57  ControlLayout makeFullItem(
58  Process::ControlOutlet& port, const Process::Context& ctx, QGraphicsItem* parent,
59  QObject* context);
60 
61  // Widget stuff
62  virtual void setupInletInspector(
63  const Process::Inlet& port, const score::DocumentContext& ctx, QWidget* parent,
64  Inspector::Layout& lay, QObject* context);
65  virtual void setupOutletInspector(
66  const Process::Outlet& port, const score::DocumentContext& ctx, QWidget* parent,
67  Inspector::Layout& lay, QObject* context);
68 
69  virtual PortItemLayout defaultLayout() const noexcept;
70 };
71 
72 class SCORE_LIB_PROCESS_EXPORT PortFactoryList final
73  : public score::InterfaceList<PortFactory>
74 {
75 public:
76  using object_type = Process::Port;
77  ~PortFactoryList();
78  Process::Port* loadMissing(const VisitorVariant& vis, QObject* parent) const;
79 };
80 
81 template <typename Model_T>
82 class PortFactory_T final : public Process::PortFactory
83 {
84 public:
85  ~PortFactory_T() override = default;
86 
87 private:
88  UuidKey<Process::Port> concreteKey() const noexcept override
89  {
91  }
92 
93  Model_T* load(const VisitorVariant& vis, QObject* parent) override
94  {
95  return score::deserialize_dyn(vis, [&](auto&& deserializer) {
96  return new Model_T{deserializer, parent};
97  });
98  }
99 };
100 
101 SCORE_LIB_PROCESS_EXPORT
102 void readPorts(
103  DataStreamReader& wr, const Process::Inlets& ins, const Process::Outlets& outs);
104 
105 SCORE_LIB_PROCESS_EXPORT
106 void readPorts(
107  JSONReader& obj, const Process::Inlets& ins, const Process::Outlets& outs);
108 
109 SCORE_LIB_PROCESS_EXPORT
110 void writePorts(
112  Process::Outlets& outs, QObject* parent);
113 
114 SCORE_LIB_PROCESS_EXPORT
115 void writePorts(
116  const JSONWriter& obj, const Process::PortFactoryList& pl, Process::Inlets& ins,
117  Process::Outlets& outs, QObject* parent);
118 }
Definition: DataStreamVisitor.hpp:27
Definition: DataStreamVisitor.hpp:202
Definition: score-lib-process/Process/Dataflow/PortItem.hpp:39
Definition: lib/score/widgets/Layout.hpp:29
Definition: JSONVisitor.hpp:52
Definition: JSONVisitor.hpp:423
Definition: Port.hpp:203
Definition: Port.hpp:425
Definition: Port.hpp:177
Definition: Port.hpp:273
Definition: PortFactory.hpp:83
Definition: PortFactory.hpp:30
Definition: PortFactory.hpp:74
Definition: Port.hpp:102
Definition: UuidKey.hpp:343
Base class for plug-in interfaces.
Definition: Interface.hpp:52
InterfaceList Default implementation of InterfaceListBase.
Definition: InterfaceList.hpp:80
Definition: TextItem.hpp:28
Classes used for making and extending the inspector (default right panel).
Definition: lib/score/widgets/Layout.hpp:27
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
Definition: ProcessContext.hpp:12
Definition: PortFactory.hpp:21
Definition: PortForward.hpp:23
Definition: PortForward.hpp:27
Definition: Port.hpp:90
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26
Definition: DocumentContext.hpp:18