ComponentManager.h 962 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef __COMPONENT_MANAGER_H__
  2. #define __COMPONENT_MANAGER_H__
  3. #include <QObject>
  4. #include <QMap>
  5. #include <QQmlContext>
  6. #include <QQmlPropertyMap>
  7. #include <QWebChannel>
  8. #include "utils/Utils.h"
  9. class ComponentBase : public QObject
  10. {
  11. public:
  12. explicit ComponentBase(QObject* parent = nullptr) : QObject(parent) { }
  13. virtual bool componentInitialize() = 0;
  14. virtual const char* componentName() = 0;
  15. virtual bool componentExport() = 0;
  16. // executed after ALL components are initialized
  17. virtual void componentPostInitialize() { }
  18. };
  19. class ComponentManager : public QObject
  20. {
  21. Q_OBJECT
  22. DEFINE_SINGLETON(ComponentManager);
  23. public:
  24. void initialize();
  25. inline QQmlPropertyMap &getQmlPropertyMap() { return m_qmlProperyMap; }
  26. void setWebChannel(QWebChannel* webChannel);
  27. private:
  28. ComponentManager();
  29. void registerComponent(ComponentBase* comp);
  30. QMap<QString, ComponentBase*> m_components;
  31. QQmlPropertyMap m_qmlProperyMap;
  32. };
  33. #endif