| 31 |
31 |
| 32 #include <QTreeView> |
32 #include <QTreeView> |
| 33 #include <QTreeWidgetItem> |
33 #include <QTreeWidgetItem> |
| 34 #include <QListView> |
34 #include <QListView> |
| 35 |
35 |
| |
36 extern "C" void* ui_strmodel_getvalue(void *elm, int column) { |
| |
37 return column == 0 ? elm : NULL; |
| |
38 } |
| 36 |
39 |
| |
40 |
| |
41 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { |
| |
42 UiContainerPrivate *ctn = ui_obj_container(obj); |
| |
43 UI_APPLY_LAYOUT(ctn->layout, args); |
| |
44 |
| |
45 QListView *view = new QListView(); |
| |
46 |
| |
47 ui_getvaluefunc getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
| |
48 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.list, args.varname, UI_VAR_LIST); |
| |
49 |
| |
50 ListModel *model = new ListModel(obj, view, var, getvalue); |
| |
51 view->setModel(model); |
| |
52 |
| |
53 if(var) { |
| |
54 UiList *list = (UiList*)var->value; |
| |
55 list->update = ui_listmodel_update; |
| |
56 list->getselection = ui_listmodel_getselection; |
| |
57 list->setselection = ui_listmodel_setselection; |
| |
58 list->obj = model; |
| |
59 } |
| |
60 |
| |
61 model->setActivationCallback(args.onactivate, args.onactivatedata); |
| |
62 model->setSelectionCallback(args.onselection, args.onselectiondata); |
| |
63 |
| |
64 QItemSelectionModel *s = view->selectionModel(); |
| |
65 QObject::connect( |
| |
66 s, |
| |
67 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
| |
68 model, |
| |
69 SLOT(selectionChanged(const QItemSelection &, const QItemSelection &))); |
| |
70 |
| |
71 |
| |
72 ctn->add(view, false); |
| |
73 |
| |
74 return view; |
| |
75 } |