2023-09-11 18:10:50 +08:00
|
|
|
#ifndef FLUEVENTBUS_H
|
|
|
|
#define FLUEVENTBUS_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtQml/qqml.h>
|
|
|
|
#include "stdafx.h"
|
2023-09-13 15:11:22 +08:00
|
|
|
#include "singleton.h"
|
2023-09-11 18:10:50 +08:00
|
|
|
|
2024-02-27 12:23:24 +08:00
|
|
|
/**
|
|
|
|
* @brief The FluEvent class
|
|
|
|
*/
|
2023-09-11 18:10:50 +08:00
|
|
|
class FluEvent : public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY_AUTO(QString,name);
|
|
|
|
QML_NAMED_ELEMENT(FluEvent)
|
|
|
|
public:
|
|
|
|
explicit FluEvent(QObject *parent = nullptr);
|
|
|
|
Q_SIGNAL void triggered(QMap<QString, QVariant> data);
|
|
|
|
};
|
|
|
|
|
2024-02-27 12:23:24 +08:00
|
|
|
/**
|
|
|
|
* @brief The FluEventBus class
|
|
|
|
*/
|
2023-09-11 18:10:50 +08:00
|
|
|
class FluEventBus : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
QML_NAMED_ELEMENT(FluEventBus)
|
|
|
|
QML_SINGLETON
|
|
|
|
private:
|
|
|
|
explicit FluEventBus(QObject *parent = nullptr);
|
|
|
|
public:
|
2024-01-04 00:08:34 +08:00
|
|
|
SINGLETON(FluEventBus)
|
2023-09-13 15:11:22 +08:00
|
|
|
static FluEventBus *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
2023-09-11 18:10:50 +08:00
|
|
|
Q_INVOKABLE void registerEvent(FluEvent* event);
|
|
|
|
Q_INVOKABLE void unRegisterEvent(FluEvent* event);
|
|
|
|
Q_INVOKABLE void post(const QString& name,const QMap<QString, QVariant>& params = {});
|
|
|
|
private:
|
2023-09-13 15:11:22 +08:00
|
|
|
QList<FluEvent*> _eventData;
|
2023-09-11 18:10:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FLUEVENTBUS_H
|