• 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/selectinputchannel.cpp
1
/*
2
  Q Light Controller
3
  selectinputchannel.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 <QSettings>
21
#include <QTreeWidgetItem>
22
#include <QTreeWidget>
23
#include <QDebug>
24
#include <QAction>
25

26
#include "selectinputchannel.h"
27
#include "qlcinputchannel.h"
28
#include "qlcinputprofile.h"
29
#include "inputoutputmap.h"
30
#include "qlcchannel.h"
31
#include "inputpatch.h"
32

33
#define KColumnName     0
34
#define KColumnUniverse 1
35
#define KColumnChannel  2
36

37
#define SETTINGS_GEOMETRY "selectinputchannel/geometry"
38
#define SETTINGS_ALLOWUNPATCHED "selectinputchannel/allowunpatched"
39

40
/****************************************************************************
41
 * Initialization
42
 ****************************************************************************/
43

44
SelectInputChannel::SelectInputChannel(QWidget* parent, InputOutputMap *ioMap)
×
45
    : QDialog(parent)
46
    , m_ioMap(ioMap)
×
47
{
48
    Q_ASSERT(ioMap != NULL);
×
49

50
    m_universe = InputOutputMap::invalidUniverse();
×
51
    m_channel = QLCChannel::invalid();
×
52

53
    setupUi(this);
×
54

55
    loadSettings();
×
56

57
    QAction* action = new QAction(this);
×
58
    action->setShortcut(QKeySequence(QKeySequence::Close));
×
59
    connect(action, SIGNAL(triggered(bool)), this, SLOT(reject()));
×
60
    addAction(action);
×
61

62
    connect(m_allowUnpatchedCb, SIGNAL(clicked()), this, SLOT(slotUnpatchedClicked()));
×
63

64
    fillTree();
×
65

66
    /* Listen to item changed signals so that we can catch user's
67
       manual input for <...> nodes. Connect AFTER filling the tree
68
       so all the initial item->setText()'s won't get caught here. */
69
    connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
70
            this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
71
}
×
72

73
SelectInputChannel::~SelectInputChannel()
×
74
{
75
    saveSettings();
×
76
}
×
77

78
void SelectInputChannel::saveSettings()
×
79
{
80
    QSettings settings;
×
81
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
82
    settings.setValue(SETTINGS_ALLOWUNPATCHED, m_allowUnpatchedCb->isChecked());
×
83
}
×
84

85
void SelectInputChannel::loadSettings()
×
86
{
87
    QSettings settings;
×
88
    QVariant geometry = settings.value(SETTINGS_GEOMETRY);
×
89
    if (geometry.isValid())
×
90
        restoreGeometry(geometry.toByteArray());
×
91
    QVariant allowUnpatched = settings.value(SETTINGS_ALLOWUNPATCHED);
×
92
    if (allowUnpatched.isValid())
×
93
        m_allowUnpatchedCb->setChecked(allowUnpatched.toBool());
×
94
}
×
95

96
void SelectInputChannel::accept()
×
97
{
98
    QTreeWidgetItem* item;
99

100
    /* Extract data from the selected item */
101
    item = m_tree->currentItem();
×
102
    if (item != NULL)
×
103
    {
104
        m_universe = item->text(KColumnUniverse).toUInt();
×
105
        m_channel = item->text(KColumnChannel).toUInt();
×
106
    }
107

108
    QDialog::accept();
×
109
}
×
110

111
void SelectInputChannel::slotUnpatchedClicked()
×
112
{
113
    disconnect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
114
            this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
115
    fillTree();
×
116
    connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
×
117
            this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
118
}
×
119

120
/****************************************************************************
121
 * Selection
122
 ****************************************************************************/
123

124
quint32 SelectInputChannel::universe() const
×
125
{
126
    return m_universe;
×
127
}
128

129
quint32 SelectInputChannel::channel() const
×
130
{
131
    return m_channel;
×
132
}
133

134
/****************************************************************************
135
 * Tree widget
136
 ****************************************************************************/
137

