summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qformlayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qformlayout.cpp')
-rw-r--r--src/widgets/kernel/qformlayout.cpp102
1 files changed, 49 insertions, 53 deletions
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp
index 6f7527c013..4ffa226d7f 100644
--- a/src/widgets/kernel/qformlayout.cpp
+++ b/src/widgets/kernel/qformlayout.cpp
@@ -199,18 +199,17 @@ public:
ItemMatrix m_matrix;
QList<QFormLayoutItem *> m_things;
- int layoutWidth; // the last width that we called setupVerticalLayoutData on (for vLayouts)
+ int layoutWidth = -1; // the last width that we called setupVerticalLayoutData on (for vLayouts)
- int hfw_width; // the last width we calculated HFW for
- int hfw_height; // what that height was
- int hfw_minheight; // what that minheight was
+ int hfw_width = -1; // the last width we calculated HFW for
+ int hfw_height = -1; // what that height was
- int hfw_sh_height; // the hfw for sh_width
- int hfw_sh_minheight; // the minhfw for sh_width
+ int hfw_sh_height = -1; // the hfw for sh_width
+ int hfw_sh_minheight = -1; // the minhfw for sh_width
- int min_width; // the width that gets turned into minSize (from updateSizes)
- int sh_width; // the width that gets turned into prefSize (from updateSizes)
- int thresh_width; // the width that we start splitting label/field pairs at (from updateSizes)
+ int min_width = -1; // the width that gets turned into minSize (from updateSizes)
+ int sh_width = -1; // the width that gets turned into prefSize (from updateSizes)
+ int thresh_width = QLAYOUTSIZE_MAX; // the width that we start splitting label/field pairs at (from updateSizes)
QSize minSize;
QSize prefSize;
int formMaxWidth;
@@ -222,17 +221,15 @@ public:
QVector<QLayoutStruct> hfwLayouts;
- int hSpacing;
- int vSpacing;
+ int hSpacing = -1;
+ int vSpacing = -1;
QLayoutItem* replaceAt(int index, QLayoutItem*) override;
};
QFormLayoutPrivate::QFormLayoutPrivate()
: fieldGrowthPolicy(DefaultFieldGrowthPolicy),
rowWrapPolicy(DefaultRowWrapPolicy), has_hfw(false), dirty(true), sizesDirty(true),
- expandVertical(0), expandHorizontal(0), labelAlignment(0), formAlignment(0),
- layoutWidth(-1), hfw_width(-1), hfw_sh_height(-1), min_width(-1),
- sh_width(-1), thresh_width(QLAYOUTSIZE_MAX), hSpacing(-1), vSpacing(-1)
+ expandVertical(0), expandHorizontal(0)
{
}
@@ -298,11 +295,11 @@ void QFormLayoutPrivate::updateSizes()
bool expandH = false;
bool expandV = false;
- QFormLayoutItem *prevLbl = 0;
- QFormLayoutItem *prevFld = 0;
+ QFormLayoutItem *prevLbl = nullptr;
+ QFormLayoutItem *prevFld = nullptr;
QWidget *parent = q->parentWidget();
- QStyle *style = parent ? parent->style() : 0;
+ QStyle *style = parent ? parent->style() : nullptr;
int userVSpacing = q->verticalSpacing();
int userHSpacing = wrapAllRows ? 0 : q->horizontalSpacing();
@@ -367,9 +364,9 @@ void QFormLayoutPrivate::updateSizes()
QSizePolicy::ControlTypes fldtoptypes =
QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType);
if (label && lbltop)
- label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
+ label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, nullptr, parent);
if (field && fldtop)
- field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
+ field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, nullptr, parent);
} else {
// Side by side.. we have to also consider the spacings to empty cells, which can strangely be more than
// non empty cells..
@@ -383,21 +380,21 @@ void QFormLayoutPrivate::updateSizes()
// To be compatible to QGridLayout, we have to compare solitary labels & fields with both predecessors
if (label) {
if (!field) {
- int lblspacing = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
- int fldspacing = style->combinedLayoutSpacing(fldtoptypes, lbltypes, Qt::Vertical, 0, parent);
+ int lblspacing = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, nullptr, parent);
+ int fldspacing = style->combinedLayoutSpacing(fldtoptypes, lbltypes, Qt::Vertical, nullptr, parent);
label->vSpace = qMax(lblspacing, fldspacing);
} else
- label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
+ label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, nullptr, parent);
}
if (field) {
// check spacing against both the previous label and field
if (!label) {
- int lblspacing = style->combinedLayoutSpacing(lbltoptypes, fldtypes, Qt::Vertical, 0, parent);
- int fldspacing = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
+ int lblspacing = style->combinedLayoutSpacing(lbltoptypes, fldtypes, Qt::Vertical, nullptr, parent);
+ int fldspacing = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, nullptr, parent);
field->vSpace = qMax(lblspacing, fldspacing);
} else
- field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
+ field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, nullptr, parent);
}
}
}
@@ -406,7 +403,7 @@ void QFormLayoutPrivate::updateSizes()
// hard-coded the left and right control types so that all the rows have the same
// inter-column spacing (otherwise the right column isn't always left aligned)
if (userHSpacing < 0 && !wrapAllRows && (label || !field->fullRow) && field)
- field->sbsHSpace = style->combinedLayoutSpacing(QSizePolicy::Label, QSizePolicy::LineEdit, Qt::Horizontal, 0, parent);
+ field->sbsHSpace = style->combinedLayoutSpacing(QSizePolicy::Label, QSizePolicy::LineEdit, Qt::Horizontal, nullptr, parent);
}
// Now update our min/sizehint widths
@@ -481,7 +478,6 @@ void QFormLayoutPrivate::recalcHFW(int w)
} else {
hfw_width = w;
hfw_height = qMin(QLAYOUTSIZE_MAX, h);
- hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);
}
}
@@ -598,13 +594,13 @@ static inline int spacingHelper(QWidget* parent, QStyle *style, int userVSpacing
QSizePolicy::ControlTypes(item1 ? item1->controlTypes() : QSizePolicy::DefaultType);
int spacing2 = 0;
- spacing = style->combinedLayoutSpacing(itemtypes, prevItem1->controlTypes(), Qt::Vertical, 0, parent);
+ spacing = style->combinedLayoutSpacing(itemtypes, prevItem1->controlTypes(), Qt::Vertical, nullptr, parent);
// At most of one of item2 and prevItem2 will be nonnull
if (item2)
- spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, 0, parent);
+ spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, nullptr, parent);
else if (prevItem2)
- spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, 0, parent);
+ spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, nullptr, parent);
spacing = qMax(spacing, spacing2);
}
@@ -652,7 +648,7 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
vLayouts.clear();
vLayouts.resize((2 * rr) + 2); // a max, some may be unused
- QStyle *style = 0;
+ QStyle *style = nullptr;
int userVSpacing = q->verticalSpacing();
@@ -680,8 +676,8 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
maxLabelWidth = width;
}
- QFormLayoutItem *prevItem1 = 0;
- QFormLayoutItem *prevItem2 = 0;
+ QFormLayoutItem *prevItem1 = nullptr;
+ QFormLayoutItem *prevItem2 = nullptr;
bool prevRowSplit = false;
for (int i = 0; i < rr; ++i) {
@@ -715,13 +711,13 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
initLayoutStruct(vLayouts[vidx], label);
if (vidx > 1)
- vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2);
+ vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, nullptr, prevItem1, prevItem2);
label->vLayoutIndex = vidx;
label->sideBySide = false;
prevItem1 = label;
- prevItem2 = 0;
+ prevItem2 = nullptr;
if (vLayouts[vidx].stretch > 0)
addTopBottomStretch = false;
@@ -733,13 +729,13 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
initLayoutStruct(vLayouts[vidx], field);
if (vidx > 1)
- vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2);
+ vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, nullptr, prevItem1, prevItem2);
field->vLayoutIndex = vidx;
field->sideBySide = false;
prevItem1 = field;
- prevItem2 = 0;
+ prevItem2 = nullptr;
if (vLayouts[vidx].stretch > 0)
addTopBottomStretch = false;
@@ -762,7 +758,7 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
if (label->expandingDirections() & Qt::Vertical)
expanding = true;
- label->sideBySide = (field != 0);
+ label->sideBySide = (field != nullptr);
label->vLayoutIndex = vidx;
stretch1 = label->vStretch();
}
@@ -794,7 +790,7 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
prevItem2 = field;
} else {
prevItem1 = field;
- prevItem2 = 0;
+ prevItem2 = nullptr;
}
prevRowSplit = false;
@@ -995,12 +991,12 @@ QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem)
{
Q_Q(QFormLayout);
if (!newitem)
- return 0;
+ return nullptr;
const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index));
if (Q_UNLIKELY(storageIndex == -1)) {
// ### Qt6 - fix warning too when this class becomes public
qWarning("QFormLayoutPrivate::replaceAt: Invalid index %d", index);
- return 0;
+ return nullptr;
}
int row, col;
@@ -1196,7 +1192,7 @@ QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem)
\sa QWidget::setLayout()
*/
QFormLayout::QFormLayout(QWidget *parent)
- : QLayout(*new QFormLayoutPrivate, 0, parent)
+ : QLayout(*new QFormLayoutPrivate, nullptr, parent)
{
}
@@ -1332,7 +1328,7 @@ void QFormLayout::insertRow(int row, const QString &labelText, QWidget *field)
if (field && !d->checkWidget(field))
return;
- QLabel *label = 0;
+ QLabel *label = nullptr;
if (!labelText.isEmpty()) {
label = new QLabel(labelText);
#ifndef QT_NO_SHORTCUT
@@ -1354,7 +1350,7 @@ void QFormLayout::insertRow(int row, const QString &labelText, QLayout *field)
if (field && !d->checkLayout(field))
return;
- insertRow(row, labelText.isEmpty() ? 0 : new QLabel(labelText), field);
+ insertRow(row, labelText.isEmpty() ? nullptr : new QLabel(labelText), field);
}
/*!
@@ -1657,7 +1653,7 @@ QLayoutItem *QFormLayout::itemAt(int index) const
Q_D(const QFormLayout);
if (QFormLayoutItem *formItem = d->m_things.value(index))
return formItem->item;
- return 0;
+ return nullptr;
}
/*!
@@ -1670,7 +1666,7 @@ QLayoutItem *QFormLayout::takeAt(int index)
const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index));
if (Q_UNLIKELY(storageIndex == -1)) {
qWarning("QFormLayout::takeAt: Invalid index %d", index);
- return 0;
+ return nullptr;
}
int row, col;
@@ -1696,7 +1692,7 @@ Qt::Orientations QFormLayout::expandingDirections() const
QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d);
e->updateSizes();
- Qt::Orientations o = 0;
+ Qt::Orientations o;
if (e->expandHorizontal)
o = Qt::Horizontal;
if (e->expandVertical)
@@ -1835,7 +1831,7 @@ QLayoutItem *QFormLayout::itemAt(int row, ItemRole role) const
{
Q_D(const QFormLayout);
if (uint(row) >= uint(d->m_matrix.rowCount()))
- return 0;
+ return nullptr;
switch (role) {
case SpanningRole:
if (QFormLayoutItem *item = d->m_matrix(row, 1))
@@ -1848,7 +1844,7 @@ QLayoutItem *QFormLayout::itemAt(int row, ItemRole role) const
return item->item;
break;
}
- return 0;
+ return nullptr;
}
/*!
@@ -1932,7 +1928,7 @@ QWidget *QFormLayout::labelForField(QWidget *field) const
if (QFormLayoutItem *label = d->m_matrix(row, LabelRole))
return label->widget();
}
- return 0;
+ return nullptr;
}
/*!
@@ -1951,7 +1947,7 @@ QWidget *QFormLayout::labelForField(QLayout *field) const
if (QFormLayoutItem *label = d->m_matrix(row, LabelRole))
return label->widget();
}
- return 0;
+ return nullptr;
}
/*!
@@ -2326,7 +2322,7 @@ void QFormLayout::resetRowWrapPolicy()
void QFormLayout::resetFormAlignment()
{
Q_D(QFormLayout);
- d->formAlignment = 0;
+ d->formAlignment = { };
}
/*!
@@ -2336,7 +2332,7 @@ void QFormLayout::resetFormAlignment()
void QFormLayout::resetLabelAlignment()
{
Q_D(QFormLayout);
- d->labelAlignment = 0;
+ d->labelAlignment = { };
}
#if 0