File indexing completed on 2024-09-15 04:14:33
0001 /*************************************************************************** 0002 * Copyright (C) 2017 by Emmanuel Lepage Vallee * 0003 * Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 3 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0017 **************************************************************************/ 0018 0019 #include <QAbstractItemModel> 0020 #include <QTimer> 0021 0022 struct ModelViewTesterItem; 0023 0024 /** 0025 * Perform every model operations so the all the Q_ASSERT and extra validation 0026 * code in the TreeView2 can be used. 0027 * 0028 * It could not be a QStandardItemModel because it lacks fine grained control 0029 * over the move operations. 0030 */ 0031 class ModelViewTester : public QAbstractItemModel 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 Q_PROPERTY(int interval READ interval WRITE setInterval) 0037 0038 0039 explicit ModelViewTester(QObject* parent = nullptr); 0040 virtual ~ModelViewTester(); 0041 0042 Q_INVOKABLE void run(); 0043 0044 int interval() const {return m_pTimer->interval(); } 0045 void setInterval(int i) { m_pTimer->setInterval(i); } 0046 0047 //Model implementation 0048 virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; 0049 virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; 0050 virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; 0051 // virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; 0052 virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const override; 0053 virtual QModelIndex parent ( const QModelIndex& index ) const override; 0054 virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex()) const override; 0055 virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const override; 0056 virtual bool dropMimeData ( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent ) override; 0057 virtual QHash<int,QByteArray> roleNames() const override; 0058 0059 public Q_SLOTS: 0060 //Test function 0061 void prependSimpleRoot(); 0062 void appendSimpleRoot(); 0063 void appendRootChildren(); 0064 0065 void moveRootToFront(); 0066 void moveChildByOne(); 0067 void moveChildByParent(); 0068 void moveToGrandChildren(); 0069 0070 void insertRoot(); 0071 void insertFirst(); 0072 void insertChild(); 0073 0074 void removeRoot(); 0075 void resetModel(); 0076 0077 void largeFrontTree(); 0078 void removeLargeTree(); 0079 void removeLargeTree2(); 0080 void largeFrontTree2(); 0081 void removeLargeTree3(); 0082 0083 private: 0084 ModelViewTesterItem* m_pRoot; 0085 0086 int count {0}; 0087 QStringList steps; 0088 QTimer *m_pTimer {new QTimer(this)}; 0089 };