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

mcallegari / qlcplus / 12611954629

04 Jan 2025 04:17PM UTC coverage: 31.468% (-0.5%) from 31.963%
12611954629

Pull #1649

github

web-flow
Merge d17d3ec9b into 3ed321c32
Pull Request #1649: Function Wizard: create Effects

2 of 53 new or added lines in 2 files covered. (3.77%)

2597 existing lines in 15 files now uncovered.

14093 of 44785 relevant lines covered (31.47%)

26791.82 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 Color1Reset:
108
        case Color2Reset:
109
        case Color3Reset:
110
        case Color4Reset:
111
        case Color5Reset:
112
            return Button;
UNCOV
113
        case Color1Knob:
×
114
        case Color2Knob:
115
        case Color3Knob:
116
        case Color4Knob:
117
        case Color5Knob:
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
{
UNCOV
128
    switch(type)
×
129
    {
UNCOV
130
        case Color1: return "Color1"; break;
×
UNCOV
131
        case Color2: return "Color2"; break;
×
132
        case Color3: return "Color3"; break;
×
UNCOV
133
        case Color4: return "Color4"; break;
×
134
        case Color5: return "Color5"; break;
×
135
        case Color1Reset: return "ResetColor1"; break;
×
136
        case Color2Reset: return "ResetColor2"; break;
×
137
        case Color3Reset: return "ResetColor3"; break;
×
138
        case Color4Reset: return "ResetColor4"; break;
×
139
        case Color5Reset: return "ResetColor5"; break;
×
140
        case Animation: return "Animation"; break;
×
141
        case Image: return "Image"; break;
×
UNCOV
142
        case Text: return "Text"; break;
×
143
        case Color1Knob: return "Color1Knob"; break;
×
UNCOV
144
        case Color2Knob: return "Color2Knob"; break;
×
UNCOV
145
        case Color3Knob: return "Color3Knob"; break;
×
146
        case Color4Knob: return "Color4Knob"; break;
×
UNCOV
147
        case Color5Knob: return "Color5Knob"; break;
×
148
    }
149
    return QString();
150
}
151

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

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

UNCOV
180
bool VCMatrixControl::compare(VCMatrixControl const* left, VCMatrixControl const* right)
×
181
{
UNCOV
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";
×
UNCOV
190
        return false;
×
191
    }
192

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

241
    return true;
242
}
243

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

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

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

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

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

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

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

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

UNCOV
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