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

mcallegari / qlcplus / 22831302206

08 Mar 2026 10:26PM UTC coverage: 33.973% (+0.002%) from 33.971%
22831302206

Pull #1974

github

web-flow
Merge 4cabf63f2 into b399c6226
Pull Request #1974: more code improvements

114 of 237 new or added lines in 63 files covered. (48.1%)

1 existing line in 1 file now uncovered.

17651 of 51956 relevant lines covered (33.97%)

19779.77 hits per line

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

93.81
/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
{
NEW
92
    return (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 &&
×
NEW
102
        m_powerConsumption == 0);
×
103
}
104

105
/****************************************************************************
106
 * Properties
107
 ****************************************************************************/
108

109
void QLCPhysical::setBulbType(const QString& type)
2✔
110
{
111
    m_bulbType = type;
2✔
112
}
2✔
113

114
QString QLCPhysical::bulbType() const
646✔
115
{
116
    return m_bulbType;
646✔
117
}
118

119
void QLCPhysical::setBulbLumens(int lumens)
1✔
120
{
121
    m_bulbLumens = lumens;
1✔
122
}
1✔
123

124
int QLCPhysical::bulbLumens() const
376✔
125
{
126
    return m_bulbLumens;
376✔
127
}
128

129
void QLCPhysical::setBulbColourTemperature(int temp)
1✔
130
{
131
    m_bulbColourTemperature = temp;
1✔
132
}
1✔
133

134
int QLCPhysical::bulbColourTemperature() const
376✔
135
{
136
    return m_bulbColourTemperature;
376✔
137
}
138

139
void QLCPhysical::setWeight(double weight)
3✔
140
{
141
    m_weight = weight;
3✔
142
}
3✔
143

144
double QLCPhysical::weight() const
375✔
145
{
146
    return m_weight;
375✔
147
}
148

149
void QLCPhysical::setWidth(int width)
243✔
150
{
151
    m_width = width;
243✔
152
}
243✔
153

154
int QLCPhysical::width() const
375✔
155
{
156
    return m_width;
375✔
157
}
158

159
void QLCPhysical::setHeight(int height)
243✔
160
{
161
    m_height = height;
243✔
162
}
243✔
163

164
int QLCPhysical::height() const
375✔
165
{
166
    return m_height;
375✔
167
}
168

169
void QLCPhysical::setDepth(int depth)
243✔
170
{
171
    m_depth = depth;
243✔
172
}
243✔
173

174
int QLCPhysical::depth() const
375✔
175
{
176
    return m_depth;
375✔
177
}
178

179
void QLCPhysical::setLensName(const QString& name)
1✔
180
{
181
    m_lensName = name;
1✔
182
}
1✔
183

184
QString QLCPhysical::lensName() const
374✔
185
{
186
    return m_lensName;
374✔
187
}
188

189
void QLCPhysical::setLensDegreesMin(double degrees)
1✔
190
{
191
    m_lensDegreesMin = degrees;
1✔
192
}
1✔
193

194
double QLCPhysical::lensDegreesMin() const
374✔
195
{
196
    return m_lensDegreesMin;
374✔
197
}
198

199
void QLCPhysical::setLensDegreesMax(double degrees)
1✔
200
{
201
    m_lensDegreesMax = degrees;
1✔
202
}
1✔
203

204
double QLCPhysical::lensDegreesMax() const
374✔
205
{
206
    return m_lensDegreesMax;
374✔
207
}
208

209
void QLCPhysical::setFocusType(const QString& type)
1✔
210
{
211
    m_focusType = type;
1✔
212
}
1✔
213

214
QString QLCPhysical::focusType() const
374✔
215
{
216
    return m_focusType;
374✔
217
}
218

219
void QLCPhysical::setFocusPanMax(int pan)
1✔
220
{
221
    m_focusPanMax = pan;
1✔
222
}
1✔
223

224
int QLCPhysical::focusPanMax() const
398✔
225
{
226
    return m_focusPanMax;
398✔
227
}
228

229
void QLCPhysical::setFocusTiltMax(int tilt)
1✔
230
{
231
    m_focusTiltMax = tilt;
1✔
232
}
1✔
233

234
int QLCPhysical::focusTiltMax() const
398✔
235
{
236
    return m_focusTiltMax;
398✔
237
}
238

239
void QLCPhysical::setLayoutSize(QSize size)
22✔
240
{
241
    m_layout = size;
22✔
242
}
22✔
243

244
QSize QLCPhysical::layoutSize() const
374✔
245
{
246
    return m_layout;
374✔
247
}
248

249
void QLCPhysical::setPowerConsumption(int watt)
1✔
250
{
251
    m_powerConsumption = watt;
1✔
252
}
1✔
253

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

273
void QLCPhysical::setDmxConnector(const QString& type)
1✔
274
{
275
    m_dmxConnector = type;
1✔
276
}
1✔
277

278
QString QLCPhysical::dmxConnector() const
374✔
279
{
280
    return m_dmxConnector;
374✔
281
}
282

283
/****************************************************************************
284
 * Load & Save
285
 ****************************************************************************/
286

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

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

345
    return true;
57✔
346
}
347

348
bool QLCPhysical::saveXML(QXmlStreamWriter *doc) const
3✔
349
{
350
    Q_ASSERT(doc != NULL);
3✔
351

352
    /* Physical entry */
353
    doc->writeStartElement(KXMLQLCPhysical);
6✔
354

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

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

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

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

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

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

399
    doc->writeEndElement();
3✔
400

401
    return true;
3✔
402
}
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