138
void SelectInputChannel::fillTree()
×
139
{
140
    QLCInputChannel* channel;
141
    QTreeWidgetItem* uniItem;
142
    QTreeWidgetItem* chItem;
143
    QLCInputProfile* profile;
144
    quint32 uni;
145
    InputPatch* patch;
146

147
    // Clear tree
148
    while (m_tree->takeTopLevelItem(0));
×
149

150
    /* Add an option to select no input at all */
151
    chItem = new QTreeWidgetItem(m_tree);
×
152
    chItem->setText(KColumnName, KInputNone);
×
153
    chItem->setText(KColumnUniverse, QString("%1")
×
154
                    .arg(InputOutputMap::invalidUniverse()));
×
155
    chItem->setText(KColumnChannel, QString("%1")
×
156
                    .arg(QLCChannel::invalid()));
×
157

158
    for (uni = 0; uni < m_ioMap->universesCount(); uni++)
×
159
    {
160
        /* Get the patch associated to the current universe */
161
        patch = m_ioMap->inputPatch(uni);
×
162
        if (patch == NULL && !m_allowUnpatchedCb->isChecked())
×
163
            continue;
×
164

165
        /* Make an item for each universe */
166
        uniItem = new QTreeWidgetItem(m_tree);
×
167
        updateUniverseItem(uniItem, uni, patch);
×
168

169
        /* Add a manual option to each patched universe */
170
        chItem = new QTreeWidgetItem(uniItem);
×
171
        updateChannelItem(chItem, uni, NULL, NULL);
×
172

173
        /* Don't try to find a profile on an non-patched universe */
174
        if (patch == NULL)
×
175
            continue;
×
176

177
        /* Add known channels from profile (if any) */
178
        profile = patch->profile();
×
179
        if (profile != NULL)
×
180
        {
181
            QMapIterator <quint32, QLCInputChannel*>
182
            it(profile->channels());
×
183
            while (it.hasNext() == true)
×
184
            {
185
                channel = it.next().value();
×
186
                Q_ASSERT(channel != NULL);
×
187

188
                chItem = new QTreeWidgetItem(uniItem);
×
189
                updateChannelItem(chItem, uni, channel,
×
190
                                  profile);
191
            }
192
        }
193
    }
194
}
×
195

196
void SelectInputChannel::updateChannelItem(QTreeWidgetItem* item,
×
197
        quint32 universe,
198
        const QLCInputChannel* channel,
199
        const QLCInputProfile* profile)
200
{
201
    Q_ASSERT(item != NULL);
×
202

203
    /* Add a manual option to each universe */
204
    item->setText(KColumnUniverse, QString("%1").arg(universe));
×
205
    if (channel == NULL && profile == NULL)
×
206
    {
207
        item->setFlags(item->flags() | Qt::ItemIsEditable);
×
208
        item->setText(KColumnName,
×
209
                      tr("<Double click here to enter channel number manually>"));
×
210
        item->setText(KColumnChannel,
×
211
                      QString("%1").arg(QLCChannel::invalid()));
×
212
    }
213
    else
214
    {
215
        item->setText(KColumnName, QString("%1: %2")
×
216
                      .arg(profile->channelNumber(channel) + 1)
×
217
                      .arg(channel->name()));
×
218
        item->setText(KColumnChannel, QString("%1")
×
219
                      .arg(profile->channelNumber(channel)));
×
220

221
        /* Display nice icons to indicate channel type */
222
        item->setIcon(KColumnName, channel->icon());
×
223
    }
224
}
×
225

226
void SelectInputChannel::updateUniverseItem(QTreeWidgetItem* item,
×
227
        quint32 universe,
228
        InputPatch* patch)
229
{
230
    QString name;
×
231

232
    Q_ASSERT(item != NULL);
×
233

234
    if (patch == NULL)
×
235
    {
236
        /* The current universe doesn't have an input assigned to it */
237
        name = QString("%1: %2").arg(universe + 1).arg(KInputNone);
×
238
    }
239
    else
240
    {
241
        /* The current universe has something assigned to it. Check,
242
           whether it has an input profile. */
243
        if (patch->profile() != NULL)
×
244
        {
245
            name = QString("%1: %2").arg(universe + 1)
×
246
                   .arg(patch->profileName());
×
247
        }
248
        else
249
        {
250
            name = QString("%1: %2 / %3").arg(universe + 1)
×
251
                   .arg(patch->pluginName())
×
252
                   .arg(patch->inputName());
×
253
        }
254
    }
255

256
    item->setText(KColumnName, name);
×
257
    item->setText(KColumnUniverse, QString("%1").arg(universe));
×
258
    item->setText(KColumnChannel, QString("%1").arg(QLCChannel::invalid()));
×
259
}
×
260

261
void SelectInputChannel::slotItemChanged(QTreeWidgetItem* item, int column)
×
262
{
263
    quint32 channel;
264

265
    Q_ASSERT(item != NULL);
×
266
    if (column != KColumnName)
×
267
        return;
×
268

269
    /* Extract only numbers from the input data */
270
    channel = item->text(KColumnName).toUInt();
×
271

272
    /* Put the entered channel number also to the channel column */
273
    item->setText(KColumnChannel, QString("%1").arg(channel - 1));
×
274
}
275

276
void SelectInputChannel::slotItemDoubleClicked(QTreeWidgetItem* item, int column)
×
277
{
278
    Q_UNUSED(column);
279

280
    if (!(item->flags() & Qt::ItemIsEditable))
×
281
        accept();
×
282
}
×
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