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

mcallegari / qlcplus / 6796513551

08 Nov 2023 09:52AM UTC coverage: 28.09% (+0.02%) from 28.067%
6796513551

Pull #1462

github

web-flow
Merge b9be672c4 into 63469273b
Pull Request #1462: Overriding flash functionality

28 of 42 new or added lines in 5 files covered. (66.67%)

2 existing lines in 1 file now uncovered.

15407 of 54849 relevant lines covered (28.09%)

20304.0 hits per line

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

0.0
/engine/src/channelmodifier.cpp
1
/*
2
  Q Light Controller Plus
3
  channelmodifier.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
#include <QXmlStreamReader>
20
#include <QXmlStreamWriter>
21
#include <QDebug>
22

23
#include "channelmodifier.h"
24
#include "qlcfile.h"
25

26
ChannelModifier::ChannelModifier()
×
27
{
28
    m_values.fill(0, 256);
×
29
    m_name = QString();
×
30
    m_type = UserTemplate;
×
31
}
×
32

33
void ChannelModifier::setName(QString name)
×
34
{
35
    m_name = name;
×
36
}
×
37

38
QString ChannelModifier::name() const
×
39
{
40
    return m_name;
×
41
}
42

43
void ChannelModifier::setType(ChannelModifier::Type type)
×
44
{
45
    m_type = type;
×
46
}
×
47

48
ChannelModifier::Type ChannelModifier::type() const
×
49
{
50
    return m_type;
×
51
}
52

53
void ChannelModifier::setModifierMap(QList<QPair<uchar, uchar> > map)
×
54
{
55
    m_map = map;
×
56
    m_values.fill(0, 256);
×
57
    QPair<uchar, uchar> lastDMXPair;
×
58
    for (int i = 0; i < m_map.count(); i++)
×
59
    {
60
        QPair<uchar, uchar> dmxPair = m_map.at(i);
×
61
        m_values[dmxPair.first] = dmxPair.second;
×
62
        if (i != 0)
×
63
        {
64
            // calculate the increment to go from one pair to another
65
            // in a linear progression
66
            float dmxInc = 0;
×
67
            if (dmxPair.first - lastDMXPair.first > 0)
×
68
                dmxInc = (float)(dmxPair.second - lastDMXPair.second) / (float)(dmxPair.first - lastDMXPair.first);
×
69

70
            // use a float variable here to be as more accurate as possible
71
            float floatVal = lastDMXPair.second;
×
72
            for (int p = lastDMXPair.first; p < dmxPair.first; p++)
×
73
            {
74
                // the float value is rounded here but it
75
                // is what we wanted
76
                m_values[p] = floatVal;
×
77
                floatVal += dmxInc;
×
78
            }
79
        }
80
        lastDMXPair = dmxPair;
×
81
    }
82
// Enable the following to display the template full range of value
83
/*
84
    qDebug() << "Template:" << m_name;
85
    for (int d = 0; d < m_values.count(); d++)
86
        qDebug() << "Pos:" << d << "val:" << QString::number((uchar)m_values.at(d));
87
*/
88
}
×
89

90
QList< QPair<uchar, uchar> > ChannelModifier::modifierMap() const
×
91
{
92
    return m_map;
×
93
}
94

95
uchar ChannelModifier::getValue(uchar dmxValue)
×
96
{
97
    return m_values.at(dmxValue);
×
98
}
99

