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

mcallegari / qlcplus / 18357067171

08 Oct 2025 08:16PM UTC coverage: 34.26% (+2.2%) from 32.066%
18357067171

push

github

mcallegari
Merge branch 'master' into filedialog

1282 of 4424 new or added lines in 152 files covered. (28.98%)

1342 existing lines in 152 files now uncovered.

17704 of 51675 relevant lines covered (34.26%)

19430.31 hits per line

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

0.0
/ui/src/virtualconsole/vcmatrixpresetselection.cpp
1
/*
2
  Q Light Controller Plus
3
  vcmatrixpresetselection.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 <QComboBox>
21
#include <QLineEdit>
22
#include <QSpinBox>
23
#include <QLabel>
24
#include <QDebug>
25
#include <QSettings>
26

27
#include "vcmatrixpresetselection.h"
28
#include "ui_vcmatrixpresetselection.h"
29
#include "rgbscriptscache.h"
30
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
31
 #include "rgbscript.h"
32
#else
33
 #include "rgbscriptv4.h"
34
#endif
35
#include "doc.h"
36

37
#define SETTINGS_GEOMETRY "vcmatrixpresetselection/geometry"
38

UNCOV
39
VCMatrixPresetSelection::VCMatrixPresetSelection(Doc *doc, QWidget *parent)
×
40
    : QDialog(parent)
41
    , m_doc(doc)
×
42
{
43
    Q_ASSERT(doc != NULL);
×
44

45
    setupUi(this);
×
46

NEW
47
    QSettings settings;
×
NEW
48
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
NEW
49
    if (geometrySettings.isValid() == true)
×
NEW
50
        restoreGeometry(geometrySettings.toByteArray());
×
51

52
    m_presetCombo->addItems(RGBAlgorithm::algorithms(m_doc));
×
53
    slotUpdatePresetProperties();
×
54
    connect(m_presetCombo, SIGNAL(currentIndexChanged(int)),
×
55
            this, SLOT(slotUpdatePresetProperties()));
56
}
×
57

58
VCMatrixPresetSelection::~VCMatrixPresetSelection()
×
59
{
NEW
60
    QSettings settings;
×
NEW
61
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
UNCOV
62
}
×
63

64
/**
65
 * Helper function. Deletes all child widgets of the given layout @a item.
66
 */
67
void VCMatrixPresetSelection::resetProperties(QLayoutItem *item)
×
68
{
69
    if (item->layout()) {
×
70
        // Process all child items recursively.
71
        for (int i = item->layout()->count() - 1; i >= 0; i--)
×
72
            resetProperties(item->layout()->itemAt(i));
×
73
    }
74
    delete item->widget();
×
75
}
×
76

