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

mcallegari / qlcplus / 42490069460

08 Nov 2026 02:29PM UTC coverage: 61.578% (+24.8%) from 36.826%
42490069460

push

github

mcallegari
qmlui: introduce v5 VC test units and switch coverage

1 of 2 new or added lines in 1 file covered. (50.0%)

144 existing lines in 12 files now uncovered.

18014 of 29254 relevant lines covered (61.58%)

63099.24 hits per line

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

89.99
/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 <algorithm>
23
#include <QXmlStreamWriter>
24
#include <QStringList>
25
#include <QString>
26
#include <QDebug>
27
#include <QList>
28
#include <QTime>
29
#include <QDir>
30
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
31
#include <QRandomGenerator>
32
#endif
33

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

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

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

60
#define AUTOSAVE_TIMEOUT    30 // seconds
61

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

92
    m_autosaveTimer.setInterval(AUTOSAVE_TIMEOUT * 1000);
241 ✔
93
    m_autosaveTimer.setSingleShot(true);
241 ✔
94

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

100
Doc::~Doc()
426 ✔
101
{
102
    delete m_masterTimer;
241 ✔
103
    m_masterTimer = NULL;
241 ✔
104

105
    clearContents();
241 ✔
106

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

116
    delete m_ioMap;
241 ✔
117
    m_ioMap = NULL;
241 ✔
118

119
    delete m_ioPluginCache;
241 ✔
120
    m_ioPluginCache = NULL;
241 ✔
121

122
    delete m_modifiersCache;
241 ✔
123
    m_modifiersCache = NULL;
241 ✔
124

125
    delete m_fixtureDefCache;
241 ✔
126
    m_fixtureDefCache = NULL;
241 ✔
127

128
    delete m_rgbScriptsCache;
241 ✔
129
    m_rgbScriptsCache = NULL;
241 ✔
130
}
426 ✔
131

132
void Doc::clearContents()
514 ✔
133
{
134
    emit clearing();
514 ✔
135

136
    m_clipboard->resetContents();
514 ✔
137

138
    if (m_monitorProps != NULL)
514 ✔
139
        m_monitorProps->reset();
23 ✔
140

141
    destroyAudioCapture();
514 ✔
142

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

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

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

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

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

193
    m_orderedGroups.clear();
514 ✔
194

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

204
    emit cleared();
514 ✔
205
}
514 ✔
206

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

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

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

222
    QFileInfo f(filePath);
4 ✔
223

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

234
QString Doc::denormalizeComponentPath(const QString& filePath) const
4 ✔
235
{
236
    if (filePath.isEmpty())
4 ✔
237
        return filePath;
1 ✔
238

239
    return QFileInfo(QDir(workspacePath()), filePath).absoluteFilePath();
6 ✔
240
}
241

242
/*****************************************************************************
243
 * Engine components
244
 *****************************************************************************/
245

246
QLCFixtureDefCache* Doc::fixtureDefCache() const
218 ✔
247
{
248
    return m_fixtureDefCache;
218 ✔
249
}
250

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

367
    m_mode = mode;
3 ✔
368

369
    if (mode == Operate)
3 ✔
370
        m_autosaveTimer.stop();
2 ✔
371
    else if (m_modified)
1 ✔
UNCOV
372
        m_autosaveTimer.start();
×
373

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

390
    emit modeChanged(m_mode);
3 ✔
391
}
392

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

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

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

408
/*********************************************************************
409
 * Clipboard
410
 *********************************************************************/
411

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

417
/*****************************************************************************
418
 * Fixtures
419
 *****************************************************************************/
420

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

432
    return m_latestFixtureId;
16,766 ✔
433
}
434

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

439
    quint32 i;
440
    quint32 uni = fixture->lastUniverse();
395 ✔
441

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

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

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

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

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

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

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

482
    // Add the fixture channels capabilities to the universe they belong
483
    patchFixtureChannels(fixture);
391 ✔
484

485
    emit fixtureAdded(id);
391 ✔
486
    setModified();
391 ✔
487

488
    return true;
391 ✔
489
}
490

491
void Doc::patchFixtureChannels(Fixture *fixture)
395 ✔
492
{
493
    QList<Universe *> universes = inputOutputMap()->claimUniverses();
395 ✔
494

495
    QList<int> forcedHTP = fixture->forcedHTPChannels();
395 ✔
496
    QList<int> forcedLTP = fixture->forcedLTPChannels();
395 ✔
497

498
    for (quint32 i = 0; i < fixture->channels(); i++)
6,615 ✔
499
    {
500
        const QLCChannel *channel(fixture->channel(i));
6,220 ✔
501
        quint32 absAddress = fixture->channelAddress(i);
6,220 ✔
502

503
        // don't touch the channels of another fixture
504
        if (m_addresses.value(absAddress, fixture->id()) != fixture->id())
6,220 ✔
505
            continue;
4 ✔
506

507
        quint32 uni = absAddress >> 9;
6,216 ✔
508
        quint32 addr = absAddress & 0x01FF;
6,216 ✔
509

510
        // the fixture may not fit in the universe (e.g. address too high)
511
        if (uni >= quint32(universes.count()) || addr >= 512)
6,216 ✔
512
            continue;
×
513

514
        // Inform Universe of any HTP/LTP forcing
515
        if (forcedHTP.contains(int(i)))
6,216 ✔
516
            universes.at(uni)->setChannelCapability(addr, channel->group(), Universe::HTP);
×
517
        else if (forcedLTP.contains(int(i)))
6,216 ✔
518
            universes.at(uni)->setChannelCapability(addr, channel->group(), Universe::LTP);
3 ✔
519
        else
520
            universes.at(uni)->setChannelCapability(addr, channel->group());
6,213 ✔
521

522
        // Apply the default value BEFORE modifiers
523
        universes.at(uni)->setChannelDefaultValue(addr, channel->defaultValue());
6,216 ✔
524

525
        // Apply a channel modifier, if defined
526
        ChannelModifier *mod = fixture->channelModifier(i);
6,216 ✔
527
        universes.at(uni)->setChannelModifier(addr, mod);
6,216 ✔
528
    }
529

530
    inputOutputMap()->releaseUniverses(true);
395 ✔
531
}
395 ✔
532

