3#include <QQmlComponent>
7#include <QQmlIncubator>
10#include "qml_material/model/lazy_row.hpp"
14class DelegateRecycler :
public QObject {
17 QPointer<QQuickItem> parent, view;
19 Qt::Orientation orientation = Qt::Vertical;
20 LazyRow::Usage usage = LazyRow::Cached;
21 bool fixedExtent =
false;
24 explicit DelegateRecycler(QQmlEngine*, QObject* parent =
nullptr);
25 ~DelegateRecycler()
override;
26 QQuickItem* acquire(QQmlComponent*,
const ItemSnapshotPtr&,
int index);
27 QQuickItem* acquire(QQmlComponent*,
const ItemSnapshotPtr&,
int index,
const Placement&,
29 bool rebind(QQuickItem*,
const ItemSnapshotPtr&,
int index);
30 bool rebind(QQuickItem*,
const ItemSnapshotPtr&,
int index,
const Placement&);
31 void retainPreparations(QQmlComponent*,
const ItemSnapshotPtr&,
const QSet<QString>&);
32 void cancelPreparations();
33 bool pending(
const QString&)
const;
34 int pendingCount()
const;
35 void setReadyCallback(std::function<
void()> callback) { m_ready = std::move(callback); }
36 void attach(QQuickItem*, QQuickItem* parent);
37 void layout(QQuickItem*,
const QRectF&, Qt::Orientation = Qt::Vertical,
38 bool fixedExtent =
false);
39 void release(QQuickItem*);
41 void setPoolLimit(
int);
45 LazyRow* row(QQuickItem*)
const;
46 QString errorString()
const {
return m_error; }
52 QPointer<QQuickItem> item;
53 QPointer<QObject> object;
54 QPointer<QQuickItem> host;
55 QPointer<LazyRow> row;
56 QPointer<QQmlComponent> component;
59 QQuickItem* itemIdentity =
nullptr;
61 std::shared_ptr<Incubator> incubator;
62 bool preparing =
false;
63 bool cancelled =
false;
65 bool updating =
false;
67 std::shared_ptr<Entry> entry(QQuickItem*)
const;
68 bool place(
const std::shared_ptr<Entry>&,
const Placement&);
69 void remove(
const std::shared_ptr<Entry>&);
70 void finishPreparation(
const std::shared_ptr<Entry>&);
71 static void retire(
const std::shared_ptr<Entry>&, QQmlEngine*);
74 QPointer<QQmlEngine> m_engine;
75 QList<std::shared_ptr<Entry>> m_entries;
76 QHash<QQuickItem*, std::weak_ptr<Entry>> m_items;
77 QHash<QString, std::shared_ptr<Entry>> m_pending;
78 std::function<void()> m_ready;
80 quint64 m_generation = 0;
82 int m_updateDepth = 0;
83 bool m_clearing =
false;
84 bool m_readyQueued =
false;