SlotPresenter.hpp
1 #pragma once
2 
3 #include <Process/HeaderDelegate.hpp>
4 #include <Process/LayerPresenter.hpp>
5 
6 #include <Scenario/Document/Interval/LayerData.hpp>
7 #include <Scenario/Document/Interval/SlotHeader.hpp>
8 
9 #include <ossia/detail/variant.hpp>
10 
11 namespace Scenario
12 {
13 class SlotHeader;
15 {
16  SlotHeader* header{};
17  Process::HeaderDelegate* headerDelegate{};
18  SlotFooter* footer{};
19  Process::FooterDelegate* footerDelegate{};
20  std::vector<LayerData> layers;
21 
22  void cleanupHeaderFooter();
23  void cleanup(QGraphicsScene* sc);
24 
25  void putToFront(const Id<Process::ProcessModel>&);
26 
27  double headerHeight() const noexcept
28  {
29  if(!header)
30  return SlotHeader::headerHeight();
31 
32  if(!headerDelegate)
33  return header->headerHeight();
34 
35  return headerDelegate->boundingRect().height();
36  }
37 
38  double footerHeight() const noexcept { return SlotFooter::footerHeight(); }
39 };
40 
41 class NodalIntervalView;
43 {
44  SlotHeader* header{};
45  SlotFooter* footer{};
46  NodalIntervalView* view{};
47  double height = 500.;
48  void cleanup();
49 };
50 
51 struct SlotPresenter : ossia::variant<LayerSlotPresenter, NodalSlotPresenter>
52 {
53  //using variant::variant;
54  SlotPresenter() = default;
55  SlotPresenter(const SlotPresenter&) = delete;
56  SlotPresenter(SlotPresenter&&) noexcept = default;
57  SlotPresenter& operator=(const SlotPresenter&) = delete;
58  SlotPresenter& operator=(SlotPresenter&&) noexcept = default;
59 
60  explicit SlotPresenter(const LayerSlotPresenter& l) noexcept = delete;
61  explicit SlotPresenter(const NodalSlotPresenter& l) noexcept = delete;
62  explicit SlotPresenter(LayerSlotPresenter&& l) noexcept
63  : ossia::variant<LayerSlotPresenter, NodalSlotPresenter>{std::move(l)}
64  {
65  }
66  explicit SlotPresenter(NodalSlotPresenter&& l) noexcept
67  : ossia::variant<LayerSlotPresenter, NodalSlotPresenter>{std::move(l)}
68  {
69  }
70 
71  LayerSlotPresenter* getLayerSlot() const noexcept
72  {
73  return ossia::get_if<LayerSlotPresenter>((variant*)this);
74  }
75  NodalSlotPresenter* getNodalSlot() const noexcept
76  {
77  return ossia::get_if<NodalSlotPresenter>((variant*)this);
78  }
79 
80  template <typename Layer, typename Nodal>
81  auto visit(const Layer& lfun, const Nodal& nfun)
82  {
83  struct
84  {
85  const Layer& lfun;
86  const Nodal& nfun;
87  void operator()(LayerSlotPresenter& pres) const { return lfun(pres); }
88  void operator()(NodalSlotPresenter& pres) const { return nfun(pres); }
89  } visitor{lfun, nfun};
90  return ossia::visit(visitor, (variant&)*this);
91  }
92 
93  template <typename Layer, typename Nodal>
94  auto visit(const Layer& lfun, const Nodal& nfun) const
95  {
96  struct
97  {
98  const Layer& lfun;
99  const Nodal& nfun;
100  void operator()(const LayerSlotPresenter& pres) const { return lfun(pres); }
101  void operator()(const NodalSlotPresenter& pres) const { return nfun(pres); }
102  } visitor{lfun, nfun};
103  return ossia::visit(visitor, (const variant&)*this);
104  }
105 
106  template <typename F>
107  auto visit(const F& fun)
108  {
109  return ossia::visit(fun, (variant&)*this);
110  }
111 
112  template <typename F>
113  auto visit(const F& fun) const
114  {
115  return ossia::visit(fun, (const variant&)*this);
116  }
117 
118  void cleanup(QGraphicsScene* sc)
119  {
120  if(auto p = getLayerSlot())
121  p->cleanup(sc);
122  else if(auto p = getNodalSlot())
123  p->cleanup();
124  }
125 };
126 
127 }
Definition: HeaderDelegate.hpp:16
Definition: NodalIntervalView.hpp:20
Definition: SlotHeader.hpp:13
The id_base_t class.
Definition: Identifier.hpp:57
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: SlotPresenter.hpp:15
Definition: SlotPresenter.hpp:43
Definition: SlotPresenter.hpp:52