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

mcallegari / qlcplus / 6567093872

18 Oct 2023 10:04PM UTC coverage: 28.038% (-0.02%) from 28.056%
6567093872

push

github

mcallegari
qmlui: fix qmake build

15332 of 54682 relevant lines covered (28.04%)

20313.58 hits per line

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

77.38
/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,864✔
57
{
58
}
7,864✔
59

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

64
void QLCInputChannel::setType(Type type)
11,954✔
65
{
66
    m_type = type;
11,954✔
67
    if (type == Encoder)
11,954✔
68
        m_movementSensitivity = 1;
52✔
69
    else
70
        m_movementSensitivity = 20;
11,902✔
71
}
11,954✔
72

73
QLCInputChannel::Type QLCInputChannel::type() const
807✔
74
{
75
    return m_type;
807✔
76
}
77

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

101
QLCInputChannel::Type QLCInputChannel::stringToType(const QString& type)
11,943✔
102
{
103
    if (type == KXMLQLCInputChannelButton)
11,943✔
104
        return Button;
7,165✔
105
    else if (type == KXMLQLCInputChannelKnob)
4,778✔
106
        return Knob;
1,900✔
107
    else if (type == KXMLQLCInputChannelEncoder)
2,878✔
108
        return Encoder;
52✔
109
    else if (type == KXMLQLCInputChannelSlider)
2,826✔
110
        return Slider;
2,803✔
111
    else if (type == KXMLQLCInputChannelPageUp)
23✔
112
        return NextPage;
10✔
113
    else if (type == KXMLQLCInputChannelPageDown)
13✔
114
        return PrevPage;
10✔
115
    else if (type == KXMLQLCInputChannelPageSet)
3✔
116
        return PageSet;
1✔
117
    else
118
        return NoType;
2✔
119
}
120

121
QStringList QLCInputChannel::types()
1✔
122
{
123
    QStringList list;
1✔
124
    list << KXMLQLCInputChannelSlider;
1✔
125
    list << KXMLQLCInputChannelKnob;
1✔
126
    list << KXMLQLCInputChannelEncoder;
1✔
127
    list << KXMLQLCInputChannelButton;
1✔
128
    list << KXMLQLCInputChannelPageUp;
1✔
129
    list << KXMLQLCInputChannelPageDown;
1✔
130
    list << KXMLQLCInputChannelPageSet;
1✔
131
    return list;
1✔
132
}
133

134
QIcon QLCInputChannel::typeToIcon(Type type)
×
135
{
136
    return QIcon(iconResource(type));
×
137
}
138

139
QIcon QLCInputChannel::stringToIcon(const QString& str)
×
140
{
141
    return typeToIcon(stringToType(str));
×
142
}
143

144
QString QLCInputChannel::iconResource(Type type, bool svg)
×
145
{
146
    QString prefix = svg ? "qrc" : "";
×
147
    QString ext = svg ? "svg" : "png";
×
148

149
    switch(type)
×
150
    {
151
        case Button: return QString("%1:/button.%2").arg(prefix, ext);
×
152
        case Knob: return QString("%1:/knob.%2").arg(prefix, ext);
×
153
        case Encoder: return QString("%1:/knob.%2").arg(prefix, ext);
×
154
        case Slider: return QString("%1:/slider.%2").arg(prefix, ext);
×
155
        case PrevPage: return QString("%1:/forward.%2").arg(prefix, ext);
×
156
        case NextPage: return QString("%1:/back.%2").arg(prefix, ext);
×
157
        case PageSet: return QString("%1:/star.%2").arg(prefix, ext);
×
158
        default: return QString();
×
159
    }
160

161
    return QString("%1:/other.%2").arg(prefix, ext);
162
}
163

164
QIcon QLCInputChannel::icon() const
×
165
{
166
    return typeToIcon(type());
×
167
}
168

169
/****************************************************************************
170
 * Name
171
 ****************************************************************************/
172

173
void QLCInputChannel::setName(const QString& name)
11,961✔
174
{
175
    m_name = name;
11,961✔
176
}
11,961✔
177

178
QString QLCInputChannel::name() const
35✔
179
{
180
    return m_name;
35✔
181
}
182

183
/*********************************************************************
184
 * Slider/Knob movement behaviour specific methods
185
 *********************************************************************/
186

187
QLCInputChannel::MovementType QLCInputChannel::movementType() const
11✔
188
{
189
    return m_movementType;
11✔
190
}
191

192
void QLCInputChannel::setMovementType(QLCInputChannel::MovementType type)
10✔
193
{
194
    m_movementType = type;
10✔
195
}
10✔
196

197
int QLCInputChannel::movementSensitivity() const
10✔
198
{
199
    return m_movementSensitivity;
10✔
200
}
201

202
void QLCInputChannel::setMovementSensitivity(int value)
61✔
203
{
204
    m_movementSensitivity = value;
61✔
205
}
61✔
206

207
/*********************************************************************
208
 * Button behaviour specific methods
209
 *********************************************************************/
210

211
void QLCInputChannel::setSendExtraPress(bool enable)
79✔
212
{
213
    m_sendExtraPress = enable;
79✔
214
}
79✔
215

216
bool QLCInputChannel::sendExtraPress() const
14✔
217
{
218
    return m_sendExtraPress;
14✔
219
}
220

