• 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

31.51
/ui/src/functionselection.cpp
1
/*
2
  Q Light Controller
3
  functionselection.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 <QTreeWidgetItem>
21
#include <QTreeWidget>
22
#include <QHeaderView>
23
#include <QMessageBox>
24
#include <QPushButton>
25
#include <QSettings>
26
#include <QToolBar>
27
#include <QDebug>
28

29
#include "functionselection.h"
30
#include "functionstreewidget.h"
31
#include "doc.h"
32

33
#define KColumnName 0
34

35
#define SETTINGS_GEOMETRY "functionselect/geometry"
36

37
/*****************************************************************************
38
 * Initialization
39
 *****************************************************************************/
40

41
FunctionSelection::FunctionSelection(QWidget* parent, Doc* doc)
6✔
42
    : QDialog(parent)
43
    , m_doc(doc)
6✔
44
    , m_isInitializing(true)
6✔
45
    , m_none(false)
6✔
46
    , m_noneItem(NULL)
6✔
47
    , m_newTrack(false)
6✔
48
    , m_newTrackItem(NULL)
6✔
49
    , m_multiSelection(true)
6✔
50
    , m_runningOnlyFlag(false)
6✔
51
    , m_filter(Function::SceneType | Function::ChaserType | Function::SequenceType | Function::CollectionType |
6✔
52
               Function::EFXType | Function::ScriptType | Function::RGBMatrixType |
53
               Function::ShowType | Function::AudioType | Function::VideoType)
54
    , m_disableFilters(0)
6✔
55
    , m_constFilter(false)
6✔
56
{
57
    Q_ASSERT(doc != NULL);
58

59
    setupUi(this);
6✔
60

61
    m_funcTree = new FunctionsTreeWidget(m_doc, this);
6✔
62
    QStringList labels;
63
    labels << tr("Functions");
6✔
64
    m_funcTree->setHeaderLabels(labels);
6✔
65
    m_funcTree->setRootIsDecorated(true);
6✔
66
    m_funcTree->setAllColumnsShowFocus(true);
6✔
67
    m_funcTree->setSortingEnabled(true);
6✔
68
    m_funcTree->sortByColumn(KColumnName, Qt::AscendingOrder);
6✔
69
    m_treeVbox->addWidget(m_funcTree);
6✔
70

71
    QAction* action = new QAction(this);
6✔
72
    action->setShortcut(QKeySequence(QKeySequence::Close));
6✔
73
    connect(action, SIGNAL(triggered(bool)), this, SLOT(reject()));
6✔
74
    addAction(action);
6✔
75

76
    connect(m_allFunctionsRadio, SIGNAL(clicked()),
6✔
77
            this, SLOT(slotAllFunctionsChecked()));
78

79
    connect(m_runningFunctionsRadio, SIGNAL(clicked()),
6✔
80
            this, SLOT(slotRunningFunctionsChecked()));
81

82
    connect(m_sceneCheck, SIGNAL(toggled(bool)),
6✔
83
            this, SLOT(slotSceneChecked(bool)));
84

85
    connect(m_chaserCheck, SIGNAL(toggled(bool)),
6✔
86
            this, SLOT(slotChaserChecked(bool)));
87

88
    connect(m_sequenceCheck, SIGNAL(toggled(bool)),
6✔
89
            this, SLOT(slotSequenceChecked(bool)));
90

91
    connect(m_efxCheck, SIGNAL(toggled(bool)),
6✔
92
            this, SLOT(slotEFXChecked(bool)));
93

94
    connect(m_collectionCheck, SIGNAL(toggled(bool)),
6✔
95
            this, SLOT(slotCollectionChecked(bool)));
96

97
    connect(m_scriptCheck, SIGNAL(toggled(bool)),
6✔
98
            this, SLOT(slotScriptChecked(bool)));
99

100
    connect(m_rgbMatrixCheck, SIGNAL(toggled(bool)),
6✔
101
            this, SLOT(slotRGBMatrixChecked(bool)));
102

103
    connect(m_showCheck, SIGNAL(toggled(bool)),
6✔
104
            this, SLOT(slotShowChecked(bool)));
105

106
    connect(m_audioCheck, SIGNAL(toggled(bool)),
6✔
107
            this, SLOT(slotAudioChecked(bool)));
108

109
    connect(m_videoCheck, SIGNAL(toggled(bool)),
6✔
110
            this, SLOT(slotVideoChecked(bool)));
111

112
    QSettings settings;
6✔
113
    QVariant var = settings.value(SETTINGS_FILTER);
12✔
114
    if (var.isValid() == true)
6✔
115
        setFilter(var.toInt(), false);
5✔
116

117
    var = settings.value(SETTINGS_GEOMETRY);
12✔
118
    if (var.isValid() == true)
6✔
119
        restoreGeometry(var.toByteArray());
5✔
120
}
12✔
121

