ui/qt/list.cpp

changeset 597
fc85ca42a7ce
parent 587
61813a91c84d
child 634
14016ce0a434
equal deleted inserted replaced
596:34866811080d 597:fc85ca42a7ce
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 40
41 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { 41 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) {
42 UiContainerPrivate *ctn = ui_obj_container(obj); 42 UiContainerPrivate *ctn = ui_obj_container(obj);
43 UI_APPLY_LAYOUT(ctn->layout, args); 43 UI_APPLY_LAYOUT(ctn->layout, args);
44 44
45 QListView *view = new QListView(); 45 QListView *view = new QListView();
46 46
47 ui_getvaluefunc getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; 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); 48 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST);
49 49
50 ListModel *model = new ListModel(obj, view, var, getvalue); 50 ListModel *model = new ListModel(obj, view, var, getvalue);
51 view->setModel(model); 51 view->setModel(model);
52 52
53 if(var) { 53 if(var) {
56 list->getselection = ui_listmodel_getselection; 56 list->getselection = ui_listmodel_getselection;
57 list->setselection = ui_listmodel_setselection; 57 list->setselection = ui_listmodel_setselection;
58 list->obj = model; 58 list->obj = model;
59 } 59 }
60 60
61 model->setActivationCallback(args.onactivate, args.onactivatedata); 61 model->setActivationCallback(args->onactivate, args->onactivatedata);
62 model->setSelectionCallback(args.onselection, args.onselectiondata); 62 model->setSelectionCallback(args->onselection, args->onselectiondata);
63 63
64 QItemSelectionModel *s = view->selectionModel(); 64 QItemSelectionModel *s = view->selectionModel();
65 QObject::connect( 65 QObject::connect(
66 s, 66 s,
67 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), 67 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
72 ctn->add(view, false); 72 ctn->add(view, false);
73 73
74 return view; 74 return view;
75 } 75 }
76 76
77 UIWIDGET ui_table_create(UiObject* obj, UiListArgs args) { 77 UIWIDGET ui_table_create(UiObject* obj, UiListArgs *args) {
78 UiContainerPrivate *ctn = ui_obj_container(obj); 78 UiContainerPrivate *ctn = ui_obj_container(obj);
79 UI_APPLY_LAYOUT(ctn->layout, args); 79 UI_APPLY_LAYOUT(ctn->layout, args);
80 80
81 QTreeView *view = new QTreeView(); 81 QTreeView *view = new QTreeView();
82 view->setItemsExpandable(false); 82 view->setItemsExpandable(false);
83 view->setRootIsDecorated(false); 83 view->setRootIsDecorated(false);
84 if(args.multiselection) { 84 if(args->multiselection) {
85 view->setSelectionMode(QAbstractItemView::ExtendedSelection); 85 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
86 } 86 }
87 87
88 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.list, args.varname, UI_VAR_LIST); 88 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST);
89 89
90 TableModel *model = new TableModel(obj, view, var, args.model); 90 TableModel *model = new TableModel(obj, view, var, args->model);
91 view->setModel(model); 91 view->setModel(model);
92 92
93 if(var) { 93 if(var) {
94 UiList *list = (UiList*)var->value; 94 UiList *list = (UiList*)var->value;
95 list->update = ui_listmodel_update; 95 list->update = ui_listmodel_update;
96 list->getselection = ui_listmodel_getselection; 96 list->getselection = ui_listmodel_getselection;
97 list->setselection = ui_listmodel_setselection; 97 list->setselection = ui_listmodel_setselection;
98 list->obj = model; 98 list->obj = model;
99 } 99 }
100 100
101 model->setActivationCallback(args.onactivate, args.onactivatedata); 101 model->setActivationCallback(args->onactivate, args->onactivatedata);
102 model->setSelectionCallback(args.onselection, args.onselectiondata); 102 model->setSelectionCallback(args->onselection, args->onselectiondata);
103 103
104 QItemSelectionModel *s = view->selectionModel(); 104 QItemSelectionModel *s = view->selectionModel();
105 QObject::connect( 105 QObject::connect(
106 s, 106 s,
107 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), 107 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),

mercurial