• 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/collectioneditor.cpp
1
/*
2
  Q Light Controller
3
  collectioneditor.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 <QSettings>
23
#include <QLineEdit>
24
#include <QLabel>
25

26
#include "functionselection.h"
27
#include "collectioneditor.h"
28
#include "mastertimer.h"
29
#include "collection.h"
30
#include "function.h"
31
#include "doc.h"
32

33
#define PROP_ID Qt::UserRole
34

35
CollectionEditor::CollectionEditor(QWidget* parent, Collection* fc, Doc* doc)
×
36
    : QWidget(parent)
37
    , m_doc(doc)
×
38
    , m_collection(fc)
×
39
{
40
    Q_ASSERT(doc != NULL);
41
    Q_ASSERT(fc != NULL);
42

43
    setupUi(this);
×
44

45
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
46
            this, SLOT(slotNameEdited(const QString&)));
47
    connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd()));
×
48
    connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove()));
×
49
    connect(m_moveUp, SIGNAL(clicked()), this, SLOT(slotMoveUp()));
×
50
    connect(m_moveDown, SIGNAL(clicked()), this, SLOT(slotMoveDown()));
×
51
    connect(m_testButton, SIGNAL(clicked()),
×
52
            this, SLOT(slotTestClicked()));
53

54
    m_nameEdit->setText(m_collection->name());
×
55
    m_nameEdit->setSelection(0, m_nameEdit->text().length());
×
56

57
    updateFunctionList();
×
58

59
    // Set focus to the editor
60
    m_nameEdit->setFocus();
×
61
}
×
62

63
CollectionEditor::~CollectionEditor()
×
64
{
65
    if (m_testButton->isChecked())
×
66
        m_collection->stopAndWait ();
×
67
}
×
68

69
void CollectionEditor::slotNameEdited(const QString& text)
×
70
{
71
    m_collection->setName(text);
×
72
}
×
73

74
void CollectionEditor::slotAdd()
×
75
{
76
    FunctionSelection fs(this, m_doc);
×
77
    {
78
        QList<quint32> disabledList;
79
        disabledList << m_collection->id();
×
80
        foreach (Function* function, m_doc->functions())
×
81
        {
82
            if (function->contains(m_collection->id()))
×
83
                disabledList << function->id();
×
84
        }
85
        fs.setDisabledFunctions(disabledList);
×
86
    }
×
87

88
    if (fs.exec() == QDialog::Accepted)
×
89
    {
90
        QListIterator <quint32> it(fs.selection());
×
91
        while (it.hasNext() == true)
×
92
            m_collection->addFunction(it.next());
×
93
        updateFunctionList();
×
94
    }
95
}
×
96

97
void CollectionEditor::slotRemove()
×
98
{
99
    QList <QTreeWidgetItem*> items(m_tree->selectedItems());
×
100
    QListIterator <QTreeWidgetItem*> it(items);
×
101

102
    while (it.hasNext() == true)
×
103
    {
104
        QTreeWidgetItem* item(it.next());
×
105
        quint32 id = item->data(0, PROP_ID).toUInt();
×
106
        m_collection->removeFunction(id);
×
107
        delete item;
×
108
    }
109
}
×
110

111
void CollectionEditor::slotMoveUp()
×
112
{
113
    QList <QTreeWidgetItem*> items(m_tree->selectedItems());
×
114
    QListIterator <QTreeWidgetItem*> it(items);
×
115

116
    // Check, whether even one of the items would "bleed" over the edge and
117
    // cancel the operation if that is the case.
118
    while (it.hasNext() == true)
×
119
    {
120
        QTreeWidgetItem* item(it.next());
×
121
        int index = m_tree->indexOfTopLevelItem(item);
×
122
        if (index == 0)
×
123
            return;
124
    }
125

126
    // Move the items
127
    it.toFront();
128
    while (it.hasNext() == true)
×
129
    {
130
        QTreeWidgetItem* item(it.next());
×
131
        int index = m_tree->indexOfTopLevelItem(item);
×
132
        m_tree->takeTopLevelItem(index);
×
133
        m_tree->insertTopLevelItem(index - 1, item);
×
134

135
        quint32 id = item->data(0, PROP_ID).toUInt();
×
136
        m_collection->removeFunction(id);
×
137
        m_collection->addFunction(id, index - 1);
×
138
    }
139

140
    // Select the moved items
141
    it.toFront();
142
    while (it.hasNext() == true)
×
143
        it.next()->setSelected(true);
×
144
}
×
145

146
void CollectionEditor::slotMoveDown()
×
147
{
148
    QList <QTreeWidgetItem*> items(m_tree->selectedItems());
×
149
    QListIterator <QTreeWidgetItem*> it(items);
×
150

151
    // Check, whether even one of the items would "bleed" over the edge and
152
    // cancel the operation if that is the case.
153
    while (it.hasNext() == true)
×
154
    {
155
        QTreeWidgetItem* item(it.next());
×
156
        int index = m_tree->indexOfTopLevelItem(item);
×
157
        if (index == m_tree->topLevelItemCount() - 1)
×
158
            return;
159
    }
160

161
    // Move the items
162
    it.toBack();
163
    while (it.hasPrevious() == true)
×
164
    {
165
        QTreeWidgetItem* item(it.previous());
×
166
        int index = m_tree->indexOfTopLevelItem(item);
×
167
        m_tree->takeTopLevelItem(index);
×
168
        m_tree->insertTopLevelItem(index + 1, item);
×
169

170
        quint32 id = item->data(0, PROP_ID).toUInt();
×
171
        m_collection->removeFunction(id);
×
172
        m_collection->addFunction(id, index + 1);
×
173
    }
174

175
    // Select the items
176
    it.toFront();
177
    while (it.hasNext() == true)
×
178
        it.next()->setSelected(true);
×
179
}
×
180

181
void CollectionEditor::slotTestClicked()
×
182
{
183
    if (m_testButton->isChecked() == true)
×
184
        m_collection->start(m_doc->masterTimer(), functionParent());
×
185
    else
186
        m_collection->stopAndWait();
×
187
}
×
188

189
FunctionParent CollectionEditor::functionParent() const
×
190
{
191
    return FunctionParent::master();
×
192
}
193

194
void CollectionEditor::updateFunctionList()
×
195
{
196
    m_tree->clear();
×
197

198
    foreach (QVariant fid, m_collection->functions())
×
199
    {
200
        Function* function = m_doc->function(fid.toUInt());
×
201
        Q_ASSERT(function != NULL);
202

203
        QTreeWidgetItem* item = new QTreeWidgetItem(m_tree);
×
204
        item->setText(0, function->name());
×
205
        item->setData(0, PROP_ID, function->id());
×
206
        item->setIcon(0, function->getIcon());
×
207
    }
×
208
}
×
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