122
int FunctionSelection::exec()
×
123
{
124
    m_sceneCheck->setChecked(m_filter & Function::SceneType);
×
125
    m_chaserCheck->setChecked(m_filter & Function::ChaserType);
×
126
    m_sequenceCheck->setChecked(m_filter & Function::SequenceType);
×
127
    m_efxCheck->setChecked(m_filter & Function::EFXType);
×
128
    m_collectionCheck->setChecked(m_filter & Function::CollectionType);
×
129
    m_scriptCheck->setChecked(m_filter & Function::ScriptType);
×
130
    m_rgbMatrixCheck->setChecked(m_filter & Function::RGBMatrixType);
×
131
    m_showCheck->setChecked(m_filter & Function::ShowType);
×
132
    m_audioCheck->setChecked(m_filter & Function::AudioType);
×
133
    m_videoCheck->setChecked(m_filter & Function::VideoType);
×
134

135
    if (m_constFilter == true)
×
136
    {
137
        m_sceneCheck->setEnabled(false);
×
138
        m_chaserCheck->setEnabled(false);
×
139
        m_sequenceCheck->setEnabled(false);
×
140
        m_efxCheck->setEnabled(false);
×
141
        m_collectionCheck->setEnabled(false);
×
142
        m_scriptCheck->setEnabled(false);
×
143
        m_rgbMatrixCheck->setEnabled(false);
×
144
        m_showCheck->setEnabled(false);
×
145
        m_audioCheck->setEnabled(false);
×
146
        m_videoCheck->setEnabled(false);
×
147
    }
148
    else
149
    {
150
        m_sceneCheck->setDisabled(m_disableFilters & Function::SceneType);
×
151
        m_chaserCheck->setDisabled(m_disableFilters & Function::ChaserType);
×
152
        m_sequenceCheck->setDisabled(m_disableFilters & Function::SequenceType);
×
153
        m_efxCheck->setDisabled(m_disableFilters & Function::EFXType);
×
154
        m_collectionCheck->setDisabled(m_disableFilters & Function::CollectionType);
×
155
        m_scriptCheck->setDisabled(m_disableFilters & Function::ScriptType);
×
156
        m_rgbMatrixCheck->setDisabled(m_disableFilters & Function::RGBMatrixType);
×
157
        m_showCheck->setDisabled(m_disableFilters & Function::ShowType);
×
158
        m_audioCheck->setDisabled(m_disableFilters & Function::AudioType);
×
159
        m_videoCheck->setDisabled(m_disableFilters & Function::VideoType);
×
160
    }
161

162
    /* Multiple/single selection */
163
    if (m_multiSelection == true)
×
164
        m_funcTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
×
165
    else
166
        m_funcTree->setSelectionMode(QAbstractItemView::SingleSelection);
×
167

168
    m_isInitializing = false;
×
169

170
    refillTree();
×
171

172
    connect(m_funcTree, SIGNAL(itemSelectionChanged()),
×
173
            this, SLOT(slotItemSelectionChanged()));
174
    connect(m_funcTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
×
175
            this, SLOT(slotItemDoubleClicked(QTreeWidgetItem*)));
176

177
    slotItemSelectionChanged();
×
178

179
    return QDialog::exec();
×
180
}
181

182
void FunctionSelection::showNone(bool show)
×
183
{
184
    m_none = show;
×
185

186
    refillTree();
×
187
}
×
188

189
void FunctionSelection::showNewTrack(bool show)
×
190
{
191
    m_newTrack = show;
×
192

193
    refillTree();
×
194
}
×
195

196
FunctionSelection::~FunctionSelection()
6✔
197
{
198
    if (!m_constFilter)
6✔
199
    {
200
        QSettings settings;
5✔
201
        settings.setValue(SETTINGS_FILTER, m_filter);
5✔
202
    }
5✔
203

204
    QSettings settings;
6✔
205
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
6✔
206
}
6✔
207

