flagrow.cpp
changeset 779 1fb50e79661c
child 823 0bba81dde1bc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/flagrow.cpp	Tue Jul 07 09:34:24 2009 +0000
     1.3 @@ -0,0 +1,164 @@
     1.4 +#include "flagrow.h"
     1.5 +
     1.6 +#include <iostream>
     1.7 +using namespace std;
     1.8 +
     1.9 +/////////////////////////////////////////////////////////////////
    1.10 +// FlagRow
    1.11 +/////////////////////////////////////////////////////////////////
    1.12 +FlagRow::FlagRow()
    1.13 +{
    1.14 +	toolBar=NULL;
    1.15 +	masterRow=NULL;
    1.16 +//    cout << "Const FlagRow ()\n";
    1.17 +//    init ();
    1.18 +}
    1.19 +
    1.20 +FlagRow::~FlagRow()
    1.21 +{
    1.22 +	//cout << "Destr FlagRow\n";
    1.23 +//	while (!flag.isEmpty())
    1.24 +//		delete (flag.takeFirst() );
    1.25 +}
    1.26 +
    1.27 +void FlagRow::addFlag (Flag *flag)
    1.28 +{
    1.29 +	Flag *f=new Flag;
    1.30 +	f->copy (flag);
    1.31 +	flags.append (f);
    1.32 +	activeNames.append (flag->getName());
    1.33 +}
    1.34 +
    1.35 +Flag* FlagRow::getFlag (const QString &name)
    1.36 +{
    1.37 +	int i=0;
    1.38 +	while (i<=flags.size()-1)
    1.39 +	{
    1.40 +		if (flags.at(i)->getName()==name)
    1.41 +			return flags.at(i);
    1.42 +		i++;	
    1.43 +	}
    1.44 +	return NULL;
    1.45 +}
    1.46 +
    1.47 +QStringList FlagRow::activeFlagNames()
    1.48 +{
    1.49 +	return activeNames;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +bool FlagRow::isActive (const QString &name)
    1.54 +{
    1.55 +	return activeNames.contains (name);
    1.56 +}
    1.57 +
    1.58 +void FlagRow::toggle (const QString &name, FlagRow *masterRow)
    1.59 +{
    1.60 +	if (isActive(name) )
    1.61 +		deactivate (name);
    1.62 +	else
    1.63 +	{
    1.64 +		activate (name);	
    1.65 +		if (!masterRow) return;
    1.66 +
    1.67 +		Flag *flag=masterRow->getFlag (name);
    1.68 +		if (!flag) return;
    1.69 +		QString mygroup=flag->getGroup();
    1.70 +
    1.71 +		for (int i=0;i<activeNames.size();++i)
    1.72 +		{
    1.73 +			flag=masterRow->getFlag (activeNames.at(i) );
    1.74 +			if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup())
    1.75 +				deactivate (activeNames.at(i));
    1.76 +		}
    1.77 +	}
    1.78 +}
    1.79 +
    1.80 +void FlagRow::activate (const QString &name)
    1.81 +{
    1.82 +	if (!activeNames.contains (name))
    1.83 +		activeNames.append (name);
    1.84 +	else
    1.85 +		qWarning (QString("FlagRow::activate - %1 is already active").arg(name));
    1.86 +}
    1.87 +
    1.88 +
    1.89 +void FlagRow::deactivate (const QString &name)
    1.90 +{
    1.91 +	int n=activeNames.indexOf (name);
    1.92 +	if (n>=0)
    1.93 +		activeNames.removeAt(n);
    1.94 +	else
    1.95 +		qWarning (QString("FlagRow::deactivate - %1 is not active").arg(name));
    1.96 +}
    1.97 +
    1.98 +void FlagRow::deactivateAll ()
    1.99 +{
   1.100 +	if (!toolBar) activeNames.clear();
   1.101 +}
   1.102 +
   1.103 +
   1.104 +void FlagRow::resetUsedCounter()
   1.105 +{
   1.106 +	for (int i=0; i<flags.size(); ++i)
   1.107 +		flags.at(i)->setUsed (false);
   1.108 +}
   1.109 +
   1.110 +QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) 
   1.111 +{
   1.112 +	// Build xml string
   1.113 +	QString s;
   1.114 +	
   1.115 +	if (!toolBar)
   1.116 +	{
   1.117 +		if (!activeNames.isEmpty())
   1.118 +		for (int i=0; i<activeNames.size(); ++i)
   1.119 +		{
   1.120 +			// save flag to xml, if flag is set 
   1.121 +			s+=valueElement("standardflag",activeNames.at(i));
   1.122 +
   1.123 +			// and tell parentRow, that this flag is used	
   1.124 +			masterRow->getFlag(activeNames.at(i))->setUsed(true);
   1.125 +		}	
   1.126 +	} else
   1.127 +		// Save icons to dir, if verbose is set (xml export)
   1.128 +		// and I am a master
   1.129 +		// and this flag is really used somewhere
   1.130 +		if (writeflags)
   1.131 +			for (int i=0; i<flags.size(); ++i)
   1.132 +				if (flags.at(i)->isUsed()) flags.at(i)->saveToDir (tmpdir,prefix);
   1.133 +	return s;		
   1.134 +}
   1.135 +
   1.136 +void FlagRow::setName (const QString &n)
   1.137 +{
   1.138 +	rowName=n;
   1.139 +}
   1.140 +
   1.141 +void FlagRow::setToolBar (QToolBar *tb)
   1.142 +{
   1.143 +	toolBar=tb;
   1.144 +}
   1.145 +
   1.146 +void FlagRow::setMasterRow (FlagRow *row)
   1.147 +{
   1.148 +	masterRow=row;
   1.149 +}
   1.150 +
   1.151 +void FlagRow::updateToolBar (const QStringList &activeNames)
   1.152 +{
   1.153 +	if (toolBar )
   1.154 +	{
   1.155 +		if (activeNames.isEmpty() )
   1.156 +			for (int i=0;i<flags.size();++i)
   1.157 +				flags.at(i)->getAction()->setChecked (false);
   1.158 +		else		
   1.159 +			for (int i=0;i<flags.size();++i)
   1.160 +				flags.at(i)->getAction()->setChecked (
   1.161 +					activeNames.contains (flags.at(i)->getName()));
   1.162 +	}
   1.163 +	return;
   1.164 +		
   1.165 +}
   1.166 +
   1.167 +