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

mcallegari / qlcplus / 16348489961

17 Jul 2025 02:53PM UTC coverage: 34.215% (-0.07%) from 34.286%
16348489961

Pull #1782

github

web-flow
Merge 131a05ba3 into 30458f6f0
Pull Request #1782: Feature: Control RGB Matrix script properties with VC Knobs in animation widget

7 of 124 new or added lines in 5 files covered. (5.65%)

7 existing lines in 4 files now uncovered.

17704 of 51744 relevant lines covered (34.21%)

19388.54 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 <QCheckBox>
24
#include <QLabel>
25
#include <QDebug>
26
#include <QSettings>
27

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

38
#define SETTINGS_GEOMETRY "vcmatrixpresetselection/geometry"
39

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

46
    setupUi(this);
×
47

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

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

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

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

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

83
    int gridRowIdx = 0;
×
84

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

91
    m_properties.clear();
×
NEW
92
    m_dynamicProperties.clear();
×
93

94
    foreach (RGBScriptProperty prop, properties)
×
95
    {
NEW
96
        QCheckBox *propCheck = new QCheckBox(this);
×
NEW
97
        propCheck->setProperty("pName", prop.m_name);
×
NEW
98
        m_propertiesLayout->addWidget(propCheck, gridRowIdx, 2);
×
NEW
99
        connect(propCheck, SIGNAL(toggled(bool)),
×
100
                this, SLOT(slotPropertyCheckChanged(bool)));
101

UNCOV
102
        switch(prop.m_type)
×
103
        {
104
            case RGBScriptProperty::List:
×
105
            {
106
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
107
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
108
                QComboBox *propCombo = new QComboBox(this);
×
109
                propCombo->addItems(prop.m_listValues);
×
110
                propCombo->setProperty("pName", prop.m_name);
×
111
                QString pValue = script->property(prop.m_name);
×
112

113
                if (!pValue.isEmpty())
×
114
                    propCombo->setCurrentText(pValue);
×
115

116
                connect(propCombo, SIGNAL(currentIndexChanged(int)),
×
117
                        this, SLOT(slotPropertyComboChanged(int)));
118

119
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
×
120
                m_properties[prop.m_name] = pValue;
×
121
                gridRowIdx++;
×
122
            }
×
123
            break;
×
124
            case RGBScriptProperty::Range:
×
125
            {
126
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
127
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
128
                QSpinBox *propSpin = new QSpinBox(this);
×
129
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
×
130
                propSpin->setProperty("pName", prop.m_name);
×
131
                QString pValue = script->property(prop.m_name);
×
132
                if (!pValue.isEmpty())
×
133
                    propSpin->setValue(pValue.toInt());
×
134

135
                connect(propSpin, SIGNAL(valueChanged(int)),
×
136
                        this, SLOT(slotPropertySpinChanged(int)));
137

138
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
139
                m_properties[prop.m_name] = pValue;
×
140
                gridRowIdx++;
×
141
            }
×
142
            break;
×
143
            case RGBScriptProperty::Float:
×
144
            {
145
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
146
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
147
                QDoubleSpinBox *propSpin = new QDoubleSpinBox(this);
×
148
                propSpin->setDecimals(3);
×
149
                propSpin->setRange(-1000000, 1000000);
×
150
                propSpin->setProperty("pName", prop.m_name);
×
151
                QString pValue = script->property(prop.m_name);
×
152
                if (!pValue.isEmpty())
×
153
                    propSpin->setValue(pValue.toDouble());
×
154

155
                connect(propSpin, SIGNAL(valueChanged(double)),
×
156
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
157

158
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
159
                m_properties[prop.m_name] = pValue;
×
160
                gridRowIdx++;
×
161
            }
×
162
            break;
×
163
            case RGBScriptProperty::String:
×
164
            {
165
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
166
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
167
                QLineEdit *propEdit = new QLineEdit(this);
×
168
                propEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
×
169
                propEdit->setProperty("pName", prop.m_name);
×
170
                QString pValue = script->property(prop.m_name);
×
171

172
                if (!pValue.isEmpty())
×
173
                    propEdit->setText(pValue);
×
174

175
                connect(propEdit, SIGNAL(textEdited(QString)),
×
176
                        this, SLOT(slotPropertyEditChanged(QString)));
177

178
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
179
                m_properties[prop.m_name] = pValue;
×
180
                gridRowIdx++;
×
181
            }
×
182
            break;
×
183
            default:
×
184
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
185
            break;
×
186
        }
187
    }
×
188
}
×
189

190
void VCMatrixPresetSelection::slotUpdatePresetProperties()
×
191
{
192
    resetProperties(m_propertiesLayout->layout());
×
193
    RGBScript* selScript = m_doc->rgbScriptsCache()->script(m_presetCombo->currentText());
×
194
    displayProperties(selScript);
×
195
    delete selScript;
×
196
}
×
197

198
void VCMatrixPresetSelection::slotPropertyComboChanged(int index)
×
199
{
200
    QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
201
    QString pName = combo->property("pName").toString();
×
202
    QString pValue = combo->itemText(index);
×
203
    qDebug() << "Property combo changed to" << pValue;
×
204
    m_properties[pName] = pValue;
×
205
}
×
206

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

215
void VCMatrixPresetSelection::slotPropertyDoubleSpinChanged(double value)
×
216
{
217
    qDebug() << "Property float changed to" << value;
×
218
    QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(sender());
×
219
    QString pName = spin->property("pName").toString();
×
220
    m_properties[pName] = QString::number(value);
×
221
}
×
222

223
void VCMatrixPresetSelection::slotPropertyEditChanged(QString text)
×
224
{
225
    qDebug() << "Property string changed to" << text;
×
226
    QLineEdit *edit = qobject_cast<QLineEdit *>(sender());
×
227
    QString pName = edit->property("pName").toString();
×
228
    m_properties[pName] = text;
×
229
}
×
230

231
QString VCMatrixPresetSelection::selectedPreset()
×
232
{
233
    return m_presetCombo->currentText();
×
234
}
235

236
QMap<QString, QString> VCMatrixPresetSelection::customizedProperties()
×
237
{
238
    return m_properties;
×
239
}
240

NEW
241
QMap<QString, bool> VCMatrixPresetSelection::dynamicProperties() const
×
242
{
NEW
243
    return m_dynamicProperties;
×
244
}
245

NEW
246
void VCMatrixPresetSelection::slotPropertyCheckChanged(bool checked)
×
247
{
NEW
248
    QCheckBox *check = qobject_cast<QCheckBox *>(sender());
×
NEW
249
    QString pName = check->property("pName").toString();
×
NEW
250
    m_dynamicProperties[pName] = checked;
×
NEW
251
}
×
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