533
void Doc::unpatchChannels(const QList<quint32> &addresses)
13 ✔
534
{
535
    if (addresses.isEmpty())
13 ✔
536
        return;
2 ✔
537

538
    QList<Universe *> universes = inputOutputMap()->claimUniverses();
11 ✔
539

540
    foreach (quint32 address, addresses)
404 ✔
541
    {
542
        // still (or again) used by a fixture
543
        if (m_addresses.contains(address))
393 ✔
544
            continue;
×
545

546
        quint32 uni = address / 512;
393 ✔
547
        if (uni < quint32(universes.count()))
393 ✔
548
            universes.at(uni)->resetChannelCapability(address % 512);
393 ✔
549
    }
11 ✔
550

551
    inputOutputMap()->releaseUniverses(true);
11 ✔
552
}
11 ✔
553

554
QList<quint32> Doc::fixtureAddresses(quint32 id) const
21 ✔
555
{
556
    QList<quint32> addresses;
21 ✔
557

558
    QHashIterator <quint32, quint32> it(m_addresses);
21 ✔
559
    while (it.hasNext() == true)
528 ✔
560
    {
561
        it.next();
507 ✔
562
        if (it.value() == id)
507 ✔
563
            addresses.append(it.key());
414 ✔
564
    }
565

566
    return addresses;
42 ✔
567
}
21 ✔
568

569
bool Doc::deleteFixture(quint32 id)
15 ✔
570
{
571
    if (m_fixtures.contains(id) == true)
15 ✔
572
    {
573
        Fixture* fxi = m_fixtures.take(id);
9 ✔
574
        Q_ASSERT(fxi != NULL);
9 ✔
575
        m_fixturesListCacheUpToDate = false;
9 ✔
576

577
        /* Keep track of fixture addresses */
578
        QList<quint32> oldAddresses = fixtureAddresses(id);
9 ✔
579
        QMutableHashIterator <uint,uint> it(m_addresses);
9 ✔
580
        while (it.hasNext() == true)
450 ✔
581
        {
582
            it.next();
441 ✔
583
            if (it.value() == id)
441 ✔
584
                it.remove();
384 ✔
585
        }
586

587
        /* The channels are free now: remove their capabilities, default
588
         * values and modifiers, which would otherwise keep affecting the output */
589
        unpatchChannels(oldAddresses);
9 ✔
590
        if (m_monitorProps != NULL)
9 ✔
591
            m_monitorProps->removeFixture(id);
×
592

593
        emit fixtureRemoved(id);
9 ✔
594
        setModified();
9 ✔
595
        delete fxi;
9 ✔
596

597
        if (m_fixtures.count() == 0)
9 ✔
598
            m_latestFixtureId = 0;
3 ✔
599

600
        return true;
9 ✔
601
    }
9 ✔
602
    else
603
    {
604
        qWarning() << Q_FUNC_INFO << "No fixture with id" << id;
6 ✔
605
        return false;
6 ✔
606
    }
607
}
608

609
bool Doc::replaceFixtures(QList<Fixture*> newFixturesList)
6 ✔
610
{
611
    // Delete all fixture instances
612
    QListIterator <quint32> fxit(m_fixtures.keys());
6 ✔
613
    while (fxit.hasNext() == true)
14 ✔
614
    {
615
        Fixture* fxi = m_fixtures.take(fxit.next());
8 ✔
616
        disconnect(fxi, SIGNAL(changed(quint32)),
8 ✔
617
                   this, SLOT(slotFixtureChanged(quint32)));
618
        delete fxi;
8 ✔
619
        m_fixturesListCacheUpToDate = false;
8 ✔
620
    }
621
    m_latestFixtureId = 0;
6 ✔
622
    m_addresses.clear();
6 ✔
623

624
    foreach (Fixture *fixture, newFixturesList)
14 ✔
625
    {
626
        quint32 id = fixture->id();
8 ✔
627
        // create a copy of the original cause remapping will
628
        // destroy it later
629
        Fixture *newFixture = new Fixture(this);
8 ✔
630
        newFixture->setID(id);
8 ✔
631
        newFixture->setName(fixture->name());
8 ✔
632
        newFixture->setAddress(fixture->address());
8 ✔
633
        newFixture->setUniverse(fixture->universe());
8 ✔
634
        newFixture->setCrossUniverse(fixture->crossUniverse());
8 ✔
635

636
        if (fixture->fixtureDef() == NULL ||
18 ✔
637
            (fixture->fixtureDef()->manufacturer() == KXMLFixtureGeneric &&
18 ✔
638
             fixture->fixtureDef()->model() == KXMLFixtureGeneric))
10 ✔
639
        {
640
            // Generic dimmers just need to know the number of channels
641
            newFixture->setChannels(fixture->channels());
2 ✔
642
        }
643
        else if (fixture->fixtureDef() == NULL ||
12 ✔
644
            (fixture->fixtureDef()->manufacturer() == KXMLFixtureGeneric &&
12 ✔
645
             fixture->fixtureDef()->model() == KXMLFixtureRGBPanel))
6 ✔
646
        {
647
            // RGB Panels definitions are not cached or shared, so
648
            // let's make a deep copy of them
649
            QLCFixtureDef *fixtureDef = new QLCFixtureDef();
×
650
            *fixtureDef = *fixture->fixtureDef();
×
651
            QLCFixtureMode *mode = new QLCFixtureMode(fixtureDef);
×
652
            *mode = *fixture->fixtureMode();
×
653
            newFixture->setFixtureDefinition(fixtureDef, mode);
×
654
        }
655
        else
656
        {
657
            QLCFixtureDef *def = fixtureDefCache()->fixtureDef(fixture->fixtureDef()->manufacturer(),
12 ✔
658
                                                               fixture->fixtureDef()->model());
12 ✔
659
            QLCFixtureMode *mode = NULL;
6 ✔
660
            if (def != NULL)
6 ✔
661
                mode = def->mode(fixture->fixtureMode()->name());
1 ✔
662
            newFixture->setFixtureDefinition(def, mode);
6 ✔
663
        }
664

665
        newFixture->setExcludeFadeChannels(fixture->excludeFadeChannels());
8 ✔
666
        newFixture->setForcedHTPChannels(fixture->forcedHTPChannels());
8 ✔
667
        newFixture->setForcedLTPChannels(fixture->forcedLTPChannels());
8 ✔
668

669
        for (quint32 s = 0; s < fixture->channels(); s++)
35 ✔
670
        {
671
            ChannelModifier *chMod = fixture->channelModifier(s);
27 ✔
672
            if (chMod != NULL)
27 ✔
673
                newFixture->setChannelModifier(s, chMod);
×
674
        }
675

676
        m_fixtures.insert(id, newFixture);
8 ✔
677
        m_fixturesListCacheUpToDate = false;
8 ✔
678

679
        /* Patch fixture change signals thru Doc */
680
        connect(newFixture, SIGNAL(changed(quint32)),
8 ✔
681
                this, SLOT(slotFixtureChanged(quint32)));
682

683
        /* Keep track of fixture addresses */
684
        for (quint32 i = 0; i < newFixture->channels(); i++)
20 ✔
685
            m_addresses[newFixture->channelAddress(i)] = id;
12 ✔
686
        m_latestFixtureId = id;
8 ✔
687
    }
6 ✔
688
    return true;
6 ✔
689
}
6 ✔
690

