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

mcallegari / qlcplus / 43708031602

15 Nov 2026 11:15AM UTC coverage: 61.667% (+0.09%) from 61.581%
43708031602

push

github

mcallegari
engine: fix Doc test unit

18048 of 29267 relevant lines covered (61.67%)

63071.28 hits per line

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

86.55
/engine/src/track.cpp
1
/*
2
  Q Light Controller Plus
3
  track.cpp
4

5
  Copyright (c) Massimo Callegari
6

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

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

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

20
#include <QXmlStreamReader>
21
#include <QXmlStreamWriter>
22
#include <QDebug>
23

24
#include "sequence.h"
25
#include "track.h"
26
#include "scene.h"
27
#include "show.h"
28
#include "doc.h"
29

30
#define KXMLQLCTrackName      QStringLiteral("Name")
31
#define KXMLQLCTrackSceneID   QStringLiteral("SceneID")
32
#define KXMLQLCTrackIsMute    QStringLiteral("isMute")
33

34
#define KXMLQLCTrackFunctions QStringLiteral("Functions")
35

36
Track::Track(quint32 sceneID, QObject *parent)
24 ✔
37
    : QObject(parent)
38
    , m_id(Track::invalidId())
48 ✔
39
    , m_showId(Function::invalidId())
24 ✔
40
    , m_sceneID(sceneID)
24 ✔
41
    , m_isMute(false)
48 ✔
42
{
43
    setName(tr("New Track"));
24 ✔
44
}
24 ✔
45

46
Track::~Track()
39 ✔
47
{
48

49
}
39 ✔
50

51
/****************************************************************************
52
 * ID
53
 ****************************************************************************/
54

55
void Track::setId(quint32 id)
24 ✔
56
{
57
    m_id = id;
24 ✔
58
}
24 ✔
59

60
quint32 Track::id() const
103 ✔
61
{
62
    return m_id;
103 ✔
63
}
64

65
quint32 Track::invalidId()
79 ✔
66
{
67
    return UINT_MAX;
79 ✔
68
}
69

70
quint32 Track::showId() const
4 ✔
71
{
72
    return m_showId;
4 ✔
73
}
74

75
void Track::setShowId(quint32 id)
19 ✔
76
{
77
    m_showId = id;
19 ✔
78
}
19 ✔
79

80
/****************************************************************************
81
 * Name
82
 ****************************************************************************/
83

84
void Track::setName(const QString& name)
33 ✔
85
{
86
    m_name = name;
33 ✔
87
    emit changed(this->id());
33 ✔
88
}
33 ✔
89

90
QString Track::name() const
35 ✔
91
{
92
    return m_name;
35 ✔
93
}
94

95
/*********************************************************************
96
 * Scene
97
 *********************************************************************/
98
void Track::setSceneID(quint32 id)
2 ✔
99
{
100
    m_sceneID = id;
2 ✔
101
}
2 ✔
102

103
quint32 Track::getSceneID() const
11 ✔
104
{
105
    return m_sceneID;
11 ✔
106
}
107

108
/*********************************************************************
109
 * Mute state
110
 *********************************************************************/
111
void Track::setMute(bool state)
4 ✔
112
{
113
    if (m_isMute == state)
4 ✔
114
        return;
×
115

116
    m_isMute = state;
4 ✔
117

118
    emit muteChanged(state);
4 ✔
119
}
120

121
bool Track::isMute() const
15 ✔
122
{
123
    return m_isMute;
15 ✔
124
}
125

126
/*********************************************************************
127
 * Sequences
128
 *********************************************************************/
129

130
ShowFunction *Track::createShowFunction(quint32 functionID)
12 ✔
131
{
132
    Show *show = qobject_cast<Show *>(parent());
12 ✔
133
    quint32 uId = show == NULL ? 0 : show->getLatestShowFunctionId();
12 ✔
134
    ShowFunction *func = new ShowFunction(uId);
12 ✔
135
    func->setFunctionID(functionID);
12 ✔
136
    m_functions.append(func);
12 ✔
137

138
    return func;
12 ✔
139
}
140

141
bool Track::addShowFunction(ShowFunction *func)
13 ✔
142
{
143
    if (func == NULL || func->functionID() == Function::invalidId())
13 ✔
144
        return false;
2 ✔
145

146
    // forbid self-containment
147
    Show *show = qobject_cast<Show *>(parent());
11 ✔
148
    if (show != NULL && func->functionID() == show->id())
11 ✔
149
        return false;
1 ✔
150

151
    m_functions.append(func);
10 ✔
152

153
    return true;
10 ✔
154
}
155

