| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "qmlitem.h" |
| 5 | |
| 6 | #include "iqmlcomponentfactory.h" |
| 7 | #include <Qt> |
| 8 | |
| 9 | QString const &QMLItem::name() const |
| 10 | { |
| 11 | return name_; |
| 12 | } |
| 13 | |
| 14 | void QMLItem::setName(QString const &name) |
| 15 | { |
| 16 | if (name_ != name) { |
| 17 | name_ = name; |
| 18 | emit nameChanged(); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | void QMLItem::setupChild(QQuickItem *child) |
| 23 | { |
| 24 | auto qmlItemChild = dynamic_cast<QMLItem *>(child); |
| 25 | if (qmlItemChild != nullptr) |
| 26 | connect(qmlItemChild, &QMLItem::settingsChanged, this, |
| 27 | &QMLItem::settingsChanged, Qt::UniqueConnection); |
| 28 | } |
| 29 | |
| 30 | QMLItem::Initializer::Initializer(IQMLComponentFactory const &qmlComponentFactory, |
| 31 | QQmlApplicationEngine &qmlEngine) noexcept |
| 32 | : qmlComponentFactory_(qmlComponentFactory) |
| 33 | , qmlEngine_(qmlEngine) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | std::pair<std::optional<std::reference_wrapper<Exportable::Exporter>>, QMLItem *> |
| 38 | QMLItem::Initializer::initializer(std::string const &itemID, QMLItem *parent) |
| 39 | { |
| 40 | auto item = qmlComponentFactory_.createQMLItem(itemID, parent, qmlEngine_); |
| 41 | if (item != nullptr) { |
| 42 | auto factory = item->initializer(qmlComponentFactory_, qmlEngine_); |
| 43 | if (factory != nullptr) { |
| 44 | initializers_.emplace_back(std::move(factory)); |
| 45 | return {*initializers_.back(), item}; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return {}; |
| 50 | } |