CurveCommandObjectBase.hpp
1 #pragma once
2 #include <Curve/Segment/CurveSegmentData.hpp>
3 
4 #include <score/command/Dispatchers/SingleOngoingCommandDispatcher.hpp>
5 #include <score/model/Identifier.hpp>
6 #include <score/model/path/Path.hpp>
7 #include <score/tools/IdentifierGeneration.hpp>
8 #include <score/tools/std/Optional.hpp>
9 
10 #include <QByteArray>
11 #include <QPoint>
12 #include <QVector>
13 
14 #include <score_plugin_curve_export.h>
15 
16 #include <vector>
17 
18 namespace score
19 {
20 class CommandStackFacade;
21 } // namespace score
22 
23 /*
24 concept CommandObject
25 {
26  public:
27  void instantiate();
28  void update();
29  void commit();
30  void rollback();
31 };
32 */
33 // CreateSegment
34 // CreateSegmentBetweenPoints
35 
36 // RemoveSegment -> easy peasy
37 // RemovePoint -> which segment do we merge ? At the left or at the right ?
38 // A point(view) has pointers to one or both of its curve segments.
39 
40 namespace Curve
41 {
42 class UpdateCurve;
43 class Model;
44 class Presenter;
45 class StateBase;
46 class SegmentModel;
47 
48 class SCORE_PLUGIN_CURVE_EXPORT CommandObjectBase
49 {
50 public:
52  const Model& model, Presenter* pres, const score::CommandStackFacade&);
53  virtual ~CommandObjectBase();
54 
55  void setCurveState(Curve::StateBase* stateBase) { m_state = stateBase; }
56  void press();
57 
58  void handleLocking();
59 
60 protected:
61  // Creates and pushes an UpdateCurve command
62  // from a vector of segments.
63  // They are removed afterwards
64  void submit(std::vector<SegmentData>&&);
65 
66  auto find(std::vector<SegmentData>& segments, const OptionalId<SegmentModel>& id)
67  {
68  return std::find_if(
69  segments.begin(), segments.end(), [&](const auto& seg) { return seg.id == id; });
70  }
71  auto find(const std::vector<SegmentData>& segments, const OptionalId<SegmentModel>& id)
72  {
73  return std::find_if(segments.cbegin(), segments.cend(), [&](const auto& seg) {
74  return seg.id == id;
75  });
76  }
77 
78  virtual void on_press() = 0;
79 
80  QVector<QByteArray> m_oldCurveData;
81  QPointF m_originalPress; // Note : there should be only one per curve...
82 
83  const Model& m_model;
84  Presenter* m_presenter{};
85 
86  Curve::StateBase* m_state{};
87 
89 
90  std::vector<SegmentData> m_startSegments;
91 
92  // To prevent behind locked at 0.000001 or 0.9999
93  double m_xmin{-1}, m_xmax{2}, m_xLastPoint{2};
94 };
95 }
Definition: CurveCommandObjectBase.hpp:49
Definition: CurveModel.hpp:25
Definition: CurvePresenter.hpp:32
Definition: CurvePaletteBaseStates.hpp:20
The SingleOngoingCommandDispatcher class.
Definition: SingleOngoingCommandDispatcher.hpp:17
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Base toolkit upon which the software is built.
Definition: Application.cpp:90