Пример #1
0
void
ColumnView::onCustomContextMenu( const QPoint& pos )
{
    m_contextMenu->clear();

    QModelIndex idx = indexAt( pos );
    idx = idx.sibling( idx.row(), 0 );
    m_contextMenuIndex = idx;

    if ( !idx.isValid() )
        return;

    QList<query_ptr> queries;
    QList<artist_ptr> artists;
    QList<album_ptr> albums;

    QModelIndexList indexes = selectedIndexes();
    if ( !indexes.contains( idx ) )
    {
        indexes.clear();
        indexes << idx;
    }

    foreach ( const QModelIndex& index, indexes )
    {
        if ( index.column() || indexes.contains( index.parent() ) )
            continue;

        PlayableItem* item = m_proxyModel->itemFromIndex( m_proxyModel->mapToSource( index ) );

        if ( item && !item->result().isNull() )
            queries << item->result()->toQuery();
        else if ( item && !item->query().isNull() )
            queries << item->query();
        if ( item && !item->artist().isNull() )
            artists << item->artist();
        if ( item && !item->album().isNull() )
            albums << item->album();
    }

    m_contextMenu->setQueries( queries );
    m_contextMenu->setArtists( artists );
    m_contextMenu->setAlbums( albums );
    m_contextMenu->setPlaylistInterface( proxyModel()->playlistInterface() );

    m_contextMenu->exec( viewport()->mapToGlobal( pos ) );
}
Пример #2
0
void
TestDynamicModel::testDnD()
{
    Dynamic::DynamicModel *model = Dynamic::DynamicModel::instance();

    // load from the empty directory
    model->loadPlaylists();

    // -- copy a playlist
    QModelIndex playlistIndex = model->index( 2, 0 );
    QModelIndexList indexes;
    indexes << playlistIndex;
    int oldRowCount = model->rowCount();
    QString oldName = model->data( playlistIndex ).toString();
    QMimeData* data = model->mimeData( indexes );
    QVERIFY( model->dropMimeData( data, Qt::CopyAction, 0, 0, QModelIndex() ) );

    QCOMPARE( model->rowCount(), oldRowCount + 1 );
    playlistIndex = model->index( 0, 0 );
    QCOMPARE( oldName, model->data( playlistIndex ).toString() );
    delete data;

    // -- move a playlist (to the end)
    playlistIndex = model->index( 0, 0 );
    indexes.clear();
    indexes << playlistIndex;

    oldRowCount = model->rowCount();
    oldName = model->data( playlistIndex ).toString();
    data = model->mimeData( indexes );
    QVERIFY( model->dropMimeData( data, Qt::MoveAction, oldRowCount, 0, QModelIndex() ) );

    QCOMPARE( model->rowCount(), oldRowCount );
    playlistIndex = model->index( oldRowCount - 1, 0 );
    QCOMPARE( oldName, model->data( playlistIndex ).toString() );
    delete data;


    // -- copy a bias
    // TODO
    QModelIndex biasIndex = model->index( 0, 0, playlistIndex );
    QModelIndex subBiasIndex = model->index( 0, 0, biasIndex );

}