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

mcallegari / qlcplus / 40027806002

23 Oct 2026 09:34PM UTC coverage: 36.076% (+0.2%) from 35.891%
40027806002

push

github

mcallegari
engine: add test units for universe split

18801 of 52115 relevant lines covered (36.08%)

42105.94 hits per line

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

89.78
/engine/src/doc.cpp
1
/*
2
  Q Light Controller Plus
3
  doc.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 <QXmlStreamWriter>
23
#include <QStringList>
24
#include <QString>
25
#include <QDebug>
26
#include <QList>
27
#include <QTime>
28
#include <QDir>
29
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
30
#include <QRandomGenerator>
31
#endif
32

33
#include "qlcfixturemode.h"
34
#include "qlcfixturedef.h"
35
#include "qlcrdmservice.h"
36

37
#include "monitorproperties.h"
38
#include "audioplugincache.h"
39
#include "rgbscriptscache.h"
40
#include "serviceloader.h"
41
#include "channelsgroup.h"
42
#include "scriptwrapper.h"
43
#include "collection.h"
44
#include "function.h"
45
#include "universe.h"
46
#include "sequence.h"
47
#include "fixture.h"
48
#include "chaser.h"
49
#include "show.h"
50
#include "doc.h"
51
#include "bus.h"
52

53
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
54
 #include "audiocapture_qt5.h"
55
#else
56
 #include "audiocapture_qt6.h"
57
#endif
58

59
#define AUTOSAVE_TIMEOUT    30 // seconds
60

61
Doc::Doc(QObject* parent, int universes)
220 ✔
62
    : QObject(parent)
63
    , m_workspacePath("")
220 ✔
64
    , m_fixtureDefCache(new QLCFixtureDefCache)
220 ✔
65
    , m_modifiersCache(new QLCModifiersCache)
220 ✔
66
    , m_rgbScriptsCache(new RGBScriptsCache(this))
220 ✔
67
    , m_ioPluginCache(new IOPluginCache(this))
220 ✔
68
    , m_audioPluginCache(new AudioPluginCache(this))
220 ✔
69
    , m_serviceLoader(new ServiceLoader(this))
220 ✔
70
    , m_masterTimer(new MasterTimer(this))
220 ✔
71
    , m_ioMap(new InputOutputMap(this, universes))
220 ✔
72
    , m_monitorProps(NULL)
220 ✔
73
    , m_mode(Design)
220 ✔
74
    , m_kiosk(false)
220 ✔
75
    , m_loadStatus(Cleared)
220 ✔
76
    , m_clipboard(new QLCClipboard(this))
220 ✔
77
    , m_fixturesListCacheUpToDate(false)
220 ✔
78
    , m_latestFixtureId(0)
220 ✔
79
    , m_latestFixtureGroupId(0)
220 ✔
80
    , m_latestChannelsGroupId(0)
220 ✔
81
    , m_latestPaletteId(0)
220 ✔
82
    , m_latestFunctionId(0)
220 ✔
83
    , m_startupFunctionId(Function::invalidId())
660 ✔
84
{
85
    Bus::init(this);
220 ✔
86
    resetModified();
220 ✔
87
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
88
    qsrand(QTime::currentTime().msec());
89
#endif
90

91
    m_autosaveTimer.setInterval(AUTOSAVE_TIMEOUT * 1000);
220 ✔
92
    m_autosaveTimer.setSingleShot(true);
220 ✔
93

94
    connect(&m_autosaveTimer, SIGNAL(timeout()), this, SIGNAL(needAutosave()));
220 ✔
95
    connect(m_serviceLoader, SIGNAL(serviceAvailable(QString)),
220 ✔
96
            this, SLOT(slotServiceAvailable(QString)));
97
}
220 ✔
98

99
Doc::~Doc()
379 ✔
100
{
101
    delete m_masterTimer;
220 ✔
102
    m_masterTimer = NULL;
220 ✔
103

104
    clearContents();
220 ✔
105

106
    if (isKiosk() == false)
220 ✔
107
    {
108
        // TODO: is this still needed ??
109
        //m_ioMap->saveDefaults();
110
    }
111
    /* Services use the I/O plugins: unload them first */
112
    delete m_serviceLoader;
220 ✔
113
    m_serviceLoader = NULL;
220 ✔
114

115
    delete m_ioMap;
220 ✔
116
    m_ioMap = NULL;
220 ✔
117

118
    delete m_ioPluginCache;
220 ✔
119
    m_ioPluginCache = NULL;
220 ✔
120

121
    delete m_modifiersCache;
220 ✔
122
    m_modifiersCache = NULL;
220 ✔
123

124
    delete m_fixtureDefCache;
220 ✔
125
    m_fixtureDefCache = NULL;
220 ✔
126

127
    delete m_rgbScriptsCache;
220 ✔
128
    m_rgbScriptsCache = NULL;
220 ✔
129
}
379 ✔
130

131
void Doc::clearContents()
531 ✔
132
{
133
    emit clearing();
531 ✔
134

135
    m_clipboard->resetContents();
531 ✔
136

137
    if (m_monitorProps != NULL)
531 ✔
138
        m_monitorProps->reset();
15 ✔
139

140
    destroyAudioCapture();
531 ✔
141

142
    // Delete all function instances
143
    QListIterator <quint32> funcit(m_functions.keys());
531 ✔
144
    while (funcit.hasNext() == true)
796 ✔
145
    {
146
        Function* func = m_functions.take(funcit.next());
265 ✔
147
        if (func == NULL)
265 ✔
148
            continue;
×
149
        emit functionRemoved(func->id());
265 ✔
150
        delete func;
265 ✔
151
    }
152

153
    // Delete all palettes
154
    QListIterator <quint32> palIt(m_palettes.keys());
531 ✔
155
    while (palIt.hasNext() == true)
531 ✔
156
    {
157
        QLCPalette *palette = m_palettes.take(palIt.next());
×
158
        emit paletteRemoved(palette->id());
×
159
        delete palette;
×
160
    }
161

162
    // Delete all channel groups
163
    QListIterator <quint32> grpchans(m_channelsGroups.keys());
531 ✔
164
    while (grpchans.hasNext() == true)
536 ✔
165
    {
166
        ChannelsGroup* grp = m_channelsGroups.take(grpchans.next());
5 ✔
167
        emit channelsGroupRemoved(grp->id());
5 ✔
168
        delete grp;
5 ✔
169
    }
170

171
    // Delete all fixture groups
172
    QListIterator <quint32> grpit(m_fixtureGroups.keys());
531 ✔
173
    while (grpit.hasNext() == true)
543 ✔
174
    {
175
        FixtureGroup* grp = m_fixtureGroups.take(grpit.next());
12 ✔
176
        quint32 grpID = grp->id();
12 ✔
177
        delete grp;
12 ✔
178
        emit fixtureGroupRemoved(grpID);
12 ✔
179
    }
180

181
    // Delete all fixture instances
182
    QListIterator <quint32> fxit(m_fixtures.keys());
531 ✔
183
    while (fxit.hasNext() == true)
17,350 ✔
184
    {
185
        Fixture* fxi = m_fixtures.take(fxit.next());
16,819 ✔
186
        quint32 fxID = fxi->id();
16,819 ✔
187
        delete fxi;
16,819 ✔
188
        emit fixtureRemoved(fxID);
16,819 ✔
189
    }
190
    m_fixturesListCacheUpToDate = false;
531 ✔
191

192
    m_orderedGroups.clear();
531 ✔
193

194
    m_latestFunctionId = 0;
531 ✔
195
    m_startupFunctionId = Function::invalidId();
531 ✔
196
    m_latestFixtureId = 0;
531 ✔
197
    m_latestFixtureGroupId = 0;
531 ✔
198
    m_latestChannelsGroupId = 0;
531 ✔
199
    m_latestPaletteId = 0;
531 ✔
200
    m_addresses.clear();
531 ✔
201
    m_loadStatus = Cleared;
531 ✔
202

203
    emit cleared();
531 ✔
204
}
531 ✔
205