691
bool Doc::updateFixtureChannelCapabilities(quint32 id, QList<int> forcedHTP, QList<int> forcedLTP)
2 ✔
692
{
693
    if (m_fixtures.contains(id) == false)
2 ✔
694
        return false;
1 ✔
695

696
    Fixture* fixture = m_fixtures[id];
1 ✔
697
    // get exclusive access to the universes list
698
    QList<Universe *> universes = inputOutputMap()->claimUniverses();
1 ✔
699

700
    // Set forced HTP channels
701
    fixture->setForcedHTPChannels(forcedHTP);
1 ✔
702

703
    // Set forced LTP channels
704
    fixture->setForcedLTPChannels(forcedLTP);
1 ✔
705

706
    // Update the Fixture Universe with the current channel states
707
    for (quint32 i = 0 ; i < fixture->channels(); i++)
7 ✔
708
    {
709
        const QLCChannel *channel(fixture->channel(i));
6 ✔
710

711
        // a cross-universe fixture may span multiple universes
712
        quint32 absAddress = fixture->channelAddress(i);
6 ✔
713
        quint32 uniIdx = absAddress >> 9;
6 ✔
714
        if (int(uniIdx) >= universes.count())
6 ✔
715
            continue;
×
716

717
        Universe *universe = universes.at(uniIdx);
6 ✔
718
        quint32 addr = absAddress & 0x01FF;
6 ✔
719

720
        // Inform Universe of any HTP/LTP forcing
721
        if (forcedHTP.contains(int(i)))
6 ✔
722
            universe->setChannelCapability(addr, channel->group(), Universe::HTP);
2 ✔
723
        else if (forcedLTP.contains(int(i)))
4 ✔
724
            universe->setChannelCapability(addr, channel->group(), Universe::LTP);
1 ✔
725
        else
726
            universe->setChannelCapability(addr, channel->group());
3 ✔
727

728
        // Apply the default value BEFORE modifiers
729
        universe->setChannelDefaultValue(addr, channel->defaultValue());
6 ✔
730

731
        // Apply a channel modifier, if defined
732
        ChannelModifier *mod = fixture->channelModifier(i);
6 ✔
733
        universe->setChannelModifier(addr, mod);
6 ✔
734
    }
735

736
    inputOutputMap()->releaseUniverses(true);
1 ✔
737

738
    return true;
1 ✔
739
}
1 ✔
740

741
QList<Fixture*> const& Doc::fixtures() const
56 ✔
742
{
743
    if (!m_fixturesListCacheUpToDate)
56 ✔
744
    {
745
        // Sort fixtures by id
746
        QMap <quint32, Fixture*> fixturesMap;
49 ✔
747
        QHashIterator <quint32, Fixture*> hashIt(m_fixtures);
49 ✔
748
        while (hashIt.hasNext())
112 ✔
749
        {
750
            hashIt.next();
63 ✔
751
            fixturesMap.insert(hashIt.key(), hashIt.value());
63 ✔
752
        }
753
        const_cast<QList<Fixture*>&>(m_fixturesListCache) = fixturesMap.values();
49 ✔
754
        const_cast<bool&>(m_fixturesListCacheUpToDate) = true;
49 ✔
755
    }
49 ✔
756
    return m_fixturesListCache;
56 ✔
757
}
758

759
int Doc::fixturesCount() const
×
760
{
761
    return m_fixtures.count();
×
762
}
763

764
Fixture* Doc::fixture(quint32 id) const
61,594 ✔
765
{
766
    return m_fixtures.value(id, NULL);
61,594 ✔
767
}
768

769
quint32 Doc::fixtureForAddress(quint32 universeAddress) const
60,047 ✔
770
{
771
    return m_addresses.value(universeAddress, Fixture::invalidId());
60,047 ✔
772
}
773

