summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qitemdelegate
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/itemviews/qitemdelegate')
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST4
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/CMakeLists.txt2
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp85
3 files changed, 79 insertions, 12 deletions
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST b/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST
index 5eda888af6..21cfa7cd0f 100644
--- a/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST
+++ b/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST
@@ -1,6 +1,2 @@
-[enterKey]
-opensuse-42.3 ci
-[testLineEditValidation]
-opensuse-42.3 ci
[editorKeyPress]
ubuntu-20.04
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/CMakeLists.txt b/tests/auto/widgets/itemviews/qitemdelegate/CMakeLists.txt
index 575cd4996b..5b4ec3b04a 100644
--- a/tests/auto/widgets/itemviews/qitemdelegate/CMakeLists.txt
+++ b/tests/auto/widgets/itemviews/qitemdelegate/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+# SPDX-License-Identifier: BSD-3-Clause
# Generated from qitemdelegate.pro.
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
index 68a7268473..4a694ee070 100644
--- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
@@ -34,6 +34,7 @@
#include <qscreen.h>
#include <QtWidgets/private/qabstractitemdelegate_p.h>
+#include <QtWidgets/private/qapplication_p.h>
Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint)
@@ -205,6 +206,8 @@ private slots:
void dateTextForRole_data();
void dateTextForRole();
+ void reuseEditor();
+
private:
#ifdef QT_BUILD_INTERNAL
struct RoleDelegate : public QItemDelegate
@@ -743,7 +746,7 @@ void tst_QItemDelegate::dateTimeEditor()
widget.setItem(0, 2, item3);
widget.show();
QVERIFY(QTest::qWaitForWindowExposed(&widget));
- QApplication::setActiveWindow(&widget);
+ QApplicationPrivate::setActiveWindow(&widget);
widget.editItem(item1);
@@ -759,7 +762,7 @@ void tst_QItemDelegate::dateTimeEditor()
timeEditor->setTime(time.addSecs(60));
widget.clearFocus();
- qApp->setActiveWindow(&widget);
+ QApplicationPrivate::setActiveWindow(&widget);
widget.setFocus();
widget.editItem(item2);
@@ -1023,7 +1026,7 @@ void tst_QItemDelegate::decoration()
TestItemDelegate delegate;
table.setItemDelegate(&delegate);
table.show();
- QApplication::setActiveWindow(&table);
+ QApplicationPrivate::setActiveWindow(&table);
QVERIFY(QTest::qWaitForWindowActive(&table));
QVariant value;
@@ -1278,7 +1281,7 @@ void tst_QItemDelegate::enterKey()
QListView view;
view.setModel(&model);
view.show();
- QApplication::setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
view.setFocus();
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -1338,7 +1341,7 @@ void tst_QItemDelegate::task257859_finalizeEdit()
QListView view;
view.setModel(&model);
view.show();
- QApplication::setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
view.setFocus();
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -1400,7 +1403,7 @@ void tst_QItemDelegate::comboBox()
widget.setItem(0, 0, item1);
widget.show();
QVERIFY(QTest::qWaitForWindowExposed(&widget));
- QApplication::setActiveWindow(&widget);
+ QApplicationPrivate::setActiveWindow(&widget);
widget.editItem(item1);
@@ -1465,7 +1468,7 @@ void tst_QItemDelegate::testLineEditValidation()
view.setItemDelegate(&delegate);
view.show();
view.setFocus();
- QApplication::setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
QPointer<QLineEdit> editor;
@@ -1617,6 +1620,74 @@ void tst_QItemDelegate::dateTextForRole()
#endif
}
+void tst_QItemDelegate::reuseEditor()
+{
+ class ReusingDelegate: public QItemDelegate {
+ public:
+ using QItemDelegate::QItemDelegate;
+ ~ReusingDelegate()
+ {
+ cached->deleteLater();
+ }
+
+ QWidget* createEditor(QWidget* parent,
+ const QStyleOptionViewItem&,
+ const QModelIndex&) const override
+ {
+ auto *cb = new QComboBox(parent);
+ cb->addItem("One");
+ cb->addItem("Two");
+ cb->setEditable(true);
+ return cb;
+ }
+
+ void setEditorData(QWidget* editor, const QModelIndex& index)
+ const override
+ {
+ auto *cb = qobject_cast<QComboBox*>(editor);
+ cb->setCurrentText(index.data(Qt::DisplayRole).toString());
+ }
+
+ void setModelData(QWidget* editor,
+ QAbstractItemModel* model,
+ const QModelIndex& index) const override
+ {
+ auto *cb = qobject_cast<QComboBox*>(editor);
+ model->setData(index, cb->currentText(), Qt::DisplayRole);
+ }
+
+ void destroyEditor(QWidget* editor, const QModelIndex&) const override
+ {
+ auto *cb = qobject_cast<QComboBox*>(editor);
+ cb->setParent(nullptr); // How to completely detach the editor from treeview ?
+ cb->hide();
+ cb->setEnabled(false);
+ cached = cb;
+ }
+
+ private:
+ mutable QComboBox* cached = nullptr;
+ };
+
+ QStandardItemModel model;
+ model.appendRow(new QStandardItem("One"));
+ model.appendRow(new QStandardItem("Two"));
+
+ ReusingDelegate delegate;
+
+ QTreeView tree;
+ tree.setModel(&model);
+ tree.setItemDelegate(&delegate);
+
+ tree.show();
+ QVERIFY(QTest::qWaitForWindowActive(&tree));
+
+ tree.edit(model.index(0, 0));
+ QTRY_VERIFY(qobject_cast<QComboBox *>(tree.focusWidget()));
+
+ tree.close();
+}
+
// ### _not_ covered:
// editing with a custom editor factory