1 #include "flagrowobj.h"
5 /////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////
8 FlagRowObj::FlagRowObj()
10 // cout << "Const FlagRowObj ()\n";
14 FlagRowObj::FlagRowObj(QGraphicsScene* s):MapObj(s)
16 // cout << "Const FlagRowObj (s)\n";
20 FlagRowObj::~FlagRowObj()
22 //cout << "Destr FlagRowObj\n";
23 while (!flag.isEmpty())
24 delete (flag.takeFirst() );
27 void FlagRowObj::init ()
33 void FlagRowObj::copy (FlagRowObj* other)
36 parentRow=other->parentRow;
38 for (int i=0; i<flag.size(); ++i)
42 void FlagRowObj::clone (FlagRowObj* pr)
44 // Difference to copy:
45 // We don't copy the flags here, they
46 // are created on the fly by toggle and activate
47 // This saves lots of canvas objects.
53 void FlagRowObj::move(double x, double y)
57 for (int i=0; i<flag.size(); ++i)
59 flag.at(i)->move(x+dx,y);
60 dx+=QSizeF(flag.at(i)->getSize() ).width();
64 void FlagRowObj::moveBy(double x, double y)
66 move (x+absPos.x(),y+absPos.y() );
69 void FlagRowObj::setVisibility (bool v)
71 MapObj::setVisibility(v);
72 for (int i=0; i<flag.size(); ++i)
73 flag.at(i)->setVisibility (v);
76 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
78 FlagObj *newfo=new FlagObj (scene);
79 newfo->copy (fo); // create a deep copy of fo
80 newfo->move (absPos.x() + bbox.width(), absPos.y() );
87 void FlagRowObj::positionBBox()
89 bbox.moveTopLeft(absPos );
90 clickBox.moveTopLeft(absPos );
93 void FlagRowObj::calcBBoxSize()
97 for (int i=0; i<flag.size(); ++i)
99 size=flag.at(i)->getSize();
101 boxsize.setWidth(boxsize.width() + size.width() );
103 if (size.height() > boxsize.height() )
104 boxsize.setHeight(size.height() );
106 bbox.setSize (boxsize);
107 clickBox.setSize (boxsize);
110 QString FlagRowObj::getFlagName (const QPointF &p)
112 if (!inBox (p)) return "";
113 for (int i=0; i<flag.size(); ++i)
114 if (flag.at(i)->inBox (p)) return flag.at(i)->getName();
120 bool FlagRowObj::isActive (const QString &foname)
122 FlagObj *fo=findFlag (foname);
124 return fo->isActive();
130 void FlagRowObj::toggle (const QString &foname, bool exclusive)
132 FlagObj *fo=findFlag (foname);
135 // FlagObj is here, it will be active, too.
136 // Deactivate it by removing it from this row.
141 // FlagObj is not present in this row.
142 // Copy it from parentRow
143 fo=parentRow->findFlag (foname);
150 deactivateGroup (fo);
154 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
160 void FlagRowObj::activate (const QString &foname)
162 // Note: "activate" is also called during loading of a map
163 // Here we do not check for exclusive flags!
164 FlagObj *fo=findFlag (foname);
169 // FlagObj is not present in this row.
170 // Copy it from parentRow and activate there
171 fo=parentRow->findFlag (foname);
177 fo->setVisibility (visible);
179 fo->setVisibility (false);
182 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
186 // I am the parentRow, mark flag as used
193 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
198 void FlagRowObj::deactivate (const QString &foname)
200 FlagObj *fo=findFlag (foname);
210 void FlagRowObj::deactivateAll ()
214 for (int i=0; i<flag.size(); ++i)
215 if (flag.at(i)->isActive()) flag.at(i)->deactivate();
218 while (!flag.isEmpty())
219 delete flag.takeFirst();
225 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
227 // deactivate all flags in keepof, but keep keepfo [sic!]
230 QString g=keepfo->getGroup();
233 for (int i=0; i<flag.size(); ++i)
234 if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i))
236 FlagObj *fo=flag.at(i);
244 void FlagRowObj::setToolBar(QToolBar *tb)
249 void FlagRowObj::setEnabled (bool b)
253 toolbar->setEnabled (b);
257 void FlagRowObj::setShowFlags (bool b)
262 void FlagRowObj::resetUsedCounter()
264 for (int i=0; i<flag.size(); ++i)
265 flag.at(i)->setUsed (false);
268 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
273 for (int i=0; i<flag.size(); ++i)
275 // save flag to xml, if flag is set
276 s+=valueElement("standardflag",flag.at(i)->getName() );
278 // and tell parentRow, that this flag is used
279 parentRow->activate(flag.at(i)->getName() );
282 // Save icons to dir, if verbose is set (xml export)
283 // and I am a parentRow
284 // and this flag is really used somewhere
286 for (int i=0; i<flag.size(); ++i)
287 if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
292 void FlagRowObj::setName (const QString &n)
297 void FlagRowObj::updateToolbar()
301 // We are just a branch, not the toolbar default
302 // but state has to be copied from ourselves to parentrow!
303 parentRow->deactivateAll();
304 // In parentRow activate all existing (==active) flags
305 for (int i=0; i<flag.size(); ++i)
306 parentRow->activate(flag.at(i)->getName());
307 parentRow->updateToolbar();
310 // We are the toolbar default
313 // Update state of actions in toolbar
314 for (int i=0; i<flag.size(); ++i)
315 flag.at(i)->updateAction();
320 FlagObj* FlagRowObj::findFlag (const QString &name)
322 for (int i=0; i<flag.size(); ++i)
323 if (flag.at(i)->getName()==name) return flag.at(i);