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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

92.92
/engine/src/qlcphysical.cpp
1
/*
2
  Q Light Controller Plus
3
  qlcphysical.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 <QRegularExpression>
23
#include <QLocale>
24
#include <QString>
25
#include <QDebug>
26

27
#include "qlcphysical.h"
28

29
/****************************************************************************
30
 * Initialization
31
 ****************************************************************************/
32

33
QLCPhysical::QLCPhysical()
80,634✔
34
    : m_bulbLumens(0)
80,634✔
35
    , m_bulbColourTemperature(0)
80,634✔
36
    , m_weight(0)
80,634✔
37
    , m_width(0)
80,634✔
38
    , m_height(0)
80,634✔
39
    , m_depth(0)
80,634✔
40
    , m_lensDegreesMin(0)
80,634✔
41
    , m_lensDegreesMax(0)
80,634✔
42
    , m_focusPanMax(0)
80,634✔
43
    , m_focusTiltMax(0)
80,634✔
44
    , m_layout(QSize(1, 1))
80,634✔
45
    , m_powerConsumption(0)
161,268✔
46

47
{
48
    m_lensName = "Other";
80,634✔
49
    m_focusType = "Fixed";
80,634✔
50
    m_dmxConnector = "5-pin";
80,634✔
51
}
80,634✔
52

53
QLCPhysical::~QLCPhysical()
80,222✔
54
{
55
}
80,222✔
56

57
QLCPhysical::QLCPhysical(const QLCPhysical &other)
67✔
58
{
59
    *this = other;
67✔
60
}
67✔
61

62
QLCPhysical& QLCPhysical::operator=(const QLCPhysical& physical)
370✔
63
{
64
    if (this != &physical)
370✔
65
    {
66
        m_bulbType = physical.bulbType();
370✔
67
        m_bulbLumens = physical.bulbLumens();
370✔
68
        m_bulbColourTemperature = physical.bulbColourTemperature();
370✔
69

70
        m_weight = physical.weight();
370✔
71
        m_width = physical.width();
370✔
72
        m_height = physical.height();
370✔
73
        m_depth = physical.depth();
370✔
74

75
        m_lensName = physical.lensName();
370✔
76
        m_lensDegreesMin = physical.lensDegreesMin();
370✔
77
        m_lensDegreesMax = physical.lensDegreesMax();
370✔
78

79
        m_focusType = physical.focusType();
370✔
80
        m_focusPanMax = physical.focusPanMax();
370✔
81
        m_focusTiltMax = physical.focusTiltMax();
370✔
82
        m_layout = physical.layoutSize();
370✔
83

84
        m_powerConsumption = physical.powerConsumption();
370✔
85
        m_dmxConnector = physical.dmxConnector();
370✔
86
    }
87

88
    return *this;
370✔
89
}
90

91
bool QLCPhysical::isEmpty() const
×
92
{
93
    if (m_bulbLumens == 0 &&
×
94
        m_bulbColourTemperature == 0 &&
×
95
        m_weight == 0 &&
×
96
        m_width == 0 &&
×
97
        m_height == 0 &&
×
98
        m_depth == 0 &&
×
99
        m_lensDegreesMin == 0 &&
×
100
        m_lensDegreesMax == 0 &&
×
101
        m_focusPanMax == 0 &&
×
102
        m_focusTiltMax == 0 &&
×
103
        m_powerConsumption == 0)
×
104
        return true;
×
105

106
    return false;
×
107
}
108

109
/****************************************************************************
110
 * Properties
111
 ****************************************************************************/
112

113
void QLCPhysical::setBulbType(const QString& type)
2✔
114
{
115
    m_bulbType = type;
2✔
116
}
2✔
117

118
QString QLCPhysical::bulbType() const
650✔
119
{
120
    return m_bulbType;
650✔
121
}
122

123
void QLCPhysical::setBulbLumens(int lumens)
1✔
124
{
125
    m_bulbLumens = lumens;
1✔
126
}
1✔
127