100
QFile::FileError ChannelModifier::saveXML(const QString &fileName)
×
101
{
102
    QFile::FileError error;
103

104
    if (fileName.isEmpty() == true)
×
105
        return QFile::OpenError;
×
106

107
    QFile file(fileName);
×
108
    if (file.open(QIODevice::WriteOnly) == false)
×
109
        return file.error();
×
110

111
    QXmlStreamWriter doc(&file);
×
112
    doc.setAutoFormatting(true);
×
113
    doc.setAutoFormattingIndent(1);
×
114
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
115
    doc.setCodec("UTF-8");
×
116
#endif
117
    QLCFile::writeXMLHeader(&doc, KXMLQLCChannelModifierDocument);
×
118

119
    doc.writeTextElement(KXMLQLCChannelModName, m_name);
×
120

121
    qDebug() << "Got map with" << m_map.count() << "handlers";
×
122
    for(int i = 0; i < m_map.count(); i++)
×
123
    {
124
        QPair<uchar, uchar> mapElement = m_map.at(i);
×
125
        doc.writeStartElement(KXMLQLCChannelModHandler);
×
126
        doc.writeAttribute(KXMLQLCChannelModOriginalDMX, QString::number(mapElement.first));
×
127
        doc.writeAttribute(KXMLQLCChannelModModifiedDMX, QString::number(mapElement.second));
×
128
        doc.writeEndElement();
×
129
    }
130

131
    /* End the document and close all the open elements */
132
    error = QFile::NoError;
×
133
    doc.writeEndDocument();
×
134
    file.close();
×
135

136
    return error;
×
137
}
138

139
QFile::FileError ChannelModifier::loadXML(const QString &fileName, Type type)
×
140
{
141
    QFile::FileError error = QFile::NoError;
×
142

143
    if (fileName.isEmpty() == true)
×
144
        return QFile::OpenError;
×
145

146
    QXmlStreamReader *doc = QLCFile::getXMLReader(fileName);
×
147
    if (doc == NULL || doc->device() == NULL || doc->hasError())
×
148
    {
149
        qWarning() << Q_FUNC_INFO << "Unable to read from" << fileName;
×
150
        return QFile::ReadError;
×
151
    }
152

153
    while (!doc->atEnd())
×
154
    {
155
        if (doc->readNext() == QXmlStreamReader::DTD)
×
156
            break;
×
157
    }
158
    if (doc->hasError())
×
159
    {
160
        QLCFile::releaseXMLReader(doc);
×
161
        return QFile::ResourceError;
×
162
    }
163

164
    QList< QPair<uchar, uchar> > modMap;
×
165

166
    if (doc->dtdName() == KXMLQLCChannelModifierDocument)
×
167
    {
168
        if (doc->readNextStartElement() == false)
×
169
            return QFile::ResourceError;
×
170

171
        if (doc->name() == KXMLQLCChannelModifierDocument)
×
172
        {
173
            while (doc->readNextStartElement())
×
174
            {
175
                if (doc->name() == KXMLQLCChannelModName)
×
176
                {
177
                    setName(doc->readElementText());
×
178
                }
179
                else if(doc->name() == KXMLQLCChannelModHandler)
×
180
                {
181
                    QPair <uchar, uchar> dmxPair(0, 0);
×
182
                    QXmlStreamAttributes attrs = doc->attributes();
×
183
                    if (attrs.hasAttribute(KXMLQLCChannelModOriginalDMX))
×
184
                        dmxPair.first = attrs.value(KXMLQLCChannelModOriginalDMX).toString().toUInt();
×
185
                    if (attrs.hasAttribute(KXMLQLCChannelModModifiedDMX))
×
186
                        dmxPair.second = attrs.value(KXMLQLCChannelModModifiedDMX).toString().toUInt();
×
187
                    modMap.append(dmxPair);
×
188
                    doc->skipCurrentElement();
×
189
                }
190
                else if (doc->name() == KXMLQLCCreator)
×
191
                {
192
                    /* Ignore creator information */
193
                    doc->skipCurrentElement();
×
194
                }
195
                else
196
                {
197
                    qWarning() << Q_FUNC_INFO << "Unknown ChannelModifier tag:" << doc->name();
×
198
                    doc->skipCurrentElement();
×
199
                }
200
            }
201
        }
202
    }
203
    if (modMap.count() > 0)
×
204
    {
205
        setType(type);
×
206
        setModifierMap(modMap);
×
207
    }
208

209
    QLCFile::releaseXMLReader(doc);
×
210

211
    return error;
×
212
}
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