2015-09-06 20:33:09 +02:00
|
|
|
#include "./entryfiltermodel.h"
|
|
|
|
#include "./entrymodel.h"
|
2015-04-22 19:30:09 +02:00
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \class EntryFilterModel
|
|
|
|
* \brief The EntryFilterModel class provides a QSortFilterProxyModel specialization for the EntryModel class.
|
|
|
|
*
|
|
|
|
* \sa http://qt-project.org/doc/qt-5/qsortfilterproxymodel.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Constructs a new filter entry model.
|
|
|
|
*/
|
|
|
|
EntryFilterModel::EntryFilterModel(QObject *parent) :
|
|
|
|
QSortFilterProxyModel(parent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool EntryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
{
|
2016-04-08 00:04:23 +02:00
|
|
|
// just use default implementation
|
2015-04-22 19:30:09 +02:00
|
|
|
if(QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-08 00:04:23 +02:00
|
|
|
|
|
|
|
// also accept rows where the direct parent is accepted
|
|
|
|
if(sourceParent.isValid() && QSortFilterProxyModel::filterAcceptsRow(sourceParent.row(), sourceParent.parent())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// also accept rows which contain accepted childs
|
2016-03-15 15:33:13 +01:00
|
|
|
return hasAcceptedChildren(sourceModel()->index(sourceRow, 0, sourceParent));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EntryFilterModel::hasAcceptedChildren(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
for(int i = 0, rowCount = sourceModel()->rowCount(index); i < rowCount; ++i) {
|
|
|
|
if(filterAcceptsRow(i, index)) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-22 19:30:09 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|