1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 08:52:12 +02:00

* Fixed sidebar sorting for items with identical names.

This commit is contained in:
Christian Muehlhaeuser 2011-08-17 03:18:39 +02:00
parent b1d57df4fc
commit ac3d410559
9 changed files with 42 additions and 3 deletions

@ -82,7 +82,7 @@ DirLister::scanDir( QDir dir, int depth, DirLister::Mode mode )
return;
}
tDebug( LOGVERBOSE ) << "DirLister::scanDir scanning: " << dir.canonicalPath() << " with mode " << mode;
tDebug( LOGVERBOSE ) << "DirLister::scanDir scanning:" << dir.canonicalPath() << "with mode" << mode;
if( !dir.exists() )
{
tDebug( LOGVERBOSE ) << "Dir no longer exists, not scanning";

@ -138,6 +138,18 @@ CollectionItem::text() const
}
int
CollectionItem::IDValue() const
{
if( m_source.isNull() )
return -1;
if( m_source->isLocal() )
return 0;
return m_source->id();
}
int
CollectionItem::peerSortValue() const
{

@ -37,6 +37,7 @@ public:
virtual void activate();
virtual QIcon icon() const;
virtual int peerSortValue() const;
virtual int IDValue() const;
Tomahawk::source_ptr source() const;

@ -87,6 +87,13 @@ PlaylistItem::peerSortValue() const
}
int
PlaylistItem::IDValue() const
{
return m_playlist->createdOn();
}
Qt::ItemFlags
PlaylistItem::flags() const
{
@ -244,6 +251,13 @@ DynamicPlaylistItem::peerSortValue() const
}
int
DynamicPlaylistItem::IDValue() const
{
return m_dynplaylist->createdOn();
}
void
DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& revision )
{

@ -38,6 +38,7 @@ public:
virtual QIcon icon() const;
virtual bool setData(const QVariant& v, bool role);
virtual int peerSortValue() const;
virtual int IDValue() const;
virtual bool activateCurrent();
@ -67,6 +68,7 @@ public:
virtual bool willAcceptDrag( const QMimeData* data ) const;
virtual void activate();
virtual int peerSortValue() const;
virtual int IDValue() const;
virtual QIcon icon() const;
virtual bool activateCurrent();

@ -55,6 +55,7 @@ public:
virtual bool dropMimeData( const QMimeData*, Qt::DropAction ) { return false; }
virtual bool setData( const QVariant&, bool ) { return false; }
virtual int peerSortValue() const { return 0; } // How to sort relative to peers in the tree.
virtual int IDValue() const { return 0; }
/// don't call me unless you are a sourcetreeitem. i prefer this to making everyone a friend
void beginRowsAdded( int from, int to ) { emit beginChildRowsAdded( from, to ); }

@ -106,6 +106,8 @@ SourcesModel::data( const QModelIndex& index, int role ) const
return itemFromIndex( index )->icon();
case SourcesModel::SortRole:
return itemFromIndex( index )->peerSortValue();
case SourcesModel::IDRole:
return itemFromIndex( index )->IDValue();
}
return QVariant();
}

@ -61,7 +61,8 @@ public:
enum Roles {
SourceTreeItemRole = Qt::UserRole + 10,
SourceTreeItemTypeRole = Qt::UserRole + 11,
SortRole = Qt::UserRole + 12
SortRole = Qt::UserRole + 12,
IDRole = Qt::UserRole + 13
};
SourcesModel( QObject* parent = 0 );

@ -94,5 +94,11 @@ SourcesProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right )
if ( m_model->data( left, SourcesModel::SortRole ) != m_model->data( right, SourcesModel::SortRole ) )
return ( m_model->data( left, SourcesModel::SortRole ).toInt() < m_model->data( right, SourcesModel::SortRole ).toInt() );
return QString::localeAwareCompare( left.data().toString().toLower(), right.data().toString().toLower() ) < 0;
const QString& lefts = left.data().toString().toLower();
const QString& rights = right.data().toString().toLower();
if ( lefts == rights )
return ( m_model->data( left, SourcesModel::IDRole ).toInt() < m_model->data( right, SourcesModel::IDRole ).toInt() );
else
return QString::localeAwareCompare( lefts, rights ) < 0;
}