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

mcallegari / qlcplus / 6633445329

24 Oct 2023 10:56PM UTC coverage: 28.07% (+0.03%) from 28.038%
6633445329

push

github

mcallegari
qmlui: fix qmake build

15376 of 54778 relevant lines covered (28.07%)

20279.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.96
/engine/src/qlcinputchannel.cpp
1
/*
2
  Q Light Controller
3
  qlcinputchannel.cpp
4

5
  Copyright (c) Heikki Junnila
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 <QString>
23
#include <QDebug>
24
#include <QIcon>
25

26
#include "qlcinputchannel.h"
27
#include "qlcinputprofile.h"
28

29
/****************************************************************************
30
 * Initialization
31
 ****************************************************************************/
32

33
QLCInputChannel::QLCInputChannel()
11,975✔
34
    : m_type(Button)
35
    , m_movementType(Absolute)
36
    , m_movementSensitivity(20)
37
    , m_sendExtraPress(false)
38
    , m_lower(0)
39
    , m_upper(UCHAR_MAX)
11,975✔
40
{
41
}
11,975✔
42

43
QLCInputChannel *QLCInputChannel::createCopy()
10✔
44
{
45
    QLCInputChannel *copy = new QLCInputChannel();
10✔
46
    copy->setName(this->name());
10✔
47
    copy->setType(this->type());
10✔
48
    copy->setMovementType(this->movementType());
10✔
49
    copy->setMovementSensitivity(this->movementSensitivity());
10✔
50
    copy->setSendExtraPress(this->sendExtraPress());
10✔
51
    copy->setRange(this->lowerValue(), this->upperValue());
10✔
52

53
    return copy;
10✔
54
}
55

56
QLCInputChannel::~QLCInputChannel()
7,856✔
57
{
58
}
7,856✔
59

60
/****************************************************************************
61
 * Type
62
 ****************************************************************************/
63

64
void QLCInputChannel::setType(Type type)
11,954✔
65
{
66
    if (type == m_type)
11,954✔
67
        return;
7,172✔
68

69
    m_type = type;
4,782✔
70
    if (type == Encoder)
4,782✔
71
        m_movementSensitivity = 1;
52✔
72
    else
73
        m_movementSensitivity = 20;
4,730✔
74

75
    emit typeChanged();
4,782✔
76
}
77

78
QLCInputChannel::Type QLCInputChannel::type() const
807✔
79
{
80
    return m_type;
807✔
81
}
82

83
QString QLCInputChannel::typeToString(Type type)
12✔
84
{
85
    switch (type)
12✔
86
    {
87
        case Button:
4✔
88
            return KXMLQLCInputChannelButton;
4✔
89
        case Knob:
2✔
90
            return KXMLQLCInputChannelKnob;
2✔
91
        case Encoder:
1✔
92
            return KXMLQLCInputChannelEncoder;
1✔
93
        case Slider:
1✔
94
            return KXMLQLCInputChannelSlider;
1✔
95
        case NextPage:
1✔
96
            return KXMLQLCInputChannelPageUp;
1✔
97
        case PrevPage:
1✔
98
            return KXMLQLCInputChannelPageDown;
1✔
99
        case PageSet:
1✔
100
            return KXMLQLCInputChannelPageSet;
1✔
101
        default:
1✔
102
            return KXMLQLCInputChannelNone;
1✔
103
        }
104
}
105

106
QString QLCInputChannel::typeString()
×
107
{
108
    return typeToString(type());
×
109
}
110

111
QLCInputChannel::Type QLCInputChannel::stringToType(const QString& type)
11,943✔
112
{
113
    if (type == KXMLQLCInputChannelButton)
11,943✔
114
        return Button;
7,165✔
115
    else if (type == KXMLQLCInputChannelKnob)
4,778✔
116
        return Knob;
1,900✔
117
    else if (type == KXMLQLCInputChannelEncoder)
2,878✔
118
        return Encoder;
52✔
119
    else if (type == KXMLQLCInputChannelSlider)
2,826✔
120
        return Slider;
2,803✔
121
    else if (type == KXMLQLCInputChannelPageUp)
23✔
122
        return NextPage;
10✔
123
    else if (type == KXMLQLCInputChannelPageDown)
13✔
124
        return PrevPage;
10✔
125
    else if (type == KXMLQLCInputChannelPageSet)
3✔
126
        return PageSet;
1✔
127
    else
128
        return NoType;
2✔
129
}
130

