1 #include "tgabstractlistmodel.h"
2
3 #include <QHash>
4
TgAbstractListModel(QObject * parent)5 TgAbstractListModel::TgAbstractListModel(QObject *parent) :
6 QAbstractListModel(parent)
7 {
8 }
9
roles() const10 QStringList TgAbstractListModel::roles() const
11 {
12 QStringList result;
13 const QHash<int,QByteArray> &roles = roleNames();
14 QHashIterator<int,QByteArray> i(roles);
15 while(i.hasNext())
16 {
17 i.next();
18 result << i.value();
19 }
20
21 qSort(result.begin(), result.end());
22 return result;
23 }
24
get(int row,int role) const25 QVariant TgAbstractListModel::get(int row, int role) const
26 {
27 if(row >= rowCount())
28 return QVariant();
29
30 const QModelIndex &idx = index(row,0);
31 return data(idx , role);
32 }
33
get(int index) const34 QVariantMap TgAbstractListModel::get(int index) const
35 {
36 if(index >= rowCount())
37 return QVariantMap();
38
39 QVariantMap result;
40 const QHash<int,QByteArray> &roles = roleNames();
41 QHashIterator<int,QByteArray> i(roles);
42 while(i.hasNext())
43 {
44 i.next();
45 result[i.value()] = get(index, i.key());
46 }
47
48 return result;
49 }
50
~TgAbstractListModel()51 TgAbstractListModel::~TgAbstractListModel()
52 {
53 }
54
55