| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "iqmlcomponentfactory.h" |
| 7 | #include <memory> |
| 8 | #include <string_view> |
| 9 | |
| 10 | class IQMLComponentRegistry; |
| 11 | class QQuickItem; |
| 12 | |
| 13 | class QMLComponentFactory final : public IQMLComponentFactory |
| 14 | { |
| 15 | public: |
| 16 | QMLComponentFactory( |
| 17 | std::unique_ptr<IQMLComponentRegistry> &&qmlComponentRegistry) noexcept; |
| 18 | |
| 19 | void registerQMLTypes() const override; |
| 20 | |
| 21 | QMLItem *createQMLItem(std::string const &itemID, QQuickItem *parent, |
| 22 | QQmlApplicationEngine &qmlEngine) const override; |
| 23 | |
| 24 | QQuickItem *createQuickItem(std::string const &itemID, QQuickItem *parent, |
| 25 | std::string const &parentObjectName) const override; |
| 26 | |
| 27 | private: |
| 28 | /// Parent item to the first object that has parentObjectName as |
| 29 | /// object name (the parent itself or one of its children) |
| 30 | /// If there is no object with parentObjectName as object name, |
| 31 | /// the item is parented to parent. |
| 32 | void parentItem(QQuickItem *item, QQuickItem *parent, |
| 33 | std::string_view parentObjectName) const; |
| 34 | |
| 35 | std::unique_ptr<IQMLComponentRegistry> qmlComponentRegistry_; |
| 36 | }; |