• 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/fixturegroupeditor.cpp
1
/*
2
  Q Light Controller
3
  fixturegroupeditor.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 <QTableWidgetItem>
21
#include <QTableWidget>
22
#include <QSettings>
23
#include <QLineEdit>
24
#include <QSpinBox>
25
#include <QDebug>
26

27
#include "fixturegroupeditor.h"
28
#include "fixtureselection.h"
29
#include "fixturegroup.h"
30
#include "fixture.h"
31
#include "doc.h"
32

33
#define SETTINGS_GEOMETRY "fixturegroupeditor/geometry"
34

35
#define PROP_FIXTURE Qt::UserRole
36
#define PROP_HEAD Qt::UserRole + 1
37

38
FixtureGroupEditor::FixtureGroupEditor(FixtureGroup* grp, Doc* doc, QWidget* parent)
×
39
    : QWidget(parent)
40
    , m_grp(grp)
41
    , m_doc(doc)
×
42
{
43
    Q_ASSERT(grp != NULL);
×
44
    Q_ASSERT(doc != NULL);
×
45

46
    setupUi(this);
×
47

48
    m_nameEdit->setText(m_grp->name());
×
49
    m_xSpin->setValue(m_grp->size().width());
×
50
    m_ySpin->setValue(m_grp->size().height());
×
51

52
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
53
            this, SLOT(slotNameEdited(const QString&)));
54
    connect(m_xSpin, SIGNAL(valueChanged(int)),
×
55
            this, SLOT(slotXSpinValueChanged(int)));
56
    connect(m_ySpin, SIGNAL(valueChanged(int)),
×
57
            this, SLOT(slotYSpinValueChanged(int)));
58

59
    connect(m_rightButton, SIGNAL(clicked()),
×
60
            this, SLOT(slotRightClicked()));
61
    connect(m_downButton, SIGNAL(clicked()),
×
62
            this, SLOT(slotDownClicked()));
63
    connect(m_removeButton, SIGNAL(clicked()),
×
64
            this, SLOT(slotRemoveFixtureClicked()));
65

66
    m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
×
67
    m_table->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
×
68
    m_table->setIconSize(QSize(20, 20));
×
69
    updateTable();
×
70
}
×
71

72
FixtureGroupEditor::~FixtureGroupEditor()
×
73
{
74
}
×
75

76
void FixtureGroupEditor::updateTable()
×
77
{
78
    qDebug() << Q_FUNC_INFO;
×
79
    // Store these since they might get reset
80
    int savedRow = m_row;
×
81
    int savedCol = m_column;
×
82

83
    disconnect(m_table, SIGNAL(cellChanged(int,int)),
×
84
               this, SLOT(slotCellChanged(int,int)));
85
    disconnect(m_table, SIGNAL(cellPressed(int,int)),
×
86
               this, SLOT(slotCellActivated(int,int)));
87
    disconnect(m_table->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
×
88
            this, SLOT(slotResized()));
89

90
    m_table->clear();
×
91

92
    m_table->setRowCount(m_grp->size().height());
×
93
    m_table->setColumnCount(m_grp->size().width());
×
94

95
    QMapIterator <QLCPoint,GroupHead> it(m_grp->headsMap());
×
96
    while (it.hasNext() == true)
×
97
    {
98
        it.next();
×
99

100
        QLCPoint pt(it.key());
×
101

102
        GroupHead head(it.value());
×
103
        Fixture* fxi = m_doc->fixture(head.fxi);
×
104
        if (fxi == NULL)
×
105
            continue;
×
106

107
        QIcon icon = fxi->getIconFromType();
×
108
        QString str = QString("%1 H:%2\nA:%3 U:%4").arg(fxi->name())
×
109
                                               .arg(head.head + 1)
×
110
                                               .arg(fxi->address() + 1)
×
111
                                               .arg(fxi->universe() + 1);
×
112

113
        QTableWidgetItem* item = new QTableWidgetItem(icon, str);
×
114
        item->setData(PROP_FIXTURE, head.fxi);
×
115
        item->setData(PROP_HEAD, head.head);
×
116
        item->setToolTip(str);
×
117

118
        m_table->setItem(pt.y(), pt.x(), item);
×
119
    }
120

121
    connect(m_table, SIGNAL(cellPressed(int,int)),
×
122
            this, SLOT(slotCellActivated(int,int)));
123
    connect(m_table, SIGNAL(cellChanged(int,int)),
×
124
            this, SLOT(slotCellChanged(int,int)));
125
    connect(m_table->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
×
126
            this, SLOT(slotResized()));
127

128
    if (savedRow < m_table->rowCount() && savedCol < m_table->columnCount())
×
129
    {
130
        m_row = savedRow;
×
131
        m_column = savedCol;
×
132
    }
133
    else
134
    {
135
        m_row = 0;
×
136
        m_column = 0;
×
137
    }
138

139
    m_table->setCurrentCell(m_row, m_column);
×
140
    slotResized();
×
141
}
×
142

143
void FixtureGroupEditor::slotNameEdited(const QString& text)
×
144
{
145
    m_grp->setName(text);
×
146
}
×
147

148
void FixtureGroupEditor::slotXSpinValueChanged(int value)
×
149
{
150
    m_grp->setSize(QSize(value, m_grp->size().height()));
×
151
    updateTable();
×
152
}
×
153

154
void FixtureGroupEditor::slotYSpinValueChanged(int value)
×
155
{
156
    m_grp->setSize(QSize(m_grp->size().width(), value));
×
157
    updateTable();
×
158
}
×
159

160
void FixtureGroupEditor::slotRightClicked()
×
161
{
162
    addFixtureHeads(Qt::RightArrow);
×
163
}
×
164

165
void FixtureGroupEditor::slotDownClicked()
×
166
{
167
    addFixtureHeads(Qt::DownArrow);
×
168
}
×
169

170
void FixtureGroupEditor::slotRemoveFixtureClicked()
×
171
{
172
    QTableWidgetItem* item = m_table->currentItem();
×
173
    if (item == NULL)
×
174
        return;
×
175

176
    if (m_grp->resignHead(QLCPoint(m_column, m_row)) == true)
×
177
        delete item;
×
178
}
179

180
void FixtureGroupEditor::slotCellActivated(int row, int column)
×
181
{
182
    m_row = row;
×
183
    m_column = column;
×
184

185
    if (m_table->currentItem() == NULL)
×
186
        m_removeButton->setEnabled(false);
×
187
    else
188
        m_removeButton->setEnabled(true);
×
189
}
×
190

191
void FixtureGroupEditor::slotCellChanged(int row, int column)
×
192
{
193
    if (row < 0 || column < 0)
×
194
    {
195
        updateTable();
×
196
        return;
×
197
    }
198

199
    QMap <QLCPoint,GroupHead> hash = m_grp->headsMap();
×
200
    QLCPoint from(m_column, m_row);
×
201
    QLCPoint to(column, row);
×
202
    GroupHead fromHead;
×
203
    GroupHead toHead;
×
204

205
    if (hash.contains(from) == true)
×
206
        fromHead = hash[from];
×
207
    if (hash.contains(to) == true)
×
208
        toHead = hash[to];
×
209

210
    m_grp->swap(from, to);
×
211

212
    updateTable();
×
213
    m_table->setCurrentCell(row, column);
×
214
    slotCellActivated(row, column);
×
215
}
216

217
void FixtureGroupEditor::slotResized()
×
218
{
219
    disconnect(m_table, SIGNAL(cellChanged(int,int)),
×
220
               this, SLOT(slotCellChanged(int,int)));
221

222
    float cellWidth = (float)(m_table->columnWidth(0) - m_table->iconSize().width());
×
223
    QFont font = m_table->font();
×
224
    QFontMetrics fm(font);
×
225
    float pSizeF = font.pointSizeF();
×
226

227
    for (int y = 0; y < m_table->rowCount(); y++)
×
228
    {
229
        for (int x = 0; x < m_table->columnCount(); x++)
×
230
        {
231
            QTableWidgetItem* item = m_table->item(y, x);
×
232
            if (item != NULL)
×
233
            {
234
                QFont scaledFont = font;
×
235
#if (QT_VERSION < QT_VERSION_CHECK(5, 11, 0))
236
                float baseWidth  = (float)fm.width(item->text());
237
#else
238
                float baseWidth  = (float)fm.horizontalAdvance(item->text());
×
239
#endif
240
                float factor = cellWidth / baseWidth;
×
241
                if (factor != 1)
×
242
                    scaledFont.setPointSizeF((pSizeF * factor) + 2);
×
243
                else
244
                    scaledFont.setPointSize(font.pointSize() - 2);
×
245

246
                item->setFont(scaledFont);
×
247
            }
248
        }
249
    }
250

251
    connect(m_table, SIGNAL(cellChanged(int,int)),
×
252
            this, SLOT(slotCellChanged(int,int)));
253
}
×
254

255
void FixtureGroupEditor::addFixtureHeads(Qt::ArrowType direction)
×
256
{
257
    FixtureSelection fs(this, m_doc);
×
258
    fs.setMultiSelection(true);
×
259
    fs.setSelectionMode(FixtureSelection::Heads);
×
260
    fs.setDisabledHeads(m_grp->headList());
×
261
    if (fs.exec() == QDialog::Accepted)
×
262
    {
263
        int row = m_row;
×
264
        int col = m_column;
×
265
        foreach (GroupHead gh, fs.selectedHeads())
×
266
        {
267
            m_grp->assignHead(QLCPoint(col, row), gh);
×
268
            if (direction == Qt::RightArrow)
×
269
                col++;
×
270
            else
271
                row++;
×
272
        }
273

274
        updateTable();
×
275
        m_table->setCurrentCell(row, col);
×
276
    }
277
}
×
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