summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJarek Kobus <jkobus@trolltech.com>2011-02-01 12:15:28 (GMT)
committerJarek Kobus <jkobus@trolltech.com>2011-02-01 12:15:28 (GMT)
commit0e456bf74dfea10c0f5c164eb5a920e4661a91b2 (patch)
treed2d2b7aeb5ab477d5749dc0cdc234723d3bd01ed /tools
parent84b81d47829d56cbd5568034161bf25898ab0824 (diff)
downloadQt-0e456bf74dfea10c0f5c164eb5a920e4661a91b2.zip
Qt-0e456bf74dfea10c0f5c164eb5a920e4661a91b2.tar.gz
Qt-0e456bf74dfea10c0f5c164eb5a920e4661a91b2.tar.bz2
Fix a crash when undoing form layout
In a rare case when breaking a layout might make widgets overlap, the internal heuristic failed when recreating an original layout during undo. Some widgets were removed from the grid. The patch fixes this heuristic (makes sure we don't remove other widgets). Creating a form layout from overlapping widgets works better now. Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Task-number: QTCREATORBUG-3616
Diffstat (limited to 'tools')
-rw-r--r--tools/designer/src/lib/shared/layout.cpp22
-rw-r--r--tools/designer/src/lib/shared/qlayout_widget.cpp3
2 files changed, 15 insertions, 10 deletions
diff --git a/tools/designer/src/lib/shared/layout.cpp b/tools/designer/src/lib/shared/layout.cpp
index c9ffe71..9fe438b 100644
--- a/tools/designer/src/lib/shared/layout.cpp
+++ b/tools/designer/src/lib/shared/layout.cpp
@@ -996,13 +996,23 @@ bool Grid::shrinkFormLayoutSpans()
for (WidgetSet::const_iterator it = widgets.constBegin(); it != cend ; ++it) {
QWidget *w = *it;
int row, col, rowspan, colspan;
- locateWidget(w, row, col, rowspan, colspan);
+ if (!locateWidget(w, row, col, rowspan, colspan))
+ qDebug("ooops, widget '%s' does not fit in layout", w->objectName().toUtf8().constData());
const int maxColSpan = col == 0 ? 2 : 1;
const int newColSpan = qMin(colspan, maxColSpan);
const int newRowSpan = qMin(rowspan, maxRowSpan);
if (newColSpan != colspan || newRowSpan != rowspan) {
- setCells(QRect(col, row, colspan, rowspan), 0);
- setCells(QRect(col, row, newColSpan, newRowSpan), w);
+ // in case like this:
+ // W1 W1
+ // W1 W2
+ // do:
+ // W1 0
+ // 0 W2
+ for (int i = row; i < row + rowspan - 1; i++)
+ for (int j = col; j < col + colspan - 1; j++)
+ if (i > row + newColSpan - 1 || j > col + newRowSpan - 1)
+ if (cell(i, j) == w)
+ setCell(i, j, 0);
shrunk = true;
}
}
@@ -1177,11 +1187,7 @@ void GridLayout<GridLikeLayout, LayoutType, GridMode>::doLayout()
if (const Spacer *spacer = qobject_cast<const Spacer*>(w))
alignment = spacer->alignment();
- if (rs * cs == 1) {
- addWidgetToGrid(layout, w, r, c, 1, 1, alignment);
- } else {
- addWidgetToGrid(layout, w, r, c, rs, cs, alignment);
- }
+ addWidgetToGrid(layout, w, r, c, rs, cs, alignment);
w->show();
} else {
diff --git a/tools/designer/src/lib/shared/qlayout_widget.cpp b/tools/designer/src/lib/shared/qlayout_widget.cpp
index 20db606..4debb5e 100644
--- a/tools/designer/src/lib/shared/qlayout_widget.cpp
+++ b/tools/designer/src/lib/shared/qlayout_widget.cpp
@@ -1181,8 +1181,7 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
} else {
for (int c = 0; c < FormLayoutColumns; c++) {
const QFormLayout::ItemRole role = c == 0 ? QFormLayout::LabelRole : QFormLayout::FieldRole;
- if (widgets[c]) {
- Q_ASSERT(BoxLayoutHelper::findItemOfWidget(items, widgets[c]));
+ if (widgets[c] && BoxLayoutHelper::findItemOfWidget(items, widgets[c])) {
formLayout->setWidget(r, role, widgets[c]);
} else {
formLayout->setItem(r, role, createFormSpacer());