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

mcallegari / qlcplus / 7252848206

18 Dec 2023 07:26PM UTC coverage: 32.067% (+0.001%) from 32.066%
7252848206

push

github

mcallegari
Code style review #1427

199 of 628 new or added lines in 101 files covered. (31.69%)

8 existing lines in 2 files now uncovered.

15169 of 47304 relevant lines covered (32.07%)

23733.74 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
            m_inputSource->setRange(vcmc.m_inputSource->lowerValue(), vcmc.m_inputSource->upperValue());
×
55
        }
56
    }
57

58
    return *this;
×
59
}
60

61
VCMatrixControl::~VCMatrixControl()
×
62
{
63
}
×
64

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

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

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

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

93
VCMatrixControl::WidgetType VCMatrixControl::widgetType() const
×
94
{
95
    switch(m_type)
×
96
    {
97
        case StartColor:
×
98
        case EndColor:
99
        case Animation:
100
        case Image:
101
        case Text:
102
        case ResetEndColor:
103
            return Button;
×
104
        case StartColorKnob:
×
105
        case EndColorKnob:
106
            return Knob;
×
107
    }
108

109
    // We're never supposed to be here
110
    Q_ASSERT(false);
×
111
    return Button;
112
}
113

114
QString VCMatrixControl::typeToString(VCMatrixControl::ControlType type)
×
115
{
116
    switch(type)
×
117
    {
118
        case StartColor: return "StartColor"; break;
×
119
        case EndColor: return "EndColor"; break;
×
120
        case ResetEndColor: return "ResetEndColor"; break;
×
121
        case Animation: return "Animation"; break;
×
122
        case Image: return "Image"; break;
×
123
        case Text: return "Text"; break;
×
124
        case StartColorKnob: return "StartColorKnob"; break;
×
125
        case EndColorKnob: return "EndColorKnob"; break;
×
126
    }
127
    return QString();
×
128
}
129

130
VCMatrixControl::ControlType VCMatrixControl::stringToType(QString str)
×
131
{
132
    if (str == "StartColor") return StartColor;
×
133
    else if (str == "EndColor") return EndColor;
×
134
    else if (str == "ResetEndColor") return ResetEndColor;
×
135
    else if (str == "Animation") return Animation;
×
136
    else if (str == "Image") return Image;
×
137
    else if (str == "Text") return Text;
×
138
    else if (str == "StartColorKnob") return StartColorKnob;
×
139
    else if (str == "EndColorKnob") return EndColorKnob;
×
140
    else
141
        return StartColor;
×
142
}
143

144
bool VCMatrixControl::operator<(VCMatrixControl const& right) const
×
145
{
146
    return m_id < right.m_id;
×
147
}
148

149
bool VCMatrixControl::compare(VCMatrixControl const* left, VCMatrixControl const* right)
×
150
{
151
    return *left < *right;
×
152
}
153

154
bool VCMatrixControl::loadXML(QXmlStreamReader &root)
×
155
{
156
    if (root.name() != KXMLQLCVCMatrixControl)
×
157
    {
158
        qWarning() << Q_FUNC_INFO << "Matrix control node not found";
×
159
        return false;
×
160
    }
161

162
    if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlID) == false)
×
163
    {
164
        qWarning() << Q_FUNC_INFO << "Matrix control ID not found";
×
165
        return false;
×
166
    }
167

168
    m_id = root.attributes().value(KXMLQLCVCMatrixControlID).toString().toUInt();
×
169

170
    /* Children */
171
    while (root.readNextStartElement())
×
172
    {
173
        if (root.name() == KXMLQLCVCMatrixControlType)
×
174
        {
175
            m_type = stringToType(root.readElementText());
×
176
        }
177
        else if (root.name() == KXMLQLCVCMatrixControlColor)
×
178
        {
179
            m_color = QColor(root.readElementText());
×
180
        }
181
        else if (root.name() == KXMLQLCVCMatrixControlResource)
×
182
        {
183
            m_resource = root.readElementText();
×
184
        }
185
        else if (root.name() == KXMLQLCVCMatrixControlProperty)
×
186
        {
187
            if (root.attributes().hasAttribute(KXMLQLCVCMatrixControlPropertyName))
×
188
            {
189
                QString pName = root.attributes().value(KXMLQLCVCMatrixControlPropertyName).toString();
×
190
                QString pValue = root.readElementText();
×
191
                m_properties[pName] = pValue;
×
192
            }
193
        }
194
        else if (root.name() == KXMLQLCVCWidgetInput)
×
195
        {
196
            m_inputSource = VCWidget::getXMLInput(root);
×
197
            root.skipCurrentElement();
×
198
        }
199
        else if (root.name() == KXMLQLCVCWidgetKey)
×
200
        {
201
            m_keySequence = VCWidget::stripKeySequence(QKeySequence(root.readElementText()));
×
202
        }
203
        else
204
        {
205
            qWarning() << Q_FUNC_INFO << "Unknown VCMatrixControl tag:" << root.name().toString();
×
206
            root.skipCurrentElement();
×
207
        }
208
    }
209

210
    return true;
×
211
}
212

213
bool VCMatrixControl::saveXML(QXmlStreamWriter *doc)
×
214
{
215
    Q_ASSERT(doc != NULL);
×
216

217
    doc->writeStartElement(KXMLQLCVCMatrixControl);
×
218
    doc->writeAttribute(KXMLQLCVCMatrixControlID, QString::number(m_id));
×
219

220
    doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type));
×
221

222
    if (m_type == StartColor || m_type == EndColor || m_type == StartColorKnob || m_type == EndColorKnob)
×
223
    {
224
        doc->writeTextElement(KXMLQLCVCMatrixControlColor, m_color.name());
×
225
    }
226
    else
227
    {
228
        doc->writeTextElement(KXMLQLCVCMatrixControlResource, m_resource);
×
229
    }
230

231
    if (!m_properties.isEmpty())
×
232
    {
233
        QHashIterator<QString, QString> it(m_properties);
×
NEW
234
        while (it.hasNext())
×
235
        {
236
            it.next();
×
237
            doc->writeStartElement(KXMLQLCVCMatrixControlProperty);
×
238
            doc->writeAttribute(KXMLQLCVCMatrixControlPropertyName, it.key());
×
239
            doc->writeCharacters(it.value());
×
240
            doc->writeEndElement();
×
241
        }
242
    }
243

244
    /* External input source */
245
    if (!m_inputSource.isNull() && m_inputSource->isValid())
×
246
        VCWidget::saveXMLInput(doc, m_inputSource);
×
247

248
    /* Key sequence */
249
    if (m_keySequence.isEmpty() == false)
×
250
        doc->writeTextElement(KXMLQLCVCWidgetKey, m_keySequence.toString());
×
251

252
    /* End the <Control> tag */
253
    doc->writeEndElement();
×
254

255
    return true;
×
256
}
257

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