ViewSolutions
1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Toggle main menu visibility
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
8
#include "
historynotificationsmodel.h
"
9
#include <QDebug>
10
11
namespace
ViewSolutions
{
12
13
HistoryNotificationsModel::HistoryNotificationsModel
(QObject *parent)
14
: QAbstractListModel{parent} {
15
}
16
17
int
HistoryNotificationsModel::rowCount
(
const
QModelIndex &parent)
const
{
18
Q_UNUSED(parent);
19
return
notificationsList.count();
20
}
21
22
QVariant
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
41
QHash<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
51
void
HistoryNotificationsModel::addHistoryObject
(
const
NotificationData
¬ificationData) {
52
beginInsertRows({},
rowCount
({}),
rowCount
({}));
53
notificationsList.append(notificationData);
54
endInsertRows();
55
}
56
57
void
HistoryNotificationsModel::setHistory
(
const
QList<NotificationData> &historyList) {
58
notificationsList = std::move(historyList);
59
}
60
61
void
HistoryNotificationsModel::clearAllHistory
() {
62
beginResetModel();
63
notificationsList.clear();
64
endResetModel();
65
}
66
67
void
HistoryNotificationsModel::removeNotificationItemAtIndex
(
const
int
elementIndex) {
68
beginRemoveRows({}, elementIndex, elementIndex);
69
notificationsList.removeAt(elementIndex);
70
endRemoveRows();
71
}
72
73
}
ViewSolutions::HistoryNotificationsModel::setHistory
void setHistory(const QList< ViewSolutions::NotificationData > &historyList)
setHistory replaces the complete history list with a new one.
Definition
historynotificationsmodel.cpp:57
ViewSolutions::HistoryNotificationsModel::clearAllHistory
Q_INVOKABLE void clearAllHistory()
clearAllHistory removes all notifications from the history.
Definition
historynotificationsmodel.cpp:61
ViewSolutions::HistoryNotificationsModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition
historynotificationsmodel.cpp:22
ViewSolutions::HistoryNotificationsModel::removeNotificationItemAtIndex
Q_INVOKABLE void removeNotificationItemAtIndex(const int index)
removeNotificationItemAtIndex removes one notification from the history list.
Definition
historynotificationsmodel.cpp:67
ViewSolutions::HistoryNotificationsModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition
historynotificationsmodel.cpp:17
ViewSolutions::HistoryNotificationsModel::addHistoryObject
void addHistoryObject(const ViewSolutions::NotificationData ¬ificationData)
addHistoryObject adds a new notification to the history list.
Definition
historynotificationsmodel.cpp:51
ViewSolutions::HistoryNotificationsModel::roleNames
QHash< int, QByteArray > roleNames() const override
Definition
historynotificationsmodel.cpp:41
ViewSolutions::HistoryNotificationsModel::HistoryNotificationsModel
HistoryNotificationsModel(QObject *parent=nullptr)
Definition
historynotificationsmodel.cpp:13
ViewSolutions::NotificationData
The NotificationData class view data for NotificationServiceView. This class contains a structure wit...
Definition
notificationdata.h:28
historynotificationsmodel.h
ViewSolutions
The ViewSolutions namespace.
Definition
avatargenerator.cpp:14
ViewSolutions
src
historynotificationsmodel.cpp
Generated by
1.18.0