From 96f0449f6e7b9c3f35fb7c546b6bbdb633d1a7bc Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 17 Apr 2012 19:47:37 +0200 Subject: Take account of spanned items in QTreeView when dragging. Also remove some code which has been unused since it was introduced in 32182d107fa75e5619ecc91a81f50626f429ebe1 Task-number: QTBUG-25140 Change-Id: I27f9496c2c998de7ea858b943c2f19d979ef18c2 Reviewed-by: David Faure --- src/gui/itemviews/qtreeview.cpp | 41 ++++++++-------------------------- tests/auto/qtreeview/tst_qtreeview.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 4006601..1a8a686 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1343,39 +1343,16 @@ void QTreeViewPrivate::_q_modelDestroyed() 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 startEnd = startAndEndColumns(viewportRect); - QVector columns; - for (int i = startEnd.first; i <= startEnd.second; ++i) { - int logical = header->logicalIndex(i); - if (!header->isSectionHidden(logical)) - columns += logical; - } - QSet 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; + if (spanningIndexes.isEmpty()) + return QAbstractItemViewPrivate::draggablePaintPairs(indexes, r); + QModelIndexList list; + foreach (const QModelIndex &idx, indexes) { + if (idx.column() > 0 && q->isFirstColumnSpanned(idx.row(), idx.parent())) + continue; + list << idx; + } + return QAbstractItemViewPrivate::draggablePaintPairs(list, r); } void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, const QModelIndex ¤t) const diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 05b2e3c..c0747a8 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -216,6 +216,8 @@ private slots: void indexRowSizeHint(); void addRowsWhileSectionsAreHidden(); void filterProxyModelCrash(); + void renderToPixmap_data(); + void renderToPixmap(); void styleOptionViewItem(); void keyboardNavigationWithDisabled(); @@ -2901,6 +2903,37 @@ void tst_QTreeView::filterProxyModelCrash() view.repaint(); //used to crash } +void tst_QTreeView::renderToPixmap_data() +{ + QTest::addColumn("row"); + QTest::newRow("row-0") << 0; + QTest::newRow("row-1") << 1; +} + +void tst_QTreeView::renderToPixmap() +{ + QFETCH(int, row); + PublicView view; + QStandardItemModel model; + + model.appendRow(new QStandardItem("Spanning")); + model.appendRow(QList() << new QStandardItem("Not") << new QStandardItem("Spanning")); + + view.setModel(&model); + view.setFirstColumnSpanned(0, QModelIndex(), true); + +#ifdef QT_BUILD_INTERNAL + { + // We select the index at row=0 because it spans the + // column (regression test for an assert) + // We select the index at row=1 for coverage. + QItemSelection sel(model.index(row,0), model.index(row,1)); + QRect rect; + view.aiv_priv()->renderToPixmap(sel.indexes(), &rect); + } +#endif +} + void tst_QTreeView::styleOptionViewItem() { class MyDelegate : public QStyledItemDelegate -- cgit v0.12