fileformat/Reporter/Reporter.h
Go to the documentation of this file.
00001 /* Copyright 2009 Andreas Gölzer
00002 
00003  This file is part of readESM.
00004 
00005  readESM is free software: you can redistribute it and/or modify it under the
00006  terms of the GNU General Public License as published by the Free Software
00007  Foundation, either version 3 of the License, or (at your option) any later
00008  version.
00009 
00010  readESM is distributed in the hope that it will be useful, but WITHOUT ANY
00011  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00013 
00014  You should have received a copy of the GNU General Public License along with
00015  readESM.  If not, see <http://www.gnu.org/licenses/>. */
00016 
00017 #ifndef REPORTER_H
00018 #define REPORTER_H REPORTER_H
00019 
00020 #include <QtCore/QCoreApplication>
00021 #include <QtCore/QSharedPointer>
00022 #include <QtCore/QString>
00023 #include <QtCore/QTextStream>
00024 
00025 class DataType;
00026 class Block;
00027 
00028 class Reporter {
00029         Q_DECLARE_TR_FUNCTIONS(Reporter)
00030 public:
00031         virtual void tagValuePair(const QString& tag, const QString& value) = 0;
00032         virtual void tagValuePair(const QString& tag, int value);
00033         virtual void writeBlock(const Block& value, const QString& tag = "");
00035         virtual QByteArray toQByteArray() const = 0;
00036         virtual void setTitle(const QString& newtitle);
00037         virtual bool allowSvg() const = 0;
00038         void flush();
00039         Reporter();
00040         template <typename Arraytype>
00041         void writeArray(const Arraytype& ray, const QString& title = "", bool defaultShown = true){
00042                 arrayStart(ray.numberOfBlocks(), title, defaultShown);
00043                 ++nestLevel;
00044                 for(int j = 0; j < ray.numberOfBlocks(); ++j){
00045                         this->writeBlock(ray[j]);
00046                 }
00047                 --nestLevel;
00048                 arrayEnd(ray.numberOfBlocks());
00049         }
00050 protected:
00051         int nestLevel;
00052         QByteArray collected;
00053         mutable QTextStream collector;
00054         QString title;
00055         virtual void subBlock(const Block& value, const QString& tag) = 0;
00056         virtual void arrayStart(int count, const QString& title, bool defaultShown){}
00057         virtual void arrayEnd(int count){}
00058 };
00059 
00060 #endif