summaryrefslogtreecommitdiffstats
path: root/tests/manual/qml2dperformance/randomModel.h
blob: 4d32cd9e65ce01acb19756b3a4df1e25ac951633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef RANDOMMODEL_H
#define RANDOMMODEL_H

#include <qabstractitemmodel.h>
#include <qtmetamacros.h>
#include <QtQmlIntegration/qqmlintegration.h>

class RandomModel : public QAbstractTableModel
{
    Q_OBJECT
    Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged)

public:
    enum Roles {
        XRole = Qt::DisplayRole + 1,
        YRole,
    };
    RandomModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    void setRowCount(int rowCount);
    int columnCount(const QModelIndex &parent) const override;

    QVariant headerData(int section,
                        Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role) override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QHash<int, QByteArray> roleNames() const override;

    Q_INVOKABLE void nextCache();

Q_SIGNALS:
    void rowCountChanged(int rowCount);

private:
    void generateCaches();
    void clearData();

    int m_cacheCount = 60;
    int m_columnCount;
    int m_rowCount;
    int m_currentCache = 0;
    QVector<QList<QList<qreal>>> m_data;
};

#endif // RANDOMMODEL_H