diff -r 2d4cc445a86a -r ee6b0f3a4c2f vymmodel.cpp --- a/vymmodel.cpp Mon Mar 23 09:06:51 2009 +0000 +++ b/vymmodel.cpp Thu Mar 26 07:49:17 2009 +0000 @@ -53,6 +53,7 @@ { // cout << "Const VymModel\n"; init(); + rootItem->setModel (this); } @@ -69,22 +70,22 @@ selModel->clearSelection(); // Remove stuff - while (!mapCenters.isEmpty()) // FIXME VM needs to be in treemodel only... + while (!mapCenters.isEmpty()) // FIXME-2 VM needs to be in treemodel only... delete mapCenters.takeFirst(); QModelIndex ri=index(rootItem); - //removeRows (0, rowCount(ri),ri); // FIXME here should be at least a beginRemoveRows... + //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows... } void VymModel::init () { // We should have at least one map center to start with - // addMapCenter(); FIXME VM create this in MapEditor as long as model is part of that + // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that // No MapEditor yet mapEditor=NULL; - // Also no scene yet (should not be needed anyway) FIXME VM + // Also no scene yet (should not be needed anyway) FIXME-3 VM mapScene=NULL; // History @@ -150,7 +151,7 @@ netstate=Offline; // Create MapCenter - // addMapCenter(); FIXME VM create this in MapEditor until BO and MCO are independent of scene + // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene } @@ -164,7 +165,7 @@ } -MapEditor* VymModel::getMapEditor() // FIXME VM better return favourite editor here +MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here { return mapEditor; } @@ -174,7 +175,7 @@ return blockReposition; } -void VymModel::updateActions() // FIXME maybe don't update if blockReposition is set +void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set { cout << "VymModel::updateActions \n"; // Tell mainwindow to update states of actions @@ -233,12 +234,12 @@ s+=xml.beginElement("vymmap",mapAttr); xml.incIndent(); - // Find the used flags while traversing the tree // FIXME this can be done local to vymmodel maybe... + // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe... standardFlagsDefault->resetUsedCounter(); // Reset the counters before saving // TODO constr. of FIO creates lots of objects, better do this in some other way... - FloatImageObj (mapScene).resetSaveCounter();// FIXME this can be done local to vymmodel maybe... + FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe... // Build xml recursivly if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) @@ -350,7 +351,7 @@ if (lmode==NewMap) { selModel->clearSelection(); - // FIXME VM not needed??? model->setMapEditor(this); + // FIXME-2 VM not needed??? model->setMapEditor(this); // (map state is set later at end of load...) } else { @@ -464,7 +465,7 @@ file.close(); if ( ok ) { - reposition(); // FIXME VM reposition the view instead... + reposition(); // FIXME-2 VM reposition the view instead... selection.update(); if (lmode==NewMap) { @@ -889,7 +890,7 @@ { importDirInt (fd->selectedFile() ); reposition(); - //FIXME VM needed? scene()->update(); + //FIXME-3 VM needed? scene()->update(); } } } @@ -932,7 +933,7 @@ QDateTime tmod=QFileInfo (filePath).lastModified(); if (tmod>fileChangedTime) { - // FIXME VM switch to current mapeditor and finish lineedits... + // FIXME-2 VM switch to current mapeditor and finish lineedits... QMessageBox mb( vymName, tr("The file of the map on disk has changed:\n\n" " %1\n\nDo you want to reload that map with the new file?").arg(filePath), @@ -1200,7 +1201,7 @@ void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) { - sendData(redoCom); //FIXME testing + sendData(redoCom); //FIXME-3 testing // Main saveState @@ -1463,7 +1464,7 @@ return QDate::currentDate().toString ("yyyy-MM-dd"); } -int VymModel::countBranches() // FIXME Optimize this: use internal counter instead of going through whole map each time... +int VymModel::countBranches() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time... { int c=0; TreeItem *cur=NULL; @@ -1491,15 +1492,15 @@ "setHeading (\""+s+"\")", QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) ); sel->setHeading(s ); - /* FIXME testing only + /* FIXME-3 testing only */ TreeItem *ti=getSelectedItem(); if (ti) { ti->setHeading (s); - //FIXME VM ix is wrong ModelIndex below, ix2 is (hopefully) correct: + //FIXME-3 VM ix is wrong ModelIndex below, ix2 is (hopefully) correct: //QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) ); - //FIXME VM testing only cout <<"VM::setHeading s="<row()<<","<column()<<")"<row()<<","<column()<<")"<update(); + // FIXME-3 VM needed? scene()->update(); } } @@ -1929,7 +1932,7 @@ BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo))); reposition(); - //FIXME VM needed? scene()->update(); + //FIXME-3 VM needed? scene()->update(); selection.update(); ensureSelectionVisible(); } @@ -1946,7 +1949,7 @@ BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo))); reposition(); - //FIXME VM needed? scene()->update(); + //FIXME-3 VM needed? scene()->update(); selection.update(); ensureSelectionVisible(); } @@ -1984,7 +1987,7 @@ BranchObj *bo=getSelectedBranch(); if (bo) { - FloatImageObj *newfio=bo->addFloatImage(); // FIXME VM Old model, merge with below + FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below // Create TreeItem QList cData; @@ -1998,7 +2001,7 @@ if (newfio) { newfio->setTreeItem (ti); - select (newfio); // FIXME VM really needed here? + select (newfio); // FIXME-2 VM really needed here? return ti; } } @@ -2008,8 +2011,7 @@ MapCenterObj* VymModel::addMapCenter () { MapCenterObj *mco=addMapCenter (contextPos); - cout <<"VM::addMCO () mapScene="<setMapEditor(mapEditor); //FIXME VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects + mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects mapCenter->move (absPos); mapCenter->setVisibility (true); mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); @@ -2035,7 +2037,6 @@ QModelIndex parix=index(rootItem); int n=rootItem->branchCount(); - cout << "VM::addMapCenter n="<setTreeItem (ti); - select (newbo); // FIXME VM really needed here? + select (newbo); // FIXME-2 VM really needed here? } }else if (num==-1) { num=bo->getNum()+1; bo=(BranchObj*)bo->getParObj(); - if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing + if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing }else if (num==-3) { num=bo->getNum(); bo=(BranchObj*)bo->getParObj(); - if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing + if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing } } return newbo; @@ -2155,7 +2156,7 @@ if (bo) { - // FIXME VM do we still need this in model? setCursor (Qt::ArrowCursor); + // FIXME-1 VM do we still need this in model? setCursor (Qt::ArrowCursor); newbo=addNewBranchInt (pos-2); @@ -2169,7 +2170,7 @@ QString ("Add new branch to %1").arg(getObjectName(bo))); reposition(); - // selection.update(); FIXME + // selection.update(); FIXME-3 latestSelectionString=getSelectString(newbo); // In Network mode, the client needs to know where the new branch is, // so we have to pass on this information via saveState. @@ -2197,7 +2198,7 @@ BranchObj *parbo=(BranchObj*)(bo->getParObj()); // add below selection - newbo=parbo->insertBranch(bo->getNum()+1); //FIXME VM still missing + newbo=parbo->insertBranch(bo->getNum()+1); //FIXME-1 VM still missing if (newbo) { @@ -2210,7 +2211,7 @@ QString ("Add branch before %1").arg(getObjectName(bo))); reposition(); - // selection.update(); FIXME + // selection.update(); FIXME-3 } } latestSelectionString=selection.getSelectString(); @@ -2219,7 +2220,7 @@ void VymModel::deleteSelection() { - BranchObj *bo = getSelectedBranch(); // FIXME VM should not be necessary + BranchObj *bo = getSelectedBranch(); // FIXME-2 VM should not be necessary if (!bo) return; QModelIndex ix=getSelectedIndex(); @@ -2229,11 +2230,11 @@ if (!parentIndex.isValid()) return; TreeItem *ti=bo->getTreeItem(); - if (selectionType()==TreeItem::MapCenter) //FIXME VM still missing + if (selectionType()==TreeItem::MapCenter) //FIXME-1 VM still missing { // BranchObj* par=(BranchObj*)(bo->getParObj()); //selection.unselect(); - /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!) + /* FIXME-1 VM Note: does saveStateRemovingPart work for MCO? (No parent!) saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo))); */ /* @@ -2272,7 +2273,7 @@ emit (layoutChanged() ); return; } - FloatImageObj *fio=selection.getFloatImage(); //FIXME VM still missing + FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing if (fio) { @@ -2292,7 +2293,7 @@ } } -void VymModel::deleteKeepChildren() //FIXME VM still missing +void VymModel::deleteKeepChildren() //FIXME-1 VM still missing { BranchObj *bo=getSelectedBranch(); @@ -2329,7 +2330,7 @@ } } -void VymModel::deleteChildren() //FIXME VM still missing +void VymModel::deleteChildren() //FIXME-1 VM still missing { BranchObj *bo=getSelectedBranch(); @@ -2366,7 +2367,7 @@ ); bo->toggleScroll(); selection.update(); - // FIXME VM needed? scene()->update(); + // FIXME-3 VM needed? scene()->update(); return true; } return false; @@ -2391,7 +2392,7 @@ ); bo->toggleScroll(); selection.update(); - // FIXME VM needed? scene()->update(); + // FIXME-3 VM needed? scene()->update(); return true; } return false; @@ -2409,8 +2410,10 @@ } } -void VymModel::unscrollChildren() -{ +void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel + +{ +/* BranchObj *bo=getSelectedBranch(); if (bo) { @@ -2421,7 +2424,9 @@ bo=bo->next(); } } +*/ } + void VymModel::addFloatImage (const QPixmap &img) { BranchObj *bo=getSelectedBranch(); @@ -2434,7 +2439,7 @@ saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio ); saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image"); reposition(); - // FIXME VM needed? scene()->update(); + // FIXME-3 VM needed? scene()->update(); } } @@ -2585,7 +2590,7 @@ "setVymLink (\""+fd->selectedFile()+"\")", QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile()) ); - setVymLink (fd->selectedFile() ); // FIXME ok? + setVymLink (fd->selectedFile() ); // FIXME-2 ok? } } } @@ -2619,7 +2624,7 @@ bo->setVymLink ("" ); updateActions(); reposition(); - // FIXME VM needed? scene()->update(); + // FIXME-3 VM needed? scene()->update(); } } @@ -2633,8 +2638,10 @@ } -QStringList VymModel::getVymLinks() -{ +QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel +{ + return QStringList(); +/* QStringList links; BranchObj *bo=getSelectedBranch(); if (bo) @@ -2647,6 +2654,7 @@ } } return links; +*/ } @@ -2664,7 +2672,7 @@ } } -void VymModel::editXLink(int i) // FIXME VM missing saveState +void VymModel::editXLink(int i) // FIXME-1 VM missing saveState { BranchObj *bo=getSelectedBranch(); if (bo) @@ -2850,7 +2858,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(0)) { - //FIXME missing action for copy + //FIXME-1 missing action for copy } ///////////////////////////////////////////////////////////////////// } else if (com=="cut") @@ -3629,7 +3637,7 @@ // Any errors? if (parser.errorLevel()==NoError) { - // setChanged(); FIXME should not be called e.g. for export?! + // setChanged(); FIXME-2 should not be called e.g. for export?! reposition(); } else @@ -3839,12 +3847,15 @@ void VymModel::updateNoteFlag() { setChanged(); + cout << "VM::updateNoteFlag()\n"; + /* FIXME-1 modify note flag BranchObj *bo=getSelectedBranch(); if (bo) { bo->updateNoteFlag(); mainWindow->updateActions(); } + */ } void VymModel::updateRelPositions() @@ -4066,7 +4077,7 @@ } } -void VymModel::selectMapBackgroundImage () // FIXME move to ME +void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME { Q3FileDialog *fd=new Q3FileDialog( NULL); fd->setMode (Q3FileDialog::ExistingFile); @@ -4087,7 +4098,7 @@ } } -void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate +void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate { QColor oldcol=mapScene->backgroundBrush().color(); /* @@ -4103,7 +4114,7 @@ mapScene->setBackgroundBrush(brush); } -void VymModel::selectMapBackgroundColor() // FIXME move to ME +void VymModel::selectMapBackgroundColor() // FIXME-1 move to ME { QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL); if ( !col.isValid() ) return; @@ -4111,7 +4122,7 @@ } -void VymModel::setMapBackgroundColor(QColor col) // FIXME move to ME +void VymModel::setMapBackgroundColor(QColor col) // FIXME-1 move to ME { QColor oldcol=mapScene->backgroundBrush().color(); saveState( @@ -4121,38 +4132,38 @@ mapScene->setBackgroundBrush(col); } -QColor VymModel::getMapBackgroundColor() // FIXME move to ME +QColor VymModel::getMapBackgroundColor() // FIXME-1 move to ME { return mapScene->backgroundBrush().color(); } -LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME move to ME +LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-1 move to ME { return linkcolorhint; } -QColor VymModel::getMapDefLinkColor() // FIXME move to ME +QColor VymModel::getMapDefLinkColor() // FIXME-1 move to ME { return defLinkColor; } -void VymModel::setMapDefXLinkColor(QColor col) // FIXME move to ME +void VymModel::setMapDefXLinkColor(QColor col) // FIXME-1 move to ME { defXLinkColor=col; } -QColor VymModel::getMapDefXLinkColor() // FIXME move to ME +QColor VymModel::getMapDefXLinkColor() // FIXME-1 move to ME { return defXLinkColor; } -void VymModel::setMapDefXLinkWidth (int w) // FIXME move to ME +void VymModel::setMapDefXLinkWidth (int w) // FIXME-1 move to ME { defXLinkWidth=w; } -int VymModel::getMapDefXLinkWidth() // FIXME move to ME +int VymModel::getMapDefXLinkWidth() // FIXME-1 move to ME { return defXLinkWidth; } @@ -4276,7 +4287,7 @@ if (!tcpServer->listen(QHostAddress::Any,port)) { QMessageBox::critical(NULL, "vym server", QString("Unable to start the server: %1.").arg(tcpServer->errorString())); - //FIXME needed? we are no widget any longer... close(); + //FIXME-3 needed? we are no widget any longer... close(); return; } connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient())); @@ -4415,11 +4426,18 @@ mapEditor->setSelectionColor (col); } -void VymModel::updateSelection() -{ - QItemSelection newsel=selModel->selection(); - updateSelection (newsel); +/* +void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel) +{ + cout << "VymModel::changeSelection ("; + if (!newsel.indexes().isEmpty() ) + cout << getItem(newsel.indexes().first() )->getHeading().toStdString(); + cout << ","; + if (!oldsel.indexes().isEmpty() ) + cout << getItem(oldsel.indexes().first() )->getHeading().toStdString(); + cout << ")\n"; } +*/ void VymModel::updateSelection(const QItemSelection &newsel) { @@ -4428,6 +4446,12 @@ sendSelection(); } +void VymModel::updateSelection() +{ + QItemSelection newsel=selModel->selection(); + updateSelection (newsel); +} + void VymModel::setSelectionColor(QColor col) { if ( !col.isValid() ) return; @@ -4450,7 +4474,7 @@ for (int i=0;isetHideTmp (mode); reposition(); - // FIXME needed? scene()->update(); + // FIXME-3 needed? scene()->update(); } @@ -4469,7 +4493,6 @@ void VymModel::setSelectionModel (QItemSelectionModel *sm) { selModel=sm; - cout << "VM::setSelModel selModel="<select (ix,QItemSelectionModel::ClearAndSelect ); ti->setLastSelectedBranch(); - //updateSelection(oldsel); //FIXME needed? + //updateSelection(oldsel); //FIXME-3 needed? return true; } return false; @@ -4545,11 +4568,16 @@ selection.reselect(); } -void VymModel::ensureSelectionVisible() +void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented... { LinkableMapObj *lmo=getSelectedLMO(); if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() ); - +} + +void VymModel::emitContentHasChanged (TreeItem *ti) +{ + QModelIndex ix=index(ti); + emit (contentHasChanged (ix) ); } void VymModel::selectInt (LinkableMapObj *lmo) @@ -4557,7 +4585,7 @@ if (selection.select(lmo)) { //selection.update(); - sendSelection (); // FIXME VM use signal + sendSelection (); // FIXME-4 VM use signal } } @@ -4947,10 +4975,11 @@ TreeItem* VymModel::getSelectedItem() { - // FIXME this may not only be branch, but also float etc... - BranchObj* bo=getSelectedBranch(); - if (bo) return bo->getTreeItem(); // FIXME VM get directly from treemodl - return NULL; + QModelIndexList list=selModel->selectedIndexes(); + if (!list.isEmpty() ) + return getItem (list.first() ); + else + return NULL; } QModelIndex VymModel::getSelectedIndex() @@ -4976,7 +5005,7 @@ return QString(); } -QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME VM needs to use TreeModel +QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel { QString s; if (!lmo) return s;