diff -r 133e2ed6b9c5 -r f1006de05c54 vymmodel.cpp --- a/vymmodel.cpp Thu Sep 03 08:52:00 2009 +0000 +++ b/vymmodel.cpp Mon Sep 07 15:36:57 2009 +0000 @@ -77,9 +77,6 @@ void VymModel::init () { - // We should have at least one map center to start with - // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that - // No MapEditor yet mapEditor=NULL; @@ -844,11 +841,11 @@ } -void VymModel::importDirInt(BranchObj *dst, QDir d) -{ -/* FIXME-2 importDirInt not ported yet - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::importDirInt(BranchItem *dst, QDir d) +{ + BranchItem *selbi=getSelectedBranch(); + BranchItem *bi; + if (selbi) { // Traverse directories d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks ); @@ -860,18 +857,16 @@ fi=list.at(i); if (fi.fileName() != "." && fi.fileName() != ".." ) { - dst->addBranch(); - bo=dst->getLastBranch(); - BranchItem *bi=(BranchItem*)(bo->getTreeItem()); + bi=addNewBranchInt(dst,-2); bi->setHeading (fi.fileName() ); // FIXME-3 check this - bo->setColor (QColor("blue")); + bi->setHeadingColor (QColor("blue")); bi->toggleScroll(); if ( !d.cd(fi.fileName()) ) QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); else { // Recursively add subdirs - importDirInt (bo,d); + importDirInt (bi,d); d.cdUp(); } } @@ -883,36 +878,31 @@ for (int i = 0; i < list.size(); ++i) { fi=list.at(i); - dst->addBranch(); - bo=dst->getLastBranch(); - bo->setHeading (fi.fileName() ); - bo->setColor (QColor("black")); + bi=addNewBranchInt (dst,-2); + bi->setHeading (fi.fileName() ); + bi->setHeadingColor (QColor("black")); if (fi.fileName().right(4) == ".vym" ) - bo->setVymLink (fi.filePath()); + bi->setVymLink (fi.filePath()); } } -*/ } -void VymModel::importDirInt (const QString &s) // FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::importDirInt (const QString &s) +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi) { - saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); + saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); QDir d(s); - importDirInt (bo,d); + importDirInt (selbi,d); } -*/ } -void VymModel::importDir() //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::importDir() //FIXME-3 check me... (not tested yet) +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi) { QStringList filters; filters <<"VYM map (*.vym)"; @@ -930,7 +920,6 @@ //FIXME-3 VM needed? scene()->update(); } } -*/ } @@ -1435,11 +1424,12 @@ parts.removeFirst(); if (typ=="mc" || typ=="bo") ti=ti->getBranchNum (n); - /* FIXME-2 + /* FIXME-2 add other types to getSelectionString and findBy... else if (typ="fi") ti=ti->getImageNum (n); */ + if(!ti) return NULL; } return ti; } @@ -1923,7 +1913,7 @@ } } -void VymModel::moveUp() +void VymModel::moveUp() //FIXME-2 crashes if trying to move MCO { BranchItem *selbi=getSelectedBranch(); if (selbi) @@ -1996,8 +1986,9 @@ emit (layoutAboutToBeChanged() ); parix=index(dst); + if (!parix.isValid()) cout << "VM::createII invalid index\n"; n=dst->getRowNumAppend(newii); - beginInsertRows (parix,n,n+1); + beginInsertRows (parix,n,n); dst->appendChild (newii); endInsertRows (); @@ -2023,12 +2014,13 @@ cData << "new xLink"<<"undef"; XLinkItem *newxli=new XLinkItem(cData) ; + newxli->setBegin (bi); emit (layoutAboutToBeChanged() ); parix=index(bi); n=bi->getRowNumAppend(newxli); - beginInsertRows (parix,n,n+1); + beginInsertRows (parix,n,n); bi->appendChild (newxli); endInsertRows (); @@ -2036,7 +2028,6 @@ // save scroll state. If scrolled, automatically select // new branch in order to tmp unscroll parent... - newxli->setBegin (bi); if (createMO) { newxli->createMapObj(mapScene); @@ -2060,7 +2051,7 @@ QModelIndex parix=index(selbi); int n=selbi->getRowNumAppend (a); - beginInsertRows (parix,n,n+1); + beginInsertRows (parix,n,n); selbi->appendChild (a); endInsertRows (); @@ -2087,22 +2078,22 @@ return bi; } -BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?! +BranchItem* VymModel::addMapCenter(QPointF absPos) // createMapCenter could then probably be merged with createBranch { // Create TreeItem QModelIndex parix=index(rootItem); - int n=rootItem->branchCount(); - - emit (layoutAboutToBeChanged() ); - beginInsertRows (parix,n,n+1); - QList cData; cData << "VM:addMapCenter" << "undef"; BranchItem *newbi=new BranchItem (cData,rootItem); newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); + int n=rootItem->getRowNumAppend (newbi); + + emit (layoutAboutToBeChanged() ); + beginInsertRows (parix,n,n); + rootItem->appendChild (newbi); endInsertRows(); @@ -2110,12 +2101,13 @@ // Create MapObj newbi->setPositionMode (MapItem::Absolute); - newbi->createMapObj(mapScene); + BranchObj *bo=newbi->createMapObj(mapScene); + if (bo) bo->move (absPos); return newbi; } -BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) +BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) { // Depending on pos: // -3 insert in children of parent above selection @@ -2140,7 +2132,7 @@ parbi=dst; parix=index(parbi); n=parbi->getRowNumAppend (newbi); - beginInsertRows (parix,n,n+1); + beginInsertRows (parix,n,n); parbi->appendChild (newbi); endInsertRows (); }else if (num==-1 || num==-3) @@ -2350,7 +2342,7 @@ QString("Delete %1").arg(getObjectName(ti)) ); } - // FIXME-0 savestate missing for deletion of other times + // FIXME-1 savestate missing for deletion of other types than above unselect(); deleteItem (ti); emitDataHasChanged (pi); @@ -2576,22 +2568,20 @@ } } -void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) - { - FloatImageObj *fio=bo->addFloatImage(); - fio->load(img); - fio->setOriginalFilename("No original filename (image added by dropevent)"); - QString s=getSelectString(bo); - 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-3 VM needed? scene()->update(); - } -*/ +void VymModel::addFloatImage (const QPixmap &img) +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi) + { + ImageItem *ii=createImage (selbi); + ii->load(img); + ii->setOriginalFilename("No original filename (image added by dropevent)"); + QString s=getSelectString(selbi); + saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii ); + saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image"); + reposition(); + // FIXME-3 VM needed? scene()->update(); + } } @@ -3815,7 +3805,6 @@ void VymModel::exportImage(QString fname, bool askName, QString format) { -/* FIXME-2 export as image, but directly from mapEditor?! if (fname=="") { fname=getMapName()+".png"; @@ -3842,7 +3831,6 @@ QPixmap pix (mapEditor->getPixmap()); pix.save(fname, format); setExportMode (false); -*/ } @@ -4596,23 +4584,6 @@ mapEditor->setSelectionColor (col); } -/* -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,const QItemSelection &oldsel) //FIXME-4 connected but not used so far -{ -} - void VymModel::emitSelectionChanged(const QItemSelection &newsel) { emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor @@ -4914,13 +4885,13 @@ return getSelectString (getSelectedItem()); } -QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below... +QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor { if (!lmo) return QString(); return getSelectString (lmo->getTreeItem() ); } -QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:" +QString VymModel::getSelectString (TreeItem *ti) { QString s; if (!ti) return s;