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

traintastic / traintastic / 26121453997

19 May 2026 07:52PM UTC coverage: 25.063% (-0.6%) from 25.624%
26121453997

Pull #221

github

web-flow
Merge 598936246 into 15e38bcf7
Pull Request #221: Xpressnet new messages

49 of 1129 new or added lines in 16 files covered. (4.34%)

782 existing lines in 21 files now uncovered.

8483 of 33847 relevant lines covered (25.06%)

172.88 hits per line

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

0.0
/server/src/hardware/interface/cbus/cbussessionlisttablemodel.cpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 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 "cbussessionlisttablemodel.hpp"
23
#include "cbussessionlist.hpp"
24
#include "../../../compat/stdformat.hpp"
25
#include "../../../utils/utf8.hpp"
26

27
constexpr uint32_t columnAddress = 0;
28
constexpr uint32_t columnLong = 1;
29
constexpr uint32_t columnSession = 2;
30
constexpr uint32_t columnControlledBy = 3;
31
constexpr uint32_t columnSpeed = 4;
32
constexpr uint32_t columnDirection = 5;
33
constexpr uint32_t columnF0 = 6;
34
constexpr uint32_t columnF1 = 7;
35
constexpr uint32_t columnF2 = 8;
36
constexpr uint32_t columnF3 = 9;
37
constexpr uint32_t columnF4 = 10;
38
constexpr uint32_t columnF5 = 11;
39
constexpr uint32_t columnF6 = 12;
40
constexpr uint32_t columnF7 = 13;
41
constexpr uint32_t columnF8 = 14;
42
constexpr uint32_t columnF9 = 15;
43
constexpr uint32_t columnF10 = 16;
44
constexpr uint32_t columnF11 = 17;
45
constexpr uint32_t columnF12 = 18;
46
constexpr uint32_t columnF13 = 19;
47
constexpr uint32_t columnF14 = 20;
48
constexpr uint32_t columnF15 = 21;
49
constexpr uint32_t columnF16 = 22;
50
constexpr uint32_t columnF17 = 23;
51
constexpr uint32_t columnF18 = 24;
52
constexpr uint32_t columnF19 = 25;
53
constexpr uint32_t columnF20 = 26;
54
constexpr uint32_t columnF21 = 27;
55
constexpr uint32_t columnF22 = 28;
56
constexpr uint32_t columnF23 = 29;
57
constexpr uint32_t columnF24 = 30;
58
constexpr uint32_t columnF25 = 31;
59
constexpr uint32_t columnF26 = 32;
60
constexpr uint32_t columnF27 = 33;
61
constexpr uint32_t columnF28 = 34;
62
constexpr uint32_t columnSteps = 35;
63

64
CBUSSessionListTableModel::CBUSSessionListTableModel(CBUSSessionList& list)
×
UNCOV
65
  : m_list{list.shared_ptr<CBUSSessionList>()}
×
66
{
67
  assert(m_list);
×
UNCOV
68
  m_list->m_models.push_back(this);
×
69

UNCOV
70
  setColumnHeaders({
×
71
    std::string_view{"hardware:address"},
72
    std::string_view{"cbus_session_list:long"},
73
    std::string_view{"cbus_session_list:session"},
74
    std::string_view{"cbus_session_list:controlled_by"},
75
    std::string_view{"cbus_session_list:speed"},
76
    std::string_view{"cbus_session_list:direction"},
77
    std::string_view{"function:f0"},
78
    std::string_view{"function:f1"},
79
    std::string_view{"function:f2"},
80
    std::string_view{"function:f3"},
81
    std::string_view{"function:f4"},
82
    std::string_view{"function:f5"},
83
    std::string_view{"function:f6"},
84
    std::string_view{"function:f7"},
85
    std::string_view{"function:f8"},
86
    std::string_view{"function:f9"},
87
    std::string_view{"function:f10"},
88
    std::string_view{"function:f11"},
89
    std::string_view{"function:f12"},
90
    std::string_view{"function:f13"},
91
    std::string_view{"function:f14"},
92
    std::string_view{"function:f15"},
93
    std::string_view{"function:f16"},
94
    std::string_view{"function:f17"},
95
    std::string_view{"function:f18"},
96
    std::string_view{"function:f19"},
97
    std::string_view{"function:f20"},
98
    std::string_view{"function:f21"},
99
    std::string_view{"function:f22"},
100
    std::string_view{"function:f23"},
101
    std::string_view{"function:f24"},
102
    std::string_view{"function:f25"},
103
    std::string_view{"function:f26"},
104
    std::string_view{"function:f27"},
105
    std::string_view{"function:f28"},
106
    std::string_view{"hardware:speed_steps"}
107
  });
108

UNCOV
109
  setRowCount(m_list->m_sessions.size());
×
110
}
×
111

