QmlMaterial 0.1.0
Loading...
Searching...
No Matches
delegate_recycler.hpp
1#pragma once
2
3#include <QQmlComponent>
4#include <QQmlEngine>
5#include <QQuickItem>
6#include <QPointer>
7#include "qml_material/model/lazy_row.hpp"
8
9namespace qml_material
10{
11class DelegateRecycler : public QObject {
12public:
13 explicit DelegateRecycler(QQmlEngine*, QObject* parent = nullptr);
14 ~DelegateRecycler() override;
15 QQuickItem* acquire(QQmlComponent*, const ItemSnapshotPtr&, int index);
16 bool rebind(QQuickItem*, const ItemSnapshotPtr&, int index);
17 void attach(QQuickItem*, QQuickItem* parent);
18 void layout(QQuickItem*, const QRectF&);
19 void release(QQuickItem*);
20 void clear();
21 void setPoolLimit(int);
22 int poolSize() const;
23 LazyRow* row(QQuickItem*) const;
24 QString errorString() const { return m_error; }
25
26private:
27 struct Entry {
28 ~Entry();
29 QPointer<QQuickItem> item;
30 QPointer<QQuickItem> host;
31 QPointer<LazyRow> row;
32 QPointer<QQmlComponent> component;
33 QString type;
34 bool idle = false;
35 bool updating = false;
36 };
37 std::shared_ptr<Entry> entry(QQuickItem*) const;
38 void trim();
39 QPointer<QQmlEngine> m_engine;
40 QList<std::shared_ptr<Entry>> m_entries;
41 QString m_error;
42 quint64 m_generation = 0;
43 int m_poolLimit = 16;
44 bool m_clearing = false;
45};
46} // namespace qml_material