131
QStringList QLCInputChannel::types()
1✔
132
{
133
    QStringList list;
1✔
134
    list << KXMLQLCInputChannelSlider;
1✔
135
    list << KXMLQLCInputChannelKnob;
1✔
136
    list << KXMLQLCInputChannelEncoder;
1✔
137
    list << KXMLQLCInputChannelButton;
1✔
138
    list << KXMLQLCInputChannelPageUp;
1✔
139
    list << KXMLQLCInputChannelPageDown;
1✔
140
    list << KXMLQLCInputChannelPageSet;
1✔
141
    return list;
1✔
142
}
143

144
QIcon QLCInputChannel::typeToIcon(Type type)
×
145
{
146
    return QIcon(iconResource(type));
×
147
}
148

149
QIcon QLCInputChannel::stringToIcon(const QString& str)
×
150
{
151
    return typeToIcon(stringToType(str));
×
152
}
153

154
QString QLCInputChannel::iconResource(Type type, bool svg)
×
155
{
156
    QString prefix = svg ? "qrc" : "";
×
157
    QString ext = svg ? "svg" : "png";
×
158

159
    switch(type)
×
160
    {
161
        case Button: return QString("%1:/button.%2").arg(prefix, ext);
×
162
        case Knob: return QString("%1:/knob.%2").arg(prefix, ext);
×
163
        case Encoder: return QString("%1:/knob.%2").arg(prefix, ext);
×
164
        case Slider: return QString("%1:/slider.%2").arg(prefix, ext);
×
165
        case PrevPage: return QString("%1:/forward.%2").arg(prefix, ext);
×
166
        case NextPage: return QString("%1:/back.%2").arg(prefix, ext);
×
167
        case PageSet: return QString("%1:/star.%2").arg(prefix, ext);
×
168
        default: return QString();
×
169
    }
170

171
    return QString("%1:/other.%2").arg(prefix, ext);
172
}
173

174
QIcon QLCInputChannel::icon() const
×
175
{
176
    return typeToIcon(type());
×
177
}
178

179
/****************************************************************************
180
 * Name
181
 ****************************************************************************/
182

183
void QLCInputChannel::setName(const QString& name)
11,961✔
184
{
185
    if (name == m_name)
11,961✔
186
        return;
×
187

188
    m_name = name;
11,961✔
189

190
    emit nameChanged();
11,961✔
191
}
192

193
QString QLCInputChannel::name() const
35✔
194
{
195
    return m_name;
35✔
196
}
197

198
/*********************************************************************
199
 * Slider/Knob movement behaviour specific methods
200
 *********************************************************************/
201

202
QLCInputChannel::MovementType QLCInputChannel::movementType() const
11✔
203
{
204
    return m_movementType;
11✔
205
}
206

207
void QLCInputChannel::setMovementType(QLCInputChannel::MovementType type)
10✔
208
{
209
    m_movementType = type;
10✔
210
}
10✔
211

212
int QLCInputChannel::movementSensitivity() const
10✔
213
{
214
    return m_movementSensitivity;
10✔
215
}
216

217
void QLCInputChannel::setMovementSensitivity(int value)
61✔
218
{
219
    m_movementSensitivity = value;
61✔
220
}
61✔
221

222
/*********************************************************************
223
 * Button behaviour specific methods
224
 *********************************************************************/
225

226
void QLCInputChannel::setSendExtraPress(bool enable)
79✔
227
{
228
    if (enable == m_sendExtraPress)
79✔
229
        return;
10✔
230

231
    m_sendExtraPress = enable;
69✔
232
    emit sendExtraPressChanged();
69✔
233
}
234

235
bool QLCInputChannel::sendExtraPress() const
14✔
236
{
237
    return m_sendExtraPress;
14✔
238
}
239

240
void QLCInputChannel::setRange(uchar lower, uchar upper)
619✔
241
{
242
    setLowerValue(lower);
619✔
243
    setUpperValue(upper);
619✔
244
}
619✔
245

246
uchar QLCInputChannel::lowerValue() const
13✔
247
{
248
    return m_lower;
13✔
249
}
250

251
void QLCInputChannel::setLowerValue(const uchar value)
619✔
252
{
253
    if (value == m_lower)
619✔
254
        return;
253✔
255

256
    m_lower = value;
366✔
257
    emit lowerValueChanged();
366✔
258
}
259

260
uchar QLCInputChannel::upperValue() const
13✔
261
{
262
    return m_upper;
13✔
263
}
264

265
void QLCInputChannel::setUpperValue(const uchar value)
619✔
266
{
267
    if (value == m_upper)
619✔
268
        return;
13✔
269

270
    m_upper = value;
606✔
271
    emit upperValueChanged();
606✔
272
}
273

274
/****************************************************************************
275
 * Load & Save
276
 ****************************************************************************/
277

