1 #include "flagrowobj.h"
6 /////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////
9 FlagRowObj::FlagRowObj()
11 // cout << "Const FlagRowObj ()\n";
15 FlagRowObj::FlagRowObj(QGraphicsScene* s):MapObj(s)
17 // cout << "Const FlagRowObj (s)\n";
21 FlagRowObj::~FlagRowObj()
23 //cout << "Destr FlagRowObj\n";
24 while (!flag.isEmpty())
25 delete (flag.takeFirst() );
28 void FlagRowObj::init ()
34 void FlagRowObj::copy (FlagRowObj* other)
37 parentRow=other->parentRow;
39 for (int i=0; i<flag.size(); ++i)
43 void FlagRowObj::clone (FlagRowObj* pr)
45 // Difference to copy:
46 // We don't copy the flags here, they
47 // are created on the fly by toggle and activate
48 // This saves lots of canvas objects.
54 void FlagRowObj::move(double x, double y)
58 for (int i=0; i<flag.size(); ++i)
60 flag.at(i)->move(x+dx,y);
61 dx+=QSizeF(flag.at(i)->getSize() ).width();
65 void FlagRowObj::moveBy(double x, double y)
67 move (x+absPos.x(),y+absPos.y() );
70 void FlagRowObj::setVisibility (bool v)
72 MapObj::setVisibility(v);
73 for (int i=0; i<flag.size(); ++i)
74 flag.at(i)->setVisibility (v);
77 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
79 FlagObj *newfo=new FlagObj (scene);
80 newfo->copy (fo); // create a deep copy of fo
81 newfo->move (absPos.x() + bbox.width(), absPos.y() );
88 void FlagRowObj::positionBBox()
90 bbox.moveTopLeft(absPos );
91 clickBox.moveTopLeft(absPos );
94 void FlagRowObj::calcBBoxSize()
98 for (int i=0; i<flag.size(); ++i)
100 size=flag.at(i)->getSize();
102 boxsize.setWidth(boxsize.width() + size.width() );
104 if (size.height() > boxsize.height() )
105 boxsize.setHeight(size.height() );
107 bbox.setSize (boxsize);
108 clickBox.setSize (boxsize);
111 QString FlagRowObj::getFlagName (const QPointF &p)
113 if (!inBox (p,clickBox)) return "";
114 for (int i=0; i<flag.size(); ++i)
115 if (inBox (p,flag.at(i)->getClickBox ())) return flag.at(i)->getName();
121 bool FlagRowObj::isActive (const QString &foname)
123 FlagObj *fo=findFlag (foname);
125 return fo->isActive();
131 void FlagRowObj::toggle (const QString &foname, bool exclusive)
133 FlagObj *fo=findFlag (foname);
136 // FlagObj is here, it will be active, too.
137 // Deactivate it by removing it from this row.
142 // FlagObj is not present in this row.
143 // Copy it from parentRow
144 fo=parentRow->findFlag (foname);
151 deactivateGroup (fo);
155 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
161 void FlagRowObj::activate (const QString &foname)
163 // Note: "activate" is also called during loading of a map
164 // Here we do not check for exclusive flags!
165 FlagObj *fo=findFlag (foname);
170 // FlagObj is not present in this row.
171 // Copy it from parentRow and activate there
172 fo=parentRow->findFlag (foname);
178 fo->setVisibility (visible);
180 fo->setVisibility (false);
183 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
187 // I am the parentRow, mark flag as used
194 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
199 void FlagRowObj::deactivate (const QString &foname)
201 FlagObj *fo=findFlag (foname);
211 void FlagRowObj::deactivateAll ()
215 for (int i=0; i<flag.size(); ++i)
216 if (flag.at(i)->isActive()) flag.at(i)->deactivate();
219 while (!flag.isEmpty())
220 delete flag.takeFirst();
226 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
228 // deactivate all flags in keepof, but keep keepfo [sic!]
231 QString g=keepfo->getGroup();
234 for (int i=0; i<flag.size(); ++i)
235 if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i))
237 FlagObj *fo=flag.at(i);
245 void FlagRowObj::setToolBar(QToolBar *tb)
250 void FlagRowObj::setEnabled (bool b)
254 toolbar->setEnabled (b);
258 void FlagRowObj::setShowFlags (bool b)
263 void FlagRowObj::resetUsedCounter()
265 for (int i=0; i<flag.size(); ++i)
266 flag.at(i)->setUsed (false);
269 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
274 for (int i=0; i<flag.size(); ++i)
276 // save flag to xml, if flag is set
277 s+=valueElement("standardflag",flag.at(i)->getName() );
279 // and tell parentRow, that this flag is used
280 parentRow->activate(flag.at(i)->getName() );
283 // Save icons to dir, if verbose is set (xml export)
284 // and I am a parentRow
285 // and this flag is really used somewhere
287 for (int i=0; i<flag.size(); ++i)
288 if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
293 void FlagRowObj::setName (const QString &n)
298 void FlagRowObj::updateToolbar()
302 // We are just a branch, not the toolbar default
303 // but state has to be copied from ourselves to parentrow!
304 parentRow->deactivateAll();
305 // In parentRow activate all existing (==active) flags
306 for (int i=0; i<flag.size(); ++i)
307 parentRow->activate(flag.at(i)->getName());
308 parentRow->updateToolbar();
311 // We are the toolbar default
314 // Update state of actions in toolbar
315 for (int i=0; i<flag.size(); ++i)
316 flag.at(i)->updateAction();
321 FlagObj* FlagRowObj::findFlag (const QString &name)
323 for (int i=0; i<flag.size(); ++i)
324 if (flag.at(i)->getName()==name) return flag.at(i);