コード例 #1
0
void RepoTreeModel::removeReposDeletedOnServer(const std::vector<ServerRepo>& repos)
{
    int i, n;
    DeleteRepoData data;
    n = repos.size();
    for (i = 0; i < n; i++) {
        const ServerRepo& repo = repos[i];
        data.map.insert(repo.id, &repo);
    }

    forEachRepoItem(&RepoTreeModel::collectDeletedRepos, (void *)&data);

    QListIterator<RepoItem*> iter(data.itemsToDelete);
    while(iter.hasNext()) {
        RepoItem *item = iter.next();

        const ServerRepo& repo = item->repo();

        qDebug("remove repo %s(%s) from \"%s\"\n",
               toCStr(repo.name), toCStr(repo.id),
               toCStr(((RepoCategoryItem*)item->parent())->name()));

        item->parent()->removeRow(item->row());
    }
}
コード例 #2
0
ファイル: RepoModel.cpp プロジェクト: nimgould/mantid
/** Provide the parent of a given entry, through the QModelIndex abstraction.
 *
 * @param index: The QModelIndex that identifies one entry.
 * @return A QModelIndex that indentifies the parent of the given index.
 */
QModelIndex RepoModel::parent(const QModelIndex &index) const
{
    if (!index.isValid())
        return QModelIndex();
    // the child is the RepoItem pointed by the index.
    RepoItem *childItem = static_cast<RepoItem*>(index.internalPointer());
    // the parent is the parent of the RepoItem.
    RepoItem *parentItem = childItem->parent();
    // the root item does not have a parent
    if (parentItem == rootItem)
        return QModelIndex();
    // create the index and return
    return createIndex(parentItem->row(), 0, parentItem);
}