Menu

[c54480]: / flagrow.cpp  Maximize  Restore  History

Download this file

209 lines (175 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include <QDebug>
#include "flagrow.h"
extern bool debug;
/////////////////////////////////////////////////////////////////
// FlagRow
/////////////////////////////////////////////////////////////////
FlagRow::FlagRow()
{
toolBar=NULL;
masterRow=NULL;
// qDebug()<< "Const FlagRow ()";
}
FlagRow::~FlagRow()
{
//qDebug()<< "Destr FlagRow";
}
void FlagRow::addFlag (Flag *flag)
{
Flag *f=new Flag;
;
f->copy (flag);
flags.append (f);
activeNames.append (flag->getName());
}
Flag* FlagRow::getFlag (const QString &name)
{
int i=0;
while (i<=flags.size()-1)
{
if (flags.at(i)->getName()==name)
return flags.at(i);
i++;
}
return NULL;
}
QStringList FlagRow::activeFlagNames()
{
return activeNames;
}
bool FlagRow::isActive (const QString &name)
{
QString n;
foreach (n,activeNames)
if (n==name) return true;
return false;
}
bool FlagRow::toggle (const QString &name, FlagRow *masterRow)
{
if (isActive(name) )
return deactivate (name);
else
{
if (!activate (name) ) return false;
// Deactivate group
if (!masterRow) return false;
Flag *flag=masterRow->getFlag (name);
if (!flag) return false;
QString mygroup=flag->getGroup();
for (int i=0;i<activeNames.size();++i)
{
flag=masterRow->getFlag (activeNames.at(i) );
if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup())
deactivate (activeNames.at(i));
}
return true;
}
}
bool FlagRow::activate (const QString &name)
{
if (isActive (name))
{
if (debug) qWarning ()<<QString("FlagRow::activate - %1 is already active").arg(name);
return false;
}
if (!masterRow)
{
qWarning()<<"FlagRow::activate - no masterRow to activate "<<name;
return false;
}
// Check, if flag exists after all...
Flag *flag=masterRow->getFlag (name);
if (!flag)
{
qWarning()<<"FlagRow::activate - flag "<<name<<" does not exist here!";
return false;
}
activeNames.append (name);
return true;
}
bool FlagRow::deactivate (const QString &name)
{
int n=activeNames.indexOf (name);
if (n>=0)
{
activeNames.removeAt(n);
return true;
}
if (debug)
qWarning ()<<QString("FlagRow::deactivate - %1 is not active").arg(name);
return false;
}
bool FlagRow::deactivateGroup (const QString &gname)
{
if (!masterRow) return false;
if (gname.isEmpty()) return false;
foreach (QString s, activeNames )
{
Flag *flag=masterRow->getFlag (s);
if (flag && gname == flag->getGroup())
deactivate (s);
}
return true;
}
void FlagRow::deactivateAll ()
{
if (!toolBar) activeNames.clear();
}
void FlagRow::setEnabled (bool b)
{
toolBar->setEnabled (b);
}
void FlagRow::resetUsedCounter()
{
for (int i=0; i<flags.size(); ++i)
flags.at(i)->setUsed (false);
}
QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags)
{
// Build xml string
QString s;
if (!toolBar)
{
if (!activeNames.isEmpty())
for (int i=0; i<activeNames.size(); ++i)
{
// save flag to xml, if flag is set
s+=valueElement("standardflag",activeNames.at(i));
// and tell parentRow, that this flag is used
masterRow->getFlag(activeNames.at(i))->setUsed(true);
}
} else
// Save icons to dir, if verbose is set (xml export)
// and I am a master
// and this flag is really used somewhere
if (writeflags)
for (int i=0; i<flags.size(); ++i)
if (flags.at(i)->isUsed()) flags.at(i)->saveToDir (tmpdir,prefix);
return s;
}
void FlagRow::setName (const QString &n)
{
rowName=n;
}
void FlagRow::setToolBar (QToolBar *tb)
{
toolBar=tb;
}
void FlagRow::setMasterRow (FlagRow *row)
{
masterRow=row;
}
void FlagRow::updateToolBar (const QStringList &activeNames)
{
if (toolBar )
{
for (int i=0;i<flags.size();++i)
flags.at(i)->getAction()->setChecked (false);
for (int i=0;i<flags.size();++i)
{
int n=activeNames.indexOf (flags.at(i)->getName());
if (n>=0)
flags.at(i)->getAction()->setChecked (true);
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.