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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

0.0
/ui/src/channelmodifiereditor.cpp
1
/*
2
  Q Light Controller Plus
3
  channelmodifiereditor.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 <QMessageBox>
21
#include <QUrl>
22
#include <QSettings>
23

24
#include "channelmodifiergraphicsview.h"
25
#include "channelmodifiereditor.h"
26
#include "qlcmodifierscache.h"
27
#include "channelmodifier.h"
28
#include "qlcfile.h"
29
#include "doc.h"
30

31
#define SETTINGS_GEOMETRY "channelmodifiereditor/geometry"
32

33
ChannelModifierEditor::ChannelModifierEditor(Doc *doc, QString modifier, QWidget *parent)
×
34
    : QDialog(parent)
35
    , m_doc(doc)
×
36
{
37
    Q_ASSERT(doc != NULL);
×
38

39
    setupUi(this);
×
40

41
    m_view = new ChannelModifierGraphicsView(this);
×
42
    m_view->setRenderHint(QPainter::Antialiasing);
×
43
    m_view->setAcceptDrops(true);
×
44
    m_view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
×
45
    m_view->setBackgroundBrush(QBrush(QColor(11, 11, 11, 255), Qt::SolidPattern));
×
46

47
    m_mainGrid->addWidget(m_view, 2, 0);
×
48

49
    m_origDMXSpin->setEnabled(false);
×
50
    m_modifiedDMXSpin->setEnabled(false);
×
51
    m_deleteHandlerButton->setEnabled(false);
×
52

53
    QSettings settings;
×
54
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
55
    if (geometrySettings.isValid() == true)
×
56
        restoreGeometry(geometrySettings.toByteArray());
×
57

58
    connect(m_view, SIGNAL(itemClicked(uchar,uchar)),
×
59
            this, SLOT(slotHandlerClicked(uchar,uchar)));
60
    connect(m_view, SIGNAL(itemDMXMapChanged(uchar,uchar)),
×
61
            this, SLOT(slotItemDMXChanged(uchar,uchar)));
62
    connect(m_view, SIGNAL(viewClicked(QMouseEvent*)),
×
63
            this, SLOT(slotViewClicked()));
64

65
    connect(m_templatesTree, SIGNAL(itemSelectionChanged()),
×
66
            this, SLOT(slotItemSelectionChanged()));
67

68
    connect(m_origDMXSpin, SIGNAL(valueChanged(int)),
×
69
            this, SLOT(slotOriginalDMXValueChanged(int)));
70
    connect(m_modifiedDMXSpin, SIGNAL(valueChanged(int)),
×
71
            this, SLOT(slotModifiedDMXValueChanged(int)));
72

73
    connect(m_addHandlerButton, SIGNAL(clicked()),
×
74
            this, SLOT(slotAddHandlerClicked()));
75
    connect(m_deleteHandlerButton, SIGNAL(clicked()),
×
76
            this, SLOT(slotRemoveHandlerClicked()));
77
    connect(m_saveButton, SIGNAL(clicked()),
×
78
            this, SLOT(slotSaveClicked()));
79

80
    connect(m_unsetButton, SIGNAL(clicked()),
×
81
            this, SLOT(slotUnsetClicked()));
82

83
    updateModifiersList(modifier);
×
84
}
×
85

86
ChannelModifierEditor::~ChannelModifierEditor()
×
87
{
88
    QSettings settings;
×
89
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
90
}
×
91

92
ChannelModifier *ChannelModifierEditor::selectedModifier()
×
93
{
94
    return m_currentTemplate;
×
95
}
96

97
static bool alphabeticSort(QString const & left, QString const & right)
×
98
{
99
  return QString::compare(left, right) < 0;
×
100
}
101

102
void ChannelModifierEditor::updateModifiersList(QString modifier)
×
103
{
104
    QList<QString> names = m_doc->modifiersCache()->templateNames();
×
105
    std::stable_sort(names.begin(), names.end(), alphabeticSort);
×
106

107
    m_templatesTree->clear();
×
108
    foreach (QString name, names)
×
109
    {
110
        QTreeWidgetItem *item = new QTreeWidgetItem(m_templatesTree);
×
111
        item->setText(0, name);
×
112
        if (name == modifier)
×
113
            item->setSelected(true);
×
114
    }
×
115
    if (m_templatesTree->topLevelItemCount() > 0 &&
×
116
        m_templatesTree->selectedItems().count() == 0)
×
117
            m_templatesTree->setCurrentItem(m_templatesTree->topLevelItem(0));
×
118
}
×
119

120
void ChannelModifierEditor::slotViewClicked()
×
121
{
122
    m_origDMXSpin->setEnabled(false);
×
123
    m_modifiedDMXSpin->setEnabled(false);
×
124
    m_deleteHandlerButton->setEnabled(false);
×
125
}
×
126

127
void ChannelModifierEditor::slotHandlerClicked(uchar pos, uchar value)
×
128
{
129
    if (pos != 0 && pos != 255)
×
130
    {
131
        m_origDMXSpin->setEnabled(true);
×
132
        m_deleteHandlerButton->setEnabled(true);
×
133
    }
134
    else
135
        m_deleteHandlerButton->setEnabled(false);
×
136
    m_modifiedDMXSpin->setEnabled(true);
×
137
    m_origDMXSpin->blockSignals(true);
×
138
    m_modifiedDMXSpin->blockSignals(true);
×
139
    m_origDMXSpin->setValue(pos);
×
140
    m_modifiedDMXSpin->setValue(value);
×
141
    m_origDMXSpin->blockSignals(false);
×
142
    m_modifiedDMXSpin->blockSignals(false);
×
143
}
×
144

145
void ChannelModifierEditor::slotItemDMXChanged(uchar pos, uchar value)
×
146
{
147
    m_origDMXSpin->blockSignals(true);
×
148
    m_modifiedDMXSpin->blockSignals(true);
×
149
    m_origDMXSpin->setValue(pos);
×
150
    m_modifiedDMXSpin->setValue(value);
×
151
    m_origDMXSpin->blockSignals(false);
×
152
    m_modifiedDMXSpin->blockSignals(false);
×
153
}
×
154

155
void ChannelModifierEditor::slotItemSelectionChanged()
×
156
{
157
    if (m_templatesTree->selectedItems().count() > 0)
×
158
    {
159
        QTreeWidgetItem *item = m_templatesTree->selectedItems().first();
×
160
        m_currentTemplate = m_doc->modifiersCache()->modifier(item->text(0));
×
161
        m_view->setModifierMap(m_currentTemplate->modifierMap());
×
162
        m_templateNameEdit->setText(m_currentTemplate->name());
×
163
    }
164
}
×
165

166
void ChannelModifierEditor::slotOriginalDMXValueChanged(int value)
×
167
{
168
    m_view->setHandlerDMXValue(uchar(value), uchar(m_modifiedDMXSpin->value()));
×
169
}
×
170

171
void ChannelModifierEditor::slotModifiedDMXValueChanged(int value)
×
172
{
173
    m_view->setHandlerDMXValue(uchar(m_origDMXSpin->value()), uchar(value));
×
174
}
×
175

176
void ChannelModifierEditor::slotAddHandlerClicked()
×
177
{
178
    m_view->addNewHandler();
×
179
}
×
180

181
void ChannelModifierEditor::slotRemoveHandlerClicked()
×
182
{
183
    m_view->removeHander();
×
184
}
×
185

186
void ChannelModifierEditor::slotSaveClicked()
×
187
{
188
    ChannelModifier *modifier = m_doc->modifiersCache()->modifier(m_templateNameEdit->text());
×
189
    if (modifier != NULL && modifier->type() == ChannelModifier::SystemTemplate)
×
190
    {
191
        // cannot overwrite a system template !
192
        QMessageBox::critical(this, tr("Error"),
×
193
                              tr("You are trying to overwrite a system template! Please choose another name "
×
194
                                 "and the template will be saved in your channel modifier's user folder."),
195
                              QMessageBox::Close);
196
        return;
×
197
    }
198

199
    QList< QPair<uchar, uchar> > map = m_view->modifiersMap();
×
200
    QString filename = QString("%1/%2%3")
×
201
            .arg(QLCModifiersCache::userTemplateDirectory().absolutePath())
×
202
            .arg(m_templateNameEdit->text().simplified())
×
203
            .arg(KExtModifierTemplate);
×
204
    ChannelModifier *newModifier = new ChannelModifier();
×
205
    newModifier->setName(m_templateNameEdit->text());
×
206
    newModifier->setModifierMap(map);
×
207
    newModifier->saveXML(filename);
×
208

209
    if (modifier == NULL)
×
210
    {
211
        QTreeWidgetItem *item = new QTreeWidgetItem(m_templatesTree);
×
212
        item->setText(0, m_templateNameEdit->text());
×
213
        m_doc->modifiersCache()->addModifier(newModifier);
×
214
    }
215
    else
216
        modifier->setModifierMap(map);
×
217
}
×
218

219
void ChannelModifierEditor::slotUnsetClicked()
×
220
{
221
    m_currentTemplate = NULL;
×
222
    QDialog::accept();
×
223
}
×
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