29 #include "tree.h" |
29 #include "tree.h" |
30 #include "container.h" |
30 #include "container.h" |
31 |
31 |
32 #include <QTreeView> |
32 #include <QTreeView> |
33 #include <QTreeWidgetItem> |
33 #include <QTreeWidgetItem> |
|
34 #include <QListView> |
|
35 |
|
36 |
|
37 extern "C" void* ui_strmodel_getvalue(void *elm, int column) { |
|
38 return column == 0 ? elm : NULL; |
|
39 } |
|
40 |
|
41 UIWIDGET ui_listview_str(UiObject *obj, UiList *list, ui_callback f, void *udata) { |
|
42 return ui_listview(obj, list, ui_strmodel_getvalue, f, udata); |
|
43 } |
|
44 UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { |
|
45 QListView *view = new QListView(); |
|
46 ListModel *model = new ListModel(obj, view, list, getvalue, f, udata); |
|
47 view->setModel(model); |
|
48 |
|
49 QItemSelectionModel *s = view->selectionModel(); |
|
50 QObject::connect( |
|
51 s, |
|
52 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
|
53 model, |
|
54 SLOT(selectionChanged(const QItemSelection &, const QItemSelection &))); |
|
55 |
|
56 UiContainer *ct = uic_get_current_container(obj); |
|
57 ct->add(view, true); |
|
58 return view; |
|
59 } |
|
60 |
|
61 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { |
|
62 UiListPtr *listptr = (UiListPtr*)ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); |
|
63 listptr->list = list; |
|
64 return ui_listview_var(obj, listptr, getvalue, f, udata); |
|
65 } |
|
66 |
|
67 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { |
|
68 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST); |
|
69 if(var) { |
|
70 UiListVar *value = (UiListVar*)var->value; |
|
71 return ui_listview_var(obj, value->listptr, getvalue, f, udata); |
|
72 } else { |
|
73 // TODO: error |
|
74 } |
|
75 return NULL; |
|
76 } |
|
77 |
34 |
78 |
35 UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) { |
79 UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) { |
36 QTreeView *view = new QTreeView(); |
80 QTreeView *view = new QTreeView(); |
37 TableModel *model = new TableModel(obj, view, list, modelinfo); |
81 TableModel *model = new TableModel(obj, view, list, modelinfo); |
38 view->setModel(model); |
82 view->setModel(model); |