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

traintastic / traintastic / 24288605255

11 Apr 2026 06:17PM UTC coverage: 25.599% (-2.4%) from 27.99%
24288605255

push

github

web-flow
Merge pull request #222 from traintastic/cbus

Added CBUS/VLCB hardware support

169 of 3369 new or added lines in 99 files covered. (5.02%)

5 existing lines in 4 files now uncovered.

8300 of 32423 relevant lines covered (25.6%)

178.31 hits per line

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

0.0
/server/src/hardware/input/list/inputlisttablemodel.cpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 2019-2026 Reinder Feenstra
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 */
21

22
#include "inputlisttablemodel.hpp"
23
#include "inputlist.hpp"
24
#include "../inputcontroller.hpp"
25
#include "../../../core/objectproperty.tpp"
26
#include "../../../utils/displayname.hpp"
27

28
bool InputListTableModel::isListedProperty(std::string_view name)
×
29
{
30
  return
31
    name == "interface" ||
×
32
    name == "channel" ||
×
33
    name == "address";
×
34
}
35

36
static std::string_view displayName(InputListColumn column)
×
37
{
38
  switch(column)
×
39
  {
40
    case InputListColumn::Interface:
×
41
      return DisplayName::Hardware::interface;
×
42

43
    case InputListColumn::Channel:
×
44
      return DisplayName::Hardware::channel;
×
45

NEW
46
    case InputListColumn::Node:
×
NEW
47
      return DisplayName::Hardware::node;
×
48

49
    case InputListColumn::Address:
×
50
      return DisplayName::Hardware::address;
×
51
  }
52
  assert(false);
×
53
  return {};
54
}
55

56
InputListTableModel::InputListTableModel(InputList& list)
×
57
  : ObjectListTableModel<Input>(list)
×
58
{
59
  std::vector<std::string_view> labels;
×
60

61
  for(auto column : inputListColumnValues)
×
62
  {
63
    if(contains(list.columns, column))
×
64
    {
65
      labels.emplace_back(displayName(column));
×
66
      m_columns.emplace_back(column);
×
67
    }
68
  }
69

70
  setColumnHeaders(std::move(labels));
×
71
}
×
72

73
std::string InputListTableModel::getText(uint32_t column, uint32_t row) const
×
74
{
75
  if(row < rowCount())
×
76
  {
77
    const Input& input = getItem(row);
×
78

79
    assert(column < m_columns.size());
×
80
    switch(m_columns[column])
×
81
    {
82
      case InputListColumn::Interface:
×
83
        if(const auto& interface = std::dynamic_pointer_cast<Object>(input.interface.value()))
×
84
        {
85
          if(auto* property = interface->getProperty("name"); property && !property->toString().empty())
×
86
            return property->toString();
×
87

88
          return interface->getObjectId();
×
89
        }
×
90
        return "";
×
91

92
      case InputListColumn::Channel:
×
93
        if(input.interface->inputChannels().size() > 1)
×
94
        {
95
          if(const auto* it = EnumValues<InputChannel>::value.find(input.channel); it != EnumValues<InputChannel>::value.end()) /*[[likely]]*/
×
96
          {
97
            return std::string("$").append(EnumName<InputChannel>::value).append(":").append(it->second).append("$");
×
98
          }
99
        }
100
        break;
×
101

NEW
102
      case InputListColumn::Node:
×
NEW
103
        if(hasNodeAddressLocation(input.channel))
×
104
        {
NEW
105
          return std::to_string(input.node.value());
×
106
        }
NEW
107
        return {};
×
108

109
      case InputListColumn::Address:
×
110
        return std::to_string(input.address.value());
×
111
    }
112
    assert(false);
×
113
  }
114

115
  return "";
×
116
}
117

118
void InputListTableModel::propertyChanged(BaseProperty& property, uint32_t row)
×
119
{
120
  std::string_view name = property.name();
×
121

122
  if(name == "interface")
×
123
    changed(row, InputListColumn::Interface);
×
124
  else if(name == "channel")
×
125
    changed(row, InputListColumn::Channel);
×
126
  else if(name == "address")
×
127
    changed(row, InputListColumn::Address);
×
128
}
×
129

130
void InputListTableModel::changed(uint32_t row, InputListColumn column)
×
131
{
132
  for(size_t i = 0; i < m_columns.size(); i++)
×
133
  {
134
    if(m_columns[i] == column)
×
135
    {
136
      TableModel::changed(row, static_cast<uint32_t>(i));
×
137
      return;
×
138
    }
139
  }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc