• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 31257898803

08 Aug 2026 12:43PM UTC coverage: 15.185% (-0.08%) from 15.265%
31257898803

push

github

jcelerier
addons: add sysinfo addon

30517 of 200963 relevant lines covered (15.19%)

1072.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/plugins/score-lib-device/Device/ItemModels/NodeDisplayMethods.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
#include "NodeDisplayMethods.hpp"
4

5
#include <State/Domain.hpp>
6
#include <State/Value.hpp>
7
#include <State/ValueConversion.hpp>
8

9
#include <Device/Address/AddressSettings.hpp>
10
#include <Device/Address/IOType.hpp>
11
#include <Device/Node/DeviceNode.hpp>
12
#include <Device/Protocol/DeviceInterface.hpp>
13
#include <Device/Protocol/DeviceSettings.hpp>
14

15
#include <ossia/network/domain/domain.hpp>
16
#include <ossia/network/value/value_conversion.hpp>
17

18
#include <QBrush>
19
#include <QFont>
20
#include <qnamespace.h>
21

22
namespace ossia
23
{
24

25
// TODO MOVEME
26
template <>
27
QVariant convert(const ossia::value& val)
×
28
{
29
  struct vis
30
  {
31
  public:
32
    using return_type = QVariant;
33
    return_type operator()(const ossia::impulse& v) const
×
34
    {
35
      return QVariant::fromValue(v);
×
36
    }
37
    return_type operator()(int i) const { return QVariant::fromValue(i); }
×
38
    return_type operator()(float f) const { return QVariant::fromValue(f); }
×
39
    return_type operator()(bool b) const { return QVariant::fromValue(b); }
×
40
    return_type operator()(const std::string& s) const
×
41
    {
42
      return QString::fromStdString(s);
×
43
    }
×
44
    return_type operator()(char c) const { return QVariant::fromValue(QChar(c)); }
45

46
    return_type operator()(ossia::vec2f t) const { return QVector2D{t[0], t[1]}; }
×
47
    return_type operator()(ossia::vec3f t) const { return QVector3D{t[0], t[1], t[2]}; }
×
48
    return_type operator()(ossia::vec4f t) const
×
49
    {
50
      return QVector4D{t[0], t[1], t[2], t[3]};
×
51
    }
52
    return_type operator()(const std::vector<ossia::value>& t) const
×
53
    {
54
      QVariantList arr;
×
55
      arr.reserve(t.size());
×
56

57
      for(const auto& elt : t)
×
58
      {
59
        arr.push_back(ossia::apply_nonnull(*this, elt.v));
×
60
      }
61

62
      return arr;
×
63
    }
×
64
    return_type operator()(const ossia::value_map_type& t) const
×
65
    {
66
      QVariantMap arr;
×
67

68
      for(const auto& [k, v] : t)
×
69
      {
70
        arr.insert(QString::fromStdString(k), ossia::apply_nonnull(*this, v));
×
71
      }
72

73
      return arr;
×
74
    }
×
75
    return_type operator()() const { return {}; }
×
76
  };
77

78
  return val.apply(vis{});
×
79
}
80
}
81
namespace Device
82
{
83
QVariant nameColumnData(const Device::Node& node, int role)
×
84
{
85
  static const QFont& italicFont{[]() {
×
86
    static QFont f;
×
87
    f.setItalic(true);
×
88
    return f;
×
89
  }()};
×
90

91
  using namespace score;
92

93
  const auto ioType = node.get<Device::AddressSettings>().ioType;
×
94
  switch(role)
×
95
  {
96
    case Qt::DisplayRole:
97
    case Qt::EditRole:
98
      return node.displayName();
×
99
    case Qt::FontRole: {
100
      if(ioType == ossia::access_mode::GET || ioType == ossia::access_mode::SET)
×
101
      {
102
        return italicFont;
×
103
      }
104
      return {};
×
105
    }
106
    case Qt::ForegroundRole: {
107
      if(ioType == ossia::access_mode::GET || ioType == ossia::access_mode::SET)
×
108
      {
109
        return QBrush(Qt::lightGray);
×
110
      }
111
      return {};
×
112
    }
113
    default:
114
      return {};
×
115
  }
116
}
×
117

118
QVariant deviceNameColumnData(const Device::Node& node, bool connected, int role)
×
119
{
120
  static const QFont& italicFont{[]() {
×
121
    static QFont f;
×
122
    f.setItalic(true);
×
123
    return f;
×
124
  }()};
×
125

126
  using namespace score;
127

128
  switch(role)
×
129
  {
130
    case Qt::DisplayRole: {
131
      const auto& name = node.get<DeviceSettings>().name;
×
132
      return connected ? name : name + " (disconnected)";
×
133
    }
134
    case Qt::EditRole:
135
      return node.get<DeviceSettings>().name;
×
136
    case Qt::FontRole: {
137
      if(!connected)
×
138
        return italicFont;
×
139
      return {};
×
140
    }
141
    default:
142
      return {};
×
143
  }
144
}
×
145

146
QVariant valueColumnData(const Device::Node& node, int role)
×
147
{
148
  using namespace score;
149
  if(node.is<DeviceSettings>())
×
150
    return {};
×
151

152
  if(role == Qt::DisplayRole || role == Qt::EditRole)
×
153
  {
154
    const ossia::value& val = node.get<AddressSettings>().value;
×
155
    if(ossia::is_array(val))
×
156
    {
157
      // TODO a nice editor for lists.
158
      return State::convert::toPrettyString(val);
×
159
    }
160
    else if(role == Qt::DisplayRole && val.get_type() == ossia::val_type::FLOAT)
×
161
    {
162
      // Done here explicitely to avoid Qt's default scientific notation QLocale conversion
163
      return State::convert::toPrettyString(*val.target<float>());
×
164
    }
165
    else
166
    {
167
      return State::convert::value<QVariant>(val);
×
168
    }
169
  }
170
  else if(role == Qt::ForegroundRole)
×
171
  {
172
    const auto ioType = node.get<AddressSettings>().ioType;
×
173

174
    if(ioType)
×
175
    {
176
      switch(*ioType)
×
177
      {
178
        case ossia::access_mode::GET:
179
          return QBrush(Qt::darkGray);
×
180
        case ossia::access_mode::SET:
181
          return QBrush(Qt::lightGray);
×
182
        default:
183
          return {};
×
184
      }
185
    }
186
  }
×
187

188
  return {};
×
189
}
×
190

191
QVariant GetColumnData(const Device::Node& node, int role)
×
192
{
193
  using namespace score;
194
  if(node.is<DeviceSettings>())
×
195
    return {};
×
196

197
  /*
198
  if(role == Qt::DisplayRole || role == Qt::EditRole)
199
  {
200
      switch(node.get<AddressSettings>().ioType)
201
      {
202
          case ossia::access_mode::GET:    return true;
203
          case ossia::access_mode::SET:   return false;
204
          case ossia::access_mode::BI: return true;
205
          case IOType::Invalid: return QVariant{};
206
          default:            return QVariant{};
207
      }
208
  }
209
  */
210

211
  if(role == Qt::CheckStateRole)
×
212
  {
213
    const auto ioType = node.get<AddressSettings>().ioType;
×
214
    if(ioType)
×
215
    {
216
      switch(*ioType)
×
217
      {
218
        case ossia::access_mode::GET:
219
          return Qt::Checked;
×
220
        case ossia::access_mode::SET:
221
          return Qt::Unchecked;
×
222
        case ossia::access_mode::BI:
223
          return Qt::Checked;
×
224
      }
225
    }
×
226
    return Qt::Unchecked;
×
227
  }
228

229
  return {};
×
230
}
×
231
QVariant SetColumnData(const Device::Node& node, int role)
×
232
{
233
  using namespace score;
234
  if(node.is<DeviceSettings>())
×
235
    return {};
×
236

237
  /*
238
  if(role == Qt::DisplayRole || role == Qt::EditRole)
239
  {
240
      switch(node.get<AddressSettings>().ioType)
241
      {
242
          case ossia::access_mode::GET:    return false;
243
          case ossia::access_mode::SET:   return true;
244
          case ossia::access_mode::BI: return true;
245
          case IOType::Invalid: return true;
246
          default:            return QVariant{};
247
      }
248
  }
249
  */
250

251
  if(role == Qt::CheckStateRole)
×
252
  {
253
    const auto ioType = node.get<AddressSettings>().ioType;
×
254
    if(ioType)
×
255
    {
256
      switch(*ioType)
×
257
      {
258
        case ossia::access_mode::GET:
259
          return Qt::Unchecked;
×
260
        case ossia::access_mode::SET:
261
          return Qt::Checked;
×
262
        case ossia::access_mode::BI:
263
          return Qt::Checked;
×
264
      }
265
    }
×
266
    return Qt::Unchecked;
×
267
  }
268
  return {};
×
269
}
×
270

271
QVariant minColumnData(const Device::Node& node, int role)
×
272
{
273
  using namespace score;
274
  if(node.is<DeviceSettings>())
×
275
    return {};
×
276

277
  if(role == Qt::DisplayRole || role == Qt::EditRole)
×
278
  {
279
    return node.get<AddressSettings>().domain.get().convert_min<QVariant>();
×
280
  }
281

282
  return {};
×
283
}
×
284

285
QVariant maxColumnData(const Device::Node& node, int role)
×
286
{
287
  using namespace score;
288
  if(node.is<DeviceSettings>())
×
289
    return {};
×
290

291
  if(role == Qt::DisplayRole || role == Qt::EditRole)
×
292
  {
293
    return node.get<AddressSettings>().domain.get().convert_max<QVariant>();
×
294
  }
295

296
  return {};
×
297
}
×
298
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc