Пример #1
0
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 );
}
Пример #2
0
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();
}