aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/gatscon/gatstotree.cpp
blob: 9c6fb5c083be46442ec46e378603fe0134c36514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (C) 2007-2013 Xagasoft, All rights reserved.
 *
 * This file is part of the libgats library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "gatstotree.h"

#include <gats/types.h>

#include <QTreeWidgetItem>

void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj )
{
    switch( pObj->getType() )
    {
        case Gats::typeInteger:
            gatsToTree( p, dynamic_cast<Gats::Integer *>( pObj ) );
            break;

        case Gats::typeString:
            gatsToTree( p, dynamic_cast<Gats::String *>( pObj ) );
            break;

        case Gats::typeFloat:
            gatsToTree( p, dynamic_cast<Gats::Float *>( pObj ) );
            break;

        case Gats::typeBoolean:
            gatsToTree( p, dynamic_cast<Gats::Boolean *>( pObj ) );
            break;

        case Gats::typeList:
            gatsToTree( p, dynamic_cast<Gats::List *>( pObj ) );
            break;

        case Gats::typeDictionary:
            gatsToTree( p, dynamic_cast<Gats::Dictionary *>( pObj ) );
            break;

        case Gats::typeNull:
            gatsToTree( p, dynamic_cast<Gats::Null *>( pObj ) );
            break;
    }
}

void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj )
{
    p->setText( 1, "int");
    p->setText( 2, QString("%1").arg( pObj->getValue() ) );
}

void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj )
{
    p->setText( 1, "str");
    p->setText( 2, QString("%1").arg( pObj->getStr() ) );
}

void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj )
{
    p->setText( 1, "float");
    p->setText( 2, QString("%1").arg( pObj->getValue() ) );
}

void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj )
{
    p->setText( 1, "bool");
    p->setText( 2, pObj->getValue()?"true":"false" );
}

void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj )
{
    p->setText( 1, "list");
    int j = 0;
    for( Gats::List::iterator i = pObj->begin(); i; i++ )
    {
        QTreeWidgetItem *pIt = new QTreeWidgetItem( p );
        pIt->setText( 0, QString("%1").arg( j++ ) );
        gatsToTree( pIt, *i );
    }
}

void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj )
{
    p->setText( 1, "dict");
    for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ )
    {
        QTreeWidgetItem *pIt = new QTreeWidgetItem( p );
        pIt->setText( 0, QString( i.getKey().getStr() ) );
        gatsToTree( pIt, *i );
    }
}

void gatsToTree( QTreeWidgetItem *p, Gats::Null *pObj )
{
    p->setText( 1, "null");
}