[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt: use `QVector<SharedInputItem>` instead of `QVariantList` as...

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue May 7 06:32:08 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
ee5566c8 by Fatih Uzunoglu at 2024-05-07T05:58:14+00:00
qt: use `QVector<SharedInputItem>` instead of `QVariantList` as `PlaylistListModel::getItemsForIndexes()` return type

- - - - -
37dd8a1e by Fatih Uzunoglu at 2024-05-07T05:58:14+00:00
qt: use `QVector<SharedInputItem>` instead of `QVariantList` as `NetworkDeviceModel::getItemsForIndexes()` return type

- - - - -
8b36c244 by Fatih Uzunoglu at 2024-05-07T05:58:14+00:00
qt: use `QVector<SharedInputItem>` instead of `QVariantList` as `NetworkMediaModel::getItemsForIndexes()` return type

- - - - -
ba05d461 by Fatih Uzunoglu at 2024-05-07T05:58:14+00:00
qml: add `isArray()` to Helpers.js

`Array.isArray()` does not seem to
work well with QML.

- - - - -
c7b294d9 by Fatih Uzunoglu at 2024-05-07T05:58:14+00:00
qml: avoid using `Array.isArray()`

See QTBUG-112291.

- - - - -


13 changed files:

- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/network/networkdevicemodel.cpp
- modules/gui/qt/network/networkdevicemodel.hpp
- modules/gui/qt/network/networkmediamodel.cpp
- modules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/playlist/playlist_model.cpp
- modules/gui/qt/playlist/playlist_model.hpp
- modules/gui/qt/playlist/qml/PlaylistListView.qml
- modules/gui/qt/util/qml/FSM.qml
- modules/gui/qt/util/qml/Helpers.js
- modules/gui/qt/widgets/qml/ComboBoxExt.qml
- modules/gui/qt/widgets/qml/DragItem.qml
- modules/gui/qt/widgets/qml/PageLoader.qml


Changes:

=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -79,7 +79,7 @@ FocusScope {
         MainCtx.hasGridListMode = Qt.binding(() => item.hasGridListMode !== undefined && item.hasGridListMode)
         MainCtx.search.available = Qt.binding(() => item.isSearchable !== undefined && item.isSearchable)
         MainCtx.sort.model = Qt.binding(function () { return item.sortModel })
-        MainCtx.sort.available = Qt.binding(function () { return Array.isArray(item.sortModel) && item.sortModel.length > 0 })
+        MainCtx.sort.available = Qt.binding(function () { return Helpers.isArray(item.sortModel) && item.sortModel.length > 0 })
 
         if (Player.hasVideoOutput && MainCtx.hasEmbededVideo)
             _showMiniPlayer = true


=====================================
modules/gui/qt/network/networkdevicemodel.cpp
=====================================
@@ -559,10 +559,10 @@ bool NetworkDeviceModel::addAndPlay(const QModelIndexList& itemIdList)
 }
 
 /* Q_INVOKABLE */
-QVariantList NetworkDeviceModel::getItemsForIndexes(const QModelIndexList & indexes) const
+QVector<SharedInputItem> NetworkDeviceModel::getItemsForIndexes(const QModelIndexList & indexes) const
 {
     Q_D(const NetworkDeviceModel);
-    QVariantList items;
+    QVector<SharedInputItem> items;
 
     for (const QModelIndex & modelIndex : indexes)
     {
@@ -570,7 +570,7 @@ QVariantList NetworkDeviceModel::getItemsForIndexes(const QModelIndexList & inde
         if (!item)
             continue;
 
-        items.append(QVariant::fromValue(SharedInputItem(item->inputItem.get(), true)));
+        items.append(SharedInputItem(item->inputItem.get(), true));
     }
 
     return items;


=====================================
modules/gui/qt/network/networkdevicemodel.hpp
=====================================
@@ -115,7 +115,7 @@ public:
     Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
     Q_INVOKABLE bool addAndPlay(const QModelIndexList& itemIdList);
 
-    Q_INVOKABLE QVariantList getItemsForIndexes(const QModelIndexList & indexes) const;
+    Q_INVOKABLE QVector<SharedInputItem> getItemsForIndexes(const QModelIndexList & indexes) const;
 
 signals:
     void ctxChanged();


=====================================
modules/gui/qt/network/networkmediamodel.cpp
=====================================
@@ -721,10 +721,10 @@ bool NetworkMediaModel::addAndPlay(const QModelIndexList& itemIdList)
 }
 
 /* Q_INVOKABLE */
-QVariantList NetworkMediaModel::getItemsForIndexes(const QModelIndexList & indexes) const
+QVector<SharedInputItem> NetworkMediaModel::getItemsForIndexes(const QModelIndexList & indexes) const
 {
     Q_D(const NetworkMediaModel);
-    QVariantList items;
+    QVector<SharedInputItem> items;
 
     for (const QModelIndex & modelIndex : indexes)
     {
@@ -736,7 +736,7 @@ QVariantList NetworkMediaModel::getItemsForIndexes(const QModelIndexList & index
 
         const NetworkTreeItem & tree = item->tree;
 
-        items.append(QVariant::fromValue(SharedInputItem(tree.media.get(), true)));
+        items.append(SharedInputItem(tree.media.get(), true));
     }
 
     return items;


=====================================
modules/gui/qt/network/networkmediamodel.hpp
=====================================
@@ -174,7 +174,7 @@ public:
     Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
     Q_INVOKABLE bool addAndPlay(const QModelIndexList& itemIdList);
 
-    Q_INVOKABLE QVariantList getItemsForIndexes(const QModelIndexList & indexes) const;
+    Q_INVOKABLE QVector<SharedInputItem> getItemsForIndexes(const QModelIndexList & indexes) const;
 
 signals:
     void nameChanged();


=====================================
modules/gui/qt/playlist/playlist_model.cpp
=====================================
@@ -24,7 +24,6 @@
 #include "playlist_model_p.hpp"
 #include <algorithm>
 #include <cassert>
-#include "util/shared_input_item.hpp"
 #include "playlist_controller.hpp"
 
 namespace vlc {
@@ -402,11 +401,11 @@ int PlaylistListModel::getCurrentIndex() const
 }
 
 /* Q_INVOKABLE */
-QVariantList PlaylistListModel::getItemsForIndexes(const QVector<int> & indexes) const
+QVector<SharedInputItem> PlaylistListModel::getItemsForIndexes(const QVector<int> & indexes) const
 {
     Q_D(const PlaylistListModel);
 
-    QVariantList items;
+    QVector<SharedInputItem> items;
 
     for (int index : indexes)
     {
@@ -423,7 +422,7 @@ QVariantList PlaylistListModel::getItemsForIndexes(const QVector<int> & indexes)
         if (media == nullptr)
             continue;
 
-        items.append(QVariant::fromValue(SharedInputItem(media, true)));
+        items.append(SharedInputItem(media, true));
     }
 
     return items;


=====================================
modules/gui/qt/playlist/playlist_model.hpp
=====================================
@@ -26,6 +26,7 @@
 #include "playlist_common.hpp"
 #include "playlist_item.hpp"
 #include "util/vlctick.hpp"
+#include "util/shared_input_item.hpp"
 
 #include <QAbstractListModel>
 
@@ -71,7 +72,7 @@ public:
 
     int getCurrentIndex() const;
 
-    Q_INVOKABLE QVariantList getItemsForIndexes(const QVector<int> & indexes) const;
+    Q_INVOKABLE QVector<SharedInputItem> getItemsForIndexes(const QVector<int> & indexes) const;
 
 public slots:
     Playlist getPlaylist() const;


=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -88,7 +88,7 @@ T.Pane {
         // NOTE: Dropping medialibrary content into the queue.
         } else if (Helpers.isValidInstanceOf(item, Widgets.DragItem)) {
             return item.getSelectedInputItem().then((inputItems) => {
-                    if (!Array.isArray(inputItems) || inputItems.length === 0) {
+                    if (!Helpers.isArray(inputItems) || inputItems.length === 0) {
                         console.warn("can't convert items to input items");
                         return
                     }


=====================================
modules/gui/qt/util/qml/FSM.qml
=====================================
@@ -17,6 +17,8 @@
  *****************************************************************************/
 import QtQuick
 
+import "qrc:///util/Helpers.js" as Helpers
+
 /**
  * @brief a pure QML hierarchical Finite State Machine implementation
  *
@@ -136,7 +138,7 @@ FSMState {
         } else if (transitions === null || transitions.toString().startsWith("FSMState")) {
             _changeState(transitions)
             return true
-        } else if (Array.isArray(transitions)) {
+        } else if (Helpers.isArray(transitions)) {
             for (const t of transitions) {
                 //stop at the first accepted transition
                 if (_evaluateTransition(state, event, t, ...args))


=====================================
modules/gui/qt/util/qml/Helpers.js
=====================================
@@ -120,3 +120,7 @@ function flickablePositionContaining(flickable, y, height, topMargin, bottomMarg
 
     return newContentY
 }
+
+function isArray(obj) {
+    return (obj?.length !== undefined) ?? false
+}


=====================================
modules/gui/qt/widgets/qml/ComboBoxExt.qml
=====================================
@@ -23,6 +23,7 @@ import org.videolan.vlc 0.1
 
 import "qrc:///style/"
 import "qrc:///widgets/" as Widgets
+import "qrc:///util/Helpers.js" as Helpers
 
 T.ComboBox {
     id: control
@@ -59,7 +60,7 @@ T.ComboBox {
         padding: VLCStyle.margin_xsmall
         leftPadding: control.leftPadding
         contentItem: Widgets.ListLabel {
-            text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
+            text: control.textRole ? (Helpers.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
             color: control.color
             elide: Text.ElideRight
             verticalAlignment: Text.AlignVCenter


=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -164,7 +164,7 @@ Item {
     }
 
     function _setInputItems(inputItems) {
-        if (!Array.isArray(inputItems) || inputItems.length === 0) {
+        if (!Helpers.isArray(inputItems) || inputItems.length === 0) {
             console.warn("can't convert items to input items");
             dragItem._inputItems = null
             return


=====================================
modules/gui/qt/widgets/qml/PageLoader.qml
=====================================
@@ -137,7 +137,7 @@ StackViewExt {
      * @return {boolean}
      */
     function isDefaulLoadedForPath(path) {
-        console.assert(Array.isArray(path))
+        console.assert(Helpers.isArray(path))
 
         let subPageName
         if (path.length === 0) {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/289427f5c45eb4e6f2ef0eb4e69466e441e4e002...c7b294d94cf84ca615e3660aeec0ba99dfcfafa9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/289427f5c45eb4e6f2ef0eb4e69466e441e4e002...c7b294d94cf84ca615e3660aeec0ba99dfcfafa9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list