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