ui/qt/list.cpp

changeset 958
749a8a36d74b
parent 802
cc73993a3ff9
child 969
7385c26d998d
equal deleted inserted replaced
957:774ee4d7bb1f 958:749a8a36d74b
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> 34 #include <QListView>
35 #include <QComboBox>
35 36
36 extern "C" void* ui_strmodel_getvalue(void *elm, int column) { 37 extern "C" void* ui_strmodel_getvalue(void *elm, int column) {
37 return column == 0 ? elm : NULL; 38 return column == 0 ? elm : NULL;
38 } 39 }
39 40
44 45
45 static void* null_getvalue(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) { 46 static void* null_getvalue(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) {
46 return NULL; 47 return NULL;
47 } 48 }
48 49
49 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) { 50 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) {
50 UiContainerPrivate *ctn = ui_obj_container(obj); 51 UiContainerPrivate *ctn = ui_obj_container(obj);
51 52
52 QListView *view = new QListView(); 53 QListView *view = new QListView();
53 ui_getvaluefunc2 getvalue = nullptr; 54 ui_getvaluefunc2 getvalue = nullptr;
54 void *getvaluedata = nullptr; 55 void *getvaluedata = nullptr;
90 ctn->add(view, layout); 91 ctn->add(view, layout);
91 92
92 return view; 93 return view;
93 } 94 }
94 95
95 UIWIDGET ui_table_create(UiObject* obj, UiListArgs *args) { 96 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) {
96 UiContainerPrivate *ctn = ui_obj_container(obj); 97 UiContainerPrivate *ctn = ui_obj_container(obj);
97 98
98 QTreeView *view = new QTreeView(); 99 QTreeView *view = new QTreeView();
99 view->setItemsExpandable(false); 100 view->setItemsExpandable(false);
100 view->setRootIsDecorated(false); 101 view->setRootIsDecorated(false);
139 UiLayout layout = UI_ARGS2LAYOUT(args); 140 UiLayout layout = UI_ARGS2LAYOUT(args);
140 ctn->add(view, layout); 141 ctn->add(view, layout);
141 142
142 return view; 143 return view;
143 } 144 }
145
146 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) {
147 UiContainerPrivate *ctn = ui_obj_container(obj);
148
149 QComboBox *view = new QComboBox();
150 UiLayout layout = UI_ARGS2LAYOUT(args);
151 ctn->add(view, layout);
152
153 ui_getvaluefunc2 getvalue = nullptr;
154 void *getvaluedata = nullptr;
155 if(args->getvalue2) {
156 getvalue = args->getvalue2;
157 getvaluedata = args->getvalue2data;
158 } else if(args->getvalue) {
159 getvalue = getvalue_wrapper;
160 getvaluedata = (void*)args->getvalue;
161 } else {
162 getvalue = getvalue_wrapper;
163 getvaluedata = (void*)ui_strmodel_getvalue;
164 }
165
166 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST);
167
168 ListModel *model = new ListModel(obj, view, var, getvalue, getvaluedata);
169 view->setModel(model);
170
171 if(var) {
172 UiList *list = (UiList*)var->value;
173 list->update = ui_listmodel_update;
174 list->getselection = ui_listmodel_getselection;
175 list->setselection = ui_listmodel_setselection;
176 list->obj = model;
177 }
178
179 model->setActivationCallback(args->onactivate, args->onactivatedata);
180 model->setSelectionCallback(args->onselection, args->onselectiondata);
181
182 return view;
183 }

mercurial