author | insilmaril |
Mon, 06 Oct 2008 11:10:20 +0000 | |
changeset 726 | 7f43b93242aa |
parent 646 | 371945eb6d31 |
child 760 | 59614eaf5fbb |
permissions | -rw-r--r-- |
insilmaril@574 | 1 |
#include "xml-base.h" |
insilmaril@574 | 2 |
|
insilmaril@574 | 3 |
#include <QMessageBox> |
insilmaril@574 | 4 |
#include <QColor> |
insilmaril@574 | 5 |
#include <QTextStream> |
insilmaril@574 | 6 |
#include <iostream> |
insilmaril@574 | 7 |
|
insilmaril@574 | 8 |
#include "misc.h" |
insilmaril@574 | 9 |
#include "settings.h" |
insilmaril@574 | 10 |
#include "linkablemapobj.h" |
insilmaril@574 | 11 |
|
insilmaril@574 | 12 |
/* |
insilmaril@574 | 13 |
static BranchObj *lastBranch; |
insilmaril@574 | 14 |
static FloatObj *lastFloat; |
insilmaril@574 | 15 |
static OrnamentedObj *lastOO; |
insilmaril@574 | 16 |
|
insilmaril@574 | 17 |
extern Settings settings; |
insilmaril@574 | 18 |
extern QString vymVersion; |
insilmaril@574 | 19 |
*/ |
insilmaril@574 | 20 |
|
insilmaril@574 | 21 |
parseBaseHandler::parseBaseHandler() {} |
insilmaril@574 | 22 |
|
insilmaril@574 | 23 |
parseBaseHandler::~parseBaseHandler() {} |
insilmaril@574 | 24 |
|
insilmaril@574 | 25 |
QString parseBaseHandler::errorProtocol() { return errorProt; } |
insilmaril@574 | 26 |
|
insilmaril@574 | 27 |
|
insilmaril@574 | 28 |
/* |
insilmaril@574 | 29 |
bool parseBaseHandler::startDocument() |
insilmaril@574 | 30 |
{ |
insilmaril@574 | 31 |
errorProt = ""; |
insilmaril@574 | 32 |
state = StateInit; |
insilmaril@574 | 33 |
laststate = StateInit; |
insilmaril@574 | 34 |
stateStack.clear(); |
insilmaril@574 | 35 |
stateStack.append(StateInit); |
insilmaril@574 | 36 |
branchDepth=0; |
insilmaril@574 | 37 |
htmldata=""; |
insilmaril@574 | 38 |
isVymPart=false; |
insilmaril@574 | 39 |
return true; |
insilmaril@574 | 40 |
} |
insilmaril@574 | 41 |
*/ |
insilmaril@574 | 42 |
|
insilmaril@574 | 43 |
QString parseBaseHandler::parseHREF(QString href) |
insilmaril@574 | 44 |
{ |
insilmaril@574 | 45 |
QString type=href.section(":",0,0); |
insilmaril@574 | 46 |
QString path=href.section(":",1,1); |
insilmaril@574 | 47 |
if (!tmpDir.endsWith("/")) |
insilmaril@574 | 48 |
return tmpDir + "/" + path; |
insilmaril@574 | 49 |
else |
insilmaril@574 | 50 |
return tmpDir + path; |
insilmaril@574 | 51 |
} |
insilmaril@574 | 52 |
|
insilmaril@574 | 53 |
|
insilmaril@574 | 54 |
/* |
insilmaril@574 | 55 |
QString parseBaseHandler::errorString() |
insilmaril@574 | 56 |
{ |
insilmaril@574 | 57 |
return "the document is not in the VYM file format"; |
insilmaril@574 | 58 |
} |
insilmaril@574 | 59 |
*/ |
insilmaril@574 | 60 |
|
insilmaril@574 | 61 |
bool parseBaseHandler::fatalError( const QXmlParseException& exception ) |
insilmaril@574 | 62 |
{ |
insilmaril@574 | 63 |
errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n") |
insilmaril@574 | 64 |
.arg( exception.message() ) |
insilmaril@574 | 65 |
.arg( exception.lineNumber() ) |
insilmaril@574 | 66 |
.arg( exception.columnNumber() ); |
insilmaril@574 | 67 |
// Try to read the bogus line |
insilmaril@574 | 68 |
errorProt+=QString("File is: %1\n").arg(inputFile); |
insilmaril@574 | 69 |
QString s; |
insilmaril@574 | 70 |
if (loadStringFromDisk (inputFile,s)) |
insilmaril@574 | 71 |
{ |
insilmaril@574 | 72 |
QStringList sl=QStringList::split ("\n",s); |
insilmaril@574 | 73 |
int i=1; |
insilmaril@574 | 74 |
QStringList::Iterator it = sl.begin(); |
insilmaril@574 | 75 |
while (i<exception.lineNumber()-1) |
insilmaril@574 | 76 |
{ |
insilmaril@574 | 77 |
it++; |
insilmaril@574 | 78 |
i++; |
insilmaril@574 | 79 |
} |
insilmaril@574 | 80 |
s=*it; |
insilmaril@574 | 81 |
s.insert (exception.columnNumber()-1,"<ERROR>"); |
insilmaril@574 | 82 |
errorProt+=s; |
insilmaril@574 | 83 |
} |
insilmaril@574 | 84 |
return QXmlDefaultHandler::fatalError( exception ); |
insilmaril@574 | 85 |
} |
insilmaril@574 | 86 |
|
insilmaril@646 | 87 |
void parseBaseHandler::setModel (VymModel *m) |
insilmaril@574 | 88 |
{ |
insilmaril@646 | 89 |
model=m; |
insilmaril@574 | 90 |
} |
insilmaril@574 | 91 |
|
insilmaril@574 | 92 |
void parseBaseHandler::setTmpDir (QString tp) |
insilmaril@574 | 93 |
{ |
insilmaril@574 | 94 |
tmpDir=tp; |
insilmaril@574 | 95 |
} |
insilmaril@574 | 96 |
|
insilmaril@574 | 97 |
void parseBaseHandler::setInputFile (QString f) |
insilmaril@574 | 98 |
{ |
insilmaril@574 | 99 |
inputFile=f; |
insilmaril@574 | 100 |
} |
insilmaril@574 | 101 |
|
insilmaril@574 | 102 |
void parseBaseHandler::setLoadMode (const LoadMode &lm) |
insilmaril@574 | 103 |
{ |
insilmaril@574 | 104 |
loadMode=lm; |
insilmaril@574 | 105 |
} |
insilmaril@574 | 106 |