208
/*****************************************************************************
209
 * Multi-selection
210
 *****************************************************************************/
211

212
void FunctionSelection::setMultiSelection(bool multi)
×
213
{
214
    m_multiSelection = multi;
×
215
}
×
216

217
/*********************************************************************
218
 * Functions filter
219
 *********************************************************************/
220

221
void FunctionSelection::slotAllFunctionsChecked()
×
222
{
223
    m_runningOnlyFlag = false;
×
224
    refillTree();
×
225
}
×
226

227
void FunctionSelection::slotRunningFunctionsChecked()
×
228
{
229
    m_runningOnlyFlag = true;
×
230
    refillTree();
×
231
}
×
232

233
/*****************************************************************************
234
 * Filter
235
 *****************************************************************************/
236

237
void FunctionSelection::setFilter(int types, bool constFilter)
6✔
238
{
239
    m_filter = types;
6✔
240
    m_constFilter = constFilter;
6✔
241
}
6✔
242

243
void FunctionSelection::disableFilters(int types)
×
244
{
245
    m_disableFilters = types;
×
246
}
×
247

248
/*****************************************************************************
249
 * Disabled functions
250
 *****************************************************************************/
251

252
void FunctionSelection::setDisabledFunctions(const QList <quint32>& ids)
×
253
{
254
    m_disabledFunctions = ids;
×
255
}
×
256

257
QList <quint32> FunctionSelection::disabledFunctions() const
×
258
{
259
    return m_disabledFunctions;
×
260
}
261

262
/*****************************************************************************
263
 * Selection
264
 *****************************************************************************/
265

266
void FunctionSelection::setSelection(QList<quint32> selection)
×
267
{
268
    m_selection = selection;
×
269
}
×
270

271
const QList <quint32> FunctionSelection::selection() const
×
272
{
273
    return m_selection;
×
274
}
275

276
/*****************************************************************************
277
 * Tree
278
 *****************************************************************************/
279

280
void FunctionSelection::refillTree()
6✔
281
{
282
    if (m_isInitializing == true)
6✔
283
        return;
6✔
284

285
    // m_selection will be erased when calling setSelected() on each new item.
286
    // A backup in made so current selection is applied correctly.
287
    QList<quint32> selection = m_selection;
×
288

289
    m_funcTree->clearTree();
×
290

291
    // Show a "none" entry
292
    if (m_none == true)
×
293
    {
294
        m_noneItem = new QTreeWidgetItem(m_funcTree);
×
295
        m_noneItem->setText(KColumnName, tr("<No function>"));
×
296
        m_noneItem->setIcon(KColumnName, QIcon(":/uncheck.png"));
×
297
        m_noneItem->setData(KColumnName, Qt::UserRole, Function::invalidId());
×
298
        m_noneItem->setSelected(selection.contains(Function::invalidId()));
×
299
    }
300

301
    if (m_newTrack == true)
×
302
    {
303
        m_newTrackItem = new QTreeWidgetItem(m_funcTree);
×
304
        m_newTrackItem->setText(KColumnName, tr("<Create a new track>"));
×
305
        m_newTrackItem->setIcon(KColumnName, QIcon(":/edit_add.png"));
×
306
        m_newTrackItem->setData(KColumnName, Qt::UserRole, Function::invalidId());
×
307
    }
308

309
    /* Fill the tree */
310
    foreach (Function* function, m_doc->functions())
×
311
    {
312
        if (m_runningOnlyFlag == true && !function->isRunning())
×
313
            continue;
×
314

315
        if (function->isVisible() == false)
×
316
            continue;
×
317

318
        if (m_filter & function->type())
×
319
        {
320
            QTreeWidgetItem* item = m_funcTree->addFunction(function->id());
×
321
            if (disabledFunctions().contains(function->id()))
×
322
                item->setFlags(Qt::NoItemFlags); // Disable the item
×
323
            else
324
                item->setSelected(selection.contains(function->id()));
×
325
        }
326
    }
327

328
    m_funcTree->resizeColumnToContents(KColumnName);
×
329
    for (int i = 0; i < m_funcTree->topLevelItemCount(); i++)
×
330
    {
331
        QTreeWidgetItem *item = m_funcTree->topLevelItem(i);
×
332
        m_funcTree->expandItem(item);
×
333
    }
334
}
×
335