206
void Doc::setWorkspacePath(QString path)
4 ✔
207
{
208
    m_workspacePath = path;
4 ✔
209
}
4 ✔
210

211
QString Doc::workspacePath() const
109 ✔
212
{
213
    return m_workspacePath;
109 ✔
214
}
215

216
QString Doc::normalizeComponentPath(const QString& filePath) const
7 ✔
217
{
218
    if (filePath.isEmpty())
7 ✔
219
        return filePath;
1 ✔
220

221
    QFileInfo f(filePath);
6 ✔
222

223
    if (f.absolutePath().startsWith(workspacePath()))
6 ✔
224
    {
225
        return QDir(workspacePath()).relativeFilePath(f.absoluteFilePath());
8 ✔
226
    }
227
    else
228
    {
229
        return f.absoluteFilePath();
2 ✔
230
    }
231
}
6 ✔
232

233
QString Doc::denormalizeComponentPath(const QString& filePath) const
8 ✔
234
{
235
    if (filePath.isEmpty())
8 ✔
236
        return filePath;
2 ✔
237

238
    return QFileInfo(QDir(workspacePath()), filePath).absoluteFilePath();
12 ✔
239
}
240

241
/*****************************************************************************
242
 * Engine components
243
 *****************************************************************************/
244

245
QLCFixtureDefCache* Doc::fixtureDefCache() const
1,686 ✔
246
{
247
    return m_fixtureDefCache;
1,686 ✔
248
}
249

250
void Doc::setFixtureDefinitionCache(QLCFixtureDefCache *cache)
×
251
{
252
    m_fixtureDefCache = cache;
×
253
}
×
254

255
QLCModifiersCache* Doc::modifiersCache() const
1 ✔
256
{
257
    return m_modifiersCache;
1 ✔
258
}
259

260
RGBScriptsCache* Doc::rgbScriptsCache() const
117 ✔
261
{
262
    return m_rgbScriptsCache;
117 ✔
263
}
264

265
IOPluginCache* Doc::ioPluginCache() const
331 ✔
266
{
267
    return m_ioPluginCache;
331 ✔
268
}
269

270
AudioPluginCache *Doc::audioPluginCache() const
1 ✔
271
{
272
    return m_audioPluginCache;
1 ✔
273
}
274

275
ServiceLoader *Doc::serviceLoader() const
×
276
{
277
    return m_serviceLoader;
×
278
}
279

280
void Doc::slotServiceAvailable(const QString &id)
×
281
{
282
    if (id == QLCRDM_SERVICE_ID)
×
283
    {
284
        QLCRDMService *rdm = m_serviceLoader->service<QLCRDMService>(id);
×
285
        if (rdm == NULL)
×
286
        {
287
            qWarning() << "The" << id << "service doesn't implement the expected interface";
×
288
            return;
×
289
        }
290
        rdm->setTransportProvider(m_ioMap);
×
291
    }
292
}
293

294
InputOutputMap* Doc::inputOutputMap() const
2,911 ✔
295
{
296
    return m_ioMap;
2,911 ✔
297
}
298

299
MasterTimer* Doc::masterTimer() const
1,338 ✔
300
{
301
    return m_masterTimer;
1,338 ✔
302
}
303

304
QSharedPointer<AudioCapture> Doc::audioInputCapture() const
43 ✔
305
{
306
    if (!m_inputCapture)
43 ✔
307
    {
308
        qDebug() << "Creating new audio capture";
2 ✔
309
        m_inputCapture = QSharedPointer<AudioCapture>(
4 ✔
310
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
311
            new AudioCaptureQt5()
312
#else
313
            new AudioCaptureQt6()
2 ✔
314
#endif
315
            );
2 ✔
316
    }
317
    return m_inputCapture;
43 ✔
318
}
319

320
void Doc::destroyAudioCapture()
531 ✔
321
{
322
    if (m_inputCapture.isNull() == false)
531 ✔
323
    {
324
        qDebug() << "Destroying audio capture";
2 ✔
325
        m_inputCapture.clear();
2 ✔
326
    }
327
}
531 ✔
328

329
/*****************************************************************************
330
 * Modified status
331
 *****************************************************************************/
332
Doc::LoadStatus Doc::loadStatus() const
2 ✔
333
{
334
    return m_loadStatus;
2 ✔
335
}
336

337
bool Doc::isModified() const
29 ✔
338
{
339
    return m_modified;
29 ✔
340
}
341

342
void Doc::setModified()
1,337 ✔
343
{
344
    m_modified = true;
1,337 ✔
345
    m_autosaveTimer.start();
1,337 ✔
346
    emit modified(true);
1,337 ✔
347
}
1,337 ✔
348

349
void Doc::resetModified()
235 ✔
350
{
351
    m_modified = false;
235 ✔
352
    m_autosaveTimer.stop();
235 ✔
353
    emit modified(false);
235 ✔
354
}
235 ✔
355

356
/*****************************************************************************
357
 * Main operating mode
358
 *****************************************************************************/
359

360
void Doc::setMode(Doc::Mode mode)
28 ✔
361
{
362
    /* Don't do mode switching twice */
363
    if (m_mode == mode)
28 ✔
364
        return;
3 ✔
365

366
    m_mode = mode;
25 ✔
367

368
    if (mode == Operate)
25 ✔
369
        m_autosaveTimer.stop();
19 ✔
370
    else if (m_modified)
6 ✔
371
        m_autosaveTimer.start();
5 ✔
372

373
    // Run startup function
374
    if (m_mode == Operate && m_startupFunctionId != Function::invalidId())
25 ✔
375
    {
376
        Function *func = function(m_startupFunctionId);
×
377
        if (func != NULL)
×
378
        {
379
            qDebug() << Q_FUNC_INFO << "Starting startup function. (" << m_startupFunctionId << ")";
×
380
            func->start(masterTimer(), FunctionParent::master());
×
381
        }
382
        else
383
        {
384
            qWarning() << Q_FUNC_INFO << "Startup function does not exist, erasing. (" << m_startupFunctionId << ")";
×
385
            m_startupFunctionId = Function::invalidId();
×
386
        }
387
    }
388

389
    emit modeChanged(m_mode);
25 ✔
390
}
391