774
int Doc::totalPowerConsumption(int& fuzzy) const
4 ✔
775
{
776
    int totalPowerConsumption = 0;
4 ✔
777

778
    // Make sure fuzzy starts from zero
779
    fuzzy = 0;
4 ✔
780

781
    QListIterator <Fixture*> fxit(fixtures());
4 ✔
782
    while (fxit.hasNext() == true)
14 ✔
783
    {
784
        Fixture* fxi(fxit.next());
10 ✔
785
        Q_ASSERT(fxi != NULL);
10 ✔
786

787
        if (fxi->fixtureMode() != NULL)
10 ✔
788
        {
789
            QLCPhysical phys = fxi->fixtureMode()->physical();
10 ✔
790
            if (phys.powerConsumption() > 0)
10 ✔
791
                totalPowerConsumption += phys.powerConsumption();
7 ✔
792
            else
793
                fuzzy++;
3 ✔
794
        }
10 ✔
795
        else
796
        {
797
            fuzzy++;
×
798
        }
799
    }
800

801
    return totalPowerConsumption;
4 ✔
802
}
4 ✔
803

804
void Doc::slotFixtureChanged(quint32 id)
6 ✔
805
{
806
    /* Keep track of fixture addresses */
807
    Fixture* fxi = fixture(id);
6 ✔
808
    QList<quint32> oldAddresses = fixtureAddresses(id);
6 ✔
809

810
    // remove it
811
    QMutableHashIterator <uint,uint> it(m_addresses);
6 ✔
812
    while (it.hasNext() == true)
39 ✔
813
    {
814
        it.next();
33 ✔
815
        if (it.value() == id)
33 ✔
816
        {
817
            qDebug() << Q_FUNC_INFO << " remove: " << it.key() << " val: " << it.value();
15 ✔
818
            it.remove();
15 ✔
819
        }
820
    }
821

822
    for (quint32 ch = 0; ch < fxi->channels(); ch++)
25 ✔
823
    {
824
        /*
825
         * setting new universe and address calls this twice,
826
         * with an tmp wrong address after the first call (old address() + new universe()).
827
         * we only add if the channel is free, to prevent messing up things
828
         */
829
        quint32 i = fxi->channelAddress(ch);
19 ✔
830
        if (m_addresses.contains(i))
19 ✔
831
            continue;
4 ✔
832

833
        m_addresses[i] = id;
15 ✔
834
    }
835

836
    /* If the fixture has been moved (or its channels count changed), the
837
     * universes must follow: free the channels it left and set up the ones
838
     * it now occupies. Other changes (e.g. the name) must not touch them,
839
     * since setting up the channels also resets them to their default value */
840
    QList<quint32> newAddresses = fixtureAddresses(id);
6 ✔
841
    std::sort(oldAddresses.begin(), oldAddresses.end());
6 ✔
842
    std::sort(newAddresses.begin(), newAddresses.end());
6 ✔
843
    if (oldAddresses != newAddresses)
6 ✔
844
    {
845
        QList<quint32> freedAddresses;
4 ✔
846
        foreach (quint32 address, oldAddresses)
13 ✔
847
        {
848
            if (newAddresses.contains(address) == false)
9 ✔
849
                freedAddresses.append(address);
9 ✔
850
        }
4 ✔
851
        unpatchChannels(freedAddresses);
4 ✔
852
        patchFixtureChannels(fxi);
4 ✔
853
    }
4 ✔
854

855
    setModified();
6 ✔
856
    emit fixtureChanged(id);
6 ✔
857
}
6 ✔
858

859
/*****************************************************************************
860
 * Fixture groups
861
 *****************************************************************************/
862

863
bool Doc::addFixtureGroup(FixtureGroup* grp, quint32 id)
17 ✔
864
{
865
    Q_ASSERT(grp != NULL);
17 ✔
866

867
    // No ID given, this method can assign one
868
    if (id == FixtureGroup::invalidId())
17 ✔
869
        id = createFixtureGroupId();
10 ✔
870

871
    if (m_fixtureGroups.contains(id) == true || id == FixtureGroup::invalidId())
17 ✔
872
    {
873
        qWarning() << Q_FUNC_INFO << "a fixture group with ID" << id << "already exists!";
2 ✔
874
        return false;
2 ✔
875
    }
876
    else
877
    {
878
        grp->setId(id);
15 ✔
879
        m_fixtureGroups[id] = grp;
15 ✔
880

881
        /* Patch fixture group change signals thru Doc */
882
        connect(grp, SIGNAL(changed(quint32)),
15 ✔
883
                this, SLOT(slotFixtureGroupChanged(quint32)));
884

885
        emit fixtureGroupAdded(id);
15 ✔
886
        setModified();
15 ✔
887

888
        return true;
15 ✔
889
    }
890
}
891

892
bool Doc::deleteFixtureGroup(quint32 id)
5 ✔
893
{
894
    if (m_fixtureGroups.contains(id) == true)
5 ✔
895
    {
896
        FixtureGroup* grp = m_fixtureGroups.take(id);
3 ✔
897
        Q_ASSERT(grp != NULL);
3 ✔
898

899
        emit fixtureGroupRemoved(id);
3 ✔
900
        setModified();
3 ✔
901
        delete grp;
3 ✔
902

903
        return true;
3 ✔
904
    }
905
    else
906
    {
907
        qWarning() << Q_FUNC_INFO << "No fixture group with id" << id;
2 ✔
908
        return false;
2 ✔
909
    }
910
}
911

912
FixtureGroup* Doc::fixtureGroup(quint32 id) const
61 ✔
913
{
914
    return m_fixtureGroups.value(id, NULL);
61 ✔
915
}
916

917
QList <FixtureGroup*> Doc::fixtureGroups() const
46 ✔
918
{
919
    return m_fixtureGroups.values();
46 ✔
920
}
921

