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

traintastic / traintastic / 23088148108

14 Mar 2026 12:40PM UTC coverage: 26.661% (-0.2%) from 26.84%
23088148108

push

github

reinder
[cbus] added input support for short/long events

0 of 133 new or added lines in 4 files covered. (0.0%)

587 existing lines in 20 files now uncovered.

8246 of 30929 relevant lines covered (26.66%)

185.83 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

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

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

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

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

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

UNCOV
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
    {
UNCOV
65
      labels.emplace_back(displayName(column));
×
UNCOV
66
      m_columns.emplace_back(column);
×
67
    }
68
  }
69

UNCOV
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

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

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

UNCOV
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
          {
UNCOV
97
            return std::string("$").append(EnumName<InputChannel>::value).append(":").append(it->second).append("$");
×
98
          }
99
        }
100
        break;
×
101

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

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

115
  return "";
×
116
}
117

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

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

UNCOV
130
void InputListTableModel::changed(uint32_t row, InputListColumn column)
×
131
{
UNCOV
132
  for(size_t i = 0; i < m_columns.size(); i++)
×
133
  {
UNCOV
134
    if(m_columns[i] == column)
×
135
    {
UNCOV
136
      TableModel::changed(row, static_cast<uint32_t>(i));
×
UNCOV
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