5#include <QtQml/QQmlEngine>
6#include <QtQml/QQmlIncubator>
7#include <QtQuick/QQuickItem>
12auto pool_object_count() -> std::size_t;
15class PoolIncubator :
public QQmlIncubator {
17 PoolIncubator(Pool* p, qint64
id, IncubationMode mode);
20 void statusChanged(Status)
override;
21 void setInitialState(QObject*)
override;
28class Pool :
public QObject {
32 Q_PROPERTY(
bool async READ async WRITE setAsync NOTIFY asyncChanged FINAL)
34 friend class PoolIncubator;
37 Pool(QObject* parent =
nullptr);
40 Q_INVOKABLE
bool contains(
const QString& key)
const;
41 Q_INVOKABLE QObject* get(
const QString& key)
const;
42 Q_INVOKABLE
void add(
const QVariant&,
const QVariantMap&,
bool autoKey =
false);
43 Q_INVOKABLE
void addWithKey(
const QString& key,
const QVariant& url_module_comp,
45 Q_SIGNAL
void objectAdded(QObject* obj,
const QVariant& key );
47 auto async() const ->
bool;
49 Q_SIGNAL
void asyncChanged(
bool);
51 Q_INVOKABLE
bool removeObject(QObject*);
52 Q_INVOKABLE
void clear();
54 void add(std::optional<QStringView> key, QQmlComponent* comp, const QVariantMap&);
57 Q_SIGNAL
void queueAdded(qint64);
58 Q_SLOT
void onQueueAdded(qint64);
59 Q_SLOT
void onUncacheObjectDeleted(QObject*);
63 bool hasKey {
false };
64 QObject*
object {
nullptr };
66 QPointer<QQmlComponent> component {};
67 PoolIncubator* incubator {
nullptr };
70 void incubatorStateChanged(qint64
id, QQmlIncubator::Status status);
71 void setInitialState(QObject* o);
72 auto genSerial() const -> qint64;
73 void onComponentProgress(qint64
id, qreal);
74 void onComponentLoaded(qint64
id);
75 auto createComponent() -> QQmlComponent*;
76 auto tryCreateComponent(const QVariant&) -> QQmlComponent*;
77 auto tryCache(QStringView) ->
bool;
79 using task_iterator = std::map<qint64, Task>::iterator;
80 void clearTask(task_iterator);
82 mutable qint64 m_serial;
83 std::map<qint64, Task> m_tasks;
84 std::map<QString, QPointer<QObject>, std::less<>> m_objs;
85 std::set<QPointer<QObject>> m_nokey_objs;