-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgfilterproxy.cpp
More file actions
50 lines (41 loc) · 1.6 KB
/
gfilterproxy.cpp
File metadata and controls
50 lines (41 loc) · 1.6 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
#include "gfilterproxy.h"
#include "gpad.h"
#include "gabstracttablemodel.h"
#include <QDebug>
GFilterProxy::GFilterProxy(QObject *parent)
: QSortFilterProxyModel(parent),
mDoFilter(false)
{
}
void GFilterProxy::toggleFilter(bool state)
{
mDoFilter = state;
invalidateFilter();
}
void GFilterProxy::clicked(const QModelIndex &index)
{
// qDebug() << __PRETTY_FUNCTION__ << mapToSource(index);
emit mouseClicked(mapToSource(index));
}
void GFilterProxy::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
// qDebug() << __PRETTY_FUNCTION__ << mapFromSource(topLeft).row() << mapFromSource(bottomRight).row();
emit dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight), roles);
if (mDoFilter && roles.contains(GPad::VisibilityRole)) {
invalidateFilter();
}
}
bool GFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &/*source_parent*/) const
{
// qDebug() << __PRETTY_FUNCTION__ << source_row;
return !mDoFilter || sourceModel()->index(source_row, 0).data(GPad::VisibilityRole).toBool();
}
void GFilterProxy::setSourceModel(QAbstractItemModel *sourceModel)
{
Q_ASSERT(sourceModel->inherits("GAbstractTableModel"));
QSortFilterProxyModel::setSourceModel(sourceModel);
mGModel = static_cast<GAbstractTableModel*>(sourceModel);
connect(this, SIGNAL(mouseClicked(QModelIndex)), mGModel, SLOT(clicked(QModelIndex)));
connect(mGModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
}