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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

0.0
/ui/src/virtualconsole/vcxypadpreset.cpp
1
/*
2
  Q Light Controller Plus
3
  vcxypadpreset.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 "vcxypadpreset.h"
25
#include "vcwidget.h"
26
#include "function.h"
27

28
VCXYPadPreset::VCXYPadPreset(quint8 id)
×
29
    : m_id(id)
×
30
    , m_name(QString())
×
31
    , m_dmxPos(QPointF())
×
32
    , m_funcID(Function::invalidId())
×
33
{
34

35
}
×
36

37
VCXYPadPreset::VCXYPadPreset(const VCXYPadPreset &other)
×
38
{
39
    *this = other;
×
40
}
×
41

42
VCXYPadPreset::~VCXYPadPreset()
×
43
{
44
}
×
45

46
QString VCXYPadPreset::getColor() const
×
47
{
48
    switch(m_type)
×
49
    {
50
        case EFX: return ("#BBBB8D"); break;
×
51
        case Scene: return ("#BB8E8E"); break;
×
52
        case FixtureGroup: return ("#95BB95"); break;
×
53
        case Position:
×
54
        default:
55
            return ("#BBBBBB");
×
56
        break;
57
    }
58
}
59

60
void VCXYPadPreset::setFunctionID(quint32 id)
×
61
{
62
    m_funcID = id;
×
63
}
×
64

65
quint32 VCXYPadPreset::functionID() const
×
66
{
67
    return m_funcID;
×
68
}
69

70
void VCXYPadPreset::setPosition(QPointF pos)
×
71
{
72
    m_dmxPos = pos;
×
73
}
×
74

75
QPointF VCXYPadPreset::position() const
×
76
{
77
    return m_dmxPos;
×
78
}
79

80
void VCXYPadPreset::setFixtureGroup(QList<GroupHead> heads)
×
81
{
82
    m_fxGroup = heads;
×
83
}
×
84

85
QList<GroupHead> VCXYPadPreset::fixtureGroup() const
×
86
{
87
    return m_fxGroup;
×
88
}
89

90
VCXYPadPreset &VCXYPadPreset::operator=(const VCXYPadPreset &vcpp)
×
91
{
92
    if (this != &vcpp)
×
93
    {
94
        m_id = vcpp.m_id;
×
95
        m_type = vcpp.m_type;
×
96
        m_name = vcpp.m_name;
×
97
        m_dmxPos = vcpp.m_dmxPos;
×
98
        m_funcID = vcpp.m_funcID;
×
99
        m_fxGroup = vcpp.m_fxGroup;
×
100
        m_keySequence = vcpp.m_keySequence;
×
101

102
        if (vcpp.m_inputSource != NULL)
×
103
        {
104
            m_inputSource = QSharedPointer<QLCInputSource>(new QLCInputSource(vcpp.m_inputSource->universe(),
×
105
                                                   vcpp.m_inputSource->channel()));
×
106

107
            m_inputSource->setFeedbackValue(QLCInputFeedback::LowerValue, vcpp.m_inputSource->feedbackValue(QLCInputFeedback::LowerValue));
×
108
            m_inputSource->setFeedbackValue(QLCInputFeedback::UpperValue, vcpp.m_inputSource->feedbackValue(QLCInputFeedback::UpperValue));
×
109
        }
110
    }
111
    return *this;
×
112
}
113

114
bool VCXYPadPreset::operator<(const VCXYPadPreset &right) const
×
115
{
116
    return m_id < right.m_id;
×
117
}
118

119
bool VCXYPadPreset::compare(const VCXYPadPreset *left, const VCXYPadPreset *right)
×
120
{
121
    return *left < *right;
×
122
}
123

124
QString VCXYPadPreset::typeToString(VCXYPadPreset::PresetType type)
×
125
{
126
    if (type == EFX)
×
127
        return "EFX";
×
128
    else if (type == Scene)
×
129
        return "Scene";
×
130
    else if (type == FixtureGroup)
×
131
        return "FixtureGroup";
×
132

133
    return "Position";
×
134
}
135

136
VCXYPadPreset::PresetType VCXYPadPreset::stringToType(QString str)
×
137
{
138
    if (str == "EFX")
×
139
        return EFX;
×
140
    else if (str == "Scene")
×
141
        return Scene;
×
142
    else if (str == "FixtureGroup")
×
143
        return FixtureGroup;
×
144

145
    return Position;
×
146
}
147

148
/************************************************************************
149
 * Load & Save
150
 ***********************************************************************/
151

