[vlc-devel] [PATCH 12/16] qt: provide direct access to model data of network models
Pierre Lamot
pierre at videolabs.io
Wed May 27 17:06:53 CEST 2020
---
modules/gui/qt/network/networkdevicemodel.cpp | 10 ++++++++++
modules/gui/qt/network/networkdevicemodel.hpp | 2 ++
modules/gui/qt/network/networkmediamodel.cpp | 12 ++++++++++++
modules/gui/qt/network/networkmediamodel.hpp | 2 ++
4 files changed, 26 insertions(+)
diff --git a/modules/gui/qt/network/networkdevicemodel.cpp b/modules/gui/qt/network/networkdevicemodel.cpp
index 07e2dd4f69..ff9aa5d97e 100644
--- a/modules/gui/qt/network/networkdevicemodel.cpp
+++ b/modules/gui/qt/network/networkdevicemodel.cpp
@@ -204,6 +204,16 @@ bool NetworkDeviceModel::addAndPlay(const QModelIndexList& itemIdList)
return ret;
}
+QMap<QString, QVariant> NetworkDeviceModel::getDataAt(int idx)
+{
+ QMap<QString, QVariant> dataDict;
+ QHash<int,QByteArray> roles = roleNames();
+ for (auto role: roles.keys()) {
+ dataDict[roles[role]] = data(index(idx), role);
+ }
+ return dataDict;
+}
+
bool NetworkDeviceModel::initializeMediaSources()
{
auto libvlc = vlc_object_instance(m_ctx->getIntf());
diff --git a/modules/gui/qt/network/networkdevicemodel.hpp b/modules/gui/qt/network/networkdevicemodel.hpp
index bc662f5c62..166870361f 100644
--- a/modules/gui/qt/network/networkdevicemodel.hpp
+++ b/modules/gui/qt/network/networkdevicemodel.hpp
@@ -89,6 +89,8 @@ public:
Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
Q_INVOKABLE bool addAndPlay(const QModelIndexList& itemIdList);
+ Q_INVOKABLE QMap<QString, QVariant> getDataAt(int index);
+
signals:
void ctxChanged();
void sdSourceChanged();
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index bd1ccda102..ddb87b5e2b 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -106,6 +106,18 @@ QHash<int, QByteArray> NetworkMediaModel::roleNames() const
};
}
+
+QMap<QString, QVariant> NetworkMediaModel::getDataAt(int idx)
+{
+ QMap<QString, QVariant> dataDict;
+ QHash<int,QByteArray> roles = roleNames();
+ for (auto role: roles.keys()) {
+ dataDict[roles[role]] = data(index(idx), role);
+ }
+ return dataDict;
+}
+
+
int NetworkMediaModel::rowCount(const QModelIndex& parent) const
{
if ( parent.isValid() )
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index ebf4634f86..ee368c1848 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -124,6 +124,8 @@ public:
inline bool getParsingPending() const { return m_parsingPending; }
int getCount() const;
+ Q_INVOKABLE QMap<QString, QVariant> getDataAt(int idx);
+
Q_INVOKABLE bool addToPlaylist( int index );
Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
Q_INVOKABLE bool addToPlaylist(const QModelIndexList& itemIdList);
--
2.25.1
More information about the vlc-devel
mailing list