diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-07-10 14:30:49 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-07-10 14:33:46 (GMT) |
commit | 364aa2a21512d32f3f4271f438e3a6fa799c1e9e (patch) | |
tree | 3f40e5d593948e13ebf4623134af4ac9e40fadb9 | |
parent | 4ed3ee42bae92b0feb5c898e4f0fdf7d34e34108 (diff) | |
download | Qt-364aa2a21512d32f3f4271f438e3a6fa799c1e9e.zip Qt-364aa2a21512d32f3f4271f438e3a6fa799c1e9e.tar.gz Qt-364aa2a21512d32f3f4271f438e3a6fa799c1e9e.tar.bz2 |
ItemViews: make the pixmap from drag and drop more efficient
We don't need to draw all the items that are selected. We just need
those whose rect intersects the one from the viewport.
Task-number: 233342
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 33 | ||||
-rw-r--r-- | src/gui/itemviews/qabstractitemview_p.h | 2 |
2 files changed, 21 insertions, 14 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index dd84304..5f347dd 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -3883,28 +3883,35 @@ bool QAbstractItemViewPrivate::openEditor(const QModelIndex &index, QEvent *even QPixmap QAbstractItemViewPrivate::renderToPixmap(const QModelIndexList &indexes, QRect *r) const { + Q_ASSERT(r); Q_Q(const QAbstractItemView); - QRect rect = q->visualRect(indexes.at(0)); + QRect &rect = *r; + const QRect viewportRect = viewport->rect(); QList<QRect> rects; + QModelIndexList paintedIndexes; for (int i = 0; i < indexes.count(); ++i) { - rects.append(q->visualRect(indexes.at(i))); - rect |= rects.at(i); + const QModelIndex &index = indexes.at(i); + const QRect current = q->visualRect(index); + if (current.intersects(viewportRect)) { + paintedIndexes += index; + rects += current; + rect |= current; + } } - rect = rect.intersected(viewport->rect()); - if (rect.width() <= 0 || rect.height() <= 0) + rect = rect.intersected(viewportRect); + if (rect.isEmpty()) return QPixmap(); - QImage image(rect.size(), QImage::Format_ARGB32_Premultiplied); - image.fill(0); - QPainter painter(&image); + QPixmap pixmap(rect.size()); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); QStyleOptionViewItemV4 option = viewOptionsV4(); option.state |= QStyle::State_Selected; - for (int j = 0; j < indexes.count(); ++j) { + for (int j = 0; j < paintedIndexes.count(); ++j) { + const QModelIndex ¤t = paintedIndexes.at(j); option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(), rects.at(j).size()); - delegateForIndex(indexes.at(j))->paint(&painter, option, indexes.at(j)); + delegateForIndex(current)->paint(&painter, option, current); } - painter.end(); - if (r) *r = rect; - return QPixmap::fromImage(image); + return pixmap; } void QAbstractItemViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command) diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 00647f6..7443d50 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -221,7 +221,7 @@ public: void clearOrRemove(); void checkPersistentEditorFocus(); - QPixmap renderToPixmap(const QModelIndexList &indexes, QRect *r = 0) const; + QPixmap renderToPixmap(const QModelIndexList &indexes, QRect *r) const; inline QPoint offset() const { const Q_Q(QAbstractItemView); |