[vlc-commits] qt/mlbasemodel: Add 'getData' function for QModelIndex

Benjamin Arnaud git at videolan.org
Tue Apr 20 12:49:06 UTC 2021


vlc | branch: master | Benjamin Arnaud <benjamin.arnaud at videolabs.io> | Tue Mar 30 10:48:03 2021 +0200| [8586c48223263274419f007b19ab349b75faa6fb] | committer: Pierre Lamot

qt/mlbasemodel: Add 'getData' function for QModelIndex

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

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

 modules/gui/qt/medialibrary/mlbasemodel.cpp | 21 +++++++++++++++++----
 modules/gui/qt/medialibrary/mlbasemodel.hpp |  3 ++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp
index c3d00d65cb..5af3cd3916 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.cpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp
@@ -52,16 +52,29 @@ void MLBaseModel::sortByColumn(QByteArray name, Qt::SortOrder order)
     endResetModel();
 }
 
-QMap<QString, QVariant> MLBaseModel::getDataAt(int idx)
+//-------------------------------------------------------------------------------------------------
+
+/* Q_INVOKABLE */ QMap<QString, QVariant> MLBaseModel::getDataAt(const QModelIndex & index)
 {
     QMap<QString, QVariant> dataDict;
-    QHash<int,QByteArray> roles = roleNames();
-    for (auto role: roles.keys()) {
-        dataDict[roles[role]] = data(index(idx), role);
+
+    QHash<int, QByteArray> roles = roleNames();
+
+    for (int role: roles.keys())
+    {
+        dataDict[roles[role]] = data(index, role);
     }
+
     return dataDict;
 }
 
+/* Q_INVOKABLE */ QMap<QString, QVariant> MLBaseModel::getDataAt(int idx)
+{
+    return getDataAt(index(idx));
+}
+
+//-------------------------------------------------------------------------------------------------
+
 void MLBaseModel::onResetRequested()
 {
     beginResetModel();
diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
index 349a75a3fc..2c54681a45 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
@@ -74,7 +74,8 @@ public: // Interface
 
     Q_INVOKABLE virtual QVariantList getItemsForIndexes(const QModelIndexList & indexes) const;
 
-    Q_INVOKABLE QMap<QString, QVariant> getDataAt(int index);
+    Q_INVOKABLE QMap<QString, QVariant> getDataAt(const QModelIndex & index);
+    Q_INVOKABLE QMap<QString, QVariant> getDataAt(int idx);
 
 signals:
     void parentIdChanged();



More information about the vlc-commits mailing list