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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

96.55
/engine/src/bus.cpp
1
/*
2
  Q Light Controller Plus
3
  bus.cpp
4

5
  Copyright (C) Heikki Junnila
6
                Massimo Callegari
7

8
  Licensed under the Apache License, Version 2.0 (the "License");
9
  you may not use this file except in compliance with the License.
10
  You may obtain a copy of the License at
11

12
      http://www.apache.org/licenses/LICENSE-2.0.txt
13

14
  Unless required by applicable law or agreed to in writing, software
15
  distributed under the License is distributed on an "AS IS" BASIS,
16
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
  See the License for the specific language governing permissions and
18
  limitations under the License.
19
*/
20

21
#include <QXmlStreamReader>
22
#include <QStringList>
23
#include <QDebug>
24

25
#include "bus.h"
26

27
#define KBusCount 32
28
#define KBusIDDefaultFade 0
29
#define KBusIDDefaultHold 1
30
#define KBusIDDefaultPalette KBusCount - 1
31
#define KBusIDInvalid UINT_MAX
32

33
/****************************************************************************
34
 * BusEntry
35
 ****************************************************************************/
36

37
/**
38
 * BusEntry is practically THE bus, while Bus is only the common access point
39
 * for individual BusEntry instances. BusEntry instances are entities that have
40
 * only a name and a value that can be set thru Bus with the entries' index
41
 * numbers that correspond to their position in Bus::m_buses list. Since
42
 * BusEntry is such a simple class, it's not a QObject and therefore it cannot
43
 * emit signals. BusEntries act just as storing locations for the values and
44
 * names for each of the buses, while Bus itself handles signal emission and
45
 * set/get methods.
46
 */
47
class BusEntry
48
{
49
public:
50
    BusEntry()
5,184✔
51
    {
5,184✔
52
        value = 0;
5,184✔
53
    }
5,184✔
54

55
    ~BusEntry()
5,184✔
56
    {
57
    }
5,184✔
58

59
    BusEntry(const BusEntry& entry)
60
    {
61
        name = entry.name;
62
        value = entry.value;
63
    }
64

65
    QString name;
66
    quint32 value;
67
};
68

69
/****************************************************************************
70
 * Initialization
71
 ****************************************************************************/
72

73
Bus* Bus::s_instance = NULL;
74

75
void Bus::init(QObject* parent)
198✔
76
{
77
    if (s_instance == NULL)
198✔
78
    {
79
        Q_ASSERT(parent != NULL);
162✔
80
        s_instance = new Bus(parent);
162✔
81
    }
82
}
198✔
83

84
Bus* Bus::instance()
58✔
85
{
86
    return s_instance;
58✔
87
}
88

89
Bus::Bus(QObject* parent) : QObject(parent)
162✔
90
{
91
    for (quint32 i = 0; i < Bus::count(); i++)
5,346✔
92
        m_buses.append(new BusEntry);
5,184✔
93

94
    m_buses[defaultFade()]->name = QString("Fade");
162✔
95
    m_buses[defaultHold()]->name = QString("Hold");
162✔
96
    m_buses[defaultPalette()]->name = QString("Palette");
162✔
97
}
162✔
98

99
quint32 Bus::count()
5,351✔
100
{
101
    return KBusCount;
5,351✔
102
}
103

104
quint32 Bus::defaultFade()
163✔
105
{
106
    return KBusIDDefaultFade;
163✔
107
}
108

109
quint32 Bus::defaultHold()
163✔
110
{
111
    return KBusIDDefaultHold;
163✔
112
}
113

114
quint32 Bus::defaultPalette()
163✔
115
{
116
    return KBusIDDefaultPalette;
163✔
117
}
118

119
quint32 Bus::invalid()
449✔
120
{
121
    return KBusIDInvalid;
449✔
122
}
123

124
Bus::~Bus()
324✔
125
{
126
    while (m_buses.isEmpty() == false)
5,346✔
127
        delete m_buses.takeFirst();
5,184✔
128

129
    s_instance = NULL;
162✔
130
}
324✔
131

132
/****************************************************************************
133
 * Name
134
 ****************************************************************************/
135

136
QString Bus::name(quint32 bus) const
42✔
137
{
138
    if (bus < KBusCount)
42✔
139
        return m_buses[bus]->name;
42✔
140
    else
141
        return QString();
×
142
}
143

144
QString Bus::idName(quint32 bus) const
36✔
145
{
146
    if (bus < KBusCount)
36✔
147
    {
148
        QString nomen(name(bus));
35✔
149
        if (nomen.simplified().isEmpty() == true)
35✔
150
            return QString("Bus %1").arg(bus + 1);
30✔
151
        else
152
            return nomen;
5✔
153
    }
35✔
154
    else
155
    {
156
        return QString();
1✔
157
    }
158
}
159

160
QStringList Bus::idNames() const
1✔
161
{
162
    QStringList list;
1✔
163
    for (quint32 bus = 0; bus < KBusCount; bus++)
33✔
164
        list << idName(bus);
32✔
165
    return list;
1✔
166
}
×
167

168
void Bus::setName(quint32 bus, const QString& name)
9✔
169
{
170
    if (bus < KBusCount)
9✔
171
    {
172
        m_buses[bus]->name = name;
8✔
173
        emit nameChanged(bus, name);
8✔
174
    }
175
}
9✔
176

177
/****************************************************************************
178
 * Value
179
 ****************************************************************************/
180

181
quint32 Bus::value(quint32 bus) const
18✔
182
{
183
    if (bus < KBusCount)
18✔
184
        return m_buses[bus]->value;
18✔
185
    else
186
        return 0;
×
187
}
188

189
void Bus::setValue(quint32 bus, quint32 value)
13✔
190
{
191
    if (bus < KBusCount)
13✔
192
    {
193
        m_buses[bus]->value = value;
12✔
194
        emit valueChanged(bus, value);
12✔
195
    }
196
}
13✔
197

198
/****************************************************************************
199
 * Tap
200
 ****************************************************************************/
201

202
void Bus::tap(quint32 bus)
2✔
203
{
204
    if (bus < KBusCount)
2✔
205
        emit tapped(bus);
1✔
206
}
2✔
207

208
/****************************************************************************
209
 * Load & Save
210
 ****************************************************************************/
211

212
bool Bus::loadXML(QXmlStreamReader &doc)
8✔
213
{
214
    if (doc.name() != KXMLQLCBus)
8✔
215
    {
216
        qWarning() << Q_FUNC_INFO << "Bus node not found!";
1✔
217
        return false;
1✔
218
    }
219

220
    quint32 id = doc.attributes().value(KXMLQLCBusID).toString().toUInt();
14✔
221
    if (id >= KBusCount)
7✔
222
    {
223
        qWarning() << Q_FUNC_INFO << "Bus ID" << id << "out of bounds.";
1✔
224
        return false;
1✔
225
    }
226

227
    while (doc.readNextStartElement())
19✔
228
    {
229
        if (doc.name() == KXMLQLCBusName)
13✔
230
            setName(id, doc.readElementText());
6✔
231
        else if (doc.name() == KXMLQLCBusValue)
7✔
232
            setValue(id, doc.readElementText().toULong());
6✔
233
        else
234
        {
235
            qWarning() << Q_FUNC_INFO << "Unknown Bus tag:" << doc.name();
1✔
236
            doc.skipCurrentElement();
1✔
237
        }
238
    }
239

240
    return true;
6✔
241
}
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