diff options
-rw-r--r-- | src/widgets/itemviews/qitemdelegate.cpp | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qstyleditemdelegate.cpp | 4 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp | 31 |
3 files changed, 31 insertions, 8 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 6c62378009..bd9f4510f7 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -551,13 +551,9 @@ void QItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con Q_UNUSED(editor); Q_UNUSED(index); #else - Q_D(const QItemDelegate); QVariant v = index.data(Qt::EditRole); QByteArray n = editor->metaObject()->userProperty().name(); - // ### Qt 5: give QComboBox a USER property - if (n.isEmpty() && editor->inherits("QComboBox")) - n = d->editorFactory()->valuePropertyName(v.userType()); if (!n.isEmpty()) { if (!v.isValid()) v = QVariant(editor->property(n).userType(), (const void *)0); diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index b27dcb0a7b..119692531f 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -488,13 +488,9 @@ void QStyledItemDelegate::setEditorData(QWidget *editor, const QModelIndex &inde Q_UNUSED(editor); Q_UNUSED(index); #else - Q_D(const QStyledItemDelegate); QVariant v = index.data(Qt::EditRole); QByteArray n = editor->metaObject()->userProperty().name(); - // ### Qt 5: give QComboBox a USER property - if (n.isEmpty() && editor->inherits("QComboBox")) - n = d->editorFactory()->valuePropertyName(v.userType()); if (!n.isEmpty()) { if (!v.isValid()) v = QVariant(editor->property(n).userType(), (const void *)0); diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 497cdfdeee..2ee166c4a2 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -58,6 +58,7 @@ #include <qtreewidget.h> #include <QItemDelegate> +#include <QComboBox> #include <QAbstractItemDelegate> #include <QTextEdit> #include <QPlainTextEdit> @@ -228,6 +229,7 @@ private slots: void editorEvent(); void enterKey_data(); void enterKey(); + void comboBox(); void task257859_finalizeEdit(); void QTBUG4435_keepSelectionOnCheck(); @@ -1205,6 +1207,35 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck() QCOMPARE(model.item(0)->checkState(), Qt::Checked); } +void tst_QItemDelegate::comboBox() +{ + QTableWidgetItem *item1 = new QTableWidgetItem; + item1->setData(Qt::DisplayRole, true); + + QTableWidget widget(1, 1); + widget.setItem(0, 0, item1); + widget.show(); + + widget.editItem(item1); + + QTestEventLoop::instance().enterLoop(1); + + QComboBox *boolEditor = qFindChild<QComboBox*>(widget.viewport()); + QVERIFY(boolEditor); + QCOMPARE(boolEditor->currentIndex(), 1); // True is selected initially. + // The data must actually be different in order for the model + // to be updated. + boolEditor->setCurrentIndex(0); + QCOMPARE(boolEditor->currentIndex(), 0); // Changed to false. + + widget.clearFocus(); + widget.setFocus(); + + QVariant data = item1->data(Qt::EditRole); + QCOMPARE(data.userType(), (int)QMetaType::Bool); + QCOMPARE(data.toBool(), false); +} + // ### _not_ covered: |