00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "cat.hpp"
00017 #include "core/category.hpp"
00018 #include "../edgelist.hpp"
00019 #include <qfile.h>
00020 #include <qregexp.h>
00021 #include <qiodevice.h>
00022 #include <qxml.h>
00023
00024 Cat::Cat(PropositionGraph* cl)
00025 {
00026 caller = cl;
00027 }
00028
00029 Cat::~Cat()
00030 {
00031 }
00032
00033
00034 bool Cat::startElement(const QString &, const QString &,
00035 const QString &qName,
00036 const QXmlAttributes &attribs)
00037 {
00038 if (qName == "category") {
00039 current = new Category();
00040 }
00041 currentText ="";
00042 return true;
00043 }
00044
00045 bool Cat::characters(const QString &str)
00046 {
00047 currentText += str;
00048 return true;
00049 }
00050
00051 bool Cat::endElement(const QString &, const QString &,
00052 const QString &qName)
00053 {
00054 if (qName == "id") {
00055 current->setId(currentText);
00056 } else if (qName == "name") {
00057 current->setName(currentText);
00058 } else if (qName == "color") {
00059 QRegExp rz("(\\d*),(\\d*),(\\d*)");
00060 rz.search(currentText);
00061 current->setColor(QColor(rz.cap(1).toInt(),rz.cap(2).toInt(),rz.cap(3).toInt()));
00062 } else if (qName == "description") {
00063 current->setDescription(currentText);
00064 } else if (qName == "category") {
00065 caller->categories->insert(current->name(), current);
00066 }
00067 return true;
00068 }
00069
00070 bool Cat::fatalError(const QXmlParseException &exception)
00071 {
00072 qWarning("Line %d, column %d: %s", exception.lineNumber(),
00073 exception.columnNumber(), exception.message().ascii());
00074
00075 return false;
00076
00077 }
00078
00079 void Cat::ioError(const QFile file, const QString message)
00080 {
00081 caller->error(file.name() + message + ": " + file.errorString());
00082 }