diff -r c6bb4fdcc55f -r 78ba80b54bc4 vymmodel.cpp --- a/vymmodel.cpp Sat Aug 08 21:58:26 2009 +0000 +++ b/vymmodel.cpp Tue Aug 18 12:39:07 2009 +0000 @@ -241,22 +241,29 @@ // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe... standardFlagsMaster->resetUsedCounter(); - // Reset the counters before saving - // TODO constr. of FIO creates lots of objects, better do this in some other way... - ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe... - // Build xml recursivly - if (!saveSel || saveSel->getType()==TreeItem::MapCenter) + if (!saveSel) // Save all mapcenters as complete map, if saveSel not set s+=saveTreeToDir(tmpdir,prefix,writeflags,offset); else { - if (saveSel->isBranchLikeType()) - // Save Subtree - s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset); - //FIXME-2 else if (saveSel->getType()==TreeItem::Image) - // Save image - //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix); + switch (saveSel->getType()) + { + case TreeItem::Branch: + // Save Subtree + s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset); + break; + case TreeItem::MapCenter: + // Save Subtree + s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset); + break; + case TreeItem::Image: + // Save Image + s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix); + break; + default://FIXME-4 other types shouldn't be safed... + break; + } } // Save local settings @@ -673,42 +680,55 @@ QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); } -void VymModel::addMapInsertInt (const QString &path, int pos) -{ -/* FIXME-2 addMapInsertInt not ported yet - BranchObj *sel=getSelectedBranch(); - if (sel) +bool VymModel::addMapInsertInt (const QString &path) +{ + QString pathDir=path.left(path.findRev("/")); + QDir d(pathDir); + QFile file (path); + + if (d.exists() ) { - 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 (this); + 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 VymModel::addMapInsertInt (const QString &path, int pos) +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi) + { + 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 (this); - 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); - } else + if (selbi->depth()>0) + relinkBranch (selbi->getLastBranch(), selbi,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; } ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn) @@ -1013,11 +1033,7 @@ s=ti->getHeading(); if (s=="") s="unnamed"; - if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter?? - return QString("branch (%1)").arg(s); - if (ti->getType()==TreeItem::Image) - return QString ("image (%1)").arg(ti->getHeading()); - return QString("Unknown type has no name!"); + return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s); } void VymModel::redo() @@ -1128,8 +1144,7 @@ QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); // select object before undo - if (!undoSelection.isEmpty()) - select (undoSelection); + select (undoSelection); if (debug) { @@ -1155,7 +1170,7 @@ redosAvail++; blockSaveState=blockSaveStateOrg; -/* TODO remove testing +/* testing only cout << "VymModel::undo() end\n"; cout << " undosAvail="<parent() ); + QString undoSelection; QString redoSelection=getSelectString(redoSel); if (redoSel->getType()==TreeItem::Branch) { + undoSelection=getSelectString (redoSel->parent()); // save the selected branch of the map, Undo will insert part of map saveState (PartOfMap, undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()), @@ -1338,6 +1354,15 @@ comment, redoSel); } + if (redoSel->getType()==TreeItem::MapCenter) + { + // save the selected branch of the map, Undo will insert part of map + saveState (PartOfMap, + undoSelection, QString("addMapInsert (\"PATH\")"), + redoSelection, "delete ()", + comment, + redoSel); + } } @@ -1983,10 +2008,10 @@ return NULL; } -AttributeItem* VymModel::addAttribute() -{ - TreeItem *selti=getSelectedItem(); - if (selti) +AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi) { QList cData; cData << "new attribute" << "undef"<<"undef"; @@ -1994,10 +2019,10 @@ emit (layoutAboutToBeChanged() ); - QModelIndex parix=index(selti); - int n=selti->getRowNumAppend (a); + QModelIndex parix=index(selbi); + int n=selbi->getRowNumAppend (a); beginInsertRows (parix,n,n+1); - selti->appendChild (a); + selbi->appendChild (a); endInsertRows (); emit (layoutChanged() ); @@ -2037,7 +2062,7 @@ QList cData; cData << "VM:addMapCenter" << "undef"<<"undef"; - BranchItem *newbi=new BranchItem (cData); + BranchItem *newbi=new BranchItem (cData,rootItem); newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); rootItem->appendChild (newbi); @@ -2197,6 +2222,10 @@ dst->insertBranch (pos,branch); endInsertRows(); + // Correct type if necessesary + if (branch->getType()==TreeItem::MapCenter) + branch->setType(TreeItem::Branch); + // reset parObj, fonts, frame, etc in related LMO or other view-objects branch->updateStyles(); @@ -2251,11 +2280,11 @@ return false; } -void VymModel::deleteSelection() // FIXME-2 include fix for deleted mapcenters from 1.12.4 +void VymModel::deleteSelection() { BranchItem *selbi=getSelectedBranch(); - if (selbi && selbi->isBranchLikeType() ) + if (selbi) { unselect(); saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi))); @@ -2268,7 +2297,7 @@ } return; } - TreeItem *ti=getSelectedImage(); + TreeItem *ti=getSelectedItem(); if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute) { TreeItem *pi=ti->parent(); @@ -2378,7 +2407,7 @@ reposition(); emit (layoutChanged() ); - if (pi->depth()>0) return pi; + if (pi->depth()>=0) return pi; } return NULL; } @@ -2873,22 +2902,29 @@ ///////////////////////////////////////////////////////////////////// } else if (com==QString("addMapInsert")) { - if (!selti) + if (parser.parCount()==2) { - parser.setError (Aborted,"Nothing selected"); - } else if (! selbi ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else - { - if (parser.checkParCount(2)) + + if (!selti) { + parser.setError (Aborted,"Nothing selected"); + } else if (! selbi ) + { + 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); } - } + } else if (parser.parCount()==1) + { + t=parser.parString (ok,0); // path to map + if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); + addMapInsertInt(t); + } else + parser.setError (Aborted,"Wrong number of parameters"); ///////////////////////////////////////////////////////////////////// } else if (com=="clearFlags") { @@ -4610,6 +4646,11 @@ bool VymModel::select (const QString &s) { + if (s.isEmpty()) + { + unselect(); + return true; + } TreeItem *ti=findBySelectString(s); if (ti) return select (index(ti)); return false;