Пример #1
0
QVariant ListModel::data(const QModelIndex& index, int role) const
{
    if (index.isValid()) {
        ListItem* item = itemFromIndex(index);
        if (item) {
            // all columns
            switch (role) {
                case Qt::BackgroundRole:
                    if (item->isHighlighted())
                        return App::HighlightBackgroundColor;
                    else if (item->isProject())
                        return App::ProjectBackgroundColor;
                    else if (item->isMilestone())
                        return App::MilestoneBackgroundColor;
                    else
                        return QVariant();
            }
            // specific column
            switch (index.column()) {
                case 0:
                    switch (role) {
                        case Qt::DisplayRole:
                            return item->html();
                        case Qt::EditRole:
                            return item->markdown();
                        case Qt::CheckStateRole:
                            if (item->isCheckable())
                                if (item->isCompleted())
                                    return Qt::Checked;
                                else if (item->isCancelled())
                                    return Qt::PartiallyChecked;
                                else
                                    return Qt::Unchecked;
                            break;
                        case Qt::DecorationRole:
                            if (item->isProject())
                                return Util::findIcon("project");
                            if (item->isMilestone())
                                return Util::findIcon("milestone");
                            if (item->isNote())
                                return Util::findIcon("note");
                            break;
#ifdef QT_DEBUG
                        case Qt::ToolTipRole:
                            return QString("id: %1 row: %2 parent: %3 milestone: %4 priority: %5").arg(item->id()).arg(item->row()).arg(item->parent()->id()).arg(item->isMilestone()).arg(item->priority());
#endif
                    } break;
                case 1:
                    switch (role) {
                        case Qt::DisplayRole:
                            return item->dueDate();
                    } break;
            }
        }
    }
    return QVariant();
}
Пример #2
0
bool ListModel::isNewItemCheckable(ListItem* parent, int row)
{
    if (row > 0) {
        ListItem* previous = parent->child(row - 1);
        if (previous)
            return previous->isCheckable();
    } else
        return parent->isProject() || parent->isMilestone();

    return false;
}