From efcbdb7a0347b4399cbabacf3cbea432eeafb17b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 17 May 2011 01:24:51 +0000 Subject: Gats::Object now has a strToGats function, it's pretty slick, it takes a string and produces a fully formed gats tree. Also, gatscon now can interact with a server directly. --- src/gatscon/gatstotree.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'src/gatscon/gatstotree.cpp') diff --git a/src/gatscon/gatstotree.cpp b/src/gatscon/gatstotree.cpp index af94fa5..d01e4b8 100644 --- a/src/gatscon/gatstotree.cpp +++ b/src/gatscon/gatstotree.cpp @@ -1,8 +1,83 @@ +#include "gatstotree.h" + #include #include void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) { + switch( pObj->getType() ) + { + case Gats::typeInteger: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeString: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeFloat: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeBoolean: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeList: + gatsToTree( p, dynamic_cast( pObj ) ); + break; + + case Gats::typeDictionary: + gatsToTree( p, dynamic_cast( 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 ); + } } -- cgit v1.2.3