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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QIFPAGINGMODEL_H
#define QIFPAGINGMODEL_H
#include <QtInterfaceFramework/QIfAbstractFeatureListModel>
#include <QtInterfaceFramework/QtInterfaceFrameworkModule>
#include <QtInterfaceFramework/QIfServiceObject>
QT_BEGIN_NAMESPACE
class QIfPagingModelPrivate;
class Q_QTINTERFACEFRAMEWORK_EXPORT QIfPagingModel : public QIfAbstractFeatureListModel
{
Q_OBJECT
QML_NAMED_ELEMENT(PagingModel)
Q_PROPERTY(QtInterfaceFrameworkModule::ModelCapabilities capabilities READ capabilities NOTIFY capabilitiesChanged FINAL)
Q_PROPERTY(int chunkSize READ chunkSize WRITE setChunkSize NOTIFY chunkSizeChanged FINAL)
Q_PROPERTY(int fetchMoreThreshold READ fetchMoreThreshold WRITE setFetchMoreThreshold NOTIFY fetchMoreThresholdChanged FINAL)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged FINAL)
//TODO fix naming
Q_PROPERTY(QIfPagingModel::LoadingType loadingType READ loadingType WRITE setLoadingType NOTIFY loadingTypeChanged FINAL)
public:
enum Roles {
NameRole = Qt::DisplayRole,
TypeRole = Qt::UserRole,
ItemRole = Qt::UserRole + 1,
LastRole = ItemRole
};
//TODO fix naming
enum LoadingType {
FetchMore,
DataChanged
};
Q_ENUM(LoadingType)
explicit QIfPagingModel(QObject *parent = nullptr);
QtInterfaceFrameworkModule::ModelCapabilities capabilities() const;
int chunkSize() const;
void setChunkSize(int chunkSize);
int fetchMoreThreshold() const;
void setFetchMoreThreshold(int fetchMoreThreshold);
QIfPagingModel::LoadingType loadingType() const;
void setLoadingType(QIfPagingModel::LoadingType loadingType);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void reload();
template <typename T> T at(int i) const {
return data(index(i,0), ItemRole).value<T>();
}
Q_SIGNALS:
void capabilitiesChanged(QtInterfaceFrameworkModule::ModelCapabilities capabilities);
void chunkSizeChanged(int chunkSize);
void countChanged();
void fetchMoreThresholdChanged(int fetchMoreThreshold);
void fetchMoreThresholdReached() const;
void loadingTypeChanged(QIfPagingModel::LoadingType loadingType);
protected:
QIfPagingModel(QIfServiceObject *serviceObject, QObject *parent = nullptr);
QIfPagingModel(QIfPagingModelPrivate &dd, QObject *parent);
void connectToServiceObject(QIfServiceObject *serviceObject) override;
void disconnectFromServiceObject(QIfServiceObject *serviceObject) override;
void clearServiceObject() override;
private:
Q_DECLARE_PRIVATE(QIfPagingModel)
Q_PRIVATE_SLOT(d_func(), void onCapabilitiesChanged(QUuid identifier, QtInterfaceFrameworkModule::ModelCapabilities capabilities))
Q_PRIVATE_SLOT(d_func(), void onDataFetched(QUuid identifer, const QList<QVariant> &items, int start, bool moreAvailable))
Q_PRIVATE_SLOT(d_func(), void onCountChanged(QUuid identifier, int new_length))
Q_PRIVATE_SLOT(d_func(), void onDataChanged(QUuid identifier, const QList<QVariant> &data, int start, int count))
Q_PRIVATE_SLOT(d_func(), void onFetchMoreThresholdReached())
};
QT_END_NAMESPACE
#endif // QIFPAGINGMODEL_H
|