ui/qt/model.cpp

changeset 577
c2e854820922
parent 516
4b31c74666d7
child 579
810b848e2e4f
--- a/ui/qt/model.cpp	Sat Apr 19 19:56:09 2025 +0200
+++ b/ui/qt/model.cpp	Sat Apr 19 20:02:23 2025 +0200
@@ -28,3 +28,35 @@
 
 #include "model.h"
 
+
+ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *userdata){
+    this->obj = obj;
+    this->view = view;
+    this->var = var;
+    this->getvalue = getvalue;
+    this->callback = f;
+    this->userdata = userdata;
+}
+
+int ListModel::rowCount(const QModelIndex& parent) const {
+    UiList *list = (UiList*)var->value;
+    return ui_list_count(list);
+}
+
+QVariant ListModel::data(const QModelIndex &index, int role) const {
+    if(role == Qt::DisplayRole) {
+        UiList *ls = (UiList*)var->value;
+        void *rowData = ls->get(ls, index.row());
+        if(rowData && getvalue) {
+            void *value = getvalue(rowData, 0);
+            return QString::fromUtf8((char*)value); 
+        }
+    }
+    return QVariant();
+}
+
+void ListModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
+    
+}
+
+

mercurial