mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
Properly sort
This commit is contained in:
parent
ca0166d8fd
commit
65779b18eb
@ -102,10 +102,6 @@ BreadcrumbButton::sizeHint() const
|
||||
return m_combo->sizeHint() + QSize( padding, 0 );
|
||||
}
|
||||
|
||||
bool caseInsensitiveLessThan( const QString &s1, const QString &s2 )
|
||||
{
|
||||
return s1.toLower() < s2.toLower();
|
||||
}
|
||||
|
||||
void
|
||||
BreadcrumbButton::setParentIndex( const QModelIndex& idx )
|
||||
@ -116,19 +112,12 @@ BreadcrumbButton::setParentIndex( const QModelIndex& idx )
|
||||
QStringList list;
|
||||
int count = m_model->rowCount( m_parentIndex );
|
||||
int defaultIndex = -1, userSelected = -1;
|
||||
|
||||
// Two-pass so we can sort the list first
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
list << m_model->index( i, 0, m_parentIndex ).data().toString();
|
||||
}
|
||||
qSort( list.begin(), list.end(), caseInsensitiveLessThan );
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
QModelIndex idx = m_model->index( i, 0, m_parentIndex );
|
||||
if ( idx.isValid() )
|
||||
{
|
||||
list << idx.data().toString();
|
||||
if ( idx.data( Breadcrumb::DefaultRole ).toBool() )
|
||||
defaultIndex = i;
|
||||
if ( idx.data( Breadcrumb::UserSelectedRole ).toBool() )
|
||||
|
@ -50,6 +50,7 @@ static QString s_whatsHotIdentifier = QString( "WhatsHotWidget" );
|
||||
WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, ui( new Ui::WhatsHotWidget )
|
||||
, m_sortedProxy( 0 )
|
||||
{
|
||||
ui->setupUi( this );
|
||||
|
||||
@ -64,6 +65,9 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
||||
TomahawkUtils::unmarginLayout( ui->verticalLayout->layout() );
|
||||
|
||||
m_crumbModelLeft = new QStandardItemModel( this );
|
||||
m_sortedProxy = new QSortFilterProxyModel( this );
|
||||
m_sortedProxy->setDynamicSortFilter( true );
|
||||
m_sortedProxy->setFilterCaseSensitivity( Qt::CaseInsensitive );
|
||||
|
||||
ui->breadCrumbLeft->setRootIcon( QPixmap( RESPATH "images/charts.png" ) );
|
||||
|
||||
@ -209,7 +213,9 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
||||
}
|
||||
}
|
||||
|
||||
ui->breadCrumbLeft->setModel( m_crumbModelLeft );
|
||||
m_sortedProxy->setSourceModel( m_crumbModelLeft );
|
||||
m_sortedProxy->sort( 0, Qt::AscendingOrder );
|
||||
ui->breadCrumbLeft->setModel( m_sortedProxy );
|
||||
break;
|
||||
}
|
||||
case InfoSystem::InfoChart:
|
||||
@ -310,7 +316,7 @@ void
|
||||
WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb changed" << index.data();
|
||||
QStandardItem* item = m_crumbModelLeft->itemFromIndex( index );
|
||||
QStandardItem* item = m_crumbModelLeft->itemFromIndex( m_sortedProxy->mapToSource( index ) );
|
||||
if( !item )
|
||||
return;
|
||||
if( !item->data( Breadcrumb::ChartIdRole ).isValid() )
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
class TreeModel;
|
||||
@ -91,6 +92,7 @@ private:
|
||||
Ui::WhatsHotWidget *ui;
|
||||
|
||||
QStandardItemModel* m_crumbModelLeft;
|
||||
QSortFilterProxyModel* m_sortedProxy;
|
||||
|
||||
// Cache our model data
|
||||
QHash< QString, AlbumModel* > m_albumModels;
|
||||
|
Loading…
x
Reference in New Issue
Block a user