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

mcallegari / qlcplus / 9242447442

26 May 2024 10:08AM UTC coverage: 31.637% (-0.4%) from 32.007%
9242447442

Pull #1422

github

web-flow
Merge 8b0046d03 into ff16fdc69
Pull Request #1422: RgbScript make stage colors available to scripts

60 of 910 new or added lines in 11 files covered. (6.59%)

9 existing lines in 4 files now uncovered.

15421 of 48743 relevant lines covered (31.64%)

22692.38 hits per line

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

77.14
/engine/src/rgbalgorithm.cpp
1
/*
2
  Q Light Controller Plus
3
  rgbalgorithm.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 <QStringList>
24
#include <QDebug>
25

26
#include "rgbscriptscache.h"
27
#include "rgbalgorithm.h"
28
#include "rgbaudio.h"
29
#include "rgbimage.h"
30
#include "rgbplain.h"
31
#include "rgbtext.h"
32
#include "doc.h"
33

34
#ifdef QT_QML_LIB
35
  #include "rgbscriptv4.h"
36
#else
37
  #include "rgbscript.h"
38
#endif
39

40
RGBAlgorithm::RGBAlgorithm(Doc * doc)
475✔
41
    : m_doc(doc)
2,375✔
42
{
43
    Q_ASSERT(5 == RGBAlgorithmRawColorCount);
44
    m_colors[0] = QColor();
475✔
45
    m_colors[1] = QColor();
475✔
46
    m_colors[2] = QColor();
475✔
47
    m_colors[3] = QColor();
475✔
48
    m_colors[4] = QColor();
475✔
49
}
475✔
50

51
void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount])
21✔
52
{
53
    for (int i = 0; i < RGBAlgorithmRawColorCount; i++)
126✔
54
    {
55
        if (acceptColors() <= i)
105✔
56
            m_colors[i] = colors[i];
63✔
57
        else
58
            m_colors[i] = QColor();
42✔
59
    }
60
}
21✔
61

NEW
62
QColor RGBAlgorithm::getColor(unsigned int i) const
×
63
{
NEW
64
    return m_colors[i];
×
65
}
66

67
/****************************************************************************
68
 * Available algorithms
69
 ****************************************************************************/
70

71
QStringList RGBAlgorithm::algorithms(Doc * doc)
1✔
72
{
73
    QStringList list;
1✔
74
    RGBPlain plain(doc);
2✔
75
    RGBText text(doc);
2✔
76
    RGBImage image(doc);
2✔
77
    RGBAudio audio(doc);
2✔
78
    list << plain.name();
1✔
79
    list << text.name();
1✔
80
    list << image.name();
1✔
81
    list << audio.name();
1✔
82
    list << doc->rgbScriptsCache()->names();
1✔
83
    return list;
2✔
84
}
85

86
RGBAlgorithm* RGBAlgorithm::algorithm(Doc * doc, const QString& name)
6✔
87
{
88
    RGBText text(doc);
12✔
89
    RGBImage image(doc);
12✔
90
    RGBAudio audio(doc);
12✔
91
    RGBPlain plain(doc);
12✔
92
    if (name == text.name())
6✔
93
        return text.clone();
1✔
94
    else if (name == image.name())
5✔
95
        return image.clone();
×
96
    else if (name == audio.name())
5✔
97
        return audio.clone();
×
98
    else if (name == plain.name())
5✔
99
        return plain.clone();
×
100
    else
101
        return doc->rgbScriptsCache()->script(name).clone();
5✔
102
}
103

104
/****************************************************************************
105
 * Load & Save
106
 ****************************************************************************/
107

108
RGBAlgorithm* RGBAlgorithm::loader(Doc * doc, QXmlStreamReader &root)
5✔
109
{
110
    RGBAlgorithm* algo = NULL;
5✔
111

112
    if (root.name() != KXMLQLCRGBAlgorithm)
5✔
113
    {
114
        qWarning() << Q_FUNC_INFO << "RGB Algorithm node not found";
2✔
115
        return NULL;
2✔
116
    }
117

118
    QString type = root.attributes().value(KXMLQLCRGBAlgorithmType).toString();
6✔
119
    if (type == KXMLQLCRGBImage)
3✔
120
    {
121
        RGBImage image(doc);
×
122
        if (image.loadXML(root) == true)
×
123
            algo = image.clone();
×
124
    }
125
    else if (type == KXMLQLCRGBText)
3✔
126
    {
127
        RGBText text(doc);
2✔
128
        if (text.loadXML(root) == true)
1✔
129
            algo = text.clone();
1✔
130
    }
131
    else if (type == KXMLQLCRGBAudio)
2✔
132
    {
133
        RGBAudio audio(doc);
×
134
        if (audio.loadXML(root) == true)
×
135
            algo = audio.clone();
×
136
    }
137
    else if (type == KXMLQLCRGBScript)
2✔
138
    {
139
        RGBScript const& scr = doc->rgbScriptsCache()->script(root.readElementText());
2✔
140
        if (scr.apiVersion() > 0 && scr.name().isEmpty() == false)
2✔
141
            algo = scr.clone();
2✔
142
    }
143
    else if (type == KXMLQLCRGBPlain)
×
144
    {
145
        RGBPlain plain(doc);
×
146
        if (plain.loadXML(root) == true)
×
147
            algo = plain.clone();
×
148
    }
149
    else
150
    {
151
        qWarning() << "Unrecognized RGB algorithm type:" << type;
×
152
    }
153

154
    return algo;
3✔
155
}
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