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

mcallegari / qlcplus / 6683238402

29 Oct 2023 12:10PM UTC coverage: 28.07%. Remained the same
6683238402

push

github

mcallegari
engine: fix build

15385 of 54809 relevant lines covered (28.07%)

20267.63 hits per line

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

97.73
/ui/src/virtualconsole/vcproperties.cpp
1
/*
2
  Q Light Controller Plus
3
  vcproperties.cpp
4

5
  Copyright (c) Heikki Junnila
6
                Massimo Callegari
7

8
  Licensed under the Apache License, Version 2.0 (the "License");
9
  you may not use this file except in compliance with the License.
10
  You may obtain a copy of the License at
11

12
      http://www.apache.org/licenses/LICENSE-2.0.txt
13

14
  Unless required by applicable law or agreed to in writing, software
15
  distributed under the License is distributed on an "AS IS" BASIS,
16
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
  See the License for the specific language governing permissions and
18
  limitations under the License.
19
*/
20

21
#include <QXmlStreamReader>
22
#include <QXmlStreamWriter>
23
#include <QWidget>
24
#include <QDebug>
25

26
#include "inputoutputmap.h"
27
#include "vcproperties.h"
28
#include "qlcchannel.h"
29

30
/*****************************************************************************
31
 * Properties Initialization
32
 *****************************************************************************/
33

34
VCProperties::VCProperties()
83✔
35
    : m_size(QSize(1920, 1080))
36

37
    , m_gmChannelMode(GrandMaster::Intensity)
38
    , m_gmValueMode(GrandMaster::Reduce)
39
    , m_gmSliderMode(GrandMaster::Normal)
40
    , m_gmInputUniverse(InputOutputMap::invalidUniverse())
166✔
41
    , m_gmInputChannel(QLCChannel::invalid())
83✔
42
{
43
}
83✔
44

45
VCProperties::VCProperties(const VCProperties& properties)
156✔
46
    : m_size(properties.m_size)
47

48
    , m_gmChannelMode(properties.m_gmChannelMode)
156✔
49
    , m_gmValueMode(properties.m_gmValueMode)
156✔
50
    , m_gmSliderMode(properties.m_gmSliderMode)
156✔
51
    , m_gmInputUniverse(properties.m_gmInputUniverse)
156✔
52
    , m_gmInputChannel(properties.m_gmInputChannel)
156✔
53
{
54
}
156✔
55

56
VCProperties::~VCProperties()
239✔
57
{
58
}
239✔
59

60
VCProperties &VCProperties::operator=(const VCProperties &props)
4✔
61
{
62
    if (this != &props)
4✔
63
    {
64
        m_size = props.m_size;
4✔
65
        m_gmChannelMode = props.m_gmChannelMode;
4✔
66
        m_gmValueMode = props.m_gmValueMode;
4✔
67
        m_gmSliderMode = props.m_gmSliderMode;
4✔
68
        m_gmInputUniverse = props.m_gmInputUniverse;
4✔
69
        m_gmInputChannel = props.m_gmInputChannel;
4✔
70
    }
71

72
    return *this;
4✔
73
}
74

75
/*****************************************************************************
76
 * Size
77
 *****************************************************************************/
78

79
void VCProperties::setSize(const QSize& size)
3✔
80
{
81
    m_size = size;
3✔
82
}
3✔
83

84
QSize VCProperties::size() const
81✔
85
{
86
    return m_size;
81✔
87
}
88

89
/*****************************************************************************
90
 * Grand Master
91
 *****************************************************************************/
92

93
void VCProperties::setGrandMasterChannelMode(GrandMaster::ChannelMode mode)
79✔
94
{
95
    m_gmChannelMode = mode;
79✔
96
}
79✔
97

98
GrandMaster::ChannelMode VCProperties::grandMasterChannelMode() const
3✔
99
{
100
    return m_gmChannelMode;
3✔
101
}
102

103
void VCProperties::setGrandMasterValueMode(GrandMaster::ValueMode mode)
79✔
104
{
105
    m_gmValueMode = mode;
79✔
106
}
79✔
107

