QmlMaterial 0.1.0
Loading...
Searching...
No Matches
lazy_row.hpp
1#pragma once
2
3#include "qml_material/model/item_source.hpp"
4#include <QQuickItem>
5#include <QPointer>
6
7namespace qml_material
8{
9class QML_MATERIAL_API LazyRow : public QObject {
10 Q_OBJECT
11 QML_ELEMENT
12 QML_UNCREATABLE("Rows are supplied by a lazy view")
13 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
14 Q_PROPERTY(QString key READ key NOTIFY keyChanged FINAL)
15 Q_PROPERTY(QVariant value READ value NOTIFY valueChanged FINAL)
16 Q_PROPERTY(quint64 revision READ revision NOTIFY revisionChanged FINAL)
17 Q_PROPERTY(quint64 contentRevision READ contentRevision NOTIFY contentRevisionChanged FINAL)
18 Q_PROPERTY(bool active READ active NOTIFY activeChanged FINAL)
19 Q_PROPERTY(Usage usage READ usage NOTIFY usageChanged FINAL)
20 Q_PROPERTY(QQuickItem* view READ view NOTIFY viewChanged FINAL)
21public:
22 enum Usage
23 {
24 Visible,
25 Cached,
26 Pooled
27 };
28 Q_ENUM(Usage)
29 using QObject::QObject;
30 Usage usage() const { return m_usage; }
31 QQuickItem* view() const { return m_view; }
32 Q_SIGNAL void usageChanged();
33 Q_SIGNAL void viewChanged();
34 int index() const { return m_index; }
35 QString key() const { return m_record.key; }
36 QVariant value() const { return m_record.value; }
37 quint64 revision() const { return m_revision; }
38 quint64 contentRevision() const { return m_record.contentRevision; }
39 bool active() const { return m_active; }
40 Q_SIGNAL void changed();
41 Q_SIGNAL void indexChanged();
42 Q_SIGNAL void keyChanged();
43 Q_SIGNAL void valueChanged();
44 Q_SIGNAL void revisionChanged();
45 Q_SIGNAL void contentRevisionChanged();
46 Q_SIGNAL void activeChanged();
47 Q_SIGNAL void pooled();
48 Q_SIGNAL void reused();
49
50private:
51 friend class DelegateRecycler;
52 friend class LazyView;
53 void setUsage(Usage, QQuickItem*);
54 Usage m_usage = Pooled;
55 QPointer<QQuickItem> m_view;
56 void bind(const ItemSnapshotPtr&, int index, QQuickItem* view = nullptr, Usage usage = Cached);
57 void pool();
58 ItemSnapshotPtr m_snapshot;
59 ItemRecord m_record;
60 int m_index = -1;
61 quint64 m_revision = 0;
62 bool m_active = false;
63 quint64 m_generation = 0;
64};
65} // namespace qml_material