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

mcallegari / qlcplus / 12633886366

06 Jan 2025 02:02PM UTC coverage: 31.649% (-0.02%) from 31.664%
12633886366

Pull #1659

github

mcallegari
engine: fix loading a 16bit RGB panel profile
Pull Request #1659: RGBPanel: implement cross universe and 16bit profiles

99 of 216 new or added lines in 10 files covered. (45.83%)

234 existing lines in 6 files now uncovered.

14141 of 44681 relevant lines covered (31.65%)

26855.13 hits per line

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

0.0
/ui/src/virtualconsole/vcmatrixcontrol.cpp
1
/*
2
  Q Light Controller Plus
3
  vcmatrixcontrol.cpp
4

5
  Copyright (c) Massimo Callegari
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QXmlStreamReader>
21
#include <QXmlStreamWriter>
22
#include <QDebug>
23

24
#include "vcmatrixcontrol.h"
25
#include "vcwidget.h"
26

27
VCMatrixControl::VCMatrixControl(quint8 id)
×
28
    : m_id(id)
×
29
{
30
    m_color = QColor();
31
    m_resource = QString();
×
32
}
×
33

34
VCMatrixControl::VCMatrixControl(const VCMatrixControl &other)
×
35
{
36
    *this = other;
×
37
}
×
38

39
VCMatrixControl &VCMatrixControl::operator=(const VCMatrixControl &vcmc)
×
40
{
41
    if (this != &vcmc)
×
42
    {
43
        m_id = vcmc.m_id;
×
44
        m_type = vcmc.m_type;
×
45
        m_color = vcmc.m_color;
×
46
        m_resource = vcmc.m_resource;
×
47
        m_properties = vcmc.m_properties;
×
48
        m_keySequence = vcmc.m_keySequence;
×
49

50
        if (vcmc.m_inputSource != NULL)
×
51
        {
52
            m_inputSource = QSharedPointer<QLCInputSource>(new QLCInputSource(vcmc.m_inputSource->universe(),
×
53
                                                   vcmc.m_inputSource->channel()));
×
54

55
            m_inputSource->setFeedbackValue(QLCInputFeedback::LowerValue, vcmc.m_inputSource->feedbackValue(QLCInputFeedback::LowerValue));
×
56
            m_inputSource->setFeedbackValue(QLCInputFeedback::UpperValue, vcmc.m_inputSource->feedbackValue(QLCInputFeedback::UpperValue));
×
57
        }
58
    }
59

60
    return *this;
×
61
}
62

63
VCMatrixControl::~VCMatrixControl()
×
64
{
65
}
×
66

67
quint8 VCMatrixControl::rgbToValue(QRgb color) const
×
68
{
69
    if (m_color == Qt::red)
×
70
        return QColor(color).red();
×
71
    if (m_color == Qt::green)
×
72
        return QColor(color).green();
×
73
    if (m_color == Qt::blue)
×
74
        return QColor(color).blue();
×
75

76
    // We're never supposed to be here
77
    Q_ASSERT(false);
78
    return 0;
79
}
80

81
QRgb VCMatrixControl::valueToRgb(quint8 value) const
×
82
{
83
    if (m_color == Qt::red)
×
84
        return qRgb(value, 0, 0);
×
85
    if (m_color == Qt::green)
×
86
        return qRgb(0, value, 0);
×
87
    if (m_color == Qt::blue)
×
88
        return qRgb(0, 0, value);
×
89

90
    // We're never supposed to be here
91
    Q_ASSERT(false);
92
    return 0;
93
}
94

95
VCMatrixControl::WidgetType VCMatrixControl::widgetType() const
×
96
{
97
    switch(m_type)
×
98
    {
99
        case Color1:
100
        case Color2:
101
        case Color3:
102
        case Color4:
103
        case Color5:
104
        case Animation:
105
        case Image:
106
        case Text:
107
        case Color2Reset:
108
        case Color3Reset:
109
        case Color4Reset:
110
        case Color5Reset:
111
            return Button;
UNCOV
112
        case Color1Knob:
×
113
        case Color2Knob:
114
        case Color3Knob:
115
        case Color4Knob:
116
        case Color5Knob:
UNCOV
117
            return Knob;
×
118
    }
119

120
    // We're never supposed to be here
121
    Q_ASSERT(false);
122
    return Button;
123
}
124

UNCOV
125
QString VCMatrixControl::typeToString(VCMatrixControl::ControlType type)
×
126
{
UNCOV
127
    switch(type)
×
128
    {
UNCOV
129
        case Color1: return "Color1"; break;
×
130
        case Color2: return "Color2"; break;
×
131
        case Color3: return "Color3"; break;
×
132
        case Color4: return "Color4"; break;
×
133
        case Color5: return "Color5"; break;
×
134
        case Color2Reset: return "ResetColor2"; break;
×
135
        case Color3Reset: return "ResetColor3"; break;
×
136
        case Color4Reset: return "ResetColor4"; break;
×
137
        case Color5Reset: return "ResetColor5"; break;
×
138
        case Animation: return "Animation"; break;
×
139
        case Image: return "Image"; break;
×
140
        case Text: return "Text"; break;
×
141
        case Color1Knob: return "Color1Knob"; break;
×
142
        case Color2Knob: return "Color2Knob"; break;
×
143
        case Color3Knob: return "Color3Knob"; break;
×
144
        case Color4Knob: return "Color4Knob"; break;
×
145
        case Color5Knob: return "Color5Knob"; break;
×
146
    }
147
    return QString();
148
}
149

UNCOV
150
VCMatrixControl::ControlType VCMatrixControl::stringToType(QString str)
×
151
{
152
    if (str == "Color1") return Color1;
×
UNCOV
153
    else if (str == "Color2") return Color2;
×
154
    else if (str == "Color3") return Color3;
×
155
    else if (str == "Color4") return Color4;
×
156
    else if (str == "Color5") return Color5;
×
157
    else if (str == "ResetColor2") return Color2Reset;
×
158
    else if (str == "ResetColor3") return Color3Reset;
×
159
    else if (str == "ResetColor4") return Color4Reset;
×
160
    else if (str == "ResetColor5") return Color5Reset;
×
161
    else if (str == "Animation") return Animation;
×
162
    else if (str == "Image") return Image;
×
163
    else if (str == "Text") return Text;
×
164
    else if (str == "Color1Knob") return Color1Knob;
×
165
    else if (str == "Color2Knob") return Color2Knob;
×
166
    else if (str == "Color3Knob") return Color3Knob;
×
167
    else if (str == "Color4Knob") return Color4Knob;
×
168
    else if (str == "Color5Knob") return Color5Knob;
×
169
    else
170
        return Color1;
×
171
}
172

UNCOV
173
bool VCMatrixControl::operator<(VCMatrixControl const& right) const
×
174
{
175
    return m_id < right.m_id;
×
176
}
177

UNCOV
178
bool VCMatrixControl::compare(VCMatrixControl const* left, VCMatrixControl const* right)
×
179
{
180
    return *left < *right;
×
181
}
182

UNCOV
183
bool VCMatrixControl::loadXML(QXmlStreamReader &root)
×
184
{
185
    if (root.name() != KXMLQLCVCMatrixControl)
×
186
    {
187
        qWarning() << Q_FUNC_INFO << "Matrix control node not found";
×
UNCOV
188
        return false;
×
189
    }
190

UNCOV
191
    if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlID) == false)
×
192
    {
193
        qWarning() << Q_FUNC_INFO << "Matrix control ID not found";
×
UNCOV
194
        return false;
×
195
    }
196

UNCOV
197
    m_id = root.attributes().value(KXMLQLCVCMatrixControlID).toString().toUInt();
×
198

199
    /* Children */
