ViewSolutions 1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Loading...
Searching...
No Matches
notificationservice.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the GPLv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
9
10namespace ViewSolutions {
11
12NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
13 qRegisterMetaType<NotificationData>("NotificationData");
14 qRegisterMetaType<QList<NotificationData>> ("QList<NotificationData>");
15 _history = new HistoryNotificationsModel();
16 QQmlEngine::setObjectOwnership(_history, QQmlEngine::CppOwnership);
17
18 connect(_history, &HistoryNotificationsModel::rowsInserted, this, &NotificationService::countNotificationsChanged);
19 connect(_history, &HistoryNotificationsModel::rowsRemoved, this, &NotificationService::countNotificationsChanged);
20 connect(_history, &HistoryNotificationsModel::modelReset, this, &NotificationService::countNotificationsChanged);
21}
22
26
28 return _notify;
29}
30
32 return _question;
33}
34
36 if (_notify != notify) {
37 _history->addHistoryObject(notify);
38 }
39 _notify = notify;
40
41 emit notifyChanged();
42}
43
45
46 _question = question;
47 int questionCode = rand();
48 _question.setCode(questionCode);
49 emit questionChanged();
50
51 _listners[questionCode] = listner;
52
53 return _question.type();
54}
55
56void NotificationService::questionComplete(bool accepted, int code) {
57
58 if (_listners.contains(code)) {
59 auto listner = _listners.value(code);
60 listner(accepted);
61 _listners.remove(code);
62 }
63
64 emit questionCompleted(accepted, code);
65}
66
67void NotificationService::setNotify(const QString &title,
68 const QString &text,
69 const QString &img,
70 int type) {
71
72 setNotify(NotificationData(title, text, img,
73 static_cast<NotificationData::Type>(type)));
74}
75
76int NotificationService::setQuestion(QObject *listnerObject,
77 const QString &listnerMethod,
78 const QString &title,
79 const QString &text,
80 const QString &img,
81 int code) {
82
83 Listner listner = [listnerObject, listnerMethod](bool accept) {
84
85 const QByteArray stringData = listnerMethod.toLatin1();
86 char method[100];
87 method[qMin(99, stringData.size())] = '\0';
88 std::copy(stringData.constBegin(), stringData.constBegin() + qMin(99, stringData.size()), method);
89
90 QMetaObject::invokeMethod(listnerObject, method,
91 Qt::QueuedConnection, Q_ARG(bool, accept));
92 };
93
94 return setQuestion(listner, NotificationData(title, text, img, code));
95}
96
98 const QString &title,
99 const QString &text,
100 const QString &img,
101 int code) {
102
103 return setQuestion(listner, NotificationData(title, text, img, code));
104}
105
106
107NotificationService *NotificationService::getService() {
108 static auto service = new NotificationService;
109 return service;
110}
111
113 return _history;
114}
115
119
121 return _history->rowCount({});
122}
123
124
126 return "NotificationService";
127}
128
129}
130
The NotificationData class view data for NotificationServiceView. This class contains a structure wit...
Type
The Type enum This enum contatins all available types of the notification messages.
void notifyChanged()
notifyChanged This signal emited whet the notificator (Ths object) received a new notification messag...
void setNotify(const NotificationData &notify)
setNotify This method add new notification message of application.
void sigShowHistory()
sigShowHistory This signal is emitted when the notification history view should be shown (see showHis...
void questionChanged()
questionChanged This signal emited whet the notificator (Ths object) received a new question message.
int setQuestion(const Listner &listner, const NotificationData &question)
setQuestion This method sets information of the users question.
Q_INVOKABLE void questionComplete(bool accepted, int code=0)
questionComplete This method is main responce method of the users questions.
Q_INVOKABLE void showHistory()
showHistory - This method used for emit signal by which show notification menu.
void questionCompleted(bool accepted, int questionCode)
questionCompleted This signal emited when youser clcik any buttons on question popup.
static NotificationService * getService()
getService This method return instance to notify service.
QString modelId() const override
modelId returns text model id. override this method to provide access to model in qml or other models...
The ViewSolutions namespace.
std::function< void(bool accept)> Listner
Listner This is listner lyambda function of user ansver. This function has next signature: void(bool ...