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 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);
201 if (fo) flag.remove(fo);
206 void FlagRowObj::deactivateAll ()
211 for (fo=flag.first();fo; fo=flag.next() )
214 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
217 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
219 // deactivate all flags in keepof, but keep keepfo [sic!]
223 for (fo=flag.first();fo; fo=flag.next() )
224 if (keepfo->getGroup()==fo->getGroup() && keepfo!=fo)
229 void FlagRowObj::setEnabled (bool b)
231 // If we have no parent, we are the default FlagRowObj
232 // and have QToolbarButtons
236 for (fo=flag.first();fo; fo=flag.next() )
241 void FlagRowObj::setShowFlags (bool b)
246 void FlagRowObj::resetUsedCounter()
249 for (fo=flag.first();fo; fo=flag.next() )
253 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
259 for (fo=flag.first();fo; fo=flag.next() )
261 // save flag to xml, if flag is set
262 s+=valueElement("standardflag",fo->getName() );
264 // and tell parentRow, that this flag is used
265 parentRow->activate(fo->getName() );
268 // Save icons to dir, if verbose is set (xml export)
269 // and I am a parentRow
270 // and this flag is really used somewhere
272 for (fo=flag.first();fo; fo=flag.next() )
273 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
278 void FlagRowObj::setName (const QString &n)
283 void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
285 //Only make toolbar for the parentrow, not each row in branches
288 // create bar and buttons
289 QToolBar* tb = new QToolBar( w);
293 for (fo=flag.first();fo; fo=flag.next() )
303 a->setToggleAction(true);
304 // FIXME should not be enabled by default, later in updateToolbar
308 connect(a, SIGNAL( activated() ),
309 w, SLOT( standardFlagChanged() ) );
312 qWarning ("FlagRowObj::makeToolbar must not be called for ordinary rows");
315 void FlagRowObj::updateToolbar()
320 // We are just a branch, not the toolbar default
321 parentRow->deactivateAll();
322 // In parentRow activate all existing (==active) flags
323 for (fo=flag.first();fo; fo=flag.next() )
324 parentRow->activate(fo->getName());
325 parentRow->updateToolbar();
328 // We are the toolbar default
329 for (fo=flag.first();fo; fo=flag.next() )
334 FlagObj* FlagRowObj::findFlag (const QString &name)
337 for (fo=flag.first();fo; fo=flag.next() )
339 if (fo->getName()==name) return fo;