922
quint32 Doc::createFixtureGroupId()
10 ✔
923
{
924
    /* This results in an endless loop if there are UINT_MAX-1 fixture groups. That,
925
       however, seems a bit unlikely. Are there even 4294967295-1 fixtures in
926
       total in the whole world? */
927
    while (m_fixtureGroups.contains(m_latestFixtureGroupId) == true ||
25 ✔
928
           m_latestFixtureGroupId == FixtureGroup::invalidId())
10 ✔
929
    {
930
        m_latestFixtureGroupId++;
5 ✔
931
    }
932

933
    return m_latestFixtureGroupId;
10 ✔
934
}
935

936
void Doc::slotFixtureGroupChanged(quint32 id)
28 ✔
937
{
938
    setModified();
28 ✔
939
    emit fixtureGroupChanged(id);
28 ✔
940
}
28 ✔
941

942
/*********************************************************************
943
 * Channels groups
944
 *********************************************************************/
945
bool Doc::addChannelsGroup(ChannelsGroup *grp, quint32 id)
6 ✔
946
{
947
    Q_ASSERT(grp != NULL);
6 ✔
948

949
    // No ID given, this method can assign one
950
    if (id == ChannelsGroup::invalidId())
6 ✔
951
        id = createChannelsGroupId();
5 ✔
952

953
     grp->setId(id);
6 ✔
954
     m_channelsGroups[id] = grp;
6 ✔
955
     if (m_orderedGroups.contains(id) == false)
6 ✔
956
        m_orderedGroups.append(id);
6 ✔
957

958
     emit channelsGroupAdded(id);
6 ✔
959
     setModified();
6 ✔
960

961
     return true;
6 ✔
962
}
963

964
bool Doc::deleteChannelsGroup(quint32 id)
2 ✔
965
{
966
    if (m_channelsGroups.contains(id) == true)
2 ✔
967
    {
968
        ChannelsGroup* grp = m_channelsGroups.take(id);
1 ✔
969
        Q_ASSERT(grp != NULL);
1 ✔
970

971
        emit channelsGroupRemoved(id);
1 ✔
972
        setModified();
1 ✔
973
        delete grp;
1 ✔
974

975
        int idx = m_orderedGroups.indexOf(id);
1 ✔
976
        if (idx != -1)
1 ✔
977
            m_orderedGroups.takeAt(idx);
1 ✔
978

979
        return true;
1 ✔
980
    }
981
    else
982
    {
983
        qWarning() << Q_FUNC_INFO << "No channels group with id" << id;
1 ✔
984
        return false;
1 ✔
985
    }
986
}
987

988
bool Doc::moveChannelGroup(quint32 id, int direction)
3 ✔
989
{
990
    if (direction == 0 || m_orderedGroups.contains(id) == false)
3 ✔
991
        return false;
1 ✔
992

993
    int idx = m_orderedGroups.indexOf(id);
2 ✔
994

995
    if (idx + direction < 0 || idx + direction >= m_orderedGroups.count())
2 ✔
996
        return false;
1 ✔
997

998
    qDebug() << Q_FUNC_INFO << m_orderedGroups;
1 ✔
999
    m_orderedGroups.takeAt(idx);
1 ✔
1000
    m_orderedGroups.insert(idx + direction, id);
1 ✔
1001
    qDebug() << Q_FUNC_INFO << m_orderedGroups;
1 ✔
1002

1003
    setModified();
1 ✔
1004
    return true;
1 ✔
1005
}
1006

1007
ChannelsGroup* Doc::channelsGroup(quint32 id) const
2 ✔
1008
{
1009
    return m_channelsGroups.value(id, NULL);
2 ✔
1010
}
1011

1012
QList <ChannelsGroup*> Doc::channelsGroups() const
23 ✔
1013
{
1014
    QList <ChannelsGroup*> orderedList;
23 ✔
1015

1016
    for (int i = 0; i < m_orderedGroups.count(); i++)
48 ✔
1017
    {
1018
        orderedList.append(m_channelsGroups[m_orderedGroups.at(i)]);
25 ✔
1019
    }
1020
    return orderedList;
23 ✔
1021
}
×
1022

1023
quint32 Doc::createChannelsGroupId()
5 ✔
1024
{
1025
    while (m_channelsGroups.contains(m_latestChannelsGroupId) == true ||
12 ✔
1026
           m_latestChannelsGroupId == ChannelsGroup::invalidId())
5 ✔
1027
    {
1028
        m_latestChannelsGroupId++;
2 ✔
1029
    }
1030

1031
    return m_latestChannelsGroupId;
5 ✔
1032
}
1033

1034
/*********************************************************************
1035
 * Palettes
1036
 *********************************************************************/
1037

1038
bool Doc::addPalette(QLCPalette *palette, quint32 id)
2 ✔
1039
{
1040
    Q_ASSERT(palette != NULL);
2 ✔
1041

1042
    // No ID given, this method can assign one
1043
    if (id == QLCPalette::invalidId())
2 ✔
1044
        id = createPaletteId();
2 ✔
1045

1046
    if (m_palettes.contains(id) == true || id == QLCPalette::invalidId())
2 ✔
1047
    {
1048
        qWarning() << Q_FUNC_INFO << "a palette with ID" << id << "already exists!";
×
1049
        return false;
×
1050
    }
1051
    else
1052
    {
1053
        palette->setID(id);
2 ✔
1054
        palette->setTemporary(false);
2 ✔
1055
        m_palettes[id] = palette;
2 ✔
1056

1057
        emit paletteAdded(id);
2 ✔
1058
        setModified();
2 ✔
1059
    }
1060

1061
    return true;
2 ✔
1062
}
1063