77
void VCMatrixPresetSelection::displayProperties(RGBScript *script)
×
78
{
79
    if (script == NULL)
×
80
        return;
×
81

82
    int gridRowIdx = 0;
×
83

84
    QList<RGBScriptProperty> properties = script->properties();
×
85
    if (properties.count() > 0)
×
86
        m_propertiesGroup->show();
×
87
    else
88
        m_propertiesGroup->hide();
×
89

90
    m_properties.clear();
×
91

NEW
92
    foreach (RGBScriptProperty prop, properties)
×
93
    {
94
        switch(prop.m_type)
×
95
        {
96
            case RGBScriptProperty::List:
×
97
            {
98
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
99
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
100
                QComboBox *propCombo = new QComboBox(this);
×
101
                propCombo->addItems(prop.m_listValues);
×
102
                propCombo->setProperty("pName", prop.m_name);
×
103
                QString pValue = script->property(prop.m_name);
×
104

105
                if (!pValue.isEmpty())
×
106
                    propCombo->setCurrentText(pValue);
×
107

NEW
108
                connect(propCombo, SIGNAL(currentIndexChanged(int)),
×
109
                        this, SLOT(slotPropertyComboChanged(int)));
110

111
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
×
112
                m_properties[prop.m_name] = pValue;
×
113
                gridRowIdx++;
×
UNCOV
114
            }
×
115
            break;
×
116
            case RGBScriptProperty::Range:
×
117
            {
118
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
119
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
120
                QSpinBox *propSpin = new QSpinBox(this);
×
121
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
×
122
                propSpin->setProperty("pName", prop.m_name);
×
123
                QString pValue = script->property(prop.m_name);
×
124
                if (!pValue.isEmpty())
×
125
                    propSpin->setValue(pValue.toInt());
×
126

UNCOV
127
                connect(propSpin, SIGNAL(valueChanged(int)),
×
128
                        this, SLOT(slotPropertySpinChanged(int)));
129

130
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
131
                m_properties[prop.m_name] = pValue;
×
132
                gridRowIdx++;
×
UNCOV
133
            }
×
134
            break;
×
NEW
135
            case RGBScriptProperty::Float:
×
136
            {
NEW
137
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
NEW
138
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
NEW
139
                QDoubleSpinBox *propSpin = new QDoubleSpinBox(this);
×
NEW
140
                propSpin->setDecimals(3);
×
NEW
141
                propSpin->setRange(-1000000, 1000000);
×
NEW
142
                propSpin->setProperty("pName", prop.m_name);
×
NEW
143
                QString pValue = script->property(prop.m_name);
×
NEW
144
                if (!pValue.isEmpty())
×
NEW
145
                    propSpin->setValue(pValue.toDouble());
×
146

NEW
147
                connect(propSpin, SIGNAL(valueChanged(double)),
×
148
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
149

NEW
150
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
NEW
151
                m_properties[prop.m_name] = pValue;
×
NEW
152
                gridRowIdx++;
×
NEW
153
            }
×
NEW
154
            break;
×
NEW
155
            case RGBScriptProperty::String:
×
156
            {
NEW
157
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
NEW
158
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
NEW
159
                QLineEdit *propEdit = new QLineEdit(this);
×
NEW
160
                propEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
×
NEW
161
                propEdit->setProperty("pName", prop.m_name);
×
NEW
162
                QString pValue = script->property(prop.m_name);
×
163

NEW
164
                if (!pValue.isEmpty())
×
NEW
165
                    propEdit->setText(pValue);
×
166

NEW
167
                connect(propEdit, SIGNAL(textEdited(QString)),
×
168
                        this, SLOT(slotPropertyEditChanged(QString)));
169

NEW
170
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
NEW
171
                m_properties[prop.m_name] = pValue;
×
NEW
172
                gridRowIdx++;
×
NEW
173
            }
×
NEW
174
            break;
×
175
            default:
×
176
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
177
            break;
×
178
        }
UNCOV
179
    }
×
UNCOV
180
}
×
181

182
void VCMatrixPresetSelection::slotUpdatePresetProperties()
×
183
{
184
    resetProperties(m_propertiesLayout->layout());
×
NEW
185
    RGBScript* selScript = m_doc->rgbScriptsCache()->script(m_presetCombo->currentText());
×
NEW
186
    displayProperties(selScript);
×
NEW
187
    delete selScript;
×
UNCOV
188
}
×
189

NEW
190
void VCMatrixPresetSelection::slotPropertyComboChanged(int index)
×
191
{
NEW
192
    QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
193
    QString pName = combo->property("pName").toString();
×
NEW
194
    QString pValue = combo->itemText(index);
×
NEW
195
    qDebug() << "Property combo changed to" << pValue;
×
NEW
196
    m_properties[pName] = pValue;
×
UNCOV
197
}
×
198

199
void VCMatrixPresetSelection::slotPropertySpinChanged(int value)
×
200
{
201
    qDebug() << "Property spin changed to" << value;
×
NEW
202
    QSpinBox *spin = qobject_cast<QSpinBox *>(sender());
×
203
    QString pName = spin->property("pName").toString();
×
204
    m_properties[pName] = QString::number(value);
×
205
}
×
206

NEW
207
void VCMatrixPresetSelection::slotPropertyDoubleSpinChanged(double value)
×
208
{
NEW
209
    qDebug() << "Property float changed to" << value;
×
NEW
210
    QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(sender());
×
NEW
211
    QString pName = spin->property("pName").toString();
×
NEW
212
    m_properties[pName] = QString::number(value);
×
NEW
213
}
×
214

NEW
215
void VCMatrixPresetSelection::slotPropertyEditChanged(QString text)
×
216
{
NEW
217
    qDebug() << "Property string changed to" << text;
×
NEW
218
    QLineEdit *edit = qobject_cast<QLineEdit *>(sender());
×
NEW
219
    QString pName = edit->property("pName").toString();
×
NEW
220
    m_properties[pName] = text;
×
NEW
221
}
×
222

UNCOV
223
QString VCMatrixPresetSelection::selectedPreset()
×
224
{
225
    return m_presetCombo->currentText();
×
226
}
227

NEW
228
QMap<QString, QString> VCMatrixPresetSelection::customizedProperties()
×
229
{
230
    return m_properties;
×
231
}
232

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