From 8e01aa83880bf9cc669106f1e219abd3b3fca186 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 4 Aug 2009 20:06:04 +0200 Subject: Fixed bug where Q[Styled]ItemDelegate edition wouldn't terminate when the item lost focus to an unrelated dialog. The tests against the active modal window was unnecessary. Task-number: 257859 Reviewed-by: olivier --- src/gui/itemviews/qitemdelegate.cpp | 7 +----- src/gui/itemviews/qstyleditemdelegate.cpp | 8 +------ tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 33 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp index aff715c..962ce54 100644 --- a/src/gui/itemviews/qitemdelegate.cpp +++ b/src/gui/itemviews/qitemdelegate.cpp @@ -1238,12 +1238,7 @@ bool QItemDelegate::eventFilter(QObject *object, QEvent *event) if (QDragManager::self() && QDragManager::self()->object != 0) return false; #endif - // Opening a modal dialog will start a new eventloop - // that will process the deleteLater event. - if (QApplication::activeModalWidget() - && !QApplication::activeModalWidget()->isAncestorOf(editor) - && qobject_cast(QApplication::activeModalWidget())) - return false; + emit commitData(editor); emit closeEditor(editor, NoHint); } diff --git a/src/gui/itemviews/qstyleditemdelegate.cpp b/src/gui/itemviews/qstyleditemdelegate.cpp index 7ec2afe..8faf0be 100644 --- a/src/gui/itemviews/qstyleditemdelegate.cpp +++ b/src/gui/itemviews/qstyleditemdelegate.cpp @@ -686,13 +686,7 @@ bool QStyledItemDelegate::eventFilter(QObject *object, QEvent *event) if (QDragManager::self() && QDragManager::self()->object != 0) return false; #endif - // Opening a modal dialog will start a new eventloop - // that will process the deleteLater event. - QWidget *activeModalWidget = QApplication::activeModalWidget(); - if (activeModalWidget - && !activeModalWidget->isAncestorOf(editor) - && qobject_cast(activeModalWidget)) - return false; + emit commitData(editor); emit closeEditor(editor, NoHint); } diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 65dd86f..6714de3 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -61,6 +61,7 @@ #include #include #include +#include Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) @@ -230,6 +231,8 @@ private slots: void editorEvent(); void enterKey_data(); void enterKey(); + + void task257859_finalizeEdit(); }; @@ -1124,6 +1127,36 @@ void tst_QItemDelegate::enterKey() QCOMPARE(editor && editor->hasFocus(), expectedFocus); } +void tst_QItemDelegate::task257859_finalizeEdit() +{ + QStandardItemModel model; + model.appendRow(new QStandardItem()); + + QListView view; + view.setModel(&model); + view.show(); + QApplication::setActiveWindow(&view); + view.setFocus(); + QTest::qWait(30); + + QModelIndex index = model.index(0, 0); + view.edit(index); + QTest::qWait(30); + + QList lineEditors = qFindChildren(view.viewport()); + QCOMPARE(lineEditors.count(), 1); + + QPointer editor = lineEditors.at(0); + QCOMPARE(editor->hasFocus(), true); + + QDialog dialog; + QTimer::singleShot(100, &dialog, SLOT(close())); + dialog.exec(); + + QTest::qWait(10); + + QVERIFY(!editor); +} // ### _not_ covered: -- cgit v0.12