mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 02:24:50 +02:00
refactor the sourcetreeitem a bit so an item always exists properly as soon as it is constructed
that way the model's rowForItem() will work with any just-constructed SourceTreeItem make the treeview open the playlists when you open the collection.
This commit is contained in:
@@ -33,12 +33,9 @@ SourcesModel::SourcesModel( QObject* parent )
|
|||||||
: QAbstractItemModel( parent )
|
: QAbstractItemModel( parent )
|
||||||
{
|
{
|
||||||
m_rootItem = new SourceTreeItem( this, 0, Invalid );
|
m_rootItem = new SourceTreeItem( this, 0, Invalid );
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
=======
|
|
||||||
appendItem( source_ptr() );
|
appendItem( source_ptr() );
|
||||||
|
|
||||||
>>>>>>> add supercollection back
|
|
||||||
onSourcesAdded( SourceList::instance()->sources() );
|
onSourcesAdded( SourceList::instance()->sources() );
|
||||||
|
|
||||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
||||||
@@ -89,18 +86,7 @@ SourcesModel::rowCount( const QModelIndex& parent ) const
|
|||||||
return itemFromIndex( parent )->children().count();
|
return itemFromIndex( parent )->children().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
bool
|
|
||||||
SourcesModel::hasChildren( const QModelIndex& parent ) const
|
|
||||||
{
|
|
||||||
return rowCount( parent ) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QModelIndex
|
QModelIndex
|
||||||
=======
|
|
||||||
QModelIndex
|
|
||||||
>>>>>>> add supercollection back
|
|
||||||
SourcesModel::parent( const QModelIndex& child ) const
|
SourcesModel::parent( const QModelIndex& child ) const
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO << child;
|
// qDebug() << Q_FUNC_INFO << child;
|
||||||
@@ -112,13 +98,8 @@ SourcesModel::parent( const QModelIndex& child ) const
|
|||||||
SourceTreeItem* parent = node->parent();
|
SourceTreeItem* parent = node->parent();
|
||||||
if( parent == m_rootItem )
|
if( parent == m_rootItem )
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
return createIndex( rowForItem( node ), 0, parent );
|
|
||||||
=======
|
|
||||||
|
|
||||||
return createIndex( rowForItem( parent ), 0, parent );
|
return createIndex( rowForItem( parent ), 0, parent );
|
||||||
>>>>>>> add supercollection back
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex
|
QModelIndex
|
||||||
@@ -201,16 +182,8 @@ SourcesModel::appendItem( const Tomahawk::source_ptr& source )
|
|||||||
CollectionItem* item = new CollectionItem( this, m_rootItem, source );
|
CollectionItem* item = new CollectionItem( this, m_rootItem, source );
|
||||||
connect( item, SIGNAL( updated() ), this, SLOT( collectionUpdated() ) );
|
connect( item, SIGNAL( updated() ), this, SLOT( collectionUpdated() ) );
|
||||||
|
|
||||||
m_rootItem->appendChild( item );
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
qDebug() << "Appending source item:" << item->source()->friendlyName();
|
|
||||||
|
|
||||||
=======
|
|
||||||
|
|
||||||
|
|
||||||
>>>>>>> add supercollection back
|
|
||||||
if ( !source.isNull() )
|
if ( !source.isNull() )
|
||||||
{
|
{
|
||||||
qDebug() << "Appending source item:" << item->source()->friendlyName();
|
qDebug() << "Appending source item:" << item->source()->friendlyName();
|
||||||
|
@@ -88,9 +88,6 @@ public:
|
|||||||
QModelIndex indexFromPlaylist( const Tomahawk::playlist_ptr& playlist );
|
QModelIndex indexFromPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||||
QModelIndex indexFromItem( SourceTreeItem* item ) const;
|
QModelIndex indexFromItem( SourceTreeItem* item ) const;
|
||||||
|
|
||||||
signals:
|
|
||||||
void clicked( const QModelIndex& );
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );
|
void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );
|
||||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
|
@@ -34,6 +34,8 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent )
|
|||||||
// setSortRole( SourcesModel::SortRole );
|
// setSortRole( SourcesModel::SortRole );
|
||||||
|
|
||||||
setSourceModel( model );
|
setSourceModel( model );
|
||||||
|
|
||||||
|
connect( model, SIGNAL( askForExpand( QModelIndex ) ), this, SLOT( askedToExpand( QModelIndex ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -42,9 +44,6 @@ SourcesProxyModel::showOfflineSources()
|
|||||||
{
|
{
|
||||||
m_filtered = false;
|
m_filtered = false;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
|
|
||||||
// Q_ASSERT( qobject_cast<QTreeView*>( parent() ) );
|
|
||||||
// qobject_cast<QTreeView*>( parent() )->expandAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -53,9 +52,6 @@ SourcesProxyModel::hideOfflineSources()
|
|||||||
{
|
{
|
||||||
m_filtered = true;
|
m_filtered = true;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
|
|
||||||
// Q_ASSERT( qobject_cast<QTreeView*>( parent() ) );
|
|
||||||
// qobject_cast<QTreeView*>( parent() )->expandAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -27,18 +27,25 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType )
|
SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType, int index )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_type( thisType )
|
, m_type( thisType )
|
||||||
, m_parent( parent )
|
, m_parent( parent )
|
||||||
, m_model( model )
|
, m_model( model )
|
||||||
{
|
{
|
||||||
// connect( this, SIGNAL( selectRequest() ), m_model, SLOT( onItemSelectRequest() ) );
|
|
||||||
|
|
||||||
connect( this, SIGNAL( beginChildRowsAdded( int,int ) ), m_model, SLOT( onItemRowsAddedBegin( int,int ) ) );
|
connect( this, SIGNAL( beginChildRowsAdded( int,int ) ), m_model, SLOT( onItemRowsAddedBegin( int,int ) ) );
|
||||||
connect( this, SIGNAL( beginChildRowsRemoved( int,int ) ), m_model, SLOT( onItemRowsRemovedBegin( int,int ) ) );
|
connect( this, SIGNAL( beginChildRowsRemoved( int,int ) ), m_model, SLOT( onItemRowsRemovedBegin( int,int ) ) );
|
||||||
connect( this, SIGNAL( childRowsAdded() ), m_model, SLOT( onItemRowsAddedDone() ) );
|
connect( this, SIGNAL( childRowsAdded() ), m_model, SLOT( onItemRowsAddedDone() ) );
|
||||||
connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) );
|
connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) );
|
||||||
|
|
||||||
|
if( !m_parent )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// caller must call begin/endInsertRows
|
||||||
|
if( index < 0 )
|
||||||
|
m_parent->appendChild( this );
|
||||||
|
else
|
||||||
|
m_parent->insertChild( index, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,8 +68,8 @@ CategoryItem::activate()
|
|||||||
|
|
||||||
/// PlaylistItem
|
/// PlaylistItem
|
||||||
|
|
||||||
PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const playlist_ptr& pl )
|
PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const playlist_ptr& pl, int index )
|
||||||
: SourceTreeItem( mdl, parent, SourcesModel::StaticPlaylist )
|
: SourceTreeItem( mdl, parent, SourcesModel::StaticPlaylist, index )
|
||||||
, m_loaded( false )
|
, m_loaded( false )
|
||||||
, m_playlist( pl )
|
, m_playlist( pl )
|
||||||
{
|
{
|
||||||
@@ -278,7 +285,6 @@ CategoryItem::CategoryItem( SourcesModel* model, SourceTreeItem* parent, Sources
|
|||||||
// beginRowsAdded( 0, 0 );
|
// beginRowsAdded( 0, 0 );
|
||||||
if( m_showAdd ) {
|
if( m_showAdd ) {
|
||||||
m_addItem = new CategoryAddItem( model, this, m_category );
|
m_addItem = new CategoryAddItem( model, this, m_category );
|
||||||
appendChild( m_addItem );
|
|
||||||
}
|
}
|
||||||
// endRowsAdded();
|
// endRowsAdded();
|
||||||
}
|
}
|
||||||
@@ -316,10 +322,8 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
|||||||
}
|
}
|
||||||
// create category item
|
// create category item
|
||||||
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source->isLocal() );
|
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source->isLocal() );
|
||||||
appendChild( m_playlists );
|
|
||||||
|
|
||||||
m_stations = new CategoryItem( model(), this, SourcesModel::StationsCategory, source->isLocal() );
|
m_stations = new CategoryItem( model(), this, SourcesModel::StationsCategory, source->isLocal() );
|
||||||
appendChild( m_stations );
|
|
||||||
|
|
||||||
// ugh :( we're being added by the model, no need to notify for added rows now
|
// ugh :( we're being added by the model, no need to notify for added rows now
|
||||||
m_playlists->blockSignals( true );
|
m_playlists->blockSignals( true );
|
||||||
@@ -365,14 +369,18 @@ CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QList< SourceTreeItem* > items;
|
QList< SourceTreeItem* > items;
|
||||||
|
int addOffset = playlists.first()->author()->isLocal() ? 1 : 0;
|
||||||
|
|
||||||
|
int from = m_playlists->children().count() - addOffset;
|
||||||
|
m_playlists->beginRowsAdded( from, from + playlists.count() - 1 );
|
||||||
foreach( const playlist_ptr& p, playlists )
|
foreach( const playlist_ptr& p, playlists )
|
||||||
{
|
{
|
||||||
PlaylistItem* plItem = new PlaylistItem( model(), m_playlists, p );
|
PlaylistItem* plItem = new PlaylistItem( model(), m_playlists, p, m_playlists->children().count() - addOffset );
|
||||||
qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
|
qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
|
||||||
p->loadRevision();
|
p->loadRevision();
|
||||||
items << plItem;
|
items << plItem;
|
||||||
}
|
}
|
||||||
m_playlists->insertItems( items );
|
m_playlists->endRowsAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -31,7 +31,7 @@ class SourceTreeItem : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SourceTreeItem() : m_type( SourcesModel::Invalid ), m_parent( 0 ), m_model( 0 ) {}
|
SourceTreeItem() : m_type( SourcesModel::Invalid ), m_parent( 0 ), m_model( 0 ) {}
|
||||||
SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType );
|
SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType, int index = -1 ); // if index is -1, append at end of parent's child list
|
||||||
virtual ~SourceTreeItem();
|
virtual ~SourceTreeItem();
|
||||||
|
|
||||||
// generic info used by the tree model
|
// generic info used by the tree model
|
||||||
@@ -53,18 +53,17 @@ public:
|
|||||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action ) { return false; }
|
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action ) { return false; }
|
||||||
|
|
||||||
/// don't call me unless you are a sourcetreeitem. i prefer this to making everyone a friend
|
/// don't call me unless you are a sourcetreeitem. i prefer this to making everyone a friend
|
||||||
void beginRowsAdded( int from, int num ) { emit beginChildRowsAdded( from, num ); }
|
void beginRowsAdded( int from, int to ) { emit beginChildRowsAdded( from, to ); }
|
||||||
void endRowsAdded() { emit childRowsAdded(); }
|
void endRowsAdded() { emit childRowsAdded(); }
|
||||||
void beginRowsRemoved( int from, int num ) { emit beginChildRowsRemoved( from, num ); }
|
void beginRowsRemoved( int from, int to ) { emit beginChildRowsRemoved( from, to ); }
|
||||||
void endRowsRemoved() { emit childRowsRemoved(); }
|
void endRowsRemoved() { emit childRowsRemoved(); }
|
||||||
signals:
|
signals:
|
||||||
void updated();
|
void updated();
|
||||||
void selectRequest();
|
|
||||||
|
|
||||||
void beginChildRowsAdded( int fromRow, int num );
|
void beginChildRowsAdded( int fromRow, int toRow );
|
||||||
void childRowsAdded();
|
void childRowsAdded();
|
||||||
|
|
||||||
void beginChildRowsRemoved( int fromRow, int num );
|
void beginChildRowsRemoved( int fromRow, int toRow );
|
||||||
void childRowsRemoved();
|
void childRowsRemoved();
|
||||||
private:
|
private:
|
||||||
SourcesModel::RowType m_type;
|
SourcesModel::RowType m_type;
|
||||||
@@ -147,7 +146,7 @@ class PlaylistItem : public SourceTreeItem
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PlaylistItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::playlist_ptr& pl );
|
PlaylistItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::playlist_ptr& pl, int index = -1 );
|
||||||
|
|
||||||
virtual QString text() const;
|
virtual QString text() const;
|
||||||
virtual Tomahawk::playlist_ptr playlist() const;
|
virtual Tomahawk::playlist_ptr playlist() const;
|
||||||
|
@@ -77,10 +77,13 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
|||||||
setAllColumnsShowFocus( true );
|
setAllColumnsShowFocus( true );
|
||||||
setUniformRowHeights( false );
|
setUniformRowHeights( false );
|
||||||
setIndentation( 16 );
|
setIndentation( 16 );
|
||||||
setAnimated( true );
|
|
||||||
|
|
||||||
setSortingEnabled( true );
|
// setSortingEnabled( true );
|
||||||
sortByColumn( 1, Qt::AscendingOrder );
|
// sortByColumn( 1, Qt::AscendingOrder );
|
||||||
|
|
||||||
|
// TODO animation conflicts with the expanding-playlists-when-collection-is-null
|
||||||
|
// so investigate
|
||||||
|
// setAnimated( true );
|
||||||
|
|
||||||
setItemDelegate( new SourceDelegate( this ) );
|
setItemDelegate( new SourceDelegate( this ) );
|
||||||
|
|
||||||
@@ -237,7 +240,7 @@ SourceTreeView::onItemExpanded( const QModelIndex& idx )
|
|||||||
// make sure to expand children nodes for collections
|
// make sure to expand children nodes for collections
|
||||||
if( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection ) {
|
if( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection ) {
|
||||||
for( int i = 0; i < model()->rowCount( idx ); i++ ) {
|
for( int i = 0; i < model()->rowCount( idx ); i++ ) {
|
||||||
expand( model()->index( i, 0, idx ) );
|
setExpanded( model()->index( i, 0, idx ), true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,20 +269,6 @@ SourceTreeView::deletePlaylist()
|
|||||||
playlist_ptr playlist = item->playlist();
|
playlist_ptr playlist = item->playlist();
|
||||||
Playlist::remove( playlist );
|
Playlist::remove( playlist );
|
||||||
}
|
}
|
||||||
// SourcesModel::SourceType type = SourcesModel::indexType( idx );
|
|
||||||
// if ( type == SourcesModel::PlaylistSource )
|
|
||||||
// {
|
|
||||||
// playlist_ptr playlist = SourcesModel::indexToPlaylist( idx );
|
|
||||||
// if ( !playlist.isNull() )
|
|
||||||
// {
|
|
||||||
// qDebug() << "Playlist about to be deleted:" << playlist->title();
|
|
||||||
// Playlist::remove( playlist );
|
|
||||||
// }
|
|
||||||
// } else if( type == SourcesModel::DynamicPlaylistSource ) {
|
|
||||||
// dynplaylist_ptr playlist = SourcesModel::indexToDynamicPlaylist( idx );
|
|
||||||
// if( !playlist.isNull() )
|
|
||||||
// DynamicPlaylist::remove( playlist );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
explicit SourceTreeView( QWidget* parent = 0 );
|
explicit SourceTreeView( QWidget* parent = 0 );
|
||||||
|
|
||||||
|
public slots:
|
||||||
void showOfflineSources();
|
void showOfflineSources();
|
||||||
void hideOfflineSources();
|
void hideOfflineSources();
|
||||||
|
|
||||||
|
2
thirdparty/jreen
vendored
2
thirdparty/jreen
vendored
Submodule thirdparty/jreen updated: 126ef9d96b...040ca3f3cb
Reference in New Issue
Block a user