summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qabstractitemview.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-04-26 00:14:29 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-04-27 05:34:29 +0200
commit6625a4744ee3b5441d7ebc07e5722df86415c809 (patch)
treea64d05550f458642a7a381f5b5a6fd38af1ec6bd /src/widgets/itemviews/qabstractitemview.cpp
parentf02879a97a6e7587a7e116f85d6a153f616a5d3f (diff)
QAbstractItemView: warn in some erroneous conditions
If a user or a delegate asks a view to act on an editor that does not belong to the view, report a warning instead of silently ignoring the problem. This erroneous condition can happen for instance if a user installs the same delegate on multiple views (something that the documentation says _not_ to do) and the delegate indeed emits signals related to the editors of one view -- the other views don't know about that editor. Change-Id: I2d10582ebb7aefca4acea306b8a57bcc3162050a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/itemviews/qabstractitemview.cpp')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index a4dee5e48c..b2f18d134e 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -2936,8 +2936,10 @@ void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndE
bool isPersistent = d->persistent.contains(editor);
bool hadFocus = editor->hasFocus();
QModelIndex index = d->indexForEditor(editor);
- if (!index.isValid())
+ if (!index.isValid()) {
+ qWarning("QAbstractItemView::closeEditor called with an editor that does not belong to this view");
return; // the editor was not registered
+ }
// start a timer that expires immediately when we return to the event loop
// to identify whether this close was triggered by a mousepress-initiated
@@ -3015,8 +3017,10 @@ void QAbstractItemView::commitData(QWidget *editor)
if (!editor || !d->itemDelegate || d->currentlyCommittingEditor)
return;
QModelIndex index = d->indexForEditor(editor);
- if (!index.isValid())
+ if (!index.isValid()) {
+ qWarning("QAbstractItemView::commitData called with an editor that does not belong to this view");
return;
+ }
d->currentlyCommittingEditor = editor;
QAbstractItemDelegate *delegate = itemDelegateForIndex(index);
editor->removeEventFilter(delegate);