7#include <QtQml/qqmlregistration.h>
9#include "qml_material/export.hpp"
18 quint64 contentRevision = 0;
23 QVector<ItemRecord> rows;
24 QHash<QString, int> indexes;
26 bool stableKeys =
false;
28 int indexOfKey(
const QString& key)
const {
return indexes.value(key, -1); }
30using ItemSnapshotPtr = std::shared_ptr<const ItemSnapshot>;
48 ItemSnapshotPtr before;
49 ItemSnapshotPtr after;
50 QVector<ItemChange> changes;
54class QML_MATERIAL_API ItemSource :
public QObject {
56 QML_NAMED_ELEMENT(ItemSource)
57 QML_UNCREATABLE(
"Use an item source adapter")
58 Q_PROPERTY(
int count READ count NOTIFY stateChanged FINAL)
59 Q_PROPERTY(quint64 revision READ revision NOTIFY stateChanged FINAL)
60 Q_PROPERTY(
bool stableKeys READ stableKeys NOTIFY stateChanged FINAL)
61 Q_PROPERTY(QString errorString READ errorString NOTIFY stateChanged FINAL)
63 explicit ItemSource(QObject* parent =
nullptr);
64 ItemSnapshotPtr snapshot()
const {
return m_snapshot; }
65 int count()
const {
return int(m_snapshot->rows.size()); }
66 quint64 revision()
const {
return m_snapshot->revision; }
67 bool stableKeys()
const {
return m_snapshot->stableKeys; }
68 QString errorString()
const {
return m_snapshot->error; }
69 Q_INVOKABLE
int indexOfKey(
const QString& key)
const {
return m_snapshot->indexOfKey(key); }
70 Q_INVOKABLE
virtual void requestMore();
71 Q_SIGNAL
void stateChanged();
72 Q_SIGNAL
void fetchStateChanged();
73 Q_SIGNAL
void committed(
const qml_material::ItemChangeSet& change);
76 void publish(QVector<ItemRecord>,
bool stableKeys, QVector<ItemChange> changes = {},
77 bool reset =
true, QString error = {});
80 ItemSnapshotPtr m_snapshot;
81 QList<ItemChangeSet> m_pending;
82 bool m_publishing =
false;
85class QML_MATERIAL_API ListSnapshotSource :
public ItemSource {
88 Q_PROPERTY(QVariantList items READ items WRITE setItems NOTIFY itemsChanged FINAL)
89 Q_PROPERTY(QString keyRole READ keyRole WRITE setKeyRole NOTIFY keyRoleChanged FINAL)
90 Q_PROPERTY(QString typeRole READ typeRole WRITE setTypeRole NOTIFY typeRoleChanged FINAL)
92 using ItemSource::ItemSource;
93 QVariantList items()
const {
return m_items; }
94 QString keyRole()
const {
return m_keyRole; }
95 QString typeRole()
const {
return m_typeRole; }
96 void setItems(
const QVariantList&);
97 void setKeyRole(
const QString&);
98 void setTypeRole(
const QString&);
99 Q_SIGNAL
void itemsChanged();
100 Q_SIGNAL
void keyRoleChanged();
101 Q_SIGNAL
void typeRoleChanged();
105 QVariantList m_items;
106 QString m_keyRole, m_typeRole;
109Q_DECLARE_METATYPE(qml_material::ItemChangeSet)