392
Doc::Mode Doc::mode() const
339 ✔
393
{
394
    return m_mode;
339 ✔
395
}
396

397
void Doc::setKiosk(bool state)
1 ✔
398
{
399
    m_kiosk = state;
1 ✔
400
}
1 ✔
401

402
bool Doc::isKiosk() const
222 ✔
403
{
404
    return m_kiosk;
222 ✔
405
}
406

407
/*********************************************************************
408
 * Clipboard
409
 *********************************************************************/
410

411
QLCClipboard *Doc::clipboard()
1 ✔
412
{
413
    return m_clipboard;
1 ✔
414
}
415

416
/*****************************************************************************
417
 * Fixtures
418
 *****************************************************************************/
419

420
quint32 Doc::createFixtureId()
16,825 ✔
421
{
422
    /* This results in an endless loop if there are UINT_MAX-1 fixtures. That,
423
       however, seems a bit unlikely. Are there even 4294967295-1 fixtures in
424
       total in the whole world? */
425
    while (m_fixtures.contains(m_latestFixtureId) == true ||
50,290 ✔
426
           m_latestFixtureId == Fixture::invalidId())
16,825 ✔
427
    {
428
        m_latestFixtureId++;
16,640 ✔
429
    }
430

431
    return m_latestFixtureId;
16,825 ✔
432
}
433

434
bool Doc::addFixture(Fixture* fixture, quint32 id)
454 ✔
435
{
436
    Q_ASSERT(fixture != NULL);
454 ✔
437

438
    quint32 i;
439
    quint32 uni = fixture->lastUniverse();
454 ✔
440

441
    // No ID given, this method can assign one
442
    if (id == Fixture::invalidId())
454 ✔
443
        id = createFixtureId();
441 ✔
444

445
    if (m_fixtures.contains(id) == true || id == Fixture::invalidId())
454 ✔
446
    {
447
        qWarning() << Q_FUNC_INFO << "a fixture with ID" << id << "already exists!";
1 ✔
448
        return false;
1 ✔
449
    }
450

451
    /* Check for overlapping address */
452
    for (i = 0; i < fixture->channels(); i++)
7,233 ✔
453
    {
454
        quint32 absAddress = fixture->channelAddress(i);
6,786 ✔
455
        if (m_addresses.contains(absAddress))
6,786 ✔
456
        {
457
            qWarning() << Q_FUNC_INFO << "fixture" << id << "overlapping with fixture" << m_addresses[absAddress] << "@ channel" << absAddress;
6 ✔
458
            return false;
6 ✔
459
        }
460
    }
461

462
    fixture->setID(id);
447 ✔
463
    m_fixtures.insert(id, fixture);
447 ✔
464
    m_fixturesListCacheUpToDate = false;
447 ✔
465

466
    /* Patch fixture change signals thru Doc */
467
    connect(fixture, SIGNAL(changed(quint32)),
447 ✔
468
            this, SLOT(slotFixtureChanged(quint32)));
469

470
    /* Keep track of fixture addresses */
471
    for (i = 0; i < fixture->channels(); i++)
7,077 ✔
472
        m_addresses[fixture->channelAddress(i)] = id;
6,630 ✔
473

474
    if (uni >= inputOutputMap()->universesCount())
447 ✔
475
    {
476
        for (i = inputOutputMap()->universesCount(); i <= uni; i++)
2 ✔
477
            inputOutputMap()->addUniverse(i);
1 ✔
478
        inputOutputMap()->startUniverses();
1 ✔
479
    }
480

481
    // Add the fixture channels capabilities to the universe they belong
482
    QList<Universe *> universes = inputOutputMap()->claimUniverses();
447 ✔
483

484
    QList<int> forcedHTP = fixture->forcedHTPChannels();
447 ✔
485
    QList<int> forcedLTP = fixture->forcedLTPChannels();
447 ✔
486

487
    for (i = 0; i < fixture->channels(); i++)
7,077 ✔
488
    {
489
        const QLCChannel *channel(fixture->channel(i));
6,630 ✔
490
        quint32 absAddress = fixture->channelAddress(i);
6,630 ✔
491
        uni = absAddress >> 9;
6,630 ✔
492
        quint32 addr = absAddress & 0x01FF;
6,630 ✔
493

494
        // Inform Universe of any HTP/LTP forcing
495
        if (forcedHTP.contains(int(i)))
6,630 ✔
496
            universes.at(uni)->setChannelCapability(addr, channel->group(), Universe::HTP);
×
497
        else if (forcedLTP.contains(int(i)))
6,630 ✔
498
            universes.at(uni)->setChannelCapability(addr, channel->group(), Universe::LTP);
1 ✔
499
        else
500
            universes.at(uni)->setChannelCapability(addr, channel->group());
6,629 ✔
501

502
        // Apply the default value BEFORE modifiers
503
        universes.at(uni)->setChannelDefaultValue(addr, channel->defaultValue());
6,630 ✔
504

505
        // Apply a channel modifier, if defined
506
        ChannelModifier *mod = fixture->channelModifier(i);
6,630 ✔
507
        universes.at(uni)->setChannelModifier(addr, mod);
6,630 ✔
508
    }
509
    inputOutputMap()->releaseUniverses(true);
447 ✔
510

511
    emit fixtureAdded(id);
447 ✔
512
    setModified();
447 ✔
513

514
    return true;
447 ✔
515
}
447 ✔
516

517
bool Doc::deleteFixture(quint32 id)
18 ✔
518
{
519
    if (m_fixtures.contains(id) == true)
18 ✔
520
    {
521
        Fixture* fxi = m_fixtures.take(id);
12 ✔
522
        Q_ASSERT(fxi != NULL);
12 ✔
523
        m_fixturesListCacheUpToDate = false;
12 ✔
524

525
        /* Keep track of fixture addresses */
526
        QMutableHashIterator <uint,uint> it(m_addresses);
12 ✔
527
        while (it.hasNext() == true)
478 ✔
528
        {
529
            it.next();
466 ✔
530
            if (it.value() == id)
466 ✔
531
                it.remove();
409 ✔
532
        }
533
        if (m_monitorProps != NULL)
12 ✔
534
            m_monitorProps->removeFixture(id);
×
535

536
        emit fixtureRemoved(id);
12 ✔
537
        setModified();
12 ✔
538
        delete fxi;
12 ✔
539

540
        if (m_fixtures.count() == 0)
12 ✔
541
            m_latestFixtureId = 0;
6 ✔
542

543
        return true;
12 ✔
544
    }
545
    else
546
    {
547
        qWarning() << Q_FUNC_INFO << "No fixture with id" << id;
6 ✔
548
        return false;
6 ✔
549
    }
550
}
551

