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

mcallegari / qlcplus / 13763878004

10 Mar 2025 11:47AM UTC coverage: 31.887%. Remained the same
13763878004

push

github

mcallegari
4.14.1 release to date

14701 of 46103 relevant lines covered (31.89%)

26418.09 hits per line

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

0.0
/ui/src/addchannelsgroup.cpp
1
/*
2
  Q Light Controller
3
  addchannelsgroup.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 <QPushButton>
21
#include <QDebug>
22
#include <QSettings>
23

24
#include "inputselectionwidget.h"
25
#include "addchannelsgroup.h"
26
#include "qlcfixturemode.h"
27
#include "qlcfixturedef.h"
28
#include "channelsgroup.h"
29
#include "fixture.h"
30
#include "doc.h"
31

32
#define KColumnName  0
33
#define KColumnType  1
34
#define KColumnGroup 2
35
#define KColumnChIdx 3
36
#define KColumnID    4
37

38
#define SETTINGS_GEOMETRY "addchannelsgroup/geometry"
39
#define SETTINGS_APPLYALL "addchannelsgroup/applyall"
40

41
AddChannelsGroup::AddChannelsGroup(QWidget* parent, Doc* doc, ChannelsGroup *group)
×
42
    : QDialog(parent)
43
    , m_doc(doc)
×
44
    , m_chansGroup(group)
×
45
    , m_checkedChannels(0)
×
46
    , m_isUpdating(false)
×
47
{
48
    Q_ASSERT(doc != NULL);
49
    Q_ASSERT(m_chansGroup != NULL);
50

51
    setupUi(this);
×
52

53
    m_tree->header()->setSectionHidden(KColumnID, true);
×
54
    m_tree->setSelectionMode(QAbstractItemView::MultiSelection);
×
55
    m_tree->setAlternatingRowColors(true);
×
56
    m_tree->setIconSize(QSize(20, 20));
×
57

58
    m_groupNameEdit->setText(group->name());
×
59

60
    QList <SceneValue> chans = group->getChannels();
×
61
    int ch = 0;
62

63
    foreach (Fixture* fxi, m_doc->fixtures())
×
64
    {
65
        QTreeWidgetItem *topItem = NULL;
66
        quint32 uni = fxi->universe();
×
67
        for (int i = 0; i < m_tree->topLevelItemCount(); i++)
×
68
        {
69
            QTreeWidgetItem* tItem = m_tree->topLevelItem(i);
×
70
            quint32 tUni = tItem->text(KColumnID).toUInt();
×
71
            if (tUni == uni)
×
72
            {
73
                topItem = tItem;
74
                break;
75
            }
76
        }
77
        // Haven't found this universe node ? Create it.
78
        if (topItem == NULL)
×
79
        {
80
            topItem = new QTreeWidgetItem(m_tree);
×
81
            topItem->setText(KColumnName, m_doc->inputOutputMap()->universes().at(uni)->name());
×
82
            topItem->setText(KColumnID, QString::number(uni));
×
83
            topItem->setExpanded(true);
×
84
        }
85

86
        QTreeWidgetItem *fItem = new QTreeWidgetItem(topItem);
×
87
        fItem->setExpanded(true);
×
88
        fItem->setText(KColumnName, fxi->name());
×
89
        fItem->setIcon(KColumnName, fxi->getIconFromType());
×
90
        fItem->setText(KColumnID, QString::number(fxi->id()));
×
91

92
        for (quint32 c = 0; c < fxi->channels(); c++)
×
93
        {
94
            const QLCChannel* channel = fxi->channel(c);
×
95
            QTreeWidgetItem *item = new QTreeWidgetItem(fItem);
×
96
            item->setText(KColumnName, QString("%1:%2").arg(c + 1)
×
97
                          .arg(channel->name()));
×
98
            item->setIcon(KColumnName, channel->getIcon());
×
99
            if (channel->group() == QLCChannel::Intensity &&
×
100
                channel->colour() != QLCChannel::NoColour)
×
101
                item->setText(KColumnType, QLCChannel::colourToString(channel->colour()));
×
102
            else
103
                item->setText(KColumnType, QLCChannel::groupToString(channel->group()));
×
104

105
            item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
×
106
            if (chans.count() > ch &&
×
107
                chans.at(ch).fxi == fxi->id() &&
×
108
                chans.at(ch).channel == c)
×
109
            {
110
                item->setCheckState(KColumnGroup, Qt::Checked);
×
111
                m_checkedChannels++;
×
112
                ch++;
×
113
            }
114
            else
115
                item->setCheckState(KColumnGroup, Qt::Unchecked);
×
116
            item->setText(KColumnID, QString::number(fxi->id()));
×
117
            item->setText(KColumnChIdx, QString::number(c));
×
118
        }
119
    }
120
    m_tree->header()->resizeSections(QHeaderView::ResizeToContents);
×
121

122
    QSettings settings;
×
123
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
124
    if (geometrySettings.isValid() == true)
×
125
        restoreGeometry(geometrySettings.toByteArray());
×
126
    QVariant apply4AllSettings = settings.value(SETTINGS_APPLYALL);
×
127
    if (apply4AllSettings.isValid() == true)
×
128
       m_applyAllCheck->setChecked(apply4AllSettings.toBool());
×
129

130
    m_inputSelWidget = new InputSelectionWidget(m_doc, this);
×
131
    m_inputSelWidget->setKeyInputVisibility(false);
×
132
    m_inputSelWidget->setInputSource(group->inputSource());
×
133
    m_inputSelWidget->show();
×
134
    m_extControlLayout->addWidget(m_inputSelWidget);
×
135

136
    if (m_checkedChannels == 0)
×
137
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
×
138

139
    connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
140
            this, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
141
    connect(m_collapseButton, SIGNAL(clicked(bool)),
×
142
            m_tree, SLOT(collapseAll()));
×
143
    connect(m_expandButton, SIGNAL(clicked(bool)),
×
144
            m_tree, SLOT(expandAll()));
×
145
}
×
146

147
AddChannelsGroup::~AddChannelsGroup()
×
148
{
149
    QSettings settings;
×
150
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
151
    settings.setValue(SETTINGS_APPLYALL, m_applyAllCheck->isChecked());
×
152
}
×
153

154
void AddChannelsGroup::accept()
×
155
{
156
    m_chansGroup->resetChannels();
×
157

158
    for (int t = 0; t < m_tree->topLevelItemCount(); t++)
×
159
    {
160
        QTreeWidgetItem *uniItem = m_tree->topLevelItem(t);
×
161
        for (int f = 0; f < uniItem->childCount(); f++)
×
162
        {
163
            QTreeWidgetItem *fixItem = uniItem->child(f);
×
164
            quint32 fxID = fixItem->text(KColumnID).toUInt();
×
165
            Fixture *fxi = m_doc->fixture(fxID);
×
166
            if (fxi != NULL)
×
167
            {
168
                for (int c = 0; c < fixItem->childCount(); c++)
×
169
                {
170
                    QTreeWidgetItem *chanItem = fixItem->child(c);
×
171
                    if (chanItem->checkState(KColumnGroup) == Qt::Checked)
×
172
                    {
173
                        m_chansGroup->addChannel(QString(chanItem->text(KColumnID)).toUInt(),
×
174
                                                 QString(chanItem->text(KColumnChIdx)).toUInt());
×
175
                        qDebug() << "Added channel with ID:" << chanItem->text(KColumnID) << ", and channel:" << chanItem->text(KColumnChIdx);
176
                    }
177
                }
178
            }
179
        }
180
    }
181

182
    m_chansGroup->setName(m_groupNameEdit->text());
×
183
    m_chansGroup->setInputSource(m_inputSelWidget->inputSource());
×
184
    QDialog::accept();
×
185
}
×
186

187
void AddChannelsGroup::slotItemChecked(QTreeWidgetItem *item, int col)
×
188
{
189
    if (m_isUpdating == true || col != KColumnGroup || item->text(KColumnID).isEmpty())
×
190
        return;
191

192
    m_isUpdating = true;
×
193

194
    if (m_applyAllCheck->isChecked() == false)
×
195
    {
196
        if (item->checkState(col) == Qt::Checked)
×
197
            m_checkedChannels++;
×
198
        else
199
            m_checkedChannels--;
×
200
    }
201
    else
202
    {
203
        Fixture *fixture = m_doc->fixture(item->text(KColumnID).toUInt());
×
204
        if (fixture == NULL)
×
205
            return;
×
206

207
        const QLCFixtureDef *def = fixture->fixtureDef();
×
208
        if (def == NULL)
×
209
            return;
210

211
        QString manufacturer = def->manufacturer();
×
212
        QString model = def->model();
×
213
        QString mode = fixture->fixtureMode() ? fixture->fixtureMode()->name() : "";
×
214

215
        int chIdx = item->text(KColumnChIdx).toInt();
×
216
        Qt::CheckState enable = item->checkState(KColumnGroup);
×
217

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

220
        for (int t = 0; t < m_tree->topLevelItemCount(); t++)
×
221
        {
222
            QTreeWidgetItem *uniItem = m_tree->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
                    QString tmpMode = fxi->fixtureMode() ? fxi->fixtureMode()->name() : "";
×
231
                    const QLCFixtureDef *tmpDef = fxi->fixtureDef();
×
232
                    if (tmpDef != NULL)
×
233
                    {
234
                        QString tmpManuf = tmpDef->manufacturer();
×
235
                        QString tmpModel = tmpDef->model();
×
236
                        if (tmpManuf == manufacturer && tmpModel == model && tmpMode == mode)
×
237
                        {
238
                            QTreeWidgetItem* item = fixItem->child(chIdx);
×
239
                            if (item != NULL)
×
240
                            {
241
                                item->setCheckState(KColumnGroup, enable);
×
242
                                if (enable == Qt::Checked)
×
243
                                    m_checkedChannels++;
×
244
                                else
245
                                    m_checkedChannels--;
×
246
                            }
247
                        }
248
                    }
×
249
                }
×
250
            }
251
        }
252
    }
×
253

254
    if (m_checkedChannels > 0)
×
255
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
×
256
    else
257
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
×
258

259
    m_isUpdating = false;
×
260
}
261

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