• 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

82.5
/ui/src/monitor/monitorfixture.cpp
1
/*
2
  Q Light Controller
3
  monitorfixture.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 <QGridLayout>
21
#include <QByteArray>
22
#include <QString>
23
#include <QFrame>
24
#include <QLabel>
25
#include <QDebug>
26
#include <QFont>
27
#include <cmath>
28

29
#include "monitorfixture.h"
30
#include "qlcmacros.h"
31
#include "fixture.h"
32
#include "doc.h"
33

34
MonitorFixture::MonitorFixture(QWidget* parent, Doc* doc)
6✔
35
    : QFrame(parent)
36
    , m_doc(doc)
6✔
37
{
38
    Q_ASSERT(doc != NULL);
39

40
    m_fixtureLabel = NULL;
6✔
41
    m_fixture = Fixture::invalidId();
6✔
42
    m_channelStyle = MonitorProperties::DMXChannels;
6✔
43
    m_valueStyle = MonitorProperties::DMXValues;
6✔
44

45
    new QGridLayout(this);
6✔
46
    layout()->setContentsMargins(3, 3, 3, 3);
6✔
47

48
    setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
6✔
49
    setAutoFillBackground(true);
6✔
50
    setBackgroundRole(QPalette::Window);
6✔
51
}
6✔
52

53
MonitorFixture::~MonitorFixture()
6✔
54
{
55
    if (m_fixture != Fixture::invalidId())
6✔
56
    {
57
        Fixture* fxi = m_doc->fixture(m_fixture);
5✔
58
        if (fxi != NULL)
5✔
59
            disconnect(fxi, SIGNAL(valuesChanged()), this, SLOT(slotValuesChanged()));
5✔
60
    }
61

62
    if (m_fixtureLabel != NULL)
6✔
63
        delete m_fixtureLabel;
5✔
64

65
    while (m_iconsLabels.isEmpty() == false)
34✔
66
        delete m_iconsLabels.takeFirst();
28✔
67
    while (m_channelLabels.isEmpty() == false)
34✔
68
        delete m_channelLabels.takeFirst();
28✔
69
    while (m_valueLabels.isEmpty() == false)
34✔
70
        delete m_valueLabels.takeFirst();
28✔
71
}
6✔
72

73
bool MonitorFixture::operator<(const MonitorFixture& mof)
6✔
74
{
75
    Fixture* fxi;
76
    Fixture* mof_fxi;
77

78
    fxi = m_doc->fixture(m_fixture);
6✔
79
    if (fxi == NULL)
6✔
80
        return false;
81

82
    mof_fxi = m_doc->fixture(mof.fixture());
6✔
83
    if (mof_fxi == NULL)
6✔
84
        return false;
85

86
    if ((*fxi) < (*mof_fxi))
6✔
87
        return true;
88
    else
89
        return false;
3✔
90
}
91

92
void MonitorFixture::updateLabelStyles()
2✔
93
{
94
    slotChannelStyleChanged(m_channelStyle);
2✔
95
    slotValueStyleChanged(m_valueStyle);
2✔
96
}
2✔
97

98
/****************************************************************************
99
 * Fixture
100
 ****************************************************************************/
101

102
void MonitorFixture::setFixture(quint32 fxi_id)
5✔
103
{
104
    Fixture* fxi;
105

106
    /* Get rid of old stuff first, if such exists */
107
    if (m_fixtureLabel != NULL)
5✔
108
        delete m_fixtureLabel;
×
109
    while (m_iconsLabels.isEmpty() == false)
5✔
110
        delete m_iconsLabels.takeFirst();
×
111
    while (m_channelLabels.isEmpty() == false)
5✔
112
        delete m_channelLabels.takeFirst();
×
113
    while (m_valueLabels.isEmpty() == false)
5✔
114
        delete m_valueLabels.takeFirst();
×
115

116
    m_fixture = fxi_id;
5✔
117
    fxi = m_doc->fixture(m_fixture);
5✔
118
    if (fxi != NULL)
5✔
119
    {
120
        /* The grid layout uses columns and rows. The first row is for
121
           the fixture name, second row for channel numbers and the
122
           third row for channel values. Each channel is in its own
123
           column. */
124
        QGridLayout* lay = qobject_cast<QGridLayout*> (layout());
5✔
125
        lay->setVerticalSpacing(1);
5✔
126

127
        /* Create a new fixture label and set the fixture name there */
128
        m_fixtureLabel = new QLabel(this);
5✔
129
        m_fixtureLabel->setText(QString("<B>%1</B>").arg(fxi->name()));
5✔
130

131
        /* Set the fixture name to span all channels horizontally */
132
        lay->addWidget(m_fixtureLabel, 0, 0, 1, fxi->channels(),
5✔
133
                       Qt::AlignLeft);
134

135
        QByteArray fxValues = fxi->channelValues();
5✔
136

137
        /* Create channel numbers and value labels */
138
        for (quint32 i = 0; i < fxi->channels(); i++)
33✔
139
        {
140
            const QLCChannel * channel = fxi->channel(i);
28✔
141
            /* Create the icon over the channel number */
142
            QLabel *icon = new QLabel(this);
28✔
143
            icon->setFixedSize(22, 22);
28✔
144

145
            /* Create a label for channel number */
146
            QLabel *label = new QLabel(this);
28✔
147

148
            if (channel != NULL)
28✔
149
            {
150
                icon->setToolTip(channel->name());
28✔
151
                label->setToolTip(channel->name());
28✔
152
                QString resStr = channel->getIconNameFromGroup(channel->group());
28✔
153

154
                if (resStr.startsWith(":"))
28✔
155
                    icon->setStyleSheet("QLabel { border-image: url(" + resStr + ") 0 0 0 0 stretch stretch; }");
28✔
156
                else
157
                    icon->setStyleSheet("QLabel { background: " + resStr + "; }");
×
158
            }
28✔
159
            lay->addWidget(icon, 1, i, Qt::AlignHCenter);
28✔
160
            lay->addWidget(label, 2, i, Qt::AlignHCenter);
28✔
161
            m_iconsLabels.append(icon);
28✔
162
            m_channelLabels.append(label);
28✔
163

164
            /* Create a label for value */
165
            QString str;
166
            label = new QLabel(this);
28✔
167
            lay->addWidget(label, 3, i, Qt::AlignHCenter);
28✔
168
            label->setText(str.asprintf("%.3d", uchar(fxValues.at(i))));
28✔
169
            m_valueLabels.append(label);
28✔
170
        }
28✔
171
        connect(fxi, SIGNAL(valuesChanged()), this, SLOT(slotValuesChanged()));
5✔
172
    }
5✔
173
}
5✔
174

