mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-22 16:59:58 +01:00
* Speed up item detection & size-hint calculation for huge collections.
This commit is contained in:
parent
655a5d8ecf
commit
04e8132384
@ -78,6 +78,14 @@ namespace Tomahawk
|
||||
InfoSystemMode,
|
||||
};
|
||||
|
||||
enum ModelTypes
|
||||
{
|
||||
TypeArtist = 0,
|
||||
TypeAlbum,
|
||||
TypeQuery,
|
||||
TypeResult
|
||||
};
|
||||
|
||||
class ExternalResolver;
|
||||
typedef boost::function<Tomahawk::ExternalResolver*(QString)> ResolverFactoryFunc;
|
||||
|
||||
|
@ -24,14 +24,15 @@
|
||||
#include <QMimeData>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "audio/AudioEngine.h"
|
||||
#include "utils/TomahawkUtils.h"
|
||||
#include "Source.h"
|
||||
|
||||
#include "Artist.h"
|
||||
#include "Album.h"
|
||||
#include "Pipeline.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"
|
||||
|
||||
using namespace Tomahawk;
|
||||
@ -274,11 +275,29 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if ( role == Qt::TextAlignmentRole )
|
||||
else if ( role == Qt::TextAlignmentRole )
|
||||
{
|
||||
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() )
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
{ Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3, Collection = 4 };
|
||||
|
||||
enum PlayableProxyModelRole
|
||||
{ StyleRole = Qt::UserRole + 1 };
|
||||
{ StyleRole = Qt::UserRole + 1, TypeRole };
|
||||
|
||||
explicit PlayableProxyModel ( QObject* parent = 0 );
|
||||
virtual ~PlayableProxyModel() {}
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "PlayableItem.h"
|
||||
#include "TreeProxyModel.h"
|
||||
#include "TreeView.h"
|
||||
#include "Typedefs.h"
|
||||
|
||||
|
||||
TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy )
|
||||
@ -48,23 +49,28 @@ TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy )
|
||||
QSize
|
||||
TreeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
QSize size = QStyledItemDelegate::sizeHint( option, index );
|
||||
QSize size;
|
||||
|
||||
if ( index.isValid() )
|
||||
{
|
||||
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
||||
if ( item )
|
||||
Tomahawk::ModelTypes type = (Tomahawk::ModelTypes)index.data( PlayableProxyModel::TypeRole ).toInt();
|
||||
switch ( type )
|
||||
{
|
||||
if ( item->album() )
|
||||
case Tomahawk::TypeAlbum:
|
||||
{
|
||||
size.setHeight( option.fontMetrics.height() * 3 );
|
||||
return size;
|
||||
}
|
||||
else if ( item->query() || item->result() )
|
||||
|
||||
case Tomahawk::TypeQuery:
|
||||
case Tomahawk::TypeResult:
|
||||
{
|
||||
size.setHeight( option.fontMetrics.height() * 1.6 );
|
||||
return size;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user