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