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

mcallegari / qlcplus / 8961243534

05 May 2024 09:23PM UTC coverage: 32.068% (+4.0%) from 28.094%
8961243534

push

github

mcallegari
Merge branch 'master' into qmltoqt6

902 of 2557 new or added lines in 140 files covered. (35.28%)

166 existing lines in 76 files now uncovered.

15395 of 48008 relevant lines covered (32.07%)

22949.67 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

NEW
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

108
                connect(propCombo, SIGNAL(currentIndexChanged(QString)),
×
109
                        this, SLOT(slotPropertyComboChanged(QString)));
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

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++;
×
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++;
×
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++;
×
173
            }
NEW
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(QString value)
×
190
{
191
    qDebug() << "Property combo changed to" << value;
×
NEW
192
    QComboBox *combo = qobject_cast<QComboBox *>(sender());
×
193
    QString pName = combo->property("pName").toString();
×
194
    m_properties[pName] = value;
×
195
}
×
196

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

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

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

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

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

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