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

mcallegari / qlcplus / 7237666926

17 Dec 2023 09:35AM UTC coverage: 32.066% (+4.0%) from 28.056%
7237666926

push

github

mcallegari
Merge branch 'master' into filedialog

190 of 510 new or added lines in 28 files covered. (37.25%)

34 existing lines in 20 files now uncovered.

15171 of 47312 relevant lines covered (32.07%)

23729.73 hits per line

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

78.49
/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

28
/****************************************************************************
29
 * Initialization
30
 ****************************************************************************/
31

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

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

52
    return copy;
10✔
53
}
54

55
QLCInputChannel::~QLCInputChannel()
8,092✔
56
{
57
}
8,092✔
58

59
/****************************************************************************
60
 * Type
61
 ****************************************************************************/
62

63
void QLCInputChannel::setType(Type type)
12,308✔
64
{
65
    if (type == m_type)
12,308✔
66
        return;
7,436✔
67

68
    m_type = type;
4,872✔
69
    if (type == Encoder)
4,872✔
70
        m_movementSensitivity = 1;
112✔
71
    else
72
        m_movementSensitivity = 20;
4,760✔
73

74
    emit typeChanged();
4,872✔
75
}
76

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

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

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

110
QLCInputChannel::Type QLCInputChannel::stringToType(const QString& type)
12,297✔
111
{
112
    if (type == KXMLQLCInputChannelButton)
12,297✔
113
        return Button;
7,429✔
114
    else if (type == KXMLQLCInputChannelKnob)
4,868✔
115
        return Knob;
1,900✔
116
    else if (type == KXMLQLCInputChannelEncoder)
2,968✔
117
        return Encoder;
112✔
118
    else if (type == KXMLQLCInputChannelSlider)
2,856✔
119
        return Slider;
2,833✔
120
    else if (type == KXMLQLCInputChannelPageUp)
23✔
121
        return NextPage;
10✔
122
    else if (type == KXMLQLCInputChannelPageDown)
13✔
123
        return PrevPage;
10✔
124
    else if (type == KXMLQLCInputChannelPageSet)
3✔
125
        return PageSet;
1✔
126
    else
127
        return NoType;
2✔
128
}
129

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

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

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

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

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

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

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

178
/****************************************************************************
179
 * Name
180
 ****************************************************************************/
181

182
void QLCInputChannel::setName(const QString& name)
12,315✔
183
{
184
    if (name == m_name)
12,315✔
NEW
185
        return;
×
186

187
    m_name = name;
12,315✔
188

189
    emit nameChanged();
12,315✔
190
}
191

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

285
    while (root.readNextStartElement())
37,659✔
286
    {
287
        if (root.name() == KXMLQLCInputChannelName)
25,370✔
288
        {
289
            setName(root.readElementText());
12,289✔
290
        }
291
        else if (root.name() == KXMLQLCInputChannelType)
13,081✔
292
        {
293
            setType(stringToType(root.readElementText()));
12,289✔
294
        }
295
        else if (root.name() == KXMLQLCInputChannelExtraPress)
792✔
296
        {
297
            root.readElementText();
69✔
298
            setSendExtraPress(true);
69✔
299
        }
300
        else if (root.name() == KXMLQLCInputChannelMovement)
723✔
301
        {
302
            if (root.attributes().hasAttribute(KXMLQLCInputChannelSensitivity))
114✔
303
                setMovementSensitivity(root.attributes().value(KXMLQLCInputChannelSensitivity).toString().toInt());
114✔
304

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

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

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

327
    return true;
12,289✔
328
}
329

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

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

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

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

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