mirror of
https://github.com/QuasarApp/SimpleQmlNotify.git
synced 2025-04-29 07:04:36 +00:00
updated questions and added documentation about questions
This commit is contained in:
parent
65ba064f89
commit
1ee7405ea8
53
README.md
53
README.md
@ -38,7 +38,9 @@ Simple Qml notification service for qml applications.
|
|||||||
* Rebuild yuor project
|
* Rebuild yuor project
|
||||||
|
|
||||||
|
|
||||||
## Use
|
## Using
|
||||||
|
|
||||||
|
### Notification
|
||||||
|
|
||||||
### CPP
|
### CPP
|
||||||
``` cpp
|
``` cpp
|
||||||
@ -62,3 +64,52 @@ Simple Qml notification service for qml applications.
|
|||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Questions
|
||||||
|
|
||||||
|
|
||||||
|
### CPP
|
||||||
|
``` 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.
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### QML
|
||||||
|
|
||||||
|
``` 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
@ -48,4 +48,8 @@ int NotificationData::type() const {
|
|||||||
bool NotificationData::isValid() const {
|
bool NotificationData::isValid() const {
|
||||||
return _text.size() || _title.size() || _img.size();
|
return _text.size() || _title.size() || _img.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotificationData::setCode(int code) {
|
||||||
|
_type = code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE bool isValid() const;
|
Q_INVOKABLE bool isValid() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setCode This method sets new code of the question.
|
||||||
|
* @param code are new value of the code.
|
||||||
|
*/
|
||||||
|
void setCode(int code);
|
||||||
|
|
||||||
bool operator ==(const NotificationData &righ);
|
bool operator ==(const NotificationData &righ);
|
||||||
bool operator !=(const NotificationData &righ);
|
bool operator !=(const NotificationData &righ);
|
||||||
|
|
||||||
|
@ -31,10 +31,13 @@ void NotificationService::setNotify(const NotificationData& notify) {
|
|||||||
emit notifyChanged();
|
emit notifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationService::setQuestion(const NotificationData &question) {
|
int NotificationService::setQuestion(const NotificationData &question) {
|
||||||
|
|
||||||
_question = question;
|
_question = question;
|
||||||
|
_question.setCode(rand() % std::numeric_limits<int>().max());
|
||||||
emit questionChanged();
|
emit questionChanged();
|
||||||
|
|
||||||
|
return _question.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationService::questionComplete(bool accepted, int code) {
|
void NotificationService::questionComplete(bool accepted, int code) {
|
||||||
|
@ -41,8 +41,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief setQuestion This method sets information of the users question.
|
* @brief setQuestion This method sets information of the users question.
|
||||||
* @param question are data of the question.
|
* @param question are data of the question.
|
||||||
|
* @return return question code. You must be save this code for check ansver of your qestion.
|
||||||
*/
|
*/
|
||||||
void setQuestion(const NotificationData& question);
|
int setQuestion(const NotificationData& question);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief questionComplete This method is main responce method of the users questions.
|
* @brief questionComplete This method is main responce method of the users questions.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user