ViewSolutions 1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Loading...
Searching...
No Matches
historynotificationsmodel.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2020-2025 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
9#include <QDebug>
10
11namespace ViewSolutions {
12
14 : QAbstractListModel{parent} {
15}
16
17int HistoryNotificationsModel::rowCount(const QModelIndex &parent) const {
18 Q_UNUSED(parent);
19 return notificationsList.count();
20}
21
22QVariant HistoryNotificationsModel::data(const QModelIndex &index, int role) const {
23 if(index.row() < 0 || index.row() >= notificationsList.count())
24 return QVariant();
25
26 switch (role) {
27 case Icon:
28 return notificationsList.at(index.row()).img();
29 case Title:
30 return notificationsList.at(index.row()).title();
31 case Message:
32 return notificationsList.at(index.row()).text();
33 case Type:
34 return notificationsList.at(index.row()).type();
35 default:
36 break;
37 }
38 return QVariant();
39}
40
41QHash<int, QByteArray> HistoryNotificationsModel::roleNames() const {
42 QHash<int, QByteArray> roles;
43 roles[Icon] = "icon";
44 roles[Title] = "title";
45 roles[Message] = "text";
46 roles[Type] = "type";
47 return roles;
48}
49
50
52 beginInsertRows({}, rowCount({}), rowCount({}));
53 notificationsList.append(notificationData);
54 endInsertRows();
55}
56
57void HistoryNotificationsModel::setHistory(const QList<NotificationData> &historyList) {
58 notificationsList = std::move(historyList);
59}
60
62 beginResetModel();
63 notificationsList.clear();
64 endResetModel();
65}
66
68 beginRemoveRows({}, elementIndex, elementIndex);
69 notificationsList.removeAt(elementIndex);
70 endRemoveRows();
71}
72
73}
void setHistory(const QList< ViewSolutions::NotificationData > &historyList)
setHistory replaces the complete history list with a new one.
Q_INVOKABLE void clearAllHistory()
clearAllHistory removes all notifications from the history.
QVariant data(const QModelIndex &index, int role) const override
Q_INVOKABLE void removeNotificationItemAtIndex(const int index)
removeNotificationItemAtIndex removes one notification from the history list.
int rowCount(const QModelIndex &parent) const override
void addHistoryObject(const ViewSolutions::NotificationData &notificationData)
addHistoryObject adds a new notification to the history list.
QHash< int, QByteArray > roleNames() const override
The NotificationData class view data for NotificationServiceView. This class contains a structure wit...
The ViewSolutions namespace.