ui/qt/model.cpp

changeset 634
14016ce0a434
parent 585
e71867b33bfd
child 637
6a2c744fe042
--- a/ui/qt/model.cpp	Wed Jun 25 21:59:36 2025 +0200
+++ b/ui/qt/model.cpp	Wed Jun 25 22:14:25 2025 +0200
@@ -28,12 +28,21 @@
 
 #include "model.h"
 
+static void* model_getvalue(UiModel *model, UiList *list, void *elm, int row, int col) {
+    if(model->getvalue2) {
+        return model->getvalue2(list, elm, row, col, model->getvalue2data);
+    } else if(model->getvalue) {
+        return model->getvalue(elm, col);
+    }
+    return NULL;
+}
 
-ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc getvalue){
+ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc2 getvalue, void *getvaluedata){
     this->obj = obj;
     this->view = view;
     this->var = var;
     this->getvalue = getvalue;
+    this->getvaluedata = getvaluedata;
     this->onactivate = nullptr;
     this->onactivatedata = nullptr;
     this->onselection = nullptr;
@@ -69,7 +78,7 @@
         UiList *ls = (UiList*)var->value;
         void *rowData = ls->get(ls, index.row());
         if(rowData && getvalue) {
-            void *value = getvalue(rowData, 0);
+            void *value = getvalue(ls, rowData, index.row(), 0, getvaluedata);
             if(value) {
                 return QString::fromUtf8((char*)value); 
             }
@@ -144,9 +153,9 @@
     if(role == Qt::DisplayRole) {
         UiList *ls = (UiList*)var->value;
         void *rowData = ls->get(ls, index.row());
-        if(rowData && model->getvalue) {
+        if(rowData) {
             int col = index.column();
-            void *value = model->getvalue(rowData, col);
+            void *value = model_getvalue(model, ls, rowData, index.row(), col);
             if(value) {
                 UiModelType type = model->types[col];
                 switch(type) {

mercurial