• 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/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
#include <QSettings>
25

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

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

41
#define SETTINGS_GEOMETRY "channelsselection/geometry"
42

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

50
    setupUi(this);
×
51

52
    QStringList hdrLabels;
53
    hdrLabels << tr("Name") << tr("Type");
×
54

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

66
    m_channelsTree->setHeaderLabels(hdrLabels);
×
67

68
    updateFixturesTree();
×
69

70
    QSettings settings;
×
71
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
72
    if (geometrySettings.isValid() == true)
×
73
        restoreGeometry(geometrySettings.toByteArray());
×
74

75
    connect(m_channelsTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
76
            this, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
77
    connect(m_channelsTree, SIGNAL(expanded(QModelIndex)),
×
78
            this, SLOT(slotItemExpanded()));
79
    connect(m_channelsTree, SIGNAL(collapsed(QModelIndex)),
×
80
            this, SLOT(slotItemExpanded()));
81
    connect(m_collapseButton, SIGNAL(clicked(bool)),
×
82
            m_channelsTree, SLOT(collapseAll()));
×
83
    connect(m_expandButton, SIGNAL(clicked(bool)),
×
84
            m_channelsTree, SLOT(expandAll()));
×
85
}
×
86

87
ChannelsSelection::~ChannelsSelection()
×
88
{
89
    QSettings settings;
×
90
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
91
}
×
92

93
void ChannelsSelection::setChannelsList(QList<SceneValue> list)
×
94
{
95
    if (list.count() > 0)
×
96
    {
97
        m_channelsList = list;
×
98
        updateFixturesTree();
×
99
    }
100
}
×
101

102
QList<SceneValue> ChannelsSelection::channelsList()
×
103
{
104
    return m_channelsList;
×
105
}
106

107
void ChannelsSelection::updateFixturesTree()
×
108
{
109
    m_channelsTree->clear();
×
110
    m_channelsTree->setIconSize(QSize(24, 24));
×
111
    m_channelsTree->setAllColumnsShowFocus(true);
×
112

113
    foreach (Fixture *fxi, m_doc->fixtures())
×
114
    {
115
        QTreeWidgetItem *topItem = NULL;
116
        quint32 uni = fxi->universe();
×
117
        for (int i = 0; i < m_channelsTree->topLevelItemCount(); i++)
×
118
        {
119
            QTreeWidgetItem* tItem = m_channelsTree->topLevelItem(i);
×
120
            quint32 tUni = tItem->text(KColumnID).toUInt();
×
121
            if (tUni == uni)
×
122
            {
123
                topItem = tItem;
124
                break;
125
            }
126
        }
127
        // Haven't found this universe node ? Create it.
128
        if (topItem == NULL)
×
129
        {
130
            topItem = new QTreeWidgetItem(m_channelsTree);
×
131
            topItem->setText(KColumnName, m_doc->inputOutputMap()->universes().at(uni)->name());
×
132
            topItem->setText(KColumnID, QString::number(uni));
×
133
            topItem->setExpanded(true);
×
134
        }
135

136
        QTreeWidgetItem *fItem = new QTreeWidgetItem(topItem);
×
137
        fItem->setText(KColumnName, fxi->name());
×
138
        fItem->setIcon(KColumnName, fxi->getIconFromType());
×
139
        fItem->setText(KColumnID, QString::number(fxi->id()));
×
140

141
        QList<int> forcedHTP = fxi->forcedHTPChannels();
×
142
        QList<int> forcedLTP = fxi->forcedLTPChannels();
×
143

144
        for (quint32 c = 0; c < fxi->channels(); c++)
×
145
        {
146
            const QLCChannel* channel = fxi->channel(c);
×
147
            QTreeWidgetItem *item = new QTreeWidgetItem(fItem);
×
148
            item->setText(KColumnName, QString("%1:%2").arg(c + 1)
×
149
                          .arg(channel->name()));
×
150
            item->setIcon(KColumnName, channel->getIcon());
×
151
            if (channel->group() == QLCChannel::Intensity &&
×
152
                channel->colour() != QLCChannel::NoColour)
×
153
                item->setText(KColumnType, QLCChannel::colourToString(channel->colour()));
×
154
            else
155
                item->setText(KColumnType, QLCChannel::groupToString(channel->group()));
×
156

157
            item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
×
158
            if (m_mode == ConfigurationMode)
×
159
            {
160
                if (fxi->channelCanFade(c))
×
161
                    item->setCheckState(KColumnSelection, Qt::Checked);
×
162
                else
163
                    item->setCheckState(KColumnSelection, Qt::Unchecked);
×
164

165
                QComboBox *combo = new QComboBox();
×
166
                combo->addItem("HTP", false);
×
167
                combo->addItem("LTP", false);
×
168
                combo->setProperty("treeItem", QVariant::fromValue((void *)item));
×
169
                m_channelsTree->setItemWidget(item, KColumnBehaviour, combo);
×
170

171
                int bIdx = 1;
172

173
                if (forcedHTP.contains(int(c)))
×
174
                    bIdx = 0;
175
                else if (forcedLTP.contains(int(c)))
×
176
                    bIdx = 1;
177
                else if (channel->group() == QLCChannel::Intensity)
×
178
                    bIdx = 0;
179

180
                combo->setCurrentIndex(bIdx);
×
181
                // set the other behaviour as true
182
                combo->setItemData(bIdx == 0 ? 1 : 0, true, Qt::UserRole);
×
183

184
                QPushButton *button = new QPushButton();
×
185
                ChannelModifier *mod = fxi->channelModifier(c);
×
186
                if (mod == NULL)
×
187
                    button->setText("...");
×
188
                else
189
                    button->setText(mod->name());
×
190
                button->setProperty("treeItem", QVariant::fromValue((void *)item));
×
191
                m_channelsTree->setItemWidget(item, KColumnModifier, button);
×
192

193
                connect(combo, SIGNAL(currentIndexChanged(int)),
×
194
                        this, SLOT(slotComboChanged(int)));
195
                connect(button, SIGNAL(clicked()),
×
196
                        this, SLOT(slotModifierButtonClicked()));
197
            }
198
            else
199
            {
200
                SceneValue scv(fxi->id(), c);
×
201
                if (m_channelsList.contains(scv))
×
202
                    item->setCheckState(KColumnSelection, Qt::Checked);
×
203
                else
204
                    item->setCheckState(KColumnSelection, Qt::Unchecked);
×
205
            }
×
206
            item->setText(KColumnID, QString::number(fxi->id()));
×
207
            item->setText(KColumnChIdx, QString::number(c));
×
208
        }
209
    }
×
210
    m_channelsTree->header()->resizeSections(QHeaderView::ResizeToContents);
×
211
}
×
212