552
bool Doc::replaceFixtures(QList<Fixture*> newFixturesList)
6 ✔
553
{
554
    // Delete all fixture instances
555
    QListIterator <quint32> fxit(m_fixtures.keys());
6 ✔
556
    while (fxit.hasNext() == true)
14 ✔
557
    {
558
        Fixture* fxi = m_fixtures.take(fxit.next());
8 ✔
559
        disconnect(fxi, SIGNAL(changed(quint32)),
8 ✔
560
                   this, SLOT(slotFixtureChanged(quint32)));
561
        delete fxi;
8 ✔
562
        m_fixturesListCacheUpToDate = false;
8 ✔
563
    }
564
    m_latestFixtureId = 0;
6 ✔
565
    m_addresses.clear();
6 ✔
566

567
    foreach (Fixture *fixture, newFixturesList)
14 ✔
568
    {
569
        quint32 id = fixture->id();
8 ✔
570
        // create a copy of the original cause remapping will
571
        // destroy it later
572
        Fixture *newFixture = new Fixture(this);
8 ✔
573
        newFixture->setID(id);
8 ✔
574
        newFixture->setName(fixture->name());
8 ✔
575
        newFixture->setAddress(fixture->address());
8 ✔
576
        newFixture->setUniverse(fixture->universe());
8 ✔
577
        newFixture->setCrossUniverse(fixture->crossUniverse());
8 ✔
578

579
        if (fixture->fixtureDef() == NULL ||
18 ✔
580
            (fixture->fixtureDef()->manufacturer() == KXMLFixtureGeneric &&
18 ✔
581
             fixture->fixtureDef()->model() == KXMLFixtureGeneric))
10 ✔
582
        {
583
            // Generic dimmers just need to know the number of channels
584
            newFixture->setChannels(fixture->channels());
2 ✔
585
        }
586
        else if (fixture->fixtureDef() == NULL ||
12 ✔
587
            (fixture->fixtureDef()->manufacturer() == KXMLFixtureGeneric &&
12 ✔
588
             fixture->fixtureDef()->model() == KXMLFixtureRGBPanel))
6 ✔
589
        {
590
            // RGB Panels definitions are not cached or shared, so
591
            // let's make a deep copy of them
592
            QLCFixtureDef *fixtureDef = new QLCFixtureDef();
×
593
            *fixtureDef = *fixture->fixtureDef();
×
594
            QLCFixtureMode *mode = new QLCFixtureMode(fixtureDef);
×
595
            *mode = *fixture->fixtureMode();
×
596
            newFixture->setFixtureDefinition(fixtureDef, mode);
×
597
        }
598
        else
599
        {
600
            QLCFixtureDef *def = fixtureDefCache()->fixtureDef(fixture->fixtureDef()->manufacturer(),
12 ✔
601
                                                               fixture->fixtureDef()->model());
12 ✔
602
            QLCFixtureMode *mode = NULL;
6 ✔
603
            if (def != NULL)
6 ✔
604
                mode = def->mode(fixture->fixtureMode()->name());
1 ✔
605
            newFixture->setFixtureDefinition(def, mode);
6 ✔
606
        }
607

608
        newFixture->setExcludeFadeChannels(fixture->excludeFadeChannels());
8 ✔
609
        newFixture->setForcedHTPChannels(fixture->forcedHTPChannels());
8 ✔
610
        newFixture->setForcedLTPChannels(fixture->forcedLTPChannels());
8 ✔
611

612
        for (quint32 s = 0; s < fixture->channels(); s++)
35 ✔
613
        {
614
            ChannelModifier *chMod = fixture->channelModifier(s);
27 ✔
615
            if (chMod != NULL)
27 ✔
616
                newFixture->setChannelModifier(s, chMod);
×
617
        }
618

619
        m_fixtures.insert(id, newFixture);
8 ✔
620
        m_fixturesListCacheUpToDate = false;
8 ✔
621

622
        /* Patch fixture change signals thru Doc */
623
        connect(newFixture, SIGNAL(changed(quint32)),
8 ✔
624
                this, SLOT(slotFixtureChanged(quint32)));
625

626
        /* Keep track of fixture addresses */
627
        for (quint32 i = 0; i < newFixture->channels(); i++)
20 ✔
628
            m_addresses[newFixture->channelAddress(i)] = id;
12 ✔
629
        m_latestFixtureId = id;
8 ✔
630
    }
6 ✔
631
    return true;
6 ✔
632
}
6 ✔
633

634
bool Doc::updateFixtureChannelCapabilities(quint32 id, QList<int> forcedHTP, QList<int> forcedLTP)
2 ✔
635
{
636
    if (m_fixtures.contains(id) == false)
2 ✔
637
        return false;
1 ✔
638

639
    Fixture* fixture = m_fixtures[id];
1 ✔
640
    // get exclusive access to the universes list
641
    QList<Universe *> universes = inputOutputMap()->claimUniverses();
1 ✔
642

643
    // Set forced HTP channels
644
    fixture->setForcedHTPChannels(forcedHTP);
1 ✔
645

646
    // Set forced LTP channels
647
    fixture->setForcedLTPChannels(forcedLTP);
1 ✔
648

649
    // Update the Fixture Universe with the current channel states
650
    for (quint32 i = 0 ; i < fixture->channels(); i++)
7 ✔
651
    {
652
        const QLCChannel *channel(fixture->channel(i));
6 ✔
653

654
        // a cross-universe fixture may span multiple universes
655
        quint32 absAddress = fixture->channelAddress(i);
6 ✔
656
        quint32 uniIdx = absAddress >> 9;
6 ✔
657
        if (int(uniIdx) >= universes.count())
6 ✔
658
            continue;
×
659

660
        Universe *universe = universes.at(uniIdx);
6 ✔
661
        quint32 addr = absAddress & 0x01FF;
6 ✔
662

663
        // Inform Universe of any HTP/LTP forcing
664
        if (forcedHTP.contains(int(i)))
6 ✔
665
            universe->setChannelCapability(addr, channel->group(), Universe::HTP);
2 ✔
666
        else if (forcedLTP.contains(int(i)))
4 ✔
667
            universe->setChannelCapability(addr, channel->group(), Universe::LTP);
1 ✔
668
        else
669
            universe->setChannelCapability(addr, channel->group());
3 ✔
670

671
        // Apply the default value BEFORE modifiers
672
        universe->setChannelDefaultValue(addr, channel->defaultValue());
6 ✔
673

674
        // Apply a channel modifier, if defined
675
        ChannelModifier *mod = fixture->channelModifier(i);
6 ✔
676
        universe->setChannelModifier(addr, mod);
6 ✔
677
    }
678

679
    inputOutputMap()->releaseUniverses(true);
1 ✔
680

681
    return true;
1 ✔
682
}
1 ✔
683

684
QList<Fixture*> const& Doc::fixtures() const
81 ✔
685
{
686
    if (!m_fixturesListCacheUpToDate)
81 ✔
687
    {
688
        // Sort fixtures by id
689
        QMap <quint32, Fixture*> fixturesMap;
49 ✔
690
        QHashIterator <quint32, Fixture*> hashIt(m_fixtures);
49 ✔
691
        while (hashIt.hasNext())
92 ✔
692
        {
693
            hashIt.next();
43 ✔
694
            fixturesMap.insert(hashIt.key(), hashIt.value());
43 ✔
695
        }
696
        const_cast<QList<Fixture*>&>(m_fixturesListCache) = fixturesMap.values();
49 ✔
697
        const_cast<bool&>(m_fixturesListCacheUpToDate) = true;
49 ✔
698
    }
49 ✔
699
    return m_fixturesListCache;
81 ✔
700
}
701