336
void FunctionSelection::slotItemSelectionChanged()
×
337
{
338
    m_selection.clear();
×
339

340
    QListIterator <QTreeWidgetItem*> it(m_funcTree->selectedItems());
×
341
    while (it.hasNext() == true)
×
342
    {
343
        QTreeWidgetItem *item = it.next();
×
344
        quint32 id = item->data(KColumnName, Qt::UserRole).toUInt();
×
345
        if ((id != Function::invalidId() || item == m_noneItem || item == m_newTrackItem)
×
346
             && m_selection.contains(id) == false)
×
347
                    m_selection.append(id);
×
348
    }
349

350
    if (m_selection.isEmpty() == true)
×
351
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
×
352
    else
353
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
×
354
}
×
355

356
void FunctionSelection::slotItemDoubleClicked(QTreeWidgetItem* item)
×
357
{
358
    if (item == NULL)
×
359
        return;
360

361
    if (m_buttonBox->button(QDialogButtonBox::Ok)->isEnabled() == false)
×
362
        return;
363

364
    accept();
×
365
}
366

367
void FunctionSelection::slotSceneChecked(bool state)
2✔
368
{
369
    if (state == true)
2✔
370
        m_filter = (m_filter | Function::SceneType);
×
371
    else
372
        m_filter = (m_filter & ~Function::SceneType);
2✔
373
    refillTree();
2✔
374
}
2✔
375

376
void FunctionSelection::slotChaserChecked(bool state)
2✔
377
{
378
    if (state == true)
2✔
379
        m_filter = (m_filter | Function::ChaserType);
2✔
380
    else
381
        m_filter = (m_filter & ~Function::ChaserType);
×
382
    refillTree();
2✔
383
}
2✔
384

385
void FunctionSelection::slotSequenceChecked(bool state)
×
386
{
387
    if (state == true)
×
388
        m_filter = (m_filter | Function::SequenceType);
×
389
    else
390
        m_filter = (m_filter & ~Function::SequenceType);
×
391
    refillTree();
×
392
}
×
393

394
void FunctionSelection::slotEFXChecked(bool state)
2✔
395
{
396
    if (state == true)
2✔
397
        m_filter = (m_filter | Function::EFXType);
×
398
    else
399
        m_filter = (m_filter & ~Function::EFXType);
2✔
400
    refillTree();
2✔
401
}
2✔
402

403
void FunctionSelection::slotCollectionChecked(bool state)
×
404
{
405
    if (state == true)
×
406
        m_filter = (m_filter | Function::CollectionType);
×
407
    else
408
        m_filter = (m_filter & ~Function::CollectionType);
×
409
    refillTree();
×
410
}
×
411

412
void FunctionSelection::slotScriptChecked(bool state)
×
413
{
414
    if (state == true)
×
415
        m_filter = (m_filter | Function::ScriptType);
×
416
    else
417
        m_filter = (m_filter & ~Function::ScriptType);
×
418
    refillTree();
×
419
}
×
420

421
void FunctionSelection::slotRGBMatrixChecked(bool state)
×
422
{
423
    if (state == true)
×
424
        m_filter = (m_filter | Function::RGBMatrixType);
×
425
    else
426
        m_filter = (m_filter & ~Function::RGBMatrixType);
×
427
    refillTree();
×
428
}
×
429

430
void FunctionSelection::slotShowChecked(bool state)
×
431
{
432
    if (state == true)
×
433
        m_filter = (m_filter | Function::ShowType);
×
434
    else
435
        m_filter = (m_filter & ~Function::ShowType);
×
436
    refillTree();
×
437
}
×
438

439
void FunctionSelection::slotAudioChecked(bool state)
×
440
{
441
    if (state == true)
×
442
        m_filter = (m_filter | Function::AudioType);
×
443
    else
444
        m_filter = (m_filter & ~Function::AudioType);
×
445
    refillTree();
×
446
}
×
447

448
void FunctionSelection::slotVideoChecked(bool state)
×
449
{
450
    if (state == true)
×
451
        m_filter = (m_filter | Function::VideoType);
×
452
    else
453
        m_filter = (m_filter & ~Function::VideoType);
×
454
    refillTree();
×
455
}
×
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