UNCOV
200
    while (root.readNextStartElement())
×
201
    {
202
        if (root.name() == KXMLQLCVCMatrixControlType)
×
203
        {
204
            m_type = stringToType(root.readElementText());
×
205
        }
206
        else if (root.name() == KXMLQLCVCMatrixControlColor)
×
207
        {
208
            m_color = QColor(root.readElementText());
×
209
        }
210
        else if (root.name() == KXMLQLCVCMatrixControlResource)
×
211
        {
212
            m_resource = root.readElementText();
×
213
        }
214
        else if (root.name() == KXMLQLCVCMatrixControlProperty)
×
215
        {
216
            if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlPropertyName))
×
217
            {
218
                QString pName = root.attributes().value(KXMLQLCVCMatrixControlPropertyName).toString();
×
UNCOV
219
                QString pValue = root.readElementText();
×
220
                m_properties[pName] = pValue;
×
221
            }
222
        }
UNCOV
223
        else if (root.name() == KXMLQLCVCWidgetInput)
×
224
        {
225
            m_inputSource = VCWidget::getXMLInput(root);
×
UNCOV
226
            root.skipCurrentElement();
×
227
        }
228
        else if (root.name() == KXMLQLCVCWidgetKey)
×
229
        {
230
            m_keySequence = VCWidget::stripKeySequence(QKeySequence(root.readElementText()));
×
231
        }
