/
advqsortfilterproxymodel.cpp
110 lines (74 loc) · 3.07 KB
/
advqsortfilterproxymodel.cpp
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
108
109
110
#include "advqsortfilterproxymodel.h"
AdvQSortFilterProxyModel::AdvQSortFilterProxyModel(QObject *parent)
{
showOffline = true;
}
QVariant AdvQSortFilterProxyModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::BackgroundRole ) {
QBrush demonicBackground(QColor(255, 60, 43));
QBrush evilBackground(QColor(255,123,71));
QBrush unkownBackground(QColor(102, 191, 255));
QBrush goodBackground(QColor(110, 255, 96));
if (index.column() == 1) {
if (index.data().toString() == "online") {
return QVariant(goodBackground);
} else {
if (index.data().toString() == "hosting") {
return QVariant(unkownBackground);
}
}
}
}
/*
if ( role == Qt::TextAlignmentRole )
{
if (index.column() == 1) {
return Qt::AlignVCenter | Qt::AlignHCenter;
}
}
*/
return QSortFilterProxyModel::data( index, role );
}
bool AdvQSortFilterProxyModel::updateCol(int keycol, QVariant key, int updatecol, QVariant updatedata)
{
bool updateok = false;
for(int i = 0; i<this->sourceModel()->rowCount(); ++i)
{
QModelIndex key_index = this->sourceModel()->index(i,keycol);
QModelIndex update_index = this->sourceModel()->index(i,updatecol);
if ( this->sourceModel()->itemData(key_index)[0].toString() == key.toString() ) {
updateok = this->sourceModel()->setData(update_index,updatedata);
}
}
return updateok;
}
QVariant AdvQSortFilterProxyModel::getColData(int keycol, QVariant key, int updatecol)
{
QVariant data = "";
for(int i = 0; i<this->sourceModel()->rowCount(); ++i)
{
QModelIndex key_index = this->sourceModel()->index(i,keycol);
QModelIndex update_index = this->sourceModel()->index(i,updatecol);
if ( this->sourceModel()->itemData(key_index)[0].toString() == key.toString() ) {
data = this->sourceModel()->data(update_index,0);
}
}
return data;
}
void AdvQSortFilterProxyModel::setShowOffline(bool showoffline)
{
this->showOffline = showoffline;
}
bool AdvQSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
QModelIndex index0 = sourceModel()->index(source_row, 0, source_parent);
QModelIndex index1 = sourceModel()->index(source_row, 1, source_parent);
QModelIndex index2 = sourceModel()->index(source_row, 2, source_parent);
QModelIndex index3 = sourceModel()->index(source_row, 3, source_parent);
if (showOffline == true) {
return (sourceModel()->data(index0).toString().contains(filterRegExp()) || sourceModel()->data(index3).toString().contains(filterRegExp()));
} else {
return ((sourceModel()->data(index0).toString().contains(filterRegExp()) || sourceModel()->data(index3).toString().contains(filterRegExp())) && sourceModel()->data(index1).toString() != "offline");
}
}