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

mcallegari / qlcplus / 7307414152

23 Dec 2023 09:18AM UTC coverage: 32.067%. Remained the same
7307414152

push

github

web-flow
Merge pull request #1493 from yestalgia/readme

Update Readme

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/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_APPLYALL "addchannelsgroup/applyall"
39

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

50
    setupUi(this);
×
51

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

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

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

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

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

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

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

121
    QSettings settings;
×
122
    QVariant var = settings.value(SETTINGS_APPLYALL);
×
123
    if (var.isValid() == true)
×
124
       m_applyAllCheck->setChecked(var.toBool());
×
125

126
    m_inputSelWidget = new InputSelectionWidget(m_doc, this);
×
127
    m_inputSelWidget->setKeyInputVisibility(false);
×
128
    m_inputSelWidget->setInputSource(group->inputSource());
×
129
    m_inputSelWidget->show();
×
130
    m_extControlLayout->addWidget(m_inputSelWidget);
×
131

132
    if (m_checkedChannels == 0)
×
133
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
×
134

135
    connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
136
            this, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
137
    connect(m_collapseButton, SIGNAL(clicked(bool)),
×
138
            m_tree, SLOT(collapseAll()));
×
139
    connect(m_expandButton, SIGNAL(clicked(bool)),
×
140
            m_tree, SLOT(expandAll()));
×
141
}
×
142

143
AddChannelsGroup::~AddChannelsGroup()
×
144
{
145
    QSettings settings;
×
146
    settings.setValue(SETTINGS_APPLYALL, m_applyAllCheck->isChecked());
×
147
}
×
148

149
void AddChannelsGroup::accept()
×
150
{
151
    m_chansGroup->resetChannels();
×
152

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

177
    m_chansGroup->setName(m_groupNameEdit->text());
×
178
    m_chansGroup->setInputSource(m_inputSelWidget->inputSource());
×
179
    QDialog::accept();
×
180
}
×
181

182
void AddChannelsGroup::slotItemChecked(QTreeWidgetItem *item, int col)
×
183
{
184
    if (m_isUpdating == true || col != KColumnGroup || item->text(KColumnID).isEmpty())
×
185
        return;
×
186

187
    m_isUpdating = true;
×
188

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

202
        const QLCFixtureDef *def = fixture->fixtureDef();
×
203
        if (def == NULL)
×
204
            return;
×
205

206
        QString manufacturer = def->manufacturer();
×
207
        QString model = def->model();
×
208
        QString mode = fixture->fixtureMode() ? fixture->fixtureMode()->name() : "";
×
209

210
        int chIdx = item->text(KColumnChIdx).toInt();
×
211
        Qt::CheckState enable = item->checkState(KColumnGroup);
×
212

213
        qDebug() << "Manuf:" << manufacturer << ", model:" << model << ", ch:" << chIdx;
×
214

215
        for (int t = 0; t < m_tree->topLevelItemCount(); t++)
×
216
        {
217
            QTreeWidgetItem *uniItem = m_tree->topLevelItem(t);
×
218
            for (int f = 0; f < uniItem->childCount(); f++)
×
219
            {
220
                QTreeWidgetItem *fixItem = uniItem->child(f);
×
221
                quint32 fxID = fixItem->text(KColumnID).toUInt();
×
222
                Fixture *fxi = m_doc->fixture(fxID);
×
223
                if (fxi != NULL)
×
224
                {
225
                    QString tmpMode = fxi->fixtureMode() ? fxi->fixtureMode()->name() : "";
×
226
                    const QLCFixtureDef *tmpDef = fxi->fixtureDef();
×
227
                    if (tmpDef != NULL)
×
228
                    {
229
                        QString tmpManuf = tmpDef->manufacturer();
×
230
                        QString tmpModel = tmpDef->model();
×
231
                        if (tmpManuf == manufacturer && tmpModel == model && tmpMode == mode)
×
232
                        {
233
                            QTreeWidgetItem* item = fixItem->child(chIdx);
×
234
                            if (item != NULL)
×
235
                            {
236
                                item->setCheckState(KColumnGroup, enable);
×
237
                                if (enable == Qt::Checked)
×
238
                                    m_checkedChannels++;
×
239
                                else
240
                                    m_checkedChannels--;
×
241
                            }
242
                        }
243
                    }
244
                }
245
            }
246
        }
247
    }
248

249
    if (m_checkedChannels > 0)
×
250
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
×
251
    else
252
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
×
253

254
    m_isUpdating = false;
×
255
}
256

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