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

mcallegari / qlcplus / 21760395819

06 Feb 2026 05:52PM UTC coverage: 33.994% (-0.08%) from 34.078%
21760395819

push

github

mcallegari
Back to 5.2.1 debug

17635 of 51877 relevant lines covered (33.99%)

19809.79 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()
82,599✔
34
    : m_bulbLumens(0)
82,599✔
35
    , m_bulbColourTemperature(0)
82,599✔
36
    , m_weight(0)
82,599✔
37
    , m_width(0)
82,599✔
38
    , m_height(0)
82,599✔
39
    , m_depth(0)
82,599✔
40
    , m_lensName("Other")
82,599✔
41
    , m_lensDegreesMin(0)
82,599✔
42
    , m_lensDegreesMax(0)
82,599✔
43
    , m_focusType("Fixed")
82,599✔
44
    , m_focusPanMax(0)
82,599✔
45
    , m_focusTiltMax(0)
82,599✔
46
    , m_layout(QSize(1, 1))
82,599✔
47
    , m_powerConsumption(0)
82,599✔
48
    , m_dmxConnector("5-pin")
165,198✔
49
{
50
}
82,599✔
51

52
QLCPhysical::~QLCPhysical()
82,186✔
53
{
54
}
82,186✔
55

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

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

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

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

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

83
        m_powerConsumption = physical.powerConsumption();
369✔
84
        m_dmxConnector = physical.dmxConnector();
369✔
85
    }
86

87
    return *this;
369✔
88
}
89

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

105
    return false;
×
106
}
107

108
/****************************************************************************
109
 * Properties
110
 ****************************************************************************/
111

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

348
    return true;
57✔
349
}
350

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

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

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

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

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

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

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

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

402
    doc->writeEndElement();
3✔
403

404
    return true;
3✔
405
}
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