--- a/ui/qt/list.cpp Sun Apr 20 10:56:50 2025 +0200 +++ b/ui/qt/list.cpp Mon Apr 21 11:03:17 2025 +0200 @@ -33,4 +33,43 @@ #include <QTreeWidgetItem> #include <QListView> +extern "C" void* ui_strmodel_getvalue(void *elm, int column) { + return column == 0 ? elm : NULL; +} + +UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { + UiContainerPrivate *ctn = ui_obj_container(obj); + UI_APPLY_LAYOUT(ctn->layout, args); + + QListView *view = new QListView(); + + ui_getvaluefunc getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; + UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.list, args.varname, UI_VAR_LIST); + + ListModel *model = new ListModel(obj, view, var, getvalue); + view->setModel(model); + + if(var) { + UiList *list = (UiList*)var->value; + list->update = ui_listmodel_update; + list->getselection = ui_listmodel_getselection; + list->setselection = ui_listmodel_setselection; + list->obj = model; + } + + model->setActivationCallback(args.onactivate, args.onactivatedata); + model->setSelectionCallback(args.onselection, args.onselectiondata); + + QItemSelectionModel *s = view->selectionModel(); + QObject::connect( + s, + SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), + model, + SLOT(selectionChanged(const QItemSelection &, const QItemSelection &))); + + + ctn->add(view, false); + + return view; +}