• 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/channelsselection.cpp
1
/*
2
  Q Light Controller Plus
3
  channelsselection.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 <QTreeWidgetItem>
21
#include <QPushButton>
22
#include <QComboBox>
23
#include <QDebug>
24

25
#include "channelmodifiereditor.h"
26
#include "channelsselection.h"
27
#include "channelmodifier.h"
28
#include "qlcfixturedef.h"
29
#include "universe.h"
30
#include "doc.h"
31

32
#define KColumnName         0
33
#define KColumnType         1
34
#define KColumnSelection    2
35
#define KColumnBehaviour    3
36
#define KColumnModifier     4
37
#define KColumnChIdx        5
38
#define KColumnID           6
39

40
ChannelsSelection::ChannelsSelection(Doc *doc, QWidget *parent, ChannelSelectionType mode)
×
41
    : QDialog(parent)
42
    , m_doc(doc)
43
    , m_mode(mode)
×
44
{
45
    Q_ASSERT(doc != NULL);
×
46

47
    setupUi(this);
×
48

49
    QStringList hdrLabels;
×
50
    hdrLabels << tr("Name") << tr("Type");
×
51

52
    if (mode == NormalMode)
×
53
    {
54
        hdrLabels << tr("Selected");
×
55
    }
56
    else if (mode == ConfigurationMode)
×
57
    {
58
        setWindowTitle(tr("Channel properties configuration"));
×
59
        setWindowIcon(QIcon(":/fade.png"));
×
60
        hdrLabels << tr("Can fade") << tr("Behaviour") << tr("Modifier");
×
61
    }
62

63
    m_channelsTree->setHeaderLabels(hdrLabels);
×
64

65
    updateFixturesTree();
×
66

67
    connect(m_channelsTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
68
            this, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
69
    connect(m_channelsTree, SIGNAL(expanded(QModelIndex)),
×
70
            this, SLOT(slotItemExpanded()));
71
    connect(m_channelsTree, SIGNAL(collapsed(QModelIndex)),
×
72
            this, SLOT(slotItemExpanded()));
73
    connect(m_collapseButton, SIGNAL(clicked(bool)),
×
74
            m_channelsTree, SLOT(collapseAll()));
×
75
    connect(m_expandButton, SIGNAL(clicked(bool)),
×
76
            m_channelsTree, SLOT(expandAll()));
×
77
}
×
78

79
ChannelsSelection::~ChannelsSelection()
×
80
{
81
}
×
82

83
void ChannelsSelection::setChannelsList(QList<SceneValue> list)
×
84
{
85
    if (list.count() > 0)
×
86
    {
87
        m_channelsList = list;
×
88
        updateFixturesTree();
×
89
    }
90
}
×
91

92
QList<SceneValue> ChannelsSelection::channelsList()
×
93
{
94
    return m_channelsList;
×
95
}
96

97
void ChannelsSelection::updateFixturesTree()
×
98
{
99
    m_channelsTree->clear();
×
100
    m_channelsTree->setIconSize(QSize(24, 24));
×
101
    m_channelsTree->setAllColumnsShowFocus(true);
×
102

NEW
103
    foreach (Fixture *fxi, m_doc->fixtures())
×
104
    {
105
        QTreeWidgetItem *topItem = NULL;
×
106
        quint32 uni = fxi->universe();
×
107
        for (int i = 0; i < m_channelsTree->topLevelItemCount(); i++)
×
108
        {
109
            QTreeWidgetItem* tItem = m_channelsTree->topLevelItem(i);
×
110
            quint32 tUni = tItem->text(KColumnID).toUInt();
×
111
            if (tUni == uni)
×
112
            {
113
                topItem = tItem;
×
114
                break;
×
115
            }
116
        }
117
        // Haven't found this universe node ? Create it.
118
        if (topItem == NULL)
×
119
        {
120
            topItem = new QTreeWidgetItem(m_channelsTree);
×
121
            topItem->setText(KColumnName, m_doc->inputOutputMap()->universes().at(uni)->name());
×
122
            topItem->setText(KColumnID, QString::number(uni));
×
123
            topItem->setExpanded(true);
×
124
        }
125

126
        QTreeWidgetItem *fItem = new QTreeWidgetItem(topItem);
×
127
        fItem->setText(KColumnName, fxi->name());
×
128
        fItem->setIcon(KColumnName, fxi->getIconFromType());
×
129
        fItem->setText(KColumnID, QString::number(fxi->id()));
×
130

131
        QList<int> forcedHTP = fxi->forcedHTPChannels();
×
132
        QList<int> forcedLTP = fxi->forcedLTPChannels();
×
133

134
        for (quint32 c = 0; c < fxi->channels(); c++)
×
135
        {
136
            const QLCChannel* channel = fxi->channel(c);
×
137
            QTreeWidgetItem *item = new QTreeWidgetItem(fItem);
×
138
            item->setText(KColumnName, QString("%1:%2").arg(c + 1)
×
139
                          .arg(channel->name()));
×
140
            item->setIcon(KColumnName, channel->getIcon());
×
141
            if (channel->group() == QLCChannel::Intensity &&
×
142
                channel->colour() != QLCChannel::NoColour)
×
143
                item->setText(KColumnType, QLCChannel::colourToString(channel->colour()));
×
144
            else
145
                item->setText(KColumnType, QLCChannel::groupToString(channel->group()));
×
146

147
            item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
×
148
            if (m_mode == ConfigurationMode)
×
149
            {
150
                if (fxi->channelCanFade(c))
×
151
                    item->setCheckState(KColumnSelection, Qt::Checked);
×
152
                else
153
                    item->setCheckState(KColumnSelection, Qt::Unchecked);
×
154

155
                QComboBox *combo = new QComboBox();
×
156
                combo->addItem("HTP", false);
×
157
                combo->addItem("LTP", false);
×
158
                combo->setProperty("treeItem", QVariant::fromValue((void *)item));
×
159
                m_channelsTree->setItemWidget(item, KColumnBehaviour, combo);
×
160

161
                int bIdx = 1;
×
162

163
                if (forcedHTP.contains(int(c)))
×
164
                    bIdx = 0;
×
165
                else if (forcedLTP.contains(int(c)))
×
166
                    bIdx = 1;
×
167
                else if (channel->group() == QLCChannel::Intensity)
×
168
                    bIdx = 0;
×
169

170
                combo->setCurrentIndex(bIdx);
×
171
                // set the other behaviour as true
172
                combo->setItemData(bIdx == 0 ? 1 : 0, true, Qt::UserRole);
×
173

174
                QPushButton *button = new QPushButton();
×
175
                ChannelModifier *mod = fxi->channelModifier(c);
×
176
                if (mod == NULL)
×
177
                    button->setText("...");
×
178
                else
179
                    button->setText(mod->name());
×
180
                button->setProperty("treeItem", QVariant::fromValue((void *)item));
×
181
                m_channelsTree->setItemWidget(item, KColumnModifier, button);
×
182

183
                connect(combo, SIGNAL(currentIndexChanged(int)),
×
184
                        this, SLOT(slotComboChanged(int)));
185
                connect(button, SIGNAL(clicked()),
×
186
                        this, SLOT(slotModifierButtonClicked()));
187
            }
188
            else
189
            {
190
                SceneValue scv(fxi->id(), c);
×
191
                if (m_channelsList.contains(scv))
×
192
                    item->setCheckState(KColumnSelection, Qt::Checked);
×
193
                else
194
                    item->setCheckState(KColumnSelection, Qt::Unchecked);
×
195
            }
196
            item->setText(KColumnID, QString::number(fxi->id()));
×
197
            item->setText(KColumnChIdx, QString::number(c));
×
198
        }
199
    }
200
    m_channelsTree->header()->resizeSections(QHeaderView::ResizeToContents);
×
201
}
×
202

203
QList<QTreeWidgetItem *> ChannelsSelection::getSameChannels(QTreeWidgetItem *item)
×
204
{
205
    QList<QTreeWidgetItem *> sameChannelsList;
×
206
    Fixture *fixture = m_doc->fixture(item->text(KColumnID).toUInt());
×
207
    if (fixture == NULL)
×
208
        return sameChannelsList;
×
209

210
    const QLCFixtureDef *def = fixture->fixtureDef();
×
211
    if (def == NULL)
×
212
        return sameChannelsList;
×
213

214
    QString manufacturer = def->manufacturer();
×
215
    QString model = def->model();
×
216
    int chIdx = item->text(KColumnChIdx).toInt();
×
217

218
    qDebug() << "Manuf:" << manufacturer << ", model:" << model << ", ch:" << chIdx;
×
219

220
    for (int t = 0; t < m_channelsTree->topLevelItemCount(); t++)
×
221
    {
222
        QTreeWidgetItem *uniItem = m_channelsTree->topLevelItem(t);
×
223
        for (int f = 0; f < uniItem->childCount(); f++)
×
224
        {
225
            QTreeWidgetItem *fixItem = uniItem->child(f);
×
226
            quint32 fxID = fixItem->text(KColumnID).toUInt();
×
227
            Fixture *fxi = m_doc->fixture(fxID);
×
228
            if (fxi != NULL)
×
229
            {
230
                const QLCFixtureDef *tmpDef = fxi->fixtureDef();
×
231
                if (tmpDef != NULL)
×
232
                {
233
                    QString tmpManuf = tmpDef->manufacturer();
×
234
                    QString tmpModel = tmpDef->model();
×
235
                    if (tmpManuf == manufacturer && tmpModel == model)
×
236
                    {
237
                        QTreeWidgetItem* chItem = fixItem->child(chIdx);
×
238
                        if (chItem != NULL)
×
239
                            sameChannelsList.append(chItem);
×
240
                    }
241
                }
242
            }
243
        }
244
    }
245

246
    return sameChannelsList;
×
247
}
248

249
void ChannelsSelection::slotItemChecked(QTreeWidgetItem *item, int col)
×
250
{
251
    if (m_applyAllCheck->isChecked() == false || col != KColumnSelection ||
×
252
        item->text(KColumnID).isEmpty())
×
253
        return;
×
254

255
    m_channelsTree->blockSignals(true);
×
256

257
    Qt::CheckState enable = item->checkState(KColumnSelection);
×
258

NEW
259
    foreach (QTreeWidgetItem *chItem, getSameChannels(item))
×
260
        chItem->setCheckState(KColumnSelection, enable);
×
261

262
    m_channelsTree->blockSignals(false);
×
263
}
264

265
void ChannelsSelection::slotItemExpanded()
×
266
{
267
    m_channelsTree->header()->resizeSections(QHeaderView::ResizeToContents);
×
268
}
×
269

270
void ChannelsSelection::slotComboChanged(int idx)
×
271
{
272
    Q_UNUSED(idx)
273
    QComboBox *combo = (QComboBox *)sender();
×
274
    if (combo != NULL)
×
275
    {
276
        combo->setStyleSheet("QWidget {color:red}");
×
277
        if (m_applyAllCheck->isChecked() == true)
×
278
        {
279
            QVariant var = combo->property("treeItem");
×
280
            QTreeWidgetItem *item = (QTreeWidgetItem *) var.value<void *>();
×
281

NEW
282
            foreach (QTreeWidgetItem *chItem, getSameChannels(item))
×
283
            {
284
                QComboBox *chCombo = qobject_cast<QComboBox *>(m_channelsTree->itemWidget(chItem, KColumnBehaviour));
×
285
                if (chCombo != NULL)
×
286
                {
287
                    chCombo->blockSignals(true);
×
288
                    chCombo->setCurrentIndex(idx);
×
289
                    chCombo->setStyleSheet("QWidget {color:red}");
×
290
                    chCombo->blockSignals(false);
×
291
                }
292
            }
293
        }
294
    }
295
}
×
296

297
void ChannelsSelection::slotModifierButtonClicked()
×
298
{
299
    QPushButton *button = (QPushButton *)sender();
×
300
    if (button == NULL)
×
301
        return;
×
302

303
    ChannelModifierEditor cme(m_doc, button->text(), this);
×
304
    if (cme.exec() == QDialog::Rejected)
×
305
        return; // User pressed cancel
×
306

307
    QString displayName = "...";
×
308
    ChannelModifier *modif = cme.selectedModifier();
×
309
    if (modif != NULL)
×
310
        displayName = modif->name();
×
311

312
    button->setText(displayName);
×
313
    if (m_applyAllCheck->isChecked() == true)
×
314
    {
315
        QVariant var = button->property("treeItem");
×
316
        QTreeWidgetItem *item = (QTreeWidgetItem *) var.value<void *>();
×
317

NEW
318
        foreach (QTreeWidgetItem *chItem, getSameChannels(item))
×
319
        {
320
            QPushButton *chButton = qobject_cast<QPushButton *>(m_channelsTree->itemWidget(chItem, KColumnModifier));
×
321
            if (chButton != NULL)
×
322
                chButton->setText(displayName);
×
323
        }
324
    }
325
}
326

327
void ChannelsSelection::accept()
×
328
{
329
    QList<int> excludeList;
×
330
    QList<int> forcedHTPList;
×
331
    QList<int> forcedLTPList;
×
332
    m_channelsList.clear();
×
333

334
    for (int t = 0; t < m_channelsTree->topLevelItemCount(); t++)
×
335
    {
336
        QTreeWidgetItem *uniItem = m_channelsTree->topLevelItem(t);
×
337
        for (int f = 0; f < uniItem->childCount(); f++)
×
338
        {
339
            QTreeWidgetItem *fixItem = uniItem->child(f);
×
340
            quint32 fxID = fixItem->text(KColumnID).toUInt();
×
341
            Fixture *fxi = m_doc->fixture(fxID);
×
342
            if (fxi != NULL)
×
343
            {
344
                excludeList.clear();
×
345
                forcedHTPList.clear();
×
346
                forcedLTPList.clear();
×
347
                for (int c = 0; c < fixItem->childCount(); c++)
×
348
                {
349
                    QTreeWidgetItem *chanItem = fixItem->child(c);
×
350
                    const QLCChannel* channel = fxi->channel(c);
×
351

352
                    if (m_mode == ConfigurationMode)
×
353
                    {
354
                        if (chanItem->checkState(KColumnSelection) == Qt::Unchecked)
×
355
                            excludeList.append(c);
×
356

357
                        QComboBox *combo = (QComboBox *)m_channelsTree->itemWidget(chanItem, KColumnBehaviour);
×
358
                        if (combo != NULL)
×
359
                        {
360
                            if (combo->currentIndex() == 0) // HTP
×
361
                            {
362
                                // do not force a channel that is already HTP by nature
363
                                if (channel->group() != QLCChannel::Intensity)
×
364
                                    forcedHTPList.append(c);
×
365
                            }
366
                            else // LTP
367
                            {
368
                                // do not force a channel that is already LTP by nature
369
                                if (channel->group() == QLCChannel::Intensity)
×
370
                                    forcedLTPList.append(c);
×
371
                            }
372
                        }
373
                        QPushButton *button = (QPushButton *)m_channelsTree->itemWidget(chanItem, KColumnModifier);
×
374
                        if (button != NULL)
×
375
                        {
376
                            ChannelModifier *mod = m_doc->modifiersCache()->modifier(button->text());
×
377
                            fxi->setChannelModifier((quint32)c, mod);
×
378
                        }
379
                    }
380
                    else
381
                    {
382
                        if (chanItem->checkState(KColumnSelection) == Qt::Checked)
×
383
                            m_channelsList.append(SceneValue(fxID, c));
×
384
                    }
385
                }
386
                if (m_mode == ConfigurationMode)
×
387
                {
388
                    fxi->setExcludeFadeChannels(excludeList);
×
389
                    m_doc->updateFixtureChannelCapabilities(fxi->id(), forcedHTPList, forcedLTPList);
×
390
                }
391
            }
392
        }
393
    }
394

395
    /* Close dialog */
396
    QDialog::accept();
×
397
}
×
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