128
int QLCPhysical::bulbLumens() const
379✔
129
{
130
    return m_bulbLumens;
379✔
131
}
132

133
void QLCPhysical::setBulbColourTemperature(int temp)
1✔
134
{
135
    m_bulbColourTemperature = temp;
1✔
136
}
1✔
137

138
int QLCPhysical::bulbColourTemperature() const
379✔
139
{
140
    return m_bulbColourTemperature;
379✔
141
}
142

143
void QLCPhysical::setWeight(double weight)
3✔
144
{
145
    m_weight = weight;
3✔
146
}
3✔
147

148
double QLCPhysical::weight() const
380✔
149
{
150
    return m_weight;
380✔
151
}
152

153
void QLCPhysical::setWidth(int width)
244✔
154
{
155
    m_width = width;
244✔
156
}
244✔
157

158
int QLCPhysical::width() const
380✔
159
{
160
    return m_width;
380✔
161
}
162

163
void QLCPhysical::setHeight(int height)
244✔
164
{
165
    m_height = height;
244✔
166
}
244✔
167

168
int QLCPhysical::height() const
380✔
169
{
170
    return m_height;
380✔
171
}
172

173
void QLCPhysical::setDepth(int depth)
244✔
174
{
175
    m_depth = depth;
244✔
176
}
244✔
177

178
int QLCPhysical::depth() const
380✔
179
{
180
    return m_depth;
380✔
181
}
182

183
void QLCPhysical::setLensName(const QString& name)
1✔
184
{
185
    m_lensName = name;
1✔
186
}
1✔
187

188
QString QLCPhysical::lensName() const
377✔
189
{
190
    return m_lensName;
377✔
191
}
192

193
void QLCPhysical::setLensDegreesMin(double degrees)
1✔
194
{
195
    m_lensDegreesMin = degrees;
1✔
196
}
1✔
197

198
double QLCPhysical::lensDegreesMin() const
379✔
199
{
200
    return m_lensDegreesMin;
379✔
201
}
202

203
void QLCPhysical::setLensDegreesMax(double degrees)
1✔
204
{
205
    m_lensDegreesMax = degrees;
1✔
206
}
1✔
207

208
double QLCPhysical::lensDegreesMax() const
377✔
209
{
210
    return m_lensDegreesMax;
377✔
211
}
212

213
void QLCPhysical::setFocusType(const QString& type)
1✔
214
{
215
    m_focusType = type;
1✔
216
}
1✔
217

218
QString QLCPhysical::focusType() const
377✔
219
{
220
    return m_focusType;
377✔
221
}
222

223
void QLCPhysical::setFocusPanMax(int pan)
1✔
224
{
225
    m_focusPanMax = pan;
1✔
226
}
1✔
227

228
int QLCPhysical::focusPanMax() const
401✔
229
{
230
    return m_focusPanMax;
401✔
231
}
232

233
void QLCPhysical::setFocusTiltMax(int tilt)
1✔
234
{
235
    m_focusTiltMax = tilt;
1✔
236
}
1✔
237

238
int QLCPhysical::focusTiltMax() const
401✔
239
{
240
    return m_focusTiltMax;
401✔
241
}
242

243
void QLCPhysical::setLayoutSize(QSize size)
22✔
244
{
245
    m_layout = size;
22✔
246
}
22✔
247

248
QSize QLCPhysical::layoutSize() const
377✔
249
{
250
    return m_layout;
377✔
251
}
252

253
void QLCPhysical::setPowerConsumption(int watt)
1✔
254
{
255
    m_powerConsumption = watt;
1✔
256
}
1✔
257

258
int QLCPhysical::powerConsumption() const
396✔
259
{
260
    if (m_powerConsumption != 0)
396✔
261
    {
262
        return m_powerConsumption;
127✔
263
    }
264
    else
265
    {
266
        /* If power consumption value is missing, return bulb watts
267
         * plus a guesstimate 100W, since there's usually other
268
          * electronics consuming power as well. */
269
        int bulbWatts = bulbType().remove(QRegularExpression("[A-Z]*")).toInt();
269✔
270
        if (bulbWatts > 0)
269✔
271
            return bulbWatts + 100;
×
272
        else
273
            return 0;
269✔
274
    }
275
}
276