702
int Doc::fixturesCount() const
×
703
{
704
    return m_fixtures.count();
×
705
}
706

707
Fixture* Doc::fixture(quint32 id) const
61,733 ✔
708
{
709
    return m_fixtures.value(id, NULL);
61,733 ✔
710
}
711

712
quint32 Doc::fixtureForAddress(quint32 universeAddress) const
60,090 ✔
713
{
714
    return m_addresses.value(universeAddress, Fixture::invalidId());
60,090 ✔
715
}
716

717
int Doc::totalPowerConsumption(int& fuzzy) const
4 ✔
718
{
719
    int totalPowerConsumption = 0;
4 ✔
720

721
    // Make sure fuzzy starts from zero
722
    fuzzy = 0;
4 ✔
723

724
    QListIterator <Fixture*> fxit(fixtures());
4 ✔
725
    while (fxit.hasNext() == true)
14 ✔
726
    {
727
        Fixture* fxi(fxit.next());
10 ✔
728
        Q_ASSERT(fxi != NULL);
10 ✔
729

730
        if (fxi->fixtureMode() != NULL)
10 ✔
731
        {
732
            QLCPhysical phys = fxi->fixtureMode()->physical();
10 ✔
733
            if (phys.powerConsumption() > 0)
10 ✔
734
                totalPowerConsumption += phys.powerConsumption();
7 ✔
735
            else
736
                fuzzy++;
3 ✔
737
        }
10 ✔
738
        else
739
        {
740
            fuzzy++;
×
741
        }
742
    }
743

744
    return totalPowerConsumption;
4 ✔
745
}
4 ✔
746

747
void Doc::slotFixtureChanged(quint32 id)
4 ✔
748
{
749
    /* Keep track of fixture addresses */
750
    Fixture* fxi = fixture(id);
4 ✔
751

752
    // remove it
753
    QMutableHashIterator <uint,uint> it(m_addresses);
4 ✔
754
    while (it.hasNext() == true)
67 ✔
755
    {
756
        it.next();
63 ✔
757
        if (it.value() == id)
63 ✔
758
        {
759
            qDebug() << Q_FUNC_INFO << " remove: " << it.key() << " val: " << it.value();
19 ✔
760
            it.remove();
19 ✔
761
        }
762
    }
763

764
    for (quint32 ch = 0; ch < fxi->channels(); ch++)
23 ✔
765
    {
766
        /*
767
         * setting new universe and address calls this twice,
768
         * with an tmp wrong address after the first call (old address() + new universe()).
769
         * we only add if the channel is free, to prevent messing up things
770
         */
771
        quint32 i = fxi->channelAddress(ch);
19 ✔
772
        Q_ASSERT(!m_addresses.contains(i));
19 ✔
773
        m_addresses[i] = id;
19 ✔
774
    }
775

776
    setModified();
4 ✔
777
    emit fixtureChanged(id);
4 ✔
778
}
4 ✔
779

780
/*****************************************************************************
781
 * Fixture groups
782
 *****************************************************************************/
783

784
bool Doc::addFixtureGroup(FixtureGroup* grp, quint32 id)
16 ✔
785
{
786
    Q_ASSERT(grp != NULL);
16 ✔
787

788
    // No ID given, this method can assign one
789
    if (id == FixtureGroup::invalidId())
16 ✔
790
        id = createFixtureGroupId();
9 ✔
791

792
    if (m_fixtureGroups.contains(id) == true || id == FixtureGroup::invalidId())
16 ✔
793
    {
794
        qWarning() << Q_FUNC_INFO << "a fixture group with ID" << id << "already exists!";
2 ✔
795
        return false;
2 ✔
796
    }
797
    else
798
    {
799
        grp->setId(id);
14 ✔
800
        m_fixtureGroups[id] = grp;
14 ✔
801

802
        /* Patch fixture group change signals thru Doc */
803
        connect(grp, SIGNAL(changed(quint32)),
14 ✔
804
                this, SLOT(slotFixtureGroupChanged(quint32)));
805

806
        emit fixtureGroupAdded(id);
14 ✔
807
        setModified();
14 ✔
808

809
        return true;
14 ✔
810
    }
811
}
812

813
bool Doc::deleteFixtureGroup(quint32 id)
4 ✔
814
{
815
    if (m_fixtureGroups.contains(id) == true)
4 ✔
816
    {
817
        FixtureGroup* grp = m_fixtureGroups.take(id);
2 ✔
818
        Q_ASSERT(grp != NULL);
2 ✔
819

820
        emit fixtureGroupRemoved(id);
2 ✔
821
        setModified();
2 ✔
822
        delete grp;
2 ✔
823

824
        return true;
2 ✔
825
    }
826
    else
827
    {
828
        qWarning() << Q_FUNC_INFO << "No fixture group with id" << id;
2 ✔
829
        return false;
2 ✔
830
    }
831
}
832

833
FixtureGroup* Doc::fixtureGroup(quint32 id) const
51 ✔
834
{
835
    return m_fixtureGroups.value(id, NULL);
51 ✔
836
}
837

838
QList <FixtureGroup*> Doc::fixtureGroups() const
42 ✔
839
{
840
    return m_fixtureGroups.values();
42 ✔
841
}
842

843
quint32 Doc::createFixtureGroupId()
9 ✔
844
{
845
    /* This results in an endless loop if there are UINT_MAX-1 fixture groups. That,
846
       however, seems a bit unlikely. Are there even 4294967295-1 fixtures in
847
       total in the whole world? */
848
    while (m_fixtureGroups.contains(m_latestFixtureGroupId) == true ||
22 ✔
849
           m_latestFixtureGroupId == FixtureGroup::invalidId())
9 ✔
850
    {
851
        m_latestFixtureGroupId++;
4 ✔
852
    }
853

854
    return m_latestFixtureGroupId;
9 ✔
855
}
856

857
void Doc::slotFixtureGroupChanged(quint32 id)
27 ✔
858
{
859
    setModified();
27 ✔
860
    emit fixtureGroupChanged(id);
27 ✔
861
}
27 ✔
862

863
/*********************************************************************
864
 * Channels groups
865
 *********************************************************************/
866
bool Doc::addChannelsGroup(ChannelsGroup *grp, quint32 id)
6 ✔
867
{
868
    Q_ASSERT(grp != NULL);
6 ✔
869

870
    // No ID given, this method can assign one
871
    if (id == ChannelsGroup::invalidId())
6 ✔
872
        id = createChannelsGroupId();
5 ✔
873

874
     grp->setId(id);
6 ✔
875
     m_channelsGroups[id] = grp;
6 ✔
876
     if (m_orderedGroups.contains(id) == false)
6 ✔
877
        m_orderedGroups.append(id);
6 ✔
878

879
     emit channelsGroupAdded(id);
6 ✔
880
     setModified();
6 ✔
881

882
     return true;
6 ✔
883
}
884

