[vlc-commits] qml: change sort models from ListModel to Array

Pierre Lamot git at videolan.org
Fri Jan 10 15:06:21 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Dec 11 15:58:46 2019 +0100| [88ee5c11162f9b07e7e93b2d231a1b179ba98efc] | committer: Jean-Baptiste Kempf

qml: change sort models from ListModel to Array

  i18n.qtr can't be used in ListModel

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=88ee5c11162f9b07e7e93b2d231a1b179ba98efc
---

 .../gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml | 12 ++++++------
 .../qml/MusicAlbumsGridExpandDelegate.qml          | 10 +++++-----
 .../qt/medialibrary/qml/MusicArtistsDisplay.qml    |  6 +++---
 .../gui/qt/medialibrary/qml/MusicGenresDisplay.qml |  6 +++---
 .../qt/medialibrary/qml/MusicTrackListDisplay.qml  | 16 ++++++++--------
 .../gui/qt/medialibrary/qml/VideoListDisplay.qml   | 12 ++++++------
 modules/gui/qt/playlist/qml/PlaylistToolbar.qml    | 22 +++++++++++-----------
 .../gui/qt/widgets/qml/KeyNavigableTableView.qml   | 16 ++++++++--------
 8 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
index accc5b9e8e..f7f89c6d3e 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml
@@ -29,12 +29,12 @@ import "qrc:///style/"
 Widgets.NavigableFocusScope {
     id: root
 
-    property var sortModel: ListModel {
-        ListElement { text: qsTr("Alphabetic");  criteria: "title";}
-        ListElement { text: qsTr("Duration");    criteria: "duration"; }
-        ListElement { text: qsTr("Date");        criteria: "release_year"; }
-        ListElement { text: qsTr("Artist");      criteria: "main_artist"; }
-    }
+    property var sortModel: [
+        { text: i18n.qtr("Alphabetic"),  criteria: "title"},
+        { text: i18n.qtr("Duration"),    criteria: "duration" },
+        { text: i18n.qtr("Date"),        criteria: "release_year" },
+        { text: i18n.qtr("Artist"),      criteria: "main_artist" },
+    ]
 
     property alias model: delegateModel.model
     property alias parentId: delegateModel.parentId
diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml b/modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml
index c46df982e7..9b02f50295 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml
@@ -203,11 +203,11 @@ Widgets.NavigableFocusScope {
                     }
                 }
 
