ui/qt/list.cpp

changeset 634
14016ce0a434
parent 597
fc85ca42a7ce
child 637
6a2c744fe042
equal deleted inserted replaced
633:4c6ba81d319e 634:14016ce0a434
35 35
36 extern "C" void* ui_strmodel_getvalue(void *elm, int column) { 36 extern "C" void* ui_strmodel_getvalue(void *elm, int column) {
37 return column == 0 ? elm : NULL; 37 return column == 0 ? elm : NULL;
38 } 38 }
39 39
40 static void* getvalue_wrapper(UiList *list, void *elm, int row, int col, void *userdata) {
41 ui_getvaluefunc getvalue = (ui_getvaluefunc)userdata;
42 return getvalue(elm, col);
43 }
40 44
41 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) { 45 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) {
42 UiContainerPrivate *ctn = ui_obj_container(obj); 46 UiContainerPrivate *ctn = ui_obj_container(obj);
43 UI_APPLY_LAYOUT(ctn->layout, args); 47 UI_APPLY_LAYOUT(ctn->layout, args);
44 48
45 QListView *view = new QListView(); 49 QListView *view = new QListView();
50 ui_getvaluefunc2 getvalue = nullptr;
51 void *getvaluedata = nullptr;
52 if(args->getvalue2) {
53 getvalue = args->getvalue2;
54 getvaluedata = args->getvalue2data;
55 } else if(args->getvalue) {
56 getvalue = getvalue_wrapper;
57 getvaluedata = (void*)args->getvalue;
58 } else {
59 getvalue = getvalue_wrapper;
60 getvaluedata = (void*)ui_strmodel_getvalue;
61 }
46 62
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); 63 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST);
49 64
50 ListModel *model = new ListModel(obj, view, var, getvalue); 65 ListModel *model = new ListModel(obj, view, var, getvalue, getvaluedata);
51 view->setModel(model); 66 view->setModel(model);
52 67
53 if(var) { 68 if(var) {
54 UiList *list = (UiList*)var->value; 69 UiList *list = (UiList*)var->value;
55 list->update = ui_listmodel_update; 70 list->update = ui_listmodel_update;

mercurial