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

mcallegari / qlcplus / 16450929051

22 Jul 2025 05:09PM UTC coverage: 34.174% (-0.1%) from 34.286%
16450929051

Pull #1782

github

web-flow
Merge f80a306ab into 8a22b7b84
Pull Request #1782: Feature: Control RGB Matrix script properties with VC Knobs in animation widget

7 of 189 new or added lines in 6 files covered. (3.7%)

9 existing lines in 4 files now uncovered.

17704 of 51806 relevant lines covered (34.17%)

19373.32 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;
×
NEW
48
        m_dynamicProperties = vcmc.m_dynamicProperties;
×
UNCOV
49
        m_keySequence = vcmc.m_keySequence;
×
50

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

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

61
    return *this;
×
62
}
63

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

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

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

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

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

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

123
    // We're never supposed to be here
124
    Q_ASSERT(false);
×
125
    return Button;
126
}
127

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

155
VCMatrixControl::ControlType VCMatrixControl::stringToType(QString str)
×
156
{
157
    if (str == "Color1" || str == "StartColor") return Color1;
×
158
    else if (str == "Color2" || str == "EndColor") return Color2;
×
159
    else if (str == "Color3") return Color3;
×
160
    else if (str == "Color4") return Color4;
×
161
    else if (str == "Color5") return Color5;
×
162
    else if (str == "ResetColor2") return Color2Reset;
×
163
    else if (str == "ResetColor3") return Color3Reset;
×
164
    else if (str == "ResetColor4") return Color4Reset;
×
165
    else if (str == "ResetColor5") return Color5Reset;
×
166
    else if (str == "Animation") return Animation;
×
NEW
167
    else if (str == "AnimationKnob") return AnimationKnob;
×
168
    else if (str == "Image") return Image;
×
169
    else if (str == "Text") return Text;
×
170
    else if (str == "Color1Knob" || str == "StartColorKnob") return Color1Knob;
×
171
    else if (str == "Color2Knob" || str == "EndColorKnob") return Color2Knob;
×
172
    else if (str == "Color3Knob") return Color3Knob;
×
173
    else if (str == "Color4Knob") return Color4Knob;
×
174
    else if (str == "Color5Knob") return Color5Knob;
×
175
    else
176
        return Color1;
×
177
}
178

179
bool VCMatrixControl::operator<(VCMatrixControl const& right) const
×
180
{
181
    return m_id < right.m_id;
×
182
}
183

184
bool VCMatrixControl::compare(VCMatrixControl const* left, VCMatrixControl const* right)
×
185
{
186
    return *left < *right;
×
187
}
188

189
bool VCMatrixControl::loadXML(QXmlStreamReader &root)
×
190
{
191
    if (root.name() != KXMLQLCVCMatrixControl)
×
192
    {
193
        qWarning() << Q_FUNC_INFO << "Matrix control node not found";
×
194
        return false;
×
195
    }
196

197
    if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlID) == false)
×
198
    {
199
        qWarning() << Q_FUNC_INFO << "Matrix control ID not found";
×
200
        return false;
×
201
    }
202

203
    m_id = root.attributes().value(KXMLQLCVCMatrixControlID).toString().toUInt();
×
204

205
    /* Children */
206
    while (root.readNextStartElement())
×
207
    {
208
        if (root.name() == KXMLQLCVCMatrixControlType)
×
209
        {
210
            m_type = stringToType(root.readElementText());
×
211
        }
212
        else if (root.name() == KXMLQLCVCMatrixControlColor)
×
213
        {
214
            m_color = QColor(root.readElementText());
×
215
        }
216
        else if (root.name() == KXMLQLCVCMatrixControlResource)
×
217
        {
218
            m_resource = root.readElementText();
×
219
        }
220
        else if (root.name() == KXMLQLCVCMatrixControlProperty)
×
221
        {
222
            if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlPropertyName))
×
223
            {
224
                QString pName = root.attributes().value(KXMLQLCVCMatrixControlPropertyName).toString();
×
225
                QString pValue = root.readElementText();
×
226
                m_properties[pName] = pValue;
×
227
            }