885
bool Doc::deleteChannelsGroup(quint32 id)
2 ✔
886
{
887
    if (m_channelsGroups.contains(id) == true)
2 ✔
888
    {
889
        ChannelsGroup* grp = m_channelsGroups.take(id);
1 ✔
890
        Q_ASSERT(grp != NULL);
1 ✔
891

892
        emit channelsGroupRemoved(id);
1 ✔
893
        setModified();
1 ✔
894
        delete grp;
1 ✔
895

896
        int idx = m_orderedGroups.indexOf(id);
1 ✔
897
        if (idx != -1)
1 ✔
898
            m_orderedGroups.takeAt(idx);
1 ✔
899

900
        return true;
1 ✔
901
    }
902
    else
903
    {
904
        qWarning() << Q_FUNC_INFO << "No channels group with id" << id;
1 ✔
905
        return false;
1 ✔
906
    }
907
}
908

909
bool Doc::moveChannelGroup(quint32 id, int direction)
3 ✔
910
{
911
    if (direction == 0 || m_orderedGroups.contains(id) == false)
3 ✔
912
        return false;
1 ✔
913

914
    int idx = m_orderedGroups.indexOf(id);
2 ✔
915

916
    if (idx + direction < 0 || idx + direction >= m_orderedGroups.count())
2 ✔
917
        return false;
1 ✔
918

919
    qDebug() << Q_FUNC_INFO << m_orderedGroups;
1 ✔
920
    m_orderedGroups.takeAt(idx);
1 ✔
921
    m_orderedGroups.insert(idx + direction, id);
1 ✔
922
    qDebug() << Q_FUNC_INFO << m_orderedGroups;
1 ✔
923

924
    setModified();
1 ✔
925
    return true;
1 ✔
926
}
927

928
ChannelsGroup* Doc::channelsGroup(quint32 id) const
2 ✔
929
{
930
    return m_channelsGroups.value(id, NULL);
2 ✔
931
}
932

933
QList <ChannelsGroup*> Doc::channelsGroups() const
23 ✔
934
{
935
    QList <ChannelsGroup*> orderedList;
23 ✔
936

937
    for (int i = 0; i < m_orderedGroups.count(); i++)
48 ✔
938
    {
939
        orderedList.append(m_channelsGroups[m_orderedGroups.at(i)]);
25 ✔
940
    }
941
    return orderedList;
23 ✔
942
}
×
943

944
quint32 Doc::createChannelsGroupId()
5 ✔
945
{
946
    while (m_channelsGroups.contains(m_latestChannelsGroupId) == true ||
12 ✔
947
           m_latestChannelsGroupId == ChannelsGroup::invalidId())
5 ✔
948
    {
949
        m_latestChannelsGroupId++;
2 ✔
950
    }
951

952
    return m_latestChannelsGroupId;
5 ✔
953
}
954

955
/*********************************************************************
956
 * Palettes
957
 *********************************************************************/
958

959
bool Doc::addPalette(QLCPalette *palette, quint32 id)
2 ✔
960
{
961
    Q_ASSERT(palette != NULL);
2 ✔
962

963
    // No ID given, this method can assign one
964
    if (id == QLCPalette::invalidId())
2 ✔
965
        id = createPaletteId();
2 ✔
966

967
    if (m_palettes.contains(id) == true || id == QLCPalette::invalidId())
2 ✔
968
    {
969
        qWarning() << Q_FUNC_INFO << "a palette with ID" << id << "already exists!";
×
970
        return false;
×
971
    }
972
    else
973
    {
974
        palette->setID(id);
2 ✔
975
        palette->setTemporary(false);
2 ✔
976
        m_palettes[id] = palette;
2 ✔
977

978
        emit paletteAdded(id);
2 ✔
979
        setModified();
2 ✔
980
    }
981

982
    return true;
2 ✔
983
}
984

985
bool Doc::deletePalette(quint32 id)
3 ✔
986
{
987
    if (m_palettes.contains(id) == true)
3 ✔
988
    {
989
        QLCPalette *palette = m_palettes.take(id);
2 ✔
990
        Q_ASSERT(palette != NULL);
2 ✔
991

992
        emit paletteRemoved(id);
2 ✔
993
        setModified();
2 ✔
994
        delete palette;
2 ✔
995

996
        return true;
2 ✔
997
    }
998
    else
999
    {
1000
        qWarning() << Q_FUNC_INFO << "No palette with id" << id;
1 ✔
1001
        return false;
1 ✔
1002
    }
1003
}
1004

1005
QLCPalette *Doc::palette(quint32 id) const
2 ✔
1006
{
1007
    return m_palettes.value(id, NULL);
2 ✔
1008
}
1009

1010
QList<QLCPalette *> Doc::palettes() const
8 ✔
1011
{
1012
    return m_palettes.values();
8 ✔
1013
}
1014

1015
quint32 Doc::createPaletteId()
2 ✔
1016
{
1017
    while (m_palettes.contains(m_latestPaletteId) == true ||
5 ✔
1018
           m_latestPaletteId == FixtureGroup::invalidId())
2 ✔
1019
    {
1020
        m_latestPaletteId++;
1 ✔
1021
    }
1022

1023
    return m_latestPaletteId;
2 ✔
1024
}
1025

1026
/*****************************************************************************
1027
 * Functions
1028
 *****************************************************************************/
1029

1030
quint32 Doc::createFunctionId()
262 ✔
1031
{
1032
    /* This results in an endless loop if there are UINT_MAX-1 functions. That,
1033
       however, seems a bit unlikely. Are there even 4294967295-1 functions in
1034
       total in the whole world? */
1035
    while (m_functions.contains(m_latestFunctionId) == true ||
700 ✔
1036
           m_latestFunctionId == Fixture::invalidId())
262 ✔
1037
    {
1038
        m_latestFunctionId++;
176 ✔
1039
    }
1040

1041
    return m_latestFunctionId;
262 ✔
1042
}
1043

1044
bool Doc::addFunction(Function* func, quint32 id)
275 ✔
1045
{
1046
    Q_ASSERT(func != NULL);
275 ✔
1047

1048
    if (id == Function::invalidId())
275 ✔
1049
        id = createFunctionId();
262 ✔
1050

1051
    if (m_functions.contains(id) == true || id == Fixture::invalidId())
275 ✔
1052
    {
1053
        qWarning() << Q_FUNC_INFO << "a function with ID" << id << "already exists!";
2 ✔
1054
        return false;
2 ✔
1055
    }
1056
    else
1057
    {
1058
        // Listen to function changes
1059
        connect(func, SIGNAL(changed(quint32)),
273 ✔
1060
                this, SLOT(slotFunctionChanged(quint32)));
1061

1062
        // Listen to function name changes
1063
        connect(func, SIGNAL(nameChanged(quint32)),
273 ✔
1064
                this, SLOT(slotFunctionNameChanged(quint32)));
1065

1066
        // Make the function listen to fixture removals
1067
        connect(this, SIGNAL(fixtureRemoved(quint32)),
273 ✔
1068
                func, SLOT(slotFixtureRemoved(quint32)));
1069

1070
        // Place the function in the map and assign it the new ID
1071
        m_functions[id] = func;
273 ✔
1072
        func->setID(id);
273 ✔
1073
        emit functionAdded(id);
273 ✔
1074
        setModified();
273 ✔
1075

1076
        return true;
273 ✔
1077
    }
1078
}
1079

