insilmaril@650: #include insilmaril@650: insilmaril@650: #include "geometry.h" // for addBBox insilmaril@650: #include "vymmodel.h" insilmaril@650: insilmaril@650: VymModel::VymModel() insilmaril@650: { insilmaril@650: // cout << "Const VymModel\n"; insilmaril@650: } insilmaril@650: insilmaril@650: insilmaril@650: VymModel::~VymModel() insilmaril@650: { insilmaril@650: // cout << "Destr VymModel\n"; insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::clear() insilmaril@650: { insilmaril@665: while (!mapCenters.isEmpty()) insilmaril@665: delete mapCenters.takeFirst(); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::init () insilmaril@650: { insilmaril@660: addMapCenter(); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::setMapEditor(MapEditor *me) insilmaril@650: { insilmaril@650: mapEditor=me; insilmaril@650: for (int i=0; isetMapEditor(mapEditor); insilmaril@650: } insilmaril@650: insilmaril@650: MapEditor* VymModel::getMapEditor() insilmaril@650: { insilmaril@650: return mapEditor; insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::setVersion (const QString &s) insilmaril@650: { insilmaril@650: version=s; insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::setAuthor (const QString &s) insilmaril@650: { insilmaril@650: author=s; insilmaril@650: } insilmaril@650: insilmaril@650: QString VymModel::getAuthor() insilmaril@650: { insilmaril@650: return author; insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::setComment (const QString &s) insilmaril@650: { insilmaril@650: comment=s; insilmaril@650: } insilmaril@650: insilmaril@650: QString VymModel::getComment () insilmaril@650: { insilmaril@650: return comment; insilmaril@650: } insilmaril@650: insilmaril@650: QString VymModel::getDate () insilmaril@650: { insilmaril@650: return QDate::currentDate().toString ("yyyy-MM-dd"); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::setScene (QGraphicsScene *s) insilmaril@650: { insilmaril@650: mapScene=s; insilmaril@650: init(); // Here we have a mapScene set, insilmaril@650: // which is (still) needed to create MapCenters insilmaril@650: } insilmaril@650: insilmaril@650: QGraphicsScene* VymModel::getScene () insilmaril@650: { insilmaril@650: return mapScene; insilmaril@650: } insilmaril@650: insilmaril@650: MapCenterObj* VymModel::addMapCenter() insilmaril@650: { insilmaril@650: MapCenterObj *mapCenter = new MapCenterObj(mapScene); insilmaril@650: mapCenter->setVisibility (true); insilmaril@650: mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); insilmaril@650: mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects insilmaril@650: mapCenters.append(mapCenter); insilmaril@650: return mapCenter; insilmaril@650: } insilmaril@650: insilmaril@650: MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco) insilmaril@650: { insilmaril@650: int i=mapCenters.indexOf (mco); insilmaril@650: if (i>=0) insilmaril@650: { insilmaril@650: mapCenters.removeAt (i); insilmaril@650: delete (mco); insilmaril@650: if (i>0) return mapCenters.at(i-1); // Return previous MCO insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: BranchObj* VymModel::first() insilmaril@650: { insilmaril@650: if (mapCenters.count()>0) insilmaril@650: return mapCenters.first(); insilmaril@650: else insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: BranchObj* VymModel::next(BranchObj *bo_start) insilmaril@650: { insilmaril@650: BranchObj *rbo; insilmaril@650: BranchObj *bo=bo_start; insilmaril@650: if (bo) insilmaril@650: { insilmaril@665: // Try to find next branch in current MapCenter insilmaril@650: rbo=bo->next(); insilmaril@650: if (rbo) return rbo; insilmaril@650: insilmaril@650: // Try to find MapCenter of bo insilmaril@650: while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj(); insilmaril@650: insilmaril@650: insilmaril@650: // Try to find next MapCenter insilmaril@650: int i=mapCenters.indexOf ((MapCenterObj*)bo); insilmaril@650: if (i+1 > mapCenters.count() || i<0) return NULL; insilmaril@650: if (mapCenters.at(i)!=bo_start) insilmaril@650: return mapCenters.at(i); insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO) insilmaril@650: { insilmaril@650: LinkableMapObj *lmo; insilmaril@650: insilmaril@650: for (int i=0;ifindMapObj (p,excludeLMO); insilmaril@650: if (lmo) return lmo; insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: LinkableMapObj* VymModel::findObjBySelect(const QString &s) insilmaril@650: { insilmaril@650: LinkableMapObj *lmo; insilmaril@650: if (!s.isEmpty() ) insilmaril@650: { insilmaril@650: QString part; insilmaril@650: QString typ; insilmaril@650: QString num; insilmaril@650: part=s.section(",",0,0); insilmaril@652: typ=part.left (2); insilmaril@650: num=part.right(part.length() - 3); insilmaril@650: if (typ=="mc" && num.toInt()>=0 && num.toInt() findObjBySelect(s); insilmaril@650: if (lmo) return lmo; insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: LinkableMapObj* VymModel::findID (const QString &s) insilmaril@650: { insilmaril@650: LinkableMapObj *lmo; insilmaril@650: for (int i=0; ifindID (s); insilmaril@650: if (lmo) return lmo; insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) insilmaril@650: { insilmaril@650: QString s; insilmaril@650: insilmaril@650: for (int i=0; isaveToDir (tmpdir,prefix,verbose,offset); insilmaril@650: return s; insilmaril@650: } insilmaril@650: insilmaril@650: insilmaril@652: ////////////////////////////////////////////// insilmaril@652: // View related insilmaril@652: ////////////////////////////////////////////// insilmaril@652: insilmaril@652: /* FIXME copied from MCO, still needed? insilmaril@652: void VymModel::updateLink() insilmaril@652: { insilmaril@652: // set childPos to middle of MapCenterObj insilmaril@652: childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 ); insilmaril@652: childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 ); insilmaril@652: parPos=childPos; insilmaril@652: for (int i=0; iupdateLink(); insilmaril@652: } insilmaril@652: insilmaril@652: */ insilmaril@652: void VymModel::updateRelPositions() insilmaril@652: { insilmaril@652: for (int i=0; iupdateRelPositions(); insilmaril@652: } insilmaril@652: insilmaril@652: void VymModel::reposition() insilmaril@652: { insilmaril@652: for (int i=0;ireposition(); // for positioning heading insilmaril@652: } insilmaril@652: insilmaril@665: QPolygonF VymModel::shape(BranchObj *bo) insilmaril@665: { insilmaril@665: // Creating (arbitrary) shapes insilmaril@665: insilmaril@665: QPolygonF p; insilmaril@665: QRectF rb=bo->getBBox(); insilmaril@665: if (bo->getDepth()==0) insilmaril@665: { insilmaril@665: // Just take BBox of this mapCenter insilmaril@665: p<getTotalBBox(); insilmaril@665: if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@665: p <" insilmaril@665: <<"="<getHeading() )<<")" insilmaril@665: <<" with ("<< qPrintable (boB->getHeading() ) insilmaril@665: <<") willIntersect" insilmaril@665: <getNum()); insilmaril@652: else insilmaril@652: // Branch, call myself recursively insilmaril@652: s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); insilmaril@652: } else insilmaril@652: { insilmaril@652: // MapCenter insilmaril@652: int i=mapCenters.indexOf ((MapCenterObj*)lmo); insilmaril@652: if (i>=0) s=QString("mc:%1").arg(i); insilmaril@652: } insilmaril@652: } insilmaril@652: return s; insilmaril@652: insilmaril@652: } insilmaril@652: insilmaril@652: insilmaril@652: void VymModel::setHideTmp (HideTmpMode mode) insilmaril@652: { insilmaril@652: for (int i=0;isetHideTmp (mode); insilmaril@652: } insilmaril@652: insilmaril@652: QRectF VymModel::getTotalBBox() insilmaril@652: { insilmaril@652: QRectF r; insilmaril@652: for (int i=0;igetTotalBBox(), r); insilmaril@652: return r; insilmaril@652: } insilmaril@652: