• 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

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

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

47
    QSettings settings;
×
48
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
49
    if (geometrySettings.isValid() == true)
×
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
{
60
    QSettings settings;
×
61
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
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

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

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++;
×
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

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

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

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

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

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

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

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

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

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

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

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

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

227
QHash<QString, QString> VCMatrixPresetSelection::customizedProperties()
×
228
{
229
    return m_properties;
×
230
}
231

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