-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebdatafiltermodel.cpp
51 lines (43 loc) · 1.26 KB
/
webdatafiltermodel.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
#include "webdatafiltermodel.h"
#include <QStandardItemModel>
WebDataFilterModel::WebDataFilterModel( QObject* parent ): QSortFilterProxyModel( parent ), mShowOnlyFavourites( false )
{
}
WebDataFilterModel::~WebDataFilterModel()
{
}
void WebDataFilterModel::setShowOnlyFavourites( bool b )
{
mShowOnlyFavourites = b;
invalidateFilter();
}
void WebDataFilterModel::_setFilterWildcard( const QString& pattern )
{
QSortFilterProxyModel::setFilterWildcard( pattern );
invalidateFilter();
}
bool WebDataFilterModel::filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const
{
//if parent is valid, we have a toplevel item that should be always shown
if ( !source_parent.isValid() )
{
return true;
}
if ( mShowOnlyFavourites )
{
QStandardItemModel* model = dynamic_cast<QStandardItemModel*>( sourceModel() );
if ( model )
{
QStandardItem* item = model->itemFromIndex( model->index( source_row, 1, source_parent ) );
{
if ( item && item->checkState() != Qt::Checked )
{
return false;
}
}
}
}
//else we have a row that describes a table and that
//should be tested using the given wildcard/regexp
return QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent );
}