Beispiel #1
0
QVariant SpyModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

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

    switch(role) {
        case Qt::DecorationRole: // icon
        {
            break;
        }
        case Qt::DisplayRole:
            return item->data(index.column());
        case Qt::TextAlignmentRole:
        {
            break;
        }
        case Qt::ForegroundRole:
        {
            break;
        }
        case Qt::BackgroundColorRole:
            break;
        case Qt::ToolTipRole:
            break;
    }

    return QVariant();
}
Beispiel #2
0
void SpyModel::addResult(QString file, bool isTTH)
{
    if (file.isEmpty() || file.isNull())
        return;

    SpyItem *item;
    SpyItem * parent = NULL;

    if (hashes.contains(file))
        parent = hashes[file];
    else
        parent = rootItem;

    QList<QVariant> item_data;

    item_data << "" << file;
    item = pool.construct(item_data, parent);

    item->isTTH = isTTH;

    if (parent == rootItem)
        hashes.insert(file, item);

    parent->appendChild(item);

    sort();

    emit layoutChanged();
}
void SpyFrame::contextMenu(){
    QModelIndexList list = treeView->selectionModel()->selectedRows(0);

    if (list.isEmpty())
        return;

    SpyItem *item = reinterpret_cast<SpyItem*>(list.at(0).internalPointer());

    QMenu *m = new QMenu(this);
    m->addAction(tr("Search"));

    QAction *ret = m->exec(QCursor::pos());

    if (!ret)
        return;

    SearchFrame *fr = ArenaWidgetFactory().create<SearchFrame, QWidget*>(this);
    QString src = item->data(COLUMN_SPY_STRING).toString();

    if (item->isTTH){
        src.remove(0, 4);

        fr->searchAlternates(src);
    }
    else
        fr->searchFile(src);

}
Beispiel #4
0
QModelIndex SpyModel::parent(const QModelIndex &index) const
{
    if (!index.isValid())
        return QModelIndex();

    SpyItem *childItem = static_cast<SpyItem*>(index.internalPointer());
    SpyItem *parentItem = childItem->parent();

    if (parentItem == rootItem)
        return QModelIndex();

    return createIndex(parentItem->row(), 0, parentItem);
}
Beispiel #5
0
int SpyModel::rowCount(const QModelIndex &parent) const
{
    SpyItem *parentItem;
    if (parent.column() > 0)
        return 0;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast<SpyItem*>(parent.internalPointer());

    return parentItem->childCount();
}
Beispiel #6
0
QModelIndex SpyModel::index(int row, int column, const QModelIndex &parent)
            const
{
    if (!hasIndex(row, column, parent))
        return QModelIndex();

    SpyItem *parentItem;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast<SpyItem*>(parent.internalPointer());

    SpyItem *childItem = parentItem->child(row);
    if (childItem)
        return createIndex(row, column, childItem);
    else
        return QModelIndex();
}