-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqmlnotifyservice.h
79 lines (67 loc) · 2.17 KB
/
qmlnotifyservice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (C) 2018-2024 QuasarApp.
* Distributed under the GPLv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
#ifndef QMLNOTIFYSERVICE_H
#define QMLNOTIFYSERVICE_H
#include "notifyservice_global.h"
#include "notificationservice.h"
class QQmlApplicationEngine;
inline void initSNotufyResources() { Q_INIT_RESOURCE(NotifyModule); }
/**
* Simple notify service for qml.
* Use :
* @code{cpp}
* #include <qmlnotifyservice.h>
* QmlNotificationService::init();
* auto service = QmlNotificationService::NotificationService::getService()
* service->setNotify("title", "text", "UrlOfImage", NotificationData::Normal)
* @endcode
*
* in qml :
* @code{qml}
* NotificationServiceView {
anchors.fill: parent;
}
* @endcode
* Questions
* CPP
* @code{cpp}
#include <qmlnotifyservice.h>
int main() {
QmlNotificationService::init();
auto service = QmlNotificationService::NotificationService::getService();
int questionCode = service->setQuestion("title", "some text");
QObject::connect(service, QmlNotificationService::NotificationService::questionCompleted,
[questionCode](bool accepted, int questionCode) {
if (accepted && code === questionCode) {
// your action here.
}
})
}
* @endcode
* QML
* @code{qml}
NotificationServiceView {
anchors.fill: parent;
}
readonly property int questionCode: 0;
questionCode = notificationService.setQuestion(qsTr("Remove %0 user").arg(userModel.userId),
qsTr("All saved data and records will be delete, Do you want continuee?"))
Connections {
target: notificationService
function onQuestionCompleted(accepted, code) {
if (accepted && code === privateRoot.questionCode) {
if (userModel)
backEnd.removeUser(userModel.userId)
}
}
}
* @endcode
*/
namespace QmlNotificationService {
bool NOTIFYSERVICESHARED_EXPORT init(QQmlApplicationEngine *engine);
}
#endif // QMLNOTIFYSERVICE_H