summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@edeltech.ch>2016-08-29 09:59:46 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-02-07 09:09:42 +0000
commit8b1d9d308b1f31e1b9c817e0d91e14baa3b76d6b (patch)
tree543808bd6248fcd83856aed02efe27018efaaa2b /tests
parentd0b8356e7efcb546bf8838b01b94840e4c0d3ab3 (diff)
Fix result handling in QDialog::done
The setData method of an item view would get an incorrect value of a QDialog's result. This patch changes the order of functions called to fix that. [ChangeLog][QtWidgets][QDialog] Fixed a bug where accessing the result of QDialog's result could yield an incorrect value in some situation like using it as a delegate for item views. Task-number: QTBUG-6018 Task-number: QTBUG-12156 Task-number: QTBUG-14430 Change-Id: I6ee4b6e8cacf6a806631c05c6c5dbcff925df65e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index 426db265ae..d241296a6b 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -52,6 +52,7 @@
#include <qstringlistmodel.h>
#include <qsortfilterproxymodel.h>
#include <qproxystyle.h>
+#include <qdialog.h>
static inline void setFrameless(QWidget *w)
{
@@ -149,6 +150,7 @@ private slots:
void QTBUG50535_update_on_new_selection_model();
void testSelectionModelInSyncWithView();
void testClickToSelect();
+ void testDialogAsEditor();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -173,6 +175,29 @@ public:
QSize size;
};
+class DialogItemDelegate : public QStyledItemDelegate
+{
+public:
+ DialogItemDelegate() : QStyledItemDelegate() { }
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
+ {
+ openedEditor = new QDialog(parent);
+ return openedEditor;
+ }
+
+ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+ {
+ Q_UNUSED(model)
+ Q_UNUSED(index)
+
+ QDialog *dialog = qobject_cast<QDialog *>(editor);
+ result = static_cast<QDialog::DialogCode>(dialog->result());
+ }
+
+ mutable QDialog::DialogCode result;
+ mutable QDialog *openedEditor;
+};
+
// Testing get/set functions
void tst_QAbstractItemView::getSetCheck()
{
@@ -2156,5 +2181,37 @@ void tst_QAbstractItemView::testClickToSelect()
QCOMPARE(spy.back().front().value<QRect>(), QRect(nearCenterA, QSize(1, 1)));
}
+void tst_QAbstractItemView::testDialogAsEditor()
+{
+ DialogItemDelegate delegate;
+
+ QStandardItemModel model;
+ model.appendRow(new QStandardItem(QStringLiteral("editme")));
+
+ QListView view;
+ view.setItemDelegate(&delegate);
+ view.setModel(&model);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ view.edit(model.index(0,0));
+
+ QVERIFY(QTest::qWaitForWindowExposed(delegate.openedEditor));
+
+ delegate.openedEditor->reject();
+ QApplication::processEvents();
+
+ QCOMPARE(delegate.result, QDialog::Rejected);
+
+ view.edit(model.index(0,0));
+
+ QVERIFY(QTest::qWaitForWindowExposed(delegate.openedEditor));
+
+ delegate.openedEditor->accept();
+ QApplication::processEvents();
+
+ QCOMPARE(delegate.result, QDialog::Accepted);
+}
+
QTEST_MAIN(tst_QAbstractItemView)
#include "tst_qabstractitemview.moc"