1 #include "flagrowobj.h"
3 /////////////////////////////////////////////////////////////////
5 /////////////////////////////////////////////////////////////////
6 FlagRowObj::FlagRowObj()
8 // cout << "Const FlagRowObj ()\n";
12 FlagRowObj::FlagRowObj(QCanvas* c):MapObj(c)
14 // cout << "Const FlagRowObj\n";
18 FlagRowObj::~FlagRowObj()
20 // cout << "Destr FlagRowObj\n";
24 void FlagRowObj::init ()
26 flag.setAutoDelete (true);
31 void FlagRowObj::copy (FlagRowObj* other)
34 parentRow=other->parentRow;
37 for (fo=other->flag.first(); fo; fo=other->flag.next() )
41 void FlagRowObj::clone (FlagRowObj* pr)
43 // Difference to copy:
44 // We don't copy the flags here, they
45 // are created on the fly by toggle and activate
46 // This saves lots of canvas objects.
52 void FlagRowObj::move(double x, double y)
57 for (fo=flag.first(); fo; fo=flag.next() )
60 dx+=QSize(fo->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);
73 for (fo=flag.first(); fo; fo=flag.next() )
74 fo->setVisibility (v);
77 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
79 FlagObj *newfo=new FlagObj (canvas);
80 newfo->move (absPos.x() + bbox.width(), absPos.y() );
81 newfo->copy (fo); // create a deep copy of fo
88 void FlagRowObj::positionBBox()
90 bbox.moveTopLeft(absPos );
91 clickBox.moveTopLeft(absPos );
94 void FlagRowObj::calcBBoxSize()
99 for (fo=flag.first(); fo; fo=flag.next() )
103 boxsize.setWidth(boxsize.width() + size.width() );
105 if (size.height() > boxsize.height() )
106 boxsize.setHeight(size.height() );
108 bbox.setSize (boxsize);
109 clickBox.setSize (boxsize);
112 QString FlagRowObj::getFlagName (const QPoint &p)
114 if (!inBox (p)) return "";
116 for (fo=flag.first();fo; fo=flag.next() )
117 if (fo->inBox (p)) return fo->getName();
123 bool FlagRowObj::isActive (const QString &foname)
125 FlagObj *fo=findFlag (foname);
127 return fo->isActive();
133 void FlagRowObj::toggle (const QString &foname, bool exclusive)
135 FlagObj *fo=findFlag (foname);
138 // FlagObj is here, it will be active, too.
139 // Deactivate it by removing it from this row.
143 // FlagObj is not present in this row.
144 // Copy it from parentRow
145 fo=parentRow->findFlag (foname);
152 deactivateGroup (fo);
156 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
162 void FlagRowObj::activate (const QString &foname)
164 // Note: "activate" is also called during loading of a map
165 // Here we do not check for exclusive flags!
166 FlagObj *fo=findFlag (foname);
171 // FlagObj is not present in this row.
172 // Copy it from parentRow and activate there
173 fo=parentRow->findFlag (foname);
179 fo->setVisibility (visible);
181 fo->setVisibility (false);
184 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
188 // I am the parentRow, mark flag as used
195 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
200 void FlagRowObj::deactivate (const QString &foname)
202 FlagObj *fo=findFlag (foname);
203 if (fo) flag.remove(fo);
208 void FlagRowObj::deactivateAll ()
213 for (fo=flag.first();fo; fo=flag.next() )
216 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
219 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
221 // deactivate all flags in keepof, but keep keepfo [sic!]
224 QString g=keepfo->getGroup();
228 for (fo=flag.first();fo; fo=flag.next() )
229 if (g==fo->getGroup() && keepfo!=fo)
235 void FlagRowObj::setEnabled (bool b)
237 // If we have no parent, we are the default FlagRowObj
238 // and have QToolbarButtons
242 for (fo=flag.first();fo; fo=flag.next() )
247 void FlagRowObj::setShowFlags (bool b)
252 void FlagRowObj::resetUsedCounter()
255 for (fo=flag.first();fo; fo=flag.next() )
259 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
265 for (fo=flag.first();fo; fo=flag.next() )
267 // save flag to xml, if flag is set
268 s+=valueElement("standardflag",fo->getName() );
270 // and tell parentRow, that this flag is used
271 parentRow->activate(fo->getName() );
274 // Save icons to dir, if verbose is set (xml export)
275 // and I am a parentRow
276 // and this flag is really used somewhere
278 for (fo=flag.first();fo; fo=flag.next() )
279 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
284 void FlagRowObj::setName (const QString &n)
289 void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
291 //Only make toolbar for the parentrow, not each row in branches
294 // create bar and buttons
295 QToolBar* tb = new QToolBar( w);
299 for (fo=flag.first();fo; fo=flag.next() )
309 a->setToggleAction(true);
310 // FIXME should not be enabled by default, later in updateToolbar
314 connect(a, SIGNAL( activated() ),
315 w, SLOT( standardFlagChanged() ) );
318 qWarning ("FlagRowObj::makeToolbar must not be called for ordinary rows");
321 void FlagRowObj::updateToolbar()
326 // We are just a branch, not the toolbar default
327 parentRow->deactivateAll();
328 // In parentRow activate all existing (==active) flags
329 for (fo=flag.first();fo; fo=flag.next() )
330 parentRow->activate(fo->getName());
331 parentRow->updateToolbar();
334 // We are the toolbar default
335 for (fo=flag.first();fo; fo=flag.next() )
340 FlagObj* FlagRowObj::findFlag (const QString &name)
343 for (fo=flag.first();fo; fo=flag.next() )
345 if (fo->getName()==name) return fo;