flagrowobj.cpp
changeset 849 988f1908a7c4
parent 766 7a71a914afdb
     1.1 --- a/flagrowobj.cpp	Thu May 07 08:48:53 2009 +0000
     1.2 +++ b/flagrowobj.cpp	Fri Jul 23 16:43:49 2010 +0000
     1.3 @@ -3,6 +3,7 @@
     1.4  #include <iostream>
     1.5  using namespace std;
     1.6  
     1.7 +#include "flag.h"
     1.8  #include "flagrowobj.h"
     1.9  
    1.10  #include "geometry.h"
    1.11 @@ -31,30 +32,17 @@
    1.12  
    1.13  void FlagRowObj::init ()
    1.14  {
    1.15 -	parentRow=NULL;
    1.16  	showFlags=true;
    1.17  }
    1.18  
    1.19  void FlagRowObj::copy (FlagRowObj* other)
    1.20  {
    1.21      MapObj::copy(other);
    1.22 -	parentRow=other->parentRow;
    1.23  	flag.clear();
    1.24  	for (int i=0; i<flag.size(); ++i)
    1.25  		addFlag (flag.at(i));
    1.26  }
    1.27  
    1.28 -void FlagRowObj::clone (FlagRowObj* pr)
    1.29 -{
    1.30 -	// Difference to copy:
    1.31 -	// We don't copy the flags here, they
    1.32 -	// are created on the fly by toggle and activate
    1.33 -	// This saves lots of canvas objects.
    1.34 -	MapObj::copy(pr);
    1.35 -	flag.clear();
    1.36 -	parentRow=pr;
    1.37 -}
    1.38 -
    1.39  void FlagRowObj::move(double x, double y)
    1.40  {
    1.41      MapObj::move(x,y);
    1.42 @@ -89,6 +77,14 @@
    1.43  	return newfo;
    1.44  }
    1.45  
    1.46 +QStringList FlagRowObj::activeFlagNames()
    1.47 +{
    1.48 +	QStringList list;
    1.49 +	for (int i=0; i<flag.size(); ++i)
    1.50 +		list.append (flag.at(i)->getName());
    1.51 +	return list;
    1.52 +}
    1.53 +
    1.54  void FlagRowObj::positionBBox()
    1.55  {
    1.56      bbox.moveTopLeft(absPos );
    1.57 @@ -124,84 +120,28 @@
    1.58  
    1.59  bool FlagRowObj::isActive (const QString &foname)
    1.60  {
    1.61 +
    1.62  	FlagObj *fo=findFlag (foname);
    1.63 -	if (parentRow && fo)
    1.64 -		return fo->isActive();
    1.65 +	if (fo) 
    1.66 +		return true;
    1.67  	else
    1.68 -		if (fo) return true;
    1.69 -	return false;
    1.70 +		return false;
    1.71  }
    1.72  
    1.73 -void FlagRowObj::toggle (const QString &foname)
    1.74 +void FlagRowObj::activate (Flag *flag)	
    1.75  {
    1.76 -	FlagObj *fo=findFlag (foname);
    1.77 -	if (fo)
    1.78 +	if (flag) 
    1.79  	{
    1.80 -		// FlagObj is here, it will be active, too.
    1.81 -		// Deactivate it by removing it from this row.
    1.82 -		flag.remove (fo);
    1.83 -		delete (fo);
    1.84 -	} else
    1.85 -	{
    1.86 -		// FlagObj is not present in this row.
    1.87 -		// Copy it from parentRow
    1.88 -		fo=parentRow->findFlag (foname);
    1.89 -		if (fo)
    1.90 -		{
    1.91 -			fo=addFlag (fo);
    1.92 -			fo->activate();
    1.93 -			/*FIXME-0 move to VM if (exclusive) 
    1.94 -			{
    1.95 -				deactivateGroup (fo);
    1.96 -				updateToolbar();
    1.97 -			}
    1.98 -			*/
    1.99 -		} else
   1.100 -			qWarning ("FlagRowObj ("+name+")::toggle ("+foname+")  failed - could not find it in parentRow");
   1.101 -	}	
   1.102 -	calcBBoxSize();
   1.103 -	positionBBox();	
   1.104 -}
   1.105 -
   1.106 -void FlagRowObj::activate (const QString &foname)
   1.107 -{
   1.108 -	cout << "FRO::activate  "<<foname.toStdString()<<endl;
   1.109 -	// Note: "activate" is also called during loading of a map
   1.110 -	// Here we do not check for exclusive flags!
   1.111 -	FlagObj *fo=findFlag (foname);
   1.112 -	if (parentRow)
   1.113 -	{
   1.114 -		if (!fo)
   1.115 -		{
   1.116 -			// FlagObj is not present in this row.
   1.117 -			// Copy it from parentRow and activate there
   1.118 -			fo=parentRow->findFlag (foname);
   1.119 -			if (fo)
   1.120 -			{
   1.121 -				fo=addFlag (fo);
   1.122 -				fo->activate();
   1.123 -				if (showFlags) 
   1.124 -					fo->setVisibility (visible);
   1.125 -				else
   1.126 -					fo->setVisibility (false);
   1.127 -				calcBBoxSize();
   1.128 -			} else
   1.129 -				qWarning ("FlagRowObj ("+name+")::activate ("+foname+")  failed - could not find it in parentRow");
   1.130 -		}	
   1.131 -	} else
   1.132 -	{
   1.133 -		// I am the parentRow, mark flag as used
   1.134 -		if (fo)
   1.135 -		{
   1.136 -			fo->setUsed(true);
   1.137 -			fo->activate();
   1.138 -		}	
   1.139 +		FlagObj *fo=addFlag (new FlagObj (flag));
   1.140 +		fo->activate();
   1.141 +		if (showFlags)	// FIXME-3 necessary? only called from FIO::init
   1.142 +			fo->setVisibility (visible);
   1.143  		else
   1.144 -			qWarning ("FlagRowObj::activate no FlagObj \""+foname+"\" found in parentRow");
   1.145 +			fo->setVisibility (false);
   1.146 +		calcBBoxSize();
   1.147  	}
   1.148  }
   1.149  
   1.150 -
   1.151  void FlagRowObj::deactivate (const QString &foname)
   1.152  {
   1.153  	FlagObj *fo=findFlag (foname);
   1.154 @@ -214,116 +154,11 @@
   1.155  	positionBBox();
   1.156  }
   1.157  
   1.158 -void FlagRowObj::deactivateAll ()
   1.159 -{
   1.160 -	if (!parentRow)
   1.161 -	{
   1.162 -		for (int i=0; i<flag.size(); ++i)
   1.163 -			if (flag.at(i)->isActive()) flag.at(i)->deactivate();
   1.164 -	} else
   1.165 -	{
   1.166 -		while (!flag.isEmpty())
   1.167 -			delete flag.takeFirst();
   1.168 -		calcBBoxSize();
   1.169 -		positionBBox();
   1.170 -	}
   1.171 -}
   1.172 -
   1.173 -void FlagRowObj::deactivateGroup (FlagObj *keepfo)	//FIXME-0 move to VM
   1.174 -{
   1.175 -	// deactivate all flags in keepof, but keep keepfo [sic!]
   1.176 -	if (keepfo)
   1.177 -	{
   1.178 -		QString g=keepfo->getGroup();
   1.179 -		if (g!="undefined")
   1.180 -		{
   1.181 -			for (int i=0; i<flag.size(); ++i)
   1.182 -				if (g==flag.at(i)->getGroup() && keepfo!=flag.at(i)) 
   1.183 -				{
   1.184 -					FlagObj *fo=flag.at(i);
   1.185 -					flag.remove (fo);
   1.186 -					delete (fo);
   1.187 -				}	
   1.188 -		}		
   1.189 -	}	
   1.190 -}
   1.191 -
   1.192 -void FlagRowObj::setToolBar(QToolBar *tb)
   1.193 -{
   1.194 -	toolbar=tb;
   1.195 -}
   1.196 -
   1.197 -void FlagRowObj::setEnabled (bool b)
   1.198 -{
   1.199 -	if (toolbar)
   1.200 -	{
   1.201 -		toolbar->setEnabled (b);
   1.202 -	}
   1.203 -}
   1.204 -
   1.205  void FlagRowObj::setShowFlags (bool b)
   1.206  {
   1.207  	showFlags=b;
   1.208  }
   1.209  
   1.210 -void FlagRowObj::resetUsedCounter()
   1.211 -{
   1.212 -	for (int i=0; i<flag.size(); ++i)
   1.213 -		flag.at(i)->setUsed (false);
   1.214 -}
   1.215 -
   1.216 -QString FlagRowObj::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
   1.217 -{
   1.218 -	// Build xml string
   1.219 -	QString s;
   1.220 -	if (parentRow)
   1.221 -		for (int i=0; i<flag.size(); ++i)
   1.222 -		{
   1.223 -			// save flag to xml, if flag is set 
   1.224 -			s+=valueElement("standardflag",flag.at(i)->getName() );
   1.225 -
   1.226 -			// and tell parentRow, that this flag is used
   1.227 -			parentRow->activate(flag.at(i)->getName() );
   1.228 -		}	
   1.229 -	else
   1.230 -		// Save icons to dir, if verbose is set (xml export)
   1.231 -		// and I am a parentRow 
   1.232 -		// and this flag is really used somewhere
   1.233 -		if (writeflags)
   1.234 -			for (int i=0; i<flag.size(); ++i)
   1.235 -				if (flag.at(i)->isUsed()) flag.at(i)->saveToDir (tmpdir,prefix);
   1.236 -	return s;		
   1.237 -
   1.238 -}
   1.239 -
   1.240 -void FlagRowObj::setName (const QString &n)
   1.241 -{
   1.242 -	name=n;
   1.243 -}
   1.244 -
   1.245 -void  FlagRowObj::updateToolbar()	//FIXME-2 this needs to be changed with VM
   1.246 -{
   1.247 -	if (parentRow)
   1.248 -	{
   1.249 -		// We are just a branch, not the toolbar default
   1.250 -		// but state has to be copied from ourselves to parentrow!
   1.251 -		parentRow->deactivateAll();
   1.252 -		// In parentRow activate all existing (==active) flags
   1.253 -		for (int i=0; i<flag.size(); ++i)
   1.254 -			parentRow->activate(flag.at(i)->getName());
   1.255 -		parentRow->updateToolbar();	
   1.256 -	} else
   1.257 -	{
   1.258 -		// We are the toolbar default
   1.259 -		if (toolbar)
   1.260 -		{
   1.261 -			// Update state of actions in toolbar
   1.262 -			for (int i=0; i<flag.size(); ++i)
   1.263 -				flag.at(i)->updateAction();
   1.264 -		}	
   1.265 -	}
   1.266 -}
   1.267 -
   1.268  FlagObj* FlagRowObj::findFlag (const QString &name)
   1.269  {
   1.270  	for (int i=0; i<flag.size(); ++i)