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

mcallegari / qlcplus / 6841397861

12 Nov 2023 02:56PM UTC coverage: 28.636% (+0.5%) from 28.089%
6841397861

push

github

mcallegari
engine/test: prefer QVERIFY for numeric comparison

15723 of 54907 relevant lines covered (28.64%)

20282.61 hits per line

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

55.41
/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 "doc.h"
28

29
#define KXMLQLCTrackID        QString("ID")
30
#define KXMLQLCTrackName      QString("Name")
31
#define KXMLQLCTrackSceneID   QString("SceneID")
32
#define KXMLQLCTrackIsMute    QString("isMute")
33

34
#define KXMLQLCTrackFunctions QString("Functions")
35

36
Track::Track(quint32 sceneID)
12✔
37
    : m_id(Track::invalidId())
24✔
38
    , m_showId(Function::invalidId())
24✔
39
    , m_sceneID(sceneID)
40
    , m_isMute(false)
12✔
41

42
{
43
    setName(tr("New Track"));
12✔
44
}
12✔
45

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

49
}
10✔
50

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

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

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

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

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

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

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

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

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

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

103
quint32 Track::getSceneID()
8✔
104
{
105
    return m_sceneID;
8✔
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()
6✔
122
{
123
    return m_isMute;
6✔
124
}
125

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

130
ShowFunction* Track::createShowFunction(quint32 id)
1✔
131
{
132
    ShowFunction *func = new ShowFunction();
1✔
133
    func->setFunctionID(id);
1✔
134
    m_functions.append(func);
1✔
135

136
    return func;
1✔
137
}
138

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

144
    m_functions.append(func);
1✔
145

146
    return true;
1✔
147
}
148

149
bool Track::removeShowFunction(ShowFunction *function, bool performDelete)
2✔
150
{
151
    if (m_functions.contains(function) == false)
2✔
152
        return false;
1✔
153

154
    ShowFunction *func = m_functions.takeAt(m_functions.indexOf(function));
1✔
155
    if (performDelete)
1✔
156
        delete func;
1✔
157

158
    return true;
1✔
159
}
160

161
QList <ShowFunction *> Track::showFunctions() const
5✔
162
{
163
    return m_functions;
5✔
164
}
165

166
/*****************************************************************************
167
 * Load & Save
168
 *****************************************************************************/
169
bool Track::saveXML(QXmlStreamWriter *doc)
3✔
170
{
171
    Q_ASSERT(doc != NULL);
3✔
172

173
    /* Track entry */
174
    doc->writeStartElement(KXMLQLCTrack);
3✔
175
    doc->writeAttribute(KXMLQLCTrackID, QString::number(this->id()));
3✔
176
    doc->writeAttribute(KXMLQLCTrackName, this->name());
3✔
177
    if (m_sceneID != Scene::invalidId())
3✔
178
        doc->writeAttribute(KXMLQLCTrackSceneID, QString::number(m_sceneID));
3✔
179
    doc->writeAttribute(KXMLQLCTrackIsMute, QString::number(m_isMute));
3✔
180

181
    /* Save the list of Functions if any is present */
182
    if (m_functions.isEmpty() == false)
3✔
183
    {
184
        foreach(ShowFunction *func, showFunctions())
×
185
            func->saveXML(doc);
×
186
    }
187

188
    doc->writeEndElement();
3✔
189

190
    return true;
3✔
191
}
192

