SimpleQmlNotify/notificationservice.h

121 lines
4.1 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:
/**
2021-04-15 15:56:38 +03:00
* @brief Notify This method return data of the last notify message.
* @return return data of the last notify message.
2019-11-19 15:20:38 +03:00
*/
NotificationData notify() const;
2021-04-15 15:56:38 +03:00
/**
* @brief question This method return data of the last question.
* @return question data.
*/
2021-01-18 23:20:03 +03:00
NotificationData question() const;
2019-11-19 15:20:38 +03:00
/**
2021-04-15 15:56:38 +03:00
* @brief setNotify This method add new notification message of application.
* @param notify are message data.
2019-11-19 15:20:38 +03:00
*/
void setNotify(const NotificationData &notify);
2021-04-15 15:56:38 +03:00
/**
* @brief setQuestion This method sets information of the users question.
* @param question are data of the question.
*/
2021-01-18 23:20:03 +03:00
void setQuestion(const NotificationData& question);
2021-04-15 15:56:38 +03:00
/**
* @brief questionComplete This method is main responce method of the users questions.
* @param accepted are boolean option. Set this option to true if user click on accept button.
* @param code are automaticly generated code fo the question.
*/
2021-01-18 23:20:03 +03:00
Q_INVOKABLE void questionComplete(bool accepted, int code = 0);
2021-04-15 15:56:38 +03:00
/**
* @brief setNotify This method set new notify message for user. When notify changed on main application windows shows notify message.
* @param title are title of a notify window.
* @param text are text value of a notify window.
* @param img are url to image of a notify window.
* @param type are code of a notification type. For more information about notification type see the NotificationData enum.
*/
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-04-15 15:56:38 +03:00
/**
* @brief setQuestion This method set new question for user. When question changed on main application windows shows question.
* @param title are title of a question window.
* @param text are text value of a question window.
* @param img are url to image of a queston window.
* @param code are code of question. This code must be sendet to the questionComplete method after buttons clik.
*/
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
/**
2021-04-15 15:56:38 +03:00
* @brief getService This method return instance to notify service.
* @return pointer to the notification 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:
2021-04-15 15:56:38 +03:00
/**
* @brief notifyChanged This signal emited whet the notificator (Ths object) received a new notification message.
*/
2019-11-19 15:20:38 +03:00
void notifyChanged();
2021-04-15 15:56:38 +03:00
/**
* @brief questionChanged This signal emited whet the notificator (Ths object) received a new question message.
*/
2021-01-18 23:20:03 +03:00
void questionChanged();
2021-04-15 15:56:38 +03:00
/**
* @brief questionCompleted This signal emited when youser clcik any buttons on question popup.
* @param accepted are bool option with "true" value if the yesr click to accept button.
* @param questionCode are automaticly generated code of the question.
* For more information about code option see the setQuestion method.
*/
2021-01-18 23:20:03 +03:00
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