-                sortModel: ListModel {
-                    ListElement{ criteria: "track_number";  width:0.10; visible: true; text: qsTr("#"); showSection: "" }
-                    ListElement{isPrimary: true; criteria: "title";         width:0.70; visible: true; text: qsTr("Title"); showSection: "" }
-                    ListElement{ criteria: "duration";      width:0.20; visible: true; text: qsTr("Duration"); showSection: "" }
-                }
+                sortModel: [
+                    { criteria: "track_number",  width:0.10, visible: true, text: i18n.qtr("#"), showSection: "" },
+                    { isPrimary: true, criteria: "title",         width:0.70, visible: true, text: i18n.qtr("Title"), showSection: "" },
+                    { criteria: "duration",      width:0.20, visible: true, text: i18n.qtr("Duration"), showSection: "" },
+                ]
                 focus: true
 
                 navigationParent: root
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index 89cd31781d..896b6ae459 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -29,9 +29,9 @@ import "qrc:///style/"
 Widgets.NavigableFocusScope {
     id: root
     property alias model: delegateModel.model
-    property var sortModel: ListModel {
-        ListElement { text: qsTr("Alphabetic");  criteria: "title" }
-    }
+    property var sortModel: [
+        { text: i18n.qtr("Alphabetic"),  criteria: "title" }
+    ]
 
     property var artistId
 
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
index 7580daf6ed..e5cab3fe18 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
@@ -28,9 +28,9 @@ import "qrc:///style/"
 Widgets.NavigableFocusScope {
     id: root
     property alias model: delegateModel.model
-    property var sortModel: ListModel {
-        ListElement { text: qsTr("Alphabetic"); criteria: "title" }
-    }
+    property var sortModel: [
+        { text: i18n.qtr("Alphabetic"), criteria: "title" }
+    ]
 
     function goToView( parent ) {
         history.push([ "mc", "music", "albums", { parentId: parent } ], History.Go)
diff --git a/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
index 60d955dea8..bdcd13c136 100644
--- a/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
@@ -28,14 +28,14 @@ import "qrc:///style/"
 Widgets.KeyNavigableTableView {
     id: root
 
-    sortModel: ListModel {
-        ListElement{ isPrimary: true; criteria: "title";       width:0.44; text: qsTr("Title");    showSection: "title" }
-        ListElement{ criteria: "album_title"; width:0.25; text: qsTr("Album");    showSection: "album_title" }
-        ListElement{ criteria: "main_artist"; width:0.15; text: qsTr("Artist");   showSection: "main_artist" }
-        ListElement{ criteria: "duration";    width:0.06; text: qsTr("Duration"); showSection: "" }
-        ListElement{ criteria: "track_number";width:0.05; text: qsTr("Track"); showSection: "" }
-        ListElement{ criteria: "disc_number"; width:0.05; text: qsTr("Disc");  showSection: "" }
-    }
+    sortModel: [
+        { isPrimary: true, criteria: "title",       width:0.44, text: i18n.qtr("Title"),    showSection: "title" },
+        { criteria: "album_title", width:0.25, text: i18n.qtr("Album"),    showSection: "album_title" },
+        { criteria: "main_artist", width:0.15, text: i18n.qtr("Artist"),   showSection: "main_artist" },
+        { criteria: "duration",    width:0.06, text: i18n.qtr("Duration"), showSection: "" },
+        { criteria: "track_number",width:0.05, text: i18n.qtr("Track"), showSection: "" },
+        { criteria: "disc_number", width:0.05, text: i18n.qtr("Disc"),  showSection: "" },
+    ]
 
     section.property: "title_first_symbol"
 
diff --git a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
index b09e1d3ea0..5a72730d59 100644
--- a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
@@ -29,12 +29,12 @@ Widgets.KeyNavigableTableView {
     model: MLVideoModel {
         ml: medialib
     }
-    sortModel: ListModel {
-        ListElement{ type: "image"; criteria: "thumbnail";   width:0.2; text: qsTr("Thumbnail"); showSection: "" }
-        ListElement{ criteria: "duration";    width:0.1; text: qsTr("Duration"); showSection: "" }
-        ListElement{ isPrimary: true; criteria: "title";       width:0.6; text: qsTr("Title");    showSection: "title" }
-        ListElement{ type: "contextButton";   width:0.1; }
-    }
+    sortModel: [
+        { type: "image", criteria: "thumbnail",   width:0.2, text: i18n.qtr("Thumbnail"), showSection: "" },
+        { criteria: "duration",    width:0.1, text: i18n.qtr("Duration"), showSection: "" },
+        { isPrimary: true, criteria: "title",       width:0.6, text: i18n.qtr("Title"),    showSection: "title" },
+        { type: "contextButton",   width:0.1, },
+    ]
     section.property: "title_first_symbol"
 
     rowHeight: VLCStyle.video_small_height + VLCStyle.margin_normal
diff --git a/modules/gui/qt/playlist/qml/PlaylistToolbar.qml b/modules/gui/qt/playlist/qml/PlaylistToolbar.qml
index d08378f34a..7e3344ae7e 100644
--- a/modules/gui/qt/playlist/qml/PlaylistToolbar.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistToolbar.qml
@@ -88,17 +88,17 @@ Widgets.NavigableFocusScope {
                 //Layout.minimumWidth: VLCStyle.icon_normal * 2
                 popupAlignment: Qt.AlignRight | Qt.AlignTop
 
-                model: ListModel {
-                    ListElement { text: qsTr("Tile");             criteria: PlaylistControllerModel.SORT_KEY_TITLE}
-                    ListElement { text: qsTr("Duration");         criteria: PlaylistControllerModel.SORT_KEY_DURATION}
-                    ListElement { text: qsTr("Artist");           criteria: PlaylistControllerModel.SORT_KEY_ARTIST}
-                    ListElement { text: qsTr("Album");            criteria: PlaylistControllerModel.SORT_KEY_ALBUM}
-                    ListElement { text: qsTr("Genre");            criteria: PlaylistControllerModel.SORT_KEY_GENRE}
-                    ListElement { text: qsTr("Date");             criteria: PlaylistControllerModel.SORT_KEY_DATE}
-                    ListElement { text: qsTr("Track number");     criteria: PlaylistControllerModel.SORT_KEY_TRACK_NUMBER}
-                    ListElement { text: qsTr("URL");              criteria: PlaylistControllerModel.SORT_KEY_URL}
-                    ListElement { text: qsTr("Rating");           criteria: PlaylistControllerModel.SORT_KEY_RATIN}
-                }
+                model: [
+                    { text: i18n.qtr("Tile"),             criteria: PlaylistControllerModel.SORT_KEY_TITLE },
+                    { text: i18n.qtr("Duration"),         criteria: PlaylistControllerModel.SORT_KEY_DURATION },
+                    { text: i18n.qtr("Artist"),           criteria: PlaylistControllerModel.SORT_KEY_ARTIST },
+                    { text: i18n.qtr("Album"),            criteria: PlaylistControllerModel.SORT_KEY_ALBUM },
+                    { text: i18n.qtr("Genre"),            criteria: PlaylistControllerModel.SORT_KEY_GENRE },
+                    { text: i18n.qtr("Date"),             criteria: PlaylistControllerModel.SORT_KEY_DATE },
+                    { text: i18n.qtr("Track number"),     criteria: PlaylistControllerModel.SORT_KEY_TRACK_NUMBER },
+                    { text: i18n.qtr("URL"),              criteria: PlaylistControllerModel.SORT_KEY_URL },
+                    { text: i18n.qtr("Rating"),           criteria: PlaylistControllerModel.SORT_KEY_RATIN },
+                ]
                 textRole: "text"
 
                 listWidth: VLCStyle.widthSortBox
diff --git a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
index 2fc2899731..26d2ed9e5a 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -33,7 +33,7 @@ NavigableFocusScope {
     signal contextMenuButtonClicked(Item menuParent, var menuModel)
     signal rightClick(Item menuParent, var menuModel)
 
-    property var sortModel: ListModel { }
+    property var sortModel: []
     property Component colDelegate: Item { }
     property var model: []
 
@@ -106,14 +106,14 @@ NavigableFocusScope {
 
                                 Item {
                                     height: parent.height
-                                    width: model.width * view.width
+                                    width: modelData.width * view.width
                                     Layout.alignment: Qt.AlignVCenter
                                     Loader{
                                         anchors.fill: parent
                                         sourceComponent: colDelegate
 
                                         property var rowModel: element.rowModel
-                                        property var colModel: model
+                                        property var colModel: modelData
 
                                     }
 
@@ -159,11 +159,11 @@ NavigableFocusScope {
                         model: sortModel
                         MouseArea {
                             height: VLCStyle.fontHeight_normal
-                            width: model.width * view.width
+                            width: modelData.width * view.width
                             //Layout.alignment: Qt.AlignVCenter
 
                             Text {
-                                text: model.text || ""
+                                text: modelData.text || ""
                                 elide: Text.ElideRight
                                 font {
                                     pixelSize: VLCStyle.fontSize_normal
@@ -180,7 +180,7 @@ NavigableFocusScope {
 
                             Text {
                                 text: (root.model.sortOrder === Qt.AscendingOrder) ? "▼" : "▲"
-                                visible: root.model.sortCriteria === model.criteria
+                                visible: root.model.sortCriteria === modelData.criteria
                                 font.pixelSize: VLCStyle.fontSize_normal
                                 color: VLCStyle.colors.accent
                                 anchors {
@@ -190,8 +190,8 @@ NavigableFocusScope {
                                 }
                             }
                             onClicked: {
-                                if (root.model.sortCriteria !== model.criteria)
-                                    root.model.sortCriteria = model.criteria
+                                if (root.model.sortCriteria !== modelData.criteria)
+                                    root.model.sortCriteria = modelData.criteria
                                 else
                                     root.model.sortOrder = (root.model.sortOrder === Qt.AscendingOrder) ? Qt.DescendingOrder : Qt.AscendingOrder
                             }



More information about the vlc-commits mailing list