# HG changeset patch # User Olaf Wintermann # Date 1409431726 -7200 # Node ID 2b124f8ebd956ca87e31efc251e9a36221dbc199 # Parent ddfd6b90cc54e6978546cbe821549e6d486b0317 added table view (Qt) diff -r ddfd6b90cc54 -r 2b124f8ebd95 application/main.c --- a/application/main.c Thu Aug 28 19:25:21 2014 +0200 +++ b/application/main.c Sat Aug 30 22:48:46 2014 +0200 @@ -102,9 +102,9 @@ printf("create window\n"); UiObject *window = ui_window("Mod0", NULL); - ui_textarea(window, &text); + //ui_textarea(window, &text); - /* + ///* UiModelInfo *model = ui_model_info(window->ctx, UI_STRING, "Name", UI_STRING, "Email", -1); model->getvalue = (ui_model_getvalue_f)person_getvalue; model->activate = action_activate; @@ -128,9 +128,10 @@ ui_list_append(list, p4); //ui_sidebar(window); - //ui_table(window, list, model); + ui_table(window, list, model); //ui_end(window); + /* UiTabbedPane *view = ui_tabbed_document_view(window); UiObject *tab1 = ui_document_tab(view); diff -r ddfd6b90cc54 -r 2b124f8ebd95 ui/qt/model.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/model.cpp Sat Aug 30 22:48:46 2014 +0200 @@ -0,0 +1,64 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "model.h" + +TableModel::TableModel(UiListPtr *list, UiModelInfo *info) { + this->list = list; + this->info = info; +} + +int TableModel::rowCount(const QModelIndex &parent) const { + return list->list->count(list->list); +} + +int TableModel::columnCount(const QModelIndex &parent) const { + return info->columns; +} + +QVariant TableModel::data(const QModelIndex &index, int role) const { + if(role == Qt::DisplayRole) { + UiList *ls = list->list; + void *rowData = ls->get(ls, index.row()); + if(rowData && info->getvalue) { + void *value = info->getvalue(rowData, index.column()); + switch(info->types[index.column()]) { + case UI_STRING: { + return QString::fromUtf8((char*)value); + } + case UI_INTEGER: { + int *intptr = (int*)value; + return QVariant(*intptr); + } + } + } + } + return QVariant(); +} + + diff -r ddfd6b90cc54 -r 2b124f8ebd95 ui/qt/model.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/model.h Sat Aug 30 22:48:46 2014 +0200 @@ -0,0 +1,51 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef MODEL_H +#define MODEL_H + +#include "toolkit.h" +#include "../ui/tree.h" +#include "../common/context.h" +#include + +class TableModel : public QAbstractTableModel { + Q_OBJECT + + UiListPtr *list; + UiModelInfo *info; +public: + TableModel(UiListPtr *list, UiModelInfo *info); + + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; +}; + +#endif /* MODEL_H */ + diff -r ddfd6b90cc54 -r 2b124f8ebd95 ui/qt/qt4.pro --- a/ui/qt/qt4.pro Thu Aug 28 19:25:21 2014 +0200 +++ b/ui/qt/qt4.pro Sat Aug 30 22:48:46 2014 +0200 @@ -42,6 +42,8 @@ SOURCES += stock.cpp SOURCES += container.cpp SOURCES += text.cpp +SOURCES += model.cpp +SOURCES += tree.cpp HEADERS += toolkit.h HEADERS += window.h @@ -50,4 +52,6 @@ HEADERS += stock.h HEADERS += container.h HEADERS += text.h +HEADERS += model.h +HEADESR += tree.h diff -r ddfd6b90cc54 -r 2b124f8ebd95 ui/qt/tree.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/tree.cpp Sat Aug 30 22:48:46 2014 +0200 @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tree.h" +#include "container.h" + +UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) { + QTableView *view = new QTableView(); + TableModel *model = new TableModel(list, modelinfo); + view->setModel(model); + + UiContainer *ct = uic_get_current_container(obj); + ct->add(view); + return view; +} + +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; +} + diff -r ddfd6b90cc54 -r 2b124f8ebd95 ui/qt/tree.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/tree.h Sat Aug 30 22:48:46 2014 +0200 @@ -0,0 +1,40 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TREE_H +#define TREE_H + +#include "../ui/tree.h" +#include "model.h" + +#include + + + +#endif /* TREE_H */ + diff -r ddfd6b90cc54 -r 2b124f8ebd95 ui/ui/tree.h --- a/ui/ui/tree.h Thu Aug 28 19:25:21 2014 +0200 +++ b/ui/ui/tree.h Sat Aug 30 22:48:46 2014 +0200 @@ -38,12 +38,11 @@ typedef struct UiModelInfo UiModelInfo; typedef struct UiListSelection UiListSelection; -typedef enum UiModelType UiModelType; -enum UiModelType { +typedef enum UiModelType { UI_STRING = 0, UI_INTEGER -}; +} UiModelType; struct UiModelInfo { /*