diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-11-25 01:00:25 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-11-25 11:30:04 +0100 |
commit | 58c69df4d38324644bc49ec5f42ee8343a454b2d (patch) | |
tree | de0a1ce603292dcaff134d4e1e8ab064295515a2 /tests/auto/widgets/itemviews | |
parent | 03b1d2c44940322208c12c7bceee376b51d8e852 (diff) | |
parent | 59a705e3710b0ba93bb698e3223241cfac932948 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/corelib/tools/qhash.h
src/gui/kernel/qevent.h
src/widgets/kernel/qshortcut.cpp
src/widgets/kernel/qshortcut.h
Change-Id: If61c206ee43ad1d97f5b07f58ac93c4583ce5620
Diffstat (limited to 'tests/auto/widgets/itemviews')
5 files changed, 69 insertions, 4 deletions
diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp index 5097f2e356..546b2ab3a8 100644 --- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp +++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp @@ -697,7 +697,7 @@ void tst_QDirModel::roleNames_data() { QTest::addColumn<int>("role"); QTest::addColumn<QByteArray>("roleName"); - QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("decoration"); + QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("fileIcon"); QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display"); QTest::newRow("fileIcon") << int(QDirModel::FileIconRole) << QByteArray("fileIcon"); QTest::newRow("filePath") << int(QDirModel::FilePathRole) << QByteArray("filePath"); @@ -713,8 +713,8 @@ void tst_QDirModel::roleNames() QVERIFY(roles.contains(role)); QFETCH(QByteArray, roleName); - QList<QByteArray> values = roles.values(role); - QVERIFY(values.contains(roleName)); + QCOMPARE(roles.values(role).count(), 1); + QCOMPARE(roles.value(role), roleName); } diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index cb083fdcbe..dcb932de66 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -1512,6 +1512,20 @@ void tst_QListWidget::itemData() QCOMPARE(flags.count(), 6); for (int i = 0; i < 4; ++i) QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1)); + + item.setBackground(QBrush(Qt::red)); + item.setForeground(QBrush(Qt::red)); + item.setSizeHint(QSize(10, 10)); + QCOMPARE(item.data(Qt::BackgroundRole), QVariant(QBrush(Qt::red))); + QCOMPARE(item.data(Qt::ForegroundRole), QVariant(QBrush(Qt::red))); + QCOMPARE(item.data(Qt::SizeHintRole), QVariant(QSize(10, 10))); + // an empty brush should result in a QVariant() + item.setBackground(QBrush()); + item.setForeground(QBrush()); + item.setSizeHint(QSize()); + QCOMPARE(item.data(Qt::BackgroundRole), QVariant()); + QCOMPARE(item.data(Qt::ForegroundRole), QVariant()); + QCOMPARE(item.data(Qt::SizeHintRole), QVariant()); } void tst_QListWidget::changeDataWithSorting() diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index f640996690..38dae7743f 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -1404,9 +1404,17 @@ void tst_QTableWidget::setItemData() QCOMPARE(table.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole, Qt::ToolTipRole})); QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("Display")); + QCOMPARE(table.model()->data(idx, Qt::EditRole).toString(), QLatin1String("Display")); QCOMPARE(table.model()->data(idx, Qt::ToolTipRole).toString(), QLatin1String("ToolTip")); QCOMPARE(dataChangedSpy.count(), 1); - QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.takeFirst().at(0))); + QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.first().at(0))); + QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.first().at(1))); + const auto roles = qvariant_cast<QVector<int>>(dataChangedSpy.first().at(2)); + QCOMPARE(roles.size(), 3); + QVERIFY(roles.contains(Qt::DisplayRole)); + QVERIFY(roles.contains(Qt::EditRole)); + QVERIFY(roles.contains(Qt::ToolTipRole)); + dataChangedSpy.clear(); table.model()->setItemData(idx, data); QCOMPARE(dataChangedSpy.count(), 0); @@ -1416,6 +1424,21 @@ void tst_QTableWidget::setItemData() table.model()->setItemData(idx, data); QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("dizplaye")); QCOMPARE(dataChangedSpy.count(), 1); + QCOMPARE(QVector<int>({Qt::DisplayRole, Qt::EditRole}), qvariant_cast<QVector<int>>(dataChangedSpy.first().at(2))); + + item->setBackground(QBrush(Qt::red)); + item->setForeground(QBrush(Qt::green)); + item->setSizeHint(QSize(10, 10)); + QCOMPARE(item->data(Qt::BackgroundRole), QVariant(QBrush(Qt::red))); + QCOMPARE(item->data(Qt::ForegroundRole), QVariant(QBrush(Qt::green))); + QCOMPARE(item->data(Qt::SizeHintRole), QVariant(QSize(10, 10))); + // an empty brush should result in a QVariant() + item->setBackground(QBrush()); + item->setForeground(QBrush()); + item->setSizeHint(QSize()); + QCOMPARE(item->data(Qt::BackgroundRole), QVariant()); + QCOMPARE(item->data(Qt::ForegroundRole), QVariant()); + QCOMPARE(item->data(Qt::SizeHintRole), QVariant()); } void tst_QTableWidget::cellWidget() diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index dcffe8043b..9750a31824 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -2868,6 +2868,7 @@ public: }; Node *root; + bool crash = false; EvilModel(QObject *parent = nullptr): QAbstractItemModel(parent), root(new Node) {} @@ -2876,6 +2877,11 @@ public: delete root; } + void setCrash() + { + crash = true; + } + void change() { emit layoutAboutToBeChanged(); @@ -2944,6 +2950,10 @@ public: QVariant data(const QModelIndex &idx, int role) const override { + if (crash) { + QTest::qFail("Should not get here...", __FILE__, __LINE__); + return QVariant(); + } if (idx.isValid() && role == Qt::DisplayRole) { Node *parentNode = root; if (idx.isValid()) { @@ -2963,6 +2973,7 @@ void tst_QTreeView::evilModel_data() { QTest::addColumn<bool>("visible"); QTest::newRow("visible") << false; + QTest::newRow("visible") << true; } void tst_QTreeView::evilModel() @@ -3132,6 +3143,9 @@ void tst_QTreeView::evilModel() model.change(); view.setRootIndex(secondLevel); + + model.setCrash(); + view.setModel(nullptr); } void tst_QTreeView::indexRowSizeHint() diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 2118bb5a29..7da56ab797 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1994,6 +1994,20 @@ void tst_QTreeWidget::itemData() QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1)); flags = widget.model()->itemData(widget.model()->index(0, 1)); QCOMPARE(flags.count(), 0); + + item.setBackground(0, QBrush(Qt::red)); + item.setForeground(0, QBrush(Qt::green)); + item.setSizeHint(0, QSize(10, 10)); + QCOMPARE(item.data(0, Qt::BackgroundRole), QVariant(QBrush(Qt::red))); + QCOMPARE(item.data(0, Qt::ForegroundRole), QVariant(QBrush(Qt::green))); + QCOMPARE(item.data(0, Qt::SizeHintRole), QVariant(QSize(10, 10))); + // an empty brush should result in a QVariant() + item.setBackground(0, QBrush()); + item.setForeground(0, QBrush()); + item.setSizeHint(0, QSize()); + QCOMPARE(item.data(0, Qt::BackgroundRole), QVariant()); + QCOMPARE(item.data(0, Qt::ForegroundRole), QVariant()); + QCOMPARE(item.data(0, Qt::SizeHintRole), QVariant()); } void tst_QTreeWidget::enableDisable() |