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

mcallegari / qlcplus / 16450929051

22 Jul 2025 05:09PM UTC coverage: 34.174% (-0.1%) from 34.286%
16450929051

Pull #1782

github

web-flow
Merge f80a306ab into 8a22b7b84
Pull Request #1782: Feature: Control RGB Matrix script properties with VC Knobs in animation widget

7 of 189 new or added lines in 6 files covered. (3.7%)

9 existing lines in 4 files now uncovered.

17704 of 51806 relevant lines covered (34.17%)

19373.32 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

NEW
48
    QSizePolicy sp = scrollArea->widget()->sizePolicy();
×
NEW
49
    sp.setHorizontalPolicy(QSizePolicy::Ignored);
×
NEW
50
    scrollArea->widget()->setSizePolicy(sp);
×
51

52
    QSettings settings;
×
53
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
54
    if (geometrySettings.isValid() == true)
×
55
        restoreGeometry(geometrySettings.toByteArray());
×
56

57
    m_presetCombo->addItems(RGBAlgorithm::algorithms(m_doc));
×
58
    slotUpdatePresetProperties();
×
59
    connect(m_presetCombo, SIGNAL(currentIndexChanged(int)),
×
60
            this, SLOT(slotUpdatePresetProperties()));
NEW
61
    connect(m_checkAll, SIGNAL(toggled(bool)),
×
62
            this, SLOT(slotCheckAllToggled(bool)));
UNCOV
63
}
×
64

65
VCMatrixPresetSelection::~VCMatrixPresetSelection()
×
66
{
67
    QSettings settings;
×
68
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
69
}
×
70

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

84
void VCMatrixPresetSelection::displayProperties(RGBScript *script)
×
85
{
86
    if (script == NULL)
×
87
        return;
×
88

89
    int gridRowIdx = 0;
×
90

91
    QList<RGBScriptProperty> properties = script->properties();
×
92
    if (properties.count() > 0)
×
93
        m_propertiesGroup->show();
×
94
    else
95
        m_propertiesGroup->hide();
×
96

97
    m_properties.clear();
×
NEW
98
    m_dynamicProperties.clear();
×
99

100
    foreach (RGBScriptProperty prop, properties)
×
101
    {
NEW
102
        QCheckBox *propCheck = new QCheckBox(this);
×
NEW
103
        propCheck->setProperty("pName", prop.m_name);
×
NEW
104
        m_propertiesLayout->addWidget(propCheck, gridRowIdx, 2);
×
NEW
105
        connect(propCheck, SIGNAL(toggled(bool)),
×
106
                this, SLOT(slotPropertyCheckChanged(bool)));
107

UNCOV
108
        switch(prop.m_type)
×
109
        {
110
            case RGBScriptProperty::List:
×
111
            {
112
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
113
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
114
                QComboBox *propCombo = new QComboBox(this);
×
115
                propCombo->addItems(prop.m_listValues);
×
116
                propCombo->setProperty("pName", prop.m_name);
×
117
                QString pValue = script->property(prop.m_name);
×
118

119
                if (!pValue.isEmpty())
×
120
                    propCombo->setCurrentText(pValue);
×
121

122
                connect(propCombo, SIGNAL(currentIndexChanged(int)),
×
123
                        this, SLOT(slotPropertyComboChanged(int)));
124

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

141
                connect(propSpin, SIGNAL(valueChanged(int)),
×
142
                        this, SLOT(slotPropertySpinChanged(int)));
143

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

161
                connect(propSpin, SIGNAL(valueChanged(double)),
×
162
                        this, SLOT(slotPropertyDoubleSpinChanged(double)));
163

164
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
165
                m_properties[prop.m_name] = pValue;
×
166
                gridRowIdx++;
×
167
            }
×
168
            break;
×
169
            case RGBScriptProperty::String:
×
170
            {
171
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
172
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
173
                QLineEdit *propEdit = new QLineEdit(this);
×
NEW
174
                propEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
×
175
                propEdit->setProperty("pName", prop.m_name);
×
176
                QString pValue = script->property(prop.m_name);
×
177

178
                if (!pValue.isEmpty())
×
179
                    propEdit->setText(pValue);
×
180

181
                connect(propEdit, SIGNAL(textEdited(QString)),
×
182
                        this, SLOT(slotPropertyEditChanged(QString)));
183

184
                m_propertiesLayout->addWidget(propEdit, gridRowIdx, 1);
×
185
                m_properties[prop.m_name] = pValue;
×
186
                gridRowIdx++;
×
187
            }
×
188
            break;
×
189
            default:
×
190
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
191
            break;
×
192
        }
193
    }
×
194
}
×
195

