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

mcallegari / qlcplus / 8440834527

26 Mar 2024 06:08PM UTC coverage: 31.709% (-0.4%) from 32.081%
8440834527

Pull #1422

github

web-flow
Merge 34f746340 into 7e2ec9324
Pull Request #1422: RgbScript make stage colors available to scripts

50 of 898 new or added lines in 11 files covered. (5.57%)

9 existing lines in 4 files now uncovered.

15408 of 48592 relevant lines covered (31.71%)

22631.0 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
    {
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 Color2Reset:
108
        case Color3Reset:
109
        case Color4Reset:
110
        case Color5Reset:
111
            return Button;
×
NEW
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

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

150
VCMatrixControl::ControlType VCMatrixControl::stringToType(QString str)
×
151
{
NEW
152
    if (str == "Color1") return Color1;
×
NEW
153
    else if (str == "Color2") return Color2;
×
NEW
154
    else if (str == "Color3") return Color3;
×
NEW
155
    else if (str == "Color4") return Color4;
×
NEW
156
    else if (str == "Color5") return Color5;
×
NEW
157
    else if (str == "ResetColor2") return Color2Reset;
×
NEW
158
    else if (str == "ResetColor3") return Color3Reset;
×
NEW
159
    else if (str == "ResetColor4") return Color4Reset;
×
NEW
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;
×
NEW
164
    else if (str == "Color1Knob") return Color1Knob;
×
NEW
165
    else if (str == "Color2Knob") return Color2Knob;
×
NEW
166
    else if (str == "Color3Knob") return Color3Knob;
×
NEW
167
    else if (str == "Color4Knob") return Color4Knob;
×
NEW
168
    else if (str == "Color5Knob") return Color5Knob;
×
169
    else
NEW
170
        return Color1;
×
171
}
172

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

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

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

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

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

199
    /* Children */
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();
×
219
                QString pValue = root.readElementText();
×
220
                m_properties[pName] = pValue;
×
221
            }
222
        }
223
        else if (root.name() == KXMLQLCVCWidgetInput)
×
224
        {
225
            m_inputSource = VCWidget::getXMLInput(root);
×
226
            root.skipCurrentElement();
×
227
        }
228
        else if (root.name() == KXMLQLCVCWidgetKey)
×
229
        {
230
            m_keySequence = VCWidget::stripKeySequence(QKeySequence(root.readElementText()));
×
231
        }
232
        else
233
        {
234
            qWarning() << Q_FUNC_INFO << "Unknown VCMatrixControl tag:" << root.name().toString();
×
235
            root.skipCurrentElement();
×
236
        }
237
    }
238

239
    return true;
×
240
}
241

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

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

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

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

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

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

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

290
    /* End the <Control> tag */
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

© 2025 Coveralls, Inc