static void indent(QTextBlock block, const QStringList &previousCode) { int indent = indentForBottomLine(previousCode, QChar::Null); indentLine(block, indent); }
QString CppToQsConverter::convertedCode( Tree *qsTree, const QString& code, const QSet<QString>& classesWithNoQ ) { QString result; QStringList program; QStringList comments; int programWidth = 0; QStringList originalLines = code.split("\n"); QStringList::ConstIterator ol = originalLines.begin(); while ( ol != originalLines.end() ) { QString code = (*ol).trimmed(); QString comment; int slashSlash = code.indexOf( "//" ); if ( slashSlash != -1 ) { comment = code.mid( slashSlash ); code.truncate( slashSlash ); code = code.trimmed(); } code = convertCodeLine( qsTree, program, code, classesWithNoQ ); program.append( code ); comment = convertComment( qsTree, comment, classesWithNoQ ); comments.append( comment ); int n = indentForBottomLine( program, QChar::Null ); for ( int i = 0; i < n; i++ ) program.last().prepend( " " ); int width = columnForIndex( program.last(), program.last().length() ); if ( !comment.isEmpty() && width > programWidth ) programWidth = width; ++ol; } programWidth = ( (programWidth + (tabSize - 1) + 2) / tabSize ) * tabSize; QStringList::ConstIterator p = program.begin(); QStringList::ConstIterator c = comments.begin(); while ( c != comments.end() ) { if ( c != comments.begin() ) result += "\n"; if ( (*p).trimmed().isEmpty() ) { if ( !(*c).isEmpty() ) result += *p; } else { result += *p; if ( !(*c).isEmpty() ) { int i = columnForIndex( *p, (*p).length() ); while ( i++ < programWidth ) result += " "; } } result += *c; ++p; ++c; } return result; }