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 ()
29 void VymModel::setMapEditor(MapEditor *me)
32 for (int i=0; i<mapCenters.count(); i++)
33 mapCenters.at(i)->setMapEditor(mapEditor);
36 MapEditor* VymModel::getMapEditor()
41 void VymModel::setVersion (const QString &s)
46 void VymModel::setAuthor (const QString &s)
51 QString VymModel::getAuthor()
56 void VymModel::setComment (const QString &s)
61 QString VymModel::getComment ()
66 QString VymModel::getDate ()
68 return QDate::currentDate().toString ("yyyy-MM-dd");
71 void VymModel::setScene (QGraphicsScene *s)
74 init(); // Here we have a mapScene set,
75 // which is (still) needed to create MapCenters
78 QGraphicsScene* VymModel::getScene ()
83 MapCenterObj* VymModel::addMapCenter()
85 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
86 mapCenter->setVisibility (true);
87 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
88 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
89 mapCenters.append(mapCenter);
93 MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
95 int i=mapCenters.indexOf (mco);
98 mapCenters.removeAt (i);
100 if (i>0) return mapCenters.at(i-1); // Return previous MCO
105 BranchObj* VymModel::first()
107 if (mapCenters.count()>0)
108 return mapCenters.first();
113 BranchObj* VymModel::next(BranchObj *bo_start)
116 BranchObj *bo=bo_start;
122 // Try to find MapCenter of bo
123 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
126 // Try to find next MapCenter
127 int i=mapCenters.indexOf ((MapCenterObj*)bo);
128 if (i+1 > mapCenters.count() || i<0) return NULL;
129 if (mapCenters.at(i)!=bo_start)
130 return mapCenters.at(i);
135 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
139 for (int i=0;i<mapCenters.count(); i++)
141 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
147 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
155 part=s.section(",",0,0);
157 num=part.right(part.length() - 3);
158 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
159 return mapCenters.at(num.toInt() );
162 for (int i=0; i<mapCenters.count(); i++)
164 lmo=mapCenters.at(i)->findObjBySelect(s);
170 LinkableMapObj* VymModel::findID (const QString &s)
173 for (int i=0; i<mapCenters.count(); i++)
175 lmo=mapCenters.at(i)->findID (s);
181 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
185 for (int i=0; i<mapCenters.count(); i++)
186 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
191 //////////////////////////////////////////////
193 //////////////////////////////////////////////
195 /* FIXME copied from MCO, still needed?
196 void VymModel::updateLink()
198 // set childPos to middle of MapCenterObj
199 childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
200 childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
202 for (int i=0; i<branch.size(); ++i)
203 branch.at(i)->updateLink();
207 void VymModel::updateRelPositions()
209 for (int i=0; i<mapCenters.count(); i++)
210 mapCenters.at(i)->updateRelPositions();
213 void VymModel::reposition()
215 for (int i=0;i<mapCenters.count(); i++)
216 mapCenters.at(i)->reposition(); // for positioning heading
221 //////////////////////////////////////////////
223 //////////////////////////////////////////////
226 // Only as long as we dont have Model/View yet
227 LinkableMapObj* VymModel::getSelection()
229 return mapEditor->getSelection();
231 BranchObj* VymModel::getSelectedBranch()
233 return mapEditor->getSelectedBranch();
237 bool VymModel::select (const QString &s)
239 return mapEditor->select (s);
242 QString VymModel::getSelectString (LinkableMapObj *lmo)
246 if (typeid(*lmo)==typeid(BranchObj) ||
247 typeid(*lmo)==typeid(MapCenterObj) )
249 LinkableMapObj *par=lmo->getParObj();
252 if (lmo->getDepth() ==1)
253 // Mainbranch, return
254 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
256 // Branch, call myself recursively
257 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
261 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
262 if (i>=0) s=QString("mc:%1").arg(i);
270 void VymModel::setHideTmp (HideTmpMode mode)
272 for (int i=0;i<mapCenters.count(); i++)
273 mapCenters.at(i)->setHideTmp (mode);
276 QRectF VymModel::getTotalBBox()
279 for (int i=0;i<mapCenters.count(); i++)
280 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);