forked from qt-creator/qt-creator
Utils: Centralize adding layoutitems in LayoutBuilder
As a side-effect, this fixes adding stretch and space in the the dummy vboxes for formlayout fields with more than two items that was accidentally missing before. Change-Id: I18e4755ccd3cd9e1de761b70dc621b17376277dc Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -160,6 +160,23 @@ static QWidget *widgetForItem(QLayoutItem *item)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addItemToBoxLayout(QBoxLayout *layout, const LayoutBuilder::LayoutItem &item)
|
||||||
|
{
|
||||||
|
if (QWidget *w = item.widget) {
|
||||||
|
layout->addWidget(w);
|
||||||
|
} else if (QLayout *l = item.layout) {
|
||||||
|
layout->addLayout(l);
|
||||||
|
} else if (item.specialType == LayoutBuilder::SpecialType::Stretch) {
|
||||||
|
layout->addStretch(item.specialValue.toInt());
|
||||||
|
} else if (item.specialType == LayoutBuilder::SpecialType::Space) {
|
||||||
|
layout->addSpacing(item.specialValue.toInt());
|
||||||
|
} else if (!item.text.isEmpty()) {
|
||||||
|
layout->addWidget(new QLabel(item.text));
|
||||||
|
} else {
|
||||||
|
QTC_CHECK(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void flushPendingFormItems(QFormLayout *formLayout,
|
static void flushPendingFormItems(QFormLayout *formLayout,
|
||||||
LayoutBuilder::LayoutItems &pendingFormItems)
|
LayoutBuilder::LayoutItems &pendingFormItems)
|
||||||
{
|
{
|
||||||
@@ -172,14 +189,8 @@ static void flushPendingFormItems(QFormLayout *formLayout,
|
|||||||
if (pendingFormItems.size() > 2) {
|
if (pendingFormItems.size() > 2) {
|
||||||
auto hbox = new QHBoxLayout;
|
auto hbox = new QHBoxLayout;
|
||||||
setMargins(false, hbox);
|
setMargins(false, hbox);
|
||||||
for (int i = 1; i < pendingFormItems.size(); ++i) {
|
for (int i = 1; i < pendingFormItems.size(); ++i)
|
||||||
if (QWidget *w = pendingFormItems.at(i).widget)
|
addItemToBoxLayout(hbox, pendingFormItems.at(i));
|
||||||
hbox->addWidget(w);
|
|
||||||
else if (QLayout *l = pendingFormItems.at(i).layout)
|
|
||||||
hbox->addLayout(l);
|
|
||||||
else
|
|
||||||
QTC_CHECK(false);
|
|
||||||
}
|
|
||||||
while (pendingFormItems.size() >= 2)
|
while (pendingFormItems.size() >= 2)
|
||||||
pendingFormItems.pop_back();
|
pendingFormItems.pop_back();
|
||||||
pendingFormItems.append(LayoutBuilder::LayoutItem(hbox));
|
pendingFormItems.append(LayoutBuilder::LayoutItem(hbox));
|
||||||
@@ -256,15 +267,7 @@ static void doLayoutHelper(QLayout *layout,
|
|||||||
gridLayout->addLayout(item.layout, currentGridRow, currentGridColumn, 1, item.span, align);
|
gridLayout->addLayout(item.layout, currentGridRow, currentGridColumn, 1, item.span, align);
|
||||||
currentGridColumn += item.span;
|
currentGridColumn += item.span;
|
||||||
} else if (boxLayout) {
|
} else if (boxLayout) {
|
||||||
if (widget) {
|
addItemToBoxLayout(boxLayout, item);
|
||||||
boxLayout->addWidget(widget);
|
|
||||||
} else if (item.layout) {
|
|
||||||
boxLayout->addLayout(item.layout);
|
|
||||||
} else if (item.specialType == LayoutBuilder::SpecialType::Stretch) {
|
|
||||||
boxLayout->addStretch(item.specialValue.toInt());
|
|
||||||
} else if (item.specialType == LayoutBuilder::SpecialType::Space) {
|
|
||||||
boxLayout->addSpacing(item.specialValue.toInt());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pendingFormItems.append(item);
|
pendingFormItems.append(item);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user