108
GrandMaster::ValueMode VCProperties::grandMasterValueMode() const
3✔
109
{
110
    return m_gmValueMode;
3✔
111
}
112

113
void VCProperties::setGrandMasterSliderMode(GrandMaster::SliderMode mode)
1✔
114
{
115
    m_gmSliderMode = mode;
1✔
116
}
1✔
117

118
GrandMaster::SliderMode VCProperties::grandMasterSlideMode() const
×
119
{
120
    return m_gmSliderMode;
×
121
}
122

123
void VCProperties::setGrandMasterInputSource(quint32 universe, quint32 channel)
78✔
124
{
125
    m_gmInputUniverse = universe;
78✔
126
    m_gmInputChannel = channel;
78✔
127
}
78✔
128

129
quint32 VCProperties::grandMasterInputUniverse() const
78✔
130
{
131
    return m_gmInputUniverse;
78✔
132
}
133

134
quint32 VCProperties::grandMasterInputChannel() const
78✔
135
{
136
    return m_gmInputChannel;
78✔
137
}
138

139
/*****************************************************************************
140
 * Load & Save
141
 *****************************************************************************/
142

143
bool VCProperties::loadXML(QXmlStreamReader &root)
4✔
144
{
145
    if (root.name() != KXMLQLCVCProperties)
4✔
146
    {
147
        qWarning() << Q_FUNC_INFO << "Virtual console properties node not found";
1✔
148
        return false;
1✔
149
    }
150

151
    QString str;
3✔
152
    while (root.readNextStartElement())
11✔
153
    {
154
        if (root.name() == KXMLQLCVCPropertiesSize)
8✔
155
        {
156
            QSize sz;
3✔
157

158
            /* Width */
159
            str = root.attributes().value(KXMLQLCVCPropertiesSizeWidth).toString();
3✔
160
            if (str.isEmpty() == false)
3✔
161
                sz.setWidth(str.toInt());
3✔
162

163
            /* Height */
164
            str = root.attributes().value(KXMLQLCVCPropertiesSizeHeight).toString();
3✔
165
            if (str.isEmpty() == false)
3✔
166
                sz.setHeight(str.toInt());
3✔
167

168
            /* Set size if both are valid */
169
            if (sz.isValid() == true)
3✔
170
                setSize(sz);
3✔
171
            root.skipCurrentElement();
3✔
172
        }
173
        else if (root.name() == KXMLQLCVCPropertiesGrandMaster)
5✔
174
        {
175
            QXmlStreamAttributes attrs = root.attributes();
6✔
176

177
            str = attrs.value(KXMLQLCVCPropertiesGrandMasterChannelMode).toString();
3✔
178
            setGrandMasterChannelMode(GrandMaster::stringToChannelMode(str));
3✔
179

180
            str = attrs.value(KXMLQLCVCPropertiesGrandMasterValueMode).toString();
3✔
181
            setGrandMasterValueMode(GrandMaster::stringToValueMode(str));
3✔
182

183
            if (attrs.hasAttribute(KXMLQLCVCPropertiesGrandMasterSliderMode))
3✔
184
            {
185
                str = attrs.value(KXMLQLCVCPropertiesGrandMasterSliderMode).toString();
1✔
186
                setGrandMasterSliderMode(GrandMaster::stringToSliderMode(str));
1✔
187
            }
188

189
            QXmlStreamReader::TokenType tType = root.readNext();
3✔
190
            if (tType == QXmlStreamReader::Characters)
3✔
191
                tType = root.readNext();
×
192

193
            // check if there is a Input tag defined
194
            if (tType == QXmlStreamReader::StartElement)
3✔
195
            {
196
                if (root.name() == KXMLQLCVCPropertiesInput)
2✔
197
                {
198
                    quint32 universe = InputOutputMap::invalidUniverse();
2✔
199
                    quint32 channel = QLCChannel::invalid();
2✔
200
                    /* External input */
201
                    if (loadXMLInput(root, &universe, &channel) == true)
2✔
202
                        setGrandMasterInputSource(universe, channel);
2✔
203
                }
204
                root.skipCurrentElement();
2✔
205
            }
206
        }
207
        else
208
        {
209
            qWarning() << Q_FUNC_INFO << "Unknown virtual console property tag:"
2✔
210
                       << root.name().toString();
2✔
211
            root.skipCurrentElement();
2✔
212
        }
213
    }
214

215
    return true;
3✔
216
}
217

