[vlc-devel] [PATCH 10/16] qt: provide direct access to model data in ML models
Pierre Lamot
pierre at videolabs.io
Wed May 27 17:06:51 CEST 2020
---
modules/gui/qt/medialibrary/mlbasemodel.cpp | 10 ++++++++++
modules/gui/qt/medialibrary/mlbasemodel.hpp | 2 ++
2 files changed, 12 insertions(+)
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp
index 3ba327f171..db56ced9d2 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.cpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp
@@ -55,6 +55,16 @@ void MLBaseModel::sortByColumn(QByteArray name, Qt::SortOrder order)
endResetModel();
}
+QMap<QString, QVariant> MLBaseModel::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;
+}
+
void MLBaseModel::onResetRequested()
{
beginResetModel();
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
index 125c599f49..1909094939 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
@@ -57,6 +57,8 @@ public:
Q_INVOKABLE virtual QVariantList getIdsForIndexes( QVariantList indexes ) const = 0;
Q_INVOKABLE virtual QVariantList getIdsForIndexes( QModelIndexList indexes ) const = 0;
+ Q_INVOKABLE QMap<QString, QVariant> getDataAt(int index);
+
signals:
void parentIdChanged();
void resetRequested();
--
2.25.1
More information about the vlc-devel
mailing list