mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-20 04:41:36 +02:00
* Split up PlItem into Track- and TreeModelItem.
This commit is contained in:
@@ -90,6 +90,7 @@ set( libSources
|
||||
playlist/trackproxymodel.cpp
|
||||
playlist/trackview.cpp
|
||||
playlist/trackheader.cpp
|
||||
playlist/treemodelitem.cpp
|
||||
playlist/albumitem.cpp
|
||||
playlist/albummodel.cpp
|
||||
playlist/albumproxymodel.cpp
|
||||
@@ -245,6 +246,7 @@ set( libHeaders
|
||||
playlist/trackproxymodel.h
|
||||
playlist/trackview.h
|
||||
playlist/trackheader.h
|
||||
playlist/treemodelitem.h
|
||||
playlist/albumitem.h
|
||||
playlist/albummodel.h
|
||||
playlist/albumproxymodel.h
|
||||
|
@@ -49,8 +49,8 @@ CollectionModel::index( int row, int column, const QModelIndex& parent ) const
|
||||
if ( !m_rootItem || row < 0 || column < 0 )
|
||||
return QModelIndex();
|
||||
|
||||
TrackModelItem* parentItem = itemFromIndex( parent );
|
||||
TrackModelItem* childItem = parentItem->children.value( row );
|
||||
TreeModelItem* parentItem = itemFromIndex( parent );
|
||||
TreeModelItem* childItem = parentItem->children.value( row );
|
||||
if ( !childItem )
|
||||
return QModelIndex();
|
||||
|
||||
@@ -64,7 +64,7 @@ CollectionModel::rowCount( const QModelIndex& parent ) const
|
||||
if ( parent.column() > 0 )
|
||||
return 0;
|
||||
|
||||
TrackModelItem* parentItem = itemFromIndex( parent );
|
||||
TreeModelItem* parentItem = itemFromIndex( parent );
|
||||
if ( !parentItem )
|
||||
return 0;
|
||||
|
||||
@@ -83,15 +83,15 @@ CollectionModel::columnCount( const QModelIndex& parent ) const
|
||||
QModelIndex
|
||||
CollectionModel::parent( const QModelIndex& child ) const
|
||||
{
|
||||
TrackModelItem* entry = itemFromIndex( child );
|
||||
TreeModelItem* entry = itemFromIndex( child );
|
||||
if ( !entry )
|
||||
return QModelIndex();
|
||||
|
||||
TrackModelItem* parentEntry = entry->parent;
|
||||
TreeModelItem* parentEntry = entry->parent;
|
||||
if ( !parentEntry )
|
||||
return QModelIndex();
|
||||
|
||||
TrackModelItem* grandparentEntry = parentEntry->parent;
|
||||
TreeModelItem* grandparentEntry = parentEntry->parent;
|
||||
if ( !grandparentEntry )
|
||||
return QModelIndex();
|
||||
|
||||
@@ -106,7 +106,7 @@ CollectionModel::data( const QModelIndex& index, int role ) const
|
||||
if ( role != Qt::DisplayRole )
|
||||
return QVariant();
|
||||
|
||||
TrackModelItem* entry = itemFromIndex( index );
|
||||
TreeModelItem* entry = itemFromIndex( index );
|
||||
if ( !entry )
|
||||
return QVariant();
|
||||
|
||||
@@ -199,7 +199,7 @@ CollectionModel::removeCollection( const collection_ptr& collection )
|
||||
disconnect( collection.data(), SIGNAL( tracksFinished( Tomahawk::collection_ptr ) ),
|
||||
this, SLOT( onTracksAddingFinished( Tomahawk::collection_ptr ) ) );
|
||||
|
||||
QList<TrackModelItem*> plitems = m_collectionIndex.values( collection );
|
||||
QList<TreeModelItem*> plitems = m_collectionIndex.values( collection );
|
||||
|
||||
m_collectionIndex.remove( collection );
|
||||
}
|
||||
@@ -210,17 +210,17 @@ CollectionModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const
|
||||
{
|
||||
// int c = rowCount( QModelIndex() );
|
||||
|
||||
TrackModelItem* plitem;
|
||||
TreeModelItem* plitem;
|
||||
foreach( const Tomahawk::query_ptr& query, tracks )
|
||||
{
|
||||
TrackModelItem* parent = m_rootItem;
|
||||
TreeModelItem* parent = m_rootItem;
|
||||
if ( parent->hash.contains( query->artist() ) )
|
||||
{
|
||||
parent = parent->hash.value( query->artist() );
|
||||
}
|
||||
else
|
||||
{
|
||||
parent = new TrackModelItem( query->artist(), m_rootItem );
|
||||
parent = new TreeModelItem( query->artist(), m_rootItem );
|
||||
m_rootItem->hash.insert( query->artist(), parent );
|
||||
}
|
||||
|
||||
@@ -232,14 +232,14 @@ CollectionModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const
|
||||
}
|
||||
else
|
||||
{
|
||||
TrackModelItem* subitem = new TrackModelItem( query->album(), parent );
|
||||
TreeModelItem* subitem = new TreeModelItem( query->album(), parent );
|
||||
parent->hash.insert( query->album(), subitem );
|
||||
parent->childCount++;
|
||||
subitem->childCount++;
|
||||
parent = subitem;
|
||||
}
|
||||
|
||||
plitem = new TrackModelItem( query, parent );
|
||||
plitem = new TreeModelItem( query, parent );
|
||||
m_collectionIndex.insertMulti( collection, plitem );
|
||||
}
|
||||
|
||||
@@ -275,11 +275,11 @@ CollectionModel::onSourceOffline( Tomahawk::source_ptr src )
|
||||
}
|
||||
|
||||
|
||||
TrackModelItem*
|
||||
TreeModelItem*
|
||||
CollectionModel::itemFromIndex( const QModelIndex& index ) const
|
||||
{
|
||||
if ( index.isValid() )
|
||||
return static_cast<TrackModelItem*>( index.internalPointer() );
|
||||
return static_cast<TreeModelItem*>( index.internalPointer() );
|
||||
else
|
||||
{
|
||||
return m_rootItem;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
|
||||
#include "trackmodelitem.h"
|
||||
#include "treemodelitem.h"
|
||||
#include "collection.h"
|
||||
#include "query.h"
|
||||
#include "typedefs.h"
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
virtual void setRepeatMode( PlaylistInterface::RepeatMode /*mode*/ ) {}
|
||||
virtual void setShuffled( bool /*shuffled*/ ) {}
|
||||
|
||||
TrackModelItem* itemFromIndex( const QModelIndex& index ) const;
|
||||
TreeModelItem* itemFromIndex( const QModelIndex& index ) const;
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
|
||||
@@ -79,8 +79,8 @@ private slots:
|
||||
void onSourceOffline( Tomahawk::source_ptr src );
|
||||
|
||||
private:
|
||||
TrackModelItem* m_rootItem;
|
||||
QMap< Tomahawk::collection_ptr, TrackModelItem* > m_collectionIndex;
|
||||
TreeModelItem* m_rootItem;
|
||||
QMap< Tomahawk::collection_ptr, TreeModelItem* > m_collectionIndex;
|
||||
};
|
||||
|
||||
#endif // COLLECTIONMODEL_H
|
||||
|
@@ -46,11 +46,6 @@ CollectionProxyModel::lessThan( const QModelIndex& left, const QModelIndex& righ
|
||||
const Tomahawk::query_ptr& q1 = p1->query();
|
||||
const Tomahawk::query_ptr& q2 = p2->query();
|
||||
|
||||
if ( q1.isNull() || q2.isNull() )
|
||||
{
|
||||
return QString::localeAwareCompare( p1->caption, p2->caption ) < 0;
|
||||
}
|
||||
|
||||
QString artist1 = q1->artist();
|
||||
QString artist2 = q2->artist();
|
||||
QString album1 = q1->album();
|
||||
|
@@ -127,21 +127,6 @@ TrackModel::data( const QModelIndex& index, int role ) const
|
||||
return QVariant();
|
||||
|
||||
const query_ptr& query = entry->query();
|
||||
if ( query.isNull() )
|
||||
{
|
||||
if ( !index.column() )
|
||||
{
|
||||
return entry->caption.isEmpty() ? "Unknown" : entry->caption;
|
||||
}
|
||||
|
||||
if ( index.column() == 1 )
|
||||
{
|
||||
return entry->childCount;
|
||||
}
|
||||
|
||||
return QVariant( "" );
|
||||
}
|
||||
|
||||
if ( !query->numResults() )
|
||||
{
|
||||
switch( index.column() )
|
||||
|
@@ -56,22 +56,6 @@ TrackModelItem::TrackModelItem( TrackModelItem* parent, QAbstractItemModel* mode
|
||||
}
|
||||
|
||||
|
||||
TrackModelItem::TrackModelItem( const QString& caption, TrackModelItem* parent )
|
||||
{
|
||||
this->parent = parent;
|
||||
this->caption = caption;
|
||||
this->model = parent->model;
|
||||
childCount = 0;
|
||||
m_isPlaying = false;
|
||||
toberemoved = false;
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
parent->children.append( this );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TrackModelItem::TrackModelItem( const Tomahawk::query_ptr& query, TrackModelItem* parent, int row )
|
||||
: QObject( parent )
|
||||
{
|
||||
@@ -86,16 +70,21 @@ TrackModelItem::TrackModelItem( const Tomahawk::plentry_ptr& entry, TrackModelIt
|
||||
setupItem( entry->query(), parent, row );
|
||||
}
|
||||
|
||||
|
||||
const Tomahawk::plentry_ptr&
|
||||
TrackModelItem::entry() const
|
||||
{
|
||||
return m_entry;
|
||||
}
|
||||
|
||||
|
||||
const Tomahawk::query_ptr&
|
||||
TrackModelItem::query() const
|
||||
{
|
||||
if ( !m_entry.isNull() ) return m_entry->query(); else return m_query;
|
||||
if ( !m_entry.isNull() )
|
||||
return m_entry->query();
|
||||
else
|
||||
return m_query;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +112,7 @@ TrackModelItem::setupItem( const Tomahawk::query_ptr& query, TrackModelItem* par
|
||||
m_query = query;
|
||||
if ( query->numResults() )
|
||||
{
|
||||
emit dataChanged();
|
||||
// emit dataChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -37,7 +37,6 @@ public:
|
||||
virtual ~TrackModelItem();
|
||||
|
||||
explicit TrackModelItem( TrackModelItem* parent = 0, QAbstractItemModel* model = 0 );
|
||||
explicit TrackModelItem( const QString& caption, TrackModelItem* parent = 0 );
|
||||
explicit TrackModelItem( const Tomahawk::query_ptr& query, TrackModelItem* parent = 0, int row = -1 );
|
||||
explicit TrackModelItem( const Tomahawk::plentry_ptr& entry, TrackModelItem* parent = 0, int row = -1 );
|
||||
|
||||
@@ -49,8 +48,6 @@ public:
|
||||
|
||||
TrackModelItem* parent;
|
||||
QVector<TrackModelItem*> children;
|
||||
QHash<QString, TrackModelItem*> hash;
|
||||
QString caption;
|
||||
int childCount;
|
||||
QPersistentModelIndex index;
|
||||
QAbstractItemModel* model;
|
||||
|
Reference in New Issue
Block a user