218
bool VCProperties::saveXML(QXmlStreamWriter *doc) const
1✔
219
{
220
    Q_ASSERT(doc != NULL);
1✔
221

222
    /* Properties entry */
223
    doc->writeStartElement(KXMLQLCVCProperties);
1✔
224

225
    /* Size */
226
    doc->writeStartElement(KXMLQLCVCPropertiesSize);
1✔
227
    doc->writeAttribute(KXMLQLCVCPropertiesSizeWidth, QString::number(size().width()));
1✔
228
    doc->writeAttribute(KXMLQLCVCPropertiesSizeHeight, QString::number(size().height()));
1✔
229
    doc->writeEndElement();
1✔
230

231
    /***********************
232
     * Grand Master slider *
233
     ***********************/
234
    doc->writeStartElement(KXMLQLCVCPropertiesGrandMaster);
1✔
235

236
    /* Channel mode */
237
    doc->writeAttribute(KXMLQLCVCPropertiesGrandMasterChannelMode,
1✔
238
                     GrandMaster::channelModeToString(m_gmChannelMode));
2✔
239

240
    /* Value mode */
241
    doc->writeAttribute(KXMLQLCVCPropertiesGrandMasterValueMode,
1✔
242
                     GrandMaster::valueModeToString(m_gmValueMode));
2✔
243

244
    /* Slider mode */
245
    doc->writeAttribute(KXMLQLCVCPropertiesGrandMasterSliderMode,
1✔
246
                     GrandMaster::sliderModeToString(m_gmSliderMode));
2✔
247

248
    /* Grand Master external input */
249
    if (m_gmInputUniverse != InputOutputMap::invalidUniverse() &&
2✔
250
        m_gmInputChannel != QLCChannel::invalid())
1✔
251
    {
252
        doc->writeStartElement(KXMLQLCVCPropertiesInput);
1✔
253
        doc->writeAttribute(KXMLQLCVCPropertiesInputUniverse,
1✔
254
                            QString("%1").arg(m_gmInputUniverse));
2✔
255
        doc->writeAttribute(KXMLQLCVCPropertiesInputChannel,
1✔
256
                            QString("%1").arg(m_gmInputChannel));
2✔
257
        doc->writeEndElement();
1✔
258
    }
259
    /* End the <GrandMaster> tag */
260
    doc->writeEndElement();
1✔
261

262
    /* End the <Properties> tag */
263
    doc->writeEndElement();
1✔
264

265
    return true;
1✔
266
}
267

268
bool VCProperties::loadXMLInput(QXmlStreamReader &root, quint32* universe, quint32* channel)
5✔
269
{
270
    /* External input */
271
    if (root.name() != KXMLQLCVCPropertiesInput)
5✔
272
        return false;
1✔
273

274
    QXmlStreamAttributes attrs = root.attributes();
8✔
275

276
    /* Universe */
277
    QString str = attrs.value(KXMLQLCVCPropertiesInputUniverse).toString();
12✔
278
    if (str.isEmpty() == false)
4✔
279
        *universe = str.toUInt();
3✔
280
    else
281
        *universe = InputOutputMap::invalidUniverse();
1✔
282

283
    /* Channel */
284
    str = attrs.value(KXMLQLCVCPropertiesInputChannel).toString();
4✔
285
    if (str.isEmpty() == false)
4✔
286
        *channel = str.toUInt();
3✔
287
    else
288
        *channel = QLCChannel::invalid();
1✔
289

290
    root.skipCurrentElement();
4✔
291

292
    /* Verdict */
293
    if (*universe != InputOutputMap::invalidUniverse() &&
7✔
294
        *channel != QLCChannel::invalid())
3✔
295
    {
296
        return true;
3✔
297
    }
298
    else
299
    {
300
        return false;
1✔
301
    }
302
}
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