#include #include "availablewidgetsmodel.h" AvailableWidgetsModel::AvailableWidgetsModel(QObject *parent) : QAbstractListModel(parent) { reload(); } QHash AvailableWidgetsModel::roleNames() const { QHash roles; roles[UrlRole] = "url"; roles[SizeRole] = "size"; return roles; } int AvailableWidgetsModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; return _widgets.size(); } QVariant AvailableWidgetsModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); const int row = index.row(); if (row < 0 || row >= _widgets.size()) return QVariant(); switch (role) { case UrlRole: return QVariant::fromValue(_widgets[row].url()); case DescriptionRole: return QVariant::fromValue(_widgets[row].description()); case SizeRole: return QVariant::fromValue(_widgets[row].size()); default: qWarning() << "Unknown role:" << role; return QVariant(); } } void AvailableWidgetsModel::reload() { beginResetModel(); _widgets.clear(); // Load builtin widgets WidgetInfo info; info.setUrl(SailfishApp::pathTo("qml/watch/faces/builtinface4.qml")); info.setDescription("Watchface #4"); info.setSize(WidgetInfo::Size4Q); _widgets.append(info); info.setUrl(SailfishApp::pathTo("qml/watch/faces/builtinface4.qml")); info.setDescription("Watchface #4"); info.setSize(WidgetInfo::Size4Q); _widgets.append(info); endResetModel(); }