summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp81
1 files changed, 78 insertions, 3 deletions
diff --git a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
index 2c3fdb1baa..4e2dbd4de4 100644
--- a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
+++ b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
@@ -30,14 +30,22 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
-#include <QtTest/QtTest>
+#include <QDataWidgetMapper>
+#include <QStandardItemModel>
+#include <QLineEdit>
+#include <QComboBox>
+#include <QTextEdit>
+#include <QVBoxLayout>
+#include <QTest>
+#include <QSignalSpy>
+#include <QMetaType>
class tst_QDataWidgetMapper: public QObject
{
Q_OBJECT
private slots:
+ void initTestCase();
+
void setModel();
void navigate();
void addMapping();
@@ -47,8 +55,12 @@ private slots:
void mappedWidgetAt();
void comboBox();
+
+ void textEditDoesntChangeFocusOnTab_qtbug3305();
};
+Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint)
+
static QStandardItemModel *testModel(QObject *parent = 0)
{
QStandardItemModel *model = new QStandardItemModel(10, 10, parent);
@@ -61,6 +73,11 @@ static QStandardItemModel *testModel(QObject *parent = 0)
return model;
}
+void tst_QDataWidgetMapper::initTestCase()
+{
+ qRegisterMetaType<QAbstractItemDelegate::EndEditHint>();
+}
+
void tst_QDataWidgetMapper::setModel()
{
QDataWidgetMapper mapper;
@@ -400,5 +417,63 @@ void tst_QDataWidgetMapper::mappedWidgetAt()
QCOMPARE(mapper.mappedWidgetAt(4242), static_cast<QWidget *>(&lineEdit2));
}
+void tst_QDataWidgetMapper::textEditDoesntChangeFocusOnTab_qtbug3305()
+{
+ QDataWidgetMapper mapper;
+ QAbstractItemModel *model = testModel(&mapper);
+ mapper.setModel(model);
+
+ QSignalSpy closeEditorSpy(mapper.itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)));
+ QVERIFY(closeEditorSpy.isValid());
+
+ QWidget container;
+ container.setLayout(new QVBoxLayout);
+
+ QLineEdit *lineEdit = new QLineEdit;
+ mapper.addMapping(lineEdit, 0);
+ container.layout()->addWidget(lineEdit);
+
+ QTextEdit *textEdit = new QTextEdit;
+ mapper.addMapping(textEdit, 1);
+ container.layout()->addWidget(textEdit);
+
+ lineEdit->setFocus();
+
+ container.show();
+
+ QApplication::setActiveWindow(&container);
+ QVERIFY(QTest::qWaitForWindowActive(&container));
+
+ int closeEditorSpyCount = 0;
+ const QString textEditContents = textEdit->toPlainText();
+
+ QCOMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+ QVERIFY(lineEdit->hasFocus());
+ QVERIFY(!textEdit->hasFocus());
+
+ // this will generate a closeEditor for the tab key, and another for the focus out
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_Tab);
+ closeEditorSpyCount += 2;
+ QTRY_COMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+
+ QTRY_VERIFY(textEdit->hasFocus());
+ QVERIFY(!lineEdit->hasFocus());
+
+ // now that the text edit is focused, a tab keypress will insert a tab, not change focus
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_Tab);
+ QTRY_COMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+
+ QVERIFY(!lineEdit->hasFocus());
+ QVERIFY(textEdit->hasFocus());
+ QCOMPARE(textEdit->toPlainText(), QLatin1Char('\t') + textEditContents);
+
+ // now give focus back to the line edit and check closeEditor gets emitted
+ lineEdit->setFocus();
+ QTRY_VERIFY(lineEdit->hasFocus());
+ QVERIFY(!textEdit->hasFocus());
+ ++closeEditorSpyCount;
+ QCOMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+}
+
QTEST_MAIN(tst_QDataWidgetMapper)
#include "tst_qdatawidgetmapper.moc"