1 #include <QApplication>
3 #include "geometry.h" // for addBBox
8 // cout << "Const VymModel\n";
14 // cout << "Destr VymModel\n";
17 void VymModel::clear()
19 for (int i=0; i<mapCenters.count(); i++)
20 mapCenters.at(i)->clear();
24 void VymModel::init ()
28 void VymModel::setMapEditor(MapEditor *me)
31 for (int i=0; i<mapCenters.count(); i++)
32 mapCenters.at(i)->setMapEditor(mapEditor);
35 MapEditor* VymModel::getMapEditor()
40 void VymModel::setVersion (const QString &s)
45 void VymModel::setAuthor (const QString &s)
50 QString VymModel::getAuthor()
55 void VymModel::setComment (const QString &s)
60 QString VymModel::getComment ()
65 QString VymModel::getDate ()
67 return QDate::currentDate().toString ("yyyy-MM-dd");
70 void VymModel::setScene (QGraphicsScene *s)
73 init(); // Here we have a mapScene set,
74 // which is (still) needed to create MapCenters
77 QGraphicsScene* VymModel::getScene ()
82 MapCenterObj* VymModel::addMapCenter()
84 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
85 mapCenter->setVisibility (true);
86 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
87 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
88 mapCenters.append(mapCenter);
92 MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
94 int i=mapCenters.indexOf (mco);
97 mapCenters.removeAt (i);
99 if (i>0) return mapCenters.at(i-1); // Return previous MCO
104 // Only as long as we dont have Model/View yet
105 LinkableMapObj* VymModel::getSelection()
107 return mapEditor->getSelection();
109 BranchObj* VymModel::getSelectedBranch()
111 return mapEditor->getSelectedBranch();
114 bool VymModel::select (const QString &s)
116 LinkableMapObj *lmo=model->findObjBySelect(s);
119 // Finally select the found object
122 xelection.unselect();
123 xelection.select(lmo);
125 ensureSelectionVisible();
133 QString VymModel::getSelectString (LinkableMapObj *lmo)
137 if (typeid(*lmo)==typeid(BranchObj) ||
138 typeid(*lmo)==typeid(MapCenterObj) )
140 LinkableMapObj *par=lmo->getParObj();
143 if (lmo->getDepth() ==1)
144 // Mainbranch, return
145 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
147 // Branch, call myself recursively
148 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
152 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
153 if (i>=0) s=QString("mc:%1").arg(i);
160 /* FIXME copied from MCO, still needed?
161 void VymModel::move (double x, double y)
163 BranchObj::move(x,y);
166 void VymModel::moveBy (double x, double y)
168 BranchObj::moveBy(x,y);
171 void VymModel::moveAll (double x, double y)
174 double dx=x-absPos.x();
175 double dy=y-absPos.y();
177 // Move myself and branches
181 void VymModel::moveAllBy (double dx, double dy)
183 // Move myself and childs
184 BranchObj::moveBy(dx,dy);
187 BranchObj* VymModel::first()
189 if (mapCenters.count()>0)
190 return mapCenters.first();
195 BranchObj* VymModel::next(BranchObj *bo_start)
198 BranchObj *bo=bo_start;
204 // Try to find MapCenter of bo
205 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
208 // Try to find next MapCenter
209 int i=mapCenters.indexOf ((MapCenterObj*)bo);
210 if (i+1 > mapCenters.count() || i<0) return NULL;
211 if (mapCenters.at(i)!=bo_start)
212 return mapCenters.at(i);
218 /* FIXME copied from MCO, still needed?
219 void VymModel::updateLink()
221 // set childPos to middle of MapCenterObj
222 childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
223 childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
225 for (int i=0; i<branch.size(); ++i)
226 branch.at(i)->updateLink();
230 void VymModel::updateRelPositions()
232 for (int i=0; i<mapCenters.count(); i++)
233 mapCenters.at(i)->updateRelPositions();
236 void VymModel::reposition()
238 for (int i=0;i<mapCenters.count(); i++)
239 mapCenters.at(i)->reposition(); // for positioning heading
242 void VymModel::setHideTmp (HideTmpMode mode)
244 for (int i=0;i<mapCenters.count(); i++)
245 mapCenters.at(i)->setHideTmp (mode);
248 QRectF VymModel::getTotalBBox()
251 for (int i=0;i<mapCenters.count(); i++)
252 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
256 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
260 for (int i=0;i<mapCenters.count(); i++)
262 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
268 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
276 part=s.section(",",0,0);
278 num=part.right(part.length() - 3);
279 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
280 return mapCenters.at(num.toInt() );
283 for (int i=0; i<mapCenters.count(); i++)
285 lmo=mapCenters.at(i)->findObjBySelect(s);
291 LinkableMapObj* VymModel::findID (const QString &s)
294 for (int i=0; i<mapCenters.count(); i++)
296 lmo=mapCenters.at(i)->findID (s);
302 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
306 for (int i=0; i<mapCenters.count(); i++)
307 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);