1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

add supercollection back

turn off proxy and cleanup trying to find signal issue
fix parent() that was causing all sorts of weird inserted bugs
fix removing to not work on a copy!
This commit is contained in:
Leo Franchi
2011-03-29 15:46:35 -04:00
parent e13bd93a58
commit 3378b1ef82
6 changed files with 33 additions and 10 deletions

View File

@@ -51,7 +51,7 @@ public slots:
virtual void removeTracks( const QDir& dir ); virtual void removeTracks( const QDir& dir );
private slots: private slots:
void dynamicPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); // void dynamicPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data );
}; };
#endif // DATABASECOLLECTION_H #endif // DATABASECOLLECTION_H

View File

@@ -33,7 +33,12 @@ 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() );
>>>>>>> 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 ) ) );
@@ -82,6 +87,7 @@ SourcesModel::rowCount( const QModelIndex& parent ) const
return itemFromIndex( parent )->children().count(); return itemFromIndex( parent )->children().count();
} }
<<<<<<< HEAD
bool bool
SourcesModel::hasChildren( const QModelIndex& parent ) const SourcesModel::hasChildren( const QModelIndex& parent ) const
{ {
@@ -90,6 +96,9 @@ SourcesModel::hasChildren( const QModelIndex& parent ) const
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;
@@ -101,8 +110,13 @@ 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( node ), 0, parent );
=======
return createIndex( rowForItem( parent ), 0, parent );
>>>>>>> add supercollection back
} }
QModelIndex QModelIndex
@@ -180,11 +194,18 @@ SourcesModel::appendItem( const Tomahawk::source_ptr& source )
m_rootItem->appendChild( item ); m_rootItem->appendChild( item );
endInsertRows(); endInsertRows();
<<<<<<< HEAD
qDebug() << "Appending source item:" << item->source()->friendlyName(); qDebug() << "Appending source item:" << item->source()->friendlyName();
=======
>>>>>>> add supercollection back
if ( !source.isNull() ) if ( !source.isNull() )
{ {
qDebug() << "Appending source item:" << item->source()->friendlyName();
connect( source.data(), SIGNAL( stats( QVariantMap ) ), SLOT( onSourceChanged() ) ); connect( source.data(), SIGNAL( stats( QVariantMap ) ), SLOT( onSourceChanged() ) );
connect( source.data(), SIGNAL( playbackStarted( Tomahawk::query_ptr ) ), SLOT( onSourceChanged() ) ); connect( source.data(), SIGNAL( playbackStarted( Tomahawk::query_ptr ) ), SLOT( onSourceChanged() ) );
connect( source.data(), SIGNAL( stateChanged() ), SLOT( onSourceChanged() ) ); connect( source.data(), SIGNAL( stateChanged() ), SLOT( onSourceChanged() ) );
@@ -369,7 +390,7 @@ SourcesModel::indexFromItem( SourceTreeItem* item ) const
idx = index( childIndexList[ i ], 0, idx ); idx = index( childIndexList[ i ], 0, idx );
} }
qDebug() << "Got index from item:" << idx << idx.data( Qt::DisplayRole ).toString(); qDebug() << "Got index from item:" << idx << idx.data( Qt::DisplayRole ).toString();
qDebug() << "parent:" << idx.parent();
return idx; return idx;
} }

View File

@@ -80,9 +80,8 @@ public:
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
virtual Qt::DropActions supportedDropActions() const; virtual Qt::DropActions supportedDropActions() const;
virtual Qt::ItemFlags flags(const QModelIndex& index) const; virtual Qt::ItemFlags flags(const QModelIndex& index) const;
virtual bool hasChildren( const QModelIndex& parent = QModelIndex() ) const;
void appendItem( const Tomahawk::source_ptr& source ); void appendItem( const Tomahawk::source_ptr& source );
bool removeItem( const Tomahawk::source_ptr& source ); bool removeItem( const Tomahawk::source_ptr& source );
signals: signals:

View File

@@ -172,6 +172,9 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
: SourceTreeItem( mdl, parent, SourcesModel::Collection ) : SourceTreeItem( mdl, parent, SourcesModel::Collection )
, m_source( source ) , m_source( source )
{ {
if( m_source.isNull() ) { // super collection
return;
}
// create category item // create category item
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory ); m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory );
appendChild( m_playlists ); appendChild( m_playlists );
@@ -237,14 +240,15 @@ CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
void void
CollectionItem::onPlaylistsDeleted( const QList< playlist_ptr >& playlists ) CollectionItem::onPlaylistsDeleted( const QList< playlist_ptr >& playlists )
{ {
int curCount = m_playlists->children().count();
foreach( const playlist_ptr& playlist, playlists ) { foreach( const playlist_ptr& playlist, playlists ) {
int curCount = m_playlists->children().count();
for( int i = 0; i < curCount; i++ ) { for( int i = 0; i < curCount; i++ ) {
PlaylistItem* pl = qobject_cast< PlaylistItem* >( m_playlists->children().at( i ) ); PlaylistItem* pl = qobject_cast< PlaylistItem* >( m_playlists->children().at( i ) );
if( pl && pl->playlist() == playlist ) { if( pl && pl->playlist() == playlist ) {
m_playlists->beginRowsRemoved( i, i ); m_playlists->beginRowsRemoved( i, i );
m_playlists->children().removeAt( i ); m_playlists->removeChild( pl );
m_playlists->endRowsRemoved(); m_playlists->endRowsRemoved();
break;
} }
} }
} }

View File

@@ -85,6 +85,7 @@ public:
return QString(); return QString();
} }
virtual void activate(); virtual void activate();
virtual Qt::ItemFlags flags() { return Qt::ItemIsEnabled; }
SourcesModel::CategoryType categoryType() { return m_category; } SourcesModel::CategoryType categoryType() { return m_category; }

View File

@@ -94,13 +94,11 @@ SourceTreeView::SourceTreeView( QWidget* parent )
header()->setStretchLastSection( false ); header()->setStretchLastSection( false );
header()->setResizeMode( 0, QHeaderView::Stretch ); header()->setResizeMode( 0, QHeaderView::Stretch );
connect( m_model, SIGNAL( clicked( QModelIndex ) ), SIGNAL( clicked( QModelIndex ) ) ); connect( m_proxyModel, SIGNAL( clicked( QModelIndex ) ), SIGNAL( clicked( QModelIndex ) ) );
connect( this, SIGNAL( clicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) ); connect( this, SIGNAL( clicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
connect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( onSelectionChanged() ) ); connect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( onSelectionChanged() ) );
// m_model->appendItem( source_ptr() );
hideOfflineSources(); hideOfflineSources();
// connect( PlaylistManager::instance(), SIGNAL( playlistActivated( Tomahawk::playlist_ptr ) ), // connect( PlaylistManager::instance(), SIGNAL( playlistActivated( Tomahawk::playlist_ptr ) ),
@@ -488,7 +486,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
Q_ASSERT( item ); Q_ASSERT( item );
QStyleOptionViewItemV4 o3 = option; QStyleOptionViewItemV4 o3 = option;
if ( type != SourcesModel::Collection ) if ( type != SourcesModel::Collection && type != SourcesModel::Category )
o3.rect.setX( 0 ); o3.rect.setX( 0 );
QApplication::style()->drawControl( QStyle::CE_ItemViewItem, &o3, painter ); QApplication::style()->drawControl( QStyle::CE_ItemViewItem, &o3, painter );