diff -r 6e4b586aa88a -r 25e634a7e1dc vymmodel.cpp --- a/vymmodel.cpp Wed Jun 03 20:37:17 2009 +0000 +++ b/vymmodel.cpp Mon Jun 08 11:36:56 2009 +0000 @@ -234,7 +234,7 @@ // Reset the counters before saving // TODO constr. of FIO creates lots of objects, better do this in some other way... - FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe... + ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe... // Build xml recursivly if (!saveSel || saveSel->getType()==TreeItem::MapCenter) @@ -260,6 +260,8 @@ xml.decIndent(); s+=xml.endElement("vymmap"); + //cout << s.toStdString() << endl; + if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags); return s; } @@ -623,7 +625,7 @@ return err; } -void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) +void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree { QString pathDir=path.left(path.findRev("/")); QDir d(pathDir); @@ -700,15 +702,14 @@ */ } -FloatImageObj* VymModel::loadFloatImageInt (BranchItem *dst,QString fn) -{ - TreeItem *fi=createImage(dst); - if (fi) +ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn) +{ + ImageItem *ii=createImage(dst); + if (ii) { - FloatImageObj *fio= ((FloatImageObj*)fi->getLMO()); - fio->load (fn); + ii->load (fn); reposition(); - return fio; + return ii; } return NULL; } @@ -735,16 +736,15 @@ // TODO loadFIO in QT4 use: lastImageDir=fd->directory(); lastImageDir=QDir (fd->dirPath()); QString s; - FloatImageObj *fio; + ImageItem *ii; for (int j=0; jselectedFiles().count(); j++) { s=fd->selectedFiles().at(j); - fio=loadFloatImageInt (selbi,s); - //FIXME-1 savestate for loadImage missing - /* - if (fio) + ii=loadFloatImageInt (selbi,s); + //FIXME-3 check savestate for loadImage + if (ii) saveState( - (LinkableMapObj*)fio, + (TreeItem*)ii, "delete ()", selbi, QString ("loadImage (%1)").arg(s ), @@ -753,7 +753,6 @@ else // TODO loadFIO error handling qWarning ("Failed to load "+s); - */ } } delete (p); @@ -761,16 +760,15 @@ } } -void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) -{ - fio->save (fn,type); +void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn) +{ + ii->save (fn,type); } void VymModel::saveFloatImage () { - //FIXME-1 FloatImageObj *fio=selection.getFloatImage(); - FloatImageObj *fio=NULL; - if (fio) + ImageItem *ii=getSelectedImageItem(); + if (ii) { QFileDialog *fd=new QFileDialog( NULL); fd->setFilters (imageIO.getFilters()); @@ -808,7 +806,7 @@ break; } } - saveFloatImageInt (fio,fd->selectedFilter(),fn ); + saveFloatImageInt (ii,fd->selectedFilter(),fn ); } delete (fd); } @@ -992,40 +990,24 @@ findReset(); } -QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete -{ - QString s; - if (!lmo) return QString("Error: NULL has no name!"); - - TreeItem *ti=lmo->getTreeItem(); - if (ti->isBranchLikeType() ) - { - - s=lmo->getTreeItem()->getHeading(); - if (s=="") s="unnamed"; - return QString("branch (%1)").arg(s); - } - if (ti->getType()==TreeItem::Image) - return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); - return QString("Unknown type has no name!"); +QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete +{ + if (!lmo || !lmo->getTreeItem() ) return QString(); + return getObjectName (lmo->getTreeItem() ); } -QString VymModel::getObjectName (const TreeItem *ti) +QString VymModel::getObjectName (TreeItem *ti) { QString s; if (!ti) return QString("Error: NULL has no name!"); - - if (ti->isBranchLikeType() ) - { - s=ti->getHeading(); - if (s=="") s="unnamed"; + s=ti->getHeading(); + if (s=="") s="unnamed"; + + if (ti->isBranchLikeType() ) //FIXME-3 shouldnt there also be mapcenter?? return QString("branch (%1)").arg(s); - } - /* FIXME-2 move floatimage to TreeModel first - if (type==TreeItem::Image) - return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); - */ + if (ti->getType()==TreeItem::Image) + return QString ("image (%1)").arg(ti->getHeading()); return QString("Unknown type has no name!"); } @@ -1480,7 +1462,7 @@ return QDate::currentDate().toString ("yyyy-MM-dd"); } -int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time... +int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time... { int c=0; BranchItem *cur=NULL; @@ -1627,9 +1609,9 @@ return urls; } -void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-1 -{ - //FIXME-1 FloatImageObj *fio=selection.getFloatImage(); +void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-0 +{ + //FIXME-0 FloatImageObj *fio=selection.getFloatImage(); FloatImageObj *fio=NULL; if (fio) { @@ -1640,7 +1622,7 @@ QString parString=getSelectString(dstPar); QString fioPreSelectString=getSelectString(fio); QString fioPreParentSelectString=getSelectString (fio->getParObj()); - // FIXME-1 ((BranchObj*)dst)->addFloatImage (fio); + // FIXME-0 ((BranchObj*)dst)->addFloatImage (fio); unselect(); // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); fio=((BranchObj*)dst)->getLastFloatImage(); @@ -1813,20 +1795,23 @@ void VymModel::setHideExport(bool b) { - BranchItem *bi=getSelectedBranchItem(); - if (bi) + MapItem *mi=(MapItem*)getSelectedItem(); + if (mi && + (mi->getType()==TreeItem::Image ||mi->isBranchLikeType())) { - bi->setHideInExport (b); + mi->setHideInExport (b); QString u= b ? "false" : "true"; QString r=!b ? "false" : "true"; saveState( - bi, + mi, QString ("setHideExport (%1)").arg(u), - bi, + mi, QString ("setHideExport (%1)").arg(r), - QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r) + QString ("Set HideExport flag of %1 to %2").arg(getObjectName(mi)).arg (r) ); + emitDataHasChanged(mi); + emitSelectionChanged(); updateActions(); reposition(); // emitSelectionChanged(); @@ -1836,9 +1821,9 @@ void VymModel::toggleHideExport() { - BranchItem *selbi=getSelectedBranchItem(); - if (selbi) - setHideExport ( !selbi->hideInExport() ); + TreeItem *selti=getSelectedItem(); + if (selti) + setHideExport ( !selti->hideInExport() ); } @@ -1971,31 +1956,35 @@ return NULL; } -TreeItem* VymModel::createImage(BranchItem *dst) //FIXME-1 -{ - return NULL; -/* +ImageItem* VymModel::createImage(BranchItem *dst) +{ if (dst) { - FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below - - // Create TreeItem + QModelIndex parix; + int n; QList cData; - cData << "VM:createImage" << "undef"<<"undef"; - TreeItem *parti=bo->getTreeItem(); - TreeItem *ti=new TreeItem (cData,parti); - ti->setLMO (newfio); - ti->setType (TreeItem::Image); - parti->appendChild (ti); - - if (newfio) - { - newfio->setTreeItem (ti); - select (newfio); // FIXME-2 VM really needed here? - return ti; - } - } -*/ + cData << "VM::createImage" << "undef"<<"undef"; + + ImageItem *newii=new ImageItem (cData); + newii->setHeading (QApplication::translate("Heading of new image in map", "new image")); + + emit (layoutAboutToBeChanged() ); + + parix=index(dst); + n=dst->getRowNumAppend(newii); + beginInsertRows (parix,n,n+1); + dst->appendChild (newii); + endInsertRows (); + + emit (layoutChanged() ); + + // save scroll state. If scrolled, automatically select + // new branch in order to tmp unscroll parent... + newii->createMapObj(mapScene); + reposition(); + return newii; + } + return NULL; } BranchItem* VymModel::addMapCenter () @@ -2065,7 +2054,7 @@ { parbi=dst; parix=index(parbi); - n=parbi->childCount(); + n=parbi->getRowNumAppend (newbi); beginInsertRows (parix,n,n+1); parbi->appendChild (newbi); endInsertRows (); @@ -2073,8 +2062,9 @@ { // insert below selection parbi=(BranchItem*)dst->parent(); - parix=index(parbi); - n=dst->childNumber()+ (3+num)/2; //-1 |-> 1;-3 |-> 0 + parix=index(parbi); + + n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0 beginInsertRows (parix,n,n); parbi->insertBranch(n,newbi); endInsertRows (); @@ -2201,52 +2191,39 @@ { BranchItem *selbi=getSelectedBranchItem(); - if (!selbi) return; - - TreeItem *pi=selbi->parent(); - QModelIndex parentIndex=index(pi); - - if (selbi->isBranchLikeType() ) + if (selbi && selbi->isBranchLikeType() ) { unselect(); saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi))); - emit (layoutAboutToBeChanged() ); - - int n=selbi->childNum(); - beginRemoveRows (parentIndex,n,n); - removeRows (n,1,parentIndex); - endRemoveRows(); - select (pi); - emitShowSelection(); - reposition(); - - emit (layoutChanged() ); + TreeItem *pi=deleteItem (selbi); + if (pi) + { + select (pi); + emitShowSelection(); + } return; } - //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing - -/* - if (fio) + ImageItem *ii=getSelectedImageItem(); + if (ii) { - BranchObj* par=(BranchObj*)fio->getParObj(); + BranchItem *pi=(BranchItem*)(ii->parent()); saveStateChangingPart( - par, - fio, + pi, + ii, "delete ()", - QString("Delete %1").arg(getObjectName(fio)) + QString("Delete %1").arg(getObjectName(ii)) ); unselect(); - par->removeFloatImage(fio); - select (par); + deleteItem (ii); + select (pi); reposition(); emitShowSelection(); return; } - */ } -void VymModel::deleteKeepChildren() +void VymModel::deleteKeepChildren() //FIXME-2 does not work yet for mapcenters { BranchItem *selbi=getSelectedBranchItem(); @@ -2275,7 +2252,15 @@ QString sel=getSelectString(selbi); unselect(); - //FIXME-0 missing in VM pi->removeBranchHere(selbi); + int pos=selbi->num(); + BranchItem *bi=selbi->getFirstBranch(); + while (bi) + { + relinkBranch (bi,pi,pos); + bi=selbi->getFirstBranch(); + pos++; + } + deleteItem (selbi); reposition(); select (sel); BranchObj *bo=getSelectedBranchObj(); @@ -2311,6 +2296,27 @@ } } +TreeItem* VymModel::deleteItem (TreeItem *ti) +{ + if (ti) + { + TreeItem *pi=ti->parent(); + QModelIndex parentIndex=index(pi); + + emit (layoutAboutToBeChanged() ); + + int n=ti->childNum(); + beginRemoveRows (parentIndex,n,n); + removeRows (n,1,parentIndex); + endRemoveRows(); + reposition(); + + emit (layoutChanged() ); + if (pi->depth()>0) return pi; + } + return NULL; +} + bool VymModel::scrollBranch(BranchItem *bi) { if (bi) @@ -2430,7 +2436,7 @@ } } -void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 +void VymModel::addFloatImage (const QPixmap &img) //FIXME-0 { /* BranchObj *bo=getSelectedBranch(); @@ -3010,7 +3016,7 @@ if (ok) importDirInt(s); } ///////////////////////////////////////////////////////////////////// - } else /* FIXME-2 if (com=="linkTo") + } else if (com=="relinkTo") { if (!selti) { @@ -3023,21 +3029,21 @@ // 1 num in parent (for branches) // 2,3 x,y of mainbranch or mapcenter s=parser.parString(ok,0); - LinkableMapObj *dst=findObjBySelect (s); + TreeItem *dst=findBySelectString (s); if (dst) { - if (typid(*dst) == typid(BranchObj) ) + if (dst->getType()==TreeItem::Branch) { // Get number in parent n=parser.parInt (ok,1); if (ok) { - selb->linkTo ((BranchObj*)(dst),n); + relinkBranch (selbi,(BranchItem*)dst,n); emitSelectionChanged(); } - } else if (typid(*dst) == typid(MapCenterObj) ) + } else if (dst->getType()==TreeItem::MapCenter) { - selb->linkTo ((BranchObj*)(dst),-1); + relinkBranch (selbi,(BranchItem*)dst); // Get coordinates of mainbranch x=parser.parDouble(ok,2); if (ok) @@ -3045,32 +3051,33 @@ y=parser.parDouble(ok,3); if (ok) { - selbi->move (x,y); + if (selbi->getLMO()) selbi->getLMO()->move (x,y); emitSelectionChanged(); } } } } } - } else if ( selectionType() == TreeItem::Image) + } else if ( selti->getType() == TreeItem::Image) { if (parser.checkParCount(1)) { // 0 selectstring of parent s=parser.parString(ok,0); - LinkableMapObj *dst=findObjBySelect (s); + TreeItem *dst=findBySelectString (s); if (dst) { - if (typid(*dst) == typid(BranchObj) || - typid(*dst) == typid(MapCenterObj)) + /* FIXME-0 relink img + if (dst->isBranchLikeType()) linkFloatImageTo (getSelectString(dst)); + */ } else parser.setError (Aborted,"Destination is not a branch"); } } else parser.setError (Aborted,"Type of selection is not a floatimage or branch"); ///////////////////////////////////////////////////////////////////// - } else */ if (com=="loadImage") + } else if (com=="loadImage") { if (!selti) { @@ -3235,18 +3242,17 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="saveImage") { - //FIXME-2 FloatImageObj *fio=selection.getFloatImage(); - FloatImageObj* fio=NULL; - if (!fio) + ImageItem *ii=getSelectedImageItem(); + if (!ii ) { - parser.setError (Aborted,"Type of selection is not an image"); + parser.setError (Aborted,"No image selected"); } else if (parser.checkParCount(2)) { s=parser.parString(ok,0); if (ok) { t=parser.parString(ok,1); - if (ok) saveFloatImageInt (fio,t,s); + if (ok) saveFloatImageInt (ii,t,s); } } ///////////////////////////////////////////////////////////////////// @@ -4553,10 +4559,7 @@ bool VymModel::select () { - QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet - - TreeItem *item = getItem (index); - return select (item->getLMO() ); + return select (selModel->selectedIndexes().first()); // TODO no multiselections yet } bool VymModel::select (const QString &s) @@ -4924,7 +4927,7 @@ TreeItem::Type type=ti->getType(); if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image) { - return ti->getLMO(); + return ((MapItem*)ti)->getLMO(); } } return NULL; @@ -4934,7 +4937,7 @@ { TreeItem *ti = getSelectedBranchItem(); if (ti) - return (BranchObj*)ti->getLMO(); + return (BranchObj*)((MapItem*)ti)->getLMO(); else return NULL; } @@ -4970,9 +4973,15 @@ return list.first(); } -FloatImageObj* VymModel::getSelectedFloatImage() -{ - //FIXME-2 return selection.getFloatImage(); +ImageItem* VymModel::getSelectedImageItem() +{ + QModelIndexList list=selModel->selectedIndexes(); + if (!list.isEmpty()) + { + TreeItem *ti=getItem (list.first()); + if (ti && ti->getType()==TreeItem::Image) + return (ImageItem*)ti; + } return NULL; } @@ -4991,8 +5000,7 @@ { QString s; if (!ti) return s; - if (ti->getType() == TreeItem::Branch || - ti->getType() == TreeItem::MapCenter) + if (ti->isBranchLikeType()) { TreeItem *par=ti->parent(); if (par)