278
bool QLCInputChannel::loadXML(QXmlStreamReader &root)
11,935✔
279
{
280
    if (root.isStartElement() == false || root.name() != KXMLQLCInputChannel)
11,935✔
281
    {
282
        qWarning() << Q_FUNC_INFO << "Channel node not found";
×
283
        return false;
×
284
    }
285

286
    while (root.readNextStartElement())
36,534✔
287
    {
288
        if (root.name() == KXMLQLCInputChannelName)
24,599✔
289
        {
290
            setName(root.readElementText());
11,935✔
291
        }
292
        else if (root.name() == KXMLQLCInputChannelType)
12,664✔
293
        {
294
            setType(stringToType(root.readElementText()));
11,935✔
295
        }
296
        else if (root.name() == KXMLQLCInputChannelExtraPress)
729✔
297
        {
298
            root.readElementText();
69✔
299
            setSendExtraPress(true);
69✔
300
        }
301
        else if (root.name() == KXMLQLCInputChannelMovement)
660✔
302
        {
303
            if (root.attributes().hasAttribute(KXMLQLCInputChannelSensitivity))
51✔
304
                setMovementSensitivity(root.attributes().value(KXMLQLCInputChannelSensitivity).toString().toInt());
51✔
305

306
            if (root.readElementText() == KXMLQLCInputChannelRelative)
51✔
307
                setMovementType(Relative);
×
308
        }
309
        else if (root.name() == KXMLQLCInputChannelFeedbacks)
609✔
310
        {
311
            uchar min = 0, max = UCHAR_MAX;
609✔
312

313
            if (root.attributes().hasAttribute(KXMLQLCInputChannelLowerValue))
609✔
314
                min = uchar(root.attributes().value(KXMLQLCInputChannelLowerValue).toString().toUInt());
366✔
315
            if (root.attributes().hasAttribute(KXMLQLCInputChannelUpperValue))
609✔
316
                max = uchar(root.attributes().value(KXMLQLCInputChannelUpperValue).toString().toUInt());
606✔
317

318
            setRange(min, max);
609✔
319
            root.skipCurrentElement();
609✔
320
        }
321
        else
322
        {
323
            qWarning() << Q_FUNC_INFO << "Unknown input channel tag" << root.name();
×
324
            root.skipCurrentElement();
×
325
        }
326
    }
327

328
    return true;
11,935✔
329
}
330

331
bool QLCInputChannel::saveXML(QXmlStreamWriter *doc, quint32 channelNumber) const
4✔
332
{
333
    if (doc == NULL || doc->device() == NULL)
4✔
334
        return false;
×
335

336
    doc->writeStartElement(KXMLQLCInputChannel);
4✔
337
    doc->writeAttribute(KXMLQLCInputChannelNumber,
4✔
338
                        QString("%1").arg(channelNumber));
8✔
339

340
    doc->writeTextElement(KXMLQLCInputChannelName, m_name);
4✔
341
    doc->writeTextElement(KXMLQLCInputChannelType, typeToString(m_type));
4✔
342
    if (sendExtraPress() == true)
4✔
343
        doc->writeTextElement(KXMLQLCInputChannelExtraPress, "True");
×
344

345
    /* Save only slider's relative movement */
346
    if ((type() == Slider || type() == Knob) && movementType() == Relative)
4✔
347
    {
348
        doc->writeStartElement(KXMLQLCInputChannelMovement);
×
349
        doc->writeAttribute(KXMLQLCInputChannelSensitivity, QString::number(movementSensitivity()));
×
350
        doc->writeCharacters(KXMLQLCInputChannelRelative);
×
351
        doc->writeEndElement();
×
352
    }
353
    else if (type() == Encoder)
4✔
354
    {
355
        doc->writeStartElement(KXMLQLCInputChannelMovement);
×
356
        doc->writeAttribute(KXMLQLCInputChannelSensitivity, QString::number(movementSensitivity()));
×
357
        doc->writeEndElement();
×
358
    }
359
    else if (type() == Button && (lowerValue() != 0 || upperValue() != UCHAR_MAX))
4✔
360
    {
361
        doc->writeStartElement(KXMLQLCInputChannelFeedbacks);
×
362
        if (lowerValue() != 0)
×
363
            doc->writeAttribute(KXMLQLCInputChannelLowerValue, QString::number(lowerValue()));
×
364
        if (upperValue() != UCHAR_MAX)
×
365
            doc->writeAttribute(KXMLQLCInputChannelUpperValue, QString::number(upperValue()));
×
366
        doc->writeEndElement();
×
367
    }
368

369
    doc->writeEndElement();
4✔
370
    return true;
4✔
371
}
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