277
void QLCPhysical::setDmxConnector(const QString& type)
1✔
278
{
279
    m_dmxConnector = type;
1✔
280
}
1✔
281

282
QString QLCPhysical::dmxConnector() const
377✔
283
{
284
    return m_dmxConnector;
377✔
285
}
286

287
/****************************************************************************
288
 * Load & Save
289
 ****************************************************************************/
290

291
bool QLCPhysical::loadXML(QXmlStreamReader &doc)
58✔
292
{
293
    if (doc.name() != KXMLQLCPhysical)
58✔
294
    {
295
        qWarning() << Q_FUNC_INFO << "Physical node not found";
1✔
296
        return false;
1✔
297
    }
298

299
    /* Subtags */
300
    while (doc.readNextStartElement())
352✔
301
    {
302
        QXmlStreamAttributes attrs = doc.attributes();
295✔
303
        if (doc.name() == KXMLQLCPhysicalBulb)
295✔
304
        {
305
            m_bulbType = attrs.value(KXMLQLCPhysicalBulbType).toString();
57✔
306
            m_bulbLumens = attrs.value(KXMLQLCPhysicalBulbLumens).toString().toInt();
57✔
307
            m_bulbColourTemperature = attrs.value(KXMLQLCPhysicalBulbColourTemperature).toString().toInt();
57✔
308
        }
309
        else if (doc.name() == KXMLQLCPhysicalDimensions)
238✔
310
        {
311
            m_weight = QLocale::c().toDouble(attrs.value(KXMLQLCPhysicalDimensionsWeight).toString());
112✔
312
            m_width = attrs.value(KXMLQLCPhysicalDimensionsWidth).toString().toInt();
56✔
313
            m_height = attrs.value(KXMLQLCPhysicalDimensionsHeight).toString().toInt();
56✔
314
            m_depth = attrs.value(KXMLQLCPhysicalDimensionsDepth).toString().toInt();
56✔
315
        }
316
        else if (doc.name() == KXMLQLCPhysicalLens)
182✔
317
        {
318
            m_lensName = attrs.value(KXMLQLCPhysicalLensName).toString();
56✔
319
            m_lensDegreesMin = QLocale::c().toDouble(attrs.value(KXMLQLCPhysicalLensDegreesMin).toString());
112✔
320
            m_lensDegreesMax = QLocale::c().toDouble(attrs.value(KXMLQLCPhysicalLensDegreesMax).toString());
112✔
321
        }
322
        else if (doc.name() == KXMLQLCPhysicalFocus)
126✔
323
        {
324
            m_focusType = attrs.value(KXMLQLCPhysicalFocusType).toString();
56✔
325
            m_focusPanMax = attrs.value(KXMLQLCPhysicalFocusPanMax).toString().toInt();
56✔
326
            m_focusTiltMax = attrs.value(KXMLQLCPhysicalFocusTiltMax).toString().toInt();
56✔
327
        }
328
        else if (doc.name() == KXMLQLCPhysicalLayout)
70✔
329
        {
330
            int columns = 1, rows = 1;
13✔
331
            if (attrs.hasAttribute(KXMLQLCPhysicalDimensionsWidth))
13✔
332
                columns = attrs.value(KXMLQLCPhysicalDimensionsWidth).toString().toInt();
13✔
333
            if (attrs.hasAttribute(KXMLQLCPhysicalDimensionsHeight))
13✔
334
                rows = attrs.value(KXMLQLCPhysicalDimensionsHeight).toString().toInt();
13✔
335
            setLayoutSize(QSize(columns, rows));
13✔
336
        }
337
        else if (doc.name() == KXMLQLCPhysicalTechnical)
57✔
338
        {
339
            m_powerConsumption = attrs.value(KXMLQLCPhysicalTechnicalPowerConsumption).toString().toInt();
56✔
340
            m_dmxConnector = attrs.value(KXMLQLCPhysicalTechnicalDmxConnector).toString();
56✔
341
        }
342
        else
343
        {
344
            qWarning() << Q_FUNC_INFO << "Unknown Physical tag:" << doc.name();
1✔
345
        }
346
        doc.skipCurrentElement();
295✔
347
    }
295✔
348

349
    return true;
57✔
350
}
351

