ObjectItemModel.hpp
1 #pragma once
2 #include <score/document/DocumentContext.hpp>
3 #include <score/plugins/panel/PanelDelegate.hpp>
4 #include <score/plugins/panel/PanelDelegateFactory.hpp>
5 #include <score/selection/SelectionDispatcher.hpp>
6 #include <score/selection/SelectionStack.hpp>
7 #include <score/widgets/MarginLess.hpp>
8 #include <score/widgets/SearchLineEdit.hpp>
9 #include <Scenario/Inspector/ObjectTree/SearchWidget.hpp>
10 
11 #include <QAbstractItemModel>
12 #include <QContextMenuEvent>
13 #include <QLabel>
14 #include <QTreeView>
15 #include <QVBoxLayout>
16 
17 #include <nano_observer.hpp>
18 
19 #include <verdigris>
20 class QToolButton;
21 class QGraphicsSceneMouseEvent;
22 namespace Scenario
23 {
24 // TimeSync / event / state / state processes
25 // or
26 // Interval / processes
27 class ObjectItemModel final
28  : public QAbstractItemModel
29  , public Nano::Observer
30 {
31  W_OBJECT(ObjectItemModel)
32 public:
33  ObjectItemModel(const score::DocumentContext& ctx, QObject* parent);
34  void setSelected(QList<const IdentifiedObjectAbstract*> sel);
35 
36  QModelIndex index(int row, int column, const QModelIndex& parent) const override;
37  QModelIndex parent(const QModelIndex& child) const override;
38  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
39 
40  int rowCount(const QModelIndex& parent) const override;
41  int columnCount(const QModelIndex& parent) const override;
42 
43  QVariant data(const QModelIndex& index, int role) const override;
44  Qt::ItemFlags flags(const QModelIndex& index) const override;
45 
46  bool setData(const QModelIndex& index, const QVariant& value, int role) override;
47 
48  QMimeData* mimeData(const QModelIndexList& indexes) const override;
49  bool canDropMimeData(
50  const QMimeData* data, Qt::DropAction action, int row, int column,
51  const QModelIndex& parent) const override;
52  bool dropMimeData(
53  const QMimeData* data, Qt::DropAction action, int row, int column,
54  const QModelIndex& parent) override;
55  Qt::DropActions supportedDropActions() const override;
56  Qt::DropActions supportedDragActions() const override;
57 
58 public:
59  void changed() W_SIGNAL(changed);
60 
61 private:
62  void setupConnections();
63  void cleanConnections();
64 
65  bool isAlive(QObject* obj) const;
66 
67  template <typename... Args>
68  void recompute(Args&&...)
69  {
70  beginResetModel();
71  cleanConnections();
72 
73  setupConnections();
74  endResetModel();
75 
76  changed();
77  }
78 
79  QList<const QObject*> m_root;
80  QMetaObject::Connection m_con;
82 
83  const score::DocumentContext& m_ctx;
84  std::vector<QMetaObject::Connection> m_itemCon;
85 };
86 
87 class ObjectWidget final : public QTreeView
88 {
89 public:
90  ObjectWidget(const score::DocumentContext& ctx, QWidget* par);
91  ObjectItemModel model;
92 
93  bool updatingSelection{false};
94 
95 private:
96  void selectionChanged(
97  const QItemSelection& selected, const QItemSelection& deselected) override;
98 
99  void contextMenuEvent(QContextMenuEvent* ev) override;
100  const score::DocumentContext& m_ctx;
101 };
102 
103 class SizePolicyWidget final : public QWidget
104 {
105 public:
106  using QWidget::QWidget;
107 
108  QSize sizeHint() const override { return m_sizePolicy; }
109  void setSizeHint(QSize s) { m_sizePolicy = s; }
110 
111 private:
112  QSize m_sizePolicy;
113 };
114 
116 {
117 public:
119  // does the current selection have a neighbor in that direction ?
120  bool hasRight() const;
121  bool hasLeft() const;
122  bool hasUp() const;
123  bool hasDown() const;
124 
125  // Select neighbor
126  void selectRight();
127  void selectLeft();
128  void selectUp();
129  void selectDown();
130 
131 private:
132  score::SelectionStack& m_stack;
133  ObjectWidget* m_objects{};
134  score::SelectionDispatcher m_selectionDispatcher;
135 };
136 
137 class SelectionStackWidget final : public QWidget
138 {
139 public:
140  SelectionStackWidget(score::SelectionStack& s, QWidget* parent, ObjectWidget* objects);
141 
142 private:
143  QToolButton* m_prev{};
144  QToolButton* m_next{};
145  QLabel* m_label{};
146  QToolButton* m_left{};
147  QToolButton* m_right{};
148  QToolButton* m_up{};
149  QToolButton* m_down{};
150  score::SelectionStack& m_stack;
151  NeighbourSelector m_selector;
152 };
153 
155 {
156 public:
158 
159 private:
160  QWidget* widget() override;
161  const score::PanelStatus& defaultPanelStatus() const override;
162 
163  void on_modelChanged(score::MaybeDocument oldm, score::MaybeDocument newm) override;
164  void setNewSelection(const Selection& sel) override;
165 
166  SizePolicyWidget* m_widget{};
167  QVBoxLayout* m_lay{};
168  SelectionStackWidget* m_stack{};
169  ObjectWidget* m_objects{};
170  SearchWidget* m_searchWidget{};
171 };
172 
174 {
175  SCORE_CONCRETE("aea973e2-84aa-4b8a-b0f0-b6ce39b6f15a")
176 
177  std::unique_ptr<score::PanelDelegate>
178  make(const score::GUIApplicationContext& ctx) override
179  {
180  return std::make_unique<ObjectPanelDelegate>(ctx);
181  }
182 };
183 }
Definition: ClipMode.hpp:10
Definition: ObjectItemModel.hpp:116
Definition: ObjectItemModel.hpp:30
Definition: ObjectItemModel.hpp:174
Definition: ObjectItemModel.hpp:155
Definition: ObjectItemModel.hpp:88
Definition: SearchWidget.hpp:14
Definition: ObjectItemModel.hpp:138
Definition: ObjectItemModel.hpp:104
Definition: Selection.hpp:12
Reimplement this interface to register new panels.
Definition: PanelDelegateFactory.hpp:10
The PanelDelegate class.
Definition: PanelDelegate.hpp:50
The SelectionDispatcher class.
Definition: SelectionDispatcher.hpp:15
The SelectionStack class.
Definition: SelectionStack.hpp:24
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: DocumentContext.hpp:18
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15
The PanelStatus struct.
Definition: PanelDelegate.hpp:24