예제 #1
0
static QVariant dataFunction(const TagRef::List &list, int index, int role)
{
    switch (role) {
    case TagRole:
        return QVariant::fromValue<Tag*>(list.at(index).tag().data());
    case TaskRole:
        return QVariant::fromValue<Task*>(list.at(index).m_task.data());
    default:
        return QVariant();
    }
}
bool TaskFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
    if (!sourceModel())
        return false;

    if (source_parent.isValid() || source_row < 0 || source_row >= sourceModel()->rowCount()) {
        qWarning() << source_parent.isValid() << source_row << sourceModel()->rowCount();
        Q_ASSERT(false);
        return false;
    }

    QModelIndex index = sourceModel()->index(source_row, 0);
    if (!index.isValid())
        return false;

    QVariant v = index.data(Storage::TaskPtrRole);
    if (!v.isValid())
        return false;

    Task::Ptr task = v.value<Task::Ptr>();
    if (!task)
        return false;

    if (task->status() == TaskStarted)
        return false;

    if (m_filterUntagged)
        return task->tags().isEmpty();

    if (m_tagText.isEmpty())
        return true;

    TagRef::List tags = task->tags();
    for (int i = 0; i < tags.count(); ++i) {
        const TagRef &tagref = tags.at(i);
        if (tagref.tagName() == m_tagText)
            return true;
    }

    return false;
}