| 26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
| 27 */ |
27 */ |
| 28 |
28 |
| 29 #include "model.h" |
29 #include "model.h" |
| 30 |
30 |
| |
31 |
| |
32 ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *userdata){ |
| |
33 this->obj = obj; |
| |
34 this->view = view; |
| |
35 this->var = var; |
| |
36 this->getvalue = getvalue; |
| |
37 this->callback = f; |
| |
38 this->userdata = userdata; |
| |
39 } |
| |
40 |
| |
41 int ListModel::rowCount(const QModelIndex& parent) const { |
| |
42 UiList *list = (UiList*)var->value; |
| |
43 return ui_list_count(list); |
| |
44 } |
| |
45 |
| |
46 QVariant ListModel::data(const QModelIndex &index, int role) const { |
| |
47 if(role == Qt::DisplayRole) { |
| |
48 UiList *ls = (UiList*)var->value; |
| |
49 void *rowData = ls->get(ls, index.row()); |
| |
50 if(rowData && getvalue) { |
| |
51 void *value = getvalue(rowData, 0); |
| |
52 return QString::fromUtf8((char*)value); |
| |
53 } |
| |
54 } |
| |
55 return QVariant(); |
| |
56 } |
| |
57 |
| |
58 void ListModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { |
| |
59 |
| |
60 } |
| |
61 |
| |
62 |