void TimeEntryDialog::setElementList( ElementList list ) { if( list.isEmpty() ) return; // Go through the element list and make sure that // each element is in the same project and has // the same asset type ElementList valid; ElementList invalid; AssetType type; Project p; foreach( Element e, list ) { if( p.isRecord() && e.project() != p ) continue; QVariant v = e.getValue( "allowTime" ); if( v.toBool() || (v.isNull() && (e.children().size()==0) ) ) { if( !type.isRecord() ) { type = e.assetType(); p = e.project(); } else if( e.assetType() != type ) continue; if( !valid.contains( e ) ) valid += e; } else invalid += e; } mAssetTree->setSelection( RecordList() ); if( valid.isEmpty() ) { if( !invalid.isEmpty() ) { setProject( invalid[0].project() ); QStringList sl; foreach( Element e, invalid ) sl += e.displayName(true); mAssetFilterEdit->setText( sl.join(",") ); } } else { Element first = valid[0]; QStringList sl; foreach( Element e, valid ) sl += e.displayName(true); mAssetFilterEdit->setText( sl.join(",") ); if( first.isRecord() ) { setProject( first.project() ); setAssetType( type ); mAssetTree->setSelection( valid ); mAssetTree->scrollTo( first ); } } }
void KreAuthorActionsHandler::remove() { int id = m_listWidget->selectedRowId(); if ( id == -1 ) return; ElementList recipeDependancies; m_database->findUseOfAuthorInRecipes( &recipeDependancies, id ); //Check the current usage of the author in existing recipes, if it's used warn //that the recipes using that author will be modified, otherwise just say that //the selected author will be removed. if ( recipeDependancies.isEmpty() ) { switch ( KMessageBox::warningContinueCancel( m_listWidget, i18n( "Are you sure you want to delete this author?" ) ) ) { case KMessageBox::Continue: m_database->removeAuthor( id ); break; } return; } else { ListInfo info; info.list = recipeDependancies; info.name = i18n("Recipes"); QPointer<DependanciesDialog> warnDialog = new DependanciesDialog( m_listWidget, info, false ); if ( warnDialog->exec() == QDialog::Accepted ) m_database->removeAuthor( id ); delete warnDialog; } }
// read a formula group recursively. Called by readFormula. QString KMolCalc::readGroup(const QString& s, ElementList* els) { if (s.isEmpty()) return QString ("Enter a formula."); //ERROR int sl = s.length(); int i = 0; QString errors ("OK"); bool ok = TRUE; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); if (!ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR ElementList* elstemp = new ElementList; while (i < sl) { int j = i; if (s[i] == '(') { ElementList* inner = new ElementList; int level = 1; // count levels of nested ( ). while (1) { if (i++ == sl) { delete inner; delete elstemp; return QString ("Bad formula."); //ERROR } if (s[i] == '(') level++; if (s[i] == ')') level--; if (level == 0) break; } errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); j = ++i; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); if (!ok || suffix == 0) { delete inner; delete elstemp; return QString ("Bad formula."); // ERROR } inner->addTo(*elstemp, suffix); delete inner; inner = NULL; } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || s[i] == '\'')); QString elname = s.mid(j, i-j); j = i; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); if (!ok || suffix == 0) { delete elstemp; return QString ("Bad formula."); // ERROR } SubUnit* group = elstable->find(elname); if (group == 0) { delete elstemp; return QString ("Undefined symbol: ") + elname; //ERROR } group->addTo(*elstemp, suffix); } else if (s[i] == '+') { if (elstemp->isEmpty()) { delete elstemp; return QString ("Bad formula."); //ERROR } elstemp->addTo(*els, prefix); delete elstemp; errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els); return errors; } else { delete elstemp; return QString ("Bad formula."); //ERROR } } elstemp->addTo(*els, prefix); delete elstemp; return errors; }