flagrow.cpp
author insilmaril
Mon, 29 Jun 2009 10:28:28 +0000
changeset 778 7b4e73ac247e
parent 774 2f002657dada
child 823 0bba81dde1bc
permissions -rw-r--r--
added imageitem.*
     1 #include "flagrow.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 /////////////////////////////////////////////////////////////////
     7 // FlagRow
     8 /////////////////////////////////////////////////////////////////
     9 FlagRow::FlagRow()
    10 {
    11 	toolBar=NULL;
    12 	masterRow=NULL;
    13 //    cout << "Const FlagRow ()\n";
    14 //    init ();
    15 }
    16 
    17 FlagRow::~FlagRow()
    18 {
    19 	//cout << "Destr FlagRow\n";
    20 //	while (!flag.isEmpty())
    21 //		delete (flag.takeFirst() );
    22 }
    23 
    24 void FlagRow::addFlag (Flag *flag)
    25 {
    26 	Flag *f=new Flag;
    27 	f->copy (flag);
    28 	flags.append (f);
    29 	activeNames.append (flag->getName());
    30 }
    31 
    32 Flag* FlagRow::getFlag (const QString &name)
    33 {
    34 	int i=0;
    35 	while (i<=flags.size()-1)
    36 	{
    37 		if (flags.at(i)->getName()==name)
    38 			return flags.at(i);
    39 		i++;	
    40 	}
    41 	return NULL;
    42 }
    43 
    44 QStringList FlagRow::activeFlagNames()
    45 {
    46 	return activeNames;
    47 }
    48 
    49 
    50 bool FlagRow::isActive (const QString &name)
    51 {
    52 	return activeNames.contains (name);
    53 }
    54 
    55 void FlagRow::toggle (const QString &name, FlagRow *masterRow)
    56 {
    57 	if (isActive(name) )
    58 		deactivate (name);
    59 	else
    60 	{
    61 		activate (name);	
    62 		if (!masterRow) return;
    63 
    64 		Flag *flag=masterRow->getFlag (name);
    65 		if (!flag) return;
    66 		QString mygroup=flag->getGroup();
    67 
    68 		for (int i=0;i<activeNames.size();++i)
    69 		{
    70 			flag=masterRow->getFlag (activeNames.at(i) );
    71 			if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup())
    72 				deactivate (activeNames.at(i));
    73 		}
    74 	}
    75 }
    76 
    77 void FlagRow::activate (const QString &name)
    78 {
    79 	if (!activeNames.contains (name))
    80 		activeNames.append (name);
    81 	else
    82 		qWarning (QString("FlagRow::activate - %1 is already active").arg(name));
    83 }
    84 
    85 
    86 void FlagRow::deactivate (const QString &name)
    87 {
    88 	int n=activeNames.indexOf (name);
    89 	if (n>=0)
    90 		activeNames.removeAt(n);
    91 	else
    92 		qWarning (QString("FlagRow::deactivate - %1 is not active").arg(name));
    93 }
    94 
    95 void FlagRow::deactivateAll ()
    96 {
    97 	if (!toolBar) activeNames.clear();
    98 }
    99 
   100 
   101 void FlagRow::resetUsedCounter()
   102 {
   103 	for (int i=0; i<flags.size(); ++i)
   104 		flags.at(i)->setUsed (false);
   105 }
   106 
   107 QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) 
   108 {
   109 	// Build xml string
   110 	QString s;
   111 	
   112 	if (!toolBar)
   113 	{
   114 		if (!activeNames.isEmpty())
   115 		for (int i=0; i<activeNames.size(); ++i)
   116 		{
   117 			// save flag to xml, if flag is set 
   118 			s+=valueElement("standardflag",activeNames.at(i));
   119 
   120 			// and tell parentRow, that this flag is used	
   121 			masterRow->getFlag(activeNames.at(i))->setUsed(true);
   122 		}	
   123 	} else
   124 		// Save icons to dir, if verbose is set (xml export)
   125 		// and I am a master
   126 		// and this flag is really used somewhere
   127 		if (writeflags)
   128 			for (int i=0; i<flags.size(); ++i)
   129 				if (flags.at(i)->isUsed()) flags.at(i)->saveToDir (tmpdir,prefix);
   130 	return s;		
   131 }
   132 
   133 void FlagRow::setName (const QString &n)
   134 {
   135 	rowName=n;
   136 }
   137 
   138 void FlagRow::setToolBar (QToolBar *tb)
   139 {
   140 	toolBar=tb;
   141 }
   142 
   143 void FlagRow::setMasterRow (FlagRow *row)
   144 {
   145 	masterRow=row;
   146 }
   147 
   148 void FlagRow::updateToolBar (const QStringList &activeNames)
   149 {
   150 	if (toolBar )
   151 	{
   152 		if (activeNames.isEmpty() )
   153 			for (int i=0;i<flags.size();++i)
   154 				flags.at(i)->getAction()->setChecked (false);
   155 		else		
   156 			for (int i=0;i<flags.size();++i)
   157 				flags.at(i)->getAction()->setChecked (
   158 					activeNames.contains (flags.at(i)->getName()));
   159 	}
   160 	return;
   161 		
   162 }
   163 
   164