blob: 37232dc2c571a731d8592d47f61a777796b64f5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include <QtCore/QDebug>
#include <sailfishapp.h>
#include "availablewidgetsmodel.h"
AvailableWidgetsModel::AvailableWidgetsModel(QObject *parent) :
QAbstractListModel(parent)
{
reload();
}
QHash<int, QByteArray> AvailableWidgetsModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[UrlRole] = "url";
roles[DescriptionRole] = "description";
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<QUrl>(_widgets[row].url());
case DescriptionRole:
return QVariant::fromValue<QString>(_widgets[row].description());
case SizeRole:
return QVariant::fromValue<int>(_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/builtinface3.qml"));
info.setDescription("Builtin watchface #3");
info.setSize(WidgetInfo::Size4Q);
Q_ASSERT(info.builtinClockfaceId() == 3); // Autodetected from passed URL
_widgets.append(info);
info.setUrl(SailfishApp::pathTo("qml/watch/faces/builtinface4.qml"));
info.setDescription("Builtin watchface #4");
info.setSize(WidgetInfo::Size4Q);
Q_ASSERT(info.builtinClockfaceId() == 4);
_widgets.append(info);
endResetModel();
}
|