summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qgridlayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qgridlayout.cpp')
-rw-r--r--src/widgets/kernel/qgridlayout.cpp156
1 files changed, 56 insertions, 100 deletions
diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp
index f1c6c96a6d..7998567a21 100644
--- a/src/widgets/kernel/qgridlayout.cpp
+++ b/src/widgets/kernel/qgridlayout.cpp
@@ -1,49 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#include "qgridlayout.h"
#include "qapplication.h"
-#include "qwidget.h"
+#include "qgridlayout.h"
#include "qlist.h"
#include "qsizepolicy.h"
-#include "qvector.h"
#include "qvarlengtharray.h"
+#include "qwidget.h"
+
#include "qlayoutengine_p.h"
#include "qlayout_p.h"
@@ -84,7 +48,7 @@ public:
Qt::Alignment alignment() const { return item_->alignment(); }
QLayoutItem *item() { return item_; }
void setItem(QLayoutItem *newitem) { item_ = newitem; }
- QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = 0; return i; }
+ QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = nullptr; return i; }
int hStretch() { return item_->widget() ?
item_->widget()->sizePolicy().horizontalStretch() : 0; }
@@ -145,36 +109,36 @@ public:
int minimumHeightForWidth(int width, int hSpacing, int vSpacing);
inline void getNextPos(int &row, int &col) { row = nextR; col = nextC; }
- inline int count() const { return things.count(); }
+ inline int count() const { return things.size(); }
QRect cellRect(int row, int col) const;
inline QLayoutItem *itemAt(int index) const {
- if (index < things.count())
+ if (index >= 0 && index < things.size())
return things.at(index)->item();
else
- return 0;
+ return nullptr;
}
inline QLayoutItem *takeAt(int index) {
Q_Q(QGridLayout);
- if (index < things.count()) {
+ if (index >= 0 && index < things.size()) {
if (QGridBox *b = things.takeAt(index)) {
QLayoutItem *item = b->takeItem();
if (QLayout *l = item->layout()) {
// sanity check in case the user passed something weird to QObject::setParent()
if (l->parent() == q)
- l->setParent(0);
+ l->setParent(nullptr);
}
delete b;
return item;
}
}
- return 0;
+ return nullptr;
}
QLayoutItem* replaceAt(int index, QLayoutItem *newitem) override
{
if (!newitem)
- return 0;
- QLayoutItem *item = 0;
+ return nullptr;
+ QLayoutItem *item = nullptr;
QGridBox *b = things.value(index);
if (b) {
item = b->takeItem();
@@ -184,7 +148,7 @@ public:
}
void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const {
- if (index < things.count()) {
+ if (index >= 0 && index < things.size()) {
const QGridBox *b = things.at(index);
int toRow = b->toRow(rr);
int toCol = b->toCol(cc);
@@ -204,7 +168,7 @@ private:
QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const;
void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c);
void setSize(int rows, int cols);
- void setupSpacings(QVector<QLayoutStruct> &chain, QGridBox *grid[], int fixedSpacing,
+ void setupSpacings(QList<QLayoutStruct> &chain, QGridBox *grid[], int fixedSpacing,
Qt::Orientation orientation);
void setupLayoutData(int hSpacing, int vSpacing);
void setupHfwLayoutData();
@@ -212,13 +176,13 @@ private:
int rr;
int cc;
- QVector<QLayoutStruct> rowData;
- QVector<QLayoutStruct> colData;
- QVector<QLayoutStruct> *hfwData;
- QVector<int> rStretch;
- QVector<int> cStretch;
- QVector<int> rMinHeights;
- QVector<int> cMinWidths;
+ QList<QLayoutStruct> rowData;
+ QList<QLayoutStruct> colData;
+ QList<QLayoutStruct> *hfwData;
+ QList<int> rStretch;
+ QList<int> cStretch;
+ QList<int> rMinHeights;
+ QList<int> cMinWidths;
QList<QGridBox *> things;
int hfw_width;
@@ -253,7 +217,7 @@ void QGridLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *
int rightMost = 0;
int bottomMost = 0;
- QWidget *w = 0;
+ QWidget *w = nullptr;
const int n = things.count();
for (int i = 0; i < n; ++i) {
QGridBox *box = things.at(i);
@@ -342,7 +306,7 @@ QGridLayoutPrivate::QGridLayoutPrivate()
setDirty();
rr = cc = 0;
nextR = nextC = 0;
- hfwData = 0;
+ hfwData = nullptr;
hReversed = false;
vReversed = false;
horizontalSpacing = -1;
@@ -390,9 +354,9 @@ void QGridLayoutPrivate::recalcHFW(int w)
and put the results in hfwData.
*/
if (!hfwData)
- hfwData = new QVector<QLayoutStruct>(rr);
+ hfwData = new QList<QLayoutStruct>(rr);
setupHfwLayoutData();
- QVector<QLayoutStruct> &rData = *hfwData;
+ QList<QLayoutStruct> &rData = *hfwData;
int h = 0;
int mh = 0;
@@ -429,7 +393,7 @@ int QGridLayoutPrivate::minimumHeightForWidth(int w, int hSpacing, int vSpacing)
if (!has_hfw)
return -1;
int top, bottom;
- effectiveMargins(0, &top, 0, &bottom);
+ effectiveMargins(nullptr, &top, nullptr, &bottom);
return hfw_minheight + top + bottom;
}
@@ -521,7 +485,7 @@ void QGridLayoutPrivate::setSize(int r, int c)
if (hfwData && (int)hfwData->size() < r) {
delete hfwData;
- hfwData = 0;
+ hfwData = nullptr;
hfw_width = -1;
}
rr = r;
@@ -615,7 +579,7 @@ void QGridLayoutPrivate::addData(QGridBox *box, const QGridLayoutSizeTriple &siz
}
}
-static void initEmptyMultiBox(QVector<QLayoutStruct> &chain, int start, int end)
+static void initEmptyMultiBox(QList<QLayoutStruct> &chain, int start, int end)
{
for (int i = start; i <= end; i++) {
QLayoutStruct *data = &chain[i];
@@ -625,8 +589,8 @@ static void initEmptyMultiBox(QVector<QLayoutStruct> &chain, int start, int end)
}
}
-static void distributeMultiBox(QVector<QLayoutStruct> &chain, int start, int end, int minSize,
- int sizeHint, QVector<int> &stretchArray, int stretch)
+static void distributeMultiBox(QList<QLayoutStruct> &chain, int start, int end, int minSize,
+ int sizeHint, QList<int> &stretchArray, int stretch)
{
int i;
int w = 0;
@@ -698,9 +662,8 @@ static QGridBox *&gridAt(QGridBox *grid[], int r, int c, int cc,
return grid[(r * cc) + c];
}
-void QGridLayoutPrivate::setupSpacings(QVector<QLayoutStruct> &chain,
- QGridBox *grid[], int fixedSpacing,
- Qt::Orientation orientation)
+void QGridLayoutPrivate::setupSpacings(QList<QLayoutStruct> &chain, QGridBox *grid[],
+ int fixedSpacing, Qt::Orientation orientation)
{
Q_Q(QGridLayout);
int numRows = rr; // or columns if orientation is horizontal
@@ -710,14 +673,14 @@ void QGridLayoutPrivate::setupSpacings(QVector<QLayoutStruct> &chain,
qSwap(numRows, numColumns);
}
- QStyle *style = 0;
+ QStyle *style = nullptr;
if (fixedSpacing < 0) {
if (QWidget *parentWidget = q->parentWidget())
style = parentWidget->style();
}
for (int c = 0; c < numColumns; ++c) {
- QGridBox *previousBox = 0;
+ QGridBox *previousBox = nullptr;
int previousRow = -1; // previous *non-empty* row
for (int r = 0; r < numRows; ++r) {
@@ -741,7 +704,7 @@ void QGridLayoutPrivate::setupSpacings(QVector<QLayoutStruct> &chain,
if (style)
spacing = style->combinedLayoutSpacing(controlTypes1, controlTypes2,
- orientation, 0, q->parentWidget());
+ orientation, nullptr, q->parentWidget());
} else {
if (orientation == Qt::Vertical) {
QGridBox *sibling = vReversed ? previousBox : box;
@@ -868,7 +831,7 @@ void QGridLayoutPrivate::setupLayoutData(int hSpacing, int vSpacing)
void QGridLayoutPrivate::addHfwData(QGridBox *box, int width)
{
- QVector<QLayoutStruct> &rData = *hfwData;
+ QList<QLayoutStruct> &rData = *hfwData;
if (box->hasHeightForWidth()) {
int hint = box->heightForWidth(width);
rData[box->row].sizeHint = qMax(hint, rData.at(box->row).sizeHint);
@@ -888,7 +851,7 @@ void QGridLayoutPrivate::addHfwData(QGridBox *box, int width)
*/
void QGridLayoutPrivate::setupHfwLayoutData()
{
- QVector<QLayoutStruct> &rData = *hfwData;
+ QList<QLayoutStruct> &rData = *hfwData;
for (int i = 0; i < rr; i++) {
rData[i] = rowData.at(i);
rData[i].minimumSize = rData[i].sizeHint = rMinHeights.at(i);
@@ -944,7 +907,7 @@ void QGridLayoutPrivate::distribute(QRect r, int hSpacing, int vSpacing)
r.adjust(+left, +top, -right, -bottom);
qGeomCalc(colData, 0, cc, r.x(), r.width());
- QVector<QLayoutStruct> *rDataPtr;
+ QList<QLayoutStruct> *rDataPtr;
if (has_hfw) {
recalcHFW(r.width());
qGeomCalc(*hfwData, 0, rr, r.y(), r.height());
@@ -953,7 +916,7 @@ void QGridLayoutPrivate::distribute(QRect r, int hSpacing, int vSpacing)
qGeomCalc(rowData, 0, rr, r.y(), r.height());
rDataPtr = &rowData;
}
- QVector<QLayoutStruct> &rData = *rDataPtr;
+ QList<QLayoutStruct> &rData = *rDataPtr;
int i;
bool reverse = ((r.bottom() > rect.bottom()) || (r.bottom() == rect.bottom()
@@ -985,7 +948,7 @@ QRect QGridLayoutPrivate::cellRect(int row, int col) const
if (row < 0 || row >= rr || col < 0 || col >= cc)
return QRect();
- const QVector<QLayoutStruct> *rDataPtr;
+ const QList<QLayoutStruct> *rDataPtr;
if (has_hfw && hfwData)
rDataPtr = hfwData;
else
@@ -1073,31 +1036,24 @@ QRect QGridLayoutPrivate::cellRect(int row, int col) const
Constructs a new QGridLayout with parent widget, \a parent. The
layout has one row and one column initially, and will expand when
new items are inserted.
-*/
-QGridLayout::QGridLayout(QWidget *parent)
- : QLayout(*new QGridLayoutPrivate, 0, parent)
-{
- Q_D(QGridLayout);
- d->expand(1, 1);
-}
-/*!
- Constructs a new grid layout.
+ The layout is set directly as the top-level layout for \a parent.
+ There can be only one top-level layout for a widget. It is returned
+ by QWidget::layout().
+
+ If \a parent is \nullptr, then you must insert this grid layout
+ into another layout, or set it as a widget's layout using
+ QWidget::setLayout().
- You must insert this grid into another layout. You can insert
- widgets and layouts into this layout at any time, but laying out
- will not be performed before this is inserted into another layout.
+ \sa QWidget::setLayout()
*/
-QGridLayout::QGridLayout()
- : QLayout(*new QGridLayoutPrivate, 0, 0)
+QGridLayout::QGridLayout(QWidget *parent)
+ : QLayout(*new QGridLayoutPrivate, nullptr, parent)
{
Q_D(QGridLayout);
d->expand(1, 1);
}
-
-
-
/*!
\internal (mostly)
@@ -1330,15 +1286,15 @@ QLayoutItem *QGridLayout::itemAt(int index) const
/*!
\since 4.4
- Returns the layout item that occupies cell (\a row, \a column), or 0 if
- the cell is empty.
+ Returns the layout item that occupies cell (\a row, \a column), or
+ \nullptr if the cell is empty.
\sa getItemPosition(), indexOf()
*/
QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const
{
Q_D(const QGridLayout);
- int n = d->things.count();
+ int n = d->things.size();
for (int i = 0; i < n; ++i) {
QGridBox *box = d->things.at(i);
if (row >= box->row && row <= box->toRow(d->rr)
@@ -1346,7 +1302,7 @@ QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const
return box->item();
}
}
- return 0;
+ return nullptr;
}
/*!