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)
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);
154 qWarning ("FlagRowObj ("+name+")::toggle ("+foname+") failed - could not find it in parentRow");
160 void FlagRowObj::activate (const QString &foname)
162 FlagObj *fo=findFlag (foname);
167 // FlagObj is not present in this row.
168 // Copy it from parentRow and activate there
169 fo=parentRow->findFlag (foname);
174 fo->setVisibility (visible);
178 qWarning ("FlagRowObj ("+name+")::activate ("+foname+") failed - could not find it in parentRow");
182 // I am the parentRow, mark flag as used
189 qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
193 void FlagRowObj::deactivate (const QString &foname)
195 FlagObj *fo=findFlag (foname);
196 if (fo) flag.remove(fo);
201 void FlagRowObj::deactivateAll ()
206 for (fo=flag.first();fo; fo=flag.next() )
211 qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
214 void FlagRowObj::setEnabled (bool b)
216 // If we have no parent, we are the default FlagRowObj
217 // and have QToolbarButtons
221 for (fo=flag.first();fo; fo=flag.next() )
226 void FlagRowObj::resetUsedCounter()
229 for (fo=flag.first();fo; fo=flag.next() )
233 QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
239 for (fo=flag.first();fo; fo=flag.next() )
241 // save flag to xml, if flag is set
242 s+=valueElement("standardflag",fo->getName() );
244 // and tell parentRow, that this flag is used
245 parentRow->activate(fo->getName() );
248 // Save icons to dir, if verbose is set (xml export)
249 // and I am a parentRow
250 // and this flag is really used somewhere
252 for (fo=flag.first();fo; fo=flag.next() )
253 if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
258 void FlagRowObj::setName (const QString &n)
263 void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
267 // create bar and buttons
268 QToolBar* tb = new QToolBar( w);
272 for (fo=flag.first();fo; fo=flag.next() )
282 a->setToggleAction(true);
283 // FIXME should not be enabled by default, later in updateToolbar
287 connect(a, SIGNAL( activated() ),
288 w, SLOT( standardFlagChanged() ) );
291 qWarning ("FlagRowObj::makeToolbar mustn't be called for ordinary rows");
294 void FlagRowObj::updateToolBar()
299 // We are just a branch, not the toolbar default
300 parentRow->deactivateAll();
301 // In parentRow activate all existing (==active) flags
302 for (fo=flag.first();fo; fo=flag.next() )
303 parentRow->activate(fo->getName());
304 parentRow->updateToolBar();
307 // We are the toolbar default
308 for (fo=flag.first();fo; fo=flag.next() )
313 FlagObj* FlagRowObj::findFlag (const QString &name)
316 for (fo=flag.first();fo; fo=flag.next() )
318 if (fo->getName()==name) return fo;