From 3cbd1038e20dcb2b25db4e74666ec21766642729 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Apr 2022 23:45:42 -0700 Subject: toString works. It does indent automatically. I figure, you know, if you're converting to a string then a big part of the reason is so you can read it. In that case, why make it optional? --- c++-qt/src/list.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'c++-qt/src/list.cpp') diff --git a/c++-qt/src/list.cpp b/c++-qt/src/list.cpp index fae51d1..cca7c46 100644 --- a/c++-qt/src/list.cpp +++ b/c++-qt/src/list.cpp @@ -48,7 +48,7 @@ void Gats::List::write( QIODevice &rOut ) const rOut.write("e", 1 ); } -void Gats::List::read( QIODevice &rIn, char cType ) +void Gats::List::read( QIODevice &rIn, char /*cType*/ ) { for(;;) { @@ -59,6 +59,32 @@ void Gats::List::read( QIODevice &rIn, char cType ) } } +QString Gats::List::toString( int iIndent ) const +{ + if( count() == 0 ) + return "[ ]"; + QString sRet("["); + iIndent++; + for( const_iterator i = begin(); i != end(); i++ ) + { + if( i != begin() ) + { + sRet += ",\n"; + } + else + { + sRet += "\n"; + } + for( int j = 0; j < iIndent; j++ ) sRet += " "; + sRet += (*i)->toString( iIndent ); + } + sRet += "\n"; + iIndent--; + for( int j = 0; j < iIndent; j++ ) sRet += " "; + sRet += ']'; + return sRet; +} + void Gats::List::append( const char *s ) { QList::append( new Gats::String( s ) ); -- cgit v1.2.3