-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyProxiModel.cpp
More file actions
33 lines (29 loc) · 899 Bytes
/
MyProxiModel.cpp
File metadata and controls
33 lines (29 loc) · 899 Bytes
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
#include "MyProxiModel.h"
MyProxiModel::MyProxiModel(QObject *parent): QSortFilterProxyModel(parent)
{
}
void MyProxiModel::ChangeFilter(const QString& newFilter)
{
m_filter= newFilter;
invalidate();
}
bool MyProxiModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (m_filter.isEmpty())
{
return true;
}
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return index.data(HeaderRole).toString().contains(m_filter, Qt::CaseInsensitive);
}
bool MyProxiModel::lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight) const
{
if (sortRole() == HeaderRole)
{
return sourceLeft.data(HeaderRole).toString() < sourceRight.data(HeaderRole).toString();
}
else
{
return sourceLeft.data(CreationDateRole).toDate() < sourceRight.data(CreationDateRole).toDate();
}
}