mirror of
https://github.com/QuasarApp/SimpleQmlNotify.git
synced 2025-04-26 13:44:34 +00:00
There were added historynotificationsmodel and historynotificationsview
This commit is contained in:
parent
b50d78111c
commit
1c6e7f06bc
@ -16,6 +16,7 @@
|
||||
<file>qmlNotify_languages/fr.qm</file>
|
||||
<file>qmlNotify_languages/de.qm</file>
|
||||
<file>qmlNotify_languages/zh.qm</file>
|
||||
<file>NotifyModule/NotificationHistoryView.qml</file>
|
||||
</qresource>
|
||||
<qresource prefix="/icons">
|
||||
<file alias="warning">icons/Warning.png</file>
|
||||
|
@ -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
|
||||
}
|
||||
|
171
NotifyModule/NotificationHistoryView.qml
Normal file
171
NotifyModule/NotificationHistoryView.qml
Normal file
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
@ -73,4 +73,11 @@ Item {
|
||||
questionMsgBox._show();
|
||||
}
|
||||
}
|
||||
|
||||
NotificationHistoryView {
|
||||
id: history
|
||||
width: parent.width * 0.6
|
||||
height: parent.height * 0.5
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
|
59
historynotificationsmodel.cpp
Normal file
59
historynotificationsmodel.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "historynotificationsmodel.h"
|
||||
#include <QDebug>
|
||||
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<int, QByteArray> HistoryNotificationsModel::roleNames() const {
|
||||
QHash<int, QByteArray> 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();
|
||||
}
|
||||
|
40
historynotificationsmodel.h
Normal file
40
historynotificationsmodel.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef HISTORYNOTIFICATIONMODEL_H
|
||||
#define HISTORYNOTIFICATIONMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#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<int, QByteArray> 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<QmlNotificationService::NotificationData> notificationsList;
|
||||
int m_notificationsCount;
|
||||
};
|
||||
|
||||
#endif // HISTORYNOTIFICATIONMODEL_H
|
@ -13,7 +13,6 @@ namespace QmlNotificationService {
|
||||
NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
|
||||
qRegisterMetaType<NotificationData>("NotificationData");
|
||||
qRegisterMetaType<QList<NotificationData>> ("QList<NotificationData>");
|
||||
|
||||
}
|
||||
|
||||
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<NotificationData> &NotificationService::history() const {
|
||||
return _history;
|
||||
}
|
||||
//const QList<NotificationData> &NotificationService::history() const {
|
||||
// return _history;
|
||||
//}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define NOTIFICATIONSERVICE_H
|
||||
|
||||
#include "notificationdata.h"
|
||||
#include "historynotificationsmodel.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
@ -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<NotificationData> 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<NotificationData> & history() const;
|
||||
// const HistoryNotificationModel & history() const;
|
||||
|
||||
signals:
|
||||
/**
|
||||
@ -145,7 +146,7 @@ private:
|
||||
QHash<int, Listner> _listners;
|
||||
NotificationData _question;
|
||||
NotificationData _notify;
|
||||
QList<NotificationData> _history;
|
||||
HistoryNotificationsModel _history;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user