-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxylistmodel.cpp
More file actions
107 lines (96 loc) · 3.69 KB
/
proxylistmodel.cpp
File metadata and controls
107 lines (96 loc) · 3.69 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
* Copyright (C) 2024 Jurgen Cruz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <https://www.gnu.org/licenses/>. *
***************************************************************************/
#include "proxylistmodel.h"
ProxyListModel::ProxyListModel(QObject *parent)
: QAbstractListModel(parent) {
}
ProxyListModel::~ProxyListModel() = default;
QHash<int, QByteArray> ProxyListModel::staticRoleNames() {
QHash<int, QByteArray> roles;
roles.insert(Qt::DisplayRole, "display");
roles.insert(Qt::DecorationRole, "decoration");
roles.insert(GroupRole, "group");
roles.insert(DescriptionRole, "description");
roles.insert(FavoriteIdRole, "favoriteId");
roles.insert(IsParentRole, "isParent");
roles.insert(IsSeparatorRole, "isSeparator");
roles.insert(HasChildrenRole, "hasChildren");
roles.insert(HasActionListRole, "hasActionList");
roles.insert(ActionListRole, "actionList");
roles.insert(UrlRole, "url");
roles.insert(DisabledRole, "disabled");
roles.insert(IsMultilineTextRole, "isMultilineText");
roles.insert(DisplayWrappedRole, "displayWrapped");
return roles;
}
QHash<int, QByteArray> ProxyListModel::roleNames() const {
return staticRoleNames();
}
QVariant ProxyListModel::data(const QModelIndex &index, const int role) const {
if (!index.isValid()) {
return QVariant();
}
int itemIndex = index.row();
const int listIndex = getListIndex(itemIndex);
if (listIndex == -1) {
return QVariant();
}
const QAbstractItemModel *list = m_entryList.at(listIndex);
const QModelIndex newIndex = list->index(itemIndex, 0);
return list->data(newIndex, role);
}
int ProxyListModel::rowCount(const QModelIndex &parent) const {
if (parent.isValid()) {
return 0;
}
int sum = 0;
for (const auto size: m_entryList) {
sum += size->rowCount();
}
return sum;
}
void ProxyListModel::addList(QAbstractItemModel *list) {
m_entryList << list;
}
DelegateInfo *ProxyListModel::getInfo(int row) {
int itemIndex = row;
const int listIndex = getListIndex(itemIndex);
if (listIndex == -1) {
return nullptr;
}
QAbstractItemModel *list = m_entryList.at(listIndex);
return new DelegateInfo(itemIndex, list, this);
}
int ProxyListModel::getListIndex(int &i) const {
const qsizetype entries = m_entryList.size();
if (entries == 0) {
return -1;
}
int j = 0;
auto list = m_entryList.at(j);
int size = list->rowCount();
while (i >= size) {
i = i - size;
j++;
if (j == entries) {
return -1;
}
list = m_entryList.at(j);
size = list->rowCount();
}
return j;
}