193
bool Track::loadXML(QXmlStreamReader &root)
3✔
194
{
195
    if (root.name() != KXMLQLCTrack)
3✔
196
    {
197
        qWarning() << Q_FUNC_INFO << "Track node not found";
×
198
        return false;
×
199
    }
200

201
    bool ok = false;
3✔
202
    QXmlStreamAttributes attrs = root.attributes();
6✔
203
    quint32 id = attrs.value(KXMLQLCTrackID).toString().toUInt(&ok);
3✔
204
    if (ok == false)
3✔
205
    {
206
        qWarning() << "Invalid Track ID:" << attrs.value(KXMLQLCTrackID).toString();
×
207
        return false;
×
208
    }
209
    // Assign the ID to myself
210
    m_id = id;
3✔
211

212
    if (attrs.hasAttribute(KXMLQLCTrackName) == true)
3✔
213
        m_name = attrs.value(KXMLQLCTrackName).toString();
3✔
214

215
    if (attrs.hasAttribute(KXMLQLCTrackSceneID))
3✔
216
    {
217
        ok = false;
3✔
218
        id = attrs.value(KXMLQLCTrackSceneID).toString().toUInt(&ok);
3✔
219
        if (ok == false)
3✔
220
        {
221
            qWarning() << "Invalid Scene ID:" << attrs.value(KXMLQLCTrackSceneID).toString();
×
222
            return false;
×
223
        }
224
        m_sceneID = id;
3✔
225
    }
226

227
    ok = false;
3✔
228
    bool mute = attrs.value(KXMLQLCTrackIsMute).toString().toInt(&ok);
3✔
229
    if (ok == false)
3✔
230
    {
231
        qWarning() << "Invalid Mute flag:" << root.attributes().value(KXMLQLCTrackIsMute).toString();
×
232
        return false;
×
233
    }
234
    m_isMute = mute;
3✔
235

236
    /* look for show functions */
237
    while (root.readNextStartElement())
3✔
238
    {
239
        if (root.name() == KXMLShowFunction)
×
240
        {
241
            ShowFunction *newFunc = new ShowFunction();
×
242
            newFunc->loadXML(root);
×
243
            if (addShowFunction(newFunc) == false)
×
244
                delete newFunc;
×
245
        }
246
        /* LEGACY code: to be removed */
247
        else if (root.name() == KXMLQLCTrackFunctions)
×
248
        {
249
            QString strvals = root.readElementText();
×
250
            if (strvals.isEmpty() == false)
×
251
            {
252
                QStringList varray = strvals.split(",");
×
253
                for (int i = 0; i < varray.count(); i++)
×
254
                    createShowFunction(QString(varray.at(i)).toUInt());
×
255
            }
256
        }
257
        else
258
        {
259
            qWarning() << Q_FUNC_INFO << "Unknown Track tag:" << root.name();
×
260
            root.skipCurrentElement();
×
261
        }
262
    }
263

264
    return true;
3✔
265
}
266

267
bool Track::postLoad(Doc* doc)
×
268
{
269
    bool modified = false;
×
270
    QMutableListIterator<ShowFunction*> it(m_functions);
×
271
    while (it.hasNext())
×
272
    {
273
        ShowFunction* showFunction = it.next();
×
274

275
        Function* function = doc->function(showFunction->functionID());
×
276
        if (function == NULL
×
277
                || (m_showId != Function::invalidId()
×
278
                    && function->contains(m_showId)))
×
279
        {
280
            it.remove();
×
281
            delete showFunction;
×
282
            modified = true;
×
283
            continue;
×
284
        }
285

286
        //if (showFunction->duration() == 0)
287
        //    showFunction->setDuration(function->totalDuration());
288
        if (showFunction->color().isValid() == false)
×
289
            showFunction->setColor(ShowFunction::defaultColor(function->type()));
×
290

291
        if (function->type() == Function::SequenceType)
×
292
        {
293
            Sequence* sequence = qobject_cast<Sequence*>(function);
×
294
            if (sequence == NULL || getSceneID() == sequence->boundSceneID())
×
295
                continue;
×
296
#ifndef QMLUI
297
            if (getSceneID() == Function::invalidId())
×
298
            {
299
                // No scene ID, use the one from this sequence
300
                setSceneID(sequence->boundSceneID());
×
301
            }
302
            else
303
            {
304
                // Conflicting scene IDs, we have to remove this sequence
305
                it.remove();
×
306
                delete showFunction;
×
307
            }
308
#endif
309
            modified = true;
×
310
        }
311
    }
312
    return modified;
×
313
}
314

315
bool Track::contains(Doc* doc, quint32 functionId)
×
316
{
317
    if (m_sceneID == functionId)
×
318
        return true;
×
319

320
    QListIterator<ShowFunction*> it(m_functions);
×
321
    while (it.hasNext())
×
322
    {
323
        ShowFunction* showFunction = it.next();
×
324

325
        Function* function = doc->function(showFunction->functionID());
×
326
        // contains() can be called during init, function may be NULL
327
        if (function == NULL)
×
328
            continue;
×
329

330
        if (function->id() == functionId)
×
331
            return true;
×
332
        if (function->contains(functionId))
×
333
            return true;
×
334
    }
335

336
    return false;
×
337
}
338

339
QList<quint32> Track::components()
×
340
{
341
    QList<quint32> ids;
×
342

343
    QListIterator<ShowFunction*> it(m_functions);
×
344
    while (it.hasNext())
×
345
    {
346
        ShowFunction* showFunction = it.next();
×
347
        ids.append(showFunction->functionID());
×
348
    }
349

350
    return ids;
×
351
}
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