[vlc-commits] qt: add function to access PlayerIdentifier enum from qml

Fatih Uzunoglu git at videolan.org
Tue Apr 6 09:55:06 UTC 2021


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Apr  2 01:22:33 2021 +0300| [6f2673000556b63a719eb9273639d74632813186] | committer: Pierre Lamot

qt: add function to access PlayerIdentifier enum from qml

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

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

 modules/gui/qt/player/player_controlbar_model.cpp | 27 +++++++++++++++++++++++
 modules/gui/qt/player/player_controlbar_model.hpp | 10 +++++++++
 2 files changed, 37 insertions(+)

diff --git a/modules/gui/qt/player/player_controlbar_model.cpp b/modules/gui/qt/player/player_controlbar_model.cpp
index 9496e8f7ba..cc36cb2228 100644
--- a/modules/gui/qt/player/player_controlbar_model.cpp
+++ b/modules/gui/qt/player/player_controlbar_model.cpp
@@ -18,8 +18,35 @@
 
 #include "player_controlbar_model.hpp"
 
+#include <QMetaEnum>
+#include <QJSEngine>
+
 #include "control_list_model.hpp"
 
+QJSValue PlayerControlbarModel::getPlaylistIdentifierListModel(QQmlEngine *engine, QJSEngine *scriptEngine)
+{
+    Q_UNUSED(engine)
+
+    static const QMetaEnum metaEnum = QMetaEnum::fromType<PlayerIdentifier>();
+
+    QJSValue array = scriptEngine->newArray();
+
+    for (int i = 0; i < metaEnum.keyCount(); ++i)
+    {
+       QJSValue obj = scriptEngine->newObject();
+
+       obj.setProperty("identifier", metaEnum.value(i));
+       obj.setProperty("name", metaEnum.key(i));
+
+       array.setProperty(i, obj);
+    }
+
+    QJSValue value = scriptEngine->newObject();
+    value.setProperty("model", array);
+
+    return value;
+}
+
 PlayerControlbarModel::PlayerControlbarModel(QObject *parent) : QObject(parent)
 {
     m_left = new ControlListModel(this);
diff --git a/modules/gui/qt/player/player_controlbar_model.hpp b/modules/gui/qt/player/player_controlbar_model.hpp
index 0463122d47..3bf7e4c08c 100644
--- a/modules/gui/qt/player/player_controlbar_model.hpp
+++ b/modules/gui/qt/player/player_controlbar_model.hpp
@@ -20,6 +20,7 @@
 #define PLAYERCONTROLBARMODEL_HPP
 
 #include <QObject>
+#include <QJSValue>
 #include <array>
 
 class ControlListModel;
@@ -44,6 +45,15 @@ public:
         Miniplayer
     };
     Q_ENUM(PlayerIdentifier)
+    // This enum is iterated through QMetaEnum, and
+    // a model out of this enum is generated
+    // and used in the configuration editor.
+    // Thanks to MOC, adding an entry to this enum
+    // is enough for the editor to consider the
+    // added entry without any other modification.
+
+    static QJSValue getPlaylistIdentifierListModel(class QQmlEngine *engine,
+                                                   class QJSEngine *scriptEngine);
 
     explicit PlayerControlbarModel(QObject *parent = nullptr);
     ~PlayerControlbarModel();



More information about the vlc-commits mailing list