summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp')
-rw-r--r--tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp99
1 files changed, 63 insertions, 36 deletions
diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
index 61683b20a6..093367c759 100644
--- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
+++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -137,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);
@@ -182,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);
@@ -196,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));
@@ -782,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();
}
@@ -843,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;
@@ -869,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);
@@ -891,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());
@@ -930,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);
@@ -945,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());
@@ -1009,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;
@@ -1026,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*)
@@ -1052,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");
@@ -1066,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()