QVariant SearchTreeModel::data(const QModelIndex& index, int role) const { if(!index.isValid()) { return QVariant(); } SearchTreeItem* item = static_cast<SearchTreeItem*>(index.internalPointer()); if(role == Qt::DecorationRole) { if(index.column() == 0) { return item->HitData.iNetwork; } if(index.column() == 8) { return item->HitData.iCountry; } } if(role == Qt::DisplayRole) { return item->data(index.column()); } return QVariant(); }
void CWidgetSearchTemplate::on_treeViewSearchResults_doubleClicked(const QModelIndex &index) { Q_UNUSED(index); SearchTreeItem* itemSearch = m_pSearchModel->topLevelItemFromIndex(CurrentItem()); if( itemSearch != NULL ) { CQueryHit* pHits = 0; CQueryHit* pLast = 0; for(int i = 0; i < itemSearch->childCount(); ++i) { if( pLast ) { pLast->m_pNext = new CQueryHit(itemSearch->child(i)->HitData.pQueryHit.data()); pLast = pLast->m_pNext; } else { pHits = new CQueryHit(itemSearch->child(i)->HitData.pQueryHit.data()); pLast = pHits; } } Downloads.m_pSection.lock(); Downloads.add(pHits); Downloads.m_pSection.unlock(); delete pHits; } }
/** * @brief SearchTreeModel::fileVisible allows to find out whether the file in the specified row is * currently visible. Note that the specified row is required to be a valid one. * @param row * @return true if the file item is visible; false otherwise. */ bool SearchTreeModel::fileVisible( int row ) const { SearchTreeItem* pChild = m_pRootItem->child( row ); Q_ASSERT( pChild ); return pChild ? pChild->visible() : false; }
QModelIndex SearchTreeModel::index( int row, int column, const QModelIndex& parent ) const { if ( !hasIndex( row, column, parent ) ) { return QModelIndex(); } SearchTreeItem* parentItem; if ( !parent.isValid() ) { parentItem = m_pRootItem; } else { parentItem = static_cast<SearchTreeItem*>( parent.internalPointer() ); } SearchTreeItem* childItem = parentItem->child( row ); if ( childItem ) { return createIndex( row, column, childItem ); } else { return QModelIndex(); } }
void SearchFile::removeChild( int position ) { SearchTreeItem* pItem = m_lChildItems.at( position ); Q_ASSERT( pItem->type() == SearchHitType ); ( ( TreeRoot* )m_pParentItem )->removeFromFilterControl( pItem ); SearchTreeItem::removeChild( position ); }
bool SearchSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const { if ( sourceParent.isValid() ) { SearchTreeItem* parentItem = static_cast<SearchTreeItem*>( sourceParent.internalPointer() ); Q_ASSERT( parentItem ); return parentItem->child( sourceRow )->visible(); } else // parent is top level/root item { return ( ( SearchTreeModel* )sourceModel() )->fileVisible( sourceRow ); } }
QModelIndex SearchTreeModel::parent( const QModelIndex& index ) const { if ( !index.isValid() ) { return QModelIndex(); } SearchTreeItem* childItem = static_cast<SearchTreeItem*>( index.internalPointer() ); SearchTreeItem* parentItem = childItem->parent(); if ( parentItem == m_pRootItem ) { return QModelIndex(); } return createIndex( parentItem->row(), 0, parentItem ); }
void TreeRoot::removeChild( int position ) { SearchTreeItem* pItem = m_lChildItems.at( position ); Q_ASSERT( pItem->type() == SearchFileType ); const Hash* const * const pHashes = &( ( SearchFile* )pItem )->m_vHashes[0]; for ( quint8 i = 0, nSize = ( ( SearchFile* )pItem )->m_vHashes.size(); i < nSize; ++i ) { if ( pHashes[i] ) { unregisterHash( *pHashes[i] ); } } removeFromFilterControl( pItem ); SearchTreeItem::removeChild( position ); }
int SearchTreeModel::rowCount( const QModelIndex& parent ) const { SearchTreeItem* parentItem; if ( parent.column() > 0 ) { return 0; } if ( !parent.isValid() ) { parentItem = m_pRootItem; } else { parentItem = static_cast<SearchTreeItem*>( parent.internalPointer() ); } return parentItem->childCount(); }
void SearchTreeModel::removeQueryHit( int position, const QModelIndex& parent ) { SearchTreeItem* parentItem; if ( parent.isValid() ) { parentItem = static_cast<SearchTreeItem*>( parent.internalPointer() ); } else { parentItem = m_pRootItem; } Q_ASSERT( parentItem ); //if ( parentItem ) //{ beginRemoveRows( parent, position, position ); parentItem->removeChild( position ); endRemoveRows(); //} }
QVariant SearchTreeModel::data( const QModelIndex& index, int role ) const { if ( !index.isValid() ) { return QVariant(); } SearchTreeItem* item = static_cast<SearchTreeItem*>( index.internalPointer() ); if ( role == Qt::DecorationRole ) { if ( index.column() == 0 ) // Index CAN be a negative value. { if ( item->parent() == m_pRootItem ) { return m_pIconProvider->icon( item->data( 1 ).toString().prepend( "." ) ); } else { return item->m_oHitData.iNetwork; } } if ( index.column() == 8 ) { return item->m_oHitData.iCountry; } } if ( role == Qt::DisplayRole ) { return item->data( index.column() ); } return QVariant(); }