ui/qt/tree.cpp

changeset 72
a00b46d92c54
parent 69
419c8c3209e8
child 130
212b63dd61be
--- a/ui/qt/tree.cpp	Sun Jan 11 16:33:28 2015 +0100
+++ b/ui/qt/tree.cpp	Mon Jan 12 12:03:05 2015 +0100
@@ -31,6 +31,50 @@
 
 #include <QTreeView>
 #include <QTreeWidgetItem>
+#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);
+    
+    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();

mercurial