diff --git a/NotifyModule.qrc b/NotifyModule.qrc
index 68a69a8..ab6d6ac 100644
--- a/NotifyModule.qrc
+++ b/NotifyModule.qrc
@@ -16,6 +16,7 @@
qmlNotify_languages/fr.qm
qmlNotify_languages/de.qm
qmlNotify_languages/zh.qm
+ NotifyModule/NotificationHistoryView.qml
icons/Warning.png
diff --git a/NotifyModule/NotificationForm.qml b/NotifyModule/NotificationForm.qml
index fc56a2f..86ff02b 100644
--- a/NotifyModule/NotificationForm.qml
+++ b/NotifyModule/NotificationForm.qml
@@ -61,6 +61,15 @@ BasePopUp {
Layout.fillWidth: true
}
+ ToolButton {
+ text: "History"
+ font.pointSize: 10
+ onClicked: {
+ history.open()
+ popup.close()
+ }
+ }
+
ToolButton {
text: "X"
onClicked: {
@@ -151,10 +160,9 @@ BasePopUp {
}
-
-
}
}
+
title: titleText
}
diff --git a/NotifyModule/NotificationHistoryView.qml b/NotifyModule/NotificationHistoryView.qml
new file mode 100644
index 0000000..00b535c
--- /dev/null
+++ b/NotifyModule/NotificationHistoryView.qml
@@ -0,0 +1,171 @@
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Controls.Material 2.15
+
+Popup {
+ id: root
+
+ readonly property var historyModel: historyNotificationsModel
+
+ ToolBar {
+ id: toolbar
+ width: parent.width
+ height: parent.height * 0.1
+ anchors {
+ top: parent.top
+ left: parent.left
+ right: parent.right
+ }
+
+ ToolButton {
+ id: clearAllButton
+ text: qsTr("Clear All")
+ height: parent.height
+ font.pointSize: 10
+ anchors {
+ left: parent.left
+ verticalCenter: parent.verticalCenter
+ }
+
+ onClicked: historyModel.clearAllHistory()
+ }
+
+ Label {
+ id: toolbarTitle
+ text: qsTr("Notification history")
+ font.pointSize: 12
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ verticalCenter: parent.verticalCenter
+ }
+ }
+
+ ToolButton {
+ id: closePopupButton
+ text: "X"
+ font.pointSize: 12
+ anchors {
+ right: parent.right
+ verticalCenter: parent.verticalCenter
+ }
+
+ onClicked: root.close()
+ }
+ }
+
+ ListView {
+ id: notificationLV
+ width: parent.width
+ height: parent.height * 0.9
+ clip: true
+ model: historyModel
+ anchors {
+ top: toolbar.bottom
+ horizontalCenter: parent.horizontalCenter
+ }
+
+ ScrollBar.vertical: ScrollBar {
+ hoverEnabled: true
+ active: hovered || pressed
+ anchors {
+ top: notificationLV.top
+ right: notificationLV.right
+ bottom: notificationLV.bottom
+ }
+ }
+
+ delegate: SwipeDelegate {
+ id: swipeDelegate
+ text: model.notificationValue
+ width: notificationLV.width
+ height: notificationLV.height * 0.15
+
+ ListView.onRemove: SequentialAnimation {
+
+ PropertyAction {
+ target: swipeDelegate
+ property: "ListView.delayRemove"
+ value: true
+ }
+
+
+ NumberAnimation {
+ target: swipeDelegate
+ property: "height"
+ to: 0
+ duration: 20
+ easing.type: Easing.InOutQuad
+ }
+
+
+ PropertyAction {
+ target: swipeDelegate;
+ property: "ListView.delayRemove"
+ value: false
+ }
+ }
+
+ Image {
+ id: notificationIcon
+ width: notificationIcon.sourceSize.width * 0.25
+ height: notificationIcon.sourceSize.height * 0.25
+ source: model.icon
+ fillMode: Image.PreserveAspectFit
+ anchors {
+ left: parent.left
+ leftMargin: parent.width * 0.1
+ verticalCenter: parent.verticalCenter
+ }
+ }
+
+ Column {
+ id: column
+ width: parent.width * 0.25
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ verticalCenter: parent.verticalCenter
+ }
+
+ Label {
+ id: notificationTitle
+ text: qsTr(model.title)
+ font.pointSize: 12
+ clip: true
+ }
+
+ Label {
+ id: notificationText
+ text: qsTr(model.text)
+ font.pointSize: 12
+ wrapMode: Text.WordWrap
+ clip: true
+ linkColor: Material.accent
+ }
+ }
+
+ swipe.right: Label {
+ id: deleteLabel
+ text: qsTr("Delete")
+ color: "white"
+ verticalAlignment: Label.AlignVCenter
+ padding: 12
+ height: parent.height
+ anchors.right: parent.right
+
+
+ SwipeDelegate.onClicked: notificationLV.model.removeNotificationItemAtIndex(index)
+
+ background: Rectangle {
+ color: deleteLabel.SwipeDelegate.pressed? "red" : "gray"
+ }
+ }
+ }
+ }
+
+ Connections {
+ target: historyModel
+ function onDataInserted() {
+ console.log(Object.keys(historyModel))
+ }
+ }
+}
diff --git a/NotifyModule/NotificationServiceView.qml b/NotifyModule/NotificationServiceView.qml
index 82ff844..27dd1c7 100644
--- a/NotifyModule/NotificationServiceView.qml
+++ b/NotifyModule/NotificationServiceView.qml
@@ -73,4 +73,11 @@ Item {
questionMsgBox._show();
}
}
+
+ NotificationHistoryView {
+ id: history
+ width: parent.width * 0.6
+ height: parent.height * 0.5
+ anchors.centerIn: parent
+ }
}
diff --git a/historynotificationsmodel.cpp b/historynotificationsmodel.cpp
new file mode 100644
index 0000000..b1d5eb2
--- /dev/null
+++ b/historynotificationsmodel.cpp
@@ -0,0 +1,59 @@
+#include "historynotificationsmodel.h"
+#include
+HistoryNotificationsModel::HistoryNotificationsModel(QObject *parent)
+ : QAbstractListModel{parent} {
+}
+
+int HistoryNotificationsModel::rowCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return notificationsList.count();
+}
+
+QVariant HistoryNotificationsModel::data(const QModelIndex &index, int role) const {
+ if(index.row() < 0 || index.row() >= notificationsList.count())
+ return QVariant();
+
+ switch (role) {
+ case Icon:
+ return notificationsList.at(index.row()).img();
+ case Title:
+ return notificationsList.at(index.row()).title();
+ case Message:
+ return notificationsList.at(index.row()).text();
+ case Type:
+ return notificationsList.at(index.row()).type();
+ default:
+ break;
+ }
+ return QVariant();
+}
+
+QHash HistoryNotificationsModel::roleNames() const {
+ QHash roles;
+ roles[Icon] = "icon";
+ roles[Title] = "title";
+ roles[Message] = "text";
+ roles[Type] = "type";
+ return roles;
+}
+
+
+void HistoryNotificationsModel::setHistory(const QmlNotificationService::NotificationData ¬ificationData) {
+ beginResetModel();
+ notificationsList.push_back(notificationData);
+ endResetModel();
+ emit dataInserted();
+}
+
+void HistoryNotificationsModel::clearAllHistory() {
+ beginResetModel();
+ notificationsList.clear();
+ endResetModel();
+}
+
+void HistoryNotificationsModel::removeNotificationItemAtIndex(const int elementIndex) {
+ beginResetModel();
+ notificationsList.removeAt(elementIndex);
+ endResetModel();
+}
+
diff --git a/historynotificationsmodel.h b/historynotificationsmodel.h
new file mode 100644
index 0000000..66432ae
--- /dev/null
+++ b/historynotificationsmodel.h
@@ -0,0 +1,40 @@
+#ifndef HISTORYNOTIFICATIONMODEL_H
+#define HISTORYNOTIFICATIONMODEL_H
+
+#include
+#include "notificationdata.h"
+
+class HistoryNotificationsModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+ enum Roles {
+ Icon = Qt::UserRole + 1,
+ Title,
+ Message,
+ Type
+ };
+
+ Q_PROPERTY(int notificationsCount READ getNotificationsCount WRITE setNotificationsCount NOTIFY notificationsCountChanged)
+
+public:
+ explicit HistoryNotificationsModel(QObject *parent = nullptr);
+
+ int rowCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ QHash roleNames() const override;
+ void setHistory(const QmlNotificationService::NotificationData ¬ificationData);
+ Q_INVOKABLE void clearAllHistory();
+
+ Q_INVOKABLE void removeNotificationItemAtIndex(const int index);
+
+
+signals:
+ void dataInserted();
+
+private:
+ QList notificationsList;
+ int m_notificationsCount;
+};
+
+#endif // HISTORYNOTIFICATIONMODEL_H
diff --git a/notificationservice.cpp b/notificationservice.cpp
index c461c8e..2f7430d 100644
--- a/notificationservice.cpp
+++ b/notificationservice.cpp
@@ -13,7 +13,6 @@ namespace QmlNotificationService {
NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
qRegisterMetaType("NotificationData");
qRegisterMetaType> ("QList");
-
}
NotificationData NotificationService::notify() const {
@@ -25,9 +24,9 @@ NotificationData NotificationService::question() const {
}
void NotificationService::setNotify(const NotificationData& notify) {
- if (_notify != notify)
- _history.push_back(_notify);
-
+ if (_notify != notify) {
+ _history.setHistory(notify);
+ }
_notify = notify;
emit notifyChanged();
@@ -104,8 +103,8 @@ NotificationService *NotificationService::getService() {
return service;
}
-const QList &NotificationService::history() const {
- return _history;
-}
+//const QList &NotificationService::history() const {
+// return _history;
+//}
}
diff --git a/notificationservice.h b/notificationservice.h
index d6b0a7e..4eabdbb 100644
--- a/notificationservice.h
+++ b/notificationservice.h
@@ -2,6 +2,7 @@
#define NOTIFICATIONSERVICE_H
#include "notificationdata.h"
+#include "historynotificationsmodel.h"
#include
#include
@@ -23,7 +24,7 @@ class NOTIFYSERVICESHARED_EXPORT NotificationService: public QObject
Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged)
Q_PROPERTY(NotificationData question READ question NOTIFY questionChanged)
- Q_PROPERTY(QList history READ history NOTIFY notifyChanged)
+ //Q_PROPERTY(HistoryNotificationModel history READ history NOTIFY notifyChanged)
public:
/**
@@ -117,7 +118,7 @@ public:
* @brief history - This method used for return notify list.
* @return list of all notify.
*/
- const QList & history() const;
+ // const HistoryNotificationModel & history() const;
signals:
/**
@@ -145,7 +146,7 @@ private:
QHash _listners;
NotificationData _question;
NotificationData _notify;
- QList _history;
+ HistoryNotificationsModel _history;
};
}