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