From 44fa85af6b4fa6c6b5d73140cbb0c3b17e2c8700 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 30 Oct 2011 18:28:17 -0400 Subject: [PATCH] sort chart dropdowns --- src/libtomahawk/widgets/BreadcrumbButton.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/widgets/BreadcrumbButton.cpp b/src/libtomahawk/widgets/BreadcrumbButton.cpp index 4a94b469a..e298d4b5b 100644 --- a/src/libtomahawk/widgets/BreadcrumbButton.cpp +++ b/src/libtomahawk/widgets/BreadcrumbButton.cpp @@ -102,6 +102,10 @@ 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 ) @@ -112,12 +116,19 @@ 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() )