213
QList<QTreeWidgetItem *> ChannelsSelection::getSameChannels(QTreeWidgetItem *item)
×
214
{
215
    QList<QTreeWidgetItem *> sameChannelsList;
216
    Fixture *fixture = m_doc->fixture(item->text(KColumnID).toUInt());
×
217
    if (fixture == NULL)
×
218
        return sameChannelsList;
219

220
    const QLCFixtureDef *def = fixture->fixtureDef();
×
221
    if (def == NULL)
×
222
        return sameChannelsList;
223

224
    QString manufacturer = def->manufacturer();
×
225
    QString model = def->model();
×
226
    int chIdx = item->text(KColumnChIdx).toInt();
×
227

228
    qDebug() << "Manuf:" << manufacturer << ", model:" << model << ", ch:" << chIdx;
229

230
    for (int t = 0; t < m_channelsTree->topLevelItemCount(); t++)
×
231
    {
232
        QTreeWidgetItem *uniItem = m_channelsTree->topLevelItem(t);
×
233
        for (int f = 0; f < uniItem->childCount(); f++)
×
234
        {
235
            QTreeWidgetItem *fixItem = uniItem->child(f);
×
236
            quint32 fxID = fixItem->text(KColumnID).toUInt();
×
237
            Fixture *fxi = m_doc->fixture(fxID);
×
238
            if (fxi != NULL)
×
239
            {
240
                const QLCFixtureDef *tmpDef = fxi->fixtureDef();
×
241
                if (tmpDef != NULL)
×
242
                {
243
                    QString tmpManuf = tmpDef->manufacturer();
×
244
                    QString tmpModel = tmpDef->model();
×
245
                    if (tmpManuf == manufacturer && tmpModel == model)
×
246
                    {
247
                        QTreeWidgetItem* chItem = fixItem->child(chIdx);
×
248
                        if (chItem != NULL)
×
249
                            sameChannelsList.append(chItem);
×
250
                    }
251
                }
×
252
            }
253
        }
254
    }
255

256
    return sameChannelsList;
257
}
×
258

