Пример #1
0
QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid())
        return QVariant();

    TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());

    if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) {
        if (item->itemType() == TorrentContentModelItem::FolderType)
            return getDirectoryIcon();
        else
            return getFileIcon();
    }

    if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
        if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED)
            return Qt::Unchecked;
        if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::MIXED)
            return Qt::PartiallyChecked;
        return Qt::Checked;
    }

    if (role == Qt::DisplayRole)
        return item->data(index.column());

    return QVariant();
}
Пример #2
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()));
}
Пример #3
0
int TorrentContentModel::getFileIndex(const QModelIndex& index)
{
    TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
    if (item->itemType() == TorrentContentModelItem::FileType)
        return static_cast<TorrentContentModelFile*>(item)->fileIndex();

    Q_ASSERT(item->itemType() == TorrentContentModelItem::FileType);
    return -1;
}
Пример #4
0
QModelIndex TorrentContentModel::parent(const QModelIndex& index) const
{
    if (!index.isValid())
        return QModelIndex();

    TorrentContentModelItem* childItem = static_cast<TorrentContentModelItem*>(index.internalPointer());
    if (!childItem)
        return QModelIndex();

    TorrentContentModelItem *parentItem = childItem->parent();
    if (parentItem == m_rootItem)
        return QModelIndex();

    return createIndex(parentItem->row(), 0, parentItem);
}
Пример #5
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;
}