×
228
        }
NEW
229
        else if (root.name() == KXMLQLCVCMatrixControlDynamicProperty)
×
230
        {
NEW
231
            if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlPropertyName))
×
232
            {
NEW
233
                QString pName = root.attributes().value(KXMLQLCVCMatrixControlPropertyName).toString();
×
NEW
234
                m_dynamicProperties[pName] = true;
×
NEW
235
            }
×
NEW
236
            root.skipCurrentElement();
×
237
        }
UNCOV
238
        else if (root.name() == KXMLQLCVCWidgetInput)
×
239
        {
240
            m_inputSource = VCWidget::getXMLInput(root);
×
241
            root.skipCurrentElement();
×
242
        }
243
        else if (root.name() == KXMLQLCVCWidgetKey)
×
244
        {
245
            m_keySequence = VCWidget::stripKeySequence(QKeySequence(root.readElementText()));
×
246
        }
247
        else
248
        {
249
            qWarning() << Q_FUNC_INFO << "Unknown VCMatrixControl tag:" << root.name().toString();
×
250
            root.skipCurrentElement();
×
251
        }
252
    }
253

254
    return true;
×
255
}
256

257
bool VCMatrixControl::saveXML(QXmlStreamWriter *doc)
×
258
{
259
    Q_ASSERT(doc != NULL);
×
260

261
    doc->writeStartElement(KXMLQLCVCMatrixControl);
×
262
    doc->writeAttribute(KXMLQLCVCMatrixControlID, QString::number(m_id));
×
263

264
    doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type));
×
265

266
    if (m_type == Color1
×
267
            || m_type == Color2
×
268
            || m_type == Color3
×
269
            || m_type == Color4
×
270
            || m_type == Color5
×
271
            || m_type == Color1Knob
×
272
            || m_type == Color2Knob
×
273
            || m_type == Color3Knob
×
274
            || m_type == Color4Knob
×
275
            || m_type == Color5Knob)
×
276
    {
277
        doc->writeTextElement(KXMLQLCVCMatrixControlColor, m_color.name());
×
278
    }
279
    else
280
    {
281
        doc->writeTextElement(KXMLQLCVCMatrixControlResource, m_resource);
×
282
    }
283

284
    if (!m_properties.isEmpty())
×
285
    {
286
        QMapIterator<QString, QString> it(m_properties);
×
287
        while (it.hasNext())
×
288
        {
289
            it.next();
×
290
            doc->writeStartElement(KXMLQLCVCMatrixControlProperty);
×
291
            doc->writeAttribute(KXMLQLCVCMatrixControlPropertyName, it.key());
×
292
            doc->writeCharacters(it.value());
×
293
            doc->writeEndElement();
×
294
        }
295
    }
×
296

NEW
297
    if (!m_dynamicProperties.isEmpty())
×
298
    {
NEW
299
        QMapIterator<QString, bool> it(m_dynamicProperties);
×
NEW
300
        while (it.hasNext())
×
301
        {
NEW
302
            it.next();
×
NEW
303
            if (it.value() == true)
×
304
            {
NEW
305
                doc->writeStartElement(KXMLQLCVCMatrixControlDynamicProperty);
×
NEW
306
                doc->writeAttribute(KXMLQLCVCMatrixControlPropertyName, it.key());
×
NEW
307
                doc->writeEndElement();
×
308
            }
309
        }
NEW
310
    }
×
311

312
    /* External input source */
313
    if (!m_inputSource.isNull() && m_inputSource->isValid())
×
314
        VCWidget::saveXMLInput(doc, m_inputSource);
×
315

316
    /* Key sequence */
317
    if (m_keySequence.isEmpty() == false)
×
318
        doc->writeTextElement(KXMLQLCVCWidgetKey, m_keySequence.toString());
×
319

320
    /* End the <Control> tag */
321
    doc->writeEndElement();
×
322

323
    return true;
×
324
}
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