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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

84.87
/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      QString("Name")
31
#define KXMLQLCTrackSceneID   QString("SceneID")
32
#define KXMLQLCTrackIsMute    QString("isMute")
33

34
#define KXMLQLCTrackFunctions QString("Functions")
35

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

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

49
}
25✔
50

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

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

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

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

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

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

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

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

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

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

103
quint32 Track::getSceneID()
12✔
104
{
105
    return m_sceneID;
12✔
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 functionID)
2✔
131
{
132
    Show *show = qobject_cast<Show *>(parent());
133
    quint32 uId = show == NULL ? 0 : show->getLatestShowFunctionId();
2✔
134
    ShowFunction *func = new ShowFunction(uId);
2✔
135
    func->setFunctionID(functionID);
2✔
136
    m_functions.append(func);
2✔
137

138
    return func;
2✔
139
}
140

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

146
    m_functions.append(func);
8✔
147

148
    return true;
8✔
149
}
150

151
ShowFunction *Track::showFunction(quint32 id)
6✔
152
{
153
    foreach (ShowFunction *sf, m_functions)
13✔
154
        if (sf->id() == id)
11✔
155
            return sf;
156

157
    return NULL;
2✔
158
}
159

160
bool Track::removeShowFunction(ShowFunction *function, bool performDelete)
2✔
161
{
162
    if (m_functions.contains(function) == false)
2✔
163
        return false;
164

165
    ShowFunction *func = m_functions.takeAt(m_functions.indexOf(function));
1✔
166
    if (performDelete && func)
1✔
167
        delete func;
1✔
168

169
    return true;
170
}
171

172
QList <ShowFunction *> Track::showFunctions() const
15✔
173
{
174
    return m_functions;
15✔
175
}
176

177
/*****************************************************************************
178
 * Load & Save
179
 *****************************************************************************/
180
bool Track::saveXML(QXmlStreamWriter *doc)
3✔
181
{
182
    Q_ASSERT(doc != NULL);
183

184
    /* Track entry */
185
    doc->writeStartElement(KXMLQLCTrack);
3✔
186
    doc->writeAttribute(KXMLQLCTrackID, QString::number(this->id()));
3✔
187
    doc->writeAttribute(KXMLQLCTrackName, this->name());
3✔
188
    if (m_sceneID != Scene::invalidId())
3✔
189
        doc->writeAttribute(KXMLQLCTrackSceneID, QString::number(m_sceneID));
3✔
190
    doc->writeAttribute(KXMLQLCTrackIsMute, QString::number(m_isMute));
3✔
191

192
    /* Save the list of Functions if any is present */
193
    if (m_functions.isEmpty() == false)
3✔
194
    {
195
        foreach (ShowFunction *func, showFunctions())
3✔
196
            func->saveXML(doc);
1✔
197
    }
198

199
    doc->writeEndElement();
3✔
200

201
    return true;
3✔
202
}
203

204
bool Track::loadXML(QXmlStreamReader &root)
3✔
205
{
206
    if (root.name() != KXMLQLCTrack)
6✔
207
    {
208
        qWarning() << Q_FUNC_INFO << "Track node not found";
×
209
        return false;
×
210
    }
211

212
    bool ok = false;
3✔
213
    QXmlStreamAttributes attrs = root.attributes();
3✔
214
    quint32 id = attrs.value(KXMLQLCTrackID).toString().toUInt(&ok);
3✔
215
    if (ok == false)
3✔
216
    {
217
        qWarning() << "Invalid Track ID:" << attrs.value(KXMLQLCTrackID).toString();
×
218
        return false;
×
219
    }
220
    // Assign the ID to myself
221
    m_id = id;
3✔
222

223
    if (attrs.hasAttribute(KXMLQLCTrackName) == true)
3✔
224
        m_name = attrs.value(KXMLQLCTrackName).toString();
3✔
225

226
    if (attrs.hasAttribute(KXMLQLCTrackSceneID))
3✔
227
    {
228
        ok = false;
3✔
229
        id = attrs.value(KXMLQLCTrackSceneID).toString().toUInt(&ok);
3✔
230
        if (ok == false)
3✔
231
        {
232
            qWarning() << "Invalid Scene ID:" << attrs.value(KXMLQLCTrackSceneID).toString();
×
233
            return false;
×
234
        }
235
        m_sceneID = id;
3✔
236
    }
237

238
    ok = false;
3✔
239
    bool mute = attrs.value(KXMLQLCTrackIsMute).toString().toInt(&ok);
3✔
240
    if (ok == false)
3✔
241
    {
242
        qWarning() << "Invalid Mute flag:" << root.attributes().value(KXMLQLCTrackIsMute).toString();
×
243
        return false;
×
244
    }
245
    m_isMute = mute;
3✔
246

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

277
    return true;
278
}
279

280
bool Track::postLoad(Doc* doc)
1✔
281
{
282
    bool modified = false;
283
    QMutableListIterator<ShowFunction*> it(m_functions);
1✔
284
    while (it.hasNext())
4✔
285
    {
286
        ShowFunction* showFunction = it.next();
3✔
287

288
        Function* function = doc->function(showFunction->functionID());
3✔
289
        if (function == NULL
1✔
290
                || (m_showId != Function::invalidId()
3✔
291
                    && function->contains(m_showId)))
2✔
292
        {
293
            it.remove();
1✔
294
            delete showFunction;
1✔
295
            modified = true;
296
            continue;
1✔
297
        }
298

299
        //if (showFunction->duration() == 0)
300
        //    showFunction->setDuration(function->totalDuration());
301
        if (showFunction->color().isValid() == false)
2✔
302
            showFunction->setColor(ShowFunction::defaultColor(function->type()));
2✔
303

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

328
bool Track::contains(Doc* doc, quint32 functionId)
5✔
329
{
330
    if (m_sceneID == functionId)
5✔
331
        return true;
332

333
    QListIterator<ShowFunction*> it(m_functions);
5✔
334
    while (it.hasNext())
9✔
335
    {
336
        ShowFunction* showFunction = it.next();
7✔
337

338
        Function* function = doc->function(showFunction->functionID());
7✔
339
        // contains() can be called during init, function may be NULL
340
        if (function == NULL)
7✔
341
            continue;
×
342

343
        if (function->id() == functionId)
7✔
344
            return true;
345
        if (function->contains(functionId))
4✔
346
            return true;
347
    }
348

349
    return false;
350
}
351

352
QList<quint32> Track::components()
4✔
353
{
354
    QList<quint32> ids;
355

356
    QListIterator<ShowFunction*> it(m_functions);
4✔
357
    while (it.hasNext())
11✔
358
    {
359
        ShowFunction* showFunction = it.next();
7✔
360
        ids.append(showFunction->functionID());
7✔
361
    }
362

363
    return ids;
4✔
364
}
×
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

© 2025 Coveralls, Inc