ui/qt/list.cpp

changeset 958
749a8a36d74b
parent 802
cc73993a3ff9
child 969
7385c26d998d
--- a/ui/qt/list.cpp	Sun Dec 07 11:07:29 2025 +0100
+++ b/ui/qt/list.cpp	Sun Dec 07 11:27:44 2025 +0100
@@ -32,6 +32,7 @@
 #include <QTreeView>
 #include <QTreeWidgetItem>
 #include <QListView>
+#include <QComboBox>
 
 extern "C" void* ui_strmodel_getvalue(void *elm, int column) {
     return column == 0 ? elm : NULL;
@@ -46,7 +47,7 @@
     return NULL;
 }
 
-UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) {
+UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) {
     UiContainerPrivate *ctn = ui_obj_container(obj);
     
     QListView *view = new QListView();
@@ -92,7 +93,7 @@
     return view;
 }
 
-UIWIDGET ui_table_create(UiObject* obj, UiListArgs *args) {
+UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) {
     UiContainerPrivate *ctn = ui_obj_container(obj);
     
     QTreeView *view = new QTreeView();
@@ -141,3 +142,42 @@
     
     return view;
 }
+
+UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) {
+    UiContainerPrivate *ctn = ui_obj_container(obj);
+    
+    QComboBox *view = new QComboBox();
+    UiLayout layout = UI_ARGS2LAYOUT(args);
+    ctn->add(view, layout);
+    
+    ui_getvaluefunc2 getvalue = nullptr;
+    void *getvaluedata = nullptr;
+    if(args->getvalue2) {
+        getvalue = args->getvalue2;
+        getvaluedata = args->getvalue2data;
+    } else if(args->getvalue) {
+        getvalue = getvalue_wrapper;
+        getvaluedata = (void*)args->getvalue;
+    } else {
+        getvalue = getvalue_wrapper;
+        getvaluedata = (void*)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, getvaluedata);
+    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);
+    
+    return view;
+}

mercurial