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();
217 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
220 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
222 // deactivate all flags in keepof, but keep keepfo [sic!]
225 QString g=keepfo->getGroup();
228 for (int i=0; i<flag.size(); ++i)
229 if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i))
231 FlagObj *fo=flag.at(i);
239 void FlagRowObj::setToolBar(QToolBar *tb)
244 void FlagRowObj::setEnabled (bool b)
248 toolbar->setEnabled (b);
252 void FlagRowObj::setShowFlags (bool b)
257 void FlagRowObj::resetUsedCounter()
259 for (int i=0; i<flag.size(); ++i)
260 flag.at(i)->setUsed (false);
263 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
268 for (int i=0; i<flag.size(); ++i)
270 // save flag to xml, if flag is set
271 s+=valueElement("standardflag",flag.at(i)->getName() );
273 // and tell parentRow, that this flag is used
274 parentRow->activate(flag.at(i)->getName() );
277 // Save icons to dir, if verbose is set (xml export)
278 // and I am a parentRow
279 // and this flag is really used somewhere
281 for (int i=0; i<flag.size(); ++i)
282 if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
287 void FlagRowObj::setName (const QString &n)
292 void FlagRowObj::updateToolbar()
296 // We are just a branch, not the toolbar default
297 // but state has to be copied from ourselves to parentrow!
298 parentRow->deactivateAll();
299 // In parentRow activate all existing (==active) flags
300 for (int i=0; i<flag.size(); ++i)
301 parentRow->activate(flag.at(i)->getName());
302 parentRow->updateToolbar();
305 // We are the toolbar default
308 // Update state of actions in toolbar
309 for (int i=0; i<flag.size(); ++i)
310 flag.at(i)->updateAction();
315 FlagObj* FlagRowObj::findFlag (const QString &name)
317 for (int i=0; i<flag.size(); ++i)
318 if (flag.at(i)->getName()==name) return flag.at(i);