SimpleQmlNotify/notificationservice.h

78 lines
2.0 KiB
C
Raw Normal View History

2019-11-19 15:20:38 +03:00
#ifndef NOTIFICATIONSERVICE_H
#define NOTIFICATIONSERVICE_H
#include "notificationdata.h"
#include <QObject>
namespace QmlNotificationService {
/**
* @brief The NotificationService class. This class used for working with notify.
2019-11-19 15:20:38 +03:00
*/
class NOTIFYSERVICESHARED_EXPORT NotificationService: public QObject
{
Q_OBJECT
Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged)
2021-01-18 23:20:03 +03:00
Q_PROPERTY(NotificationData question READ question NOTIFY questionChanged)
2019-11-19 15:20:38 +03:00
2021-01-18 23:20:03 +03:00
Q_PROPERTY(QList<NotificationData> history READ history NOTIFY notifyChanged)
2019-11-19 15:20:38 +03:00
public:
/**
* @brief Notify.
* @return notyfyData for qml.
2019-11-19 15:20:38 +03:00
*/
NotificationData notify() const;
2021-01-18 23:20:03 +03:00
NotificationData question() const;
2019-11-19 15:20:38 +03:00
/**
* @brief setNotify - Add new message for application.
* @param notify - Message data.
2019-11-19 15:20:38 +03:00
*/
void setNotify(const NotificationData &notify);
2021-01-18 23:20:03 +03:00
void setQuestion(const NotificationData& question);
Q_INVOKABLE void questionComplete(bool accepted, int code = 0);
2019-11-19 15:20:38 +03:00
Q_INVOKABLE void setNotify(const QString& title = "",
const QString& text = "",
const QString& img = "",
int type = NotificationData::Normal);
2021-01-18 23:20:03 +03:00
Q_INVOKABLE void setQuestion(const QString& title = "",
const QString& text = "",
const QString& img = "",
int code = 0);
2019-11-19 15:20:38 +03:00
/**
* @brief getService - This method return instance to notify service.
* @return pointer to service.
2019-11-19 15:20:38 +03:00
*/
static NotificationService* getService();
/**
* @brief history - This method used for return notify list.
* @return list of all notify.
2019-11-19 15:20:38 +03:00
*/
const QList<NotificationData> & history() const;
signals:
void notifyChanged();
2021-01-18 23:20:03 +03:00
void questionChanged();
void questionCompleted(bool accepted, int questionCode);
private:
explicit NotificationService(QObject *ptr = nullptr);
NotificationData _question;
NotificationData _notify;
QList<NotificationData> _history;
2019-11-19 15:20:38 +03:00
};
}
#endif // NOTIFICATIONSERVICE_H