-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnarrowablefilterproxymodel.cpp
More file actions
52 lines (44 loc) · 1.51 KB
/
narrowablefilterproxymodel.cpp
File metadata and controls
52 lines (44 loc) · 1.51 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
#include "narrowablefilterproxymodel.h"
#include <QSortFilterProxyModel>
#include <QDebug>
NarrowableFilterProxyModel::NarrowableFilterProxyModel(QObject *parent)
: AbstractProxyChainModel(parent)
{
}
NarrowableFilterProxyModel::~NarrowableFilterProxyModel()
{
}
NarrowableFilterProxyModel::RelationType NarrowableFilterProxyModel::relationTo(QAbstractProxyModel *model, QAbstractProxyModel *sourceModel)
{
QSortFilterProxyModel *filter = (QSortFilterProxyModel *) model;
QSortFilterProxyModel *sourceFilter = (QSortFilterProxyModel *) sourceModel;
const QString &pattern = filter->filterRegExp().pattern();
const QString &sourcePattern = sourceFilter->filterRegExp().pattern();
if (pattern == sourcePattern) {
return Identical;
} else if (pattern.contains(sourcePattern)) {
return Narrower;
} else {
return Different;
}
}
void NarrowableFilterProxyModel::setFilterFixedString(const QString &s)
{
if (s.isEmpty()) {
clearChain();
} else {
QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
model->setFilterFixedString(s);
addToChain(model);
}
}
void NarrowableFilterProxyModel::printRowCounts() const
{
const QSortFilterProxyModel *model = qobject_cast<QSortFilterProxyModel *>(sourceModel());
QDebug dbg = qDebug();
dbg << "row count:";
while (model) {
dbg << model->filterRegExp().pattern() << model->rowCount();
model = qobject_cast<QSortFilterProxyModel *>(model->sourceModel());
}
}