232
        else
233
        {
UNCOV
234
            qWarning() << Q_FUNC_INFO << "Unknown VCMatrixControl tag:" << root.name().toString();
×
UNCOV
235
            root.skipCurrentElement();
×
236
        }
237
    }
238

239
    return true;
240
}
241

UNCOV
242
bool VCMatrixControl::saveXML(QXmlStreamWriter *doc)
×
243
{
244
    Q_ASSERT(doc != NULL);
245

UNCOV
246
    doc->writeStartElement(KXMLQLCVCMatrixControl);
×
UNCOV
247
    doc->writeAttribute(KXMLQLCVCMatrixControlID, QString::number(m_id));
×
248

249
    doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type));
×
250

251
    if (m_type == Color1
×
UNCOV
252
            || m_type == Color2
×
253
            || m_type == Color3
×
UNCOV
254
            || m_type == Color4
×
UNCOV
255
            || m_type == Color5
×
UNCOV
256
            || m_type == Color1Knob
×
UNCOV
257
            || m_type == Color2Knob
×
UNCOV
258
            || m_type == Color3Knob
×
UNCOV
259
            || m_type == Color4Knob
×
UNCOV
260
            || m_type == Color5Knob)
×
261
    {
UNCOV
262
        doc->writeTextElement(KXMLQLCVCMatrixControlColor, m_color.name());
×
263
    }
264
    else
265
    {
UNCOV
266
        doc->writeTextElement(KXMLQLCVCMatrixControlResource, m_resource);
×
267
    }
268

UNCOV
269
    if (!m_properties.isEmpty())
×
270
    {
271
        QHashIterator<QString, QString> it(m_properties);
×
UNCOV
272
        while (it.hasNext())
×
273
        {
274
            it.next();
UNCOV
275
            doc->writeStartElement(KXMLQLCVCMatrixControlProperty);
×
UNCOV
276
            doc->writeAttribute(KXMLQLCVCMatrixControlPropertyName, it.key());
×
277
            doc->writeCharacters(it.value());
×
278
            doc->writeEndElement();
×
279
        }
280
    }
281

282
    /* External input source */
UNCOV
283
    if (!m_inputSource.isNull() && m_inputSource->isValid())
×
UNCOV
284
        VCWidget::saveXMLInput(doc, m_inputSource);
×
285

286
    /* Key sequence */
UNCOV
287
    if (m_keySequence.isEmpty() == false)
×
UNCOV
288
        doc->writeTextElement(KXMLQLCVCWidgetKey, m_keySequence.toString());
×
289

290
    /* End the <Control> tag */
UNCOV
291
    doc->writeEndElement();
×
292

293
    return true;
×
294
}
295

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