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 ); }
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(); }