bool SeasideProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { // TODO: add communication history //if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) // return false; // TODO: it may be better to filter this in SeasidePeopleModel, instead // of constantly doing it on refilter. SeasidePeopleModel *model = static_cast<SeasidePeopleModel *>(sourceModel()); SeasidePerson *person = model->personByRow(source_row); if (person->id() == model->manager()->selfContactId()) return false; if (priv->filterType == FilterAll) { // TODO: this should not be here qDebug("fastscroll: emitting countChanged"); emit const_cast<SeasideProxyModel*>(this)->countChanged(); return true; } if (priv->filterType == FilterFavorites) { if (person->favorite()) { // TODO: this should not be here qDebug("fastscroll: emitting countChanged"); emit const_cast<SeasideProxyModel*>(this)->countChanged(); return true; } return false; } else { qWarning() << "[SeasideProxyModel] invalid filter type"; return false; } }
bool SeasideProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { SeasidePeopleModel *model = static_cast<SeasidePeopleModel *>(sourceModel()); SeasidePerson *leftPerson = model->personByRow(left.row()); SeasidePerson *rightPerson = model->personByRow(right.row()); if (!leftPerson) return false; else if (!rightPerson) return true; return priv->localeHelper->isLessThan(leftPerson->displayLabel(), rightPerson->displayLabel()); }
bool SeasideProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { // TODO: add communication history //if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) // return false; // TODO: it may be better to filter this in SeasidePeopleModel, instead // of constantly doing it on refilter. SeasidePeopleModel *model = static_cast<SeasidePeopleModel *>(sourceModel()); SeasidePerson *person = model->personByRow(source_row); if (person->id() == model->manager()->selfContactId()) return false; if (priv->searchPattern.length() > 0 ) { bool result = true; bool found = false; QStringList labelList = person->displayLabel().split(" "); QStringList filterList = priv->searchPattern.split(" "); int j = 0; for (int i = 0; i < filterList.size() && result != false; i++) { found = false; for (; j < labelList.size(); j++) { if (labelList.at(j).startsWith(filterList.at(i), Qt::CaseInsensitive)) { found = true; j++; break; } } result = result && found; } if (result == false) return false; } if (priv->filterType == FilterAll) { // TODO: this should not be here qDebug("fastscroll: emitting countChanged"); emit const_cast<SeasideProxyModel*>(this)->countChanged(); return true; } if (priv->filterType == FilterFavorites) { if (person->favorite()) { // TODO: this should not be here qDebug("fastscroll: emitting countChanged"); emit const_cast<SeasideProxyModel*>(this)->countChanged(); return true; } return false; } else { qWarning() << "[SeasideProxyModel] invalid filter type"; return false; } }