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.setX (absPos.x() );
90 bbox.setY (absPos.y() );
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 (QSize(boxsize.width(), boxsize.height() ));
110 QString FlagRowObj::getFlagName (const QPoint &p)
112 if (!inBBox (p)) return "";
114 for (fo=flag.first();fo; fo=flag.next() )
115 if (fo->inBBox (p)) return fo->getName();
121 bool FlagRowObj::isActive (const QString &foname)
123 FlagObj *fo=findFlag (foname);
127 return fo->isActive();
129 qWarning ("FlagRowObj::isActive of "+name+" couldn't find "+foname);
136 void FlagRowObj::toggle (const QString &foname, bool exclusive)
138 FlagObj *fo=findFlag (foname);
141 // FlagObj is here, it will be active, too.
142 // Deactivate it by removing it from this row.
146 // FlagObj is not present in this row.
147 // Copy it from parentRow
148 fo=parentRow->findFlag (foname);
155 deactivateGroup (fo);
159 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
165 void FlagRowObj::activate (const QString &foname)
167 FlagObj *fo=findFlag (foname);
172 // FlagObj is not present in this row.
173 // Copy it from parentRow and activate there
174 fo=parentRow->findFlag (foname);
179 fo->setVisibility (visible);
183 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
187 // I am the parentRow, mark flag as used
194 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
199 void FlagRowObj::deactivate (const QString &foname)
201 FlagObj *fo=findFlag (foname);
202 if (fo) flag.remove(fo);
207 void FlagRowObj::deactivateAll ()
212 for (fo=flag.first();fo; fo=flag.next() )
215 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
218 void FlagRowObj::deactivateGroup (FlagObj *keepfo)
220 // deactivate all flags in keepof, but keep keepfo [sic!]
224 for (fo=flag.first();fo; fo=flag.next() )
225 if (keepfo->getGroup()==fo->getGroup() && keepfo!=fo)
230 void FlagRowObj::setEnabled (bool b)
232 // If we have no parent, we are the default FlagRowObj
233 // and have QToolbarButtons
237 for (fo=flag.first();fo; fo=flag.next() )
242 void FlagRowObj::resetUsedCounter()
245 for (fo=flag.first();fo; fo=flag.next() )
249 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
255 for (fo=flag.first();fo; fo=flag.next() )
257 // save flag to xml, if flag is set
258 s+=valueElement("standardflag",fo->getName() );
260 // and tell parentRow, that this flag is used
261 parentRow->activate(fo->getName() );
264 // Save icons to dir, if verbose is set (xml export)
265 // and I am a parentRow
266 // and this flag is really used somewhere
268 for (fo=flag.first();fo; fo=flag.next() )
269 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
274 void FlagRowObj::setName (const QString &n)
279 void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
281 //Only make toolbar for the parentrow, not each row in branches
284 // create bar and buttons
285 QToolBar* tb = new QToolBar( w);
289 for (fo=flag.first();fo; fo=flag.next() )
299 a->setToggleAction(true);
300 // FIXME should not be enabled by default, later in updateToolbar
304 connect(a, SIGNAL( activated() ),
305 w, SLOT( standardFlagChanged() ) );
308 qWarning ("FlagRowObj::makeToolbar mustn't be called for ordinary rows");
311 void FlagRowObj::updateToolbar()
316 // We are just a branch, not the toolbar default
317 parentRow->deactivateAll();
318 // In parentRow activate all existing (==active) flags
319 for (fo=flag.first();fo; fo=flag.next() )
320 parentRow->activate(fo->getName());
321 parentRow->updateToolbar();
324 // We are the toolbar default
325 for (fo=flag.first();fo; fo=flag.next() )
330 FlagObj* FlagRowObj::findFlag (const QString &name)
333 for (fo=flag.first();fo; fo=flag.next() )
335 if (fo->getName()==name) return fo;