insilmaril@774: #include "flagrow.h" insilmaril@774: insilmaril@774: #include insilmaril@774: using namespace std; insilmaril@774: insilmaril@774: ///////////////////////////////////////////////////////////////// insilmaril@774: // FlagRow insilmaril@774: ///////////////////////////////////////////////////////////////// insilmaril@774: FlagRow::FlagRow() insilmaril@774: { insilmaril@774: toolBar=NULL; insilmaril@774: masterRow=NULL; insilmaril@774: // cout << "Const FlagRow ()\n"; insilmaril@774: // init (); insilmaril@774: } insilmaril@774: insilmaril@774: FlagRow::~FlagRow() insilmaril@774: { insilmaril@774: //cout << "Destr FlagRow\n"; insilmaril@774: // while (!flag.isEmpty()) insilmaril@774: // delete (flag.takeFirst() ); insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::addFlag (Flag *flag) insilmaril@774: { insilmaril@774: Flag *f=new Flag; insilmaril@774: f->copy (flag); insilmaril@774: flags.append (f); insilmaril@774: activeNames.append (flag->getName()); insilmaril@774: } insilmaril@774: insilmaril@774: Flag* FlagRow::getFlag (const QString &name) insilmaril@774: { insilmaril@774: int i=0; insilmaril@774: while (i<=flags.size()-1) insilmaril@774: { insilmaril@774: if (flags.at(i)->getName()==name) insilmaril@774: return flags.at(i); insilmaril@774: i++; insilmaril@774: } insilmaril@774: return NULL; insilmaril@774: } insilmaril@774: insilmaril@774: QStringList FlagRow::activeFlagNames() insilmaril@774: { insilmaril@774: return activeNames; insilmaril@774: } insilmaril@774: insilmaril@774: insilmaril@774: bool FlagRow::isActive (const QString &name) insilmaril@774: { insilmaril@774: return activeNames.contains (name); insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::toggle (const QString &name, FlagRow *masterRow) insilmaril@774: { insilmaril@774: if (isActive(name) ) insilmaril@774: deactivate (name); insilmaril@774: else insilmaril@774: { insilmaril@774: activate (name); insilmaril@774: if (!masterRow) return; insilmaril@774: insilmaril@774: Flag *flag=masterRow->getFlag (name); insilmaril@774: if (!flag) return; insilmaril@774: QString mygroup=flag->getGroup(); insilmaril@774: insilmaril@774: for (int i=0;igetFlag (activeNames.at(i) ); insilmaril@774: if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup()) insilmaril@774: deactivate (activeNames.at(i)); insilmaril@774: } insilmaril@774: } insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::activate (const QString &name) insilmaril@774: { insilmaril@774: if (!activeNames.contains (name)) insilmaril@774: activeNames.append (name); insilmaril@774: else insilmaril@774: qWarning (QString("FlagRow::activate - %1 is already active").arg(name)); insilmaril@774: } insilmaril@774: insilmaril@774: insilmaril@774: void FlagRow::deactivate (const QString &name) insilmaril@774: { insilmaril@774: int n=activeNames.indexOf (name); insilmaril@774: if (n>=0) insilmaril@774: activeNames.removeAt(n); insilmaril@774: else insilmaril@774: qWarning (QString("FlagRow::deactivate - %1 is not active").arg(name)); insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::deactivateAll () insilmaril@774: { insilmaril@774: if (!toolBar) activeNames.clear(); insilmaril@774: } insilmaril@774: insilmaril@774: insilmaril@774: void FlagRow::resetUsedCounter() insilmaril@774: { insilmaril@774: for (int i=0; isetUsed (false); insilmaril@774: } insilmaril@774: insilmaril@774: QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) insilmaril@774: { insilmaril@774: // Build xml string insilmaril@774: QString s; insilmaril@774: insilmaril@774: if (!toolBar) insilmaril@774: { insilmaril@774: if (!activeNames.isEmpty()) insilmaril@774: for (int i=0; igetFlag(activeNames.at(i))->setUsed(true); insilmaril@774: } insilmaril@774: } else insilmaril@774: // Save icons to dir, if verbose is set (xml export) insilmaril@774: // and I am a master insilmaril@774: // and this flag is really used somewhere insilmaril@774: if (writeflags) insilmaril@774: for (int i=0; iisUsed()) flags.at(i)->saveToDir (tmpdir,prefix); insilmaril@774: return s; insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::setName (const QString &n) insilmaril@774: { insilmaril@774: rowName=n; insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::setToolBar (QToolBar *tb) insilmaril@774: { insilmaril@774: toolBar=tb; insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::setMasterRow (FlagRow *row) insilmaril@774: { insilmaril@774: masterRow=row; insilmaril@774: } insilmaril@774: insilmaril@774: void FlagRow::updateToolBar (const QStringList &activeNames) insilmaril@774: { insilmaril@774: if (toolBar ) insilmaril@774: { insilmaril@774: if (activeNames.isEmpty() ) insilmaril@774: for (int i=0;igetAction()->setChecked (false); insilmaril@774: else insilmaril@774: for (int i=0;igetAction()->setChecked ( insilmaril@774: activeNames.contains (flags.at(i)->getName())); insilmaril@774: } insilmaril@774: return; insilmaril@774: insilmaril@774: } insilmaril@774: insilmaril@774: