[vlc-commits] qt: provide direct access to model data in ML models
Pierre Lamot
git at videolan.org
Wed Jun 3 12:06:46 CEST 2020
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Tue Feb 25 10:35:39 2020 +0100| [34ae3b4f0b03f3c46c94b2c688d97ae074a578dc] | committer: Pierre Lamot
qt: provide direct access to model data in ML models
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=34ae3b4f0b03f3c46c94b2c688d97ae074a578dc
---
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();
More information about the vlc-commits
mailing list