259
void ChannelsSelection::slotItemChecked(QTreeWidgetItem *item, int col)
×
260
{
261
    if (m_applyAllCheck->isChecked() == false || col != KColumnSelection ||
×
262
        item->text(KColumnID).isEmpty())
×
263
        return;
264

265
    m_channelsTree->blockSignals(true);
×
266

267
    Qt::CheckState enable = item->checkState(KColumnSelection);
×
268

269
    foreach (QTreeWidgetItem *chItem, getSameChannels(item))
×
270
        chItem->setCheckState(KColumnSelection, enable);
×
271

272
    m_channelsTree->blockSignals(false);
×
273
}
274

275
void ChannelsSelection::slotItemExpanded()
×
276
{
277
    m_channelsTree->header()->resizeSections(QHeaderView::ResizeToContents);
×
278
}
×
279

280
void ChannelsSelection::slotComboChanged(int idx)
×
281
{
282
    Q_UNUSED(idx)
283
    QComboBox *combo = (QComboBox *)sender();
×
284
    if (combo != NULL)
×
285
    {
286
        combo->setStyleSheet("QWidget {color:red}");
×
287
        if (m_applyAllCheck->isChecked() == true)
×
288
        {
289
            QVariant var = combo->property("treeItem");
×
290
            QTreeWidgetItem *item = (QTreeWidgetItem *) var.value<void *>();
291

292
            foreach (QTreeWidgetItem *chItem, getSameChannels(item))
×
293
            {
294
                QComboBox *chCombo = qobject_cast<QComboBox *>(m_channelsTree->itemWidget(chItem, KColumnBehaviour));
×
295
                if (chCombo != NULL)
×
296
                {
297
                    chCombo->blockSignals(true);
×
298
                    chCombo->setCurrentIndex(idx);
×
299
                    chCombo->setStyleSheet("QWidget {color:red}");
×
300
                    chCombo->blockSignals(false);
×
301
                }
302
            }
303
        }
×
304
    }
305
}
×
306

307
void ChannelsSelection::slotModifierButtonClicked()
×
308
{
309
    QPushButton *button = (QPushButton *)sender();
×
310
    if (button == NULL)
×
311
        return;
×
312

313
    ChannelModifierEditor cme(m_doc, button->text(), this);
×
314
    if (cme.exec() == QDialog::Rejected)
×
315
        return; // User pressed cancel
316

317
    QString displayName = "...";
×
318
    ChannelModifier *modif = cme.selectedModifier();
×
319
    if (modif != NULL)
×
320
        displayName = modif->name();
×
321

322
    button->setText(displayName);
×
323
    if (m_applyAllCheck->isChecked() == true)
×
324
    {
325
        QVariant var = button->property("treeItem");
×
326
        QTreeWidgetItem *item = (QTreeWidgetItem *) var.value<void *>();
327

328
        foreach (QTreeWidgetItem *chItem, getSameChannels(item))
×
329
        {
330
            QPushButton *chButton = qobject_cast<QPushButton *>(m_channelsTree->itemWidget(chItem, KColumnModifier));
×
331
            if (chButton != NULL)
×
332
                chButton->setText(displayName);
×
333
        }
334
    }
×
335
}
×
336

337
void ChannelsSelection::accept()
×
338
{
339
    QList<int> excludeList;
340
    QList<int> forcedHTPList;
341
    QList<int> forcedLTPList;
342
    m_channelsList.clear();
×
343

344
    for (int t = 0; t < m_channelsTree->topLevelItemCount(); t++)
×
345
    {
346
        QTreeWidgetItem *uniItem = m_channelsTree->topLevelItem(t);
×
347
        for (int f = 0; f < uniItem->childCount(); f++)
×
348
        {
349
            QTreeWidgetItem *fixItem = uniItem->child(f);
×
350
            quint32 fxID = fixItem->text(KColumnID).toUInt();
×
351
            Fixture *fxi = m_doc->fixture(fxID);
×
352
            if (fxi != NULL)
×
353
            {
354
                excludeList.clear();
×
355
                forcedHTPList.clear();
×
356
                forcedLTPList.clear();
×
357
                for (int c = 0; c < fixItem->childCount(); c++)
×
358
                {
359
                    QTreeWidgetItem *chanItem = fixItem->child(c);
×
360
                    const QLCChannel* channel = fxi->channel(c);
×
361

362
                    if (m_mode == ConfigurationMode)
×
363
                    {
364
                        if (chanItem->checkState(KColumnSelection) == Qt::Unchecked)
×
365
                            excludeList.append(c);
×
366

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

405
    /* Close dialog */
406
    QDialog::accept();
×
407
}
×
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