6 #include "flagrowobj.h"
10 /////////////////////////////////////////////////////////////////
12 /////////////////////////////////////////////////////////////////
13 FlagRowObj::FlagRowObj()
15 // cout << "Const FlagRowObj ()\n";
19 FlagRowObj::FlagRowObj(QGraphicsScene* s):MapObj(s)
21 // cout << "Const FlagRowObj (s)\n";
25 FlagRowObj::~FlagRowObj()
27 //cout << "Destr FlagRowObj\n";
28 while (!flag.isEmpty())
29 delete (flag.takeFirst() );
32 void FlagRowObj::init ()
38 void FlagRowObj::copy (FlagRowObj* other)
41 parentRow=other->parentRow;
43 for (int i=0; i<flag.size(); ++i)
47 void FlagRowObj::clone (FlagRowObj* pr)
49 // Difference to copy:
50 // We don't copy the flags here, they
51 // are created on the fly by toggle and activate
52 // This saves lots of canvas objects.
58 void FlagRowObj::move(double x, double y)
62 for (int i=0; i<flag.size(); ++i)
64 flag.at(i)->move(x+dx,y);
65 dx+=QSizeF(flag.at(i)->getSize() ).width();
69 void FlagRowObj::moveBy(double x, double y)
71 move (x+absPos.x(),y+absPos.y() );
74 void FlagRowObj::setVisibility (bool v)
76 MapObj::setVisibility(v);
77 for (int i=0; i<flag.size(); ++i)
78 flag.at(i)->setVisibility (v);
81 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
83 FlagObj *newfo=new FlagObj (scene);
84 newfo->copy (fo); // create a deep copy of fo
85 newfo->move (absPos.x() + bbox.width(), absPos.y() );
92 void FlagRowObj::positionBBox()
94 bbox.moveTopLeft(absPos );
95 clickBox.moveTopLeft(absPos );
98 void FlagRowObj::calcBBoxSize()
102 for (int i=0; i<flag.size(); ++i)
104 size=flag.at(i)->getSize();
106 boxsize.setWidth(boxsize.width() + size.width() );
108 if (size.height() > boxsize.height() )
109 boxsize.setHeight(size.height() );
111 bbox.setSize (boxsize);
112 clickBox.setSize (boxsize);
115 QString FlagRowObj::getFlagName (const QPointF &p)
117 if (!isInBox (p,clickBox)) return "";
118 for (int i=0; i<flag.size(); ++i)
119 if (isInBox (p,flag.at(i)->getClickBox ())) return flag.at(i)->getName();
125 bool FlagRowObj::isActive (const QString &foname)
127 FlagObj *fo=findFlag (foname);
129 return fo->isActive();
135 void FlagRowObj::toggle (const QString &foname)
137 FlagObj *fo=findFlag (foname);
140 // FlagObj is here, it will be active, too.
141 // Deactivate it by removing it from this row.
146 // FlagObj is not present in this row.
147 // Copy it from parentRow
148 fo=parentRow->findFlag (foname);
153 /*FIXME-0 move to VM if (exclusive)
155 deactivateGroup (fo);
160 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
166 void FlagRowObj::activate (const QString &foname)
168 cout << "FRO::activate "<<foname.toStdString()<<endl;
169 // Note: "activate" is also called during loading of a map
170 // Here we do not check for exclusive flags!
171 FlagObj *fo=findFlag (foname);
176 // FlagObj is not present in this row.
177 // Copy it from parentRow and activate there
178 fo=parentRow->findFlag (foname);
184 fo->setVisibility (visible);
186 fo->setVisibility (false);
189 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
193 // I am the parentRow, mark flag as used
200 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
205 void FlagRowObj::deactivate (const QString &foname)
207 FlagObj *fo=findFlag (foname);
217 void FlagRowObj::deactivateAll ()
221 for (int i=0; i<flag.size(); ++i)
222 if (flag.at(i)->isActive()) flag.at(i)->deactivate();
225 while (!flag.isEmpty())
226 delete flag.takeFirst();
232 void FlagRowObj::deactivateGroup (FlagObj *keepfo) //FIXME-0 move to VM
234 // deactivate all flags in keepof, but keep keepfo [sic!]
237 QString g=keepfo->getGroup();
240 for (int i=0; i<flag.size(); ++i)
241 if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i))
243 FlagObj *fo=flag.at(i);
251 void FlagRowObj::setToolBar(QToolBar *tb)
256 void FlagRowObj::setEnabled (bool b)
260 toolbar->setEnabled (b);
264 void FlagRowObj::setShowFlags (bool b)
269 void FlagRowObj::resetUsedCounter()
271 for (int i=0; i<flag.size(); ++i)
272 flag.at(i)->setUsed (false);
275 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
280 for (int i=0; i<flag.size(); ++i)
282 // save flag to xml, if flag is set
283 s+=valueElement("standardflag",flag.at(i)->getName() );
285 // and tell parentRow, that this flag is used
286 parentRow->activate(flag.at(i)->getName() );
289 // Save icons to dir, if verbose is set (xml export)
290 // and I am a parentRow
291 // and this flag is really used somewhere
293 for (int i=0; i<flag.size(); ++i)
294 if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
299 void FlagRowObj::setName (const QString &n)
304 void FlagRowObj::updateToolbar() //FIXME-2 this needs to be changed with VM
308 // We are just a branch, not the toolbar default
309 // but state has to be copied from ourselves to parentrow!
310 parentRow->deactivateAll();
311 // In parentRow activate all existing (==active) flags
312 for (int i=0; i<flag.size(); ++i)
313 parentRow->activate(flag.at(i)->getName());
314 parentRow->updateToolbar();
317 // We are the toolbar default
320 // Update state of actions in toolbar
321 for (int i=0; i<flag.size(); ++i)
322 flag.at(i)->updateAction();
327 FlagObj* FlagRowObj::findFlag (const QString &name)
329 for (int i=0; i<flag.size(); ++i)
330 if (flag.at(i)->getName()==name) return flag.at(i);