156
ShowFunction *Track::showFunction(quint32 id) const
6 ✔
157
{
158
    foreach (ShowFunction *sf, m_functions)
13 ✔
159
        if (sf->id() == id)
11 ✔
160
            return sf;
6 ✔
161

162
    return NULL;
2 ✔
163
}
164

165
bool Track::removeShowFunction(ShowFunction *function, bool performDelete)
2 ✔
166
{
167
    if (m_functions.contains(function) == false)
2 ✔
168
        return false;
1 ✔
169

170
    ShowFunction *func = m_functions.takeAt(m_functions.indexOf(function));
1 ✔
171
    if (performDelete && func)
1 ✔
172
        delete func;
1 ✔
173

174
    return true;
1 ✔
175
}
176

177
QList <ShowFunction *> Track::showFunctions() const
40 ✔
178
{
179
    return m_functions;
40 ✔
180
}
181

182
/*****************************************************************************
183
 * Load & Save
184
 *****************************************************************************/
185
bool Track::saveXML(QXmlStreamWriter *doc) const
3 ✔
186
{
187
    Q_ASSERT(doc != NULL);
3 ✔
188

189
    /* Track entry */
190
    doc->writeStartElement(KXMLQLCTrack);
6 ✔
191
    doc->writeAttribute(KXMLQLCTrackID, QString::number(this->id()));
6 ✔
192
    doc->writeAttribute(KXMLQLCTrackName, this->name());
6 ✔
193
    if (m_sceneID != Scene::invalidId())
3 ✔
194
        doc->writeAttribute(KXMLQLCTrackSceneID, QString::number(m_sceneID));
6 ✔
195
    doc->writeAttribute(KXMLQLCTrackIsMute, QString::number(m_isMute));
6 ✔
196

197
    /* Save the list of Functions if any is present */
198
    if (m_functions.isEmpty() == false)
3 ✔
199
    {
200
        foreach (ShowFunction *func, showFunctions())
3 ✔
201
            func->saveXML(doc);
2 ✔
202
    }
203

204
    doc->writeEndElement();
3 ✔
205

206
    return true;
3 ✔
207
}
208

209
bool Track::loadXML(QXmlStreamReader &root)
4 ✔
210
{
211
    if (root.name() != KXMLQLCTrack)
4 ✔
212
    {
213
        qWarning() << Q_FUNC_INFO << "Track node not found";
×
214
        return false;
×
215
    }
216

217
    bool ok = false;
4 ✔
218
    QXmlStreamAttributes attrs = root.attributes();
4 ✔
219
    quint32 id = attrs.value(KXMLQLCTrackID).toString().toUInt(&ok);
4 ✔
220
    if (ok == false)
4 ✔
221
    {
222
        qWarning() << "Invalid Track ID:" << attrs.value(KXMLQLCTrackID).toString();
×
223
        return false;
×
224
    }
225
    // Assign the ID to myself
226
    m_id = id;
4 ✔
227

228
    if (attrs.hasAttribute(KXMLQLCTrackName) == true)
4 ✔
229
        m_name = attrs.value(KXMLQLCTrackName).toString();
4 ✔
230

231
    if (attrs.hasAttribute(KXMLQLCTrackSceneID))
4 ✔
232
    {
233
        ok = false;
3 ✔
234
        id = attrs.value(KXMLQLCTrackSceneID).toString().toUInt(&ok);
3 ✔
235
        if (ok == false)
3 ✔
236
        {
237
            qWarning() << "Invalid Scene ID:" << attrs.value(KXMLQLCTrackSceneID).toString();
×
238
            return false;
×
239
        }
240
        m_sceneID = id;
3 ✔
241
    }
242

243
    ok = false;
4 ✔
244
    bool mute = attrs.value(KXMLQLCTrackIsMute).toString().toInt(&ok);
4 ✔
245
    if (ok == false)
4 ✔
246
    {
247
        qWarning() << "Invalid Mute flag:" << root.attributes().value(KXMLQLCTrackIsMute).toString();
×
248
        return false;
×
249
    }
250
    m_isMute = mute;
4 ✔
251

252
    /* look for show functions */
253
    while (root.readNextStartElement())
7 ✔
254
    {
255
        if (root.name() == KXMLShowFunction)
3 ✔
256
        {
257
            Show *show = qobject_cast<Show *>(parent());
3 ✔
258
            quint32 uId = show == NULL ? 0 : show->getLatestShowFunctionId();
3 ✔
259
            ShowFunction *newFunc = new ShowFunction(uId);
3 ✔
260
            newFunc->loadXML(root);
3 ✔
261
            if (addShowFunction(newFunc) == false)
3 ✔
262
                delete newFunc;
1 ✔
263
        }
264
        /* LEGACY code: to be removed */
265
        else if (root.name() == KXMLQLCTrackFunctions)
×
266
        {
267
            QString strvals = root.readElementText();
×
268
            if (strvals.isEmpty() == false)
×
269
            {
270
                QStringList varray = strvals.split(",");
×
271
                for (int i = 0; i < varray.count(); i++)
×
272
                    createShowFunction(QString(varray.at(i)).toUInt());
×
273
            }
×
274
        }
×
275
        else
276
        {
277
            qWarning() << Q_FUNC_INFO << "Unknown Track tag:" << root.name();
×
278
            root.skipCurrentElement();
×
279
        }
280
    }
281

282
    return true;
4 ✔
283
}
4 ✔
284

