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

mcallegari / qlcplus / 18357067171

08 Oct 2025 08:16PM UTC coverage: 34.26% (+2.2%) from 32.066%
18357067171

push

github

mcallegari
Merge branch 'master' into filedialog

1282 of 4424 new or added lines in 152 files covered. (28.98%)

1342 existing lines in 152 files now uncovered.

17704 of 51675 relevant lines covered (34.26%)

19430.31 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

NEW
55
            m_inputSource->setFeedbackValue(QLCInputFeedback::LowerValue, vcmc.m_inputSource->feedbackValue(QLCInputFeedback::LowerValue));
×
NEW
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
    {
NEW
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 Color1Reset:
108
        case Color2Reset:
109
        case Color3Reset:
110
        case Color4Reset:
111
        case Color5Reset:
112
            return Button;
×
NEW
113
        case Color1Knob:
×
114
        case Color2Knob:
115
        case Color3Knob:
116
        case Color4Knob:
117
        case Color5Knob:
UNCOV
118
            return Knob;
×
119
    }
120

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

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

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

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

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

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

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

199
    m_id = root.attributes().value(KXMLQLCVCMatrixControlID).toString().toUInt();
×
200

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

241
    return true;
×
242
}
243

244
bool VCMatrixControl::saveXML(QXmlStreamWriter *doc)
×
245
{
246
    Q_ASSERT(doc != NULL);
×
247

248
    doc->writeStartElement(KXMLQLCVCMatrixControl);
×
249
    doc->writeAttribute(KXMLQLCVCMatrixControlID, QString::number(m_id));
×
250

251
    doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type));
×
252

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

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

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

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

292
    /* End the <Control> tag */
293
    doc->writeEndElement();
×
294

295
    return true;
×
296
}
297

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