196
void VCMatrixPresetSelection::slotUpdatePresetProperties()
×
197
{
198
    resetProperties(m_propertiesLayout->layout());
×
199
    RGBScript* selScript = m_doc->rgbScriptsCache()->script(m_presetCombo->currentText());
×
200
    displayProperties(selScript);
×
201
    delete selScript;
×
202
}
×
203

204
void VCMatrixPresetSelection::slotPropertyComboChanged(int index)
×
205
{
206
    QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
207
    QString pName = combo->property("pName").toString();
×
208
    QString pValue = combo->itemText(index);
×
209
    qDebug() << "Property combo changed to" << pValue;
×
210
    m_properties[pName] = pValue;
×
211
}
×
212

213
void VCMatrixPresetSelection::slotPropertySpinChanged(int value)
×
214
{
215
    qDebug() << "Property spin changed to" << value;
×
216
    QSpinBox *spin = qobject_cast<QSpinBox *>(sender());
×
217
    QString pName = spin->property("pName").toString();
×
218
    m_properties[pName] = QString::number(value);
×
219
}
×
220

221
void VCMatrixPresetSelection::slotPropertyDoubleSpinChanged(double value)
×
222
{
223
    qDebug() << "Property float changed to" << value;
×
224
    QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(sender());
×
225
    QString pName = spin->property("pName").toString();
×
226
    m_properties[pName] = QString::number(value);
×
227
}
×
228

229
void VCMatrixPresetSelection::slotPropertyEditChanged(QString text)
×
230
{
231
    qDebug() << "Property string changed to" << text;
×
232
    QLineEdit *edit = qobject_cast<QLineEdit *>(sender());
×
233
    QString pName = edit->property("pName").toString();
×
234
    m_properties[pName] = text;
×
235
}
×
236

237
QString VCMatrixPresetSelection::selectedPreset()
×
238
{
239
    return m_presetCombo->currentText();
×
240
}
241

242
QMap<QString, QString> VCMatrixPresetSelection::customizedProperties()
×
243
{
244
    return m_properties;
×
245
}
246

NEW
247
QMap<QString, bool> VCMatrixPresetSelection::dynamicProperties() const
×
248
{
NEW
249
    return m_dynamicProperties;
×
250
}
251

NEW
252
void VCMatrixPresetSelection::slotPropertyCheckChanged(bool checked)
×
253
{
NEW
254
    QCheckBox *check = qobject_cast<QCheckBox *>(sender());
×
NEW
255
    QString pName = check->property("pName").toString();
×
NEW
256
    m_dynamicProperties[pName] = checked;
×
NEW
257
}
×
258

NEW
259
void VCMatrixPresetSelection::slotCheckAllToggled(bool checked)
×
260
{
NEW
261
    QLayout *layout = m_propertiesLayout->layout();
×
NEW
262
    for (int i = 0; i < layout->count(); ++i)
×
263
    {
NEW
264
        QWidget *widget = layout->itemAt(i)->widget();
×
NEW
265
        if (widget)
×
266
        {
NEW
267
            QCheckBox *checkbox = qobject_cast<QCheckBox*>(widget);
×
NEW
268
            if (checkbox)
×
NEW
269
                checkbox->setChecked(checked);
×
270
        }
271
    }
NEW
272
}
×
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