diff -r edb78a44240b -r 9ff332964015 vymmodel.cpp --- a/vymmodel.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/vymmodel.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -3,6 +3,8 @@ #include "vymmodel.h" +#include "branchitem.h" +#include "mapcenteritem.h" #include "editxlinkdialog.h" #include "exports.h" #include "exportxhtmldialog.h" @@ -223,7 +225,7 @@ mapAttr+= xml.attribut("author",author) + xml.attribut("comment",comment) + xml.attribut("date",getDate()) + - xml.attribut("countBranches", QString().number(countBranches())) + + xml.attribut("branchCount", QString().number(branchCount())) + xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) + xml.attribut("linkStyle", ls ) + @@ -830,9 +832,10 @@ { dst->addBranch(); bo=dst->getLastBranch(); - bo->setHeading (fi.fileName() ); + BranchItem *bi=(BranchItem*)(bo->getTreeItem()); + bi->setHeading (fi.fileName() ); // FIXME-3 check this bo->setColor (QColor("blue")); - bo->toggleScroll(); + bi->toggleScroll(); if ( !d.cd(fi.fileName()) ) QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); else @@ -1318,7 +1321,7 @@ { // save the selected branch of the map, Undo will insert part of map saveState (PartOfMap, - undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), + undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->getTreeItem()->num()), redoSelection, "delete ()", comment, redoSel); @@ -1464,7 +1467,7 @@ return QDate::currentDate().toString ("yyyy-MM-dd"); } -int VymModel::countBranches() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time... +int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time... { int c=0; TreeItem *cur=NULL; @@ -1955,12 +1958,13 @@ } } -void VymModel::sortChildren() -{ +void VymModel::sortChildren() // FIXME-1 not implemented yet +{ +/* BranchObj* bo=getSelectedBranch(); if (bo) { - if(bo->countBranches()>1) + if(treeItem->branchCount()>1) { saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo))); bo->sortChildren(); @@ -1968,6 +1972,7 @@ ensureSelectionVisible(); } } +*/ } void VymModel::createMapCenter() @@ -2026,33 +2031,35 @@ MapCenterObj* VymModel::addMapCenter(QPointF absPos) { + + // Create TreeItem + QModelIndex parix=index(rootItem); + + int n=rootItem->branchCount(); + + emit (layoutAboutToBeChanged() ); + beginInsertRows (parix,n,n+1); + + QList cData; + cData << "VM:addMapCenter" << "undef"<<"undef"; + MapCenterItem *ti=new MapCenterItem (cData,rootItem); + cout << "VM::addMapCenter ti="<setType (TreeItem::MapCenter); + rootItem->appendChild (ti); + + endInsertRows(); + emit (newChildObject (parix)); + emit (layoutChanged() ); + + // Create MapObj MapCenterObj *mapCenter = new MapCenterObj(mapScene,this); mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects + mapCenter->setTreeItem (ti); // TreeItem needs to exist before setVisibility + ti->setLMO (mapCenter); mapCenter->move (absPos); mapCenter->setVisibility (true); mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); mapCenters.append(mapCenter); - - // Create TreeItem - QModelIndex parix=index(rootItem); - - int n=rootItem->branchCount(); - - emit (layoutAboutToBeChanged() ); - beginInsertRows (parix,n,n+1); - - QList cData; - cData << "VM:addMapCenter" << "undef"<<"undef"; - TreeItem *ti=new TreeItem (cData,rootItem); - ti->setLMO (mapCenter); - ti->setType (TreeItem::MapCenter); - mapCenter->setTreeItem (ti); - rootItem->appendChild (ti); - - endInsertRows(); - emit (newChildObject (parix)); - emit (layoutChanged() ); - // Testing /* qWarning ("MW::insertRow a"); @@ -2097,47 +2104,48 @@ // 0..n insert in children of parent at pos BranchObj *newbo=NULL; BranchObj *bo=getSelectedBranch(); + BranchItem *bi=getSelectedBranchItem(); if (bo) { if (num==-2) { + // Create TreeItem + QList cData; + cData << "new" << "undef"<<"undef"; + + BranchItem *parbi=bi; + QModelIndex parix=index(parbi); + int n=parbi->branchCount(); + + emit (layoutAboutToBeChanged() ); + beginInsertRows (parix,n,n+1); + bi=new BranchItem (cData,parbi); + bi->setType (TreeItem::Branch); + + parbi->appendChild (bi); + endInsertRows (); + emit (newChildObject (parix)); + emit (layoutChanged() ); + // save scroll state. If scrolled, automatically select // new branch in order to tmp unscroll parent... newbo=bo->addBranch(); - // Create TreeItem - QList cData; - cData << "new" << "undef"<<"undef"; - - TreeItem *parti=bo->getTreeItem(); - QModelIndex parix=index(parti); - int n=parti->branchCount(); - - emit (layoutAboutToBeChanged() ); - beginInsertRows (parix,n,n+1); - TreeItem *ti=new TreeItem (cData,parti); - ti->setLMO (newbo); - ti->setType (TreeItem::Branch); - - parti->appendChild (ti); - endInsertRows (); - emit (newChildObject (parix)); - emit (layoutChanged() ); - if (newbo) { - newbo->setTreeItem (ti); + bi->setLMO (newbo); + newbo->setTreeItem (bi); select (newbo); // FIXME-2 VM really needed here? } }else if (num==-1) { - num=bo->getNum()+1; + num=bi->num()+1; bo=(BranchObj*)bo->getParObj(); if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing }else if (num==-3) { - num=bo->getNum(); + num=bi->num(); bo=(BranchObj*)bo->getParObj(); if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing } @@ -2156,7 +2164,7 @@ if (bo) { - // FIXME-1 VM do we still need this in model? setCursor (Qt::ArrowCursor); + // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor); newbo=addNewBranchInt (pos-2); @@ -2198,7 +2206,7 @@ BranchObj *parbo=(BranchObj*)(bo->getParObj()); // add below selection - newbo=parbo->insertBranch(bo->getNum()+1); //FIXME-1 VM still missing + newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing if (newbo) { @@ -2276,8 +2284,8 @@ int n=ix.row(); beginRemoveRows (parentIndex,n,n); removeRows (n,1,parentIndex); + endRemoveRows(); par->removeBranch(bo); // remove from BranchObj lists... - endRemoveRows(); select (par); ensureSelectionVisible(); reposition(); @@ -2285,7 +2293,7 @@ emit (layoutChanged() ); return; } - FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing + //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing /* if (fio) @@ -2320,7 +2328,7 @@ if (!par) return; // Check if we have childs at all to keep - if (bo->countBranches()==0) + if (bo->getTreeItem()->branchCount()==0) { deleteSelection(); return; @@ -2362,16 +2370,17 @@ } -bool VymModel::scrollBranch(BranchObj *bo) -{ - if (bo) +bool VymModel::scrollBranch(BranchItem *bi) +{ + if (bi) { - if (bo->isScrolled()) return false; - if (bo->countBranches()==0) return false; - if (bo->getDepth()==0) return false; + if (bi->isScrolled()) return false; + if (bi->branchCount()==0) return false; + if (bi->depth()==0) return false; QString u,r; r="scroll"; u="unscroll"; + /* FIXME-1 no savestate yet saveState( bo, QString ("%1 ()").arg(u), @@ -2379,24 +2388,27 @@ QString ("%1 ()").arg(r), QString ("%1 %2").arg(r).arg(getObjectName(bo)) ); - bo->toggleScroll(); - selection.update(); + */ + bi->toggleScroll(); + //selection.update(); // FIXME-3 VM needed? scene()->update(); return true; } return false; } -bool VymModel::unscrollBranch(BranchObj *bo) -{ - if (bo) +bool VymModel::unscrollBranch(BranchItem *bi) +{ + if (bi) { - if (!bo->isScrolled()) return false; - if (bo->countBranches()==0) return false; - if (bo->getDepth()==0) return false; + if (bi->isScrolled()) return false; + if (bi->branchCount()==0) return false; + if (bi->depth()==0) return false; + QString u,r; u="scroll"; r="unscroll"; + /* FIXME-1 no savestate yet saveState( bo, QString ("%1 ()").arg(u), @@ -2404,8 +2416,9 @@ QString ("%1 ()").arg(r), QString ("%1 %2").arg(r).arg(getObjectName(bo)) ); - bo->toggleScroll(); - selection.update(); + */ + bi->toggleScroll(); + // selection.update(); // FIXME-3 VM needed? scene()->update(); return true; } @@ -2414,13 +2427,13 @@ void VymModel::toggleScroll() { - BranchObj *bo=getSelectedBranch(); - if (selectionType()==TreeItem::Branch ) + BranchItem *bi=(BranchItem*)getSelectedBranchItem(); + if (bi && bi->getType()==TreeItem::Branch ) { - if (bo->isScrolled()) - unscrollBranch (bo); + if (bi->isScrolled()) + unscrollBranch (bi); else - scrollBranch (bo); + scrollBranch (bi); } } @@ -2722,6 +2735,7 @@ void VymModel::parseAtom(const QString &atom) { BranchObj *selb=getSelectedBranch(); + BranchItem *bi=getSelectedBranchItem(); QString s,t; double x,y; int n; @@ -3260,7 +3274,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(0)) { - if (!scrollBranch (selb)) + if (!scrollBranch (bi)) parser.setError (Aborted,"Could not scroll branch"); } ///////////////////////////////////////////////////////////////////// @@ -3611,7 +3625,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(0)) { - if (!unscrollBranch (selb)) + if (!unscrollBranch (bi)) parser.setError (Aborted,"Could not unscroll branch"); } ///////////////////////////////////////////////////////////////////// @@ -4669,7 +4683,7 @@ b=select (s); if (b) { - if ( getSelectedBranch()->countBranches()>0) + if ( getSelectedItem()->branchCount()>0) s+=",bo:0"; else break; @@ -4749,8 +4763,8 @@ { b=select (s); if (b) - if ( getSelectedBranch()->countBranches()>0) - s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 ); + if ( getSelectedItem()->branchCount()>0) + s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 ); else break; else @@ -4974,7 +4988,7 @@ return NULL; } -TreeItem* VymModel::getSelectedBranchItem() +BranchItem* VymModel::getSelectedBranchItem() { QModelIndexList list=selModel->selectedIndexes(); if (!list.isEmpty() ) @@ -4982,7 +4996,7 @@ TreeItem *ti = getItem (list.first() ); TreeItem::Type type=ti->getType(); if (type ==TreeItem::Branch || type==TreeItem::MapCenter) - return ti; + return (BranchItem*)ti; } return NULL; } @@ -5019,26 +5033,32 @@ return QString(); } -QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel +QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below... +{ + if (!lmo) return QString(); + return getSelectString (lmo->getTreeItem() ); +} + +QString VymModel::getSelectString (TreeItem *ti) { QString s; - if (!lmo) return s; - if (typeid(*lmo)==typeid(BranchObj) || - typeid(*lmo)==typeid(MapCenterObj) ) + if (!ti) return s; + if (ti->getType() == TreeItem::Branch || + ti->getType() == TreeItem::MapCenter) { - LinkableMapObj *par=lmo->getParObj(); + TreeItem *par=ti->parent(); if (par) { - if (lmo->getDepth() ==1) + if (ti->depth() ==1) // Mainbranch, return - s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + s= "bo:" + QString("%1").arg(ti->num() ); else // Branch, call myself recursively - s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num()); } else { // MapCenter - int i=mapCenters.indexOf ((MapCenterObj*)lmo); + int i=rootItem->num(ti); if (i>=0) s=QString("mc:%1").arg(i); } }