221
void QLCInputChannel::setRange(uchar lower, uchar upper)
619✔
222
{
223
    m_lower = lower;
619✔
224
    m_upper = upper;
619✔
225
}
619✔
226

227
uchar QLCInputChannel::lowerValue() const
13✔
228
{
229
    return m_lower;
13✔
230
}
231

232
uchar QLCInputChannel::upperValue() const
13✔
233
{
234
    return m_upper;
13✔
235
}
236

237
/****************************************************************************
238
 * Load & Save
239
 ****************************************************************************/
240

241
bool QLCInputChannel::loadXML(QXmlStreamReader &root)
11,935✔
242
{
243
    if (root.isStartElement() == false || root.name() != KXMLQLCInputChannel)
11,935✔
244
    {
245
        qWarning() << Q_FUNC_INFO << "Channel node not found";
×
246
        return false;
×
247
    }
248

249
    while (root.readNextStartElement())
36,534✔
250
    {
251
        if (root.name() == KXMLQLCInputChannelName)
24,599✔
252
        {
253
            setName(root.readElementText());
11,935✔
254
        }
255
        else if (root.name() == KXMLQLCInputChannelType)
12,664✔
256
        {
257
            setType(stringToType(root.readElementText()));
11,935✔
258
        }
259
        else if (root.name() == KXMLQLCInputChannelExtraPress)
729✔
260
        {
261
            root.readElementText();
69✔
262
            setSendExtraPress(true);
69✔
263
        }
264
        else if (root.name() == KXMLQLCInputChannelMovement)
660✔
265
        {
266
            if (root.attributes().hasAttribute(KXMLQLCInputChannelSensitivity))
51✔
267
                setMovementSensitivity(root.attributes().value(KXMLQLCInputChannelSensitivity).toString().toInt());
51✔
268

269
            if (root.readElementText() == KXMLQLCInputChannelRelative)
51✔
270
                setMovementType(Relative);
×
271
        }
272
        else if (root.name() == KXMLQLCInputChannelFeedbacks)
609✔
273
        {
274
            uchar min = 0, max = UCHAR_MAX;
609✔
275

276
            if (root.attributes().hasAttribute(KXMLQLCInputChannelLowerValue))
609✔
277
                min = uchar(root.attributes().value(KXMLQLCInputChannelLowerValue).toString().toUInt());
366✔
278
            if (root.attributes().hasAttribute(KXMLQLCInputChannelUpperValue))
609✔
279
                max = uchar(root.attributes().value(KXMLQLCInputChannelUpperValue).toString().toUInt());
606✔
280

281
            setRange(min, max);
609✔
282
            root.skipCurrentElement();
609✔
283
        }
284
        else
285
        {
286
            qWarning() << Q_FUNC_INFO << "Unknown input channel tag" << root.name();
×
287
            root.skipCurrentElement();
×
288
        }
289
    }
290

291
    return true;
11,935✔
292
}
293

294
bool QLCInputChannel::saveXML(QXmlStreamWriter *doc, quint32 channelNumber) const
4✔
295
{
296
    if (doc == NULL || doc->device() == NULL)
4✔
297
        return false;
×
298

299
    doc->writeStartElement(KXMLQLCInputChannel);
4✔
300
    doc->writeAttribute(KXMLQLCInputChannelNumber,
4✔
301
                        QString("%1").arg(channelNumber));
8✔
302

303
    doc->writeTextElement(KXMLQLCInputChannelName, m_name);
4✔
304
    doc->writeTextElement(KXMLQLCInputChannelType, typeToString(m_type));
4✔
305
    if (sendExtraPress() == true)
4✔
306
        doc->writeTextElement(KXMLQLCInputChannelExtraPress, "True");
×
307

308
    /* Save only slider's relative movement */
309
    if ((type() == Slider || type() == Knob) && movementType() == Relative)
4✔
310
    {
311
        doc->writeStartElement(KXMLQLCInputChannelMovement);
×
312
        doc->writeAttribute(KXMLQLCInputChannelSensitivity, QString::number(movementSensitivity()));
×
313
        doc->writeCharacters(KXMLQLCInputChannelRelative);
×
314
        doc->writeEndElement();
×
315
    }
316
    else if (type() == Encoder)
4✔
317
    {
318
        doc->writeStartElement(KXMLQLCInputChannelMovement);
×
319
        doc->writeAttribute(KXMLQLCInputChannelSensitivity, QString::number(movementSensitivity()));
×
320
        doc->writeEndElement();
×
321
    }
322
    else if (type() == Button && (lowerValue() != 0 || upperValue() != UCHAR_MAX))
4✔
323
    {
324
        doc->writeStartElement(KXMLQLCInputChannelFeedbacks);
×
325
        if (lowerValue() != 0)
×
326
            doc->writeAttribute(KXMLQLCInputChannelLowerValue, QString::number(lowerValue()));
×
327
        if (upperValue() != UCHAR_MAX)
×
328
            doc->writeAttribute(KXMLQLCInputChannelUpperValue, QString::number(upperValue()));
×
329
        doc->writeEndElement();
×
330
    }
331

332
    doc->writeEndElement();
4✔
333
    return true;
4✔
334
}
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