1.1 --- a/vymmodel.cpp Fri Oct 02 14:31:03 2009 +0000
1.2 +++ b/vymmodel.cpp Fri Nov 13 08:32:03 2009 +0000
1.3 @@ -70,9 +70,8 @@
1.4 void VymModel::clear()
1.5 {
1.6 selModel->clearSelection();
1.7 -
1.8 - //QModelIndex ri=index(rootItem);
1.9 - //removeRows (0, rowCount(ri),ri); // FIXME-3 here should be at least a beginRemoveRows...
1.10 + while (rootItem->childCount() >0)
1.11 + deleteItem (rootItem->getChildNum(0) );
1.12 }
1.13
1.14 void VymModel::init ()
1.15 @@ -149,12 +148,10 @@
1.16 // Create MapCenter
1.17 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
1.18
1.19 - //Initialize DBUS
1.20 + //Initialize DBUS object
1.21 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
1.22 - //adaptor->setModel (this);
1.23 - //connection.registerObject("/Car", car);
1.24 - dbusConnection.registerService("org.insilmaril.VymModel");
1.25 - dbusConnection.sessionBus().registerObject ("/Object1",this);
1.26 + if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
1.27 + qWarning ("VymModel: Couldn't register DBUS object!");
1.28 }
1.29
1.30 void VymModel::makeTmpDirectories()
1.31 @@ -1076,7 +1073,9 @@
1.32 select (redoSelection);
1.33
1.34
1.35 - parseAtom (redoCommand);
1.36 + bool noErr;
1.37 + QString errMsg;
1.38 + parseAtom (redoCommand,noErr,errMsg);
1.39
1.40 blockSaveState=blockSaveStateOrg;
1.41
1.42 @@ -1154,7 +1153,10 @@
1.43 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1.44 cout << " ---------------------------"<<endl<<endl;
1.45 }
1.46 - parseAtom (undoCommand);
1.47 +
1.48 + bool noErr;
1.49 + QString errMsg;
1.50 + parseAtom (redoCommand,noErr,errMsg);
1.51
1.52 undosAvail--;
1.53 curStep--;
1.54 @@ -1441,11 +1443,11 @@
1.55 {
1.56 BranchItem *cur=NULL;
1.57 BranchItem *prev=NULL;
1.58 - next(cur,prev);
1.59 + nextBranch(cur,prev);
1.60 while (cur)
1.61 {
1.62 if (s==cur->getID() ) return cur;
1.63 - next(cur,prev);
1.64 + nextBranch(cur,prev);
1.65 }
1.66 return NULL;
1.67 }
1.68 @@ -1498,11 +1500,11 @@
1.69 int c=0;
1.70 BranchItem *cur=NULL;
1.71 BranchItem *prev=NULL;
1.72 - next(cur,prev);
1.73 + nextBranch(cur,prev);
1.74 while (cur)
1.75 {
1.76 c++;
1.77 - next(cur,prev);
1.78 + nextBranch(cur,prev);
1.79 }
1.80 return c;
1.81 }
1.82 @@ -1545,6 +1547,25 @@
1.83 return QString();
1.84 }
1.85
1.86 +void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here)
1.87 +{
1.88 + TreeItem *selti=getSelectedItem();
1.89 + if (selti)
1.90 + {
1.91 + selti->setNote(s);
1.92 + emitNoteHasChanged(selti);
1.93 + }
1.94 +}
1.95 +
1.96 +QString VymModel::getNote()
1.97 +{
1.98 + TreeItem *selti=getSelectedItem();
1.99 + if (selti)
1.100 + return selti->getNote();
1.101 + else
1.102 + return QString();
1.103 +}
1.104 +
1.105 BranchItem* VymModel::findText (QString s, bool cs)
1.106 {
1.107 QTextDocument::FindFlags flags=0;
1.108 @@ -1557,7 +1578,7 @@
1.109 EOFind=false;
1.110 findCurrent=NULL;
1.111 findPrevious=NULL;
1.112 - next (findCurrent,findPrevious);
1.113 + nextBranch (findCurrent,findPrevious);
1.114 }
1.115 bool searching=true;
1.116 bool foundNote=false;
1.117 @@ -1591,7 +1612,7 @@
1.118 }
1.119 if (!foundNote)
1.120 {
1.121 - if (!next(findCurrent,findPrevious) )
1.122 + if (!nextBranch(findCurrent,findPrevious) )
1.123 EOFind=true;
1.124 }
1.125 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1.126 @@ -1652,7 +1673,7 @@
1.127 while (cur)
1.128 {
1.129 if (!cur->getURL().isEmpty()) urls.append( cur->getURL());
1.130 - cur=next (cur,prev,selbi);
1.131 + cur=nextBranch (cur,prev,true,selbi);
1.132 }
1.133 return urls;
1.134 }
1.135 @@ -1852,6 +1873,23 @@
1.136 setHideExport ( !selti->hideInExport() );
1.137 }
1.138
1.139 +void VymModel::addTimestamp() //FIXME-3 new function, localize
1.140 +{
1.141 + BranchItem *selbi=addNewBranch();
1.142 + if (selbi)
1.143 + {
1.144 + QDate today=QDate::currentDate();
1.145 + QChar c='0';
1.146 + selbi->setHeading (QString ("%1-%2-%3")
1.147 + .arg(today.year(),4,10,c)
1.148 + .arg(today.month(),2,10,c)
1.149 + .arg(today.day(),2,10,c));
1.150 + emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1.151 + reposition();
1.152 + select (selbi);
1.153 + }
1.154 +}
1.155 +
1.156
1.157 void VymModel::copy()
1.158 {
1.159 @@ -2283,6 +2321,8 @@
1.160 {
1.161 if (branch && dst)
1.162 {
1.163 + unselect();
1.164 +
1.165 emit (layoutAboutToBeChanged() );
1.166 BranchItem *branchpi=(BranchItem*)branch->parent();
1.167 // Remove at current position
1.168 @@ -2365,7 +2405,7 @@
1.169 BranchItem *selbi=getSelectedBranch();
1.170
1.171 if (selbi)
1.172 - {
1.173 + { // Delete branch
1.174 unselect();
1.175 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
1.176
1.177 @@ -2379,7 +2419,7 @@
1.178 }
1.179 TreeItem *ti=getSelectedItem();
1.180 if (ti)
1.181 - {
1.182 + { // Delete other item
1.183 TreeItem *pi=ti->parent();
1.184 if (!pi) return;
1.185 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
1.186 @@ -2614,18 +2654,28 @@
1.187 cur->toggleScroll();
1.188 emitDataHasChanged (cur);
1.189 }
1.190 - cur=next (cur,prev,selbi);
1.191 + cur=nextBranch (cur,prev,true,selbi);
1.192 }
1.193 updateActions();
1.194 reposition();
1.195 }
1.196 }
1.197
1.198 -void VymModel::emitExpandAll()
1.199 +void VymModel::emitExpandAll()
1.200 {
1.201 emit (expandAll() );
1.202 }
1.203
1.204 +void VymModel::emitExpandOneLevel()
1.205 +{
1.206 + emit (expandOneLevel () );
1.207 +}
1.208 +
1.209 +void VymModel::emitCollapseOneLevel()
1.210 +{
1.211 + emit (collapseOneLevel () );
1.212 +}
1.213 +
1.214 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
1.215 {
1.216 BranchItem *bi=getSelectedBranch();
1.217 @@ -2673,7 +2723,6 @@
1.218
1.219 void VymModel::colorBranch (QColor c)
1.220 {
1.221 -cout << "VM::colBranch\n";
1.222 BranchItem *selbi=getSelectedBranch();
1.223 if (selbi)
1.224 {
1.225 @@ -2705,7 +2754,7 @@
1.226 while (cur)
1.227 {
1.228 cur->setHeadingColor(c); // color links, color children
1.229 - cur=next (cur,prev,selbi);
1.230 + cur=nextBranch (cur,prev,true,selbi);
1.231 }
1.232 mapScene->update();
1.233 }
1.234 @@ -2883,7 +2932,7 @@
1.235 while (cur)
1.236 {
1.237 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
1.238 - cur=next (cur,prev,selbi);
1.239 + cur=nextBranch (cur,prev,true,selbi);
1.240 }
1.241 return links;
1.242 }
1.243 @@ -2933,7 +2982,7 @@
1.244 // Scripting
1.245 //////////////////////////////////////////////
1.246
1.247 -void VymModel::parseAtom(const QString &atom)
1.248 +QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
1.249 {
1.250 TreeItem* selti=getSelectedItem();
1.251 BranchItem *selbi=getSelectedBranch();
1.252 @@ -2941,6 +2990,7 @@
1.253 double x,y;
1.254 int n;
1.255 bool b,ok;
1.256 + QVariant returnValue;
1.257
1.258 // Split string s into command and parameters
1.259 parser.parseAtom (atom);
1.260 @@ -3248,6 +3298,14 @@
1.261 exportXML (fname,false);
1.262 }
1.263 /////////////////////////////////////////////////////////////////////
1.264 + } else if (com=="getHeading")
1.265 + {
1.266 + if (!selti)
1.267 + {
1.268 + parser.setError (Aborted,"Nothing selected");
1.269 + } else if (parser.checkParCount(0))
1.270 + returnValue=selti->getHeading();
1.271 + /////////////////////////////////////////////////////////////////////
1.272 } else if (com=="importDir")
1.273 {
1.274 if (!selti)
1.275 @@ -3567,6 +3625,21 @@
1.276 parser.setError (Aborted,"Could not select latest added object ");
1.277 }
1.278 /////////////////////////////////////////////////////////////////////
1.279 + } else if (com=="setFlag")
1.280 + {
1.281 + if (!selti )
1.282 + {
1.283 + parser.setError (Aborted,"Nothing selected");
1.284 + } else if (! selbi )
1.285 + {
1.286 + parser.setError (Aborted,"Type of selection is not a branch");
1.287 + } else if (parser.checkParCount(1))
1.288 + {
1.289 + s=parser.parString(ok,0);
1.290 + if (ok)
1.291 + selbi->activateStandardFlag(s);
1.292 + }
1.293 + /////////////////////////////////////////////////////////////////////
1.294 } else if (com=="setFrameType")
1.295 {
1.296 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
1.297 @@ -3627,57 +3700,22 @@
1.298 if (ok) setFrameBorderWidth (n);
1.299 }
1.300 /////////////////////////////////////////////////////////////////////
1.301 - } else if (com=="setMapAuthor")
1.302 - {
1.303 - if (parser.checkParCount(1))
1.304 - {
1.305 - s=parser.parString(ok,0);
1.306 - if (ok) setAuthor (s);
1.307 - }
1.308 - /////////////////////////////////////////////////////////////////////
1.309 - } else if (com=="setMapComment")
1.310 - {
1.311 - if (parser.checkParCount(1))
1.312 - {
1.313 - s=parser.parString(ok,0);
1.314 - if (ok) setComment(s);
1.315 - }
1.316 - /////////////////////////////////////////////////////////////////////
1.317 - } else if (com=="setMapBackgroundColor")
1.318 + /* FIXME-2 else if (com=="setFrameType")
1.319 {
1.320 if (!selti )
1.321 {
1.322 parser.setError (Aborted,"Nothing selected");
1.323 - } else if (! selbi )
1.324 + } else if (! selb )
1.325 {
1.326 parser.setError (Aborted,"Type of selection is not a branch");
1.327 } else if (parser.checkParCount(1))
1.328 {
1.329 - QColor c=parser.parColor (ok,0);
1.330 - if (ok) setMapBackgroundColor (c);
1.331 - }
1.332 + s=parser.parString(ok,0);
1.333 + if (ok)
1.334 + setFrameType (s);
1.335 + }
1.336 /////////////////////////////////////////////////////////////////////
1.337 - } else if (com=="setMapDefLinkColor")
1.338 - {
1.339 - if (!selti )
1.340 - {
1.341 - parser.setError (Aborted,"Nothing selected");
1.342 - } else if (! selbi )
1.343 - {
1.344 - parser.setError (Aborted,"Type of selection is not a branch");
1.345 - } else if (parser.checkParCount(1))
1.346 - {
1.347 - QColor c=parser.parColor (ok,0);
1.348 - if (ok) setMapDefLinkColor (c);
1.349 - }
1.350 - /////////////////////////////////////////////////////////////////////
1.351 - } else if (com=="setMapLinkStyle")
1.352 - {
1.353 - if (parser.checkParCount(1))
1.354 - {
1.355 - s=parser.parString (ok,0);
1.356 - if (ok) setMapLinkStyle(s);
1.357 - }
1.358 + } else*/
1.359 /////////////////////////////////////////////////////////////////////
1.360 } else if (com=="setHeading")
1.361 {
1.362 @@ -3750,6 +3788,73 @@
1.363 if (ok) setHideLinkUnselected(b);
1.364 }
1.365 /////////////////////////////////////////////////////////////////////
1.366 + } else if (com=="setMapAuthor")
1.367 + {
1.368 + if (parser.checkParCount(1))
1.369 + {
1.370 + s=parser.parString(ok,0);
1.371 + if (ok) setAuthor (s);
1.372 + }
1.373 + /////////////////////////////////////////////////////////////////////
1.374 + } else if (com=="setMapComment")
1.375 + {
1.376 + if (parser.checkParCount(1))
1.377 + {
1.378 + s=parser.parString(ok,0);
1.379 + if (ok) setComment(s);
1.380 + }
1.381 + /////////////////////////////////////////////////////////////////////
1.382 + } else if (com=="setMapBackgroundColor")
1.383 + {
1.384 + if (!selti )
1.385 + {
1.386 + parser.setError (Aborted,"Nothing selected");
1.387 + } else if (! selbi )
1.388 + {
1.389 + parser.setError (Aborted,"Type of selection is not a branch");
1.390 + } else if (parser.checkParCount(1))
1.391 + {
1.392 + QColor c=parser.parColor (ok,0);
1.393 + if (ok) setMapBackgroundColor (c);
1.394 + }
1.395 + /////////////////////////////////////////////////////////////////////
1.396 + } else if (com=="setMapDefLinkColor")
1.397 + {
1.398 + if (!selti )
1.399 + {
1.400 + parser.setError (Aborted,"Nothing selected");
1.401 + } else if (! selbi )
1.402 + {
1.403 + parser.setError (Aborted,"Type of selection is not a branch");
1.404 + } else if (parser.checkParCount(1))
1.405 + {
1.406 + QColor c=parser.parColor (ok,0);
1.407 + if (ok) setMapDefLinkColor (c);
1.408 + }
1.409 + /////////////////////////////////////////////////////////////////////
1.410 + } else if (com=="setMapLinkStyle")
1.411 + {
1.412 + if (parser.checkParCount(1))
1.413 + {
1.414 + s=parser.parString (ok,0);
1.415 + if (ok) setMapLinkStyle(s);
1.416 + }
1.417 + /////////////////////////////////////////////////////////////////////
1.418 + } else if (com=="setNote")
1.419 + {
1.420 + if (!selti )
1.421 + {
1.422 + parser.setError (Aborted,"Nothing selected");
1.423 + } else if (! selbi )
1.424 + {
1.425 + parser.setError (Aborted,"Type of selection is not a branch");
1.426 + } else if (parser.checkParCount(1))
1.427 + {
1.428 + s=parser.parString (ok,0);
1.429 + if (ok)
1.430 + setNote (s);
1.431 + }
1.432 + /////////////////////////////////////////////////////////////////////
1.433 } else if (com=="setSelectionColor")
1.434 {
1.435 if (parser.checkParCount(1))
1.436 @@ -3785,39 +3890,7 @@
1.437 s=parser.parString (ok,0);
1.438 if (ok) setVymLink(s);
1.439 }
1.440 - }
1.441 - /////////////////////////////////////////////////////////////////////
1.442 - else if (com=="setFlag")
1.443 - {
1.444 - if (!selti )
1.445 - {
1.446 - parser.setError (Aborted,"Nothing selected");
1.447 - } else if (! selbi )
1.448 - {
1.449 - parser.setError (Aborted,"Type of selection is not a branch");
1.450 - } else if (parser.checkParCount(1))
1.451 - {
1.452 - s=parser.parString(ok,0);
1.453 - if (ok)
1.454 - selbi->activateStandardFlag(s);
1.455 - }
1.456 - /////////////////////////////////////////////////////////////////////
1.457 - } else /* FIXME-2 if (com=="setFrameType")
1.458 - {
1.459 - if (!selti )
1.460 - {
1.461 - parser.setError (Aborted,"Nothing selected");
1.462 - } else if (! selb )
1.463 - {
1.464 - parser.setError (Aborted,"Type of selection is not a branch");
1.465 - } else if (parser.checkParCount(1))
1.466 - {
1.467 - s=parser.parString(ok,0);
1.468 - if (ok)
1.469 - setFrameType (s);
1.470 - }
1.471 - /////////////////////////////////////////////////////////////////////
1.472 - } else*/ if (com=="sortChildren")
1.473 + } else if (com=="sortChildren")
1.474 {
1.475 if (!selti )
1.476 {
1.477 @@ -3894,21 +3967,34 @@
1.478 {
1.479 // setChanged(); FIXME-2 should not be called e.g. for export?!
1.480 reposition();
1.481 + errorMsg.clear();
1.482 + noErr=true;
1.483 }
1.484 else
1.485 {
1.486 // TODO Error handling
1.487 qWarning("VymModel::parseAtom: Error!");
1.488 +
1.489 qWarning(parser.errorMessage());
1.490 + noErr=false;
1.491 + errorMsg=parser.errorMessage();
1.492 }
1.493 + return returnValue;
1.494 }
1.495
1.496 void VymModel::runScript (QString script)
1.497 {
1.498 parser.setScript (script);
1.499 parser.runScript();
1.500 - while (parser.next() )
1.501 - parseAtom(parser.getAtom());
1.502 + QVariant r;
1.503 + bool noErr=true;
1.504 + QString errMsg;
1.505 + while (parser.next() && noErr)
1.506 + {
1.507 + r=parseAtom(parser.getAtom(),noErr,errMsg);
1.508 + if (!noErr) //FIXME-3 need dialog box here
1.509 + cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
1.510 + }
1.511 }
1.512
1.513 void VymModel::setExportMode (bool b)
1.514 @@ -4166,12 +4252,12 @@
1.515 BranchItem *cur=NULL;
1.516 BranchItem *prev=NULL;
1.517 BranchObj *bo;
1.518 - next (cur,prev);
1.519 + nextBranch (cur,prev);
1.520 while (cur)
1.521 {
1.522 bo=(BranchObj*)(cur->getLMO() );
1.523 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
1.524 - cur=next(cur,prev);
1.525 + cur=nextBranch(cur,prev);
1.526 }
1.527 reposition();
1.528 }
1.529 @@ -4194,12 +4280,12 @@
1.530 BranchItem *cur=NULL;
1.531 BranchItem *prev=NULL;
1.532 BranchObj *bo;
1.533 - cur=next(cur,prev);
1.534 + cur=nextBranch(cur,prev);
1.535 while (cur)
1.536 {
1.537 bo=(BranchObj*)(cur->getLMO() );
1.538 bo->setLinkColor();
1.539 - next(cur,prev);
1.540 + nextBranch(cur,prev);
1.541 }
1.542 updateActions();
1.543 }
1.544 @@ -4210,12 +4296,12 @@
1.545 BranchItem *cur=NULL;
1.546 BranchItem *prev=NULL;
1.547 BranchObj *bo;
1.548 - cur=next(cur,prev);
1.549 + cur=nextBranch(cur,prev);
1.550 while (cur)
1.551 {
1.552 bo=(BranchObj*)(cur->getLMO() );
1.553 bo->setLinkColor();
1.554 - cur=next(cur,prev);
1.555 + cur=nextBranch(cur,prev);
1.556 }
1.557 }
1.558
1.559 @@ -4234,12 +4320,12 @@
1.560 BranchItem *cur=NULL;
1.561 BranchItem *prev=NULL;
1.562 BranchObj *bo;
1.563 - cur=next(cur,prev);
1.564 + cur=nextBranch(cur,prev);
1.565 while (cur)
1.566 {
1.567 bo=(BranchObj*)(cur->getLMO() );
1.568 bo->setLinkColor();
1.569 - next(cur,prev);
1.570 + nextBranch(cur,prev);
1.571 }
1.572 }
1.573
1.574 @@ -4544,8 +4630,11 @@
1.575 QString t;
1.576 in >>t;
1.577 if (debug)
1.578 - cout << " t="<<qPrintable (t)<<endl;
1.579 - parseAtom (t);
1.580 + cout << "VymModel::readData command="<<qPrintable (t)<<endl;
1.581 + bool noErr;
1.582 + QString errMsg;
1.583 + parseAtom (t,noErr,errMsg);
1.584 +
1.585 }
1.586 return;
1.587 }
1.588 @@ -4717,8 +4806,11 @@
1.589
1.590 void VymModel::unselect()
1.591 {
1.592 - lastSelectString=getSelectString();
1.593 - selModel->clearSelection();
1.594 + if (!selModel->selectedIndexes().isEmpty())
1.595 + {
1.596 + lastSelectString=getSelectString();
1.597 + selModel->clearSelection();
1.598 + }
1.599 }
1.600
1.601 bool VymModel::reselect()