Loading...
Searching...
No Matches
DeviceExplorerModel.hpp
1#pragma once
2#include <State/Message.hpp>
3#include <State/Value.hpp>
4
5#include <Device/ItemModels/NodeBasedItemModel.hpp>
6#include <Device/Node/DeviceNode.hpp>
7
8#include <Explorer/Explorer/Column.hpp>
9
10#include <score/document/DocumentContext.hpp>
11
12#include <QAbstractItemModel>
13#include <QString>
14#include <QStringList>
15#include <QVariant>
16#include <qnamespace.h>
17
18#include <score_plugin_deviceexplorer_export.h>
19
20#include <verdigris>
21class QMimeData;
22class QObject;
23namespace score
24{
25class CommandStackFacade;
26}
27namespace Device
28{
29struct DeviceSettings;
30struct AddressSettings;
31}
32
33namespace Explorer
34{
35class ListeningManager;
36class DeviceDocumentPlugin;
37class DeviceEditDialog;
38class DeviceExplorerView;
39class DeviceExplorerWidget;
40
52struct SCORE_PLUGIN_DEVICEEXPLORER_EXPORT SelectedNodes
53{
57 std::vector<Device::Node*> parents;
58
62 std::vector<Device::Node*> messages;
63};
64
65class SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceExplorerModel final
67{
68 W_OBJECT(DeviceExplorerModel)
69
70public:
71 using QAbstractItemModel::beginResetModel;
72 using QAbstractItemModel::endResetModel;
73
74 explicit DeviceExplorerModel(DeviceDocumentPlugin&, QObject* parent);
75
77
78 Device::Node& rootNode() override { return m_rootNode; }
79
80 const Device::Node& rootNode() const override { return m_rootNode; }
81
82 void setView(DeviceExplorerView* v) { m_view = v; }
83
84 // The class that does the link with the low-level implementation of the
85 // devices. This is here so that commands don't need to save
86 // at the same time a path to the device explorer, and the device doc plugin.
87 DeviceDocumentPlugin& deviceModel() const;
88 QModelIndexList selectedIndexes() const;
89
90 const score::CommandStackFacade& commandStack() const { return m_cmdQ; }
91
92 // Returns the row (useful for undo)
93 int addDevice(Device::Node&& deviceNode);
94 int addDevice(const Device::Node& deviceNode);
95 void updateDevice(const QString& name, const Device::DeviceSettings& dev);
96
103 bool replaceDevice(Device::Node&& deviceNode);
104
105 Device::Node* addAddress(
106 Device::Node* parentNode, const Device::AddressSettings& addressSettings, int row);
107 void updateAddress(Device::Node* node, const Device::AddressSettings& addressSettings);
108
109 void addNode(Device::Node* parentNode, Device::Node&& child, int row);
110
111 void updateValue(
112 Device::Node* n, const State::AddressAccessor& addr, const ossia::value& v);
113
114 // Checks if the settings can be added; if not,
115 // trigger a dialog to edit them as wanted.
116 // Returns true if the device is to be added, false if
117 // it should not be added.
118 bool checkDeviceInstantiatable(const Device::DeviceSettings& n) const;
119 bool checkDeviceEditable(
120 const QString& originalName, const Device::DeviceSettings& n) const;
121
122 bool
123 checkAddressInstantiatable(Device::Node& parent, const Device::AddressSettings& addr);
124
125 bool checkAddressEditable(
126 Device::Node& parent, const Device::AddressSettings& before,
127 const Device::AddressSettings& after);
128
130 bool canRenameNode(const Device::Node& n) const;
131
132 int columnCount() const;
133 QStringList getColumns() const;
134 bool isEmpty() const;
135 bool isDevice(QModelIndex index) const;
136 bool hasCut() const;
137
138 void debug_printIndexes(const QModelIndexList& indexes);
139
140 int columnCount(const QModelIndex& parent) const override;
141
142 QVariant data(const QModelIndex& index, int role) const override;
143 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
144
145 Qt::ItemFlags flags(const QModelIndex& index) const override;
146
147 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
148 bool setHeaderData(int, Qt::Orientation, const QVariant&, int = Qt::EditRole) override;
149
150 void editData(
151 const Device::NodePath& path, Column column, const ossia::value& value, int role);
152 void editData(Device::Node& n, Column column, const ossia::value& value, int role);
153
154 Qt::DropActions supportedDropActions() const override;
155 Qt::DropActions supportedDragActions() const override;
156 QStringList mimeTypes() const override;
157 QMimeData* mimeData(const QModelIndexList& indexes) const override;
158 bool canDropMimeData(
159 const QMimeData* data, Qt::DropAction action, int row, int column,
160 const QModelIndex& parent) const override;
161 bool dropMimeData(
162 const QMimeData* mimeData, Qt::DropAction action, int row, int column,
163 const QModelIndex& parent) override;
164
165 SelectedNodes uniqueSelectedNodes(const QModelIndexList& indexes)
166 const; // Note : filters so that only parents are given.
167 void checkAndLoadDevice(Device::Node n);
168 void checkAndLoadDevice(Device::DeviceSettings n);
169
170public:
171 void nodeChanged(Device::Node* n)
172 E_SIGNAL(SCORE_PLUGIN_DEVICEEXPLORER_EXPORT, nodeChanged, n)
173
174
182 void valueUpdated(Device::Node* n)
183 E_SIGNAL(SCORE_PLUGIN_DEVICEEXPLORER_EXPORT, valueUpdated, n)
184
187 void deviceTreeAboutToChange(Device::Node* device)
188 E_SIGNAL(SCORE_PLUGIN_DEVICEEXPLORER_EXPORT, deviceTreeAboutToChange, device)
189 void deviceTreeChanged(Device::Node* device)
190 E_SIGNAL(SCORE_PLUGIN_DEVICEEXPLORER_EXPORT, deviceTreeChanged, device)
191
192protected:
193 void debug_printPath(const Device::NodePath& path);
194
195private:
196 DeviceDocumentPlugin& m_devicePlugin;
197
198 QModelIndex bottomIndex(const QModelIndex& index) const;
199
200 Device::Node& m_rootNode;
201
202 const score::CommandStackFacade& m_cmdQ;
203
204 DeviceExplorerView* m_view{};
205};
206
207// Will update the tree and return the messages corresponding to the selected
208// nodes.
209SCORE_PLUGIN_DEVICEEXPLORER_EXPORT State::MessageList
210getSelectionSnapshot(DeviceExplorerModel& model);
211
212SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceExplorerModel&
213deviceExplorerFromObject(const QObject&);
214SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceExplorerModel*
215try_deviceExplorerFromObject(const QObject&);
216SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceExplorerModel*
217try_deviceExplorerFromContext(const score::DocumentContext& ctx);
218SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceExplorerModel&
219deviceExplorerFromContext(const score::DocumentContext& ctx);
220
221// Will try to find a node and fill the structure with it.
222SCORE_PLUGIN_DEVICEEXPLORER_EXPORT Device::FullAddressAccessorSettings
223makeFullAddressAccessorSettings(
224 const State::AddressAccessor& mess, const score::DocumentContext& ctx,
225 ossia::value min, ossia::value max, ossia::value cur);
226}
Definition NodeBasedItemModel.hpp:18
Definition DeviceExplorerModel.hpp:67
Definition DeviceExplorerView.hpp:18
Path in a tree of QAbstractItemModel objects.
Definition TreePath.hpp:34
A small abstraction layer over the score::CommandStack.
Definition CommandStackFacade.hpp:20
Manipulation of Devices from Qt.
Definition AddressSettings.cpp:14
Base toolkit upon which the software is built.
Definition Application.cpp:117
Definition AddressSettings.hpp:49
Definition DeviceSettings.hpp:20
Definition AddressSettings.hpp:131
The SelectedNodes struct.
Definition DeviceExplorerModel.hpp:53
std::vector< Device::Node * > parents
parents The topmost parents of the selected parameters
Definition DeviceExplorerModel.hpp:57
std::vector< Device::Node * > messages
messages The selected messages
Definition DeviceExplorerModel.hpp:62
Definition Address.hpp:108
Definition DocumentContext.hpp:18