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: Ic7053d68d8200f845c1ae330342d27af7275e057 Reviewed-by: Tarja Sundqvist <tarja.sundqvist@digia.com> Reviewed-by: David Faure <faure@kde.org>bb10
parent
62932faef0
commit
99a620d2e2
|
|
@ -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<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;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
return QAbstractItemViewPrivate::draggablePaintPairs(list, r);
|
||||
}
|
||||
|
||||
void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, const QModelIndex ¤t) const
|
||||
|
|
|
|||
|
|
@ -210,6 +210,8 @@ private slots:
|
|||
void indexRowSizeHint();
|
||||
void addRowsWhileSectionsAreHidden();
|
||||
void filterProxyModelCrash();
|
||||
void renderToPixmap_data();
|
||||
void renderToPixmap();
|
||||
void styleOptionViewItem();
|
||||
void keyboardNavigationWithDisabled();
|
||||
|
||||
|
|
@ -2890,6 +2892,37 @@ void tst_QTreeView::filterProxyModelCrash()
|
|||
view.repaint(); //used to crash
|
||||
}
|
||||
|
||||
void tst_QTreeView::renderToPixmap_data()
|
||||
{
|
||||
QTest::addColumn<int>("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<QStandardItem*>() << 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue