diff -r 9eb7767c2dfa -r 608f976aa7bb xml.cpp --- a/xml.cpp Sun Jan 30 12:58:47 2005 +0000 +++ b/xml.cpp Tue Jun 06 14:58:11 2006 +0000 @@ -2,16 +2,20 @@ #include #include -#include +#include +//Added by qt3to4: +#include #include #include "misc.h" #include "settings.h" +#include "linkablemapobj.h" #include "version.h" static BranchObj *lastBranch; static FloatObj *lastFloat; +static OrnamentedObj *lastOO; extern Settings settings; @@ -47,7 +51,7 @@ const QString& eName, const QXmlAttributes& atts ) { QColor col; -// cout << "startElement <"< state="< state="<Map is newer than VYM" "

The map you are just trying to load was " "saved using vym " +atts.value("version")+". " - "The version of this vym is " __VYM_VERSION__ + "The version of this vym is " __VYM_VERSION ". If you run into problems after pressing " "the ok-button below, updating vym should help."); @@ -105,6 +109,15 @@ col.setNamedColor(atts.value("linkColor")); me->setLinkColor(col); } + if (!atts.value( "defXLinkColor").isEmpty() ) + { + col.setNamedColor(atts.value("defXLinkColor")); + me->setDefXLinkColor(col); + } + if (!atts.value( "defXLinkWidth").isEmpty() ) + { + me->setDefXLinkWidth(atts.value("defXLinkWidth").toInt ()); + } } } else if ( eName == "select" && state == StateMap ) { @@ -129,7 +142,7 @@ if (lmo && (typeid(*lmo) == typeid(BranchObj) ) || (typeid(*lmo) == typeid(MapCenterObj) ) ) { - lastBranch=(BranchObj*)(lmo); + lastBranch=(BranchObj*)lmo; if (loadMode==ImportAdd) { lastBranch->addBranch(); @@ -149,7 +162,7 @@ if (!atts.value( "textColor").isEmpty() ) { col.setNamedColor(atts.value("textColor")); - lastBranch->setColor(col ,false ); + lastBranch->setColor(col ); } } else if ( eName == "note" && state == StateMapCenter) { // only for backward compatibility (<1.4.6). Use htmlnote now. @@ -165,26 +178,43 @@ lastBranch->addFloatImage(); lastFloat=lastBranch->getLastFloatImage(); if (!readFloatImageAttr(atts)) return false; - } else if ( eName == "branch" && state == StateMap) + } else if ( (eName == "branch"||eName=="floatimage") && state == StateMap) { // This is used in vymparts, which have no mapcenter! isVymPart=true; - state=StateBranch; LinkableMapObj* lmo=me->getSelection(); + if (!lmo) + { + // If a vym part is _loaded_ (not imported), + // selection==lmo==NULL + // Treat it like ImportAdd then... + loadMode=ImportAdd; + lmo=mc; + } if (lmo && (typeid(*lmo) == typeid(BranchObj) ) || (typeid(*lmo) == typeid(MapCenterObj) ) ) { lastBranch=(BranchObj*)(lmo); - if (loadMode==ImportAdd) + if (eName=="branch") { - lastBranch->addBranch(); - lastBranch=lastBranch->getLastBranch(); - } else - lastBranch->clear(); - } else - return false; - branchDepth=1; - readBranchAttr (atts); + state=StateBranch; + if (loadMode==ImportAdd) + { + lastBranch->addBranch(); + lastBranch=lastBranch->getLastBranch(); + + } else + lastBranch->clear(); + branchDepth=1; + readBranchAttr (atts); + } else if (eName=="floatimage") + { + state=StateFloatImage; + lastBranch->addFloatImage(); + lastFloat=lastBranch->getLastFloatImage(); + if (!readFloatImageAttr(atts)) return false; + } else return false; + } else return false; } else if ( eName == "branch" && state == StateMapCenter) { state=StateBranch; @@ -201,7 +231,7 @@ if (!atts.value( "textColor").isEmpty() ) { col.setNamedColor(atts.value("textColor")); - lastBranch->setColor(col ,false ); + lastBranch->setColor(col ); } } else if ( eName == "note" && state == StateBranch) { @@ -220,6 +250,10 @@ lastBranch->addFloatImage(); lastFloat=lastBranch->getLastFloatImage(); if (!readFloatImageAttr(atts)) return false; + } else if ( eName == "xlink" && state == StateBranch ) + { + state=StateBranchXLink; + if (!readXLinkAttr (atts)) return false; } else if ( eName == "branch" && state == StateBranch ) { lastBranch->addBranch(); @@ -255,6 +289,7 @@ case StateMapCenterHeading: state=StateMapCenter; return true; case StateMapCenterNote: state=StateMapCenter; return true; case StateMapCenterFloatImage: state=StateMapCenter; return true; + case StateFloatImage: state=StateMap; return true; case StateBranch: if (branchDepth>1) { @@ -274,6 +309,7 @@ case StateBranchHeading: state=StateBranch; return true; case StateBranchNote: state=StateBranch; return true; case StateBranchFloatImage: state=StateBranch; return true; + case StateBranchXLink: state=StateBranch; return true; case StateHtmlNote: state=laststate; return true; case StateHtml: htmldata+=""; @@ -349,11 +385,27 @@ bool mapBuilderHandler::fatalError( const QXmlParseException& exception ) { - errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n") + errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n") .arg( exception.message() ) .arg( exception.lineNumber() ) .arg( exception.columnNumber() ); - + // Try to read the bogus line + errorProt+=QString("File is: %1\n").arg(inputFile); + QString s; + if (loadStringFromDisk (inputFile,s)) + { + QStringList sl=QStringList::split ("\n",s); + int i=1; + QStringList::Iterator it = sl.begin(); + while (i"); + errorProt+=s; + } return QXmlDefaultHandler::fatalError( exception ); } @@ -368,6 +420,11 @@ tmpDir=tp; } +void mapBuilderHandler::setInputFile (QString f) +{ + inputFile=f; +} + void mapBuilderHandler::setLoadMode (const LoadMode &lm) { loadMode=lm; @@ -375,28 +432,65 @@ bool mapBuilderHandler::readBranchAttr (const QXmlAttributes& a) { - bool okx,oky; - int x,y; - if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) - { - if (!a.value( "absPosY").isEmpty() ) - { - x=a.value("absPosX").toInt (&okx, 10); - y=a.value("absPosY").toInt (&oky, 10); - if (okx && oky) - lastBranch->move(x,y); - else - return false; // Couldn't read absPos - } - } + lastOO=lastBranch; + if (!readOOAttr(a)) return false; + if (!a.value( "scrolled").isEmpty() ) lastBranch->toggleScroll(); - if (!a.value( "url").isEmpty() ) - lastBranch->setURL (a.value ("url")); - if (!a.value( "vymLink").isEmpty() ) - lastBranch->setVymLink (a.value ("vymLink")); if (!a.value( "frameType").isEmpty() ) lastBranch->setFrameType (a.value("frameType")); + + if (!a.value( "incImgV").isEmpty() ) + { + if (a.value("incImgV")=="true") + lastBranch->setIncludeImagesVer(true); + else + lastBranch->setIncludeImagesVer(false); + } + if (!a.value( "incImgH").isEmpty() ) + { + if (a.value("incImgH")=="true") + lastBranch->setIncludeImagesHor(true); + else + lastBranch->setIncludeImagesHor(false); + } + return true; +} + +bool mapBuilderHandler::readOOAttr (const QXmlAttributes& a) +{ + if (lastOO) + { + bool okx,oky; + int x,y; + if (!a.value( "absPosX").isEmpty() && loadMode==NewMap && branchDepth<2) + { + if (!a.value( "absPosY").isEmpty() ) + { + x=a.value("absPosX").toInt (&okx, 10); + y=a.value("absPosY").toInt (&oky, 10); + if (okx && oky ) + lastOO->move(x,y); + else + return false; // Couldn't read absPos + } + } + if (!a.value( "url").isEmpty() ) + lastOO->setURL (a.value ("url")); + if (!a.value( "vymLink").isEmpty() ) + lastOO->setVymLink (a.value ("vymLink")); + if (!a.value( "hideInExport").isEmpty() ) + if (a.value("hideInExport")=="true") + lastOO->setHideInExport(true); + + if (!a.value( "hideLink").isEmpty()) + { + if (a.value ("hideLink") =="true") + lastOO->setHideLinkUnselected(true); + else + lastOO->setHideLinkUnselected(false); + } + } return true; } @@ -411,26 +505,26 @@ QFile file (fn); QString s; // Reading a note - if ( !file.open( IO_ReadOnly) ) + if ( !file.open( QIODevice::ReadOnly) ) { qWarning ("mapBuilderHandler::readNoteAttr: Couldn't load "+fn); return false; } QTextStream stream( &file ); QString lines; - while ( !stream.eof() ) { + while ( !stream.atEnd() ) { lines += stream.readLine()+"\n"; } file.close(); // Convert to richtext - if ( !QStyleSheet::mightBeRichText( lines ) ) + if ( !Q3StyleSheet::mightBeRichText( lines ) ) { // Here we are workarounding the QT conversion method: // convertFromPlainText does not generate valid xml, needed // for the parser, but just

and
without closing tags. // So we have to add those by ourselves //lines=quotemeta (lines); - lines = QStyleSheet::convertFromPlainText( lines, QStyleSheetItem::WhiteSpaceNormal ); + lines = Q3StyleSheet::convertFromPlainText( lines, Q3StyleSheetItem::WhiteSpaceNormal ); lines.replace ("
","
"); } @@ -448,6 +542,10 @@ bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a) { + lastOO=lastFloat; + + //if (!readOOAttr(a)) return false; + if (!a.value( "useOrientation").isEmpty() ) { if (a.value ("useOrientation") =="true") @@ -470,8 +568,9 @@ } if (!a.value( "floatExport").isEmpty() ) { - if (a.value ("floatExpofrt") =="true") - lastFloat->setFloatExport (true); + // Only for compatibility. THis is not used since 1.7.11 + if (a.value ("floatExport") =="true") + lastFloat->setFloatExport(true); else lastFloat->setFloatExport (false); } @@ -487,15 +586,66 @@ x=a.value("relPosX").toInt (&okx, 10); y=a.value("relPosY").toInt (&oky, 10); if (okx && oky) - lastFloat->setRelPos (QPoint (x,y) ); + + { + lastFloat->setRelPos (QPoint (x,y) ); + // make sure floats in mapcenter are repositioned to relative pos + if (mc==lastBranch) mc->positionContents(); + } else // Couldn't read relPos return false; } } + + if (!readOOAttr(a)) return false; + + if (!a.value ("orgName").isEmpty() ) + { + ((FloatImageObj*)(lastFloat))->setOriginalFilename (a.value("orgName")); + } return true; } +bool mapBuilderHandler::readXLinkAttr (const QXmlAttributes& a) +{ + QColor col; + bool okx; + bool success=false; + XLinkObj *xlo=new XLinkObj (mc->getCanvas()); + if (!a.value( "color").isEmpty() ) + { + col.setNamedColor(a.value("color")); + xlo->setColor (col); + } + + if (!a.value( "width").isEmpty() ) + { + xlo->setWidth(a.value ("width").toInt (&okx, 10)); + } + + if (!a.value( "beginBranch").isEmpty() ) + { + if (!a.value( "endBranch").isEmpty() ) + { + LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch")); + if (lmo && typeid (*lmo)==typeid (BranchObj)) + { + xlo->setBegin ((BranchObj*)(lmo)); + lmo=mc->findObjBySelect (a.value( "endBranch")); + if (lmo && typeid (*lmo)==typeid (BranchObj)) + { + xlo->setEnd ((BranchObj*)(lmo)); + xlo->activate(); + } + } + success=true; // Not all branches there yet, no error + } + } + if (!success) delete (xlo); + return success; +} + bool mapBuilderHandler::readHtmlAttr (const QXmlAttributes& a) { for (int i=1; i<=a.count(); i++)