1064
bool Doc::deletePalette(quint32 id)
3 ✔
1065
{
1066
    if (m_palettes.contains(id) == true)
3 ✔
1067
    {
1068
        QLCPalette *palette = m_palettes.take(id);
2 ✔
1069
        Q_ASSERT(palette != NULL);
2 ✔
1070

1071
        emit paletteRemoved(id);
2 ✔
1072
        setModified();
2 ✔
1073
        delete palette;
2 ✔
1074

1075
        return true;
2 ✔
1076
    }
1077
    else
1078
    {
1079
        qWarning() << Q_FUNC_INFO << "No palette with id" << id;
1 ✔
1080
        return false;
1 ✔
1081
    }
1082
}
1083

1084
QLCPalette *Doc::palette(quint32 id) const
2 ✔
1085
{
1086
    return m_palettes.value(id, NULL);
2 ✔
1087
}
1088

1089
QList<QLCPalette *> Doc::palettes() const
8 ✔
1090
{
1091
    return m_palettes.values();
8 ✔
1092
}
1093

1094
quint32 Doc::createPaletteId()
2 ✔
1095
{
1096
    while (m_palettes.contains(m_latestPaletteId) == true ||
5 ✔
1097
           m_latestPaletteId == FixtureGroup::invalidId())
2 ✔
1098
    {
1099
        m_latestPaletteId++;
1 ✔
1100
    }
1101

1102
    return m_latestPaletteId;
2 ✔
1103
}
1104

1105
/*****************************************************************************
1106
 * Functions
1107
 *****************************************************************************/
1108

1109
quint32 Doc::createFunctionId()
260 ✔
1110
{
1111
    /* This results in an endless loop if there are UINT_MAX-1 functions. That,
1112
       however, seems a bit unlikely. Are there even 4294967295-1 functions in
1113
       total in the whole world? */
1114
    while (m_functions.contains(m_latestFunctionId) == true ||
676 ✔
1115
           m_latestFunctionId == Fixture::invalidId())
260 ✔
1116
    {
1117
        m_latestFunctionId++;
156 ✔
1118
    }
1119

1120
    return m_latestFunctionId;
260 ✔
1121
}
1122

1123
bool Doc::addFunction(Function* func, quint32 id)
273 ✔
1124
{
1125
    Q_ASSERT(func != NULL);
273 ✔
1126

1127
    if (id == Function::invalidId())
273 ✔
1128
        id = createFunctionId();
260 ✔
1129

1130
    if (m_functions.contains(id) == true || id == Fixture::invalidId())
273 ✔
1131
    {
1132
        qWarning() << Q_FUNC_INFO << "a function with ID" << id << "already exists!";
2 ✔
1133
        return false;
2 ✔
1134
    }
1135
    else
1136
    {
1137
        // Listen to function changes
1138
        connect(func, SIGNAL(changed(quint32)),
271 ✔
1139
                this, SLOT(slotFunctionChanged(quint32)));
1140

1141
        // Listen to function name changes
1142
        connect(func, SIGNAL(nameChanged(quint32)),
271 ✔
1143
                this, SLOT(slotFunctionNameChanged(quint32)));
1144

1145
        // Make the function listen to fixture removals
1146
        connect(this, SIGNAL(fixtureRemoved(quint32)),
271 ✔
1147
                func, SLOT(slotFixtureRemoved(quint32)));
1148

1149
        // Place the function in the map and assign it the new ID
1150
        m_functions[id] = func;
271 ✔
1151
        func->setID(id);
271 ✔
1152
        emit functionAdded(id);
271 ✔
1153
        setModified();
271 ✔
1154

1155
        return true;
271 ✔
1156
    }
1157
}
1158

1159
QList <Function*> Doc::functions() const
57 ✔
1160
{
1161
    return m_functions.values();
57 ✔
1162
}
1163

1164
QList<Function *> Doc::functionsByType(Function::Type type) const
1 ✔
1165
{
1166
    QList <Function*> list;
1 ✔
1167
    foreach (Function *f, m_functions)
10 ✔
1168
    {
1169
        if (f != NULL && f->type() == type)
9 ✔
1170
            list.append(f);
5 ✔
1171
    }
1 ✔
1172
    return list;
1 ✔
1173
}
×
1174

1175
Function *Doc::functionByName(QString name)
×
1176
{
1177
    foreach (Function *f, m_functions)
×
1178
    {
1179
        if (f != NULL && f->name() == name)
×
1180
            return f;
×
1181
    }
×
1182
    return NULL;
×
1183
}
1184

1185
bool Doc::deleteFunction(quint32 id)
8 ✔
1186
{
1187
    if (m_functions.contains(id) == true)
8 ✔
1188
    {
1189
        Function* func = m_functions.take(id);
6 ✔
1190
        Q_ASSERT(func != NULL);
6 ✔
1191

1192
        if (m_startupFunctionId == id)
6 ✔
1193
            m_startupFunctionId = Function::invalidId();
×
1194

1195
        emit functionRemoved(id);
6 ✔
1196
        setModified();
6 ✔
1197
        delete func;
6 ✔
1198

1199
        return true;
6 ✔
1200
    }
1201
    else
1202
    {
1203
        qWarning() << Q_FUNC_INFO << "No function with id" << id;
2 ✔
1204
        return false;
2 ✔
1205
    }
1206
}
1207

1208
Function* Doc::function(quint32 id) const
921 ✔
1209
{
1210
    return m_functions.value(id, NULL);
921 ✔
1211
}
1212

1213
quint32 Doc::nextFunctionID() const
2 ✔
1214
{
1215
    quint32 tmpFID = m_latestFunctionId;
2 ✔
1216
    while (m_functions.contains(tmpFID) == true ||
5 ✔
1217
           tmpFID == Fixture::invalidId())
2 ✔
1218
    {
1219
        tmpFID++;
1 ✔
1220
    }
1221

1222
    return tmpFID;
2 ✔
1223
}
1224

