• 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/monitor/monitorlayout.cpp
1
/*
2
  Q Light Controller
3
  monitorlayout.cpp
4

5
  Copyright (c) Nokia Corporation/QtSoftware
6
                Heikki Junnila
7

8
  Licensed under the Apache License, Version 2.0 (the "License");
9
  you may not use this file except in compliance with the License.
10
  You may obtain a copy of the License at
11

12
      http://www.apache.org/licenses/LICENSE-2.0.txt
13

14
  Unless required by applicable law or agreed to in writing, software
15
  distributed under the License is distributed on an "AS IS" BASIS,
16
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
  See the License for the specific language governing permissions and
18
  limitations under the License.
19
*/
20

21
#include <QWidgetItem>
22
#include <QLayout>
23
#include <QDebug>
24

25
#include "monitorfixture.h"
26
#include "monitorlayout.h"
27

28
/****************************************************************************
29
 * MonitorLayoutItem
30
 ****************************************************************************/
31

32
MonitorLayoutItem::MonitorLayoutItem(MonitorFixture* mof) : QWidgetItem(mof)
×
33
{
34
}
×
35

36
MonitorLayoutItem::~MonitorLayoutItem()
×
37
{
38
}
×
39

40
bool MonitorLayoutItem::operator<(const MonitorLayoutItem& item)
×
41
{
42
    MonitorLayoutItem& ncitem = const_cast<MonitorLayoutItem&> (item);
×
43
    MonitorFixture* item_mof;
44
    MonitorFixture* mof;
45

46
    mof = qobject_cast<MonitorFixture*> (widget());
×
47
    Q_ASSERT(mof != NULL);
×
48

49
    item_mof = qobject_cast<MonitorFixture*> (ncitem.widget());
×
50
    Q_ASSERT(item_mof != NULL);
×
51

52
    if ((*mof) < (*item_mof))
×
53
        return true;
×
54
    else
55
        return false;
×
56
}
57

58
/****************************************************************************
59
 * Initialization
60
 ****************************************************************************/
61

62
MonitorLayout::MonitorLayout(QWidget *parent) : QLayout(parent)
×
63
{
64
}
×
65

66
MonitorLayout::~MonitorLayout()
×
67
{
68
    while (m_items.isEmpty() == false)
×
69
        delete m_items.takeFirst();
×
70
}
×
71

72
/****************************************************************************
73
 * Items
74
 ****************************************************************************/
75

76
void MonitorLayout::addItem(QLayoutItem* item)
×
77
{
78
    m_items.append(static_cast<MonitorLayoutItem*> (item));
×
79
    sort();
×
80
    update();
×
81
}
×
82

83
int MonitorLayout::count() const
×
84
{
85
    return m_items.size();
×
86
}
87

88
MonitorLayoutItem* MonitorLayout::itemAt(int index) const
×
89
{
90
    return m_items.value(index);
×
91
}
92

93
MonitorLayoutItem* MonitorLayout::takeAt(int index)
×
94
{
95
    if (index >= 0 && index < m_items.size())
×
96
        return m_items.takeAt(index);
×
97
    else
98
        return NULL;
×
99
}
100

101
static bool MonitorLayoutLessThan(MonitorLayoutItem* i1, MonitorLayoutItem* i2)
×
102
{
103
    if ((*i1) < (*i2))
×
104
        return true;
×
105
    else
106
        return false;
×
107
}
108

109
void MonitorLayout::sort()
×
110
{
111
    std::sort(m_items.begin(), m_items.end(), MonitorLayoutLessThan);
×
112
}
×
113

114
/****************************************************************************
115
 * Size & Geometry
116
 ****************************************************************************/
117

118
Qt::Orientations MonitorLayout::expandingDirections() const
×
119
{
120
    return Qt::Vertical;
×
121
}
122

123
bool MonitorLayout::hasHeightForWidth() const
×
124
{
125
    return true;
×
126
}
127

128
int MonitorLayout::heightForWidth(int width) const
×
129
{
130
    int height = doLayout(QRect(0, 0, width, 0), true);
×
131
    return height;
×
132
}
133

134
void MonitorLayout::setGeometry(const QRect& rect)
×
135
{
136
    QLayout::setGeometry(rect);
×
137
    doLayout(rect, false);
×
138
}
×
139

140
QSize MonitorLayout::sizeHint() const
×
141
{
142
    return minimumSize();
×
143
}
144

145
QSize MonitorLayout::minimumSize() const
×
146
{
147
    QSize size;
×
148
    QLayoutItem* item;
149

150
    foreach (item, m_items)
×
151
    size = size.expandedTo(item->minimumSize());
×
152

153
    size += QSize(2 * contentsMargins().left(), 2 * contentsMargins().top());
×
154

155
    return size;
×
156
}
157

158
int MonitorLayout::doLayout(const QRect& rect, bool testOnly) const
×
159
{
160
    int x = rect.x();
×
161
    int y = rect.y();
×
162
    int lineHeight = 0;
×
163
    QLayoutItem* item;
164

165
    foreach (item, m_items)
×
166
    {
167
        int nextX = x + item->sizeHint().width() + spacing();
×
168
        if (nextX - spacing() > rect.right() && lineHeight > 0)
×
169
        {
170
            x = rect.x();
×
171
            y = y + lineHeight + spacing();
×
172
            nextX = x + item->sizeHint().width() + spacing();
×
173
            lineHeight = 0;
×
174
        }
175

176
        if (testOnly == false)
×
177
        {
178
            item->setGeometry(QRect(QPoint(x, y),
×
179
                                    item->sizeHint()));
×
180
        }
181

182
        x = nextX;
×
183
        lineHeight = qMax(lineHeight, item->sizeHint().height());
×
184
    }
×
185

186
    return y + lineHeight - rect.y();
×
187
}
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