blob: 8808a6f267a98e4683e9664cc957bdd53500bb63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "xdgnotificationactions.h"
#include <QDebug>
KaZoe::NotificationActions::NotificationActions(QObject *parent)
: QAbstractListModel(parent)
{
}
QStringList KaZoe::NotificationActions::actionslist() const
{
return m_actionslist;
}
void KaZoe::NotificationActions::setActionslist(const QStringList &newActionslist)
{
if(newActionslist.count() % 2 != 0)
{
qWarning() << "Error in actionlist:" << newActionslist;
}
if (m_actionslist == newActionslist)
return;
m_actionslist = newActionslist;
beginResetModel();
m_actions.clear();
for(int i = 0; i < newActionslist.count() / 2; i++)
{
m_actions.append(QPair<QString, QString>(newActionslist[i * 2], newActionslist[(i * 2) + 1]));
}
endResetModel();
emit actionslistChanged();
}
int KaZoe::NotificationActions::rowCount(const QModelIndex &parent) const
{
return m_actions.count();
}
QVariant KaZoe::NotificationActions::data(const QModelIndex &index, int role) const
{
if(index.row() > m_actions.count())
return QVariant();
switch(role) {
case Qt::DisplayRole:
case TextRole:
return m_actions[index.row()].second;
case KeyRole:
return m_actions[index.row()].first;
}
return QVariant();
}
QHash<int, QByteArray> KaZoe::NotificationActions::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
roles[KeyRole] = "key";
roles[TextRole] = "actionText";
return roles;
}
|