ui/qt/tree.cpp

Sun, 11 Jan 2015 16:33:28 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 11 Jan 2015 16:33:28 +0100
changeset 71
3e021c5f18a0
parent 69
419c8c3209e8
child 72
a00b46d92c54
permissions
-rw-r--r--

added check item for menus (Qt)

/*
 * 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"

#include <QTreeView>
#include <QTreeWidgetItem>

UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) {
    QTreeView *view = new QTreeView();
    TableModel *model = new TableModel(obj, view, list, modelinfo);
    view->setModel(model);
    
    view->setItemsExpandable(false);
    view->setRootIsDecorated(false);   
    
    view->setSelectionMode(QAbstractItemView::ExtendedSelection);
    QItemSelectionModel *s = view->selectionModel();
    QObject::connect(
            s,
            SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
            model,
            SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)));
    QObject::connect(
            view,
            SIGNAL(doubleClicked(const QModelIndex &)),
            model,
            SLOT(activate(const QModelIndex &)));
    
    
    UiContainer *ct = uic_get_current_container(obj); 
    ct->add(view, true);
    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;
}

mercurial