diff options
Diffstat (limited to 'tests/auto/testlib/qabstractitemmodeltester')
-rw-r--r-- | tests/auto/testlib/qabstractitemmodeltester/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp | 48 |
2 files changed, 34 insertions, 24 deletions
diff --git a/tests/auto/testlib/qabstractitemmodeltester/CMakeLists.txt b/tests/auto/testlib/qabstractitemmodeltester/CMakeLists.txt index fc7bea8585..20329a95f1 100644 --- a/tests/auto/testlib/qabstractitemmodeltester/CMakeLists.txt +++ b/tests/auto/testlib/qabstractitemmodeltester/CMakeLists.txt @@ -1,16 +1,22 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qabstractitemmodeltester.pro. - ##################################################################### ## tst_qabstractitemmodeltester Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qabstractitemmodeltester LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qabstractitemmodeltester SOURCES ../../other/qabstractitemmodelutils/dynamictreemodel.cpp ../../other/qabstractitemmodelutils/dynamictreemodel.h tst_qabstractitemmodeltester.cpp + NO_PCH_SOURCES + tst_qabstractitemmodeltester.cpp # undef QT_NO_FOREACH INCLUDE_DIRECTORIES ../../other/qabstractitemmodelutils LIBRARIES diff --git a/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp b/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp index a7c90da6a9..c7c833fa09 100644 --- a/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp +++ b/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp @@ -1,5 +1,7 @@ // 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 + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QTest> #include <QAbstractItemModelTester> @@ -54,6 +56,7 @@ void tst_QAbstractItemModelTester::treeWidgetModel() new QTreeWidgetItem(root, QStringList(QString::number(i))); QTreeWidgetItem *remove = root->child(2); root->removeChild(remove); + delete remove; QTreeWidgetItem *parent = new QTreeWidgetItem(&widget, QStringList("parent")); new QTreeWidgetItem(parent, QStringList("child")); parent->setHidden(true); @@ -136,14 +139,8 @@ class AccessibleProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - AccessibleProxyModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) - { - } - - QModelIndexList persistent() - { - return persistentIndexList(); - } + using QSortFilterProxyModel::QSortFilterProxyModel; + using QSortFilterProxyModel::persistentIndexList; }; class ObservingObject : public QObject @@ -156,15 +153,18 @@ public: storePersistentFailureCount(0), checkPersistentFailureCount(0) { - connect(m_proxy, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), - SLOT(storePersistent())); - connect(m_proxy, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), - SLOT(checkPersistent())); + // moveRows signals can not come through because the proxy might sort/filter + // out some of the moved rows. therefore layoutChanged signals are sent from + // the QSFPM and we have to listen to them here to get properly notified + connect(m_proxy, &QAbstractProxyModel::layoutAboutToBeChanged, this, + &ObservingObject::storePersistent); + connect(m_proxy, &QAbstractProxyModel::layoutChanged, this, + &ObservingObject::checkPersistent); } public slots: - void storePersistent(const QModelIndex &parent) + void storePersistentRecursive(const QModelIndex &parent) { for (int row = 0; row < m_proxy->rowCount(parent); ++row) { QModelIndex proxyIndex = m_proxy->index(row, 0, parent); @@ -180,26 +180,27 @@ public slots: m_persistentSourceIndexes.append(sourceIndex); m_persistentProxyIndexes.append(proxyIndex); if (m_proxy->hasChildren(proxyIndex)) - storePersistent(proxyIndex); + storePersistentRecursive(proxyIndex); } } - void storePersistent() + void storePersistent(const QList<QPersistentModelIndex> &parents = {}) { - // This method is called from rowsAboutToBeMoved. Persistent indexes should be valid + // This method is called from source model rowsAboutToBeMoved. Persistent indexes should be valid foreach (const QModelIndex &idx, m_persistentProxyIndexes) if (!idx.isValid()) { qWarning("%s: persistentProxyIndexes contains invalid index", Q_FUNC_INFO); ++storePersistentFailureCount; } - - if (!m_proxy->persistent().isEmpty()) { - qWarning("%s: proxy should have no persistent indexes when storePersistent called", + const auto validCount = std::count_if(parents.begin(), parents.end(), + [](const auto &idx) { return idx.isValid(); }); + if (m_proxy->persistentIndexList().size() != validCount) { + qWarning("%s: proxy should have no additional persistent indexes when storePersistent called", Q_FUNC_INFO); ++storePersistentFailureCount; } - storePersistent(QModelIndex()); - if (m_proxy->persistent().isEmpty()) { + storePersistentRecursive(QModelIndex()); + if (m_proxy->persistentIndexList().isEmpty()) { qWarning("%s: proxy should have persistent index after storePersistent called", Q_FUNC_INFO); ++storePersistentFailureCount; @@ -208,6 +209,9 @@ public slots: void checkPersistent() { + QVERIFY(!m_persistentProxyIndexes.isEmpty()); + QVERIFY(!m_persistentSourceIndexes.isEmpty()); + for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) { m_persistentProxyIndexes.at(row); m_persistentSourceIndexes.at(row); |