1.1 --- a/vymmodel.cpp Mon Oct 06 11:10:20 2008 +0000
1.2 +++ b/vymmodel.cpp Wed Oct 29 17:42:34 2008 +0000
1.3 @@ -67,16 +67,24 @@
1.4
1.5 void VymModel::clear()
1.6 {
1.7 + cout << "VymModel::clear rows="<<rowCount(index(rootItem))<<endl;
1.8 selection.clear();
1.9
1.10 - while (!mapCenters.isEmpty())
1.11 + // Remove stuff
1.12 + while (!mapCenters.isEmpty()) // FIXME VM needs to be in treemodel only...
1.13 delete mapCenters.takeFirst();
1.14 +
1.15 + QModelIndex ri=index(rootItem);
1.16 + removeRows (0, rowCount(ri),ri);
1.17 }
1.18
1.19 void VymModel::init ()
1.20 {
1.21 // We should have at least one map center to start with
1.22 - // addMapCenter(); FIXME create this in MapEditor as long as model is part of that
1.23 + // addMapCenter(); FIXME VM create this in MapEditor as long as model is part of that
1.24 +
1.25 + // No MapEditor yet
1.26 + mapEditor=NULL;
1.27
1.28 // History
1.29 mapNum++;
1.30 @@ -143,7 +151,7 @@
1.31 netstate=Offline;
1.32
1.33 // Create MapCenter
1.34 - // addMapCenter(); FIXME create this in MapEditor until BO and MCO are independent of scene
1.35 + // addMapCenter(); FIXME VM create this in MapEditor until BO and MCO are independent of scene
1.36
1.37 }
1.38
1.39 @@ -157,7 +165,7 @@
1.40 }
1.41
1.42
1.43 -MapEditor* VymModel::getMapEditor() // FIXME better return favourite editor here
1.44 +MapEditor* VymModel::getMapEditor() // FIXME VM better return favourite editor here
1.45 {
1.46 return mapEditor;
1.47 }
1.48 @@ -329,7 +337,7 @@
1.49 if (lmode==NewMap)
1.50 {
1.51 selection.clear();
1.52 - // FIXME not needed??? model->setMapEditor(this);
1.53 + // FIXME VM not needed??? model->setMapEditor(this);
1.54 // (map state is set later at end of load...)
1.55 } else
1.56 {
1.57 @@ -443,7 +451,7 @@
1.58 file.close();
1.59 if ( ok )
1.60 {
1.61 - reposition(); // FIXME reposition the view instead...
1.62 + reposition(); // FIXME VM reposition the view instead...
1.63 selection.update();
1.64 if (lmode==NewMap)
1.65 {
1.66 @@ -469,7 +477,6 @@
1.67 removeDir (QDir(tmpZipDir));
1.68
1.69 updateActions();
1.70 -
1.71 return err;
1.72 }
1.73
1.74 @@ -688,7 +695,7 @@
1.75 fio=bo->getLastFloatImage();
1.76 fio->load(fn);
1.77 reposition();
1.78 - // FIXME needed? scene()->update();
1.79 + // FIXME VM needed? scene()->update();
1.80 return fio;
1.81 }
1.82 return NULL;
1.83 @@ -869,7 +876,7 @@
1.84 {
1.85 importDirInt (fd->selectedFile() );
1.86 reposition();
1.87 - //FIXME needed? scene()->update();
1.88 + //FIXME VM needed? scene()->update();
1.89 }
1.90 }
1.91 }
1.92 @@ -906,7 +913,7 @@
1.93 QDateTime tmod=QFileInfo (filePath).lastModified();
1.94 if (tmod>fileChangedTime)
1.95 {
1.96 - // FIXME switch to current mapeditor and finish lineedits...
1.97 + // FIXME VM switch to current mapeditor and finish lineedits...
1.98 QMessageBox mb( vymName,
1.99 tr("The file of the map on disk has changed:\n\n"
1.100 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
1.101 @@ -1485,25 +1492,21 @@
1.102 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1.103 sel->setHeading(s );
1.104 TreeItem *ti=selection.getBranchItem();
1.105 - if (ti) ti->setHeading (s);
1.106 - //FIXME ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1.107 - QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1.108 - cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1.109 - QModelIndex ix2=index (ti);
1.110 - emit (dataChanged ( ix2,ix2));
1.111 - cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1.112 -
1.113 - // FIXME playing around with selections:
1.114 - // but somehow not all mco are visible in tree then???
1.115 -// if (mapEditor)
1.116 - if (NULL)
1.117 + if (ti)
1.118 {
1.119 -
1.120 - QItemSelectionModel *selectionModel=mapEditor->selectionModel();
1.121 - selectionModel->clear();
1.122 - QItemSelection sel (ix2,ix2);
1.123 - selectionModel->select (sel, QItemSelectionModel::Select);
1.124 + ti->setHeading (s);
1.125 + //FIXME VM ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1.126 + QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1.127 + //FIXME VM testing only cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1.128 + QModelIndex ix2=index (ti);
1.129 + emit (dataChanged ( ix2,ix2));
1.130 }
1.131 + else
1.132 + {
1.133 + cout << "Warning: VM::setHeading ti==NULL\n";
1.134 + }
1.135 +
1.136 + //cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1.137
1.138 reposition();
1.139 selection.update();
1.140 @@ -1824,7 +1827,7 @@
1.141 updateActions();
1.142 reposition();
1.143 selection.update();
1.144 - // FIXME needed? scene()->update();
1.145 + // FIXME VM needed? scene()->update();
1.146 }
1.147 }
1.148
1.149 @@ -1926,7 +1929,7 @@
1.150 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1.151 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1.152 reposition();
1.153 - //FIXME needed? scene()->update();
1.154 + //FIXME VM needed? scene()->update();
1.155 selection.update();
1.156 ensureSelectionVisible();
1.157 }
1.158 @@ -1943,7 +1946,7 @@
1.159 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1.160 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1.161 reposition();
1.162 - //FIXME needed? scene()->update();
1.163 + //FIXME VM needed? scene()->update();
1.164 selection.update();
1.165 ensureSelectionVisible();
1.166 }
1.167 @@ -1975,7 +1978,7 @@
1.168 BranchObj *bo=selection.getBranch();
1.169 if (bo)
1.170 {
1.171 - BranchObj *newbo=addNewBranchInt (-2); // FIXME Old model, merge with below
1.172 + BranchObj *newbo=addNewBranchInt (-2); // FIXME VM Old model, merge with below
1.173
1.174 // Create TreeItem
1.175 QList<QVariant> cData;
1.176 @@ -1989,7 +1992,7 @@
1.177 if (newbo)
1.178 {
1.179 newbo->setTreeItem (ti);
1.180 - selection.select (newbo);
1.181 + selection.select (newbo); // FIXME VM really needed here?
1.182 }
1.183 }
1.184 }
1.185 @@ -2012,11 +2015,11 @@
1.186
1.187 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
1.188 {
1.189 - MapCenterObj *mapCenter = new MapCenterObj(mapScene);
1.190 + MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
1.191 + mapCenter->setMapEditor(mapEditor); //FIXME VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1.192 mapCenter->move (absPos);
1.193 mapCenter->setVisibility (true);
1.194 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1.195 - mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1.196 mapCenters.append(mapCenter);
1.197
1.198 // Create TreeItem
1.199 @@ -2097,7 +2100,7 @@
1.200
1.201 if (bo)
1.202 {
1.203 - // FIXME do we still need this in model? setCursor (Qt::ArrowCursor);
1.204 + // FIXME VM do we still need this in model? setCursor (Qt::ArrowCursor);
1.205
1.206 newbo=addNewBranchInt (pos-2);
1.207
1.208 @@ -2165,7 +2168,7 @@
1.209 {
1.210 // BranchObj* par=(BranchObj*)(bo->getParObj());
1.211 selection.unselect();
1.212 - /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
1.213 + /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
1.214 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
1.215 */
1.216 bo=removeMapCenter ((MapCenterObj*)bo);
1.217 @@ -2287,7 +2290,7 @@
1.218 );
1.219 bo->toggleScroll();
1.220 selection.update();
1.221 - // FIXME needed? scene()->update();
1.222 + // FIXME VM needed? scene()->update();
1.223 return true;
1.224 }
1.225 return false;
1.226 @@ -2312,7 +2315,7 @@
1.227 );
1.228 bo->toggleScroll();
1.229 selection.update();
1.230 - // FIXME needed? scene()->update();
1.231 + // FIXME VM needed? scene()->update();
1.232 return true;
1.233 }
1.234 return false;
1.235 @@ -2355,7 +2358,7 @@
1.236 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
1.237 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
1.238 reposition();
1.239 - // FIXME needed? scene()->update();
1.240 + // FIXME VM needed? scene()->update();
1.241 }
1.242 }
1.243
1.244 @@ -2540,7 +2543,7 @@
1.245 bo->setVymLink ("" );
1.246 updateActions();
1.247 reposition();
1.248 - // FIXME needed? scene()->update();
1.249 + // FIXME VM needed? scene()->update();
1.250 }
1.251 }
1.252
1.253 @@ -2585,7 +2588,7 @@
1.254 }
1.255 }
1.256
1.257 -void VymModel::editXLink(int i) // FIXME missing saveState
1.258 +void VymModel::editXLink(int i) // FIXME VM missing saveState
1.259 {
1.260 BranchObj *bo=selection.getBranch();
1.261 if (bo)
1.262 @@ -3867,14 +3870,24 @@
1.263 void VymModel::setMapLinkStyle (const QString & s)
1.264 {
1.265 QString snow;
1.266 - if (linkstyle==LinkableMapObj::Line)
1.267 - snow="StyleLine";
1.268 - else if (linkstyle==LinkableMapObj::Parabel)
1.269 - snow="StyleParabel";
1.270 - else if (linkstyle==LinkableMapObj::PolyLine)
1.271 - snow="StylePolyLine";
1.272 - else if (linkstyle==LinkableMapObj::PolyParabel)
1.273 - snow="StyleParabel";
1.274 + switch (linkstyle)
1.275 + {
1.276 + case LinkableMapObj::Line :
1.277 + snow="StyleLine";
1.278 + break;
1.279 + case LinkableMapObj::Parabel:
1.280 + snow="StyleParabel";
1.281 + break;
1.282 + case LinkableMapObj::PolyLine:
1.283 + snow="StylePolyLine";
1.284 + break;
1.285 + case LinkableMapObj::PolyParabel:
1.286 + snow="StylePolyParabel";
1.287 + break;
1.288 + default:
1.289 + snow="UndefinedStyle";
1.290 + break;
1.291 + }
1.292
1.293 saveState (
1.294 QString("setMapLinkStyle (\"%1\")").arg(s),
1.295 @@ -3888,8 +3901,10 @@
1.296 linkstyle=LinkableMapObj::Parabel;
1.297 else if (s=="StylePolyLine")
1.298 linkstyle=LinkableMapObj::PolyLine;
1.299 - else
1.300 + else if (s=="StylePolyParabel")
1.301 linkstyle=LinkableMapObj::PolyParabel;
1.302 + else
1.303 + linkstyle=LinkableMapObj::UndefinedStyle;
1.304
1.305 BranchObj *bo;
1.306 bo=first();
1.307 @@ -4341,6 +4356,11 @@
1.308 // Selection related
1.309 //////////////////////////////////////////////
1.310
1.311 +void VymModel::setSelectionModel (QItemSelectionModel *sm)
1.312 +{
1.313 + selModel=sm;
1.314 +}
1.315 +
1.316 void VymModel::setSelectionBlocked (bool b)
1.317 {
1.318 if (b)
1.319 @@ -4354,6 +4374,14 @@
1.320 return selection.isBlocked();
1.321 }
1.322
1.323 +bool VymModel::select ()
1.324 +{
1.325 + QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
1.326 +
1.327 + TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
1.328 + return select (item->getLMO() );
1.329 +}
1.330 +
1.331 bool VymModel::select (const QString &s)
1.332 {
1.333 if (selection.select(s))