-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathresultsortfilterproxymodel.cpp
More file actions
68 lines (54 loc) · 1.67 KB
/
Copy pathresultsortfilterproxymodel.cpp
File metadata and controls
68 lines (54 loc) · 1.67 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
#include "StdAfx.h"
#include "resultsortfilterproxymodel.h"
ResultSortFilterProxyModel::ResultSortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
ResultSortFilterProxyModel::~ResultSortFilterProxyModel()
{
}
void ResultSortFilterProxyModel::SetFilter(QString name, QStringList typeList)
{
m_nameFilter = name;
m_typeFilter = typeList;
invalidateFilter();
}
bool ResultSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
QVariant leftData = sourceModel()->data(left, Qt::EditRole);
QVariant rightData = sourceModel()->data(right, Qt::EditRole);
if (leftData.type() == QVariant::Int)
{
return leftData.toInt() < rightData.toInt();
}
else if (leftData.type() == QVariant::UInt)
{
return leftData.toUInt() < rightData.toUInt();
}
else if (leftData.type() == QVariant::ULongLong)
{
return leftData.toULongLong() < rightData.toULongLong();
}
else if (leftData.type() == QVariant::String)
{
QString left = leftData.toString();
QString right = rightData.toString();
return QString::localeAwareCompare(left, right) < 0;
}
}
bool ResultSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
QModelIndex nameIndex = sourceModel()->index(source_row, COLUMN_NAME, source_parent);
QModelIndex typeIndex = sourceModel()->index(source_row, COLUMN_TYPE, source_parent);
QString name = sourceModel()->data(nameIndex).toString();
QString type = sourceModel()->data(typeIndex).toString();
qDebug() << name << type;
if((m_nameFilter.isEmpty() || name.contains(m_nameFilter)) && (m_typeFilter.empty() || m_typeFilter.contains(type)))
{
return true;
}
else
{
return false;
}
}