diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-05-17 14:56:28 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-05-17 14:56:28 +0000 |
commit | 6d8bc516acf7a5995736423e838c987d08e69c09 (patch) | |
tree | 9db78ee528b26e0d5718b2ac4c987388e1b9c313 /src/gatscon/treetogats.cpp | |
parent | d269a39f27e2dcd57d0e3362ef3a7fd9ad3f3639 (diff) | |
download | libgats-6d8bc516acf7a5995736423e838c987d08e69c09.tar.gz libgats-6d8bc516acf7a5995736423e838c987d08e69c09.tar.bz2 libgats-6d8bc516acf7a5995736423e838c987d08e69c09.tar.xz libgats-6d8bc516acf7a5995736423e838c987d08e69c09.zip |
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.
Diffstat (limited to 'src/gatscon/treetogats.cpp')
-rw-r--r-- | src/gatscon/treetogats.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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 @@ | |||
1 | #include "treetogats.h" | ||
2 | |||
3 | #include <QTreeWidgetItem> | ||
4 | |||
5 | #include <gats/types.h> | ||
6 | |||
7 | Gats::Object *treeToGats( QTreeWidgetItem *pRoot ) | ||
8 | { | ||
9 | QString sType = pRoot->text( 1 ); | ||
10 | QByteArray baDat = pRoot->text( 2 ).toAscii(); | ||
11 | if( sType == "int" ) | ||
12 | { | ||
13 | return new Gats::Integer( strtoll( baDat.constData(), NULL, 10 ) ); | ||
14 | } | ||
15 | else if( sType == "str" ) | ||
16 | { | ||
17 | return new Gats::String( baDat.constData(), baDat.size() ); | ||
18 | } | ||
19 | else if( sType == "float" ) | ||
20 | { | ||
21 | return new Gats::Float( strtod( baDat.constData(), NULL ) ); | ||
22 | } | ||
23 | else if( sType == "bool" ) | ||
24 | { | ||
25 | return new Gats::Boolean( baDat == "true" ); | ||
26 | } | ||
27 | else if( sType == "list" ) | ||
28 | { | ||
29 | Gats::List *pRet = new Gats::List(); | ||
30 | for( int j = 0; j < pRoot->childCount(); j++ ) | ||
31 | { | ||
32 | pRet->append( treeToGats( pRoot->child( j ) ) ); | ||
33 | } | ||
34 | return pRet; | ||
35 | } | ||
36 | else if( sType == "dict" ) | ||
37 | { | ||
38 | Gats::Dictionary *pRet = new Gats::Dictionary(); | ||
39 | for( int j = 0; j < pRoot->childCount(); j++ ) | ||
40 | { | ||
41 | QTreeWidgetItem *pChild = pRoot->child( j ); | ||
42 | pRet->insert( | ||
43 | pChild->text( 0 ).toAscii().constData(), | ||
44 | treeToGats( pChild ) | ||
45 | ); | ||
46 | } | ||
47 | return pRet; | ||
48 | } | ||
49 | |||
50 | throw Bu::ExceptionBase("Unhandled type found."); | ||
51 | } | ||
52 | |||