From 6d8bc516acf7a5995736423e838c987d08e69c09 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 17 May 2011 14:56:28 +0000 Subject: Ok, you can now open files, save files, save files from proxies and clients, and add new root items to files. Later I'll add some actual editing capabilities, should be really easy. --- src/gatscon/treetogats.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/gatscon/treetogats.cpp (limited to 'src/gatscon/treetogats.cpp') diff --git a/src/gatscon/treetogats.cpp b/src/gatscon/treetogats.cpp new file mode 100644 index 0000000..a1571d1 --- /dev/null +++ b/src/gatscon/treetogats.cpp @@ -0,0 +1,52 @@ +#include "treetogats.h" + +#include + +#include + +Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) +{ + QString sType = pRoot->text( 1 ); + QByteArray baDat = pRoot->text( 2 ).toAscii(); + if( sType == "int" ) + { + return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); + } + else if( sType == "str" ) + { + return new Gats::String( baDat.constData(), baDat.size() ); + } + else if( sType == "float" ) + { + return new Gats::Float( strtod( baDat.constData(), NULL ) ); + } + else if( sType == "bool" ) + { + return new Gats::Boolean( baDat == "true" ); + } + else if( sType == "list" ) + { + Gats::List *pRet = new Gats::List(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + pRet->append( treeToGats( pRoot->child( j ) ) ); + } + return pRet; + } + else if( sType == "dict" ) + { + Gats::Dictionary *pRet = new Gats::Dictionary(); + for( int j = 0; j < pRoot->childCount(); j++ ) + { + QTreeWidgetItem *pChild = pRoot->child( j ); + pRet->insert( + pChild->text( 0 ).toAscii().constData(), + treeToGats( pChild ) + ); + } + return pRet; + } + + throw Bu::ExceptionBase("Unhandled type found."); +} + -- cgit v1.2.3