diff -r f0fe7c36ec5c -r 43268373032d xml-vym.cpp --- a/xml-vym.cpp Fri Apr 09 14:24:04 2010 +0000 +++ b/xml-vym.cpp Wed Jun 09 13:14:08 2010 +0000 @@ -146,9 +146,15 @@ lastBranch=bi; if (loadMode==ImportAdd) { + // Import Add lastBranch=model->createBranch(lastBranch); - } //else - model->clearItem(lastBranch); + } else + { + // Import Replace + // Parser should not be called with ImportReplace any longer, + // that's done in VymModel now. + qDebug()<<"xml-vym: ImportReplace ?!"; + } } else // add mapCenter without parent lastBranch=model->createMapCenter(); @@ -208,6 +214,8 @@ if (loadMode==ImportAdd) { lastBranch=model->createBranch(lastBranch); + if (insertPos>=0) + model->relinkBranch (lastBranch,(BranchItem*)ti,insertPos); } else model->clearItem (lastBranch); readBranchAttr (atts); @@ -239,6 +247,10 @@ { state=StateBranchXLink; if (!readXLinkAttr (atts)) return false; + } else if ( eName == "xlink" && state == StateMap) + { + state=StateLink; + if (!readLinkNewAttr (atts)) return false; } else if ( eName == "branch" && state == StateBranch ) { lastBranch=model->createBranch(lastBranch); @@ -545,10 +557,17 @@ return true; } -bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a) +bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a) { + // Format of links was changed several times: + // // object ID is used starting in version 1.8.76 // (before there was beginBranch and endBranch) + // + // Starting in 1.13.2 xlinks are no longer subitems of branches, + // but listed at the end of the data in a map. This make handling + // of links much safer and easier + if (!a.value( "beginID").isEmpty() ) { if (!a.value( "endID").isEmpty() ) @@ -557,28 +576,66 @@ TreeItem *endBI=model->findBySelectString (a.value( "endID")); if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() ) { - XLinkItem *xli=model->createXLink (lastBranch,true); - xli->setBegin ( (BranchItem*)beginBI ); - xli->setEnd ( (BranchItem*)endBI); - xli->activate(); + Link *li=new Link (model); + li->setBeginBranch ( (BranchItem*)beginBI ); + li->setEndBranch ( (BranchItem*)endBI); if (!a.value( "color").isEmpty() ) { QColor col; col.setNamedColor(a.value("color")); - xli->setColor (col); + li->setColor (col); } if (!a.value( "width").isEmpty() ) { bool okx; - xli->setWidth(a.value ("width").toInt (&okx, 10)); + li->setWidth(a.value ("width").toInt (&okx, 10)); } - xli->updateXLink(); + model->createLink (li,true); // create MO by default } } } - return true; // xLinks can only be established at the "end branch", return true + return true; +} + +bool parseVYMHandler::readLinkNewAttr (const QXmlAttributes& a) +{ + // object ID is used starting in version 1.8.76 + // (before there was beginBranch and endBranch) + + // Beginning in 1.13.2 xLinks are no longer parts of branches, but + // a separate list after all the mapCenters within ... + + if (!a.value( "beginID").isEmpty() ) + { + if (!a.value( "endID").isEmpty() ) + { + TreeItem *beginBI=model->findBySelectString (a.value( "beginID")); + TreeItem *endBI=model->findBySelectString (a.value( "endID")); + if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() ) + { + Link *li=new Link (model); + li->setBeginBranch ( (BranchItem*)beginBI ); + li->setEndBranch ( (BranchItem*)endBI); + + if (!a.value( "color").isEmpty() ) + { + QColor col; + col.setNamedColor(a.value("color")); + li->setColor (col); + } + + if (!a.value( "width").isEmpty() ) + { + bool okx; + li->setWidth(a.value ("width").toInt (&okx, 10)); + } + model->createLink (li,true); // create MO by default + } + } + } + return true; } bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)