ui/qt/tree.cpp

changeset 516
4b31c74666d7
parent 130
212b63dd61be
equal deleted inserted replaced
515:9e18cb8c4412 516:4b31c74666d7
32 #include <QTreeView> 32 #include <QTreeView>
33 #include <QTreeWidgetItem> 33 #include <QTreeWidgetItem>
34 #include <QListView> 34 #include <QListView>
35 35
36 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 // TODO: observer update
50
51 QItemSelectionModel *s = view->selectionModel();
52 QObject::connect(
53 s,
54 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
55 model,
56 SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)));
57
58 UiContainer *ct = uic_get_current_container(obj);
59 ct->add(view, true);
60 return view;
61 }
62
63 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
64 UiListPtr *listptr = (UiListPtr*)ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
65 listptr->list = list;
66 return ui_listview_var(obj, listptr, getvalue, f, udata);
67 }
68
69 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
70 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
71 if(var) {
72 UiListVar *value = (UiListVar*)var->value;
73 return ui_listview_var(obj, value->listptr, getvalue, f, udata);
74 } else {
75 // TODO: error
76 }
77 return NULL;
78 }
79
80
81 UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) {
82 QTreeView *view = new QTreeView();
83 TableModel *model = new TableModel(obj, view, list, modelinfo);
84 view->setModel(model);
85
86 view->setItemsExpandable(false);
87 view->setRootIsDecorated(false);
88
89 // TODO: observer update
90 UiTableView *u = new UiTableView();
91 u->widget = view;
92 u->model = model;
93 list->list->observers = ui_add_observer(
94 list->list->observers,
95 (ui_callback)ui_table_update,
96 u);
97
98 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
99 QItemSelectionModel *s = view->selectionModel();
100 QObject::connect(
101 s,
102 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
103 model,
104 SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)));
105 QObject::connect(
106 view,
107 SIGNAL(doubleClicked(const QModelIndex &)),
108 model,
109 SLOT(activate(const QModelIndex &)));
110
111
112 UiContainer *ct = uic_get_current_container(obj);
113 ct->add(view, true);
114 return view;
115 }
116
117 void ui_table_update(UiEvent *event, UiTableView *view) {
118 // TODO
119 printf("update\n");
120
121 //view->model->update();
122 view->widget->setModel(NULL);
123 view->widget->setModel(view->model);
124 }
125
126 UIWIDGET ui_table(UiObject *obj, UiList *list, UiModelInfo *modelinfo) {
127 UiListPtr *listptr = (UiListPtr*)ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
128 listptr->list = list;
129 return ui_table_var(obj, listptr, modelinfo);
130 }
131
132 UIWIDGET ui_table_nv(UiObject *obj, char *varname, UiModelInfo *modelinfo) {
133 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
134 if(var) {
135 UiListVar *value = (UiListVar*)var->value;
136 return ui_table_var(obj, value->listptr, modelinfo);
137 } else {
138 // TODO: error
139 }
140 return NULL;
141 }
142

mercurial