Пример #1
0
void TorrentContentModel::selectAll()
{
    for (int i = 0; i < m_rootItem->childCount(); ++i) {
        TorrentContentModelItem* child = m_rootItem->child(i);
        if (child->priority() == prio::IGNORED)
            child->setPriority(prio::NORMAL);
    }
    emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
}
Пример #2
0
bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
    if (!index.isValid())
        return false;

    if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
        TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
        qDebug("setData(%s, %d", qPrintable(item->name()), value.toInt());
        if (item->priority() != value.toInt()) {
            if (value.toInt() == Qt::PartiallyChecked)
                item->setPriority(prio::MIXED);
            else if (value.toInt() == Qt::Unchecked)
                item->setPriority(prio::IGNORED);
            else
                item->setPriority(prio::NORMAL);
            // Update folders progress in the tree
            m_rootItem->recalculateProgress();
            m_rootItem->recalculateAvailability();
            emit dataChanged(this->index(0, 0), this->index(rowCount() - 1, columnCount() - 1));
            emit filteredFilesChanged();
        }
        return true;
    }

    if (role == Qt::EditRole) {
        Q_ASSERT(index.isValid());
        TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
        switch (index.column()) {
        case TorrentContentModelItem::COL_NAME:
            item->setName(value.toString());
            break;
        case TorrentContentModelItem::COL_PRIO:
            item->setPriority(value.toInt());
            break;
        default:
            return false;
        }
        emit dataChanged(index, index);
        return true;
    }

    return false;
}