• 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

50.0
/ui/src/flowlayout.cpp
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
5
**
6
** This file is part of the examples of the Qt Toolkit.
7
**
8
** $QT_BEGIN_LICENSE:BSD$
9
** You may use this file under the terms of the BSD license as follows:
10
**
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
13
** met:
14
**   * Redistributions of source code must retain the above copyright
15
**     notice, this list of conditions and the following disclaimer.
16
**   * Redistributions in binary form must reproduce the above copyright
17
**     notice, this list of conditions and the following disclaimer in
18
**     the documentation and/or other materials provided with the
19
**     distribution.
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21
**     of its contributors may be used to endorse or promote products derived
22
**     from this software without specific prior written permission.
23
**
24
**
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36
**
37
** $QT_END_LICENSE$
38
**
39
****************************************************************************/
40

41
#include <QWidget>
42

43
#include "flowlayout.h"
44
//! [1]
45
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
×
46
    : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
×
47
{
48
    setContentsMargins(margin, margin, margin, margin);
×
49
}
×
50

51
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
9✔
52
    : m_hSpace(hSpacing), m_vSpace(vSpacing)
9✔
53
{
54
    setContentsMargins(margin, margin, margin, margin);
9✔
55
}
9✔
56
//! [1]
57

58
//! [2]
59
FlowLayout::~FlowLayout()
18✔
60
{
61
    QLayoutItem *item;
62
    while ((item = takeAt(0)))
9✔
63
        delete item;
×
64
}
18✔
65
//! [2]
66

67
//! [3]
68
void FlowLayout::addItem(QLayoutItem *item)
×
69
{
70
    itemList.append(item);
×
71
}
×
72
//! [3]
73

74
//! [4]
75
int FlowLayout::horizontalSpacing() const
×
76
{
77
    if (m_hSpace >= 0) {
×
78
        return m_hSpace;
×
79
    } else {
80
        return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
×
81
    }
82
}
83

84
int FlowLayout::verticalSpacing() const
×
85
{
86
    if (m_vSpace >= 0) {
×
87
        return m_vSpace;
×
88
    } else {
89
        return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
×
90
    }
91
}
92
//! [4]
93

94
//! [5]
95
int FlowLayout::count() const
9✔
96
{
97
    return itemList.size();
9✔
98
}
99

100
QLayoutItem *FlowLayout::itemAt(int index) const
21✔
101
{
102
    return itemList.value(index);
21✔
103
}
104

105
QLayoutItem *FlowLayout::takeAt(int index)
9✔
106
{
107
    if (index >= 0 && index < itemList.size())
9✔
108
        return itemList.takeAt(index);
×
109
    else
110
        return 0;
9✔
111
}
112
//! [5]
113

114
//! [6]
115
Qt::Orientations FlowLayout::expandingDirections() const
7✔
116
{
117
    return Qt::Horizontal;
7✔
118
}
119
//! [6]
120

121
//! [7]
122
bool FlowLayout::hasHeightForWidth() const
14✔
123
{
124
    return true;
14✔
125
}
126

127
int FlowLayout::heightForWidth(int width) const
7✔
128
{
129
    int height = doLayout(QRect(0, 0, width, 0), true);
7✔
130
    return height;
7✔
131
}
132
//! [7]
133

134
//! [8]
135
void FlowLayout::setGeometry(const QRect &rect)
7✔
136
{
137
    QLayout::setGeometry(rect);
7✔
138
    doLayout(rect, false);
7✔
139
}
7✔
140

141
QSize FlowLayout::sizeHint() const
7✔
142
{
143
    return minimumSize();
7✔
144
}
145

146
QSize FlowLayout::minimumSize() const
21✔
147
{
148
    QSize size;
21✔
149
    QLayoutItem *item;
150

151
    foreach (item, itemList)
21✔
152
        size = size.expandedTo(item->minimumSize());
21✔
153

154
    size += QSize(2 * contentsMargins().left(), 2 * contentsMargins().top());
21✔
155
    return size;
21✔
156
}
157
//! [8]
158

159
//! [9]
160
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
14✔
161
{
162
    int left, top, right, bottom;
163
    getContentsMargins(&left, &top, &right, &bottom);
14✔
164
    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
14✔
165
    int x = effectiveRect.x();
14✔
166
    int y = effectiveRect.y();
14✔
167
    int lineHeight = 0;
14✔
168
//! [9]
169

170
//! [10]
171
    QLayoutItem *item;
172
    foreach (item, itemList) {
14✔
173
        QWidget *wid = item->widget();
×
174
        int spaceX = horizontalSpacing();
×
175
        if (spaceX == -1)
×
176
            spaceX = wid->style()->layoutSpacing(
×
177
                QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
178
        int spaceY = verticalSpacing();
×
179
        if (spaceY == -1)
×
180
            spaceY = wid->style()->layoutSpacing(
×
181
                QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
182
//! [10]
183
//! [11]
184
        int nextX = x + item->sizeHint().width() + spaceX;
×
185
        if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
×
186
            x = effectiveRect.x();
×
187
            y = y + lineHeight + spaceY;
×
188
            nextX = x + item->sizeHint().width() + spaceX;
×
189
            lineHeight = 0;
×
190
        }
191

192
        if (!testOnly)
×
193
            item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
×
194

195
        x = nextX;
×
196
        lineHeight = qMax(lineHeight, item->sizeHint().height());
×
197
    }
14✔
198
    return y + lineHeight - rect.y() + bottom;
14✔
199
}
200
//! [11]
201
//! [12]
202
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
×
203
{
204
    QObject *parent = this->parent();
×
205
    if (!parent) {
×
206
        return -1;
×
207
    } else if (parent->isWidgetType()) {
×
208
        QWidget *pw = static_cast<QWidget *>(parent);
×
209
        return pw->style()->pixelMetric(pm, 0, pw);
×
210
    } else {
211
        return static_cast<QLayout *>(parent)->spacing();
×
212
    }
213
}
214
//! [12]
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