1.1 --- a/vymmodel.cpp Tue Mar 31 15:36:10 2009 +0000
1.2 +++ b/vymmodel.cpp Wed Apr 01 15:06:57 2009 +0000
1.3 @@ -3,6 +3,8 @@
1.4
1.5 #include "vymmodel.h"
1.6
1.7 +#include "branchitem.h"
1.8 +#include "mapcenteritem.h"
1.9 #include "editxlinkdialog.h"
1.10 #include "exports.h"
1.11 #include "exportxhtmldialog.h"
1.12 @@ -223,7 +225,7 @@
1.13 mapAttr+= xml.attribut("author",author) +
1.14 xml.attribut("comment",comment) +
1.15 xml.attribut("date",getDate()) +
1.16 - xml.attribut("countBranches", QString().number(countBranches())) +
1.17 + xml.attribut("branchCount", QString().number(branchCount())) +
1.18 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
1.19 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
1.20 xml.attribut("linkStyle", ls ) +
1.21 @@ -830,9 +832,10 @@
1.22 {
1.23 dst->addBranch();
1.24 bo=dst->getLastBranch();
1.25 - bo->setHeading (fi.fileName() );
1.26 + BranchItem *bi=(BranchItem*)(bo->getTreeItem());
1.27 + bi->setHeading (fi.fileName() ); // FIXME-3 check this
1.28 bo->setColor (QColor("blue"));
1.29 - bo->toggleScroll();
1.30 + bi->toggleScroll();
1.31 if ( !d.cd(fi.fileName()) )
1.32 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
1.33 else
1.34 @@ -1318,7 +1321,7 @@
1.35 {
1.36 // save the selected branch of the map, Undo will insert part of map
1.37 saveState (PartOfMap,
1.38 - undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
1.39 + undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->getTreeItem()->num()),
1.40 redoSelection, "delete ()",
1.41 comment,
1.42 redoSel);
1.43 @@ -1464,7 +1467,7 @@
1.44 return QDate::currentDate().toString ("yyyy-MM-dd");
1.45 }
1.46
1.47 -int VymModel::countBranches() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1.48 +int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
1.49 {
1.50 int c=0;
1.51 TreeItem *cur=NULL;
1.52 @@ -1955,12 +1958,13 @@
1.53 }
1.54 }
1.55
1.56 -void VymModel::sortChildren()
1.57 -{
1.58 +void VymModel::sortChildren() // FIXME-1 not implemented yet
1.59 +{
1.60 +/*
1.61 BranchObj* bo=getSelectedBranch();
1.62 if (bo)
1.63 {
1.64 - if(bo->countBranches()>1)
1.65 + if(treeItem->branchCount()>1)
1.66 {
1.67 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1.68 bo->sortChildren();
1.69 @@ -1968,6 +1972,7 @@
1.70 ensureSelectionVisible();
1.71 }
1.72 }
1.73 +*/
1.74 }
1.75
1.76 void VymModel::createMapCenter()
1.77 @@ -2026,33 +2031,35 @@
1.78
1.79 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
1.80 {
1.81 +
1.82 + // Create TreeItem
1.83 + QModelIndex parix=index(rootItem);
1.84 +
1.85 + int n=rootItem->branchCount();
1.86 +
1.87 + emit (layoutAboutToBeChanged() );
1.88 + beginInsertRows (parix,n,n+1);
1.89 +
1.90 + QList<QVariant> cData;
1.91 + cData << "VM:addMapCenter" << "undef"<<"undef";
1.92 + MapCenterItem *ti=new MapCenterItem (cData,rootItem);
1.93 + cout << "VM::addMapCenter ti="<<ti<<endl;
1.94 + ti->setType (TreeItem::MapCenter);
1.95 + rootItem->appendChild (ti);
1.96 +
1.97 + endInsertRows();
1.98 + emit (newChildObject (parix));
1.99 + emit (layoutChanged() );
1.100 +
1.101 + // Create MapObj
1.102 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
1.103 mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1.104 + mapCenter->setTreeItem (ti); // TreeItem needs to exist before setVisibility
1.105 + ti->setLMO (mapCenter);
1.106 mapCenter->move (absPos);
1.107 mapCenter->setVisibility (true);
1.108 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1.109 mapCenters.append(mapCenter);
1.110 -
1.111 - // Create TreeItem
1.112 - QModelIndex parix=index(rootItem);
1.113 -
1.114 - int n=rootItem->branchCount();
1.115 -
1.116 - emit (layoutAboutToBeChanged() );
1.117 - beginInsertRows (parix,n,n+1);
1.118 -
1.119 - QList<QVariant> cData;
1.120 - cData << "VM:addMapCenter" << "undef"<<"undef";
1.121 - TreeItem *ti=new TreeItem (cData,rootItem);
1.122 - ti->setLMO (mapCenter);
1.123 - ti->setType (TreeItem::MapCenter);
1.124 - mapCenter->setTreeItem (ti);
1.125 - rootItem->appendChild (ti);
1.126 -
1.127 - endInsertRows();
1.128 - emit (newChildObject (parix));
1.129 - emit (layoutChanged() );
1.130 -
1.131 // Testing
1.132 /*
1.133 qWarning ("MW::insertRow a");
1.134 @@ -2097,47 +2104,48 @@
1.135 // 0..n insert in children of parent at pos
1.136 BranchObj *newbo=NULL;
1.137 BranchObj *bo=getSelectedBranch();
1.138 + BranchItem *bi=getSelectedBranchItem();
1.139 if (bo)
1.140 {
1.141 if (num==-2)
1.142 {
1.143 + // Create TreeItem
1.144 + QList<QVariant> cData;
1.145 + cData << "new" << "undef"<<"undef";
1.146 +
1.147 + BranchItem *parbi=bi;
1.148 + QModelIndex parix=index(parbi);
1.149 + int n=parbi->branchCount();
1.150 +
1.151 + emit (layoutAboutToBeChanged() );
1.152 + beginInsertRows (parix,n,n+1);
1.153 + bi=new BranchItem (cData,parbi);
1.154 + bi->setType (TreeItem::Branch);
1.155 +
1.156 + parbi->appendChild (bi);
1.157 + endInsertRows ();
1.158 + emit (newChildObject (parix));
1.159 + emit (layoutChanged() );
1.160 +
1.161 // save scroll state. If scrolled, automatically select
1.162 // new branch in order to tmp unscroll parent...
1.163 newbo=bo->addBranch();
1.164
1.165 - // Create TreeItem
1.166 - QList<QVariant> cData;
1.167 - cData << "new" << "undef"<<"undef";
1.168 -
1.169 - TreeItem *parti=bo->getTreeItem();
1.170 - QModelIndex parix=index(parti);
1.171 - int n=parti->branchCount();
1.172 -
1.173 - emit (layoutAboutToBeChanged() );
1.174 - beginInsertRows (parix,n,n+1);
1.175 - TreeItem *ti=new TreeItem (cData,parti);
1.176 - ti->setLMO (newbo);
1.177 - ti->setType (TreeItem::Branch);
1.178 -
1.179 - parti->appendChild (ti);
1.180 - endInsertRows ();
1.181 - emit (newChildObject (parix));
1.182 - emit (layoutChanged() );
1.183 -
1.184 if (newbo)
1.185 {
1.186 - newbo->setTreeItem (ti);
1.187 + bi->setLMO (newbo);
1.188 + newbo->setTreeItem (bi);
1.189 select (newbo); // FIXME-2 VM really needed here?
1.190 }
1.191
1.192 }else if (num==-1)
1.193 {
1.194 - num=bo->getNum()+1;
1.195 + num=bi->num()+1;
1.196 bo=(BranchObj*)bo->getParObj();
1.197 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
1.198 }else if (num==-3)
1.199 {
1.200 - num=bo->getNum();
1.201 + num=bi->num();
1.202 bo=(BranchObj*)bo->getParObj();
1.203 if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
1.204 }
1.205 @@ -2156,7 +2164,7 @@
1.206
1.207 if (bo)
1.208 {
1.209 - // FIXME-1 VM do we still need this in model? setCursor (Qt::ArrowCursor);
1.210 + // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
1.211
1.212 newbo=addNewBranchInt (pos-2);
1.213
1.214 @@ -2198,7 +2206,7 @@
1.215 BranchObj *parbo=(BranchObj*)(bo->getParObj());
1.216
1.217 // add below selection
1.218 - newbo=parbo->insertBranch(bo->getNum()+1); //FIXME-1 VM still missing
1.219 + newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
1.220
1.221 if (newbo)
1.222 {
1.223 @@ -2276,8 +2284,8 @@
1.224 int n=ix.row();
1.225 beginRemoveRows (parentIndex,n,n);
1.226 removeRows (n,1,parentIndex);
1.227 + endRemoveRows();
1.228 par->removeBranch(bo); // remove from BranchObj lists...
1.229 - endRemoveRows();
1.230 select (par);
1.231 ensureSelectionVisible();
1.232 reposition();
1.233 @@ -2285,7 +2293,7 @@
1.234 emit (layoutChanged() );
1.235 return;
1.236 }
1.237 - FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
1.238 + //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
1.239
1.240 /*
1.241 if (fio)
1.242 @@ -2320,7 +2328,7 @@
1.243 if (!par) return;
1.244
1.245 // Check if we have childs at all to keep
1.246 - if (bo->countBranches()==0)
1.247 + if (bo->getTreeItem()->branchCount()==0)
1.248 {
1.249 deleteSelection();
1.250 return;
1.251 @@ -2362,16 +2370,17 @@
1.252 }
1.253
1.254
1.255 -bool VymModel::scrollBranch(BranchObj *bo)
1.256 -{
1.257 - if (bo)
1.258 +bool VymModel::scrollBranch(BranchItem *bi)
1.259 +{
1.260 + if (bi)
1.261 {
1.262 - if (bo->isScrolled()) return false;
1.263 - if (bo->countBranches()==0) return false;
1.264 - if (bo->getDepth()==0) return false;
1.265 + if (bi->isScrolled()) return false;
1.266 + if (bi->branchCount()==0) return false;
1.267 + if (bi->depth()==0) return false;
1.268 QString u,r;
1.269 r="scroll";
1.270 u="unscroll";
1.271 + /* FIXME-1 no savestate yet
1.272 saveState(
1.273 bo,
1.274 QString ("%1 ()").arg(u),
1.275 @@ -2379,24 +2388,27 @@
1.276 QString ("%1 ()").arg(r),
1.277 QString ("%1 %2").arg(r).arg(getObjectName(bo))
1.278 );
1.279 - bo->toggleScroll();
1.280 - selection.update();
1.281 + */
1.282 + bi->toggleScroll();
1.283 + //selection.update();
1.284 // FIXME-3 VM needed? scene()->update();
1.285 return true;
1.286 }
1.287 return false;
1.288 }
1.289
1.290 -bool VymModel::unscrollBranch(BranchObj *bo)
1.291 -{
1.292 - if (bo)
1.293 +bool VymModel::unscrollBranch(BranchItem *bi)
1.294 +{
1.295 + if (bi)
1.296 {
1.297 - if (!bo->isScrolled()) return false;
1.298 - if (bo->countBranches()==0) return false;
1.299 - if (bo->getDepth()==0) return false;
1.300 + if (bi->isScrolled()) return false;
1.301 + if (bi->branchCount()==0) return false;
1.302 + if (bi->depth()==0) return false;
1.303 +
1.304 QString u,r;
1.305 u="scroll";
1.306 r="unscroll";
1.307 + /* FIXME-1 no savestate yet
1.308 saveState(
1.309 bo,
1.310 QString ("%1 ()").arg(u),
1.311 @@ -2404,8 +2416,9 @@
1.312 QString ("%1 ()").arg(r),
1.313 QString ("%1 %2").arg(r).arg(getObjectName(bo))
1.314 );
1.315 - bo->toggleScroll();
1.316 - selection.update();
1.317 + */
1.318 + bi->toggleScroll();
1.319 + // selection.update();
1.320 // FIXME-3 VM needed? scene()->update();
1.321 return true;
1.322 }
1.323 @@ -2414,13 +2427,13 @@
1.324
1.325 void VymModel::toggleScroll()
1.326 {
1.327 - BranchObj *bo=getSelectedBranch();
1.328 - if (selectionType()==TreeItem::Branch )
1.329 + BranchItem *bi=(BranchItem*)getSelectedBranchItem();
1.330 + if (bi && bi->getType()==TreeItem::Branch )
1.331 {
1.332 - if (bo->isScrolled())
1.333 - unscrollBranch (bo);
1.334 + if (bi->isScrolled())
1.335 + unscrollBranch (bi);
1.336 else
1.337 - scrollBranch (bo);
1.338 + scrollBranch (bi);
1.339 }
1.340 }
1.341
1.342 @@ -2722,6 +2735,7 @@
1.343 void VymModel::parseAtom(const QString &atom)
1.344 {
1.345 BranchObj *selb=getSelectedBranch();
1.346 + BranchItem *bi=getSelectedBranchItem();
1.347 QString s,t;
1.348 double x,y;
1.349 int n;
1.350 @@ -3260,7 +3274,7 @@
1.351 parser.setError (Aborted,"Type of selection is not a branch");
1.352 } else if (parser.checkParCount(0))
1.353 {
1.354 - if (!scrollBranch (selb))
1.355 + if (!scrollBranch (bi))
1.356 parser.setError (Aborted,"Could not scroll branch");
1.357 }
1.358 /////////////////////////////////////////////////////////////////////
1.359 @@ -3611,7 +3625,7 @@
1.360 parser.setError (Aborted,"Type of selection is not a branch");
1.361 } else if (parser.checkParCount(0))
1.362 {
1.363 - if (!unscrollBranch (selb))
1.364 + if (!unscrollBranch (bi))
1.365 parser.setError (Aborted,"Could not unscroll branch");
1.366 }
1.367 /////////////////////////////////////////////////////////////////////
1.368 @@ -4669,7 +4683,7 @@
1.369 b=select (s);
1.370 if (b)
1.371 {
1.372 - if ( getSelectedBranch()->countBranches()>0)
1.373 + if ( getSelectedItem()->branchCount()>0)
1.374 s+=",bo:0";
1.375 else
1.376 break;
1.377 @@ -4749,8 +4763,8 @@
1.378 {
1.379 b=select (s);
1.380 if (b)
1.381 - if ( getSelectedBranch()->countBranches()>0)
1.382 - s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 );
1.383 + if ( getSelectedItem()->branchCount()>0)
1.384 + s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 );
1.385 else
1.386 break;
1.387 else
1.388 @@ -4974,7 +4988,7 @@
1.389 return NULL;
1.390 }
1.391
1.392 -TreeItem* VymModel::getSelectedBranchItem()
1.393 +BranchItem* VymModel::getSelectedBranchItem()
1.394 {
1.395 QModelIndexList list=selModel->selectedIndexes();
1.396 if (!list.isEmpty() )
1.397 @@ -4982,7 +4996,7 @@
1.398 TreeItem *ti = getItem (list.first() );
1.399 TreeItem::Type type=ti->getType();
1.400 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
1.401 - return ti;
1.402 + return (BranchItem*)ti;
1.403 }
1.404 return NULL;
1.405 }
1.406 @@ -5019,26 +5033,32 @@
1.407 return QString();
1.408 }
1.409
1.410 -QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel
1.411 +QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
1.412 +{
1.413 + if (!lmo) return QString();
1.414 + return getSelectString (lmo->getTreeItem() );
1.415 +}
1.416 +
1.417 +QString VymModel::getSelectString (TreeItem *ti)
1.418 {
1.419 QString s;
1.420 - if (!lmo) return s;
1.421 - if (typeid(*lmo)==typeid(BranchObj) ||
1.422 - typeid(*lmo)==typeid(MapCenterObj) )
1.423 + if (!ti) return s;
1.424 + if (ti->getType() == TreeItem::Branch ||
1.425 + ti->getType() == TreeItem::MapCenter)
1.426 {
1.427 - LinkableMapObj *par=lmo->getParObj();
1.428 + TreeItem *par=ti->parent();
1.429 if (par)
1.430 {
1.431 - if (lmo->getDepth() ==1)
1.432 + if (ti->depth() ==1)
1.433 // Mainbranch, return
1.434 - s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
1.435 + s= "bo:" + QString("%1").arg(ti->num() );
1.436 else
1.437 // Branch, call myself recursively
1.438 - s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
1.439 + s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
1.440 } else
1.441 {
1.442 // MapCenter
1.443 - int i=mapCenters.indexOf ((MapCenterObj*)lmo);
1.444 + int i=rootItem->num(ti);
1.445 if (i>=0) s=QString("mc:%1").arg(i);
1.446 }
1.447 }