diff -r e37153bea487 -r 394b2f297e1d vymmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vymmodel.cpp Thu Jul 17 11:11:55 2008 +0000 @@ -0,0 +1,395 @@ +#include +#include + +#include "geometry.h" // for addBBox +#include "vymmodel.h" + + +extern Settings settings; + +VymModel::VymModel() +{ +// cout << "Const VymModel\n"; +} + + +VymModel::~VymModel() +{ +// cout << "Destr VymModel\n"; +} + +void VymModel::clear() +{ + while (!mapCenters.isEmpty()) + delete mapCenters.takeFirst(); +} + +void VymModel::init () +{ + addMapCenter(); + + // animations + animationUse=settings.readBoolEntry("/animation/use",false); + animationTicks=settings.readNumEntry("/animation/ticks",10); + animationInterval=settings.readNumEntry("/animation/interval",50); + animObjList.clear(); + animationTimer=new QTimer (this); + connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate())); + +} + +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() +{ + return addMapCenter (QPointF(0,0)); +} + +MapCenterObj* VymModel::addMapCenter(QPointF absPos) +{ + MapCenterObj *mapCenter = new MapCenterObj(mapScene); + mapCenter->move (absPos); + 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; +} + +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) + { + // Try to find next branch in current MapCenter + 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+2 > mapCenters.count() || i<0) return NULL; + if (mapCenters.at(i+1)!=bo_start) + return mapCenters.at(i+1); + } + return NULL; +} + +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 (2); + 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; +} + + +////////////////////////////////////////////// +// View related +////////////////////////////////////////////// + +void VymModel::updateRelPositions() +{ + for (int i=0; iupdateRelPositions(); +} + +void VymModel::reposition() +{ + for (int i=0;ireposition(); // for positioning heading +} + +QPolygonF VymModel::shape(BranchObj *bo) +{ + // Creating (arbitrary) shapes + + QPolygonF p; + QRectF rb=bo->getBBox(); + if (bo->getDepth()==0) + { + // Just take BBox of this mapCenter + p<getTotalBBox(); + if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) + p <" + <<"="<getHeading() )<<")" + <<" with ("<< qPrintable (boB->getHeading() ) + <<") willIntersect" + <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; + +} + + +void VymModel::setHideTmp (HideTmpMode mode) +{ + for (int i=0;isetHideTmp (mode); +} + +QRectF VymModel::getTotalBBox() +{ + QRectF r; + for (int i=0;igetTotalBBox(), r); + return r; +} +