aboutsummaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-12 17:53:38 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-13 11:39:36 -0800
commit46bb242c69c999575b4d67f262bb5676f243651f (patch)
treee080a575ebc027e4cc03ced43d7b77fffe76b31b /stats
parente5c30e042b8257b54e0611695e58246f42825b13 (diff)
downloadsubsurface-46bb242c69c999575b4d67f262bb5676f243651f.tar.gz
mobile/statistics: export ChartListModel to QML
For QML, the roles have to be associated dynamically with name. Moreover, the model has to be registered as a QML type to make it accessible from QML. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r--stats/chartlistmodel.cpp12
-rw-r--r--stats/chartlistmodel.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/stats/chartlistmodel.cpp b/stats/chartlistmodel.cpp
index ae9c71748..bce54ce25 100644
--- a/stats/chartlistmodel.cpp
+++ b/stats/chartlistmodel.cpp
@@ -60,6 +60,18 @@ Qt::ItemFlags ChartListModel::flags(const QModelIndex &index) const
: Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
+QHash<int, QByteArray> ChartListModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[Qt::DisplayRole] = "display";
+ roles[IconRole] = "icon";
+ roles[IconSizeRole] = "iconSize";
+ roles[ChartNameRole] = "chartName";
+ roles[IsHeaderRole] = "isHeader";
+ roles[Qt::UserRole] = "id";
+ return roles;
+}
+
QVariant ChartListModel::data(const QModelIndex &index, int role) const
{
int row = index.row();
diff --git a/stats/chartlistmodel.h b/stats/chartlistmodel.h
index a33f6875a..701dca50e 100644
--- a/stats/chartlistmodel.h
+++ b/stats/chartlistmodel.h
@@ -44,6 +44,7 @@ private:
QFont itemFont;
QFont headerFont;
std::vector<Item> items;
+ QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;