352
bool QLCPhysical::saveXML(QXmlStreamWriter *doc)
3✔
353
{
354
    Q_ASSERT(doc != NULL);
3✔
355

356
    /* Physical entry */
357
    doc->writeStartElement(KXMLQLCPhysical);
6✔
358

359
    /* Bulb */
360
    doc->writeStartElement(KXMLQLCPhysicalBulb);
6✔
361
    doc->writeAttribute(KXMLQLCPhysicalBulbType, m_bulbType);
6✔
362
    doc->writeAttribute(KXMLQLCPhysicalBulbLumens, QString::number(m_bulbLumens));
6✔
363
    doc->writeAttribute(KXMLQLCPhysicalBulbColourTemperature, QString::number(m_bulbColourTemperature));
6✔
364
    doc->writeEndElement();
3✔
365

366
    /* Dimensions */
367
    doc->writeStartElement(KXMLQLCPhysicalDimensions);
6✔
368
    doc->writeAttribute(KXMLQLCPhysicalDimensionsWeight, QLocale::c().toString(m_weight));
6✔
369
    doc->writeAttribute(KXMLQLCPhysicalDimensionsWidth, QString::number(m_width));
6✔
370
    doc->writeAttribute(KXMLQLCPhysicalDimensionsHeight, QString::number(m_height));
6✔
371
    doc->writeAttribute(KXMLQLCPhysicalDimensionsDepth, QString::number(m_depth));
6✔
372
    doc->writeEndElement();
3✔
373

374
    /* Lens */
375
    doc->writeStartElement(KXMLQLCPhysicalLens);
6✔
376
    doc->writeAttribute(KXMLQLCPhysicalLensName, m_lensName);
6✔
377
    doc->writeAttribute(KXMLQLCPhysicalLensDegreesMin, QLocale::c().toString(m_lensDegreesMin));
6✔
378
    doc->writeAttribute(KXMLQLCPhysicalLensDegreesMax, QLocale::c().toString(m_lensDegreesMax));
6✔
379
    doc->writeEndElement();
3✔
380

381
    /* Focus */
382
    doc->writeStartElement(KXMLQLCPhysicalFocus);
6✔
383
    doc->writeAttribute(KXMLQLCPhysicalFocusType, m_focusType);
6✔
384
    doc->writeAttribute(KXMLQLCPhysicalFocusPanMax, QString::number(m_focusPanMax));
6✔
385
    doc->writeAttribute(KXMLQLCPhysicalFocusTiltMax, QString::number(m_focusTiltMax));
6✔
386
    doc->writeEndElement();
3✔
387

388
    /* Layout */
389
    if (layoutSize() != QSize(1, 1))
3✔
390
    {
391
        doc->writeStartElement(KXMLQLCPhysicalLayout);
2✔
392
        doc->writeAttribute(KXMLQLCPhysicalDimensionsWidth, QString::number(m_layout.width()));
2✔
393
        doc->writeAttribute(KXMLQLCPhysicalDimensionsHeight, QString::number(m_layout.height()));
2✔
394
        doc->writeEndElement();
1✔
395
    }
396

397
    /* Technical */
398
    doc->writeStartElement(KXMLQLCPhysicalTechnical);
6✔
399
    doc->writeAttribute(KXMLQLCPhysicalTechnicalPowerConsumption, QString::number(m_powerConsumption));
6✔
400
    doc->writeAttribute(KXMLQLCPhysicalTechnicalDmxConnector, m_dmxConnector);
6✔
401
    doc->writeEndElement();
3✔
402

403
    doc->writeEndElement();
3✔
404

405
    return true;
3✔
406
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc