6#include <QtQml/qqmlregistration.h>
7#include "qml_material/model/item_snapshot.hpp"
27 ItemSnapshotPtr before;
28 ItemSnapshotPtr after;
29 QVector<ItemChange> changes;
33struct ItemPublishResult {
39 Status status = Rejected;
41 explicit operator bool()
const {
return status == Accepted; }
44class QML_MATERIAL_API ItemSource :
public QObject {
46 QML_NAMED_ELEMENT(ItemSource)
47 QML_UNCREATABLE(
"Use an item source adapter")
48 Q_PROPERTY(
int count READ count NOTIFY stateChanged FINAL)
49 Q_PROPERTY(quint64 revision READ revision NOTIFY stateChanged FINAL)
50 Q_PROPERTY(
bool stableKeys READ stableKeys NOTIFY stateChanged FINAL)
51 Q_PROPERTY(QString errorString READ errorString NOTIFY stateChanged FINAL)
53 explicit ItemSource(QObject* parent =
nullptr);
54 ItemSnapshotPtr snapshot()
const {
return m_snapshot; }
55 int count()
const {
return m_snapshot->count(); }
56 quint64 revision()
const {
return m_snapshot->revision; }
57 bool stableKeys()
const {
return m_snapshot->stableKeys(); }
58 QString errorString()
const {
return m_error; }
59 Q_INVOKABLE
int indexOfKey(
const QString& key)
const {
return m_snapshot->indexOfKey(key); }
60 Q_INVOKABLE QVariant valueAt(
int index)
const {
61 return index >= 0 && index < count() ? m_snapshot->valueAt(index) : QVariant {};
63 Q_SIGNAL
void stateChanged();
64 Q_SIGNAL
void committed(
const qml_material::ItemChangeSet& change);
67 ItemPublishResult publish(ItemDataSnapshotPtr, QVector<ItemChange> changes = {},
70 ItemPublishResult publishValues(QVector<ItemValueUpdate>);
71 ItemPublishResult reject(QString error);
72 ItemSnapshotPtr publicationBase()
const {
return m_tail; }
80 ItemPublishResult commit(ItemSnapshotPtr, QVector<ItemChange>,
bool reset);
81 ItemSnapshotPtr m_snapshot;
82 ItemSnapshotPtr m_tail;
83 QList<Pending> m_pending;
85 bool m_publishing =
false;
88class QML_MATERIAL_API ListSnapshotSource :
public ItemSource {
91 Q_PROPERTY(QVariantList items READ items WRITE setItems NOTIFY itemsChanged FINAL)
92 Q_PROPERTY(QString keyRole READ keyRole WRITE setKeyRole NOTIFY keyRoleChanged FINAL)
93 Q_PROPERTY(QString typeRole READ typeRole WRITE setTypeRole NOTIFY typeRoleChanged FINAL)
95 using ItemSource::ItemSource;
96 QVariantList items()
const {
return m_items; }
97 QString keyRole()
const {
return m_keyRole; }
98 QString typeRole()
const {
return m_typeRole; }
99 void setItems(
const QVariantList&);
100 void setKeyRole(
const QString&);
101 void setTypeRole(
const QString&);
102 Q_SIGNAL
void itemsChanged();
103 Q_SIGNAL
void keyRoleChanged();
104 Q_SIGNAL
void typeRoleChanged();
108 QVariantList m_items;
109 QString m_keyRole, m_typeRole;
112Q_DECLARE_METATYPE(qml_material::ItemChangeSet)