1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 05:37:29 +02:00

* Speed up item detection & size-hint calculation for huge collections.

This commit is contained in:
Christian Muehlhaeuser
2013-01-09 09:06:04 +01:00
parent 655a5d8ecf
commit 04e8132384
4 changed files with 45 additions and 12 deletions

View File

@@ -78,6 +78,14 @@ namespace Tomahawk
InfoSystemMode, InfoSystemMode,
}; };
enum ModelTypes
{
TypeArtist = 0,
TypeAlbum,
TypeQuery,
TypeResult
};
class ExternalResolver; class ExternalResolver;
typedef boost::function<Tomahawk::ExternalResolver*(QString)> ResolverFactoryFunc; typedef boost::function<Tomahawk::ExternalResolver*(QString)> ResolverFactoryFunc;

View File

@@ -24,14 +24,15 @@
#include <QMimeData> #include <QMimeData>
#include <QTreeView> #include <QTreeView>
#include "audio/AudioEngine.h"
#include "utils/TomahawkUtils.h"
#include "Source.h"
#include "Artist.h" #include "Artist.h"
#include "Album.h" #include "Album.h"
#include "Pipeline.h" #include "Pipeline.h"
#include "PlayableItem.h" #include "PlayableItem.h"
#include "PlayableProxyModel.h"
#include "Source.h"
#include "Typedefs.h"
#include "audio/AudioEngine.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -274,11 +275,29 @@ PlayableModel::data( const QModelIndex& index, int role ) const
{ {
return QVariant(); return QVariant();
} }
else if ( role == Qt::TextAlignmentRole )
if ( role == Qt::TextAlignmentRole )
{ {
return QVariant( columnAlignment( index.column() ) ); return QVariant( columnAlignment( index.column() ) );
} }
else if ( role == PlayableProxyModel::TypeRole )
{
if ( entry->result() )
{
return Tomahawk::TypeResult;
}
else if ( entry->query() )
{
return Tomahawk::TypeQuery;
}
else if ( entry->artist() )
{
return Tomahawk::TypeArtist;
}
else if ( entry->album() )
{
return Tomahawk::TypeAlbum;
}
}
if ( !entry->query().isNull() ) if ( !entry->query().isNull() )
{ {

View File

@@ -36,7 +36,7 @@ public:
{ Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3, Collection = 4 }; { Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3, Collection = 4 };
enum PlayableProxyModelRole enum PlayableProxyModelRole
{ StyleRole = Qt::UserRole + 1 }; { StyleRole = Qt::UserRole + 1, TypeRole };
explicit PlayableProxyModel ( QObject* parent = 0 ); explicit PlayableProxyModel ( QObject* parent = 0 );
virtual ~PlayableProxyModel() {} virtual ~PlayableProxyModel() {}

View File

@@ -35,6 +35,7 @@
#include "PlayableItem.h" #include "PlayableItem.h"
#include "TreeProxyModel.h" #include "TreeProxyModel.h"
#include "TreeView.h" #include "TreeView.h"
#include "Typedefs.h"
TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy ) TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy )
@@ -48,23 +49,28 @@ TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy )
QSize QSize
TreeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const TreeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
QSize size = QStyledItemDelegate::sizeHint( option, index ); QSize size;
if ( index.isValid() ) if ( index.isValid() )
{ {
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); Tomahawk::ModelTypes type = (Tomahawk::ModelTypes)index.data( PlayableProxyModel::TypeRole ).toInt();
if ( item ) switch ( type )
{ {
if ( item->album() ) case Tomahawk::TypeAlbum:
{ {
size.setHeight( option.fontMetrics.height() * 3 ); size.setHeight( option.fontMetrics.height() * 3 );
return size; return size;
} }
else if ( item->query() || item->result() )
case Tomahawk::TypeQuery:
case Tomahawk::TypeResult:
{ {
size.setHeight( option.fontMetrics.height() * 1.6 ); size.setHeight( option.fontMetrics.height() * 1.6 );
return size; return size;
} }
default:
break;
} }
} }