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

mcallegari / qlcplus / 6683238402

29 Oct 2023 12:10PM UTC coverage: 28.07%. Remained the same
6683238402

push

github

mcallegari
engine: fix build

15385 of 54809 relevant lines covered (28.07%)

20267.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ui/src/fixtureconsole.cpp
1
/*
2
  Q Light Controller
3
  fixtureconsole.cpp
4

5
  Copyright (c) Heikki Junnila
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 <QHBoxLayout>
21
#include <QDebug>
22
#include <QIcon>
23
#include <QList>
24

25
#include "fixtureconsole.h"
26
#include "consolechannel.h"
27
#include "fixture.h"
28
#include "doc.h"
29

30
/*****************************************************************************
31
 * Initialization
32
 *****************************************************************************/
33

34
FixtureConsole::FixtureConsole(QWidget *parent, Doc *doc, GroupType type, bool showCheck)
×
35
    : QGroupBox(parent)
36
    , m_doc(doc)
37
    , m_groupType(type)
38
    , m_showCheckBoxes(showCheck)
39
    , m_fixture(Fixture::invalidId())
×
40
{
41
    Q_ASSERT(doc != NULL);
×
42

43
    m_layout = new QHBoxLayout(this);
×
44
    layout()->setSpacing(0);
×
45
    layout()->setContentsMargins(0, 1, 0, 1);
×
46

47
    int topMargin = m_showCheckBoxes?16:1;
×
48

49
    QString common = "QGroupBox::title {top:-15px; left: 12px; subcontrol-origin: border; background-color: transparent; } "
50
                     "QGroupBox::indicator { width: 18px; height: 18px; } "
51
                     "QGroupBox::indicator:checked { image: url(:/checkbox_full.png) } "
52
                     "QGroupBox::indicator:unchecked { image: url(:/checkbox_empty.png) }";
×
53

54
    if (m_groupType == GroupEven)
×
55
        m_styleSheet = QString("QGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #C3D1C9, stop: 1 #AFBBB4); "
×
56
                             "border: 1px solid gray; border-radius: 4px; margin-top: %1px; margin-right: 1px; } " +
57
                             (m_showCheckBoxes?common:"")).arg(topMargin);
×
58
    else if (m_groupType == GroupOdd)
×
59
        m_styleSheet = QString("QGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D6D5E0, stop: 1 #A7A6AF); "
×
60
                             "border: 1px solid gray; border-radius: 4px; margin-top: %1px; margin-right: 1px; } " +
61
                             (m_showCheckBoxes?common:"")).arg(topMargin);
×
62
    else
63
        m_styleSheet = QString("QGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D6D2D0, stop: 1 #AFACAB); "
×
64
                             "border: 1px solid gray; border-radius: 4px; margin-top: %1px; margin-right: 1px; } " +
65
                             (m_showCheckBoxes?common:"")).arg(topMargin);
×
66
}
×
67

68
FixtureConsole::~FixtureConsole()
×
69
{
70
}
×
71

72
void FixtureConsole::enableResetButton(bool enable)
×
73
{
74
    QListIterator <ConsoleChannel*> it(m_channels);
×
75
    while (it.hasNext() == true)
×
76
    {
77
        ConsoleChannel* cc = it.next();
×
78
        Q_ASSERT(cc != NULL);
×
79
        cc->showResetButton(enable);
×
80
        connect(cc, SIGNAL(resetRequest(quint32,quint32)),
×
81
                this, SIGNAL(resetRequest(quint32,quint32)));
82
    }
83
}
×
84

85
void FixtureConsole::showEvent(QShowEvent *)
×
86
{
87
    QListIterator <ConsoleChannel*> it(m_channels);
×
88
    while (it.hasNext() == true)
×
89
    {
90
        ConsoleChannel* cc = it.next();
×
91
        Q_ASSERT(cc != NULL);
×
92
        cc->setVisible(true);
×
93
    }
94
}
×
95

96
/*****************************************************************************
97
 * Fixture
98
 *****************************************************************************/
99

