--- a/ui/qt/tree.cpp Wed Mar 26 20:27:20 2025 +0100 +++ b/ui/qt/tree.cpp Wed Mar 26 20:39:04 2025 +0100 @@ -34,109 +34,3 @@ #include <QListView> -extern "C" void* ui_strmodel_getvalue(void *elm, int column) { - return column == 0 ? elm : NULL; -} - -UIWIDGET ui_listview_str(UiObject *obj, UiList *list, ui_callback f, void *udata) { - return ui_listview(obj, list, ui_strmodel_getvalue, f, udata); -} -UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { - QListView *view = new QListView(); - ListModel *model = new ListModel(obj, view, list, getvalue, f, udata); - view->setModel(model); - - // TODO: observer update - - QItemSelectionModel *s = view->selectionModel(); - QObject::connect( - s, - SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - model, - SLOT(selectionChanged(const QItemSelection &, const QItemSelection &))); - - UiContainer *ct = uic_get_current_container(obj); - ct->add(view, true); - return view; -} - -UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { - UiListPtr *listptr = (UiListPtr*)ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); - listptr->list = list; - return ui_listview_var(obj, listptr, getvalue, f, udata); -} - -UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { - UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST); - if(var) { - UiListVar *value = (UiListVar*)var->value; - return ui_listview_var(obj, value->listptr, getvalue, f, udata); - } else { - // TODO: error - } - return NULL; -} - - -UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) { - QTreeView *view = new QTreeView(); - TableModel *model = new TableModel(obj, view, list, modelinfo); - view->setModel(model); - - view->setItemsExpandable(false); - view->setRootIsDecorated(false); - - // TODO: observer update - UiTableView *u = new UiTableView(); - u->widget = view; - u->model = model; - list->list->observers = ui_add_observer( - list->list->observers, - (ui_callback)ui_table_update, - u); - - view->setSelectionMode(QAbstractItemView::ExtendedSelection); - QItemSelectionModel *s = view->selectionModel(); - QObject::connect( - s, - SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - model, - SLOT(selectionChanged(const QItemSelection &, const QItemSelection &))); - QObject::connect( - view, - SIGNAL(doubleClicked(const QModelIndex &)), - model, - SLOT(activate(const QModelIndex &))); - - - UiContainer *ct = uic_get_current_container(obj); - ct->add(view, true); - return view; -} - -void ui_table_update(UiEvent *event, UiTableView *view) { - // TODO - printf("update\n"); - - //view->model->update(); - view->widget->setModel(NULL); - view->widget->setModel(view->model); -} - -UIWIDGET ui_table(UiObject *obj, UiList *list, UiModelInfo *modelinfo) { - UiListPtr *listptr = (UiListPtr*)ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); - listptr->list = list; - return ui_table_var(obj, listptr, modelinfo); -} - -UIWIDGET ui_table_nv(UiObject *obj, char *varname, UiModelInfo *modelinfo) { - UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST); - if(var) { - UiListVar *value = (UiListVar*)var->value; - return ui_table_var(obj, value->listptr, modelinfo); - } else { - // TODO: error - } - return NULL; -} -