QModelIndex CollectionTreeModel::parent(const QModelIndex &index) const { if(!index.isValid()) { return QModelIndex(); } CollectionTreeItem *childItem = static_cast<CollectionTreeItem *>(index.internalPointer()); CollectionTreeItem *parentItem = childItem->parent(); if(parentItem == tree()->root()) { return QModelIndex(); } return createIndex(parentItem->row(), 0, parentItem); }
QMimeData * ScriptableServiceCollectionTreeModel::mimeData( const QList<CollectionTreeItem *> &items ) const { // this is basically a copy of superclass method with a couple of changes: // 1. we don't reuse tracks already in the model // 2. we tell the querymaker to masquerade special tracks using namespace Collections; Meta::TrackList tracks; QList<QueryMaker *> queries; foreach( CollectionTreeItem *item, items ) { if( item->isTrackItem() ) { using namespace Meta; const ScriptableServiceTrack *serviceTrack = dynamic_cast<const ScriptableServiceTrack *>( item->data().data() ); if( !serviceTrack ) { error() << "failed to convert generic track" << item->data() << "to ScriptableServiceTrack"; continue; } tracks << serviceTrack->playableTrack(); continue; } ScriptableServiceQueryMaker *qm = qobject_cast<ScriptableServiceQueryMaker *>( item->queryMaker() ); if( !qm ) { error() << "failed to convert generic QueryMaker to ScriptableService one"; continue; } qm->setConvertToMultiTracks( true ); for( CollectionTreeItem *tmp = item; tmp; tmp = tmp->parent() ) tmp->addMatch( qm, levelCategory( tmp->level() - 1 ) ); Collections::addTextualFilter( qm, m_currentFilter ); queries.append( qm ); } if( queries.isEmpty() && tracks.isEmpty() ) return 0; AmarokMimeData *mimeData = new AmarokMimeData(); mimeData->setTracks( tracks ); mimeData->setQueryMakers( queries ); mimeData->startQueries(); return mimeData; }