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

mcallegari / qlcplus / 8961243534

05 May 2024 09:23PM UTC coverage: 32.068% (+4.0%) from 28.094%
8961243534

push

github

mcallegari
Merge branch 'master' into qmltoqt6

902 of 2557 new or added lines in 140 files covered. (35.28%)

166 existing lines in 76 files now uncovered.

15395 of 48008 relevant lines covered (32.07%)

22949.67 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
    {
99
        case StartColor:
×
100
        case EndColor:
101
        case Animation:
102
        case Image:
103
        case Text:
104
        case ResetEndColor:
105
            return Button;
×
106
        case StartColorKnob:
×
107
        case EndColorKnob:
108
            return Knob;
×
109
    }
110

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

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

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

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

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

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

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

170
    m_id = root.attributes().value(KXMLQLCVCMatrixControlID).toString().toUInt();
×
171

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

212
    return true;
×
213
}
214

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

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

222
    doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type));
×
223

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

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

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

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

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

257
    return true;
×
258
}
259

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