diff -r 338ebdc9b947 -r 14f2b1b15242 vymmodel.cpp --- a/vymmodel.cpp Fri Oct 02 14:31:03 2009 +0000 +++ b/vymmodel.cpp Fri Nov 13 08:32:03 2009 +0000 @@ -70,9 +70,8 @@ void VymModel::clear() { selModel->clearSelection(); - - //QModelIndex ri=index(rootItem); - //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows... + while (rootItem->childCount() >0) + deleteItem (rootItem->getChildNum(0) ); } void VymModel::init () @@ -149,12 +148,10 @@ // Create MapCenter // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene - //Initialize DBUS + //Initialize DBUS object adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt - //adaptor->setModel (this); - //connection.registerObject("/Car", car); - dbusConnection.registerService("org.insilmaril.VymModel"); - dbusConnection.sessionBus().registerObject ("/Object1",this); + if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this)) + qWarning ("VymModel: Couldn't register DBUS object!"); } void VymModel::makeTmpDirectories() @@ -1076,7 +1073,9 @@ select (redoSelection); - parseAtom (redoCommand); + bool noErr; + QString errMsg; + parseAtom (redoCommand,noErr,errMsg); blockSaveState=blockSaveStateOrg; @@ -1154,7 +1153,10 @@ cout << " redoSel="<getID() ) return cur; - next(cur,prev); + nextBranch(cur,prev); } return NULL; } @@ -1498,11 +1500,11 @@ int c=0; BranchItem *cur=NULL; BranchItem *prev=NULL; - next(cur,prev); + nextBranch(cur,prev); while (cur) { c++; - next(cur,prev); + nextBranch(cur,prev); } return c; } @@ -1545,6 +1547,25 @@ return QString(); } +void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here) +{ + TreeItem *selti=getSelectedItem(); + if (selti) + { + selti->setNote(s); + emitNoteHasChanged(selti); + } +} + +QString VymModel::getNote() +{ + TreeItem *selti=getSelectedItem(); + if (selti) + return selti->getNote(); + else + return QString(); +} + BranchItem* VymModel::findText (QString s, bool cs) { QTextDocument::FindFlags flags=0; @@ -1557,7 +1578,7 @@ EOFind=false; findCurrent=NULL; findPrevious=NULL; - next (findCurrent,findPrevious); + nextBranch (findCurrent,findPrevious); } bool searching=true; bool foundNote=false; @@ -1591,7 +1612,7 @@ } if (!foundNote) { - if (!next(findCurrent,findPrevious) ) + if (!nextBranch(findCurrent,findPrevious) ) EOFind=true; } //cout <<"still searching... "<getHeading())<getURL().isEmpty()) urls.append( cur->getURL()); - cur=next (cur,prev,selbi); + cur=nextBranch (cur,prev,true,selbi); } return urls; } @@ -1852,6 +1873,23 @@ setHideExport ( !selti->hideInExport() ); } +void VymModel::addTimestamp() //FIXME-3 new function, localize +{ + BranchItem *selbi=addNewBranch(); + if (selbi) + { + QDate today=QDate::currentDate(); + QChar c='0'; + selbi->setHeading (QString ("%1-%2-%3") + .arg(today.year(),4,10,c) + .arg(today.month(),2,10,c) + .arg(today.day(),2,10,c)); + emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem? + reposition(); + select (selbi); + } +} + void VymModel::copy() { @@ -2283,6 +2321,8 @@ { if (branch && dst) { + unselect(); + emit (layoutAboutToBeChanged() ); BranchItem *branchpi=(BranchItem*)branch->parent(); // Remove at current position @@ -2365,7 +2405,7 @@ BranchItem *selbi=getSelectedBranch(); if (selbi) - { + { // Delete branch unselect(); saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi))); @@ -2379,7 +2419,7 @@ } TreeItem *ti=getSelectedItem(); if (ti) - { + { // Delete other item TreeItem *pi=ti->parent(); if (!pi) return; if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute) @@ -2614,18 +2654,28 @@ cur->toggleScroll(); emitDataHasChanged (cur); } - cur=next (cur,prev,selbi); + cur=nextBranch (cur,prev,true,selbi); } updateActions(); reposition(); } } -void VymModel::emitExpandAll() +void VymModel::emitExpandAll() { emit (expandAll() ); } +void VymModel::emitExpandOneLevel() +{ + emit (expandOneLevel () ); +} + +void VymModel::emitCollapseOneLevel() +{ + emit (collapseOneLevel () ); +} + void VymModel::toggleStandardFlag (const QString &name, FlagRow *master) { BranchItem *bi=getSelectedBranch(); @@ -2673,7 +2723,6 @@ void VymModel::colorBranch (QColor c) { -cout << "VM::colBranch\n"; BranchItem *selbi=getSelectedBranch(); if (selbi) { @@ -2705,7 +2754,7 @@ while (cur) { cur->setHeadingColor(c); // color links, color children - cur=next (cur,prev,selbi); + cur=nextBranch (cur,prev,true,selbi); } mapScene->update(); } @@ -2883,7 +2932,7 @@ while (cur) { if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink()); - cur=next (cur,prev,selbi); + cur=nextBranch (cur,prev,true,selbi); } return links; } @@ -2933,7 +2982,7 @@ // Scripting ////////////////////////////////////////////// -void VymModel::parseAtom(const QString &atom) +QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg) { TreeItem* selti=getSelectedItem(); BranchItem *selbi=getSelectedBranch(); @@ -2941,6 +2990,7 @@ double x,y; int n; bool b,ok; + QVariant returnValue; // Split string s into command and parameters parser.parseAtom (atom); @@ -3248,6 +3298,14 @@ exportXML (fname,false); } ///////////////////////////////////////////////////////////////////// + } else if (com=="getHeading") + { + if (!selti) + { + parser.setError (Aborted,"Nothing selected"); + } else if (parser.checkParCount(0)) + returnValue=selti->getHeading(); + ///////////////////////////////////////////////////////////////////// } else if (com=="importDir") { if (!selti) @@ -3567,6 +3625,21 @@ parser.setError (Aborted,"Could not select latest added object "); } ///////////////////////////////////////////////////////////////////// + } else if (com=="setFlag") + { + if (!selti ) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selbi ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParCount(1)) + { + s=parser.parString(ok,0); + if (ok) + selbi->activateStandardFlag(s); + } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameType") { if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) @@ -3627,57 +3700,22 @@ if (ok) setFrameBorderWidth (n); } ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapAuthor") - { - if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) setAuthor (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapComment") - { - if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) setComment(s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapBackgroundColor") + /* FIXME-2 else if (com=="setFrameType") { if (!selti ) { parser.setError (Aborted,"Nothing selected"); - } else if (! selbi ) + } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(1)) { - QColor c=parser.parColor (ok,0); - if (ok) setMapBackgroundColor (c); - } + s=parser.parString(ok,0); + if (ok) + setFrameType (s); + } ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapDefLinkColor") - { - if (!selti ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selbi ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - QColor c=parser.parColor (ok,0); - if (ok) setMapDefLinkColor (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapLinkStyle") - { - if (parser.checkParCount(1)) - { - s=parser.parString (ok,0); - if (ok) setMapLinkStyle(s); - } + } else*/ ///////////////////////////////////////////////////////////////////// } else if (com=="setHeading") { @@ -3750,6 +3788,73 @@ if (ok) setHideLinkUnselected(b); } ///////////////////////////////////////////////////////////////////// + } else if (com=="setMapAuthor") + { + if (parser.checkParCount(1)) + { + s=parser.parString(ok,0); + if (ok) setAuthor (s); + } + ///////////////////////////////////////////////////////////////////// + } else if (com=="setMapComment") + { + if (parser.checkParCount(1)) + { + s=parser.parString(ok,0); + if (ok) setComment(s); + } + ///////////////////////////////////////////////////////////////////// + } else if (com=="setMapBackgroundColor") + { + if (!selti ) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selbi ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParCount(1)) + { + QColor c=parser.parColor (ok,0); + if (ok) setMapBackgroundColor (c); + } + ///////////////////////////////////////////////////////////////////// + } else if (com=="setMapDefLinkColor") + { + if (!selti ) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selbi ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParCount(1)) + { + QColor c=parser.parColor (ok,0); + if (ok) setMapDefLinkColor (c); + } + ///////////////////////////////////////////////////////////////////// + } else if (com=="setMapLinkStyle") + { + if (parser.checkParCount(1)) + { + s=parser.parString (ok,0); + if (ok) setMapLinkStyle(s); + } + ///////////////////////////////////////////////////////////////////// + } else if (com=="setNote") + { + if (!selti ) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selbi ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParCount(1)) + { + s=parser.parString (ok,0); + if (ok) + setNote (s); + } + ///////////////////////////////////////////////////////////////////// } else if (com=="setSelectionColor") { if (parser.checkParCount(1)) @@ -3785,39 +3890,7 @@ s=parser.parString (ok,0); if (ok) setVymLink(s); } - } - ///////////////////////////////////////////////////////////////////// - else if (com=="setFlag") - { - if (!selti ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selbi ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) - selbi->activateStandardFlag(s); - } - ///////////////////////////////////////////////////////////////////// - } else /* FIXME-2 if (com=="setFrameType") - { - if (!selti ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) - setFrameType (s); - } - ///////////////////////////////////////////////////////////////////// - } else*/ if (com=="sortChildren") + } else if (com=="sortChildren") { if (!selti ) { @@ -3894,21 +3967,34 @@ { // setChanged(); FIXME-2 should not be called e.g. for export?! reposition(); + errorMsg.clear(); + noErr=true; } else { // TODO Error handling qWarning("VymModel::parseAtom: Error!"); + qWarning(parser.errorMessage()); + noErr=false; + errorMsg=parser.errorMessage(); } + return returnValue; } void VymModel::runScript (QString script) { parser.setScript (script); parser.runScript(); - while (parser.next() ) - parseAtom(parser.getAtom()); + QVariant r; + bool noErr=true; + QString errMsg; + while (parser.next() && noErr) + { + r=parseAtom(parser.getAtom(),noErr,errMsg); + if (!noErr) //FIXME-3 need dialog box here + cout << "VM::runScript aborted:\n"<getLMO() ); bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View - cur=next(cur,prev); + cur=nextBranch(cur,prev); } reposition(); } @@ -4194,12 +4280,12 @@ BranchItem *cur=NULL; BranchItem *prev=NULL; BranchObj *bo; - cur=next(cur,prev); + cur=nextBranch(cur,prev); while (cur) { bo=(BranchObj*)(cur->getLMO() ); bo->setLinkColor(); - next(cur,prev); + nextBranch(cur,prev); } updateActions(); } @@ -4210,12 +4296,12 @@ BranchItem *cur=NULL; BranchItem *prev=NULL; BranchObj *bo; - cur=next(cur,prev); + cur=nextBranch(cur,prev); while (cur) { bo=(BranchObj*)(cur->getLMO() ); bo->setLinkColor(); - cur=next(cur,prev); + cur=nextBranch(cur,prev); } } @@ -4234,12 +4320,12 @@ BranchItem *cur=NULL; BranchItem *prev=NULL; BranchObj *bo; - cur=next(cur,prev); + cur=nextBranch(cur,prev); while (cur) { bo=(BranchObj*)(cur->getLMO() ); bo->setLinkColor(); - next(cur,prev); + nextBranch(cur,prev); } } @@ -4544,8 +4630,11 @@ QString t; in >>t; if (debug) - cout << " t="<