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 BranchObj* VymModel::first()
106 if (mapCenters.count()>0)
107 return mapCenters.first();
112 BranchObj* VymModel::next(BranchObj *bo_start)
115 BranchObj *bo=bo_start;
121 // Try to find MapCenter of bo
122 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
125 // Try to find next MapCenter
126 int i=mapCenters.indexOf ((MapCenterObj*)bo);
127 if (i+1 > mapCenters.count() || i<0) return NULL;
128 if (mapCenters.at(i)!=bo_start)
129 return mapCenters.at(i);
134 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
138 for (int i=0;i<mapCenters.count(); i++)
140 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
146 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
154 part=s.section(",",0,0);
156 num=part.right(part.length() - 3);
157 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
158 return mapCenters.at(num.toInt() );
161 for (int i=0; i<mapCenters.count(); i++)
163 lmo=mapCenters.at(i)->findObjBySelect(s);
169 LinkableMapObj* VymModel::findID (const QString &s)
172 for (int i=0; i<mapCenters.count(); i++)
174 lmo=mapCenters.at(i)->findID (s);
180 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
184 for (int i=0; i<mapCenters.count(); i++)
185 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
190 //////////////////////////////////////////////
192 //////////////////////////////////////////////
194 /* FIXME copied from MCO, still needed?
195 void VymModel::updateLink()
197 // set childPos to middle of MapCenterObj
198 childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
199 childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
201 for (int i=0; i<branch.size(); ++i)
202 branch.at(i)->updateLink();
206 void VymModel::updateRelPositions()
208 for (int i=0; i<mapCenters.count(); i++)
209 mapCenters.at(i)->updateRelPositions();
212 void VymModel::reposition()
214 for (int i=0;i<mapCenters.count(); i++)
215 mapCenters.at(i)->reposition(); // for positioning heading
220 //////////////////////////////////////////////
222 //////////////////////////////////////////////
225 // Only as long as we dont have Model/View yet
226 LinkableMapObj* VymModel::getSelection()
228 return mapEditor->getSelection();
230 BranchObj* VymModel::getSelectedBranch()
232 return mapEditor->getSelectedBranch();
236 bool VymModel::select (const QString &s)
238 return mapEditor->select (s);
241 QString VymModel::getSelectString (LinkableMapObj *lmo)
245 if (typeid(*lmo)==typeid(BranchObj) ||
246 typeid(*lmo)==typeid(MapCenterObj) )
248 LinkableMapObj *par=lmo->getParObj();
251 if (lmo->getDepth() ==1)
252 // Mainbranch, return
253 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
255 // Branch, call myself recursively
256 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
260 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
261 if (i>=0) s=QString("mc:%1").arg(i);
269 void VymModel::setHideTmp (HideTmpMode mode)
271 for (int i=0;i<mapCenters.count(); i++)
272 mapCenters.at(i)->setHideTmp (mode);
275 QRectF VymModel::getTotalBBox()
278 for (int i=0;i<mapCenters.count(); i++)
279 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);