Fix build with -no-feature-draganddrop

Pick-to: 6.5
Change-Id: I88ecd9a84d7fb9f6cb78027cc51e34089e211ff2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Tasuku Suzuki 2023-01-16 01:09:58 +09:00
parent 1613975d95
commit 010a898771
3 changed files with 27 additions and 5 deletions

View File

@ -1793,9 +1793,11 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event)
QPoint offset = d->offset();
d->draggedPosition = pos + offset;
#if QT_CONFIG(draganddrop)
// update the pressed position when drag was enable
if (d->dragEnabled)
d->pressedPosition = d->draggedPosition;
#endif
if (!(command & QItemSelectionModel::Current)) {
d->pressedPosition = pos + offset;
@ -4127,13 +4129,21 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionComm
case QEvent::MouseButtonPress:
if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) {
// since the press might start a drag, deselect only on release
if (!pressedAlreadySelected || !dragEnabled || !isIndexDragEnabled(index))
if (!pressedAlreadySelected
#if QT_CONFIG(draganddrop)
|| !dragEnabled || !isIndexDragEnabled(index)
#endif
)
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle
}
break;
case QEvent::MouseButtonRelease:
if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) {
if (pressedAlreadySelected && dragEnabled && isIndexDragEnabled(index) && index == pressedIndex)
if (pressedAlreadySelected
#if QT_CONFIG(draganddrop)
&& dragEnabled && isIndexDragEnabled(index)
#endif
&& index == pressedIndex)
return QItemSelectionModel::Toggle|selectionBehaviorFlags();
return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); // finalize
}
@ -4181,7 +4191,10 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionC
return QItemSelectionModel::NoUpdate;
// since the press might start a drag, deselect only on release
if (controlKeyPressed && !rightButtonPressed && pressedAlreadySelected
&& dragEnabled && isIndexDragEnabled(index)) {
#if QT_CONFIG(draganddrop)
&& dragEnabled && isIndexDragEnabled(index)
#endif
) {
return QItemSelectionModel::NoUpdate;
}
break;
@ -4197,7 +4210,10 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionC
&& !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid()))
return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags();
if (index == pressedIndex && controlKeyPressed && !rightButtonPressed
&& dragEnabled && isIndexDragEnabled(index)) {
#if QT_CONFIG(draganddrop)
&& dragEnabled && isIndexDragEnabled(index)
#endif
) {
break;
}
return QItemSelectionModel::NoUpdate;
@ -4661,6 +4677,7 @@ void QAbstractItemViewPrivate::selectAll(QItemSelectionModel::SelectionFlags com
selectionModel->select(selection, command);
}
#if QT_CONFIG(draganddrop)
QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const
{
Q_Q(const QAbstractItemView);
@ -4671,6 +4688,7 @@ QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const
indexes.removeIf(isNotDragEnabled);
return indexes;
}
#endif
/*!
\reimp

View File

@ -252,12 +252,14 @@ public:
inline bool isIndexEnabled(const QModelIndex &index) const {
return (model->flags(index) & Qt::ItemIsEnabled);
}
#if QT_CONFIG(draganddrop)
inline bool isIndexDropEnabled(const QModelIndex &index) const {
return (model->flags(index) & Qt::ItemIsDropEnabled);
}
inline bool isIndexDragEnabled(const QModelIndex &index) const {
return (model->flags(index) & Qt::ItemIsDragEnabled);
}
#endif
virtual bool selectionAllowed(const QModelIndex &index) const {
// in some views we want to go ahead with selections, even if the index is invalid
@ -304,7 +306,9 @@ public:
return static_cast<QAbstractItemModelPrivate *>(model->d_ptr.data())->persistent.indexes.contains(index);
}
#if QT_CONFIG(draganddrop)
QModelIndexList selectedDraggableIndexes() const;
#endif
void doDelayedReset()
{

View File

@ -3045,8 +3045,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
)
QDragManager::self()->setCurrentTarget(nullptr, e->type() == QEvent::Drop);
break;
#endif
}
#endif // QT_CONFIG(draganddrop)
case QEvent::TouchBegin: {
// Note: TouchUpdate and TouchEnd events are never propagated
QMutableTouchEvent *touchEvent = QMutableTouchEvent::from(static_cast<QTouchEvent *>(e));