flagrowobj.cpp
changeset 406 1c8ff1928b97
parent 366 e95081c21da2
child 408 c2a05fa925a1
     1.1 --- a/flagrowobj.cpp	Mon Nov 20 12:12:05 2006 +0000
     1.2 +++ b/flagrowobj.cpp	Thu Nov 23 13:53:08 2006 +0000
     1.3 @@ -19,13 +19,13 @@
     1.4  
     1.5  FlagRowObj::~FlagRowObj()
     1.6  {
     1.7 -//    cout << "Destr FlagRowObj\n";
     1.8 -	flag.clear();
     1.9 + //   cout << "Destr FlagRowObj\n";
    1.10 +	while (!flag.isEmpty())
    1.11 +		delete flag.takeFirst();
    1.12  }
    1.13  
    1.14  void FlagRowObj::init ()
    1.15  {
    1.16 -    flag.setAutoDelete (true);
    1.17  	parentRow=NULL;
    1.18  	showFlags=true;
    1.19  }
    1.20 @@ -35,9 +35,8 @@
    1.21      MapObj::copy(other);
    1.22  	parentRow=other->parentRow;
    1.23  	flag.clear();
    1.24 -	FlagObj *fo;
    1.25 -    for (fo=other->flag.first(); fo; fo=other->flag.next() )
    1.26 -		addFlag (fo);
    1.27 +	for (int i=0; i<flag.size(); ++i)
    1.28 +		addFlag (flag.at(i));
    1.29  }
    1.30  
    1.31  void FlagRowObj::clone (FlagRowObj* pr)
    1.32 @@ -55,11 +54,10 @@
    1.33  {
    1.34      MapObj::move(x,y);
    1.35  	int dx=0;
    1.36 -	FlagObj *fo;
    1.37 -    for (fo=flag.first(); fo; fo=flag.next() )
    1.38 +	for (int i=0; i<flag.size(); ++i)
    1.39  	{
    1.40 -		fo->move(x+dx,y);
    1.41 -		dx+=QSize(fo->getSize() ).width();
    1.42 +		flag.at(i)->move(x+dx,y);
    1.43 +		dx+=QSize(flag.at(i)->getSize() ).width();
    1.44  	}
    1.45  }
    1.46  
    1.47 @@ -71,9 +69,8 @@
    1.48  void FlagRowObj::setVisibility (bool v)
    1.49  {
    1.50  	MapObj::setVisibility(v);
    1.51 -	FlagObj *fo;
    1.52 -	for (fo=flag.first(); fo; fo=flag.next() )
    1.53 -		fo->setVisibility (v);
    1.54 +	for (int i=0; i<flag.size(); ++i)
    1.55 +		flag.at(i)->setVisibility (v);
    1.56  }
    1.57  
    1.58  FlagObj* FlagRowObj::addFlag (FlagObj *fo)
    1.59 @@ -97,10 +94,9 @@
    1.60  {
    1.61  	QSize size(0,0);
    1.62  	QSize boxsize(0,0);
    1.63 -	FlagObj *fo;
    1.64 -    for (fo=flag.first(); fo; fo=flag.next() )
    1.65 +	for (int i=0; i<flag.size(); ++i)
    1.66  	{
    1.67 -		size=fo->getSize();
    1.68 +		size=flag.at(i)->getSize();
    1.69  		// add widths
    1.70  		boxsize.setWidth(boxsize.width() + size.width() );
    1.71  		// maximize height
    1.72 @@ -114,9 +110,8 @@
    1.73  QString FlagRowObj::getFlagName (const QPoint &p)
    1.74  {
    1.75  	if (!inBox (p)) return "";
    1.76 -	FlagObj *fo;
    1.77 -	for (fo=flag.first();fo; fo=flag.next() )
    1.78 -		if (fo->inBox (p)) return fo->getName();
    1.79 +	for (int i=0; i<flag.size(); ++i)
    1.80 +		if (flag.at(i)->inBox (p)) return flag.at(i)->getName();
    1.81  	return "";	
    1.82  
    1.83  	
    1.84 @@ -211,9 +206,8 @@
    1.85  {
    1.86  	if (!parentRow)
    1.87  	{
    1.88 -		FlagObj *fo;
    1.89 -		for (fo=flag.first();fo; fo=flag.next() )
    1.90 -			fo->deactivate();
    1.91 +		for (int i=0; i<flag.size(); ++i)
    1.92 +			flag.at(i)->deactivate();
    1.93  	} else
    1.94  		qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
    1.95  }
    1.96 @@ -226,10 +220,9 @@
    1.97  		QString g=keepfo->getGroup();
    1.98  		if (g!="undefined")
    1.99  		{
   1.100 -			FlagObj *fo;
   1.101 -			for (fo=flag.first();fo; fo=flag.next() )
   1.102 -				if (g==fo->getGroup() && keepfo!=fo) 
   1.103 -					flag.remove(fo);
   1.104 +			for (int i=0; i<flag.size(); ++i)
   1.105 +				if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i)) 
   1.106 +					flag.remove(flag.at(i));
   1.107  		}		
   1.108  	}	
   1.109  }
   1.110 @@ -254,32 +247,30 @@
   1.111  
   1.112  void FlagRowObj::resetUsedCounter()
   1.113  {
   1.114 -	FlagObj *fo;
   1.115 -	for (fo=flag.first();fo; fo=flag.next() )
   1.116 -		fo->setUsed (false);
   1.117 +	for (int i=0; i<flag.size(); ++i)
   1.118 +		flag.at(i)->setUsed (false);
   1.119  }
   1.120  
   1.121  QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
   1.122  {
   1.123  	// Build xml string
   1.124  	QString s;
   1.125 -	FlagObj *fo;
   1.126  	if (parentRow)
   1.127 -		for (fo=flag.first();fo; fo=flag.next() )
   1.128 +		for (int i=0; i<flag.size(); ++i)
   1.129  		{
   1.130  			// save flag to xml, if flag is set 
   1.131 -			s+=valueElement("standardflag",fo->getName() );
   1.132 +			s+=valueElement("standardflag",flag.at(i)->getName() );
   1.133  
   1.134  			// and tell parentRow, that this flag is used
   1.135 -			parentRow->activate(fo->getName() );
   1.136 +			parentRow->activate(flag.at(i)->getName() );
   1.137  		}	
   1.138  	else
   1.139  		// Save icons to dir, if verbose is set (xml export)
   1.140  		// and I am a parentRow 
   1.141  		// and this flag is really used somewhere
   1.142  		if (writeflags)
   1.143 -			for (fo=flag.first();fo; fo=flag.next() )
   1.144 -				if (fo->isUsed()) fo->saveToDir (tmpdir,prefix);
   1.145 +			for (int i=0; i<flag.size(); ++i)
   1.146 +				if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
   1.147  	return s;		
   1.148  
   1.149  }
   1.150 @@ -291,15 +282,14 @@
   1.151  
   1.152  void  FlagRowObj::updateToolbar()
   1.153  {
   1.154 -	FlagObj *fo;
   1.155  	if (parentRow)
   1.156  	{
   1.157  		// We are just a branch, not the toolbar default
   1.158  		// but state has to be copied from ourselves to parentrow!
   1.159  		parentRow->deactivateAll();
   1.160  		// In parentRow activate all existing (==active) flags
   1.161 -		for (fo=flag.first();fo; fo=flag.next() ) 
   1.162 -			parentRow->activate(fo->getName());
   1.163 +		for (int i=0; i<flag.size(); ++i)
   1.164 +			parentRow->activate(flag.at(i)->getName());
   1.165  		parentRow->updateToolbar();	
   1.166  	} else
   1.167  	{
   1.168 @@ -307,19 +297,16 @@
   1.169  		if (toolbar)
   1.170  		{
   1.171  			// Update state of actions in toolbar
   1.172 -			for (fo=flag.first();fo; fo=flag.next() ) 
   1.173 -				fo->updateAction();
   1.174 +			for (int i=0; i<flag.size(); ++i)
   1.175 +				flag.at(i)->updateAction();
   1.176  		}	
   1.177  	}
   1.178  }
   1.179  
   1.180  FlagObj* FlagRowObj::findFlag (const QString &name)
   1.181  {
   1.182 -	FlagObj *fo;
   1.183 -	for (fo=flag.first();fo; fo=flag.next() )
   1.184 -	{
   1.185 -		if (fo->getName()==name) return fo;
   1.186 -	}
   1.187 +	for (int i=0; i<flag.size(); ++i)
   1.188 +		if (flag.at(i)->getName()==name) return flag.at(i);
   1.189  	return NULL;
   1.190  }
   1.191