| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef ITEMREGISTRY_H |
| 19 |
#define ITEMREGISTRY_H |
| 20 |
|
| 21 |
#include <QLoggingCategory> |
| 22 |
#include <QObject> |
| 23 |
#include <QPointer> |
| 24 |
#include <QQuickItem> |
| 25 |
#include <QQmlListProperty> |
| 26 |
#include "PluginIncubator.h" |
| 27 |
|
| 28 |
Q_DECLARE_LOGGING_CATEGORY(PLUGIN_ITEM_REGISTRY) |
| 29 |
|
| 30 |
class ItemRegistry : public QObject |
| 31 |
{ |
| 32 |
Q_OBJECT |
| 33 |
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged) |
| 34 |
Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged) |
| 35 |
Q_PROPERTY(QQmlListProperty<QQuickItem> defaultItems READ defaultItems) |
| 36 |
Q_PROPERTY(LoadMode loadMode READ loadMode WRITE setLoadMode NOTIFY loadModeChanged) |
| 37 |
Q_PROPERTY(QString pluginId MEMBER m_pluginId) |
| 38 |
|
| 39 |
Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asyncChanged) |
| 40 |
Q_ENUMS(LoadMode) |
| 41 |
|
| 42 |
public: |
| 43 |
explicit ItemRegistry(QObject *parent = 0); |
| 44 |
|
| 45 |
enum LoadMode { |
| 46 |
DefaultOnly, |
| 47 |
LoadFirstEnabled, |
| 48 |
LoadLastEnabled, |
| 49 |
LoadAll, |
| 50 |
LoadById |
| 51 |
}; |
| 52 |
|
| 53 |
QQuickItem *target() const; |
| 54 |
QString location() const; |
| 55 |
QQmlListProperty<QQuickItem> defaultItems(); |
| 56 |
|
| 57 |
LoadMode loadMode() const; |
| 58 |
bool asynchronous() const; |
| 59 |
|
| 60 |
Q_INVOKABLE QString findFirstEnabled(const QString &location); |
| 61 |
|
| 62 |
signals: |
| 63 |
void targetChanged(QQuickItem *target); |
| 64 |
void locationChanged(QString location); |
| 65 |
void loadModeChanged(LoadMode loadMode); |
| 66 |
|
| 67 |
void asyncChanged(bool asynchronous); |
| 68 |
|
| 69 |
public slots: |
| 70 |
void setTarget(QQuickItem *target); |
| 71 |
void setLocation(QString location); |
| 72 |
void setLoadMode(LoadMode loadMode); |
| 73 |
void setAsynchronous(bool asynchronous); |
| 74 |
|
| 75 |
private slots: |
| 76 |
void loadIfPossible(); |
| 77 |
void reparentItemToTarget(QQuickItem *item); |
| 78 |
void reparentItemsToTarget(QList<QQuickItem *> items); |
| 79 |
QQuickItem *createItemFromUrl(const QString &itemUrl); |
| 80 |
void createItemAsync(const QString &itemUrl); |
| 81 |
void asyncItemReady(); |
| 82 |
void handleIncubatorError(); |
| 83 |
|
| 84 |
private: |
| 85 |
LoadMode m_loadMode; |
| 86 |
QPointer<QQuickItem> m_target; |
| 87 |
QString m_location; |
| 88 |
QList<QQuickItem *> m_defaultItems; |
| 89 |
QString m_pluginId; |
| 90 |
bool m_asynchronous; |
| 91 |
IncubatorList m_incubators; |
| 92 |
}; |
| 93 |
|
| 94 |
#endif |