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

mcallegari / qlcplus / 7252848206

18 Dec 2023 07:26PM UTC coverage: 32.067% (+0.001%) from 32.066%
7252848206

push

github

mcallegari
Code style review #1427

199 of 628 new or added lines in 101 files covered. (31.69%)

8 existing lines in 2 files now uncovered.

15169 of 47304 relevant lines covered (32.07%)

23733.74 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 <QSpinBox>
22
#include <QLabel>
23
#include <QDebug>
24

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

35
VCMatrixPresetSelection::VCMatrixPresetSelection(Doc *doc, QWidget *parent)
×
36
    : QDialog(parent)
37
    , m_doc(doc)
×
38
{
39
    Q_ASSERT(doc != NULL);
×
40

41
    setupUi(this);
×
42
    m_presetCombo->addItems(RGBAlgorithm::algorithms(m_doc));
×
43
    slotUpdatePresetProperties();
×
44
    connect(m_presetCombo, SIGNAL(currentIndexChanged(int)),
×
45
            this, SLOT(slotUpdatePresetProperties()));
46
}
×
47

48
VCMatrixPresetSelection::~VCMatrixPresetSelection()
×
49
{
50
}
×
51

52
/**
53
 * Helper function. Deletes all child widgets of the given layout @a item.
54
 */
55
void VCMatrixPresetSelection::resetProperties(QLayoutItem *item)
×
56
{
57
    if (item->layout()) {
×
58
        // Process all child items recursively.
59
        for (int i = item->layout()->count() - 1; i >= 0; i--)
×
60
            resetProperties(item->layout()->itemAt(i));
×
61
    }
62
    delete item->widget();
×
63
}
×
64

65
void VCMatrixPresetSelection::displayProperties(RGBScript *script)
×
66
{
67
    if (script == NULL)
×
68
        return;
×
69

70
    int gridRowIdx = 0;
×
71

72
    QList<RGBScriptProperty> properties = script->properties();
×
73
    if (properties.count() > 0)
×
74
        m_propertiesGroup->show();
×
75
    else
76
        m_propertiesGroup->hide();
×
77

78
    m_properties.clear();
×
79

NEW
80
    foreach (RGBScriptProperty prop, properties)
×
81
    {
82
        switch(prop.m_type)
×
83
        {
84
            case RGBScriptProperty::List:
×
85
            {
86
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
87
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
88
                QComboBox *propCombo = new QComboBox(this);
×
89
                propCombo->addItems(prop.m_listValues);
×
90
                propCombo->setProperty("pName", prop.m_name);
×
91
                QString pValue = script->property(prop.m_name);
×
92

93
                if (!pValue.isEmpty())
×
94
                    propCombo->setCurrentText(pValue);
×
95

96
                connect(propCombo, SIGNAL(currentIndexChanged(QString)),
×
97
                        this, SLOT(slotPropertyComboChanged(QString)));
98

99
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
×
100
                m_properties[prop.m_name] = pValue;
×
101
                gridRowIdx++;
×
102
            }
103
            break;
×
104
            case RGBScriptProperty::Range:
×
105
            {
106
                QLabel *propLabel = new QLabel(prop.m_displayName);
×
107
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
×
108
                QSpinBox *propSpin = new QSpinBox(this);
×
109
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
×
110
                propSpin->setProperty("pName", prop.m_name);
×
111
                QString pValue = script->property(prop.m_name);
×
112
                if (!pValue.isEmpty())
×
113
                    propSpin->setValue(pValue.toInt());
×
114
                connect(propSpin, SIGNAL(valueChanged(int)),
×
115
                        this, SLOT(slotPropertySpinChanged(int)));
116
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
×
117
                m_properties[prop.m_name] = pValue;
×
118
                gridRowIdx++;
×
119
            }
120
            break;
×
121
            default:
×
122
                qWarning() << "Type" << prop.m_type << "not handled yet";
×
123
            break;
×
124
        }
125
    }
126
}
127

128
void VCMatrixPresetSelection::slotUpdatePresetProperties()
×
129
{
130
    resetProperties(m_propertiesLayout->layout());
×
131
    RGBScript selScript = m_doc->rgbScriptsCache()->script(m_presetCombo->currentText());
×
132
    displayProperties(&selScript);
×
133
}
×
134

135
void VCMatrixPresetSelection::slotPropertyComboChanged(QString value)
×
136
{
137
    qDebug() << "Property combo changed to" << value;
×
138
    QComboBox *combo = (QComboBox *)sender();
×
139
    QString pName = combo->property("pName").toString();
×
140
    m_properties[pName] = value;
×
141
}
×
142

143
void VCMatrixPresetSelection::slotPropertySpinChanged(int value)
×
144
{
145
    qDebug() << "Property spin changed to" << value;
×
146
    QSpinBox *spin = (QSpinBox *)sender();
×
147
    QString pName = spin->property("pName").toString();
×
148
    m_properties[pName] = QString::number(value);
×
149
}
×
150

151
QString VCMatrixPresetSelection::selectedPreset()
×
152
{
153
    return m_presetCombo->currentText();
×
154
}
155

156
QHash<QString, QString> VCMatrixPresetSelection::customizedProperties()
×
157
{
158
    return m_properties;
×
159
}
160

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