1080
QList <Function*> Doc::functions() const
55 ✔
1081
{
1082
    return m_functions.values();
55 ✔
1083
}
1084

1085
QList<Function *> Doc::functionsByType(Function::Type type) const
1 ✔
1086
{
1087
    QList <Function*> list;
1 ✔
1088
    foreach (Function *f, m_functions)
10 ✔
1089
    {
1090
        if (f != NULL && f->type() == type)
9 ✔
1091
            list.append(f);
5 ✔
1092
    }
1 ✔
1093
    return list;
1 ✔
1094
}
×
1095

1096
Function *Doc::functionByName(QString name)
×
1097
{
1098
    foreach (Function *f, m_functions)
×
1099
    {
1100
        if (f != NULL && f->name() == name)
×
1101
            return f;
×
1102
    }
×
1103
    return NULL;
×
1104
}
1105

1106
bool Doc::deleteFunction(quint32 id)
10 ✔
1107
{
1108
    if (m_functions.contains(id) == true)
10 ✔
1109
    {
1110
        Function* func = m_functions.take(id);
8 ✔
1111
        Q_ASSERT(func != NULL);
8 ✔
1112

1113
        if (m_startupFunctionId == id)
8 ✔
1114
            m_startupFunctionId = Function::invalidId();
×
1115

1116
        emit functionRemoved(id);
8 ✔
1117
        setModified();
8 ✔
1118
        delete func;
8 ✔
1119

1120
        return true;
8 ✔
1121
    }
1122
    else
1123
    {
1124
        qWarning() << Q_FUNC_INFO << "No function with id" << id;
2 ✔
1125
        return false;
2 ✔
1126
    }
1127
}
1128

1129
Function* Doc::function(quint32 id) const
951 ✔
1130
{
1131
    return m_functions.value(id, NULL);
951 ✔
1132
}
1133

1134
quint32 Doc::nextFunctionID() const
2 ✔
1135
{
1136
    quint32 tmpFID = m_latestFunctionId;
2 ✔
1137
    while (m_functions.contains(tmpFID) == true ||
5 ✔
1138
           tmpFID == Fixture::invalidId())
2 ✔
1139
    {
1140
        tmpFID++;
1 ✔
1141
    }
1142

1143
    return tmpFID;
2 ✔
1144
}
1145

1146
void Doc::setStartupFunction(quint32 fid)
1 ✔
1147
{
1148
    m_startupFunctionId = fid;
1 ✔
1149
}
1 ✔
1150

1151
quint32 Doc::startupFunction() const
2 ✔
1152
{
1153
    return m_startupFunctionId;
2 ✔
1154
}
1155

1156
QList<quint32> Doc::getUsage(quint32 fid)
7 ✔
1157
{
1158
    QList<quint32> usageList;
7 ✔
1159

1160
    foreach (Function *f, m_functions)
70 ✔
1161
    {
1162
        if (f->id() == fid)
63 ✔
1163
            continue;
6 ✔
1164

1165
        switch(f->type())
57 ✔
1166
        {
1167
            case Function::CollectionType:
7 ✔
1168
            {
1169
                Collection *c = qobject_cast<Collection *>(f);
7 ✔
1170
                int pos = c->functions().indexOf(fid);
7 ✔
1171
                if (pos != -1)
7 ✔
1172
                {
1173
                    usageList.append(f->id());
2 ✔
1174
                    usageList.append(pos);
2 ✔
1175
                }
1176
            }
1177
            break;
7 ✔
1178
            case Function::ChaserType:
6 ✔
1179

1180
            {
1181
                Chaser *c = qobject_cast<Chaser *>(f);
6 ✔
1182
                for (int i = 0; i < c->stepsCount(); i++)
18 ✔
1183
                {
1184
                    ChaserStep *cs = c->stepAt(i);
12 ✔
1185
                    if (cs->fid == fid)
12 ✔
1186
                    {
1187
                        usageList.append(f->id());
2 ✔
1188
                        usageList.append(i);
2 ✔
1189
                    }
1190
                }
1191
            }
1192
            break;
6 ✔
1193
            case Function::SequenceType:
7 ✔
1194
            {
1195
                Sequence *s = qobject_cast<Sequence *>(f);
7 ✔
1196
                if (s->boundSceneID() == fid)
7 ✔
1197
                {
1198
                    usageList.append(f->id());
1 ✔
1199
                    usageList.append(0);
1 ✔
1200
                }
1201
            }
1202
            break;
7 ✔
1203
            case Function::ScriptType:
7 ✔
1204
            {
1205
                Script *s = qobject_cast<Script *>(f);
7 ✔
1206
                QList<quint32> l = s->functionList();
7 ✔
1207
                for (int i = 0; i < l.count(); i+=2)
14 ✔
1208
                {
1209
                    if (l.at(i) == fid)
7 ✔
1210
                    {
1211
                        if (i + 1 >= l.count()) {
1 ✔
1212
                            qDebug() << "Doc::getUsage: Index entry missing on " << f->name();
×
1213
                            break;
×
1214
                        }
1215
                        usageList.append(s->id());
1 ✔
1216
                        usageList.append(l.at(i + 1)); // line number
1 ✔
1217
                    }
1218
                }
1219
            }
7 ✔
1220
            break;
7 ✔
1221
            case Function::ShowType:
×
1222
            {
1223
                Show *s = qobject_cast<Show *>(f);
×
1224
                foreach (Track *t, s->tracks())
×
1225
                {
1226
                    foreach (ShowFunction *sf, t->showFunctions())
×
1227
                    {
1228
                        if (sf->functionID() == fid)
×
1229
                        {
1230
                            usageList.append(f->id());
×
1231
                            usageList.append(t->id());
×
1232
                        }
1233
                    }
×
1234
                }
×
1235
            }
1236
            break;
×
1237
            default:
30 ✔
1238
            break;
30 ✔
1239
        }
1240
    }
7 ✔
1241

1242
    return usageList;
7 ✔
1243
}
×
1244

1245
void Doc::slotFunctionChanged(quint32 fid)
118 ✔
1246
{
1247
    setModified();
118 ✔
1248
    emit functionChanged(fid);
118 ✔
1249
}
118 ✔
1250

1251
void Doc::slotFunctionNameChanged(quint32 fid)
2 ✔
1252
{
1253
    setModified();
2 ✔
1254
    emit functionNameChanged(fid);
2 ✔
1255
}
2 ✔
1256

1257
/*********************************************************************
1258
 * Monitor Properties
1259
 *********************************************************************/
1260

1261
MonitorProperties *Doc::monitorProperties()
7 ✔
1262
{
1263
    if (m_monitorProps == NULL)
7 ✔
1264
        m_monitorProps = new MonitorProperties();
2 ✔
1265

1266
    return m_monitorProps;
7 ✔
1267
}
1268