175
quint32 MonitorFixture::fixture() const
8✔
176
{
177
    return m_fixture;
8✔
178
}
179

180
void MonitorFixture::slotChannelStyleChanged(MonitorProperties::ChannelStyle style)
4✔
181
{
182
    QString str;
183
    int i = 0;
184

185
    m_channelStyle = style;
4✔
186

187
    /* Check that this MonitorFixture represents a fixture */
188
    if (m_fixture == Fixture::invalidId())
4✔
189
        return;
190

191
    Fixture* fxi = m_doc->fixture(m_fixture);
4✔
192
    Q_ASSERT(fxi != NULL);
193

194
    /* Start channel numbering from this fixture's address */
195
    if (style == MonitorProperties::DMXChannels)
4✔
196
        i = fxi->address() + 1;
2✔
197
    else
198
        i = 1;
199

200
    QListIterator <QLabel*> it(m_channelLabels);
4✔
201
    while (it.hasNext() == true)
28✔
202
        it.next()->setText(str.asprintf("<B>%.3d</B>", i++));
24✔
203
}
4✔
204

205
/****************************************************************************
206
 * Values
207
 ****************************************************************************/
208

209
void MonitorFixture::slotValueStyleChanged(MonitorProperties::ValueStyle style)
4✔
210
{
211
    if (m_valueStyle == style)
4✔
212
        return;
2✔
213

214
    m_valueStyle = style;
2✔
215

216
    QListIterator <QLabel*> it(m_valueLabels);
2✔
217
    while (it.hasNext() == true)
14✔
218
    {
219
        QLabel* label;
220
        QString str;
221
        int value;
222

223
        label = it.next();
12✔
224
        Q_ASSERT(label != NULL);
225

226
        value = label->text().toInt();
12✔
227

228
        if (style == MonitorProperties::DMXValues)
12✔
229
        {
230
            value = int(ceil(SCALE(qreal(value),
×
231
                                   qreal(0), qreal(100),
232
                                   qreal(0), qreal(UCHAR_MAX))));
233
        }
234
        else
235
        {
236
            value = int(ceil(SCALE(qreal(value),
12✔
237
                                   qreal(0), qreal(UCHAR_MAX),
238
                                   qreal(0), qreal(100))));
239
        }
240

241
        label->setText(str.asprintf("%.3d", value));
12✔
242
    }
12✔
243
}
244

245
void MonitorFixture::slotValuesChanged()
×
246
{
247
    /* Check that this MonitorFixture represents a fixture */
248
    if (m_fixture == Fixture::invalidId())
×
249
        return;
×
250

251
    /* Check that this MonitorFixture's fixture really exists */
252
    Fixture* fxi = m_doc->fixture(m_fixture);
×
253
    if (fxi == NULL)
×
254
        return;
255

256
    QByteArray fxValues = fxi->channelValues();
×
257
    int i = 0;
258

259
    QListIterator <QLabel*> it(m_valueLabels);
×
260
    while (it.hasNext() == true)
×
261
    {
262
        QLabel* label = it.next();
×
263
        Q_ASSERT(label != NULL);
264
        QString str;
265

266
        /* Set the label's text to reflect the changed value */
267
        if (m_valueStyle == MonitorProperties::DMXValues)
×
268
        {
269
            label->setText(str.asprintf("%.3d", uchar(fxValues.at(i))));
×
270
        }
271
        else
272
        {
273
            label->setText(str.asprintf("%.3d", int(ceil(SCALE(qreal(uchar(fxValues.at(i))),
×
274
                                                               qreal(0), qreal(UCHAR_MAX),
275
                                                               qreal(0), qreal(100))))));
276
        }
277
        i++;
×
278
    }
×
279
}
×
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