Menu

[2edc72]: / flagrow.cpp  Maximize  Restore  History

Download this file

164 lines (137 with data), 3.3 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
#include <QDebug>
#include "flagrow.h"
/////////////////////////////////////////////////////////////////
// FlagRow
/////////////////////////////////////////////////////////////////
FlagRow::FlagRow()
{
toolBar=NULL;
masterRow=NULL;
// cout << "Const FlagRow ()\n";
// init ();
}
FlagRow::~FlagRow()
{
//cout << "Destr FlagRow\n";
// while (!flag.isEmpty())
// delete (flag.takeFirst() );
}
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;
}
void FlagRow::toggle (const QString &name, FlagRow *masterRow)
{
if (isActive(name) )
deactivate (name);
else
{
activate (name);
if (!masterRow) return;
Flag *flag=masterRow->getFlag (name);
if (!flag) return;
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));
}
}
}
void FlagRow::activate (const QString &name)
{
if (!isActive (name))
activeNames.append (name);
}
void FlagRow::deactivate (const QString &name) //FIXME-4 complaints if CTRL-E is pressed with focus on NoteEditor ?!
{
int n=activeNames.indexOf (name);
if (n>=0)
activeNames.removeAt(n);
else
qWarning ()<<QString("FlagRow::deactivate - %1 is not active").arg(name);
}
void FlagRow::deactivateAll ()
{
if (!toolBar) activeNames.clear();
}
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.