1269
/*****************************************************************************
1270
 * Load & Save
1271
 *****************************************************************************/
1272

1273
bool Doc::loadXML(QXmlStreamReader &doc, bool loadIO)
2 ✔
1274
{
1275
    clearErrorLog();
2 ✔
1276

1277
    if (doc.name() != KXMLQLCEngine)
2 ✔
1278
    {
1279
        qWarning() << Q_FUNC_INFO << "Engine node not found";
1 ✔
1280
        return false;
1 ✔
1281
    }
1282

1283
    m_loadStatus = Loading;
1 ✔
1284
    emit loading();
1 ✔
1285

1286
    if (doc.attributes().hasAttribute(KXMLQLCStartupFunction))
2 ✔
1287
    {
1288
        quint32 sID = doc.attributes().value(KXMLQLCStartupFunction).toString().toUInt();
×
1289
        if (sID != Function::invalidId())
×
1290
            setStartupFunction(sID);
×
1291
    }
1292

1293
    while (doc.readNextStartElement())
17 ✔
1294
    {
1295
        //qDebug() << "Doc tag:" << doc.name();
1296
        if (doc.name() == KXMLFixture)
16 ✔
1297
        {
1298
            Fixture::loader(doc, this);
3 ✔
1299
        }
1300
        else if (doc.name() == KXMLQLCFixtureGroup)
13 ✔
1301
        {
1302
            FixtureGroup::loader(doc, this);
3 ✔
1303
        }
1304
        else if (doc.name() == KXMLQLCChannelsGroup)
10 ✔
1305
        {
1306
            ChannelsGroup::loader(doc, this);
×
1307
        }
1308
        else if (doc.name() == KXMLQLCPalette)
10 ✔
1309
        {
1310
            QLCPalette::loader(doc, this);
×
1311
            doc.skipCurrentElement();
×
1312
        }
1313
        else if (doc.name() == KXMLQLCFunction)
10 ✔
1314
        {
1315
            //qDebug() << doc.attributes().value("Name").toString();
1316
            Function::loader(doc, this);
4 ✔
1317
        }
1318
        else if (doc.name() == KXMLQLCBus)
6 ✔
1319
        {
1320
            /* LEGACY */
1321
            Bus::instance()->loadXML(doc);
5 ✔
1322
        }
1323
        else if (doc.name() == KXMLIOMap && loadIO)
2 ✔
1324
        {
1325
            m_ioMap->loadXML(doc);
×
1326
        }
1327
        else if (doc.name() == KXMLQLCMonitorProperties)
1 ✔
1328
        {
1329
            monitorProperties()->loadXML(doc, this);
×
1330
        }
1331
        else
1332
        {
1333
            qWarning() << Q_FUNC_INFO << "Unknown engine tag:" << doc.name();
1 ✔
1334
            doc.skipCurrentElement();
1 ✔
1335
        }
1336
    }
1337

1338
    postLoad();
1 ✔
1339

1340
    m_loadStatus = Loaded;
1 ✔
1341
    emit loaded();
1 ✔
1342

1343
    return true;
1 ✔
1344
}
1345

1346
bool Doc::saveXML(QXmlStreamWriter *doc) const
1 ✔
1347
{
1348
    Q_ASSERT(doc != NULL);
1 ✔
1349

1350
    /* Create the master Engine node */
1351
    doc->writeStartElement(KXMLQLCEngine);
2 ✔
1352

1353
    if (startupFunction() != Function::invalidId())
1 ✔
1354
        doc->writeAttribute(KXMLQLCStartupFunction, QString::number(startupFunction()));
×
1355

1356
    m_ioMap->saveXML(doc);
1 ✔
1357

1358
    /* Write fixtures into an XML document */
1359
    QListIterator <Fixture*> fxit(fixtures());
1 ✔
1360
    while (fxit.hasNext() == true)
4 ✔
1361
    {
1362
        Fixture *fxi(fxit.next());
3 ✔
1363
        if (fxi != NULL)
3 ✔
1364
            fxi->saveXML(doc);
3 ✔
1365
    }
1366

1367
    /* Write fixture groups into an XML document */
1368
    QListIterator <FixtureGroup*> grpit(fixtureGroups());
1 ✔
1369
    while (grpit.hasNext() == true)
3 ✔
1370
    {
1371
        FixtureGroup *grp(grpit.next());
2 ✔
1372
        if (grp != NULL)
2 ✔
1373
            grp->saveXML(doc);
2 ✔
1374
    }
1375

1376
    /* Write channel groups into an XML document */
1377
    QListIterator <ChannelsGroup*> chanGroups(channelsGroups());
1 ✔
1378
    while (chanGroups.hasNext() == true)
1 ✔
1379
    {
1380
        ChannelsGroup *grp(chanGroups.next());
×
1381
        if (grp != NULL)
×
1382
            grp->saveXML(doc);
×
1383
    }
1384

1385
    /* Write palettes into an XML document */
1386
    QListIterator <QLCPalette*> paletteIt(palettes());
1 ✔
1387
    while (paletteIt.hasNext() == true)
1 ✔
1388
    {
1389
        QLCPalette *palette(paletteIt.next());
×
1390
        if (palette != NULL)
×
1391
            palette->saveXML(doc);
×
1392
    }
1393

1394
    /* Write functions into an XML document */
1395
    QListIterator <Function*> funcit(functions());
1 ✔
1396
    while (funcit.hasNext() == true)
5 ✔
1397
    {
1398
        Function *func(funcit.next());
4 ✔
1399
        if (func != NULL)
4 ✔
1400
            func->saveXML(doc);
4 ✔
1401
    }
1402

1403
    if (m_monitorProps != NULL)
1 ✔
1404
        m_monitorProps->saveXML(doc, this);
1 ✔
1405

1406
    /* End the <Engine> tag */
1407
    doc->writeEndElement();
1 ✔
1408

1409
    return true;
1 ✔
1410
}
1 ✔
1411

1412
void Doc::appendToErrorLog(QString error)
8 ✔
1413
{
1414
    if (m_errorLog.contains(error))
8 ✔
1415
        return;
5 ✔
1416

1417
    m_errorLog.append(error);
3 ✔
1418
    m_errorLog.append("<br>");
3 ✔
1419
}
1420

1421
void Doc::clearErrorLog()
2 ✔
1422
{
1423
    m_errorLog = "";
2 ✔
1424
}
2 ✔
1425

1426
QString Doc::errorLog() const
1 ✔
1427
{
1428
    return m_errorLog;
1 ✔
1429
}
1430

1431
void Doc::postLoad()
1 ✔
1432
{
1433
    QListIterator <Function*> functionit(functions());
1 ✔
1434
    while (functionit.hasNext() == true)
5 ✔
1435
    {
1436
        Function* function(functionit.next());
4 ✔
1437
        Q_ASSERT(function != NULL);
4 ✔
1438
        function->postLoad();
4 ✔
1439
    }
1440
}
1 ✔
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