1 #include "flagrowobj.h"
5 /////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////
8 FlagRowObj::FlagRowObj()
10 // cout << "Const FlagRowObj ()\n";
14 FlagRowObj::FlagRowObj(Q3Canvas* c):MapObj(c)
16 // cout << "Const FlagRowObj\n";
20 FlagRowObj::~FlagRowObj()
22 // cout << "Destr FlagRowObj\n";
26 void FlagRowObj::init ()
28 flag.setAutoDelete (true);
33 void FlagRowObj::copy (FlagRowObj* other)
36 parentRow=other->parentRow;
39 for (fo=other->flag.first(); fo; fo=other->flag.next() )
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)
59 for (fo=flag.first(); fo; fo=flag.next() )
62 dx+=QSize(fo->getSize() ).width();
66 void FlagRowObj::moveBy(double x, double y)
68 move (x+absPos.x(),y+absPos.y() );
71 void FlagRowObj::setVisibility (bool v)
73 MapObj::setVisibility(v);
75 for (fo=flag.first(); fo; fo=flag.next() )
76 fo->setVisibility (v);
79 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
81 FlagObj *newfo=new FlagObj (canvas);
82 newfo->move (absPos.x() + bbox.width(), absPos.y() );
83 newfo->copy (fo); // create a deep copy of fo
90 void FlagRowObj::positionBBox()
92 bbox.moveTopLeft(absPos );
93 clickBox.moveTopLeft(absPos );
96 void FlagRowObj::calcBBoxSize()
101 for (fo=flag.first(); fo; fo=flag.next() )
105 boxsize.setWidth(boxsize.width() + size.width() );
107 if (size.height() > boxsize.height() )
108 boxsize.setHeight(size.height() );
110 bbox.setSize (boxsize);
111 clickBox.setSize (boxsize);
114 QString FlagRowObj::getFlagName (const QPoint &p)
116 if (!inBox (p)) return "";
118 for (fo=flag.first();fo; fo=flag.next() )
119 if (fo->inBox (p)) return fo->getName();
125 bool FlagRowObj::isActive (const QString &foname)
127 FlagObj *fo=findFlag (foname);
129 return fo->isActive();
135 void FlagRowObj::toggle (const QString &foname, bool exclusive)
137 FlagObj *fo=findFlag (foname);
140 // FlagObj is here, it will be active, too.
141 // Deactivate it by removing it from this row.
145 // FlagObj is not present in this row.
146 // Copy it from parentRow
147 fo=parentRow->findFlag (foname);
154 deactivateGroup (fo);
158 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
164 void FlagRowObj::activate (const QString &foname)
166 // Note: "activate" is also called during loading of a map
167 // Here we do not check for exclusive flags!
168 FlagObj *fo=findFlag (foname);
173 // FlagObj is not present in this row.
174 // Copy it from parentRow and activate there
175 fo=parentRow->findFlag (foname);
181 fo->setVisibility (visible);
183 fo->setVisibility (false);
186 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
190 // I am the parentRow, mark flag as used
197 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
202 void FlagRowObj::deactivate (const QString &foname)
204 FlagObj *fo=findFlag (foname);
205 if (fo) flag.remove(fo);
210 void FlagRowObj::deactivateAll ()
215 for (fo=flag.first();fo; fo=flag.next() )
218 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
221 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
223 // deactivate all flags in keepof, but keep keepfo [sic!]
226 QString g=keepfo->getGroup();
230 for (fo=flag.first();fo; fo=flag.next() )
231 if (g==fo->getGroup() && keepfo!=fo)
237 void FlagRowObj::setToolBar(QToolBar *tb)
242 void FlagRowObj::setEnabled (bool b)
246 toolbar->setEnabled (b);
250 void FlagRowObj::setShowFlags (bool b)
255 void FlagRowObj::resetUsedCounter()
258 for (fo=flag.first();fo; fo=flag.next() )
262 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
268 for (fo=flag.first();fo; fo=flag.next() )
270 // save flag to xml, if flag is set
271 s+=valueElement("standardflag",fo->getName() );
273 // and tell parentRow, that this flag is used
274 parentRow->activate(fo->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 (fo=flag.first();fo; fo=flag.next() )
282 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
287 void FlagRowObj::setName (const QString &n)
292 void FlagRowObj::updateToolbar()
297 // We are just a branch, not the toolbar default
298 // but state has to be copied from ourselves to parentrow!
299 parentRow->deactivateAll();
300 // In parentRow activate all existing (==active) flags
301 for (fo=flag.first();fo; fo=flag.next() )
302 parentRow->activate(fo->getName());
303 parentRow->updateToolbar();
306 // We are the toolbar default
309 // Update state of actions in toolbar
310 for (fo=flag.first();fo; fo=flag.next() )
316 FlagObj* FlagRowObj::findFlag (const QString &name)
319 for (fo=flag.first();fo; fo=flag.next() )
321 if (fo->getName()==name) return fo;