From 01bfa0e868a0696b8382deb4dd3c0ef12b584835 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Wed, 18 Mar 2026 12:49:50 +0100 Subject: kitemlistview: cancel editing when animation starts For this widget. If a file is being moved due due to external events, an animation may start, in which case we better cancel the edit. If we hook this at the animation start instead of checks spread out, we can't miss this cancellation anymore. KStandardItemListWidget gets a cancelRoleEditing slot to cleanly cancel editing and clean up its internal state. --- src/kitemviews/kitemlistview.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/kitemviews/kitemlistview.cpp') diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index b780e3ff4..e828b6967 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -117,6 +117,7 @@ KItemListView::KItemListView(QGraphicsWidget *parent) m_animation = new KItemListViewAnimation(this); connect(m_animation, &KItemListViewAnimation::finished, this, &KItemListView::slotAnimationFinished); + connect(m_animation, &KItemListViewAnimation::start, this, &KItemListView::slotAnimationStarted); m_rubberBand = new KItemListRubberBand(this); connect(m_rubberBand, &KItemListRubberBand::activationChanged, this, &KItemListView::slotRubberBandActivationChanged); @@ -758,8 +759,7 @@ void KItemListView::editRole(int index, const QByteArray &role) if (!widget) { return; } - if (m_editingRole || m_animation->isStarted(widget)) { - Q_EMIT widget->roleEditingCanceled(index, role, QVariant()); + if (widget->editedRole() == role) { return; } @@ -1577,6 +1577,13 @@ void KItemListView::slotSelectionChanged(const KItemSet ¤t, const KItemSet #endif } +void KItemListView::slotAnimationStarted(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType /* type */, const QVariant & /* endValue */) +{ + KStandardItemListWidget *listWidget = qobject_cast(widget); + Q_ASSERT(widget); + listWidget->cancelRoleEditing(); +} + void KItemListView::slotAnimationFinished(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType type) { KItemListWidget *itemListWidget = qobject_cast(widget); @@ -1926,9 +1933,6 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha if (animate) { if (m_animation->isStarted(widget, KItemListViewAnimation::MovingAnimation)) { - if (m_editingRole) { - Q_EMIT widget->roleEditingCanceled(widget->index(), QByteArray(), QVariant()); - } m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos); applyNewPos = false; } @@ -2804,7 +2808,7 @@ bool KItemListView::hasSiblingSuccessor(int index) const void KItemListView::disconnectRoleEditingSignals(int index) { - KStandardItemListWidget *widget = qobject_cast(m_visibleItems.value(index)); + KItemListWidget *widget = m_visibleItems.value(index); if (!widget) { return; } -- cgit v1.3