Ejemplo n.º 1
0
void SpreadSheet::evaluate()
{
    QMap<QPair<int, int>, QString> &currentMap = sheet1Map;

    currentMap[QPair<int, int>(sheet1->currentRow(),sheet1->currentColumn())] =
			formulaEdit->text();

    QMap<QPair<int, int>, QString>::ConstIterator it;
    QString vars;
    for ( it = currentMap.begin(); it != currentMap.end(); ++it ) {
        int row = it.key().first;
        int col = it.key().second;
	    QTableWidgetItem *item = sheet1->item(row, col);
        if ( !item )
	        continue;
	    bool ok = false;
	    item->text().toInt( &ok );
	    if ( !ok )
	        continue;
	    vars += "var " + cellName(row, col) + "=" + item->text() + ";\n";
    }

    for ( it = currentMap.begin(); it != currentMap.end(); ++it ) {
	    QTableWidgetItem *item = sheet1->item(it.key().first, it.key().second);
	    if ( !item )
	        continue;
	    evaluateCell( item, *it, vars );
    }
}
Ejemplo n.º 2
0
std::vector<int> Bot::evaluateCells(const std::vector
                                    <Point>& cells) const {
    std::vector<int> estimates;
    for (int i = 0; i < cells.size(); i++) {
        estimates.push_back(evaluateCell(cells[i]));
    }
    return estimates;
}
Ejemplo n.º 3
0
  double getCellValue(Index const& idx)
  {
    if (idx.x < 0 || idx.x >= currentDoc().width_ || idx.y < 0 || idx.y >= currentDoc().height_)
      return 0.0;

    Cell & cell = currentDoc().cells_[idx];
    if (!cell.evaluated)
      evaluateCell(cell);

    return cell.value;
  }
Ejemplo n.º 4
0
  void evaluateDocument()
  {
    Document & doc = currentDoc();

    for (auto & it : doc.cells_)
    {
      const Index idx = it.first;
      Cell & cell = it.second;

      cell.value = 0.0;

      if (cell.hasExpression)
      {
        if (cell.expression.empty())
        {
          cell.display = "#ERROR";
          cell.evaluated = true;
        }
        else
        {
          cell.evaluated = false;
          cell.display = "";
        }
      }
      else
      {
        cell.display = cell.text;
        cell.evaluated = true;

        try {
          cell.value = std::stod(cell.text);
        } catch (std::exception) {
        }
      }
    }

    for (auto & it : doc.cells_)
      evaluateCell(it.second);
  }