[vlc-devel] [PATCH 14/33] QML: sections of MusicTrackListDisplay are set by the sorting criteria

Adrien Maglo magsoft at videolan.org
Wed Jun 12 14:01:21 CEST 2019


---
 .../components/mediacenter/mlalbumtrackmodel.cpp  | 15 ++++++++++++---
 .../qt/qml/mediacenter/MusicTrackListDisplay.qml  | 13 ++++++++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp
index d9587e5fda..3c81b152af 100644
--- a/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp
+++ b/modules/gui/qt/components/mediacenter/mlalbumtrackmodel.cpp
@@ -29,7 +29,10 @@ enum Role {
     TRACK_DURATION,
     TRACK_ALBUM,
     TRACK_ARTIST,
-    TRACK_FIRST_SYMBOL,
+
+    TRACK_TITLE_FIRST_SYMBOL,
+    TRACK_ALBUM_FIRST_SYMBOL,
+    TRACK_ARTIST_FIRST_SYMBOL,
 };
 
 }
@@ -77,8 +80,12 @@ QVariant MLAlbumTrackModel::data(const QModelIndex &index, int role) const
         return QVariant::fromValue( ml_track->getAlbumTitle() );
     case TRACK_ARTIST:
         return QVariant::fromValue( ml_track->getArtist() );
-    case TRACK_FIRST_SYMBOL:
+    case TRACK_TITLE_FIRST_SYMBOL:
         return QVariant::fromValue( getFirstSymbol( ml_track->getTitle() ) );
+    case TRACK_ALBUM_FIRST_SYMBOL:
+        return QVariant::fromValue( getFirstSymbol( ml_track->getAlbumTitle() ) );
+    case TRACK_ARTIST_FIRST_SYMBOL:
+        return QVariant::fromValue( getFirstSymbol( ml_track->getArtist() ) );
     default :
         return QVariant();
     }
@@ -95,7 +102,9 @@ QHash<int, QByteArray> MLAlbumTrackModel::roleNames() const
         { TRACK_DURATION, "duration" },
         { TRACK_ALBUM, "album_title"},
         { TRACK_ARTIST, "main_artist"},
-        { TRACK_FIRST_SYMBOL, "first_symbol"},
+        { TRACK_TITLE_FIRST_SYMBOL, "title_first_symbol"},
+        { TRACK_ALBUM_FIRST_SYMBOL, "album_title_first_symbol"},
+        { TRACK_ARTIST_FIRST_SYMBOL, "main_artist_first_symbol"},
     };
 }
 
diff --git a/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml b/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml
index a33c0659f2..46701a4755 100644
--- a/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MusicTrackListDisplay.qml
@@ -37,13 +37,24 @@ Utils.KeyNavigableTableView {
         ListElement{ criteria: "disc_number"; width:0.05; text: qsTr("Disc");  showSection: "" }
     }
 
-    section.property: "first_symbol"
+    section.property: "title_first_symbol"
 
     headerColor: VLCStyle.colors.bg
 
     model: MLAlbumTrackModel {
         id: rootmodel
         ml: medialib
+        onSortCriteriaChanged: {
+            switch (rootmodel.sortCriteria) {
+            case "title":
+            case "album_title":
+            case "main_artist":
+                section.property = rootmodel.sortCriteria + "_first_symbol"
+                break;
+            default:
+                section.property = ""
+            }
+        }
     }
 
     property alias parentId: rootmodel.parentId
-- 
2.20.1



More information about the vlc-devel mailing list