diff -r c2ffbc9b832d -r f867269ab8a1 mapeditor.cpp --- a/mapeditor.cpp Sat Feb 24 12:32:53 2007 +0000 +++ b/mapeditor.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -8,7 +8,7 @@ #include "version.h" -#include "api.h" +#include "parser.h" #include "editxlinkdialog.h" #include "exports.h" #include "extrainfodialog.h" @@ -427,35 +427,34 @@ void MapEditor::parseAtom(const QString &atom) { BranchObj *selb=xelection.getBranch(); - API api; QString s,t; int x,y; bool b,ok; // Split string s into command and parameters - api.parseInput (atom); - QString com=api.command(); + parser.parseAtom (atom); + QString com=parser.command(); // External commands if (com=="addBranch") { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is not a branch"); } else { QList pl; pl << 0 <<1; - if (api.checkParamCount(pl)) + if (parser.checkParamCount(pl)) { - if (api.paramCount()==0) + if (parser.paramCount()==0) addNewBranchInt (-2); else { - y=api.parInt (ok,0); + y=parser.parInt (ok,0); if (ok ) addNewBranchInt (y); } } @@ -464,13 +463,13 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is not a branch"); } else { - if (api.paramCount()==0) + if (parser.paramCount()==0) { addNewBranchBefore (); } @@ -479,31 +478,31 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - //s=api.parString (ok,0); // selection - t=api.parString (ok,0); // path to map + //s=parser.parString (ok,0); // selection + t=parser.parString (ok,0); // path to map if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); addMapReplaceInt(selb->getSelectString(),t); } - } else if (com==QString("addMapInsert")) + } else if (com==QString("addMparsernsert")) { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is not a branch"); } else { - if (api.checkParamCount(2)) + if (parser.checkParamCount(2)) { - t=api.parString (ok,0); // path to map - y=api.parInt(ok,1); // position + t=parser.parString (ok,0); // path to map + y=parser.parInt(ok,1); // position if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); addMapInsertInt(t,y); } @@ -512,39 +511,39 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) colorBranch (c); } } else if (com=="colorSubtree") { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) colorSubtree (c); } } else if (com=="cut") { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( xelection.type()!=Branch && xelection.type()!=MapCenter && xelection.type()!=FloatImage ) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(0)) { cut(); } @@ -552,11 +551,11 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { deleteSelection(); } @@ -564,11 +563,11 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { deleteKeepChilds(); } @@ -576,11 +575,11 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { deleteChilds(); } @@ -588,32 +587,32 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( selb) { - if (api.checkParamCount(4)) + if (parser.checkParamCount(4)) { // 0 selectstring of parent // 1 num in parent (for branches) // 2,3 x,y of mainbranch or mapcenter - s=api.parString(ok,0); + s=parser.parString(ok,0); LinkableMapObj *dst=mapCenter->findObjBySelect (s); if (dst) { if (typeid(*dst) == typeid(BranchObj) ) { // Get number in parent - x=api.parInt (ok,1); + x=parser.parInt (ok,1); if (ok) selb->linkTo ((BranchObj*)(dst),x); } else if (typeid(*dst) == typeid(MapCenterObj) ) { selb->linkTo ((BranchObj*)(dst),-1); // Get coordinates of mainbranch - x=api.parInt (ok,2); + x=parser.parInt (ok,2); if (ok) { - y=api.parInt (ok,3); + y=parser.parInt (ok,3); if (ok) selb->move (x,y); } } @@ -621,10 +620,10 @@ } } else if ( xelection.type() == FloatImage) { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { // 0 selectstring of parent - s=api.parString(ok,0); + s=parser.parString(ok,0); LinkableMapObj *dst=mapCenter->findObjBySelect (s); if (dst) { @@ -632,19 +631,32 @@ typeid(*dst) == typeid(MapCenterObj)) linkTo (dst->getSelectString()); } else - api.setError (Aborted,"Destination is not a branch"); + parser.setError (Aborted,"Destination is not a branch"); } } else - api.setError (Aborted,"Type of selection is not a floatimage or branch"); + parser.setError (Aborted,"Type of selection is not a floatimage or branch"); + } else if (com=="loadImage") + { + if (xelection.isEmpty()) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selb ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) + { + s=parser.parString(ok,0); + if (ok) loadFloatImageInt (s); + } } else if (com=="moveBranchUp") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { moveBranchUp(); } @@ -652,11 +664,11 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { moveBranchDown(); } @@ -664,18 +676,18 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( xelection.type()!=Branch && xelection.type()!=MapCenter && xelection.type()!=FloatImage ) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(2)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(2)) { - x=api.parInt (ok,0); + x=parser.parInt (ok,0); if (ok) { - y=api.parInt (ok,1); + y=parser.parInt (ok,1); if (ok) move (x,y); } } @@ -683,18 +695,18 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( xelection.type()!=Branch && xelection.type()!=MapCenter && xelection.type()!=FloatImage ) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(2)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(2)) { - x=api.parInt (ok,0); + x=parser.parInt (ok,0); if (ok) { - y=api.parInt (ok,1); + y=parser.parInt (ok,1); if (ok) moveRel (x,y); } } @@ -702,11 +714,11 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { paste(); } @@ -714,80 +726,96 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { if (!scrollBranch ()) - api.setError (Aborted,"Could not scroll branch"); + parser.setError (Aborted,"Could not scroll branch"); } } else if (com=="select") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) select (s); } + } else if (com=="selectLastBranch") + { + if (xelection.isEmpty() ) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selb ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) + { + BranchObj *bo=selb->getLastBranch(); + if (!bo) + parser.setError (Aborted,"Could not select last branch"); + selectInt (bo); + + } } else if (com=="setMapAuthor") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) setMapAuthor (s); } } else if (com=="setMapComment") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) setMapComment(s); } } else if (com=="setMapBackgroundColor") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! xelection.getBranch() ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) setMapBackgroundColor (c); } } else if (com=="setMapDefLinkColor") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) setMapDefLinkColor (c); } } else if (com=="setMapLinkStyle") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setMapLinkStyle(s); } } else if (com=="setHeading") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setHeading (s); } @@ -795,39 +823,39 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(1)) { - b=api.parBool(ok,0); + b=parser.parBool(ok,0); if (ok) setHideExport (b); } } else if (com=="setURL") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setURLInt(s); } } else if (com=="setVymLink") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setVymLinkInt(s); } } @@ -835,13 +863,13 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) { selb->activateStandardFlag(s); @@ -852,26 +880,26 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { if (!unscrollBranch ()) - api.setError (Aborted,"Could not unscroll branch"); + parser.setError (Aborted,"Could not unscroll branch"); } } else if (com=="unsetFlag") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) { selb->deactivateStandardFlag(s); @@ -879,19 +907,43 @@ } } } else - api.setError (Aborted,"Unknown command"); + parser.setError (Aborted,"Unknown command"); // Any errors? - if (api.errorLevel()==NoError) + if (parser.errorLevel()==NoError) + { setChanged(); + mapCenter->reposition(); + } else { // TODO Error handling qWarning("MapEditor::parseAtom: Error!"); - qWarning(api.errorMessage()); + qWarning(parser.errorMessage()); } } +void MapEditor::runScript (QString script) +{ + // TODO "atomize" script, currently each line holds one atom + + QStringList list=script.split("\n"); + QString l; + int pos; + for (int i=0; i=0) l.truncate (pos); + + // Try to ignore empty lines + if (l.contains (QRegExp ("\\w"))) + parseAtom (l); + } + +} bool MapEditor::isDefault() { @@ -3017,6 +3069,21 @@ } } +FloatImageObj* MapEditor::loadFloatImageInt (QString fn) +{ + BranchObj *bo=xelection.getBranch(); + if (bo) + { + FloatImageObj *fio; + bo->addFloatImage(); + fio=bo->getLastFloatImage(); + fio->load(fn); + mapCenter->reposition(); + scene()->update(); + return fio; + } + return NULL; +} void MapEditor::loadFloatImage () { @@ -3035,34 +3102,28 @@ fd->setDir (lastImageDir); fd->show(); - QString fn; if ( fd->exec() == QDialog::Accepted ) { // FIXME loadFIO in QT4 use: lastImageDir=fd->directory(); lastImageDir=QDir (fd->dirPath()); - QStringList flist = fd->selectedFiles(); - QStringList::Iterator it = flist.begin(); + QString s; FloatImageObj *fio; - while( it != flist.end() ) + for (int j=0; jselectedFiles().count(); j++) { - fn = *it; - bo->addFloatImage(); - fio=bo->getLastFloatImage(); - fio->load(*it); - // FIXME loadFIO check if load of fio was successful - saveState( - (LinkableMapObj*)fio, - "delete ()", - bo, - QString ("loadFloatImage (%1)").arg(*it), - QString("Add floatimage %1 to %2").arg(*it).arg(getName(bo)) - ); - bo->getLastFloatImage()->setOriginalFilename(fn); - ++it; + s=fd->selectedFiles().at(j); + fio=loadFloatImageInt (s); + if (fio) + saveState( + (LinkableMapObj*)fio, + "delete ()", + bo, + QString ("loadImage (%1)").arg(s ), + QString("Add image %1 to %2").arg(s).arg(getName(bo)) + ); + else + // FIXME loadFIO error handling + qWarning ("Failed to load "+s); } - - mapCenter->reposition(); - scene()->update(); } delete (p); delete (fd); @@ -3269,16 +3330,19 @@ { // This is the playground + +/* WarningDialog dia; dia.showCancelButton (true); dia.setText("This is a longer \nWarning"); dia.setCaption("Warning: Flux problem"); - dia.setShowAgainName("/warnings/mapeditor"); + dia.setShowAgainName("mapeditor/testDialog"); if (dia.exec()==QDialog::Accepted) cout << "accepted!\n"; else cout << "canceled!\n"; return; +*/ /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone)