File indexing completed on 2024-04-21 03:56:06

0001 /*
0002     This file is part of the test suite of the Qt Toolkit.
0003 
0004     SPDX-FileCopyrightText: 2013 Digia Plc and/or its subsidiary(-ies) <https://www.qt.io/terms-conditions/>
0005     SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
0006 
0007     SPDX-License-Identifier: LGPL-2.1-only
0008 */
0009 
0010 #ifndef MODELTEST_H
0011 #define MODELTEST_H
0012 
0013 #include <QAbstractItemModel>
0014 #include <QObject>
0015 #include <QStack>
0016 
0017 #include "proxymodeltestsuite_export.h"
0018 
0019 class PROXYMODELTESTSUITE_EXPORT ModelTest : public QObject
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     enum Mode {
0025         Normal,
0026         Pedantic,
0027     };
0028 
0029     ModelTest(QAbstractItemModel *model, QObject *parent = nullptr);
0030     ModelTest(QAbstractItemModel *model, Mode testType, QObject *parent = nullptr);
0031 
0032 private Q_SLOTS:
0033     void nonDestructiveBasicTest();
0034     void rowCount();
0035     void columnCount();
0036     void hasIndex();
0037     void index();
0038     void parent();
0039     void data();
0040 
0041 protected Q_SLOTS:
0042     void runAllTests();
0043     void layoutAboutToBeChanged();
0044     void layoutChanged();
0045     void modelAboutToBeReset();
0046     void modelReset();
0047     void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
0048     void rowsInserted(const QModelIndex &parent, int start, int end);
0049     void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
0050     void rowsRemoved(const QModelIndex &parent, int start, int end);
0051     void rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int);
0052     void rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int);
0053     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0054     void headerDataChanged(Qt::Orientation orientation, int start, int end);
0055 
0056     void ensureConsistent();
0057     void ensureSteady();
0058 
0059 private:
0060     void checkChildren(const QModelIndex &parent, int currentDepth = 0);
0061     void refreshStatus();
0062     void persistStatus(const QModelIndex &index);
0063     void init();
0064 
0065     QAbstractItemModel *const model;
0066 
0067     struct Status {
0068         enum Type {
0069             Idle,
0070             InsertingRows,
0071             RemovingRows,
0072             MovingRows,
0073             ChangingLayout,
0074             Resetting,
0075         };
0076 
0077         Type type;
0078 
0079         QList<QPersistentModelIndex> persistent;
0080         QList<QModelIndex> nonPersistent;
0081     } status;
0082 
0083     struct Changing {
0084         QModelIndex parent;
0085         int oldSize;
0086         QVariant last;
0087         QVariant next;
0088     };
0089     QStack<Changing> insert;
0090     QStack<Changing> remove;
0091 
0092     bool fetchingMore;
0093     const bool pedantic;
0094 
0095     QList<QPersistentModelIndex> changing;
0096 };
0097 
0098 #endif