forked from YACReader/yacreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions_groups_model.cpp
More file actions
85 lines (65 loc) · 1.77 KB
/
Copy pathactions_groups_model.cpp
File metadata and controls
85 lines (65 loc) · 1.77 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "actions_groups_model.h"
ActionsGroupsModel::ActionsGroupsModel(QObject *parent)
: QAbstractItemModel(parent)
{
}
int ActionsGroupsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return groups.length();
}
int ActionsGroupsModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QModelIndex ActionsGroupsModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
return createIndex(row, column);
}
QVariant ActionsGroupsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DecorationRole)
return QVariant(groups.at(index.row()).getIcon());
if (role != Qt::DisplayRole)
return QVariant();
return QVariant(groups[index.row()].getName());
}
QModelIndex ActionsGroupsModel::parent(const QModelIndex &index) const
{
Q_UNUSED(index);
return QModelIndex();
}
void ActionsGroupsModel::addActionsGroup(const ActionsGroup &group)
{
beginInsertRows(QModelIndex(), groups.length(), groups.length());
groups.push_back(group);
endInsertRows();
}
QList<QAction *> ActionsGroupsModel::getActions(const QModelIndex &mi)
{
if (mi.isValid())
return groups[mi.row()].getActions();
return QList<QAction *>();
}
//-------------------------------------------------------------------
ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList<QAction *> &actions)
: name(name), icon(icon), actions(actions)
{
}
QString ActionsGroup::getName() const
{
return name;
}
QIcon ActionsGroup::getIcon() const
{
return icon;
}
QList<QAction *> ActionsGroup::getActions() const
{
return actions;
}