1.9.4 New base class for XML based file parsing (vym & Freemind)
authorinsilmaril
Mon Jul 30 09:47:15 2007 +0000 (2007-07-30)
changeset 576f342fa346580
parent 575 4b935d7e1671
child 577 6f090a2b10e3
1.9.4 New base class for XML based file parsing (vym & Freemind)
xml-vym.cpp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xml-vym.cpp	Mon Jul 30 09:47:15 2007 +0000
     1.3 @@ -0,0 +1,686 @@
     1.4 +#include "xml-vym.h"
     1.5 +
     1.6 +#include <QMessageBox>
     1.7 +#include <QColor>
     1.8 +#include <QTextStream>
     1.9 +#include <iostream>
    1.10 +
    1.11 +#include "misc.h"
    1.12 +#include "settings.h"
    1.13 +#include "linkablemapobj.h"
    1.14 +#include "version.h"
    1.15 +
    1.16 +static BranchObj *lastBranch;
    1.17 +static FloatObj *lastFloat;
    1.18 +static OrnamentedObj *lastOO;
    1.19 +
    1.20 +extern Settings settings;
    1.21 +extern QString vymVersion;
    1.22 +
    1.23 +/*
    1.24 +parseVYMHandler::parseVYMHandler() {}
    1.25 +
    1.26 +parseVYMHandler::~parseVYMHandler() {}
    1.27 +
    1.28 +QString parseVYMHandler::errorProtocol() { return errorProt; }
    1.29 +
    1.30 +*/
    1.31 +
    1.32 +bool parseVYMHandler::startDocument()
    1.33 +{
    1.34 +    errorProt = "";
    1.35 +    state = StateInit;
    1.36 +    laststate = StateInit;
    1.37 +	stateStack.clear();
    1.38 +	stateStack.append(StateInit);
    1.39 +    branchDepth=0;
    1.40 +	htmldata="";
    1.41 +	isVymPart=false;
    1.42 +    return true;
    1.43 +}
    1.44 +
    1.45 +
    1.46 +/*
    1.47 +QString parseVYMHandler::parseHREF(QString href)
    1.48 +{
    1.49 +	QString type=href.section(":",0,0);
    1.50 +	QString path=href.section(":",1,1);
    1.51 +	if (!tmpDir.endsWith("/"))
    1.52 +		return tmpDir + "/" + path;
    1.53 +	else	
    1.54 +		return tmpDir + path;
    1.55 +}
    1.56 +*/
    1.57 +bool parseVYMHandler::startElement  ( const QString&, const QString&,
    1.58 +                    const QString& eName, const QXmlAttributes& atts ) 
    1.59 +{
    1.60 +    QColor col;
    1.61 +	/* Testing
    1.62 +	cout << "startElement <"<< eName.ascii()
    1.63 +		<<">  state="<<state 
    1.64 +		<<"  laststate="<<stateStack.last()
    1.65 +		<<"   loadMode="<<loadMode
    1.66 +		<<"       line="<<QXmlDefaultHandler::lineNumber()
    1.67 +		<<endl;
    1.68 +	*/	
    1.69 +	stateStack.append (state);	
    1.70 +    if ( state == StateInit && (eName == "vymmap")  ) 
    1.71 +	{
    1.72 +        state = StateMap;
    1.73 +		if (!atts.value( "version").isEmpty() ) 
    1.74 +		{
    1.75 +			if (!checkVersion(atts.value("version")))
    1.76 +				QMessageBox::warning( 0, "Warning: Version Problem" ,
    1.77 +				   "<h3>Map is newer than VYM</h3>"
    1.78 +				   "<p>The map you are just trying to load was "
    1.79 +				   "saved using vym " +atts.value("version")+". "
    1.80 +				   "The version of this vym is " + vymVersion + 
    1.81 +				   ". If you run into problems after pressing "
    1.82 +				   "the ok-button below, updating vym should help.");
    1.83 +			else	   
    1.84 +				mc->setVersion(atts.value( "version" ));
    1.85 +
    1.86 +		}
    1.87 +		if (loadMode==NewMap || 
    1.88 +			(loadMode==ImportReplace && me->getSelection()==mc))
    1.89 +		{
    1.90 +			if (!atts.value( "author").isEmpty() )
    1.91 +			{
    1.92 +				mc->setAuthor(atts.value( "author" ) );
    1.93 +			}
    1.94 +			if (!atts.value( "comment").isEmpty() )
    1.95 +			{
    1.96 +				mc->setComment (atts.value( "comment" ) );
    1.97 +			}
    1.98 +			if (!atts.value( "backgroundColor").isEmpty() )
    1.99 +			{
   1.100 +				col.setNamedColor(atts.value("backgroundColor"));
   1.101 +				mc->getScene()->setBackgroundBrush(col);
   1.102 +			}	    
   1.103 +			if (!atts.value( "selectionColor").isEmpty() )
   1.104 +			{
   1.105 +				col.setNamedColor(atts.value("selectionColor"));
   1.106 +				me->setSelectionColor(col);
   1.107 +			}	    
   1.108 +			if (!atts.value( "linkColorHint").isEmpty() ) 
   1.109 +			{
   1.110 +				if (atts.value("linkColorHint")=="HeadingColor")
   1.111 +					me->setMapLinkColorHint(LinkableMapObj::HeadingColor);
   1.112 +				else
   1.113 +					me->setMapLinkColorHint(LinkableMapObj::DefaultColor);
   1.114 +			}
   1.115 +			if (!atts.value( "linkStyle").isEmpty() ) 
   1.116 +			{
   1.117 +				me->setMapLinkStyle(atts.value("linkStyle"));
   1.118 +			}	
   1.119 +			if (!atts.value( "linkColor").isEmpty() ) 
   1.120 +			{
   1.121 +				col.setNamedColor(atts.value("linkColor"));
   1.122 +				me->setMapDefLinkColor(col);
   1.123 +			}	
   1.124 +			if (!atts.value( "defXLinkColor").isEmpty() ) 
   1.125 +			{
   1.126 +				col.setNamedColor(atts.value("defXLinkColor"));
   1.127 +				me->setMapDefXLinkColor(col);
   1.128 +			}	
   1.129 +			if (!atts.value( "defXLinkWidth").isEmpty() ) 
   1.130 +			{
   1.131 +				me->setMapDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
   1.132 +			}	
   1.133 +		}	
   1.134 +	} else if ( eName == "select" && state == StateMap ) 
   1.135 +	{
   1.136 +		state=StateMapSelect;
   1.137 +	} else if ( eName == "setting" && state == StateMap ) 
   1.138 +	{
   1.139 +		state=StateMapSetting;
   1.140 +		if (loadMode==NewMap)
   1.141 +			readSettingAttr (atts);
   1.142 +	} else if ( eName == "mapcenter" && state == StateMap ) 
   1.143 +	{
   1.144 +		state=StateMapCenter;
   1.145 +		if (loadMode==NewMap)
   1.146 +		{	
   1.147 +			// Really use the found mapcenter as MCO in a new map
   1.148 +			lastBranch=mc;	// avoid empty pointer
   1.149 +		} else
   1.150 +		{
   1.151 +			// Treat the found mapcenter as a branch 
   1.152 +			// in an existing map
   1.153 +			LinkableMapObj* lmo=me->getSelection();
   1.154 +			if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
   1.155 +			        || (typeid(*lmo) == typeid(MapCenterObj) ) )
   1.156 +			{
   1.157 +				lastBranch=(BranchObj*)lmo;
   1.158 +				if (loadMode==ImportAdd)
   1.159 +				{
   1.160 +					lastBranch->addBranch();
   1.161 +					lastBranch=lastBranch->getLastBranch();
   1.162 +				} else
   1.163 +					lastBranch->clear();
   1.164 +			} else
   1.165 +				return false;
   1.166 +		}
   1.167 +		readBranchAttr (atts);
   1.168 +	} else if ( 
   1.169 +		(eName == "standardflag" ||eName == "standardFlag") && 
   1.170 +		(state == StateMapCenter || state==StateBranch)) 
   1.171 +	{
   1.172 +		state=StateStandardFlag;
   1.173 +	} else if ( eName == "heading" && (state == StateMapCenter||state==StateBranch)) 
   1.174 +	{
   1.175 +		laststate=state;
   1.176 +		state=StateHeading;
   1.177 +		if (!atts.value( "textColor").isEmpty() ) 
   1.178 +		{
   1.179 +			col.setNamedColor(atts.value("textColor"));
   1.180 +			lastBranch->setColor(col );
   1.181 +		}	    
   1.182 +	} else if ( eName == "note" && 
   1.183 +				(state == StateMapCenter ||state==StateBranch))
   1.184 +	{	// only for backward compatibility (<1.4.6). Use htmlnote now.
   1.185 +		state=StateNote;
   1.186 +		if (!readNoteAttr (atts) ) return false;
   1.187 +	} else if ( eName == "htmlnote" && state == StateMapCenter) 
   1.188 +	{
   1.189 +		laststate=state;
   1.190 +		state=StateHtmlNote;
   1.191 +    } else if ( eName == "floatimage" && 
   1.192 +				(state == StateMapCenter ||state==StateBranch)) 
   1.193 +	{
   1.194 +		state=StateFloatImage;
   1.195 +        lastBranch->addFloatImage();
   1.196 +		lastFloat=lastBranch->getLastFloatImage();
   1.197 +		if (!readFloatImageAttr(atts)) return false;
   1.198 +	} else if ( (eName == "branch"||eName=="floatimage") && state == StateMap) 
   1.199 +	{
   1.200 +		// This is used in vymparts, which have no mapcenter!
   1.201 +		isVymPart=true;
   1.202 +		LinkableMapObj* lmo=me->getSelection();
   1.203 +		if (!lmo)
   1.204 +		{
   1.205 +			// If a vym part is _loaded_ (not imported), 
   1.206 +			// selection==lmo==NULL
   1.207 +			// Treat it like ImportAdd then...
   1.208 +			loadMode=ImportAdd;
   1.209 +			lmo=mc;
   1.210 +		}	
   1.211 +		if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
   1.212 +				|| (typeid(*lmo) == typeid(MapCenterObj) ) )
   1.213 +		{
   1.214 +			lastBranch=(BranchObj*)(lmo);
   1.215 +			if (eName=="branch")
   1.216 +			{
   1.217 +				state=StateBranch;
   1.218 +				if (loadMode==ImportAdd)
   1.219 +				{
   1.220 +					lastBranch->addBranch();
   1.221 +					lastBranch=lastBranch->getLastBranch();
   1.222 +					
   1.223 +				} else
   1.224 +					lastBranch->clear();
   1.225 +				branchDepth=1;
   1.226 +				readBranchAttr (atts);
   1.227 +			} else if (eName=="floatimage")
   1.228 +			{
   1.229 +				state=StateFloatImage;
   1.230 +				lastBranch->addFloatImage();
   1.231 +				lastFloat=lastBranch->getLastFloatImage();
   1.232 +				if (!readFloatImageAttr(atts)) return false;
   1.233 +			} else return false;
   1.234 +		} else return false;
   1.235 +	} else if ( eName == "branch" && state == StateMapCenter) 
   1.236 +	{
   1.237 +		state=StateBranch;
   1.238 +		branchDepth=1;
   1.239 +		lastBranch->addBranch();
   1.240 +		lastBranch=lastBranch->getLastBranch();
   1.241 +		readBranchAttr (atts);
   1.242 +	} else if ( eName == "htmlnote" && state == StateBranch) 
   1.243 +	{
   1.244 +		laststate=state;
   1.245 +		state=StateHtmlNote;
   1.246 +		no.clear();
   1.247 +		if (!atts.value( "fonthint").isEmpty() ) 
   1.248 +			no.setFontHint(atts.value ("fonthint") );
   1.249 +	} else if ( eName == "frame" && (state == StateBranch||state==StateMapCenter)) 
   1.250 +	{
   1.251 +		laststate=state;
   1.252 +		state=StateFrame;
   1.253 +		if (!readFrameAttr(atts)) return false;
   1.254 +    } else if ( eName == "xlink" && state == StateBranch ) 
   1.255 +	{
   1.256 +		state=StateBranchXLink;
   1.257 +		if (!readXLinkAttr (atts)) return false;
   1.258 +    } else if ( eName == "branch" && state == StateBranch ) 
   1.259 +	{
   1.260 +        lastBranch->addBranch();
   1.261 +		lastBranch=lastBranch->getLastBranch();		
   1.262 +        branchDepth++;
   1.263 +		readBranchAttr (atts);
   1.264 +    } else if ( eName == "html" && state == StateHtmlNote ) 
   1.265 +	{
   1.266 +		state=StateHtml;
   1.267 +		htmldata="<"+eName;
   1.268 +		readHtmlAttr(atts);
   1.269 +		htmldata+=">";
   1.270 +    } else if ( state == StateHtml ) 
   1.271 +	{
   1.272 +		// accept all while in html mode,
   1.273 +		htmldata+="<"+eName;
   1.274 +		readHtmlAttr(atts);
   1.275 +		htmldata+=">";
   1.276 +    } else
   1.277 +        return false;   // Error
   1.278 +    return true;
   1.279 +}
   1.280 +
   1.281 +bool parseVYMHandler::endElement  ( const QString&, const QString&, const QString &eName)
   1.282 +{
   1.283 +	/* Testing
   1.284 +	cout << "endElement </" <<eName.ascii()
   1.285 +		<<">  state=" <<state 
   1.286 +		<<"  laststate=" <<laststate
   1.287 +		<<"  stateStack="<<stateStack.last() 
   1.288 +		<<endl;
   1.289 +	*/
   1.290 +    switch ( state ) 
   1.291 +	{
   1.292 +        case StateBranch: 
   1.293 +			lastBranch=(BranchObj*)(lastBranch->getParObj());
   1.294 +            break;
   1.295 +        case StateHtml: 
   1.296 +			htmldata+="</"+eName+">";
   1.297 +			if (eName=="html")
   1.298 +			{
   1.299 +				state=StateHtmlNote;  
   1.300 +				htmldata.replace ("<br></br>","<br />");
   1.301 +				no.setNote (htmldata);
   1.302 +				lastBranch->setNote (no);
   1.303 +			}	
   1.304 +			break;
   1.305 +		default: 
   1.306 +			break;
   1.307 +    }  
   1.308 +	state=stateStack.takeLast();	
   1.309 +	return true;
   1.310 +}
   1.311 +
   1.312 +bool parseVYMHandler::characters   ( const QString& ch)
   1.313 +{
   1.314 +	//cout << "characters \""<<ch<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
   1.315 +
   1.316 +	QString ch_org=quotemeta (ch);
   1.317 +    QString ch_simplified=ch.simplifyWhiteSpace();
   1.318 +    if ( ch_simplified.isEmpty() ) return true;
   1.319 +
   1.320 +    switch ( state ) 
   1.321 +    {
   1.322 +        case StateInit: break;
   1.323 +        case StateMap: break; 
   1.324 +		case StateMapSelect:
   1.325 +			me->select(ch_simplified);
   1.326 +			break;
   1.327 +		case StateMapSetting:break;
   1.328 +        case StateMapCenter: break;
   1.329 +        case StateNote:
   1.330 +			lastBranch->setNote(ch_simplified);
   1.331 +			break;
   1.332 +        case StateBranch: break;
   1.333 +        case StateStandardFlag: 
   1.334 +            lastBranch->activateStandardFlag(ch_simplified); 
   1.335 +            break;
   1.336 +        case StateFloatImage: break;
   1.337 +        case StateHtmlNote: break;
   1.338 +        case StateHtml:
   1.339 +			htmldata+=ch_org;
   1.340 +			break;
   1.341 +        case StateHeading: 
   1.342 +            lastBranch->setHeading(ch_simplified);
   1.343 +            break;
   1.344 +        default: 
   1.345 +			return false;
   1.346 +    }
   1.347 +    return true;
   1.348 +}
   1.349 +
   1.350 +QString parseVYMHandler::errorString() 
   1.351 +{
   1.352 +    return "the document is not in the VYM file format";
   1.353 +}
   1.354 +
   1.355 +/*
   1.356 +bool parseVYMHandler::fatalError( const QXmlParseException& exception ) 
   1.357 +{
   1.358 +    errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
   1.359 +    .arg( exception.message() )
   1.360 +    .arg( exception.lineNumber() )
   1.361 +    .arg( exception.columnNumber() );
   1.362 +	// Try to read the bogus line
   1.363 +	errorProt+=QString("File is: %1\n").arg(inputFile);
   1.364 +	QString s;
   1.365 +	if (loadStringFromDisk (inputFile,s))
   1.366 +	{
   1.367 +		QStringList sl=QStringList::split ("\n",s);
   1.368 +		int i=1;
   1.369 +		QStringList::Iterator it = sl.begin();
   1.370 +		while (i<exception.lineNumber()-1)
   1.371 +		{
   1.372 +			it++;
   1.373 +			i++;
   1.374 +		}
   1.375 +		s=*it;
   1.376 +		s.insert (exception.columnNumber()-1,"<ERROR>");
   1.377 +		errorProt+=s;
   1.378 +    }
   1.379 +    return QXmlDefaultHandler::fatalError( exception );
   1.380 +}
   1.381 +
   1.382 +void parseVYMHandler::setMapEditor (MapEditor* e)
   1.383 +{
   1.384 +    me=e;
   1.385 +	mc=me->getMapCenter();
   1.386 +}
   1.387 +
   1.388 +void parseVYMHandler::setTmpDir (QString tp)
   1.389 +{
   1.390 +	tmpDir=tp;
   1.391 +}
   1.392 +
   1.393 +void parseVYMHandler::setInputFile (QString f)
   1.394 +{
   1.395 +	inputFile=f;
   1.396 +}
   1.397 +
   1.398 +void parseVYMHandler::setLoadMode (const LoadMode &lm)
   1.399 +{
   1.400 +	loadMode=lm;
   1.401 +}
   1.402 +*/
   1.403 +bool parseVYMHandler::readBranchAttr (const QXmlAttributes& a)
   1.404 +{
   1.405 +	lastOO=lastBranch;
   1.406 +	if (!readOOAttr(a)) return false;
   1.407 +
   1.408 +	if (!a.value( "scrolled").isEmpty() )
   1.409 +		lastBranch->toggleScroll();
   1.410 +	if (!a.value( "frameType").isEmpty() ) 
   1.411 +		lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1
   1.412 +
   1.413 +	if (!a.value( "incImgV").isEmpty() ) 
   1.414 +	{	
   1.415 +		if (a.value("incImgV")=="true")
   1.416 +			lastBranch->setIncludeImagesVer(true);
   1.417 +		else	
   1.418 +			lastBranch->setIncludeImagesVer(false);
   1.419 +	}	
   1.420 +	if (!a.value( "incImgH").isEmpty() ) 
   1.421 +	{	
   1.422 +		if (a.value("incImgH")=="true")
   1.423 +			lastBranch->setIncludeImagesHor(true);
   1.424 +		else	
   1.425 +			lastBranch->setIncludeImagesHor(false);
   1.426 +	}	
   1.427 +	return true;	
   1.428 +}
   1.429 +
   1.430 +bool parseVYMHandler::readFrameAttr (const QXmlAttributes& a)
   1.431 +{
   1.432 +	bool ok;
   1.433 +	int x;
   1.434 +	if (lastOO)
   1.435 +	{
   1.436 +		if (!a.value( "frameType").isEmpty() ) 
   1.437 +			lastOO->setFrameType (a.value("frameType"));
   1.438 +		if (!a.value( "penColor").isEmpty() ) 
   1.439 +			lastOO->setFramePenColor (a.value("penColor"));
   1.440 +		if (!a.value( "brushColor").isEmpty() ) 
   1.441 +			lastOO->setFrameBrushColor (a.value("brushColor"));
   1.442 +		if (!a.value( "padding").isEmpty() ) 
   1.443 +		{
   1.444 +			x=a.value("padding").toInt(&ok);
   1.445 +			if (ok) lastOO->setFramePadding(x);
   1.446 +		}	
   1.447 +		if (!a.value( "borderWidth").isEmpty() ) 
   1.448 +		{
   1.449 +			x=a.value("borderWidth").toInt(&ok);
   1.450 +			if (ok) lastOO->setFrameBorderWidth(x);
   1.451 +		}	
   1.452 +	}		
   1.453 +	return true;
   1.454 +}
   1.455 +
   1.456 +bool parseVYMHandler::readOOAttr (const QXmlAttributes& a)
   1.457 +{
   1.458 +	if (lastOO)
   1.459 +	{
   1.460 +		bool okx,oky;
   1.461 +		int x,y;
   1.462 +		if (!a.value( "relPosX").isEmpty() ) 
   1.463 +		{
   1.464 +			if (!a.value( "relPosY").isEmpty() ) 
   1.465 +			{
   1.466 +				x=a.value("relPosX").toInt (&okx, 10);
   1.467 +				y=a.value("relPosY").toInt (&oky, 10);
   1.468 +				if (okx && oky  )
   1.469 +				{
   1.470 +					lastOO->setUseRelPos (true);
   1.471 +					lastOO->move2RelPos (x,y);
   1.472 +				}	
   1.473 +				else
   1.474 +					return false;   // Couldn't read relPos
   1.475 +			}           
   1.476 +		}           
   1.477 +		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) 
   1.478 +		{
   1.479 +			if (!a.value( "absPosY").isEmpty() ) 
   1.480 +			{
   1.481 +				x=a.value("absPosX").toInt (&okx, 10);
   1.482 +				y=a.value("absPosY").toInt (&oky, 10);
   1.483 +				if (okx && oky  )
   1.484 +					lastOO->move(x,y);
   1.485 +				else
   1.486 +					return false;   // Couldn't read absPos
   1.487 +			}           
   1.488 +		}           
   1.489 +		if (!a.value( "id").isEmpty() ) 
   1.490 +			lastOO->setID (a.value ("id"));
   1.491 +		if (!a.value( "url").isEmpty() ) 
   1.492 +			lastOO->setURL (a.value ("url"));
   1.493 +		if (!a.value( "vymLink").isEmpty() ) 
   1.494 +			lastOO->setVymLink (a.value ("vymLink"));
   1.495 +		if (!a.value( "hideInExport").isEmpty() ) 
   1.496 +			if (a.value("hideInExport")=="true")
   1.497 +				lastOO->setHideInExport(true);
   1.498 +
   1.499 +		if (!a.value( "hideLink").isEmpty()) 
   1.500 +		{
   1.501 +			if (a.value ("hideLink") =="true")
   1.502 +				lastOO->setHideLinkUnselected(true);
   1.503 +			else	
   1.504 +				lastOO->setHideLinkUnselected(false);
   1.505 +		}	
   1.506 +	}
   1.507 +	return true;	
   1.508 +}
   1.509 +
   1.510 +bool parseVYMHandler::readNoteAttr (const QXmlAttributes& a)
   1.511 +{	// only for backward compatibility (<1.4.6). Use htmlnote now.
   1.512 +	no.clear();
   1.513 +	QString fn;
   1.514 +	if (!a.value( "href").isEmpty() ) 
   1.515 +	{
   1.516 +		// Load note
   1.517 +		fn=parseHREF(a.value ("href") );
   1.518 +		QFile file (fn);
   1.519 +		QString s;						// Reading a note
   1.520 +
   1.521 +		if ( !file.open( QIODevice::ReadOnly) )
   1.522 +		{
   1.523 +			qWarning ("parseVYMHandler::readNoteAttr:  Couldn't load "+fn);
   1.524 +			return false;
   1.525 +		}	
   1.526 +		QTextStream stream( &file );
   1.527 +		QString lines;
   1.528 +		while ( !stream.atEnd() ) {
   1.529 +			lines += stream.readLine()+"\n"; 
   1.530 +		}
   1.531 +		file.close();
   1.532 +
   1.533 +		lines ="<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body>"+lines + "</p></body></html>";
   1.534 +		no.setNote (lines);
   1.535 +	}		
   1.536 +	if (!a.value( "fonthint").isEmpty() ) 
   1.537 +		no.setFontHint(a.value ("fonthint") );
   1.538 +	lastBranch->setNote(no);
   1.539 +	return true;
   1.540 +}
   1.541 +
   1.542 +bool parseVYMHandler::readFloatImageAttr (const QXmlAttributes& a)
   1.543 +{
   1.544 +	lastOO=lastFloat;
   1.545 +	
   1.546 +	//if (!readOOAttr(a)) return false;
   1.547 +
   1.548 +	if (!a.value( "useOrientation").isEmpty() ) 
   1.549 +	{
   1.550 +		if (a.value ("useOrientation") =="true")
   1.551 +			lastFloat->setUseOrientation (true);
   1.552 +		else	
   1.553 +			lastFloat->setUseOrientation (false);
   1.554 +	}	
   1.555 +	if (!a.value( "href").isEmpty() )
   1.556 +	{
   1.557 +		// Load FloatImage
   1.558 +		if (!lastFloat->load (parseHREF(a.value ("href") ) ))
   1.559 +		{
   1.560 +			QMessageBox::warning( 0, "Warning: " ,
   1.561 +				"Couldn't load float image\n"+parseHREF(a.value ("href") ));
   1.562 +			lastBranch->removeFloatImage(((FloatImageObj*)(lastFloat)));
   1.563 +			lastFloat=NULL;
   1.564 +			return true;
   1.565 +		}
   1.566 +		
   1.567 +	}	
   1.568 +	if (!a.value( "floatExport").isEmpty() ) 
   1.569 +	{
   1.570 +		// Only for compatibility. THis is not used since 1.7.11 
   1.571 +		if (a.value ("floatExport") =="true")
   1.572 +			lastFloat->setFloatExport(true);
   1.573 +		else	
   1.574 +			lastFloat->setFloatExport (false);
   1.575 +	}	
   1.576 +	if (!a.value( "zPlane").isEmpty() ) 
   1.577 +		lastFloat->setZValue (a.value("zPlane").toInt ());
   1.578 +    int x,y;
   1.579 +    bool okx,oky;
   1.580 +	if (!a.value( "relPosX").isEmpty() ) 
   1.581 +	{
   1.582 +		if (!a.value( "relPosY").isEmpty() ) 
   1.583 +		{
   1.584 +			// read relPos
   1.585 +			x=a.value("relPosX").toInt (&okx, 10);
   1.586 +			y=a.value("relPosY").toInt (&oky, 10);
   1.587 +			if (okx && oky) 
   1.588 +				
   1.589 +				{
   1.590 +					lastFloat->setRelPos (QPoint (x,y) );
   1.591 +					// make sure floats in mapcenter are repositioned to relative pos
   1.592 +					if (mc==lastBranch) mc->positionContents();
   1.593 +				}
   1.594 +			else
   1.595 +				// Couldn't read relPos
   1.596 +				return false;  
   1.597 +		}           
   1.598 +	}	
   1.599 +	
   1.600 +	if (!readOOAttr(a)) return false;
   1.601 +
   1.602 +	if (!a.value ("orgName").isEmpty() )
   1.603 +	{
   1.604 +		((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName"));
   1.605 +	}
   1.606 +	return true;
   1.607 +}
   1.608 +
   1.609 +bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)
   1.610 +{
   1.611 +	QColor col;
   1.612 +	bool okx;
   1.613 +	bool success=false;
   1.614 +	XLinkObj *xlo=new XLinkObj (mc->getScene());
   1.615 +	if (!a.value( "color").isEmpty() ) 
   1.616 +	{
   1.617 +		col.setNamedColor(a.value("color"));
   1.618 +		xlo->setColor (col);
   1.619 +	}
   1.620 +
   1.621 +	if (!a.value( "width").isEmpty() ) 
   1.622 +	{
   1.623 +		xlo->setWidth(a.value ("width").toInt (&okx, 10));
   1.624 +	}
   1.625 +
   1.626 +	// Connecting by select string for compatibility with version < 1.8.76
   1.627 +	if (!a.value( "beginBranch").isEmpty() ) 
   1.628 +	{ 
   1.629 +		if (!a.value( "endBranch").isEmpty() ) 
   1.630 +		{
   1.631 +			LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
   1.632 +			if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.633 +			{
   1.634 +				xlo->setBegin ((BranchObj*)lmo);
   1.635 +				lmo=mc->findObjBySelect (a.value( "endBranch"));
   1.636 +				if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.637 +				{
   1.638 +					xlo->setEnd ((BranchObj*)(lmo));
   1.639 +					xlo->activate();
   1.640 +				}
   1.641 +			}
   1.642 +			success=true; // Not all branches there yet, no error
   1.643 +		}           
   1.644 +	}	
   1.645 +
   1.646 +	// object ID is used starting in version 1.8.76
   1.647 +	if (!a.value( "beginID").isEmpty() ) 
   1.648 +	{ 
   1.649 +		if (!a.value( "endID").isEmpty() ) 
   1.650 +		{
   1.651 +			LinkableMapObj *lmo=mc->findID (a.value( "beginBranch"));
   1.652 +			if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.653 +			{
   1.654 +				xlo->setBegin ((BranchObj*)lmo);
   1.655 +				lmo=mc->findID (a.value( "endID"));
   1.656 +				if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.657 +				{
   1.658 +					xlo->setEnd ((BranchObj*)(lmo));
   1.659 +					xlo->activate();
   1.660 +				}
   1.661 +			}
   1.662 +			success=true; // Not all branches there yet, no error
   1.663 +		}           
   1.664 +	}	
   1.665 +	if (!success) delete (xlo);
   1.666 +	return success;
   1.667 +}
   1.668 +
   1.669 +bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)
   1.670 +{
   1.671 +	for (int i=1; i<=a.count(); i++)
   1.672 +		htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
   1.673 +	return true;
   1.674 +}
   1.675 +
   1.676 +bool parseVYMHandler::readSettingAttr (const QXmlAttributes& a)
   1.677 +{
   1.678 +	if (!a.value( "key").isEmpty() ) 
   1.679 +	{
   1.680 +		if (!a.value( "value").isEmpty() ) 
   1.681 +			settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
   1.682 +		else
   1.683 +			return false;
   1.684 +		
   1.685 +	} else
   1.686 +		return false;
   1.687 +	
   1.688 +	return true;
   1.689 +}