[vlc-devel] [PATCH 21/29] qt: add function to access PlayerIdentifier enum from qml
Fatih Uzunoglu
fuzun54 at outlook.com
Thu Apr 1 22:22:33 UTC 2021
---
.../gui/qt/player/player_controlbar_model.cpp | 27 +++++++++++++++++++
.../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();
--
2.27.0
More information about the vlc-devel
mailing list