From 1ee7405ea8cb69f55f8c7dc40871d7edcb8b09df Mon Sep 17 00:00:00 2001 From: EndrII Date: Thu, 15 Apr 2021 17:14:57 +0300 Subject: [PATCH] updated questions and added documentation about questions --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++- notificationdata.cpp | 4 ++++ notificationdata.h | 6 +++++ notificationservice.cpp | 5 +++- notificationservice.h | 3 ++- 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e908a6..92e498d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,9 @@ Simple Qml notification service for qml applications. * Rebuild yuor project -## Use +## Using + +### Notification ### CPP ``` cpp @@ -62,3 +64,52 @@ Simple Qml notification service for qml applications. } ``` + +### Questions + + +### CPP +``` cpp + #include + + 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) + } + } +} + +``` diff --git a/notificationdata.cpp b/notificationdata.cpp index e28660c..800ca1c 100644 --- a/notificationdata.cpp +++ b/notificationdata.cpp @@ -48,4 +48,8 @@ int NotificationData::type() const { bool NotificationData::isValid() const { return _text.size() || _title.size() || _img.size(); } + +void NotificationData::setCode(int code) { + _type = code; +} } diff --git a/notificationdata.h b/notificationdata.h index ef777ec..035612c 100644 --- a/notificationdata.h +++ b/notificationdata.h @@ -70,6 +70,12 @@ public: */ 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); diff --git a/notificationservice.cpp b/notificationservice.cpp index 48c09d5..736ce93 100644 --- a/notificationservice.cpp +++ b/notificationservice.cpp @@ -31,10 +31,13 @@ void NotificationService::setNotify(const NotificationData& notify) { emit notifyChanged(); } -void NotificationService::setQuestion(const NotificationData &question) { +int NotificationService::setQuestion(const NotificationData &question) { _question = question; + _question.setCode(rand() % std::numeric_limits().max()); emit questionChanged(); + + return _question.type(); } void NotificationService::questionComplete(bool accepted, int code) { diff --git a/notificationservice.h b/notificationservice.h index 426e763..63f3a65 100644 --- a/notificationservice.h +++ b/notificationservice.h @@ -41,8 +41,9 @@ public: /** * @brief setQuestion This method sets information of the users 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.