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

traintastic / traintastic / 22823086659

08 Mar 2026 02:30PM UTC coverage: 26.831% (+0.06%) from 26.774%
22823086659

push

github

reinder
[cbus] renamed CBUSAccessory(Short) to Long/Short event and added node setting for Long events.

0 of 15 new or added lines in 2 files covered. (0.0%)

1909 existing lines in 38 files now uncovered.

8230 of 30674 relevant lines covered (26.83%)

186.8 hits per line

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

0.0
/server/src/hardware/output/list/outputlisttablemodel.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 "outputlisttablemodel.hpp"
23
#include "outputlist.hpp"
24
#include "../addressoutput.hpp"
25
#include "../outputcontroller.hpp"
26
#include "../../../core/objectproperty.tpp"
27
#include "../../../utils/displayname.hpp"
28

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

38
static std::string_view displayName(OutputListColumn column)
×
39
{
40
  switch(column)
×
41
  {
42
    case OutputListColumn::Interface:
×
43
      return DisplayName::Hardware::interface;
×
44

45
    case OutputListColumn::Channel:
×
46
      return DisplayName::Hardware::channel;
×
47

48
    case OutputListColumn::Node:
×
49
      return DisplayName::Hardware::node;
×
50

51
    case OutputListColumn::Address:
×
UNCOV
52
      return DisplayName::Hardware::address;
×
53
  }
UNCOV
54
  assert(false);
×
55
  return {};
56
}
57

58
OutputListTableModel::OutputListTableModel(OutputList& list) :
×
UNCOV
59
  ObjectListTableModel<Output>(list)
×
60
{
UNCOV
61
  std::vector<std::string_view> labels;
×
62

UNCOV
63
  for(auto column : outputListColumnValues)
×
64
  {
65
    if(contains(list.columns, column))
×
66
    {
UNCOV
67
      labels.emplace_back(displayName(column));
×
UNCOV
68
      m_columns.emplace_back(column);
×
69
    }
70
  }
71

72
  setColumnHeaders(std::move(labels));
×
UNCOV
73
}
×
74

UNCOV
75
std::string OutputListTableModel::getText(uint32_t column, uint32_t row) const
×
76
{
UNCOV
77
  if(row < rowCount())
×
78
  {
79
    const Output& output = getItem(row);
×
80

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

UNCOV
90
          return interface->getObjectId();
×
91
        }
×
92
        return "";
×
93

94
      case OutputListColumn::Channel:
×
UNCOV
95
        if(const auto* it = EnumValues<OutputChannel>::value.find(output.channel); it != EnumValues<OutputChannel>::value.end()) /*[[likely]]*/
×
96
        {
UNCOV
97
          return std::string("$").append(EnumName<OutputChannel>::value).append(":").append(it->second).append("$");
×
98
        }
99
        break;
×
100

101
      case OutputListColumn::Node:
×
UNCOV
102
        if(const auto* addressOutput = dynamic_cast<const AddressOutput*>(&output); addressOutput && hasNode(addressOutput->channel))
×
103
        {
UNCOV
104
          return std::to_string(addressOutput->node.value());
×
105
        }
UNCOV
106
        return {};
×
107

108
      case OutputListColumn::Address:
×
UNCOV
109
        if(const auto* addressOutput = dynamic_cast<const AddressOutput*>(&output))
×
110
        {
111
          return std::to_string(addressOutput->address.value());
×
112
        }
113
        return {};
×
114
    }
115
    assert(false);
×
116
  }
117

118
  return "";
×
119
}
120

121
void OutputListTableModel::propertyChanged(BaseProperty& property, uint32_t row)
×
122
{
123
  std::string_view name = property.name();
×
124

125
  if(name == "interface")
×
UNCOV
126
    changed(row, OutputListColumn::Interface);
×
127
  else if(name == "channel")
×
UNCOV
128
    changed(row, OutputListColumn::Channel);
×
129
  else if(name == "node")
×
130
    changed(row, OutputListColumn::Node);
×
UNCOV
131
  else if(name == "address")
×
UNCOV
132
    changed(row, OutputListColumn::Address);
×
UNCOV
133
}
×
134

UNCOV
135
void OutputListTableModel::changed(uint32_t row, OutputListColumn column)
×
136
{
UNCOV
137
  for(size_t i = 0; i < m_columns.size(); i++)
×
138
  {
UNCOV
139
    if(m_columns[i] == column)
×
140
    {
UNCOV
141
      TableModel::changed(row, static_cast<uint32_t>(i));
×
UNCOV
142
      return;
×
143
    }
144
  }
145
}
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