112
CBUSSessionListTableModel::~CBUSSessionListTableModel()
×
113
{
114
  auto it = std::find(m_list->m_models.begin(), m_list->m_models.end(), this);
×
115
  assert(it != m_list->m_models.end());
×
UNCOV
116
  m_list->m_models.erase(it);
×
117
}
×
118

119
std::string CBUSSessionListTableModel::getText(uint32_t column, uint32_t row) const
×
120
{
121
  if(row < m_list->m_sessions.size())
×
122
  {
123
    const auto& session = m_list->m_sessions[row];
×
124

125
    switch(column)
×
126
    {
127

128
      case columnAddress:
×
UNCOV
129
        return std::to_string(session.address);
×
130

UNCOV
131
      case columnLong:
×
132
        return session.isLongAddress ? UTF8_CHECKMARK : "";
×
133

UNCOV
134
      case columnSession:
×
135
        if(session.session)
×
136
        {
UNCOV
137
          return std::to_string(*session.session);
×
138
        }
139
        break;
×
140

141
      case columnControlledBy:
×
UNCOV
142
        if(session.external)
×
143
        {
UNCOV
144
          return *session.external ? "CBUS/VLCB" : "Traintastic";
×
145
        }
UNCOV
146
        break;
×
147

UNCOV
148
      case columnSpeed:
×
149
        if(session.speed)
×
150
        {
151
          if(*session.speed == 0)
×
152
          {
153
            return "$throttle.stop$";
×
154
          }
UNCOV
155
          if(*session.speed == 1)
×
156
          {
UNCOV
157
            return "$throttle.estop$";
×
158
          }
UNCOV
159
          return std::to_string(*session.speed - 1);
×
160
        }
161
        break;
×
162

163
      case columnDirection:
×
UNCOV
164
        if(session.direction != Direction::Unknown)
×
165
        {
UNCOV
166
          if(const auto* it = EnumValues<Direction>::value.find(session.direction); it != EnumValues<Direction>::value.end()) [[likely]]
×
167
          {
UNCOV
168
            return std::format("${}:{}$", EnumName<Direction>::value, it->second);
×
169
          }
170
        }
UNCOV
171
        break;
×
172

UNCOV
173
      case columnF0:
×
174
      case columnF1:
175
      case columnF2:
176
      case columnF3:
177
      case columnF4:
178
      case columnF5:
179
      case columnF6:
180
      case columnF7:
181
      case columnF8:
182
      case columnF9:
183
      case columnF10:
184
      case columnF11:
185
      case columnF12:
186
      case columnF13:
187
      case columnF14:
188
      case columnF15:
189
      case columnF16:
190
      case columnF17:
191
      case columnF18:
192
      case columnF19:
193
      case columnF20:
194
      case columnF21:
195
      case columnF22:
196
      case columnF23:
197
      case columnF24:
198
      case columnF25:
199
      case columnF26:
200
      case columnF27:
201
      case columnF28:
202
        switch(session.functions[column - columnF0])
×
203
        {
204
          using enum TriState;
205

UNCOV
206
          case False:
×
207
            return "$function:off$";
×
208

UNCOV
209
          case True:
×
UNCOV
210
            return "$function:on$";
×
211

UNCOV
212
          case Undefined:
×
UNCOV
213
            break;
×
214
        };
UNCOV
215
        break;
×
216

UNCOV
217
      case columnSteps:
×
UNCOV
218
        return std::to_string(session.steps);
×
219
    }
220
  }
UNCOV
221
  return {};
×
222
}
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