285
bool Track::postLoad(Doc* doc)
2 ✔
286
{
287
    bool modified = false;
2 ✔
288
    QMutableListIterator<ShowFunction*> it(m_functions);
2 ✔
289
    while (it.hasNext())
6 ✔
290
    {
291
        ShowFunction* showFunction = it.next();
4 ✔
292

293
        Function* function = doc->function(showFunction->functionID());
4 ✔
294
        if (function == NULL
5 ✔
295
                || (m_showId != Function::invalidId()
7 ✔
296
                    && function->contains(m_showId)))
3 ✔
297
        {
298
            it.remove();
1 ✔
299
            delete showFunction;
1 ✔
300
            modified = true;
1 ✔
301
            continue;
1 ✔
302
        }
303

304
        //if (showFunction->duration() == 0)
305
        //    showFunction->setDuration(function->totalDuration());
306
        if (showFunction->color().isValid() == false)
3 ✔
307
            showFunction->setColor(ShowFunction::defaultColor(function->type()));
3 ✔
308

309
        if (function->type() == Function::SequenceType)
3 ✔
310
        {
311
            Sequence* sequence = qobject_cast<Sequence*>(function);
1 ✔
312
            if (sequence == NULL || getSceneID() == sequence->boundSceneID())
1 ✔
313
                continue;
×
314
#ifndef QMLUI
315
            if (getSceneID() == Function::invalidId())
316
            {
317
                // No scene ID, use the one from this sequence
318
                setSceneID(sequence->boundSceneID());
319
            }
320
            else
321
            {
322
                // Conflicting scene IDs, we have to remove this sequence
323
                it.remove();
324
                delete showFunction;
325
            }
326
#endif
327
            modified = true;
1 ✔
328
        }
329
    }
330
    return modified;
2 ✔
331
}
332

333
bool Track::contains(Doc* doc, quint32 functionId) const
8 ✔
334
{
335
    if (m_sceneID == functionId)
8 ✔
336
        return true;
×
337

338
    QListIterator<ShowFunction*> it(m_functions);
8 ✔
339
    while (it.hasNext())
14 ✔
340
    {
341
        ShowFunction* showFunction = it.next();
10 ✔
342

343
        Function* function = doc->function(showFunction->functionID());
10 ✔
344
        // contains() can be called during init, function may be NULL
345
        if (function == NULL)
10 ✔
346
            continue;
×
347

348
        if (function->id() == functionId)
10 ✔
349
            return true;
4 ✔
350
        if (function->contains(functionId))
6 ✔
351
            return true;
×
352
    }
353

354
    return false;
4 ✔
355
}
8 ✔
356

357
QList<quint32> Track::components() const
4 ✔
358
{
359
    QList<quint32> ids;
4 ✔
360

361
    QListIterator<ShowFunction*> it(m_functions);
4 ✔
362
    while (it.hasNext())
11 ✔
363
    {
364
        ShowFunction* showFunction = it.next();
7 ✔
365
        ids.append(showFunction->functionID());
7 ✔
366
    }
367

368
    return ids;
8 ✔
369
}
4 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc