diff options
Diffstat (limited to 'tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp')
-rw-r--r-- | tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp | 72 |
1 files changed, 62 insertions, 10 deletions
diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp index 40834459e5..093367c759 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp +++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -112,13 +112,17 @@ void tst_QStandardItem::getSetData() item.setToolTip(toolTip); QCOMPARE(item.toolTip(), toolTip); +#ifndef QT_NO_STATUSTIP QString statusTip = QLatin1String("statusTip ") + iS; item.setStatusTip(statusTip); QCOMPARE(item.statusTip(), statusTip); +#endif +#if QT_CONFIG(whatsthis) QString whatsThis = QLatin1String("whatsThis ") + iS; item.setWhatsThis(whatsThis); QCOMPARE(item.whatsThis(), whatsThis); +#endif QSize sizeHint(64*i, 48*i); item.setSizeHint(sizeHint); @@ -157,8 +161,12 @@ void tst_QStandardItem::getSetData() QCOMPARE(item.text(), text); QCOMPARE(item.icon(), icon); QCOMPARE(item.toolTip(), toolTip); +#ifndef QT_NO_STATUSTIP QCOMPARE(item.statusTip(), statusTip); +#endif +#if QT_CONFIG(whatsthis) QCOMPARE(item.whatsThis(), whatsThis); +#endif QCOMPARE(item.sizeHint(), sizeHint); QCOMPARE(item.font(), font); QCOMPARE(item.textAlignment(), textAlignment); @@ -171,8 +179,12 @@ void tst_QStandardItem::getSetData() QCOMPARE(qvariant_cast<QString>(item.data(Qt::DisplayRole)), text); QCOMPARE(qvariant_cast<QIcon>(item.data(Qt::DecorationRole)), icon); QCOMPARE(qvariant_cast<QString>(item.data(Qt::ToolTipRole)), toolTip); +#ifndef QT_NO_STATUSTIP QCOMPARE(qvariant_cast<QString>(item.data(Qt::StatusTipRole)), statusTip); +#endif +#if QT_CONFIG(whatsthis) QCOMPARE(qvariant_cast<QString>(item.data(Qt::WhatsThisRole)), whatsThis); +#endif QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint); QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font); QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment)); @@ -757,10 +769,10 @@ void tst_QStandardItem::takeColumn() QList<QStandardItem *> taken = item.takeColumn(column); if (expectSuccess) { - QCOMPARE(taken.count(), item.rowCount()); + QCOMPARE(taken.size(), item.rowCount()); QCOMPARE(item.columnCount(), columns - 1); int index = column; - for (int i = 0; i < taken.count(); ++i) { + for (int i = 0; i < taken.size(); ++i) { QCOMPARE(taken.at(i), originalChildren.takeAt(index)); index += item.columnCount(); } @@ -818,10 +830,10 @@ void tst_QStandardItem::takeRow() QList<QStandardItem *> taken = item.takeRow(row); if (expectSuccess) { - QCOMPARE(taken.count(), item.columnCount()); + QCOMPARE(taken.size(), item.columnCount()); QCOMPARE(item.rowCount(), rows - 1); int index = row * columns; - for (int i = 0; i < taken.count(); ++i) { + for (int i = 0; i < taken.size(); ++i) { QCOMPARE(taken.at(i), originalChildren.takeAt(index)); } index = 0; @@ -844,7 +856,9 @@ void tst_QStandardItem::streamItem() item.setText(QLatin1String("text")); item.setToolTip(QLatin1String("toolTip")); item.setStatusTip(QLatin1String("statusTip")); +#if QT_CONFIG(whatsthis) item.setWhatsThis(QLatin1String("whatsThis")); +#endif item.setSizeHint(QSize(64, 48)); item.setFont(QFont()); item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); @@ -866,7 +880,9 @@ void tst_QStandardItem::streamItem() QCOMPARE(streamedItem.text(), item.text()); QCOMPARE(streamedItem.toolTip(), item.toolTip()); QCOMPARE(streamedItem.statusTip(), item.statusTip()); +#if QT_CONFIG(whatsthis) QCOMPARE(streamedItem.whatsThis(), item.whatsThis()); +#endif QCOMPARE(streamedItem.sizeHint(), item.sizeHint()); QCOMPARE(streamedItem.font(), item.font()); QCOMPARE(streamedItem.textAlignment(), item.textAlignment()); @@ -905,7 +921,9 @@ void tst_QStandardItem::clone() item.setText(QLatin1String("text")); item.setToolTip(QLatin1String("toolTip")); item.setStatusTip(QLatin1String("statusTip")); +#if QT_CONFIG(whatsthis) item.setWhatsThis(QLatin1String("whatsThis")); +#endif item.setSizeHint(QSize(64, 48)); item.setFont(QFont()); item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); @@ -920,7 +938,9 @@ void tst_QStandardItem::clone() QCOMPARE(clone->text(), item.text()); QCOMPARE(clone->toolTip(), item.toolTip()); QCOMPARE(clone->statusTip(), item.statusTip()); +#if QT_CONFIG(whatsthis) QCOMPARE(clone->whatsThis(), item.whatsThis()); +#endif QCOMPARE(clone->sizeHint(), item.sizeHint()); QCOMPARE(clone->font(), item.font()); QCOMPARE(clone->textAlignment(), item.textAlignment()); @@ -984,8 +1004,8 @@ void tst_QStandardItem::sortChildren() QCOMPARE(two->child(1)->text(), QLatin1String("e")); QCOMPARE(two->child(2)->text(), QLatin1String("f")); - QCOMPARE(layoutAboutToBeChangedSpy.count(), (x == 0) ? 0 : 3); - QCOMPARE(layoutChangedSpy.count(), (x == 0) ? 0 : 3); + QCOMPARE(layoutAboutToBeChangedSpy.size(), (x == 0) ? 0 : 3); + QCOMPARE(layoutChangedSpy.size(), (x == 0) ? 0 : 3); if (x == 0) delete item; @@ -1001,11 +1021,37 @@ public: int type() const override { return QStandardItem::UserType + 1; } bool operator<(const QStandardItem &other) const override { - return text().length() < other.text().length(); + return text().size() < other.text().size(); } using QStandardItem::clone; using QStandardItem::emitDataChanged; + + void setData(const QVariant &value, int role) override + { + switch (role) { + case Qt::DisplayRole: + QStandardItem::setData(value, role); + break; + default: + // setFlags() uses "UserRole - 1" to store the flags, which is an + // implementation detail not exposed in the docs. + QStandardItem::setData(value, role); + break; + } + } + + QVariant data(int role) const override + { + switch (role) { + case Qt::DisplayRole: + return QStandardItem::data(role); + default: + // flags() uses "UserRole - 1" to get the flags, which is an implementation + // detail not exposed in the docs. + return QStandardItem::data(role); + } + } }; Q_DECLARE_METATYPE(QStandardItem*) @@ -1027,8 +1073,8 @@ void tst_QStandardItem::subclassing() QSignalSpy itemChangedSpy(&model, &QStandardItemModel::itemChanged); item->emitDataChanged(); - QCOMPARE(itemChangedSpy.count(), 1); - QCOMPARE(itemChangedSpy.at(0).count(), 1); + QCOMPARE(itemChangedSpy.size(), 1); + QCOMPARE(itemChangedSpy.at(0).size(), 1); QCOMPARE(qvariant_cast<QStandardItem*>(itemChangedSpy.at(0).at(0)), item); CustomItem *child0 = new CustomItem("cc"); @@ -1041,6 +1087,12 @@ void tst_QStandardItem::subclassing() QCOMPARE(item->child(0), child2); QCOMPARE(item->child(1), child0); QCOMPARE(item->child(2), child1); + + item->setFlags(Qt::ItemFlags{0}); + QCOMPARE(item->flags(), Qt::ItemFlags{0}); + + item->setFlags(Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable}); + QCOMPARE(item->flags(), Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable}); } void tst_QStandardItem::lessThan() |