Loading...
Searching...
No Matches
NodeBasedItemModel.hpp
1#pragma once
2#include <Device/Address/AddressSettings.hpp>
3#include <Device/Node/DeviceNode.hpp>
4#include <Device/Protocol/DeviceSettings.hpp>
5
6#include <score/model/tree/InvisibleRootNode.hpp>
7#include <score/model/tree/TreeNode.hpp>
8#include <score/model/tree/TreeNodeItemModel.hpp>
9
10#include <score_lib_device_export.h>
11
12#include <optional>
13#include <vector>
14
15namespace score
16{
17struct DocumentContext;
18}
19namespace Device
20{
21class SCORE_LIB_DEVICE_EXPORT NodeBasedItemModel
22 : public TreeNodeBasedItemModel<Device::Node>
23{
24public:
26 virtual ~NodeBasedItemModel();
27
28 QModelIndex modelIndexFromNode(node_type& n, int column) const
29 {
30 if(n.is<InvisibleRootNode>())
31 {
32 return QModelIndex();
33 }
34 else if(n.is<Device::DeviceSettings>())
35 {
36 SCORE_ASSERT(n.parent());
37 return createIndex(n.parent()->indexOfChild(&n), 0, &n);
38 }
39 else
40 {
41 node_type* parent = n.parent();
42 SCORE_ASSERT(parent);
43 SCORE_ASSERT(parent != &rootNode());
44
45 return createIndex(parent->indexOfChild(&n), column, &n);
46 }
47 }
48
49 void insertNode(node_type& parentNode, const node_type& other, int row)
50 {
51 QModelIndex parentIndex = modelIndexFromNode(parentNode, 0);
52
53 beginInsertRows(parentIndex, row, row);
54
55 auto it = parentNode.begin();
56 std::advance(it, row);
57 parentNode.emplace(it, other, &parentNode);
58
59 endInsertRows();
60 }
61
62 auto removeNode(node_type::const_iterator node)
63 {
64 SCORE_ASSERT(!node->is<InvisibleRootNode>());
65
66 if(node->is<Device::AddressSettings>())
67 {
68 node_type* parent = node->parent();
69 SCORE_ASSERT(parent);
70 SCORE_ASSERT(parent != &rootNode());
71 node_type* grandparent = parent->parent();
72 SCORE_ASSERT(grandparent);
73 int rowParent = grandparent->indexOfChild(parent);
74 QModelIndex parentIndex = createIndex(rowParent, 0, parent);
75
76 int row = parent->indexOfChild(&*node);
77
78 beginRemoveRows(parentIndex, row, row);
79 auto it = parent->erase(node);
80 endRemoveRows();
81 return it;
82 }
83 else
84 {
85 SCORE_ASSERT(node->is<Device::DeviceSettings>());
86 int row = rootNode().indexOfChild(&*node);
87
88 beginRemoveRows(QModelIndex(), row, row);
89 auto it = rootNode().erase(node);
90 endRemoveRows();
91 return it;
92 }
93 }
94};
95
96SCORE_LIB_DEVICE_EXPORT Device::FullAddressAccessorSettings
97makeFullAddressAccessorSettings(
99 ossia::value min, ossia::value max, ossia::value val);
100SCORE_LIB_DEVICE_EXPORT Device::FullAddressAccessorSettings
101makeFullAddressAccessorSettings(const Device::Node& mess);
102
104SCORE_LIB_DEVICE_EXPORT std::optional<Device::AddressSettings>
106
108SCORE_LIB_DEVICE_EXPORT Device::FullAddressAccessorSettings
109makeFullAddressAccessorSettings(
110 const State::AddressAccessor& mess, const score::DocumentContext& ctx,
111 ossia::value min, ossia::value max, ossia::value val);
112}
Definition NodeBasedItemModel.hpp:23
Definition TreeNodeItemModel.hpp:38
Manipulation of Devices from Qt.
Definition AddressSettings.cpp:14
std::optional< Device::AddressSettings > addressSettings(const State::Address &addr, const score::DocumentContext &ctx)
From the explorer's node if shown there, else the device's own node.
Definition NodeBasedItemModel.cpp:86
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition AddressSettings.hpp:49
Definition DeviceSettings.hpp:20
Definition AddressSettings.hpp:131
The InvisibleRootNodeTag struct.
Definition InvisibleRootNode.hpp:11
Definition Address.hpp:136
The Address struct.
Definition Address.hpp:81
Definition DocumentContext.hpp:18