void Spreadsheet::paste() { QTableWidgetSelectionRange range = selectedRange(); QString str = QApplication::clipboard()->text(); QStringList rows = str.split('\n'); int numRows = rows.count(); int numColumns = rows.first().count('\t') + 1; if( range.rowCount() * range.columnCount() != 1 && ( range.rowCount() != numRows || range.columnCount() != numColumns) ) { QMessageBox::information(this, tr("Spreadsheet") , tr("The information cannot be pasted because the copy" "and paste areas aren't the same size.")); return; } for(int i = 0; i < numRows; ++i) { QStringList columns = rows[i].split('\t'); for(int j = 0; j < numColumns; ++j) { int row = range.topRow() + i; int column = range.leftColumn() + j; if(row < RowCount && column < ColumnCount) setFormula(row, column, columns[j]); } } somethingChanged(); }
void Spreadsheet::sort(const SpreadsheetCompare &compare) { QList<QStringList> rows; QTableWidgetSelectionRange range = selectedRange(); int i; for(i = 0; i < range.rowCount(); ++i) { QStringList row; for(int j = 0; j < range.columnCount(); ++j) row.append(formula(range.topRow() + i, range.leftColumn() + j)); rows.append(row); } qStableSort(rows.begin(), rows.end(), compare); for(i = 0; i < range.rowCount(); ++i) { for(int j = 0; j < range.columnCount(); ++j) setFormula(range.topRow() + i, range.leftColumn() + j, rows[i][j]); } clearSelection(); somethingChanged(); }
bool Spreadsheet::readFile(const QString &fileName) { QFile file(fileName); if(!file.open(QIODevice::ReadOnly)){ QMessageBox::warning(this, tr("Spreadsheet"), tr("Cannot read the file %1:\n%2.") .arg(file.fileName().arg(file.errorString()))); return false; } QDataStream in(&file); in.setVersion(QDataStream::Qt_4_3); QApplication::setOverrideCursor(Qt::WaitCursor); quint32 magicNumber; in >> magicNumber; if(magicNumber != MagicNumber){ QMessageBox::warning(this, tr("Spreadsheet"), tr("%1 is not a spreadsheet file.").arg(file.fileName())); return false; } clear(); quint16 row, col; QString str; while(!in.atEnd()){ in >> row >> col >> str; setFormula(row, col, str); } QApplication::restoreOverrideCursor(); return true; }
bool Spreadsheet::readFile(const QString &fileName) { QFile file(fileName); if(!file.open(QIODevice::ReadOnly)) { QMessageBox::warning(this,tr("Spreadsheet"), tr("Cannot read file %1:\n%2").arg(fileName).arg(file.errorString())); return false; } QDataStream in(&file); quint32 magic; in >> magic; if(magic != MagicNumber) { QMessageBox::warning(this,tr("Spreadsheet"), tr("This file is not Spreadsheet")); return false; } clear(); quint16 row; quint16 column; QString str; QApplication::setOverrideCursor(Qt::WaitCursor); while(!in.atEnd()) { in >> row >> column >> str; setFormula(row,column,str); } QApplication::restoreOverrideCursor(); return true; }
void Spreadsheet::paste() { QString str = QApplication::clipboard()->text(); QStringList rows = str.split('\n'); int numRows = rows.count(); int numCols = rows.first().count('\t') + 1; QTableWidgetSelectionRange selection = selectedRange(); if(selection.rowCount() * selection.columnCount() != 1 && (numRows != selection.rowCount() || numCols != selection.columnCount())){ QMessageBox::information(this, tr("Spreadsheet"), tr("The information cannot be paseted" "because the copy and the paste areas aren't the same size")); return; } int destRow = selection.topRow(); int destCol = selection.leftColumn(); for(int i=0; i<numRows; i++){ QStringList columns = rows[i].split('\t'); for(int j=0; j<numCols; j++){ if(i+destRow < RowCount && j+destCol < ColumnCount) setFormula(i+destRow, j+destCol, columns[j]); } } somethingChanged(); }
void Residue::setModification(const String & modification) { //modification_ = modification; ModificationsDB * mod_db = ModificationsDB::getInstance(); ResidueModification mod = mod_db->getModification(one_letter_code_, modification, ResidueModification::ANYWHERE); modification_ = mod.getId(); // update all the members if (mod.getAverageMass() != 0) { average_weight_ = mod.getAverageMass(); } if (mod.getMonoMass() != 0) { mono_weight_ = mod.getMonoMass(); } bool updated_formula(false); if (!mod.getDiffFormula().isEmpty()) { updated_formula = true; setFormula(getFormula() + mod.getDiffFormula()); } if (mod.getFormula() != "" && !updated_formula) { updated_formula = true; String formula = mod.getFormula(); formula.removeWhitespaces(); formula_ = EmpiricalFormula(formula); } if (updated_formula) { average_weight_ = formula_.getAverageWeight(); mono_weight_ = formula_.getMonoWeight(); } else { if (mod.getAverageMass() != 0) { average_weight_ = mod.getAverageMass(); } if (mod.getMonoMass() != 0) { mono_weight_ = mod.getMonoMass(); } } // neutral losses loss_formulas_.clear(); loss_names_.clear(); if (mod.hasNeutralLoss()) { loss_formulas_.push_back(mod.getNeutralLossDiffFormula()); loss_names_.push_back(mod.getNeutralLossDiffFormula().toString()); } is_modified_ = true; }
/** * \brief Read XML formula element */ bool Column::XmlReadFormula(XmlStreamReader* reader) { QString formula; QStringList variableNames; QStringList columnPathes; while (reader->readNext()) { if (reader->isEndElement()) break; if (reader->name() == "text") { formula = reader->readElementText(); } else if (reader->name() == "variableNames") { while (reader->readNext()) { if (reader->name() == "variableNames" && reader->isEndElement()) break; if (reader->isStartElement()) variableNames << reader->readElementText(); } } else if (reader->name() == "columnPathes") { while (reader->readNext()) { if (reader->name() == "columnPathes" && reader->isEndElement()) break; if (reader->isStartElement()) columnPathes << reader->readElementText(); } } } setFormula(formula, variableNames, columnPathes); return true; }
/** Set Formula * @param attName :: Attribute name - must be "Formula" * @param attr :: Attribute value - the formula */ void UserFunctionMD::setAttribute(const std::string &attName, const UserFunctionMD::Attribute &attr) { UNUSED_ARG(attName); m_formula = attr.asString(); if (!m_vars.empty()) { setFormula(); } }
BillItemMeasure &BillItemMeasure::operator=(const BillItemMeasure &cp) { if( &cp != this ){ setUnitMeasure( cp.m_d->unitMeasure ); setComment( cp.m_d->comment ); setFormula( cp.m_d->formula ); } return *this; }
void FormulaEvaluation::showFormulaDialog() { FormulaDialog d(m_formula); if(d.exec() == QDialog::Rejected) return; setFormula(d.getFormula()); }
/** * Defining function's parameters here, ie after the workspace is set and * the dimensions are known. */ void UserFunctionMD::initDimensions() { // if (!getWorkspace()) return; if (m_vars.size() > 4) { m_vars.resize(m_dimensionIndexMap.size()); m_varNames.resize(m_dimensionIndexMap.size()); for (size_t i = 0; i < m_vars.size(); ++i) { m_varNames[i] = "x" + boost::lexical_cast<std::string>(i); m_parser.DefineVar(m_varNames[i], &m_vars[i]); } } setFormula(); }
void BillItemMeasure::loadFromXml10(const QXmlStreamAttributes &attrs) { if( attrs.hasAttribute( "comment" ) ){ setComment( attrs.value( "comment").toString() ); } if( attrs.hasAttribute( "formula" ) ){ QString f = attrs.value( "formula").toString(); if( m_d->parser->decimalSeparator() != "." ){ f.replace( ".", m_d->parser->decimalSeparator()); } setFormula( f ); } }
void UISpreadsheet::paste() { QTableWidgetSelectionRange range = selectedRange(); QString str = QApplication::clipboard()->text(); QStringList rows = str.split('\n'); int numRows = rows.count(); int numColumns = rows.first().count('\t') + 1; cout<<str.toStdString()<<" to paste "<<endl; if (range.rowCount() * range.columnCount() != 1 && (range.rowCount() != numRows || range.columnCount() != numColumns)) { QMessageBox::information(this, tr("Spreadsheet"), tr("The information cannot be pasted because the copy " "and paste areas aren't the same size.")); return; } cout<<"hola-------------------------------"<<endl; for (int i = 0; i < numRows; ++i) { QStringList columns = rows[i].split('\t'); // cout<<"---"<<columns[0].toStdString(); // cout<<" tmb "<<columns[1].toStdString()<<endl; cout<<numRows<<"filas to copy"<<endl; for (int j = 0; j < numColumns; ++j) { int row = range.topRow() + i; cout<<"row"<<row<<endl; int column = range.leftColumn() + j; if (row < RowCount && column < ColumnCount) setFormula(row, column, columns[j]); //somethingChanged(); //cout<<columns[j].toStdString()<<"should paste "<<row<<" "<<column<<endl; } } // somethingChanged(); }
void Column::Private::setFormula(int row, QString formula) { setFormula(Interval<int>(row,row), formula); }
Molecule::Molecule(QString formula) : QMap<const Element*, int>(), m_formula(formula), m_htmlFormula(""), m_validComputed(false), m_valid(false), m_htmlC(false), m_charge(0), m_state(NonMentioned) { setFormula(formula); // cf setFormula }
float fxTable::getSpot(FXPair fxp) { if (fxp.fgn == fxp.dom) return 1; bool inv = false; if (fxp.fgn < fxp.dom) { swap(fxp.fgn, fxp.dom); inv = true; } int pos = (fxp.fgn - 1)*fxp.fgn / 2 + fxp.dom; fxQuote& fxq = fx[pos]; if (fxq.status == FORMULA) { if (fxq.dirty) { throw "Recompute dirty pair"; // XXX TODO compute level based on formula and list of depedencies } } else if (fxq.status == INVALIDQUOTE) { // FX level requires combining several quotes, used Dijkstra's shortest path // lookup[dom] contains the value of the pair fgndom if known, otherwise -1 int i; for (i = 0; i <= n; ++i) { lookup[i] = -1; // any invalid value visited[i] = false; } std::list<Currency> tovisit; lookup[fxp.fgn] = 1; prev[fxp.fgn] = fxp.fgn; Currency dom2, fgn2; tovisit.push_back(fxp.fgn); do { fgn2 = tovisit.front(); tovisit.pop_front(); visited[fgn2] = true; for (std::set<Currency>::const_iterator it = fxpairs[fgn2].begin(); it != fxpairs[fgn2].end(); ++it) { dom2 = *it; if (lookup[dom2] != -1) continue; lookup[dom2] = lookup[fgn2]*getSpot(FXPair(fgn2, dom2)); // we have a direct quote for fgndom or its inverse setFormula(FXPair(fxp.fgn, dom2), lookup[dom2]); if (dom2 == fxp.dom) goto _exit; if (!visited[dom2]) { tovisit.push_back(dom2); } } } while (!tovisit.empty()); _exit: if (dom2 == fxp.dom) { fxq.level = lookup[dom2]; fxq.dirty = false; fxq.status = FORMULA; // XXX TODO record formula. } else { throw "Fx pair is missing"; } } return inv ? 1 / fxq.level : fxq.level; } // float fxTable::value(Currency fgn, Currency dom)