diff -r 25e634a7e1dc -r 8acac4fade1b vymmodel.cpp --- a/vymmodel.cpp Mon Jun 08 11:36:56 2009 +0000 +++ b/vymmodel.cpp Mon Jun 29 10:27:42 2009 +0000 @@ -1609,162 +1609,154 @@ return urls; } -void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-0 -{ - //FIXME-0 FloatImageObj *fio=selection.getFloatImage(); - FloatImageObj *fio=NULL; - if (fio) + +void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) { - TreeItem *dst=findBySelectString (dstString); - if (dst && dst->isBranchLikeType() ) - { - TreeItem *dstPar=dst->parent(); - QString parString=getSelectString(dstPar); - QString fioPreSelectString=getSelectString(fio); - QString fioPreParentSelectString=getSelectString (fio->getParObj()); - // FIXME-0 ((BranchObj*)dst)->addFloatImage (fio); - unselect(); - // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); - fio=((BranchObj*)dst)->getLastFloatImage(); - fio->setRelPos(); - fio->reposition(); - // select (fio); - saveState( - getSelectString(fio), - QString("linkTo (\"%1\")").arg(fioPreParentSelectString), - fioPreSelectString, - QString ("linkTo (\"%1\")").arg(dstString), - QString ("Link floatimage to %1").arg(getObjectName(dst))); + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + { + QString s=bo->getFrameTypeName(); + bo->setFrameType (t); + saveState (bi, QString("setFrameType (\"%1\")").arg(s), + bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); + reposition(); + bo->updateLink(); } } } - -void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2 +void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + { + saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), + bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); + bo->setFrameType (s); + reposition(); + bo->updateLink(); + } + } +} + +void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO + +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + { + saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), + bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); + bo->setFramePenColor (c); + } + } +} + +void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + { + saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), + bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); + bo->setFrameBrushColor (c); + } + } +} + +void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + { + saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), + bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); + bo->setFramePadding (i); + reposition(); + bo->updateLink(); + } + } +} + +void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + { + saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), + bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); + bo->setFrameBorderWidth (i); + reposition(); + bo->updateLink(); + } + } +} + +void VymModel::setIncludeImagesVer(bool b) //FIXME-2 { /* - BranchObj *bo=getSelectedBranch(); - if (bo) + BranchItem *bi=getSelectedBranchItem(); + if (ti) { - QString s=bo->getFrameTypeName(); - bo->setFrameType (t); - saveState (bo, QString("setFrameType (\"%1\")").arg(s), - bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); - reposition(); - bo->updateLink(); - } -*/ -} - -void VymModel::setFrameType(const QString &s) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), - bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); - bo->setFrameType (s); - reposition(); - bo->updateLink(); - } -*/ -} - -void VymModel::setFramePenColor(const QColor &c) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), - bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); - bo->setFramePenColor (c); - } -*/ -} - -void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), - bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); - bo->setFrameBrushColor (c); + BranchObj *bo=bi->getLMO(); + if (bo) + { + QString u= b ? "false" : "true"; + QString r=!b ? "false" : "true"; + + saveState( + bo, + QString("setIncludeImagesVertically (%1)").arg(u), + bo, + QString("setIncludeImagesVertically (%1)").arg(r), + QString("Include images vertically in %1").arg(getObjectName(bo)) + ); + bo->setIncludeImagesVer(b); + reposition(); + } } */} -void VymModel::setFramePadding (const int &i) //FIXME-2 +void VymModel::setIncludeImagesHor(bool b) //FIXME-2 { /* - BranchObj *bo=getSelectedBranch(); - if (bo) + TreeItem *bi=getSelectedBranchItem(); + if (ti) { - saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), - bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); - bo->setFramePadding (i); - reposition(); - bo->updateLink(); - } - */ -} - -void VymModel::setFrameBorderWidth(const int &i) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), - bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); - bo->setFrameBorderWidth (i); - reposition(); - bo->updateLink(); - } -*/ -} - -void VymModel::setIncludeImagesVer(bool b) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - QString u= b ? "false" : "true"; - QString r=!b ? "false" : "true"; - - saveState( - bo, - QString("setIncludeImagesVertically (%1)").arg(u), - bo, - QString("setIncludeImagesVertically (%1)").arg(r), - QString("Include images vertically in %1").arg(getObjectName(bo)) - ); - bo->setIncludeImagesVer(b); - reposition(); - } -*/} - -void VymModel::setIncludeImagesHor(bool b) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - QString u= b ? "false" : "true"; - QString r=!b ? "false" : "true"; - - saveState( - bo, - QString("setIncludeImagesHorizontally (%1)").arg(u), - bo, - QString("setIncludeImagesHorizontally (%1)").arg(r), - QString("Include images horizontally in %1").arg(getObjectName(bo)) - ); - bo->setIncludeImagesHor(b); - reposition(); + BranchObj *bo=bi->getLMO(); + if (bo) + { + QString u= b ? "false" : "true"; + QString r=!b ? "false" : "true"; + + saveState( + bo, + QString("setIncludeImagesHorizontally (%1)").arg(u), + bo, + QString("setIncludeImagesHorizontally (%1)").arg(r), + QString("Include images horizontally in %1").arg(getObjectName(bo)) + ); + bo->setIncludeImagesHor(b); + reposition(); + } } */ } @@ -1795,22 +1787,22 @@ void VymModel::setHideExport(bool b) { - MapItem *mi=(MapItem*)getSelectedItem(); - if (mi && - (mi->getType()==TreeItem::Image ||mi->isBranchLikeType())) + TreeItem *ti=getSelectedItem(); + if (ti && + (ti->getType()==TreeItem::Image ||ti->isBranchLikeType())) { - mi->setHideInExport (b); + ti->setHideInExport (b); QString u= b ? "false" : "true"; QString r=!b ? "false" : "true"; saveState( - mi, + ti, QString ("setHideExport (%1)").arg(u), - mi, + ti, QString ("setHideExport (%1)").arg(r), - QString ("Set HideExport flag of %1 to %2").arg(getObjectName(mi)).arg (r) + QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r) ); - emitDataHasChanged(mi); + emitDataHasChanged(ti); emitSelectionChanged(); updateActions(); reposition(); @@ -1962,11 +1954,12 @@ { QModelIndex parix; int n; + QList cData; - cData << "VM::createImage" << "undef"<<"undef"; - - ImageItem *newii=new ImageItem (cData); - newii->setHeading (QApplication::translate("Heading of new image in map", "new image")); + cData << "new" << "undef"<<"undef"; + + ImageItem *newii=new ImageItem(cData) ; + //newii->setHeading (QApplication::translate("Heading of new image in map", "new image")); emit (layoutAboutToBeChanged() ); @@ -2187,6 +2180,43 @@ return false; } +bool VymModel::relinkImage (ImageItem *image, BranchItem *dst) +{ + if (image && dst) + { + emit (layoutAboutToBeChanged() ); + + BranchItem *pi=(BranchItem*)(image->parent()); + QString oldParString=getSelectString (pi); + // Remove at current position + int n=image->childNum(); + beginRemoveRows (index(pi),n,n); + pi->removeChild (n); + endRemoveRows(); + + // Add at dst + QModelIndex dstix=index(dst); + n=dst->getRowNumAppend (image); + beginInsertRows (dstix,n,n+1); + dst->appendChild (image); + endInsertRows (); + + // Set new parent also for lmo + if (image->getLMO() && dst->getLMO() ) + image->getLMO()->setParObj (dst->getLMO() ); + + emit (layoutChanged() ); + saveState( + image, + QString("relinkTo (\"%1\")").arg(oldParString), + image, + QString ("relinkTo (\"%1\")").arg(getSelectString (dst)), + QString ("Relink floatimage to %1").arg(getObjectName(dst))); + return true; + } + return false; +} + void VymModel::deleteSelection() { BranchItem *selbi=getSelectedBranchItem(); @@ -2436,7 +2466,7 @@ } } -void VymModel::addFloatImage (const QPixmap &img) //FIXME-0 +void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop { /* BranchObj *bo=getSelectedBranch(); @@ -3067,10 +3097,8 @@ TreeItem *dst=findBySelectString (s); if (dst) { - /* FIXME-0 relink img if (dst->isBranchLikeType()) - linkFloatImageTo (getSelectString(dst)); - */ + relinkImage ( ((ImageItem*)selti),(BranchItem*)dst); } else parser.setError (Aborted,"Destination is not a branch"); } @@ -3871,7 +3899,6 @@ void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos { - cout << "VM::updateRelPos...\n"; /* FIXME-3 ??? for (int i=0; ibranchCount(); i++) ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions(); @@ -4927,7 +4954,7 @@ TreeItem::Type type=ti->getType(); if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image) { - return ((MapItem*)ti)->getLMO(); + return ti->getLMO(); } } return NULL; @@ -4937,7 +4964,7 @@ { TreeItem *ti = getSelectedBranchItem(); if (ti) - return (BranchObj*)((MapItem*)ti)->getLMO(); + return (BranchObj*)(ti->getLMO()); else return NULL; } @@ -4996,28 +5023,22 @@ return getSelectString (lmo->getTreeItem() ); } -QString VymModel::getSelectString (TreeItem *ti) +QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:" { QString s; if (!ti) return s; - if (ti->isBranchLikeType()) - { - TreeItem *par=ti->parent(); - if (par) - { - if (ti->depth() ==1) - // Mainbranch, return - s= "bo:" + QString("%1").arg(ti->num() ); - else - // Branch, call myself recursively - s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num()); - } else - { - // MapCenter - int i=rootItem->num(ti); - if (i>=0) s=QString("mc:%1").arg(i); - } - } + switch (ti->getType()) + { + case TreeItem::MapCenter: s="mc:"; break; + case TreeItem::Branch: s="bo:";break; + case TreeItem::Image: s="fi:";break; + default:break; + } + s= s + QString("%1").arg(ti->num()); + if (ti->depth() >0) + // call myself recursively + s= getSelectString(ti->parent()) +","+s; + return s; }