152
bool VCXYPadPreset::loadXML(QXmlStreamReader &root)
×
153
{
154
    if (root.name() != KXMLQLCVCXYPadPreset)
×
155
    {
156
        qWarning() << Q_FUNC_INFO << "Matrix control node not found";
×
157
        return false;
×
158
    }
159

160
    if (root.attributes().hasAttribute(KXMLQLCVCXYPadPresetID) == false)
×
161
    {
162
        qWarning() << Q_FUNC_INFO << "XYPad Preset ID not found";
×
163
        return false;
×
164
    }
165

166
    m_id = root.attributes().value(KXMLQLCVCXYPadPresetID).toString().toUInt();
×
167

168
    QPointF pos;
×
169
    bool hasPosition = false;
×
170

171
    /* Children */
172
    while (root.readNextStartElement())
×
173
    {
174
        if (root.name() == KXMLQLCVCXYPadPresetType)
×
175
        {
176
            m_type = stringToType(root.readElementText());
×
177
        }
178
        else if (root.name() == KXMLQLCVCXYPadPresetName)
×
179
        {
180
            m_name = root.readElementText();
×
181
        }
182
        else if (root.name() == KXMLQLCVCXYPadPresetFuncID)
×
183
        {
184
            setFunctionID(root.readElementText().toUInt());
×
185
        }
186
        else if (root.name() == KXMLQLCVCXYPadPresetXPos)
×
187
        {
188
            pos.setX(QString(root.readElementText()).toFloat());
×
189
            hasPosition = true;
×
190
        }
191
        else if (root.name() == KXMLQLCVCXYPadPresetYPos)
×
192
        {
193
            pos.setY(QString(root.readElementText()).toFloat());
×
194
            hasPosition = true;
×
195
        }
196
        else if (root.name() == KXMLQLCVCXYPadPresetFixture)
×
197
        {
198
            quint32 fxID = Fixture::invalidId();
×
199
            int head = -1;
×
200
            QXmlStreamAttributes attrs = root.attributes();
×
201

202
            if (attrs.hasAttribute(KXMLQLCVCXYPadPresetFixtureID))
×
203
                fxID = attrs.value(KXMLQLCVCXYPadPresetFixtureID).toString().toUInt();
×
204
            if (attrs.hasAttribute(KXMLQLCVCXYPadPresetFixtureHead))
×
205
                head = attrs.value(KXMLQLCVCXYPadPresetFixtureHead).toString().toInt();
×
206

207
            if (fxID != Fixture::invalidId() && head != -1)
×
208
                m_fxGroup.append(GroupHead(fxID, head));
×
209
            root.skipCurrentElement();
×
210
        }
×
211
        else if (root.name() == KXMLQLCVCWidgetInput)
×
212
        {
213
            m_inputSource = VCWidget::getXMLInput(root);
×
214
            root.skipCurrentElement();
×
215
        }
216
        else if (root.name() == KXMLQLCVCWidgetKey)
×
217
        {
218
            m_keySequence = VCWidget::stripKeySequence(QKeySequence(root.readElementText()));
×
219
        }
220
        else
221
        {
222
            qWarning() << Q_FUNC_INFO << "Unknown VCMatrixControl tag:" << root.name().toString();
×
223
            root.skipCurrentElement();
×
224
        }
225
    }
226

227
    if (hasPosition)
×
228
        m_dmxPos = pos;
×
229

230
    return true;
×
231
}
232

233
bool VCXYPadPreset::saveXML(QXmlStreamWriter *doc)
×
234
{
235
    Q_ASSERT(doc != NULL);
×
236

237
    doc->writeStartElement(KXMLQLCVCXYPadPreset);
×
238
    doc->writeAttribute(KXMLQLCVCXYPadPresetID, QString::number(m_id));
×
239

240
    /* Preset type */
241
    doc->writeTextElement(KXMLQLCVCXYPadPresetType, typeToString(m_type));
×
242
    /* Preset name */
243
    doc->writeTextElement(KXMLQLCVCXYPadPresetName, m_name);
×
244

245
    if (m_type == EFX || m_type == Scene)
×
246
    {
247
        doc->writeTextElement(KXMLQLCVCXYPadPresetFuncID, QString::number(m_funcID));
×
248
    }
249
    else if (m_type == Position)
×
250
    {
251
        doc->writeTextElement(KXMLQLCVCXYPadPresetXPos, QString::number(m_dmxPos.x()));
×
252
        doc->writeTextElement(KXMLQLCVCXYPadPresetYPos, QString::number(m_dmxPos.y()));
×
253
    }
254
    else if (m_type == FixtureGroup)
×
255
    {
256
        foreach (GroupHead gh, fixtureGroup())
×
257
        {
258
            doc->writeStartElement(KXMLQLCVCXYPadPresetFixture);
×
259
            doc->writeAttribute(KXMLQLCVCXYPadPresetFixtureID, QString::number(gh.fxi));
×
260
            doc->writeAttribute(KXMLQLCVCXYPadPresetFixtureHead, QString::number(gh.head));
×
261
            doc->writeEndElement();
×
262
        }
×
263
    }
264

265
    /* External input source */
266
    if (!m_inputSource.isNull() && m_inputSource->isValid())
×
267
        VCWidget::saveXMLInput(doc, m_inputSource);
×
268

269
    /* Key sequence */
270
    if (m_keySequence.isEmpty() == false)
×
271
        doc->writeTextElement(KXMLQLCVCWidgetKey, m_keySequence.toString());
×
272

273
    /* End the <Preset> tag */
274
    doc->writeEndElement();
×
275

276
    return true;
×
277
}
278

279

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