OSSIA
Open Scenario System for Interactive Application
qml_node_base.hpp
1 #pragma once
2 #include <ossia/detail/optional.hpp>
3 #include <ossia/network/base/parameter.hpp>
4 
5 #include <boost/any.hpp>
6 
7 #include <QObject>
8 #include <QPointer>
9 #include <QQuickItem>
10 #include <QString>
11 #include <QVariantMap>
12 
13 #include <nano_observer.hpp>
14 
15 #include <verdigris>
16 namespace ossia
17 {
18 namespace net
19 {
20 class node_base;
21 class parameter_base;
22 }
23 namespace qt
24 {
25 class qml_device;
26 class OSSIA_EXPORT qml_node_base
27  : public QQuickItem
28  , public Nano::Observer
29 {
30  W_OBJECT(qml_node_base)
31 
32 public:
33  qml_node_base(QQuickItem* parent = nullptr);
34  ~qml_node_base();
35 
36  QString node() const;
37  QObject* device() const;
38  ossia::net::node_base* ossiaNode();
39 
40  QString path() const;
41 
42  virtual void resetNode() = 0;
43 
44  qml_node_base* parentNode() const;
45 
46  qreal priority() const;
47  QString description() const;
48  QStringList tags() const;
49  qint32 refreshRate() const;
50  qreal stepSize() const;
51  QVariant defaultValue() const;
52  bool critical() const;
53  bool hidden() const;
54  bool disabled() const;
55  bool muted() const;
56  QString extendedType() const;
57 
58 public:
59  void setNode(QString node);
60  W_SLOT(setNode);
61  virtual void setDevice(QObject* device);
62  W_SLOT(setDevice);
63 
64  void setParentNode(qml_node_base* parentNode);
65  W_SLOT(setParentNode);
66  void setPriority(qreal priority);
67  W_SLOT(setPriority);
68  void setDescription(QString description);
69  W_SLOT(setDescription);
70  void setTags(QStringList tags);
71  W_SLOT(setTags);
72  void setExtendedType(QString extendedType);
73  W_SLOT(setExtendedType);
74  void setRefreshRate(qint32 refreshRate);
75  W_SLOT(setRefreshRate);
76  void setStepSize(qreal stepSize);
77  W_SLOT(setStepSize);
78  void setDefaultValue(QVariant defaultValue);
79  W_SLOT(setDefaultValue);
80  void setCritical(bool critical);
81  W_SLOT(setCritical);
82  void setHidden(bool hidden);
83  W_SLOT(setHidden);
84  void setDisabled(bool disabled);
85  W_SLOT(setDisabled);
86  void setMuted(bool muted);
87  W_SLOT(setMuted);
88 
89 public:
90  void nodeChanged(QString node) E_SIGNAL(OSSIA_EXPORT, nodeChanged, node);
91  void deviceChanged(qml_device* device) E_SIGNAL(OSSIA_EXPORT, deviceChanged, device);
92  void pathChanged(QString path) E_SIGNAL(OSSIA_EXPORT, pathChanged, path);
93 
94  void parentNodeChanged(qml_node_base* parentNode)
95  E_SIGNAL(OSSIA_EXPORT, parentNodeChanged, parentNode);
96 
97  void priorityChanged(qreal priority) E_SIGNAL(OSSIA_EXPORT, priorityChanged, priority);
98  void descriptionChanged(QString description)
99  E_SIGNAL(OSSIA_EXPORT, descriptionChanged, description);
100  void extendedTypeChanged(QString extendedType)
101  E_SIGNAL(OSSIA_EXPORT, extendedTypeChanged, extendedType);
102  void tagsChanged(QStringList tags) E_SIGNAL(OSSIA_EXPORT, tagsChanged, tags);
103  void refreshRateChanged(qint32 refreshRate)
104  E_SIGNAL(OSSIA_EXPORT, refreshRateChanged, refreshRate);
105  void stepSizeChanged(qreal stepSize) E_SIGNAL(OSSIA_EXPORT, stepSizeChanged, stepSize);
106  void defaultValueChanged(QVariant defaultValue)
107  E_SIGNAL(OSSIA_EXPORT, defaultValueChanged, defaultValue);
108  void criticalChanged(bool critical) E_SIGNAL(OSSIA_EXPORT, criticalChanged, critical);
109  void hiddenChanged(bool hidden) E_SIGNAL(OSSIA_EXPORT, hiddenChanged, hidden);
110  void disabledChanged(bool d) E_SIGNAL(OSSIA_EXPORT, disabledChanged, d);
111  void mutedChanged(bool muted) E_SIGNAL(OSSIA_EXPORT, mutedChanged, muted);
112 
113 protected:
114  void applyNodeAttributes();
115  ossia::net::node_base& get_parent(QObject* obj, bool relative);
116 
117  void setPath(QString str);
118  ossia::net::node_base& findClosestParent(QObject* obj, ossia::net::node_base& root);
119 
120  QString m_node;
121  QString m_userRequestedNode;
122  QPointer<qml_device> m_device{};
123  QPointer<qml_node_base> m_parentNode{};
124  ossia::net::node_base* m_ossia_node{};
125  QString m_path;
126 
127  // Attributes :
128  QString m_description;
129  QString m_extendedType;
130  QStringList m_tags;
131  QVariant m_defaultValue;
132  qreal m_priority{};
133  qint32 m_refreshRate{};
134  qreal m_stepSize{};
135  bool m_critical{};
136  bool m_hidden{};
137  bool m_disabled{};
138  bool m_muted{};
139 
140  bool m_was_destroyed{false};
141 
142  W_PROPERTY(bool, muted READ muted WRITE setMuted NOTIFY mutedChanged, W_Final)
143 
144  W_PROPERTY(
145  bool, disabled READ disabled WRITE setDisabled NOTIFY disabledChanged, W_Final)
146 
147  W_PROPERTY(bool, hidden READ hidden WRITE setHidden NOTIFY hiddenChanged, W_Final)
148 
149  W_PROPERTY(
150  bool, critical READ critical WRITE setCritical NOTIFY criticalChanged, W_Final)
151 
152  W_PROPERTY(
153  QVariant,
154  defaultValue READ defaultValue WRITE setDefaultValue NOTIFY defaultValueChanged,
155  W_Final)
156 
157  W_PROPERTY(
158  qreal, stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged, W_Final)
159 
160  W_PROPERTY(
161  qint32,
162  refreshRate READ refreshRate WRITE setRefreshRate NOTIFY refreshRateChanged,
163  W_Final)
164 
165  W_PROPERTY(
166  qreal, priority READ priority WRITE setPriority NOTIFY priorityChanged, W_Final)
167 
168  W_PROPERTY(QStringList, tags READ tags WRITE setTags NOTIFY tagsChanged, W_Final)
169 
170  W_PROPERTY(
171  QString,
172  extendedType READ extendedType WRITE setExtendedType NOTIFY extendedTypeChanged,
173  W_Final)
174 
175  W_PROPERTY(
176  QString,
177  description READ description WRITE setDescription NOTIFY descriptionChanged,
178  W_Final)
179 
180  W_PROPERTY(
181  qml_node_base*,
182  parentNode READ parentNode WRITE setParentNode NOTIFY parentNodeChanged, W_Final)
183 
184  W_PROPERTY(QObject*, device READ device WRITE setDevice NOTIFY deviceChanged)
185 
186  W_PROPERTY(QString, path READ path NOTIFY pathChanged, W_Final)
187 
188  W_PROPERTY(QString, node READ node WRITE setNode NOTIFY nodeChanged, W_Final)
189 };
190 
191 class OSSIA_EXPORT qml_property_base : public qml_node_base
192 {
193 public:
194  void on_node_deleted(const net::node_base& n);
195  ~qml_property_base();
196 
197 protected:
198  using qml_node_base::qml_node_base;
199  void clearNode(bool reading);
200 
201  ossia::net::parameter_base* m_param{};
202  std::optional<ossia::net::parameter_base::iterator> m_callback;
203 };
204 }
205 }
206 
207 W_REGISTER_ARGTYPE(ossia::qt::qml_node_base*)
The node_base class.
Definition: network/base/node.hpp:48
The parameter_base class.
Definition: ossia/network/base/parameter.hpp:48
Definition: git_info.h:7
std::string description
Human-readable description of a node.
Definition: node_attributes.hpp:74
bool disabled
A disabled node.
Definition: node_attributes.hpp:95
bool critical
Means that the node is very important, e.g. a "play" message.
Definition: node_attributes.hpp:92
bool hidden
Means that the node should not be advertised by default.
Definition: node_attributes.hpp:101
std::vector< std::string > tags
Tags applied to a node: {"model", "interesting", ...}.
Definition: node_attributes.hpp:71
float priority
When a node must be sent before other.
Definition: node_attributes.hpp:77
bool muted
Means that the node should not send / receives network messages.
Definition: node_attributes.hpp:104