diff -r 41937601b3b8 -r 98449ef9eccd mapeditor.cpp --- a/mapeditor.cpp Mon Jul 27 12:53:19 2009 +0000 +++ b/mapeditor.cpp Thu Jul 30 07:40:05 2009 +0000 @@ -249,7 +249,9 @@ s=(((BranchObj*)lmo)->getHeading()); if (s=="") s="unnamed"; - return QString("branch (%1)").arg(s); + if ((typeid(*lmo) == typeid(BranchObj) ) ) + return QString("branch (%1)").arg(s); + return QString("mapcenter (%1)").arg(s); } if ((typeid(*lmo) == typeid(FloatImageObj) )) return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); @@ -321,12 +323,15 @@ FloatImageObj (mapScene).resetSaveCounter(); // Build xml recursivly - if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) + if (!saveSel ) // Save complete map, if saveSel not set s+=model->saveToDir(tmpdir,prefix,writeflags,offset); else { - if ( typeid(*saveSel) == typeid(BranchObj) ) + if ( typeid (*saveSel) == typeid (MapCenterObj)) + // Save Subtree + s+=((MapCenterObj*)saveSel)->saveToDir(tmpdir,prefix,0,offset); + else if ( typeid(*saveSel) == typeid(BranchObj) ) // Save Subtree s+=((BranchObj*)saveSel)->saveToDir(tmpdir,prefix,offset); else @@ -471,10 +476,12 @@ qWarning ("MapEditor::saveStateRemovingPart no redoSel given!"); return; } - QString undoSelection=model->getSelectString (redoSel->getParObj()); + + QString undoSelection; QString redoSelection=model->getSelectString(redoSel); if (typeid(*redoSel) == typeid(BranchObj) ) { + undoSelection=model->getSelectString (redoSel->getParObj()); // save the selected branch of the map, Undo will insert part of map saveState (PartOfMap, undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), @@ -482,6 +489,16 @@ comment, redoSel); } + if (typeid(*redoSel) == typeid(MapCenterObj) ) + { + undoSelection.clear(); + // save the selected branch of the map, Undo will insert part of map + saveState (PartOfMap, + undoSelection, QString("addMapInsert (\"PATH\")"), + redoSelection, "delete ()", + comment, + redoSel); + } } @@ -611,21 +628,26 @@ ///////////////////////////////////////////////////////////////////// } else if (com==QString("addMapInsert")) { - if (xelection.isEmpty()) + if (parser.parCount()==2) { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else - { - if (parser.checkParCount(2)) + if (xelection.isEmpty()) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selb ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else { t=parser.parString (ok,0); // path to map n=parser.parInt(ok,1); // position if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); - addMapInsertInt(t,n); + addMapInsertInt(t,n); } + } else if (parser.parCount ()==1) + { + t=parser.parString (ok,0); // path to map + if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); + addMapInsertInt(t); } ///////////////////////////////////////////////////////////////////// } else if (com=="clearFlags") @@ -2312,8 +2334,7 @@ QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); // select object before undo - if (!undoSelection.isEmpty()) - select (undoSelection); + select (undoSelection); if (debug) { @@ -2430,40 +2451,56 @@ QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); } -void MapEditor::addMapInsertInt (const QString &path, int pos) +bool MapEditor::addMapInsertInt (const QString &path) +{ + QString pathDir=path.left(path.findRev("/")); + QDir d(pathDir); + QFile file (path); + + if (d.exists() ) + { + // We need to parse saved XML data + parseVYMHandler handler; + QXmlInputSource source( file); + QXmlSimpleReader reader; + reader.setContentHandler( &handler ); + reader.setErrorHandler( &handler ); + handler.setModel (model); + handler.setTmpDir ( pathDir ); // needed to load files with rel. path + handler.setLoadMode (ImportAdd); + blockReposition=true; + bool ok = reader.parse( source ); + blockReposition=false; + if ( ok ) return true; + + // This should never ever happen + QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), + handler.errorProtocol()); + } else + QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); + return false; +} + +bool MapEditor::addMapInsertInt (const QString &path, int pos) { BranchObj *sel=xelection.getBranch(); if (sel) { - QString pathDir=path.left(path.findRev("/")); - QDir d(pathDir); - QFile file (path); - - if (d.exists() ) + if (addMapInsertInt (path)) { - // We need to parse saved XML data - parseVYMHandler handler; - QXmlInputSource source( file); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setModel (model); - handler.setTmpDir ( pathDir ); // needed to load files with rel. path - handler.setLoadMode (ImportAdd); - blockReposition=true; - bool ok = reader.parse( source ); - blockReposition=false; - if (! ok ) - { - // This should never ever happen - QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), - handler.errorProtocol()); + { + if (sel->getDepth()>0) + sel->getLastBranch()->linkTo (sel,pos); } - if (sel->getDepth()>0) - sel->getLastBranch()->linkTo (sel,pos); + return true; } else + { QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); + return false; + } } + qWarning ("ME::addMapInsertInt nothing selected"); + return false; } void MapEditor::pasteNoSave(const int &n) @@ -2828,11 +2865,8 @@ BranchObj *bo = xelection.getBranch(); if (bo && xelection.type()==Selection::MapCenter) { - // BranchObj* par=(BranchObj*)(bo->getParObj()); xelection.unselect(); - /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!) saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); - */ bo=model->removeMapCenter ((MapCenterObj*)bo); if (bo) { @@ -2852,7 +2886,6 @@ xelection.select (par); ensureSelectionVisible(); model->reposition(); -// xelection.update(); xelection.update(); return; }