NameProperty.hpp
1 #pragma once
2 #include <LocalTree/BaseProperty.hpp>
3 
4 #include <score/model/ModelMetadata.hpp>
5 
6 #include <ossia/network/base/node.hpp>
7 
8 #include <QDebug>
9 namespace LocalTree
10 {
11 
13 {
14  score::ModelMetadata& metadata;
15 
16 public:
17  ossia::net::node_base& node;
18 
20  ossia::net::node_base& parent, score::ModelMetadata& arg_metadata,
21  QObject* context)
22  : metadata{arg_metadata}
23  , node{*parent.create_child(arg_metadata.getName().toStdString())}
24  {
25  /* // TODO do me with nano-signal-slot in device.hpp
26  m_callbackIt =
27  node->addCallback(
28  [=] (const OSSIA::net::Node& node, const std::string& name,
29  OSSIA::net::NodeChange t) {
30  if(t == OSSIA::net::NodeChange::RENAMED)
31  {
32  auto str = QString::fromStdString(node.getName());
33  if(str != metadata().name())
34  metadata().setName(str);
35  }
36  });
37  */
38 
39  auto setNameFun = [this](const QString& newName_qstring) {
40  const auto newName = newName_qstring.toStdString();
41  const auto curName = node.get_name();
42 
43  if(curName != newName)
44  {
45  node.set_name(newName);
46  auto real_newName = node.get_name();
47  if(real_newName != newName)
48  {
49  const auto& x = QString::fromStdString(real_newName);
50  qDebug() << "ERROR (real_newName/newName)" << x << newName_qstring;
51  metadata.setName(x);
52  }
53  }
54  };
55 
56  QObject::connect(&metadata, &score::ModelMetadata::NameChanged, context, setNameFun);
57 
58  setNameFun(metadata.getName());
59  }
60 
62  {
63  auto par = node.get_parent();
64  if(par)
65  par->remove_child(node);
66  }
67 };
68 
69 }
Definition: NameProperty.hpp:13
The ModelMetadata class.
Definition: ModelMetadata.hpp:22
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition: BaseCallbackWrapper.hpp:9