From 835e64fe558b8793f042493382b0c91009b28d43 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 25 Jan 2013 16:28:41 +0100 Subject: [PATCH] * Turned ugly if/else into a switch. --- src/libtomahawk/Album.h | 2 +- src/libtomahawk/Artist.h | 3 +- src/libtomahawk/playlist/PlayableModel.cpp | 76 ++++++++++++---------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/libtomahawk/Album.h b/src/libtomahawk/Album.h index 9fa18c1b9..9f2252118 100644 --- a/src/libtomahawk/Album.h +++ b/src/libtomahawk/Album.h @@ -74,7 +74,7 @@ signals: void coverChanged(); private slots: - void onTracksLoaded(Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); + void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData, const QVariant& output ); void infoSystemFinished( const QString& target ); diff --git a/src/libtomahawk/Artist.h b/src/libtomahawk/Artist.h index f3fc98fa4..ab7c0741b 100644 --- a/src/libtomahawk/Artist.h +++ b/src/libtomahawk/Artist.h @@ -77,6 +77,7 @@ public: void setWeakRef( QWeakPointer< Tomahawk::Artist > weakRef ) { m_ownRef = weakRef; } void loadId( bool autoCreate ); + signals: void tracksAdded( const QList& tracks, Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void albumsAdded( const QList& albums, Tomahawk::ModelMode mode ); @@ -88,7 +89,7 @@ signals: void statsLoaded(); private slots: - void onTracksLoaded(Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); + void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void onAlbumsFound( const QList& albums, const QVariant& data ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 4ac5cbcb2..709a7c1bc 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -271,45 +271,51 @@ PlayableModel::data( const QModelIndex& index, int role ) const if ( !entry ) return QVariant(); - if ( role == Qt::DecorationRole ) + switch ( role ) { - return QVariant(); - } - else if ( role == Qt::TextAlignmentRole ) - { - return QVariant( columnAlignment( index.column() ) ); - } - else if ( role == PlayableProxyModel::TypeRole ) - { - if ( entry->result() ) + case Qt::TextAlignmentRole: { - return Tomahawk::TypeResult; + return QVariant( columnAlignment( index.column() ) ); + break; } - 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() ) - { - return queryData( entry->query()->displayQuery(), index.column(), role ); - } - else if ( !entry->artist().isNull() ) - { - return artistData( entry->artist(), role ); - } - else if ( !entry->album().isNull() ) - { - return albumData( entry->album(), role ); + case 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; + } + break; + } + + default: + { + if ( !entry->query().isNull() ) + { + return queryData( entry->query()->displayQuery(), index.column(), role ); + } + else if ( !entry->artist().isNull() ) + { + return artistData( entry->artist(), role ); + } + else if ( !entry->album().isNull() ) + { + return albumData( entry->album(), role ); + } + break; + } } return QVariant();