diff -r 4004e795b1ad -r 65c5a0c28d20 vymmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vymmodel.cpp Tue Jan 15 10:54:41 2008 +0000 @@ -0,0 +1,311 @@ +#include + +#include "geometry.h" // for addBBox +#include "vymmodel.h" + +VymModel::VymModel() +{ +// cout << "Const VymModel\n"; +} + + +VymModel::~VymModel() +{ +// cout << "Destr VymModel\n"; +} + +void VymModel::clear() +{ + for (int i=0; iclear(); + mapCenters.clear(); +} + +void VymModel::init () +{ +} + +void VymModel::setMapEditor(MapEditor *me) +{ + mapEditor=me; + for (int i=0; isetMapEditor(mapEditor); +} + +MapEditor* VymModel::getMapEditor() +{ + return mapEditor; +} + +void VymModel::setVersion (const QString &s) +{ + version=s; +} + +void VymModel::setAuthor (const QString &s) +{ + author=s; +} + +QString VymModel::getAuthor() +{ + return author; +} + +void VymModel::setComment (const QString &s) +{ + comment=s; +} + +QString VymModel::getComment () +{ + return comment; +} + +QString VymModel::getDate () +{ + return QDate::currentDate().toString ("yyyy-MM-dd"); +} + +void VymModel::setScene (QGraphicsScene *s) +{ + mapScene=s; + init(); // Here we have a mapScene set, + // which is (still) needed to create MapCenters +} + +QGraphicsScene* VymModel::getScene () +{ + return mapScene; +} + +MapCenterObj* VymModel::addMapCenter() +{ + MapCenterObj *mapCenter = new MapCenterObj(mapScene); + mapCenter->setVisibility (true); + mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); + mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects + mapCenters.append(mapCenter); + return mapCenter; +} + +MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco) +{ + int i=mapCenters.indexOf (mco); + if (i>=0) + { + mapCenters.removeAt (i); + delete (mco); + if (i>0) return mapCenters.at(i-1); // Return previous MCO + } + return NULL; +} + +// Only as long as we dont have Model/View yet +LinkableMapObj* VymModel::getSelection() +{ + return mapEditor->getSelection(); +} +BranchObj* VymModel::getSelectedBranch() +{ + return mapEditor->getSelectedBranch(); +} + +bool VymModel::select (const QString &s) +{ + LinkableMapObj *lmo=model->findObjBySelect(s); + +/* + // Finally select the found object + if (lmo) + { + xelection.unselect(); + xelection.select(lmo); + xelection.update(); + ensureSelectionVisible(); + sendSelection (); + return true; + } + return false; +*/ +} + +QString VymModel::getSelectString (LinkableMapObj *lmo) +{ + QString s; + if (!lmo) return s; + if (typeid(*lmo)==typeid(BranchObj) || + typeid(*lmo)==typeid(MapCenterObj) ) + { + LinkableMapObj *par=lmo->getParObj(); + if (par) + { + if (lmo->getDepth() ==1) + // Mainbranch, return + s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + else + // Branch, call myself recursively + s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + } else + { + // MapCenter + int i=mapCenters.indexOf ((MapCenterObj*)lmo); + if (i>=0) s=QString("mc:%1").arg(i); + } + } + return s; + +} + +/* FIXME copied from MCO, still needed? +void VymModel::move (double x, double y) +{ + BranchObj::move(x,y); +} + +void VymModel::moveBy (double x, double y) +{ + BranchObj::moveBy(x,y); +} + +void VymModel::moveAll (double x, double y) +{ + // Get rel. position + double dx=x-absPos.x(); + double dy=y-absPos.y(); + + // Move myself and branches + moveAllBy (dx,dy); +} + +void VymModel::moveAllBy (double dx, double dy) +{ + // Move myself and childs + BranchObj::moveBy(dx,dy); +} +*/ +BranchObj* VymModel::first() +{ + if (mapCenters.count()>0) + return mapCenters.first(); + else + return NULL; +} + +BranchObj* VymModel::next(BranchObj *bo_start) +{ + BranchObj *rbo; + BranchObj *bo=bo_start; + if (bo) + { + rbo=bo->next(); + if (rbo) return rbo; + + // Try to find MapCenter of bo + while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj(); + + + // Try to find next MapCenter + int i=mapCenters.indexOf ((MapCenterObj*)bo); + if (i+1 > mapCenters.count() || i<0) return NULL; + if (mapCenters.at(i)!=bo_start) + return mapCenters.at(i); + } + return NULL; + +} + + /* FIXME copied from MCO, still needed? +void VymModel::updateLink() +{ + // set childPos to middle of MapCenterObj + childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 ); + childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 ); + parPos=childPos; + for (int i=0; iupdateLink(); +} + +*/ +void VymModel::updateRelPositions() +{ + for (int i=0; iupdateRelPositions(); +} + +void VymModel::reposition() +{ + for (int i=0;ireposition(); // for positioning heading +} + +void VymModel::setHideTmp (HideTmpMode mode) +{ + for (int i=0;isetHideTmp (mode); +} + +QRectF VymModel::getTotalBBox() +{ + QRectF r; + for (int i=0;igetTotalBBox(), r); + return r; +} + +LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO) +{ + LinkableMapObj *lmo; + + for (int i=0;ifindMapObj (p,excludeLMO); + if (lmo) return lmo; + } + return NULL; +} + +LinkableMapObj* VymModel::findObjBySelect(const QString &s) +{ + LinkableMapObj *lmo; + if (!s.isEmpty() ) + { + QString part; + QString typ; + QString num; + part=s.section(",",0,0); + typ=part.left (3); + num=part.right(part.length() - 3); + if (typ=="mc" && num.toInt()>=0 && num.toInt() findObjBySelect(s); + if (lmo) return lmo; + } + return NULL; +} + +LinkableMapObj* VymModel::findID (const QString &s) +{ + LinkableMapObj *lmo; + for (int i=0; ifindID (s); + if (lmo) return lmo; + } + return NULL; +} + +QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) +{ + QString s; + + for (int i=0; isaveToDir (tmpdir,prefix,verbose,offset); + return s; +} + +