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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

76.06
/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)
251✔
41
    : m_doc(doc)
251✔
42
{
43
}
251✔
44

45
void RGBAlgorithm::setColors(QVector<QColor> colors)
17✔
46
{
47
    int nCols = acceptColors();
17✔
48
    m_colors.clear();
17✔
49

50
    for (int i = 0; i < nCols; i++)
54✔
51
    {
52
        if (i < colors.count())
37✔
53
            m_colors.append(colors.at(i));
35✔
54
    }
55
}
17✔
56

57
QColor RGBAlgorithm::getColor(uint i) const
3✔
58
{
59
    if (i >= (uint)m_colors.count())
3✔
60
        return QColor();
61

62
    return m_colors[i];
3✔
63
}
64

65
/****************************************************************************
66
 * Available algorithms
67
 ****************************************************************************/
68

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

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

102
/****************************************************************************
103
 * Load & Save
104
 ****************************************************************************/
105

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

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

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

152
    return algo;
153
}
3✔
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