F:/KPlato/koffice/kplato/kptxmlloaderobject.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008    
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef XMLLOADEROBJECT_H
00021 #define XMLLOADEROBJECT_H
00022 
00023 #include "kptproject.h"
00024 
00025 #include <qdatetime.h>
00026 #include <QString>
00027 #include <qstringlist.h>
00028 
00029 namespace KPlato 
00030 {
00031 
00032 class XMLLoaderObject {
00033 public:
00034     enum Severity { None=0, Errors=1, Warnings=2, Diagnostics=3, Debug=4 };
00035     XMLLoaderObject()
00036     : m_project(0),
00037       m_errors(0),
00038       m_warnings(0),
00039       m_logLevel(Diagnostics),
00040       m_log() {
00041     }
00042     ~XMLLoaderObject() {}
00043     
00044     void setProject(Project *proj) { m_project = proj; }
00045     Project &project() const { return *m_project; }
00046     
00047     void startLoad() {
00048         m_timer.start();
00049         m_starttime = QDateTime::currentDateTime();
00050         m_errors = m_warnings = 0;
00051         m_log.clear();
00052         addMsg(QString("Loading started at %1").arg(m_starttime.toString()));
00053     }
00054     void stopLoad() { 
00055         m_elapsed = m_timer.elapsed();
00056         addMsg(QString("Loading finished at %1, took %2").arg(QDateTime::currentDateTime().toString()).arg(formatElapsed()));
00057     }
00058     QDateTime lastLoaded() const { return m_starttime; }
00059     int elapsed() const { return m_elapsed; }
00060     QString formatElapsed() { return QString("%1 seconds").arg((double)m_elapsed/1000); }
00061     
00062     void setLogLevel(Severity sev) { m_logLevel = sev; }
00063     const QStringList &log() const { return m_log; }
00064     void addMsg(int sev, QString msg) {
00065         increment(sev);
00066         if (m_logLevel < sev) return;
00067         QString s;
00068         if (sev == Errors) s = "ERROR";
00069         else if (sev == Warnings) s = "WARNING";
00070         else if (sev == Diagnostics) s = "Diagnostic";
00071         else if (sev == Debug) s = "Debug";
00072         else s = "Message";
00073         m_log<<QString("%1: %2").arg(s, 13).arg(msg);
00074     }
00075     void addMsg(QString msg) { m_log<<msg; }
00076     void increment(int sev) {
00077         if (sev == Errors) { incErrors(); return; }
00078         if (sev == Warnings) { incWarnings(); return; }
00079     }
00080     void incErrors() { ++m_errors; }
00081     int errors() const { return m_errors; }
00082     bool error() const { return m_errors > 0; }
00083     void incWarnings() { ++m_warnings; }
00084     int warnings() const { return m_warnings; }
00085     bool warning() const { return m_warnings > 0; }
00086 
00087 protected:
00088     Project *m_project;
00089     int m_errors;
00090     int m_warnings;
00091     int m_logLevel;
00092     QStringList m_log;
00093     QDateTime m_starttime;
00094     QTime m_timer;
00095     int m_elapsed;
00096 };
00097 
00098 } //namespace KPlato
00099 
00100 #endif

Généré le Wed Nov 22 23:40:58 2006 pour KPlato par  doxygen 1.5.1-p1