summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews/qtreeview.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-03-18 09:47:44 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-03-18 10:07:47 (GMT)
commit692f12d89e6d2cf33ca2965ccd155d30ce3d32e8 (patch)
treeaa9c63a9009c0f02d26619b461c9341a82264c3e /src/gui/itemviews/qtreeview.cpp
parent6dcdab8d9ee66f420a525400d873cfccf78c7003 (diff)
downloadQt-692f12d89e6d2cf33ca2965ccd155d30ce3d32e8.zip
Qt-692f12d89e6d2cf33ca2965ccd155d30ce3d32e8.tar.gz
Qt-692f12d89e6d2cf33ca2965ccd155d30ce3d32e8.tar.bz2
Optimized visualRegionForSelection in various item views classes
When the number of selected items is large (a few thousands), the computation of visualRegionForSelection can take a long time (up to a few seconds). Analysis with valgrind shows that most of the time is spent in miRegionOp (in qregion.cpp), which is being called by QRegion::operator+=. The visualRegionForSelection virtual method being called only to update the view after selection, we can safely ignore those item's rectangles outside the viewport, thus both reducing the number of calls to miRegionOp and the actual cost of each call. This, however, introduces a behaviour change in visualRegionForSelection, as the returned region will *not* contain any rectangle *not* intersecting the viewport. Reviewed-by: Thierry Task-number: QTBUG-884
Diffstat (limited to 'src/gui/itemviews/qtreeview.cpp')
-rw-r--r--src/gui/itemviews/qtreeview.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index ada3936..101dafe 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -2271,6 +2271,9 @@ void QTreeView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFl
/*!
Returns the rectangle from the viewport of the items in the given
\a selection.
+
+ Since 4.7, the returned region only contains rectangles intersecting
+ (or included in) the viewport.
*/
QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) const
{
@@ -2279,6 +2282,7 @@ QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) con
return QRegion();
QRegion selectionRegion;
+ const QRect &viewportRect = d->viewport->rect();
for (int i = 0; i < selection.count(); ++i) {
QItemSelectionRange range = selection.at(i);
if (!range.isValid())
@@ -2311,13 +2315,16 @@ QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) con
qSwap<int>(top, bottom);
int height = bottom - top + 1;
if (d->header->sectionsMoved()) {
- for (int c = range.left(); c <= range.right(); ++c)
- selectionRegion += QRegion(QRect(columnViewportPosition(c), top,
- columnWidth(c), height));
+ for (int c = range.left(); c <= range.right(); ++c) {
+ const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
+ if (viewportRect.intersects(rangeRect))
+ selectionRegion += rangeRect;
+ }
} else {
QRect combined = leftRect|rightRect;
combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
- selectionRegion += combined;
+ if (viewportRect.intersects(combined))
+ selectionRegion += combined;
}
}
return selectionRegion;