100
void FixtureConsole::setFixture(quint32 id)
×
101
{
102
    /* Get rid of any previous channels */
103
    while (m_channels.isEmpty() == false)
×
104
        delete m_channels.takeFirst();
×
105

106
    /* Get the new fixture */
107
    Fixture *fxi = m_doc->fixture(id);
×
108
    Q_ASSERT(fxi != NULL);
×
109
    if (m_groupType != GroupNone)
×
110
        setTitle(fxi->name());
×
111

112
    /* Create channel units */
113
    for (uint i = 0; i < fxi->channels(); i++)
×
114
    {
115
        const QLCChannel *ch = fxi->channel(i);
×
116
        Q_ASSERT(ch != NULL);
×
117
        if (ch->group() == QLCChannel::NoGroup)
×
118
            continue;
×
119

120
        ConsoleChannel* cc = new ConsoleChannel(this, m_doc, id, i, m_showCheckBoxes);
×
121
        cc->setVisible(false);
×
122
        cc->setChannelStyleSheet(m_styleSheet);
×
123

124
        m_layout->addWidget(cc);
×
125
        m_channels.append(cc);
×
126
        connect(cc, SIGNAL(valueChanged(quint32,quint32,uchar)),
×
127
                this, SIGNAL(valueChanged(quint32,quint32,uchar)));
128
        connect(cc, SIGNAL(checked(quint32,quint32,bool)),
×
129
                this, SIGNAL(checked(quint32,quint32,bool)));
130
    }
131

132
    /* Make a spacer item eat excess space to justify channels left */
133
    m_layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
×
134

135
    m_fixture = id;
×
136

137
    connect(fxi, SIGNAL(aliasChanged()), this, SLOT(slotAliasChanged()));
×
138
}
×
139

140
quint32 FixtureConsole::fixture() const
×
141
{
142
    return m_fixture;
×
143
}
144

145
void FixtureConsole::slotAliasChanged()
×
146
{
147
    quint32 i = 0;
×
148
    Fixture *fxi = m_doc->fixture(m_fixture);
×
149

150
    QListIterator <ConsoleChannel*> it(m_channels);
×
151
    while (it.hasNext() == true)
×
152
    {
153
        ConsoleChannel* cc = it.next();
×
154
        if (cc->channel() != fxi->channel(i))
×
155
        {
156
            disconnect(cc, SIGNAL(valueChanged(quint32,quint32,uchar)),
×
157
                       this, SIGNAL(valueChanged(quint32,quint32,uchar)));
158
            disconnect(cc, SIGNAL(checked(quint32,quint32,bool)),
×
159
                       this, SIGNAL(checked(quint32,quint32,bool)));
160

161
            ConsoleChannel* newCC = new ConsoleChannel(this, m_doc, fxi->id(), i, m_showCheckBoxes);
×
162
            newCC->setVisible(false);
×
163
            newCC->setChannelStyleSheet(m_styleSheet);
×
164
            if (cc->hasResetButton())
×
165
                newCC->showResetButton(true);
×
166
            newCC->setValue(cc->value());
×
167
            newCC->setVisible(true);
×
168

169
            connect(newCC, SIGNAL(valueChanged(quint32,quint32,uchar)),
×
170
                    this, SIGNAL(valueChanged(quint32,quint32,uchar)));
171
            connect(newCC, SIGNAL(checked(quint32,quint32,bool)),
×
172
                    this, SIGNAL(checked(quint32,quint32,bool)));
173

174
            QLayoutItem *item = m_layout->replaceWidget(cc, newCC);
×
175
            delete item;
×
176
            delete cc;
×
177
            m_channels.replace(i, newCC);
×
178
        }
179
        i++;
×
180
    }
181
}
×
182

183
/*****************************************************************************
184
 * Channels
185
 *****************************************************************************/
186

187
void FixtureConsole::setChecked(bool state, quint32 channel)
×
188
{
189
    QListIterator <ConsoleChannel*> it(m_channels);
×
190
    while (it.hasNext() == true)
×
191
    {
192
        ConsoleChannel* cc = it.next();
×
193
        Q_ASSERT(cc != NULL);
×
194
        if (channel == UINT_MAX || channel == cc->channelIndex())
×
195
            cc->setChecked(state);
×
196
    }
197
}
×
198

