summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels/qabstractitemmodel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/itemmodels/qabstractitemmodel')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/CMakeLists.txt16
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro9
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp159
3 files changed, 92 insertions, 92 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/CMakeLists.txt b/tests/auto/corelib/itemmodels/qabstractitemmodel/CMakeLists.txt
index 33d790ddc5..e5c7c08fc8 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/CMakeLists.txt
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/CMakeLists.txt
@@ -1,17 +1,23 @@
-# Generated from qabstractitemmodel.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qabstractitemmodel Test:
#####################################################################
-qt_add_test(tst_qabstractitemmodel
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qabstractitemmodel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qabstractitemmodel
SOURCES
../../../other/qabstractitemmodelutils/dynamictreemodel.cpp ../../../other/qabstractitemmodelutils/dynamictreemodel.h
tst_qabstractitemmodel.cpp
- DEFINES
- QT_DISABLE_DEPRECATED_BEFORE=0
INCLUDE_DIRECTORIES
../../../other/qabstractitemmodelutils
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro b/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro
deleted file mode 100644
index da1f87e76a..0000000000
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qabstractitemmodel
-QT = core testlib gui
-
-mtdir = ../../../other/qabstractitemmodelutils
-INCLUDEPATH += $$PWD/$${mtdir}
-SOURCES = tst_qabstractitemmodel.cpp $${mtdir}/dynamictreemodel.cpp
-HEADERS = $${mtdir}/dynamictreemodel.h
-DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 5d384de2b2..36eb9320a4 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/QCoreApplication>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+
+#include <QtTest/private/qcomparisontesthelper_p.h>
+#include <QtCore/QCoreApplication>
#include <QtCore/QSortFilterProxyModel>
#include <QtCore/QStringListModel>
#include <QtGui/QStandardItemModel>
@@ -37,6 +14,9 @@
// for testing QModelRoleDataSpan construction
#include <QVarLengthArray>
+#include <QSignalSpy>
+#include <QMimeData>
+
#include <array>
#include <vector>
#include <deque>
@@ -78,6 +58,7 @@ private slots:
void reset();
void complexChangesWithPersistent();
+ void modelIndexComparisons();
void testMoveSameParentUp_data();
void testMoveSameParentUp();
@@ -132,8 +113,8 @@ private:
class QtTestModel: public QAbstractItemModel
{
public:
- QtTestModel(int rows, int columns, QObject *parent = 0);
- QtTestModel(const QList<QList<QString> > tbl, QObject *parent = 0);
+ QtTestModel(int rows, int columns, QObject *parent = nullptr);
+ QtTestModel(const QList<QList<QString> > tbl, QObject *parent = nullptr);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &) const override;
int rowCount(const QModelIndex &parent) const override;
@@ -178,8 +159,8 @@ QtTestModel::QtTestModel(const QList<QList<QString> > tbl, QObject *parent)
: QAbstractItemModel(parent), wrongIndex(false)
{
table = tbl;
- rCount = tbl.count();
- cCount = tbl.at(0).count();
+ rCount = tbl.size();
+ cCount = tbl.at(0).size();
}
QModelIndex QtTestModel::index(int row, int column, const QModelIndex &parent) const
@@ -213,7 +194,7 @@ bool QtTestModel::insertRows(int row, int count, const QModelIndex &parent)
QAbstractItemModel::beginInsertRows(parent, row, row + count - 1);
int cc = columnCount(parent);
table.insert(row, count, QList<QString>(cc));
- rCount = table.count();
+ rCount = table.size();
QAbstractItemModel::endInsertRows();
return true;
}
@@ -224,7 +205,7 @@ bool QtTestModel::insertColumns(int column, int count, const QModelIndex &parent
int rc = rowCount(parent);
for (int i = 0; i < rc; ++i)
table[i].insert(column, 1, "");
- cCount = table.at(0).count();
+ cCount = table.at(0).size();
QAbstractItemModel::endInsertColumns();
return true;
}
@@ -240,7 +221,7 @@ bool QtTestModel::removeRows( int row, int count, const QModelIndex & parent)
for (int r = row+count-1; r >= row; --r)
table.remove(r);
- rCount = table.count();
+ rCount = table.size();
QAbstractItemModel::endRemoveRows();
return true;
@@ -254,7 +235,7 @@ bool QtTestModel::removeColumns(int column, int count, const QModelIndex & paren
for (int r = 0; r < rCount; ++r)
table[r].remove(c);
- cCount = table.at(0).count();
+ cCount = table.at(0).size();
QAbstractItemModel::endRemoveColumns();
return true;
@@ -282,7 +263,7 @@ bool QtTestModel::moveRows(const QModelIndex &sourceParent, int src, int cnt,
}
}
- rCount = table.count();
+ rCount = table.size();
QAbstractItemModel::endMoveRows();
return true;
@@ -312,7 +293,7 @@ bool QtTestModel::moveColumns(const QModelIndex &sourceParent, int src, int cnt,
}
}
- cCount = table.at(0).count();
+ cCount = table.at(0).size();
QAbstractItemModel::endMoveColumns();
return true;
@@ -436,11 +417,11 @@ void tst_QAbstractItemModel::itemFlags()
void tst_QAbstractItemModel::match()
{
- QtTestModel model(4, 1);
+ QtTestModel model(5, 1);
QModelIndex start = model.index(0, 0, QModelIndex());
QVERIFY(start.isValid());
QModelIndexList res = model.match(start, Qt::DisplayRole, QVariant("1"), 3);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
QModelIndex idx = model.index(1, 0, QModelIndex());
bool areEqual = (idx == res.first());
QVERIFY(areEqual);
@@ -449,44 +430,45 @@ void tst_QAbstractItemModel::match()
model.setData(model.index(1, 0, QModelIndex()), "cat", Qt::DisplayRole);
model.setData(model.index(2, 0, QModelIndex()), "dog", Qt::DisplayRole);
model.setData(model.index(3, 0, QModelIndex()), "boar", Qt::DisplayRole);
+ model.setData(model.index(4, 0, QModelIndex()), "bo/a/r", Qt::DisplayRole); // QTBUG-104585
res = model.match(start, Qt::DisplayRole, QVariant("dog"), -1, Qt::MatchExactly);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant("a"), -1, Qt::MatchContains);
- QCOMPARE(res.count(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant("b"), -1, Qt::MatchStartsWith);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant("t"), -1, Qt::MatchEndsWith);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 2);
res = model.match(start, Qt::DisplayRole, QVariant("*a*"), -1, Qt::MatchWildcard);
- QCOMPARE(res.count(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 0);
+ QCOMPARE(res.size(), 0);
res = model.match(start, Qt::DisplayRole, QVariant("BOAR"), -1, Qt::MatchFixedString);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant("bat"), -1,
Qt::MatchFixedString | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 0);
+ QCOMPARE(res.size(), 0);
res = model.match(start, Qt::DisplayRole, QVariant(QRegularExpression(".*O.*")),
-1, Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 0);
+ QCOMPARE(res.size(), 0);
res = model.match(start,
Qt::DisplayRole,
QVariant(QRegularExpression(".*O.*",
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
// Ensure that the case sensitivity is properly ignored when passing a
// QRegularExpression object.
@@ -496,7 +478,7 @@ void tst_QAbstractItemModel::match()
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
}
typedef QPair<int, int> Position;
@@ -779,7 +761,7 @@ void tst_QAbstractItemModel::dropMimeData()
// get the mimeData from the "selected" indexes
QModelIndexList selectedIndexes;
- for (int i = 0; i < selection.count(); ++i)
+ for (int i = 0; i < selection.size(); ++i)
selectedIndexes << src.index(selection.at(i).first, selection.at(i).second, QModelIndex());
QMimeData *md = src.mimeData(selectedIndexes);
// do the drop
@@ -850,8 +832,8 @@ void tst_QAbstractItemModel::removeRows()
QVERIFY(rowsRemovedSpy.isValid());
QCOMPARE(model.removeRows(6, 4), true);
- QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(rowsRemovedSpy.count(), 1);
+ QCOMPARE(rowsAboutToBeRemovedSpy.size(), 1);
+ QCOMPARE(rowsRemovedSpy.size(), 1);
}
void tst_QAbstractItemModel::removeColumns()
@@ -865,8 +847,8 @@ void tst_QAbstractItemModel::removeColumns()
QVERIFY(columnsRemovedSpy.isValid());
QCOMPARE(model.removeColumns(6, 4), true);
- QCOMPARE(columnsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(columnsRemovedSpy.count(), 1);
+ QCOMPARE(columnsAboutToBeRemovedSpy.size(), 1);
+ QCOMPARE(columnsRemovedSpy.size(), 1);
}
void tst_QAbstractItemModel::insertRows()
@@ -880,8 +862,8 @@ void tst_QAbstractItemModel::insertRows()
QVERIFY(rowsInsertedSpy.isValid());
QCOMPARE(model.insertRows(6, 4), true);
- QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
- QCOMPARE(rowsInsertedSpy.count(), 1);
+ QCOMPARE(rowsAboutToBeInsertedSpy.size(), 1);
+ QCOMPARE(rowsInsertedSpy.size(), 1);
}
void tst_QAbstractItemModel::insertColumns()
@@ -895,8 +877,8 @@ void tst_QAbstractItemModel::insertColumns()
QVERIFY(columnsInsertedSpy.isValid());
QCOMPARE(model.insertColumns(6, 4), true);
- QCOMPARE(columnsAboutToBeInsertedSpy.count(), 1);
- QCOMPARE(columnsInsertedSpy.count(), 1);
+ QCOMPARE(columnsAboutToBeInsertedSpy.size(), 1);
+ QCOMPARE(columnsInsertedSpy.size(), 1);
}
void tst_QAbstractItemModel::moveRows()
@@ -910,8 +892,8 @@ void tst_QAbstractItemModel::moveRows()
QVERIFY(rowsMovedSpy.isValid());
QCOMPARE(model.moveRows(QModelIndex(), 6, 4, QModelIndex(), 1), true);
- QCOMPARE(rowsAboutToBeMovedSpy.count(), 1);
- QCOMPARE(rowsMovedSpy.count(), 1);
+ QCOMPARE(rowsAboutToBeMovedSpy.size(), 1);
+ QCOMPARE(rowsMovedSpy.size(), 1);
}
void tst_QAbstractItemModel::moveColumns()
@@ -925,12 +907,12 @@ void tst_QAbstractItemModel::moveColumns()
QVERIFY(columnsMovedSpy.isValid());
QCOMPARE(model.moveColumns(QModelIndex(), 6, 4, QModelIndex(), 1), true);
- QCOMPARE(columnsAboutToBeMovedSpy.count(), 1);
- QCOMPARE(columnsMovedSpy.count(), 1);
+ QCOMPARE(columnsAboutToBeMovedSpy.size(), 1);
+ QCOMPARE(columnsMovedSpy.size(), 1);
QCOMPARE(model.moveColumn(QModelIndex(), 4, QModelIndex(), 1), true);
- QCOMPARE(columnsAboutToBeMovedSpy.count(), 2);
- QCOMPARE(columnsMovedSpy.count(), 2);
+ QCOMPARE(columnsAboutToBeMovedSpy.size(), 2);
+ QCOMPARE(columnsMovedSpy.size(), 2);
}
void tst_QAbstractItemModel::reset()
@@ -940,7 +922,7 @@ void tst_QAbstractItemModel::reset()
QSignalSpy resetSpy(&model, &QtTestModel::modelReset);
QVERIFY(resetSpy.isValid());
model.reset();
- QCOMPARE(resetSpy.count(), 1);
+ QCOMPARE(resetSpy.size(), 1);
}
void tst_QAbstractItemModel::complexChangesWithPersistent()
@@ -1005,6 +987,27 @@ void tst_QAbstractItemModel::complexChangesWithPersistent()
QVERIFY(e[i] == model.index(2, i-2 , QModelIndex()));
}
+void tst_QAbstractItemModel::modelIndexComparisons()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QModelIndex>();
+ QTestPrivate::testEqualityOperatorsCompile<QPersistentModelIndex>();
+ QTestPrivate::testEqualityOperatorsCompile<QPersistentModelIndex, QModelIndex>();
+
+ QtTestModel model(3, 3);
+
+ QModelIndex mi11 = model.index(1, 1);
+ QModelIndex mi22 = model.index(2, 2);
+ QPersistentModelIndex pmi11 = mi11;
+ QPersistentModelIndex pmi22 = mi22;
+
+ QT_TEST_EQUALITY_OPS(mi11, mi11, true);
+ QT_TEST_EQUALITY_OPS(mi11, mi22, false);
+ QT_TEST_EQUALITY_OPS(pmi11, pmi11, true);
+ QT_TEST_EQUALITY_OPS(pmi11, pmi22, false);
+ QT_TEST_EQUALITY_OPS(pmi11, mi11, true);
+ QT_TEST_EQUALITY_OPS(pmi11, mi22, false);
+}
+
void tst_QAbstractItemModel::testMoveSameParentDown_data()
{
QTest::addColumn<int>("startRow");
@@ -1869,7 +1872,7 @@ void ListenerObject::slotAboutToBeReset()
void ListenerObject::slotReset()
{
- for (const auto &idx : qAsConst(m_persistentIndexes)) {
+ for (const auto &idx : std::as_const(m_persistentIndexes)) {
QVERIFY(!idx.isValid());
}
}
@@ -1940,7 +1943,7 @@ public:
UserRole
};
- CustomRoleModel(QObject *parent = 0)
+ CustomRoleModel(QObject *parent = nullptr)
: QStringListModel(QStringList() << "a" << "b" << "c", parent)
{
}
@@ -1991,7 +1994,7 @@ class SignalArgumentChecker : public QObject
{
Q_OBJECT
public:
- SignalArgumentChecker(const QModelIndex &p1, const QModelIndex &p2, QObject *parent = 0)
+ SignalArgumentChecker(const QModelIndex &p1, const QModelIndex &p2, QObject *parent = nullptr)
: QObject(parent), m_p1(p1), m_p2(p2), m_p1Persistent(p1), m_p2Persistent(p2)
{
connect(p1.model(), SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>)), SLOT(layoutAboutToBeChanged(QList<QPersistentModelIndex>)));
@@ -2165,7 +2168,7 @@ class OverrideRoleNamesAndDragActions : public QStringListModel
{
Q_OBJECT
public:
- OverrideRoleNamesAndDragActions(QObject *parent = 0)
+ OverrideRoleNamesAndDragActions(QObject *parent = nullptr)
: QStringListModel(parent)
{
@@ -2204,7 +2207,7 @@ class OverrideDropActions : public QStringListModel
{
Q_OBJECT
public:
- OverrideDropActions(QObject *parent = 0)
+ OverrideDropActions(QObject *parent = nullptr)
: QStringListModel(parent)
{
}
@@ -2225,7 +2228,7 @@ class SignalConnectionTester : public QObject
{
Q_OBJECT
public:
- SignalConnectionTester(QObject *parent = 0)
+ SignalConnectionTester(QObject *parent = nullptr)
: QObject(parent), testPassed(false)
{