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);
30 void FlagRowObj::copy (FlagRowObj* other)
33 parentRow=other->parentRow;
36 for (fo=other->flag.first(); fo; fo=other->flag.next() )
40 void FlagRowObj::clone (FlagRowObj* pr)
42 // Difference to copy:
43 // We don't copy the flags here, they
44 // are created on the fly by toggle and activate
45 // This saves lots of canvas objects.
51 void FlagRowObj::move(double x, double y)
56 for (fo=flag.first(); fo; fo=flag.next() )
59 dx+=QSize(fo->getSize() ).width();
63 void FlagRowObj::moveBy(double x, double y)
65 move (x+absPos.x(),y+absPos.y() );
68 void FlagRowObj::setVisibility (bool v)
70 MapObj::setVisibility(v);
72 for (fo=flag.first(); fo; fo=flag.next() )
73 fo->setVisibility (v);
76 FlagObj* FlagRowObj::addFlag (FlagObj *fo)
78 FlagObj *newfo=new FlagObj (canvas);
79 newfo->move (absPos.x() + bbox.width(), absPos.y() );
80 newfo->copy (fo); // create a deep copy of fo
87 void FlagRowObj::positionBBox()
89 bbox.moveTopLeft(absPos );
90 clickBox.moveTopLeft(absPos );
93 void FlagRowObj::calcBBoxSize()
98 for (fo=flag.first(); fo; fo=flag.next() )
102 boxsize.setWidth(boxsize.width() + size.width() );
104 if (size.height() > boxsize.height() )
105 boxsize.setHeight(size.height() );
107 bbox.setSize (boxsize);
108 clickBox.setSize (boxsize);
111 QString FlagRowObj::getFlagName (const QPoint &p)
113 if (!inBox (p)) return "";
115 for (fo=flag.first();fo; fo=flag.next() )
117 cout << " "<<fo->getName()<<endl;
118 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 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);
178 fo->setVisibility (visible);
181 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
185 // I am the parentRow, mark flag as used
192 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
197 void FlagRowObj::deactivate (const QString &foname)
199 FlagObj *fo=findFlag (foname);
200 if (fo) flag.remove(fo);
205 void FlagRowObj::deactivateAll ()
210 for (fo=flag.first();fo; fo=flag.next() )
213 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
216 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
218 // deactivate all flags in keepof, but keep keepfo [sic!]
222 for (fo=flag.first();fo; fo=flag.next() )
223 if (keepfo->getGroup()==fo->getGroup() && keepfo!=fo)
228 void FlagRowObj::setEnabled (bool b)
230 // If we have no parent, we are the default FlagRowObj
231 // and have QToolbarButtons
235 for (fo=flag.first();fo; fo=flag.next() )
240 void FlagRowObj::resetUsedCounter()
243 for (fo=flag.first();fo; fo=flag.next() )
247 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
253 for (fo=flag.first();fo; fo=flag.next() )
255 // save flag to xml, if flag is set
256 s+=valueElement("standardflag",fo->getName() );
258 // and tell parentRow, that this flag is used
259 parentRow->activate(fo->getName() );
262 // Save icons to dir, if verbose is set (xml export)
263 // and I am a parentRow
264 // and this flag is really used somewhere
266 for (fo=flag.first();fo; fo=flag.next() )
267 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
272 void FlagRowObj::setName (const QString &n)
277 void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
279 //Only make toolbar for the parentrow, not each row in branches
282 // create bar and buttons
283 QToolBar* tb = new QToolBar( w);
287 for (fo=flag.first();fo; fo=flag.next() )
297 a->setToggleAction(true);
298 // FIXME should not be enabled by default, later in updateToolbar
302 connect(a, SIGNAL( activated() ),
303 w, SLOT( standardFlagChanged() ) );
306 qWarning ("FlagRowObj::makeToolbar must not be called for ordinary rows");
309 void FlagRowObj::updateToolbar()
314 // We are just a branch, not the toolbar default
315 parentRow->deactivateAll();
316 // In parentRow activate all existing (==active) flags
317 for (fo=flag.first();fo; fo=flag.next() )
318 parentRow->activate(fo->getName());
319 parentRow->updateToolbar();
322 // We are the toolbar default
323 for (fo=flag.first();fo; fo=flag.next() )
328 FlagObj* FlagRowObj::findFlag (const QString &name)
331 for (fo=flag.first();fo; fo=flag.next() )
333 if (fo->getName()==name) return fo;