1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef REUSEMODEL_H
30#define REUSEMODEL_H
31
32#include <QAbstractListModel>
33#include <QList>
34#include <QStringList>
35
36class ReuseModel : public QAbstractListModel
37{
38 Q_OBJECT
39
40public:
41 ReuseModel(int rowCount, QObject *parent = nullptr)
42 : QAbstractListModel(parent)
43 , m_rowCount(rowCount)
44 {}
45
46 int rowCount(const QModelIndex & = QModelIndex()) const override
47 {
48 return m_rowCount;
49 }
50
51 QVariant data(const QModelIndex &index, int role) const override
52 {
53 if (!index.isValid())
54 return QVariant();
55
56 switch (role) {
57 case Qt::DisplayRole:
58 return displayStringForRow(row: index.row());
59 default:
60 break;
61 }
62
63 return QVariant();
64 }
65
66 QString displayStringForRow(int row) const
67 {
68 return row % 2 == 0 ?
69 QStringLiteral("Even%1").arg(a: row) :
70 QStringLiteral("Odd%1").arg(a: row);
71 }
72
73 QHash<int, QByteArray> roleNames() const override
74 {
75 return {
76 {Qt::DisplayRole, "display"},
77 };
78 }
79
80private:
81 int m_rowCount;
82};
83
84#endif
85

source code of qtdeclarative/tests/auto/quick/qquicklistview/reusemodel.h