summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-07-13 12:03:39 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-07-13 12:04:44 (GMT)
commit32182d107fa75e5619ecc91a81f50626f429ebe1 (patch)
tree97d8ed9480b92d053e39850b214a14f696f1ed6b
parentd54224252d56a50b42c8991308840ea1acde8f30 (diff)
downloadQt-32182d107fa75e5619ecc91a81f50626f429ebe1.zip
Qt-32182d107fa75e5619ecc91a81f50626f429ebe1.tar.gz
Qt-32182d107fa75e5619ecc91a81f50626f429ebe1.tar.bz2
QTreeView: now dragging lots of items is fast
-rw-r--r--src/corelib/kernel/qabstractitemmodel.cpp2
-rw-r--r--src/corelib/kernel/qmimedata.cpp2
-rw-r--r--src/corelib/kernel/qvariant.cpp4
-rw-r--r--src/gui/itemviews/qabstractitemview.cpp2
-rw-r--r--src/gui/itemviews/qlistview.cpp1
-rw-r--r--src/gui/itemviews/qtreeview.cpp44
-rw-r--r--src/gui/itemviews/qtreeview_p.h2
7 files changed, 51 insertions, 6 deletions
diff --git a/src/corelib/kernel/qabstractitemmodel.cpp b/src/corelib/kernel/qabstractitemmodel.cpp
index 914f44f..1c3371f 100644
--- a/src/corelib/kernel/qabstractitemmodel.cpp
+++ b/src/corelib/kernel/qabstractitemmodel.cpp
@@ -1407,7 +1407,7 @@ QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const
QMap<int, QVariant> roles;
for (int i = 0; i < Qt::UserRole; ++i) {
QVariant variantData = data(index, i);
- if (variantData.type() != QVariant::Invalid)
+ if (variantData.isValid())
roles.insert(i, variantData);
}
return roles;
diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp
index 3d2a7cb..4a1ba9f 100644
--- a/src/corelib/kernel/qmimedata.cpp
+++ b/src/corelib/kernel/qmimedata.cpp
@@ -105,7 +105,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty
Q_Q(const QMimeData);
QVariant data = q->retrieveData(format, type);
- if (data.type() == type || data.type() == QVariant::Invalid)
+ if (data.type() == type || !data.isValid())
return data;
// provide more conversion possiblities than just what QVariant provides
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 8bf70cb..2ef9de4 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1905,7 +1905,7 @@ void QVariant::load(QDataStream &s)
create(static_cast<int>(u), 0);
d.is_null = is_null;
- if (d.type == QVariant::Invalid) {
+ if (!isValid()) {
// Since we wrote something, we should read something
QString x;
s >> x;
@@ -1949,7 +1949,7 @@ void QVariant::save(QDataStream &s) const
s << QMetaType::typeName(userType());
}
- if (d.type == QVariant::Invalid) {
+ if (!isValid()) {
s << QString();
return;
}
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp
index a4a69c3..8887977 100644
--- a/src/gui/itemviews/qabstractitemview.cpp
+++ b/src/gui/itemviews/qabstractitemview.cpp
@@ -3918,7 +3918,7 @@ QPixmap QAbstractItemViewPrivate::renderToPixmap(const QModelIndexList &indexes,
QStyleOptionViewItemV4 option = viewOptionsV4();
option.state |= QStyle::State_Selected;
for (int j = 0; j < paintPairs.count(); ++j) {
- option.rect = paintPairs.at(j).first.translated(r->topLeft());
+ option.rect = paintPairs.at(j).first.translated(-r->topLeft());
const QModelIndex &current = paintPairs.at(j).second;
delegateForIndex(current)->paint(&painter, option, current);
}
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index 9a94b31..40f28d4 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -722,7 +722,6 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList
QRect &rect = *r;
const QRect viewportRect = viewport->rect();
QItemViewPaintPairs ret;
- intersectingSet(viewportRect);
const QSet<QModelIndex> visibleIndexes = intersectingSet(viewportRect).toList().toSet();
for (int i = 0; i < indexes.count(); ++i) {
const QModelIndex &index = indexes.at(i);
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index f13ff0c..7084e6d 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -1321,6 +1321,50 @@ void QTreeViewPrivate::_q_modelDestroyed()
}
/*!
+ \reimp
+
+ We have a QTreeView way of knowing what elements are on the viewport
+*/
+QItemViewPaintPairs QTreeViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
+{
+ Q_ASSERT(r);
+ return QAbstractItemViewPrivate::draggablePaintPairs(indexes, r);
+ Q_Q(const QTreeView);
+ QRect &rect = *r;
+ const QRect viewportRect = viewport->rect();
+ int itemOffset = 0;
+ int row = firstVisibleItem(&itemOffset);
+ QPair<int, int> startEnd = startAndEndColumns(viewportRect);
+ QVector<int> columns;
+ for (int i = startEnd.first; i <= startEnd.second; ++i) {
+ int logical = header->logicalIndex(i);
+ if (!header->isSectionHidden(logical))
+ columns += logical;
+ }
+ QSet<QModelIndex> visibleIndexes;
+ for (; itemOffset < viewportRect.bottom() && row < viewItems.count(); ++row) {
+ const QModelIndex &index = viewItems.at(row).index;
+ for (int colIndex = 0; colIndex < columns.count(); ++colIndex)
+ visibleIndexes += index.sibling(index.row(), columns.at(colIndex));
+ itemOffset += itemHeight(row);
+ }
+
+ //now that we have the visible indexes, we can try to find those which are selected
+ QItemViewPaintPairs ret;
+ for (int i = 0; i < indexes.count(); ++i) {
+ const QModelIndex &index = indexes.at(i);
+ if (visibleIndexes.contains(index)) {
+ const QRect current = q->visualRect(index);
+ ret += qMakePair(current, index);
+ rect |= current;
+ }
+ }
+ rect &= viewportRect;
+ return ret;
+}
+
+
+/*!
\since 4.2
Draws the part of the tree intersecting the given \a region using the specified
\a painter.
diff --git a/src/gui/itemviews/qtreeview_p.h b/src/gui/itemviews/qtreeview_p.h
index 6fb2e41..546dc75 100644
--- a/src/gui/itemviews/qtreeview_p.h
+++ b/src/gui/itemviews/qtreeview_p.h
@@ -89,6 +89,8 @@ public:
~QTreeViewPrivate() {}
void initialize();
+ QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
+
#ifndef QT_NO_ANIMATION
struct AnimatedOperation : public QVariantAnimation
{