7#include "ItemBuilder.h"
14 m_component = component;
18 void setStateCallback(std::function<
void(
QQuickItem*)> callback)
20 m_stateCallback = callback;
23 void setCompletedCallback(std::function<
void(ItemIncubator*)> callback)
25 m_completedCallback = callback;
30 m_component->
create(*
this, m_context);
39 void setInitialState(
QObject *
object)
override
41 auto item = qobject_cast<QQuickItem*>(
object);
43 m_stateCallback(item);
50 qWarning() <<
"Could not create delegate in ItemBuilder";
52 for (
const auto &error : e) {
59 m_completedCallback(
this);
66 std::function<void(
QQuickItem*)> m_stateCallback;
67 std::function<void(ItemIncubator*)> m_completedCallback;
68 bool m_finished =
false;
71ItemBuilder::ItemBuilder(
QObject *parent)
76ItemBuilder::~ItemBuilder()
88 if (newComponent == m_component) {
92 m_component = newComponent;
101void ItemBuilder::setContext(
QQmlContext *newContext)
103 if (newContext == m_context) {
107 m_context = newContext;
112int ItemBuilder::count()
const
117void ItemBuilder::setCount(
int newCount)
119 if (newCount == m_count) {
129 return m_incubationMode;
134 if (newIncubationMode == m_incubationMode) {
138 m_incubationMode = newIncubationMode;
141QVariantMap ItemBuilder::initialProperties()
const
143 return m_initialProperties;
146void ItemBuilder::setInitialProperties(
const QVariantMap & newInitialProperties)
148 if (newInitialProperties == m_initialProperties) {
152 m_initialProperties = newInitialProperties;
157 if ((
int(m_items.size()) == m_count && m_incubators.empty()) || !m_incubators.empty() || !m_component) {
161 m_incubators.reserve(m_count);
162 std::fill_n(std::back_inserter(m_items), m_count, std::shared_ptr<QQuickItem>());
164 for (
int i = 0; i < m_count; ++i) {
165 auto context = m_context ? m_context : qmlContext(m_component);
166 auto incubator = std::make_unique<ItemIncubator>(m_component, context);
171 for (
auto itr = m_initialProperties.keyValueBegin(); itr != m_initialProperties.keyValueEnd(); ++itr) {
172 item->
setProperty((*itr).first.toUtf8().data(), (*itr).second);
175 Q_EMIT beginCreate(i, item);
178 incubator->setCompletedCallback([
this, i](ItemIncubator *incubator) {
182 Q_EMIT endCreate(i, item.get());
185 if (m_completed == m_count) {
187 m_incubators.clear();
195 m_incubators.push_back(std::move(incubator));
199bool ItemBuilder::isFinished()
const
201 return m_completed == m_count;
204std::vector<std::shared_ptr<QQuickItem>> ItemBuilder::items()
const
209void ItemBuilder::clear()
213 if (m_incubators.size() > 0) {
214 for (
auto &incubator : m_incubators) {
218 m_incubators.clear();
223#include "moc_ItemBuilder.cpp"
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QObject * parent() const const
T qobject_cast(QObject *object)
bool setProperty(const char *name, QVariant &&value)
virtual QObject * create(QQmlContext *context)
QList< QQmlError > errors() const const
QObject * object() const const
Status status() const const
void setParentItem(QQuickItem *parent)