/*************************************************************************** kvtmlwriter.cpp - description ------------------- copyright : (C) 2004 by Peter Hedlund email : peter.hedlund@kdemail.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "kvtmlwriter.h" KVTMLWriter::KVTMLWriter(QFile *file) { outputFile = file; if(outputFile->open(IO_WriteOnly)) { outputStream.setDevice(outputFile); outputStream.setEncoding(QTextStream::UnicodeUTF8); outputStream << "" << endl; outputStream << "" << endl; } } /*! \fn KVTMLWriter::addHeader(const QString &generator, int cols, int rows, const QString &title) */ void KVTMLWriter::addHeader(const QString &generator, int cols, int rows, const QString &title) { QString s = QString("") .arg(generator) .arg(cols) .arg(rows) .arg(title); outputStream << s << endl << endl; } /*! \fn KVTMLWriter::addFirstItem(const QString &ll, int lwidth, const QString &left, const QString &rl, int rwidth, const QString &right) */ void KVTMLWriter::addFirstItem(const QString &ll, int lwidth, const QString &left, const QString &rl, int rwidth, const QString &right) { outputStream << " " << endl; QString s = QString(" ") .arg(lwidth) .arg(ll); outputStream << s << escape(left) << "" << endl; s = QString(" ") .arg(rwidth) .arg(rl); outputStream << s << escape(right) << "" << endl; outputStream << " " << endl; } /*! \fn KVTMLWriter::addItem(const QString &left, const QString &right) */ void KVTMLWriter::addItem(const QString &left, const QString &right) { outputStream << " " << endl; outputStream << " " << escape(left) << "" << endl; outputStream << " " << escape(right) << "" << endl; outputStream << " " << endl; } KVTMLWriter::~KVTMLWriter() { outputStream << "" << endl; outputFile->close(); } QString KVTMLWriter::escape( const QString & s) { QString result = s; result.replace(QChar('&'), "&"); //must be done first result.replace(QChar('<'), "<"); result.replace(QChar('>'), ">"); return result; }