1225
void Doc::setStartupFunction(quint32 fid)
1 ✔
1226
{
1227
    m_startupFunctionId = fid;
1 ✔
1228
}
1 ✔
1229

1230
quint32 Doc::startupFunction() const
2 ✔
1231
{
1232
    return m_startupFunctionId;
2 ✔
1233
}
1234

1235
QList<quint32> Doc::getUsage(quint32 fid)
7 ✔
1236
{
1237
    QList<quint32> usageList;
7 ✔
1238

1239
    foreach (Function *f, m_functions)
70 ✔
1240
    {
1241
        if (f->id() == fid)
63 ✔
1242
            continue;
6 ✔
1243

1244
        switch(f->type())
57 ✔
1245
        {
1246
            case Function::CollectionType:
7 ✔
1247
            {
1248
                Collection *c = qobject_cast<Collection *>(f);
7 ✔
1249
                int pos = c->functions().indexOf(fid);
7 ✔
1250
                if (pos != -1)
7 ✔
1251
                {
1252
                    usageList.append(f->id());
2 ✔
1253
                    usageList.append(pos);
2 ✔
1254
                }
1255
            }
1256
            break;
7 ✔
1257
            case Function::ChaserType:
6 ✔
1258

1259
            {
1260
                Chaser *c = qobject_cast<Chaser *>(f);
6 ✔
1261
                for (int i = 0; i < c->stepsCount(); i++)
18 ✔
1262
                {
1263
                    ChaserStep *cs = c->stepAt(i);
12 ✔
1264
                    if (cs->fid == fid)
12 ✔
1265
                    {
1266
                        usageList.append(f->id());
2 ✔
1267
                        usageList.append(i);
2 ✔
1268
                    }
1269
                }
1270
            }
1271
            break;
6 ✔
1272
            case Function::SequenceType:
7 ✔
1273
            {
1274
                Sequence *s = qobject_cast<Sequence *>(f);
7 ✔
1275
                if (s->boundSceneID() == fid)
7 ✔
1276
                {
1277
                    usageList.append(f->id());
1 ✔
1278
                    usageList.append(0);
1 ✔
1279
                }
1280
            }
1281
            break;
7 ✔
1282
            case Function::ScriptType:
7 ✔
1283
            {
1284
                Script *s = qobject_cast<Script *>(f);
7 ✔
1285
                QList<quint32> l = s->functionList();
7 ✔
1286
                for (int i = 0; i < l.count(); i+=2)
14 ✔
1287
                {
1288
                    if (l.at(i) == fid)
7 ✔
1289
                    {
1290
                        if (i + 1 >= l.count()) {
1 ✔
1291
                            qDebug() << "Doc::getUsage: Index entry missing on " << f->name();
×
1292
                            break;
×
1293
                        }
1294
                        usageList.append(s->id());
1 ✔
1295
                        usageList.append(l.at(i + 1)); // line number
1 ✔
1296
                    }
1297
                }
1298
            }
7 ✔
1299
            break;
7 ✔
1300
            case Function::ShowType:
×
1301
            {
1302
                Show *s = qobject_cast<Show *>(f);
×
1303
                foreach (Track *t, s->tracks())
×
1304
                {
1305
                    foreach (ShowFunction *sf, t->showFunctions())
×
1306
                    {
1307
                        if (sf->functionID() == fid)
×
1308
                        {
1309
                            usageList.append(f->id());
×
1310
                            usageList.append(t->id());
×
1311
                        }
1312
                    }
×
1313
                }
×
1314
            }
1315
            break;
×
1316
            default:
30 ✔
1317
            break;
30 ✔
1318
        }
1319
    }
7 ✔
1320

1321
    return usageList;
7 ✔
1322
}
×
1323

1324
void Doc::slotFunctionChanged(quint32 fid)
65 ✔
1325
{
1326
    setModified();
65 ✔
1327
    emit functionChanged(fid);
65 ✔
1328
}
65 ✔
1329

1330
void Doc::slotFunctionNameChanged(quint32 fid)
2 ✔
1331
{
1332
    setModified();
2 ✔
1333
    emit functionNameChanged(fid);
2 ✔
1334
}
2 ✔
1335

1336
/*********************************************************************
1337
 * Monitor Properties
1338
 *********************************************************************/
1339

1340
MonitorProperties *Doc::monitorProperties()
44 ✔
1341
{
1342
    if (m_monitorProps == NULL)
44 ✔
1343
        m_monitorProps = new MonitorProperties();
10 ✔
1344

1345
    return m_monitorProps;
44 ✔
1346
}
1347

1348
/*****************************************************************************
1349
 * Load & Save
1350
 *****************************************************************************/
1351

