diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-06-16 08:05:44 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-06-16 08:50:23 (GMT) |
commit | 183abff6ffcb020b8f0c4041cc82bba0d3b03863 (patch) | |
tree | 7492fe295fdc966b72ba27f3c68ef5d7716e2801 /src/gui/graphicsview | |
parent | 17fbbdd3a081a66e1d2b26db7935111c49cea75e (diff) | |
download | Qt-183abff6ffcb020b8f0c4041cc82bba0d3b03863.zip Qt-183abff6ffcb020b8f0c4041cc82bba0d3b03863.tar.gz Qt-183abff6ffcb020b8f0c4041cc82bba0d3b03863.tar.bz2 |
Fixed problem with wrong size hints when items were removed.
The reason was that the row/column count was not updated after an item
was removed. (Note that qgraphicslinearlayout already did this, so we
just follow the same pattern, except that the code for
QGraphicsGridLayout is a bit more complex...
Task-number: QTBUG-10314
Reviewed-by: Alexis Menard
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicsgridlayout.cpp | 12 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicslinearlayout.cpp | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgridlayoutengine_p.h | 4 |
3 files changed, 15 insertions, 3 deletions
diff --git a/src/gui/graphicsview/qgraphicsgridlayout.cpp b/src/gui/graphicsview/qgraphicsgridlayout.cpp index 6ca799d..83db3ec 100644 --- a/src/gui/graphicsview/qgraphicsgridlayout.cpp +++ b/src/gui/graphicsview/qgraphicsgridlayout.cpp @@ -572,6 +572,18 @@ void QGraphicsGridLayout::removeAt(int index) if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem()) layoutItem->setParentLayoutItem(0); d->engine.removeItem(gridItem); + + // recalculate rowInfo.count if we remove an item that is on the right/bottommost row + for (int j = 0; j < NOrientations; ++j) { + // 0: Hor, 1: Ver + const Qt::Orientation orient = (j == 0 ? Qt::Horizontal : Qt::Vertical); + const int oldCount = d->engine.rowCount(orient); + if (gridItem->lastRow(orient) == oldCount - 1) { + const int newCount = d->engine.effectiveLastRow(orient) + 1; + d->engine.removeRows(newCount, oldCount - newCount, orient); + } + } + delete gridItem; invalidate(); } diff --git a/src/gui/graphicsview/qgraphicslinearlayout.cpp b/src/gui/graphicsview/qgraphicslinearlayout.cpp index 9722683..b828722 100644 --- a/src/gui/graphicsview/qgraphicslinearlayout.cpp +++ b/src/gui/graphicsview/qgraphicslinearlayout.cpp @@ -147,7 +147,7 @@ void QGraphicsLinearLayoutPrivate::removeGridItem(QGridLayoutItem *gridItem) { int index = gridItem->firstRow(orientation); engine.removeItem(gridItem); - engine.removeRow(index, orientation); + engine.removeRows(index, 1, orientation); } void QGraphicsLinearLayoutPrivate::fixIndex(int *index) const diff --git a/src/gui/graphicsview/qgridlayoutengine_p.h b/src/gui/graphicsview/qgridlayoutengine_p.h index cbf704e..9ac9a8e 100644 --- a/src/gui/graphicsview/qgridlayoutengine_p.h +++ b/src/gui/graphicsview/qgridlayoutengine_p.h @@ -363,8 +363,8 @@ public: QGridLayoutItem *itemAt(int row, int column, Qt::Orientation orientation = Qt::Vertical) const; inline void insertRow(int row, Qt::Orientation orientation = Qt::Vertical) { insertOrRemoveRows(row, +1, orientation); } - inline void removeRow(int row, Qt::Orientation orientation = Qt::Vertical) - { insertOrRemoveRows(row, -1, orientation); } + inline void removeRows(int row, int count, Qt::Orientation orientation) + { insertOrRemoveRows(row, -count, orientation); } void invalidate(); void setGeometries(const QLayoutStyleInfo &styleInfo, const QRectF &contentsGeometry); |