diff options
author | Thomas Zander <thomas.zander@trolltech.com> | 2009-05-14 10:19:53 +0200 |
---|---|---|
committer | Thomas Zander <thomas.zander@trolltech.com> | 2009-05-14 10:19:53 +0200 |
commit | 298a2b6f200761294456f47666077dd2bd8cc7ec (patch) | |
tree | 32efad2021985ebdcfbaf359665b3085305ed13b | |
parent | a0fe23273a2e85b9bc600fb36892975949adee59 (diff) |
Fixes resizing a table to be less wide to cause painting to incorrect
Make the relayout to not leave behind any unneeded cells
-rw-r--r-- | src/qgraphicstableview.cpp | 24 | ||||
-rw-r--r-- | src/qgraphicstableview_p.h | 3 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/qgraphicstableview.cpp b/src/qgraphicstableview.cpp index 8ac28e5..97de041 100644 --- a/src/qgraphicstableview.cpp +++ b/src/qgraphicstableview.cpp @@ -403,6 +403,20 @@ void QtGraphicsTableViewPrivate::removeItem(int row, int column) } } +void QtGraphicsTableViewPrivate::recycleUnusedItems(const QSet<QtGraphicsTableViewItem*> &usedItems) +{ + for (int index = 0; index < childItems.count(); ++index) { + QtGraphicsTableViewItem *item = childItems.value(index); + if (item == 0) + continue; + if (! usedItems.contains(item)) { + childItems.replace(index, 0); + unusedItems.append(item); + item->hide(); + } + } +} + // QtGraphicsTableView /*! @@ -1314,11 +1328,10 @@ void QtGraphicsTableView::doLayout() qreal x; qreal y = verticalOffset; - QList<int> rowsVisualized; // tracks all rows we show allowing us to recycle all the rest. + QSet<QtGraphicsTableViewItem*> itemsVisualized;// tracks all items we show allowing us to recycle all the rest. for (int visualRow = d->firstRow; visualRow <= maxRow; ++visualRow) { x = horizontalOffset; const int effectiveRow = verticalMapping.value(visualRow, visualRow); - rowsVisualized << effectiveRow; const qreal height = rowHeight(effectiveRow); QtGraphicsTableViewItem *item = 0; for (int visualColumn = d->firstColumn; visualColumn <= maxColumn; ++visualColumn) { @@ -1355,6 +1368,7 @@ void QtGraphicsTableView::doLayout() d->setItem(item); } Q_ASSERT(item); + itemsVisualized << item; item->setGeometry(x, y, width, height); x += width; if (x > size().width()) @@ -1365,11 +1379,7 @@ void QtGraphicsTableView::doLayout() break; } - QList<int> cachedRows = d->childItemIndexes.keys(); - for (QList<int>::Iterator i = cachedRows.begin(); i != cachedRows.end(); ++i) { - if (! rowsVisualized.contains(*i)) - d->removeItemsOnRow(*i); - } + d->recycleUnusedItems(itemsVisualized); } #include "moc_qgraphicstableview.cpp" diff --git a/src/qgraphicstableview_p.h b/src/qgraphicstableview_p.h index a38eee8..3240070 100644 --- a/src/qgraphicstableview_p.h +++ b/src/qgraphicstableview_p.h @@ -117,8 +117,9 @@ public: QtGraphicsTableViewItem *item(int row, int column) const; void setItem(QtGraphicsTableViewItem *item); - void removeItemsOnRow(int row); + void removeItemsOnRow(int row); // ### unused void removeItem(int row, int column); + void recycleUnusedItems(const QSet<QtGraphicsTableViewItem*> &usedItems); private: QList<QtGraphicsTableViewItem*> childItems; |