1352
bool Doc::loadXML(QXmlStreamReader &doc, bool loadIO)
2 ✔
1353
{
1354
    clearErrorLog();
2 ✔
1355

1356
    if (doc.name() != KXMLQLCEngine)
2 ✔
1357
    {
1358
        qWarning() << Q_FUNC_INFO << "Engine node not found";
1 ✔
1359
        return false;
1 ✔
1360
    }
1361

1362
    m_loadStatus = Loading;
1 ✔
1363
    emit loading();
1 ✔
1364

1365
    if (doc.attributes().hasAttribute(KXMLQLCStartupFunction))
2 ✔
1366
    {
1367
        quint32 sID = doc.attributes().value(KXMLQLCStartupFunction).toString().toUInt();
×
1368
        if (sID != Function::invalidId())
×
1369
            setStartupFunction(sID);
×
1370
    }
1371

1372
    while (doc.readNextStartElement())
17 ✔
1373
    {
1374
        //qDebug() << "Doc tag:" << doc.name();
1375
        if (doc.name() == KXMLFixture)
16 ✔
1376
        {
1377
            Fixture::loader(doc, this);
3 ✔
1378
        }
1379
        else if (doc.name() == KXMLQLCFixtureGroup)
13 ✔
1380
        {
1381
            FixtureGroup::loader(doc, this);
3 ✔
1382
        }
1383
        else if (doc.name() == KXMLQLCChannelsGroup)
10 ✔
1384
        {
1385
            ChannelsGroup::loader(doc, this);
×
1386
        }
1387
        else if (doc.name() == KXMLQLCPalette)
10 ✔
1388
        {
1389
            QLCPalette::loader(doc, this);
×
1390
            doc.skipCurrentElement();
×
1391
        }
1392
        else if (doc.name() == KXMLQLCFunction)
10 ✔
1393
        {
1394
            //qDebug() << doc.attributes().value("Name").toString();
1395
            Function::loader(doc, this);
4 ✔
1396
        }
1397
        else if (doc.name() == KXMLQLCBus)
6 ✔
1398
        {
1399
            /* LEGACY */
1400
            Bus::instance()->loadXML(doc);
5 ✔
1401
        }
1402
        else if (doc.name() == KXMLIOMap && loadIO)
2 ✔
1403
        {
1404
            m_ioMap->loadXML(doc);
×
1405
        }
1406
        else if (doc.name() == KXMLQLCMonitorProperties)
1 ✔
1407
        {
1408
            monitorProperties()->loadXML(doc, this);
×
1409
        }
1410
        else
1411
        {
1412
            qWarning() << Q_FUNC_INFO << "Unknown engine tag:" << doc.name();
1 ✔
1413
            doc.skipCurrentElement();
1 ✔
1414
        }
1415
    }
1416

1417
    postLoad();
1 ✔
1418

1419
    m_loadStatus = Loaded;
1 ✔
1420
    emit loaded();
1 ✔
1421

1422
    return true;
1 ✔
1423
}
1424

1425
bool Doc::saveXML(QXmlStreamWriter *doc) const
1 ✔
1426
{
1427
    Q_ASSERT(doc != NULL);
1 ✔
1428

1429
    /* Create the master Engine node */
1430
    doc->writeStartElement(KXMLQLCEngine);
2 ✔
1431

1432
    if (startupFunction() != Function::invalidId())
1 ✔
1433
        doc->writeAttribute(KXMLQLCStartupFunction, QString::number(startupFunction()));
×
1434

1435
    m_ioMap->saveXML(doc);
1 ✔
1436

1437
    /* Write fixtures into an XML document */
1438
    QListIterator <Fixture*> fxit(fixtures());
1 ✔
1439
    while (fxit.hasNext() == true)
4 ✔
1440
    {
1441
        Fixture *fxi(fxit.next());
3 ✔
1442
        if (fxi != NULL)
3 ✔
1443
            fxi->saveXML(doc);
3 ✔
1444
    }
1445

1446
    /* Write fixture groups into an XML document */
1447
    QListIterator <FixtureGroup*> grpit(fixtureGroups());
1 ✔
1448
    while (grpit.hasNext() == true)
3 ✔
1449
    {
1450
        FixtureGroup *grp(grpit.next());
2 ✔
1451
        if (grp != NULL)
2 ✔
1452
            grp->saveXML(doc);
2 ✔
1453
    }
1454

1455
    /* Write channel groups into an XML document */
1456
    QListIterator <ChannelsGroup*> chanGroups(channelsGroups());
1 ✔
1457
    while (chanGroups.hasNext() == true)
1 ✔
1458
    {
1459
        ChannelsGroup *grp(chanGroups.next());
×
1460
        if (grp != NULL)
×
1461
            grp->saveXML(doc);
×
1462
    }
1463

1464
    /* Write palettes into an XML document */
1465
    QListIterator <QLCPalette*> paletteIt(palettes());
1 ✔
1466
    while (paletteIt.hasNext() == true)
1 ✔
1467
    {
1468
        QLCPalette *palette(paletteIt.next());
×
1469
        if (palette != NULL)
×
1470
            palette->saveXML(doc);
×
1471
    }
1472

1473
    /* Write functions into an XML document */
1474
    QListIterator <Function*> funcit(functions());
1 ✔
1475
    while (funcit.hasNext() == true)
5 ✔
1476
    {
1477
        Function *func(funcit.next());
4 ✔
1478
        if (func != NULL)
4 ✔
1479
            func->saveXML(doc);
4 ✔
1480
    }
1481

1482
    if (m_monitorProps != NULL)
1 ✔
1483
        m_monitorProps->saveXML(doc, this);
1 ✔
1484

1485
    /* End the <Engine> tag */
1486
    doc->writeEndElement();
1 ✔
1487

1488
    return true;
1 ✔
1489
}
1 ✔
1490

1491
void Doc::appendToErrorLog(QString error)
8 ✔
1492
{
1493
    if (m_errorLog.contains(error))
8 ✔
1494
        return;
5 ✔
1495

1496
    m_errorLog.append(error);
3 ✔
1497
    m_errorLog.append("<br>");
3 ✔
1498
}
1499

1500
void Doc::clearErrorLog()
2 ✔
1501
{
1502
    m_errorLog = "";
2 ✔
1503
}
2 ✔
1504

1505
QString Doc::errorLog() const
1 ✔
1506
{
1507
    return m_errorLog;
1 ✔
1508
}
1509

1510
void Doc::postLoad()
1 ✔
1511
{
1512
    QListIterator <Function*> functionit(functions());
1 ✔
1513
    while (functionit.hasNext() == true)
5 ✔
1514
    {
1515
        Function* function(functionit.next());
4 ✔
1516
        Q_ASSERT(function != NULL);
4 ✔
1517
        function->postLoad();
4 ✔
1518
    }
1519
}
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