QAbstractItemView: implement full-row drop indicator

When the selection behavior is SelectRows, we're dragging full rows,
so it was very weird that the drop indicator was showing a single
column. Instead, expand the drop indicator over all columns.

This is typically for QTreeView but it also works for a QTableView where
a single row represents a single underlying object (otherwise, why use
SelectRows?).

Since we're testing the selection behavior of the drop side, not
the drag side, only do this when inserting rows, or (for OnItem) when
they're the same widget.
There's a use case for dropping single properties (from a different widget)
onto specific columns of full-row objects (there's also a use case for
overwriting the whole object but we can't know which one it will be...).

Fixes: QTBUG-1656
Change-Id: Idde0f4f8592970339f19dcc11ba667cf12677438
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit a818326985295ba1cf1b31043b24e9f089b1d834)
This commit is contained in:
David Faure 2024-08-09 18:34:11 +02:00
parent 4bda9b977e
commit 52c908fdb5

View File

@ -2074,6 +2074,13 @@ void QAbstractItemView::dragMoveEvent(QDragMoveEvent *event)
if (index.isValid() && d->showDropIndicator) {
QRect rect = visualRect(index);
d->dropIndicatorPosition = d->position(event->position().toPoint(), rect, index);
if (d->selectionBehavior == QAbstractItemView::SelectRows
&& d->dropIndicatorPosition != OnViewport
&& (d->dropIndicatorPosition != OnItem || event->source() == this)) {
if (index.column() > 0)
rect = visualRect(index.siblingAtColumn(0));
rect.setWidth(viewport()->width() - 1 - rect.x());
}
switch (d->dropIndicatorPosition) {
case AboveItem:
if (d->isIndexDropEnabled(index.parent())) {