199
void FixtureConsole::setSceneValue(const SceneValue& scv)
×
200
{
201
    Q_ASSERT(scv.fxi == m_fixture);
×
202

203
    QListIterator <ConsoleChannel*> it(m_channels);
×
204
    while (it.hasNext() == true)
×
205
    {
206
        ConsoleChannel* cc = it.next();
×
207
        Q_ASSERT(cc != NULL);
×
208
        if (cc->channelIndex() == scv.channel)
×
209
        {
210
            cc->setChecked(true);
×
211
            cc->setValue(scv.value);
×
212
        }
213
    }
214
}
×
215

216
QList <SceneValue> FixtureConsole::values() const
×
217
{
218
    QList <SceneValue> list; // list of all checked channels
×
219
    QList <SceneValue> selectedList; // list of selected channels only
×
220
    QListIterator <ConsoleChannel*> it(m_channels);
×
221
    while (it.hasNext() == true)
×
222
    {
223
        ConsoleChannel* cc = it.next();
×
224
        Q_ASSERT(cc != NULL);
×
225
        if (cc->isChecked() == true)
×
226
        {
227
            list.append(SceneValue(m_fixture, cc->channelIndex(), cc->value()));
×
228
            if (cc->isSelected())
×
229
                selectedList.append(SceneValue(m_fixture, cc->channelIndex(), cc->value()));
×
230
        }
231
    }
232

233
    if (selectedList.count() > 0)
×
234
        return selectedList;
×
235
    else
236
        return list;
×
237
}
238

239
bool FixtureConsole::hasSelections()
×
240
{
241
    foreach(ConsoleChannel *cc, m_channels)
×
242
    {
243
        Q_ASSERT(cc != NULL);
×
244
        if (cc->isChecked() && cc->isSelected())
×
245
            return true;
×
246
    }
247

248
    return false;
×
249
}
250

251
void FixtureConsole::setValues(const QList <SceneValue>& list, bool fromSelection)
×
252
{
253
    QList<ConsoleChannel *> toUncheckList = m_channels;
×
254

255
    QListIterator <SceneValue> it(list);
×
256
    while (it.hasNext() == true)
×
257
    {
258
        SceneValue val(it.next());
×
259
        if (val.channel < quint32(children().size()))
×
260
        {
261
            ConsoleChannel* cc = channel(val.channel);
×
262
            if (cc != NULL)
×
263
            {
264
                if (cc->isChecked() == false)
×
265
                    cc->setChecked(true);
×
266
                cc->setValue(val.value);
×
267
                toUncheckList.removeOne(cc);
×
268
            }
269
        }
270
    }
271

272
    if (fromSelection == false)
×
273
    {
274
        foreach (ConsoleChannel *cc, toUncheckList)
×
275
            cc->setChecked(false);
×
276
    }
277
}
×
278

279
void FixtureConsole::setValue(quint32 ch, uchar value, bool apply)
×
280
{
281
    ConsoleChannel* cc = channel(ch);
×
282
    if (cc != NULL)
×
283
        cc->setValue(value, apply);
×
284
}
×
285

286
uchar FixtureConsole::value(quint32 ch) const
×
287
{
288
    ConsoleChannel* cc = channel(ch);
×
289
    if (cc != NULL)
×
290
        return cc->value();
×
291
    else
292
        return 0;
×
293
}
294

295
void FixtureConsole::setChannelStylesheet(quint32 ch, QString ss)
×
296
{
297
    ConsoleChannel* cc = channel(ch);
×
298
    if (cc != NULL)
×
299
        cc->setChannelStyleSheet(ss);
×
300
}
×
301

302
void FixtureConsole::resetChannelsStylesheet()
×
303
{
304
    QListIterator <ConsoleChannel*> it(m_channels);
×
305
    while (it.hasNext() == true)
×
306
    {
307
        ConsoleChannel* cc = it.next();
×
308
        Q_ASSERT(cc != NULL);
×
309
        cc->setChannelStyleSheet(m_styleSheet);
×
310
    }
311
}
×
312

313
ConsoleChannel* FixtureConsole::channel(quint32 ch) const
×
314
{
315
    QListIterator <ConsoleChannel*> it(m_channels);
×
316
    while (it.hasNext() == true)
×
317
    {
318
        ConsoleChannel* cc = it.next();
×
319
        Q_ASSERT(cc != NULL);
×
320
        if (cc->channelIndex() == ch)
×
321
            return cc;
×
322
    }
323

324
    return NULL;
×
325
}
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