[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Wed Jun 26 08:43:31 PDT 2013
sc/inc/column.hxx | 1 +
sc/inc/document.hxx | 10 ++++++++++
sc/inc/table.hxx | 2 ++
sc/source/core/data/column2.cxx | 26 ++++++++++++++++++++++++++
sc/source/core/data/documen8.cxx | 9 +++++++++
sc/source/core/data/table1.cxx | 8 ++++++++
sc/source/core/tool/formulagroup.cxx | 9 ++++++---
7 files changed, 62 insertions(+), 3 deletions(-)
New commits:
commit d8b0903ef194c78a05541d45dc05c2f860dc7cbf
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Jun 26 11:45:28 2013 -0400
Implement a way to set an array of formula results to formula cell group.
Change-Id: Ifdea531e963339607a5066f81af32ffedfd408aa
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 93d292d..974a934 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -447,6 +447,7 @@ public:
bool ResolveStaticReference( ScMatrix& rMat, SCCOL nMatCol, SCROW nRow1, SCROW nRow2 );
void FillMatrix( ScMatrix& rMat, size_t nMatCol, SCROW nRow1, SCROW nRow2 ) const;
const double* FetchDoubleArray( sc::FormulaGroupContext& rCxt, SCROW nRow1, SCROW nRow2 ) const;
+ void SetFormulaResults( SCROW nRow, const double* pResults, size_t nLen );
void SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat );
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 5069ccc..87975ad 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1703,6 +1703,16 @@ public:
void FillMatrix( ScMatrix& rMat, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const;
+ /**
+ * Set an array of numerical formula results to a group of contiguous
+ * formula cells.
+ *
+ * @param rTopPos position of the top formula cell of a group.
+ * @param pResults array of numeric results.
+ * @param nLen length of numeric results.
+ */
+ void SetFormulaResults( const ScAddress& rTopPos, const double* pResults, size_t nLen );
+
private:
ScDocument(const ScDocument& r); // disabled with no definition
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index e945477..0d0aa8e 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -849,6 +849,8 @@ public:
void InterpretDirtyCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
+ void SetFormulaResults( SCCOL nCol, SCROW nRow, const double* pResults, size_t nLen );
+
/** Replace behaves differently to the Search; adjust the rCol and rRow accordingly.
'Replace' replaces at the 'current' position, but in order to achieve
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 80491b5..7205672 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2092,6 +2092,32 @@ const double* ScColumn::FetchDoubleArray( sc::FormulaGroupContext& /*rCxt*/, SCR
return &sc::numeric_block::at(*aPos.first->data, aPos.second);
}
+void ScColumn::SetFormulaResults( SCROW nRow, const double* pResults, size_t nLen )
+{
+ sc::CellStoreType::position_type aPos = maCells.position(nRow);
+ sc::CellStoreType::iterator it = aPos.first;
+ if (it->type != sc::element_type_formula)
+ // This is not a formula block.
+ return;
+
+ size_t nBlockLen = it->size - aPos.second;
+ if (nBlockLen < nLen)
+ // Result array is longer than the length of formula cells. Not good.
+ return;
+
+ sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data);
+ std::advance(itCell, aPos.second);
+
+ const double* pResEnd = pResults + nLen;
+ for (; pResults != pResEnd; ++pResults, ++itCell)
+ {
+ ScFormulaCell& rCell = **itCell;
+ rCell.SetResultDouble(*pResults);
+ rCell.ResetDirty();
+ rCell.SetChanged(true);
+ }
+}
+
void ScColumn::SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat )
{
short eOldType = pDocument->GetFormatTable()->GetType(
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 694b398..71e1878 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -449,6 +449,15 @@ void ScDocument::FillMatrix(
pTab->FillMatrix(rMat, nCol1, nRow1, nCol2, nRow2);
}
+void ScDocument::SetFormulaResults( const ScAddress& rTopPos, const double* pResults, size_t nLen )
+{
+ ScTable* pTab = FetchTable(rTopPos.Tab());
+ if (!pTab)
+ return;
+
+ pTab->SetFormulaResults(rTopPos.Col(), rTopPos.Row(), pResults, nLen);
+}
+
//------------------------------------------------------------------------
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 2de23b1..be6f4ae 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -2215,6 +2215,14 @@ void ScTable::InterpretDirtyCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW
aCol[nCol].InterpretDirtyCells(nRow1, nRow2);
}
+void ScTable::SetFormulaResults( SCCOL nCol, SCROW nRow, const double* pResults, size_t nLen )
+{
+ if (!ValidCol(nCol))
+ return;
+
+ aCol[nCol].SetFormulaResults(nRow, pResults, nLen);
+}
+
const SvtBroadcaster* ScTable::GetBroadcaster( SCCOL nCol, SCROW nRow ) const
{
if (!ValidColRow(nCol, nRow))
diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx
index 1ee57b5..c30d895 100644
--- a/sc/source/core/tool/formulagroup.cxx
+++ b/sc/source/core/tool/formulagroup.cxx
@@ -27,6 +27,8 @@ bool FormulaGroupInterpreter::interpret()
// Until we implement group calculation for real, decompose the group into
// individual formula token arrays for individual calculation.
ScAddress aTmpPos = maTopPos;
+ std::vector<double> aResults;
+ aResults.reserve(mxGroup->mnLength);
for (sal_Int32 i = 0; i < mxGroup->mnLength; ++i)
{
aTmpPos.SetRow(mxGroup->mnStart + i);
@@ -86,11 +88,12 @@ bool FormulaGroupInterpreter::interpret()
ScInterpreter aInterpreter(pDest, &mrDoc, aTmpPos, aCode2);
aInterpreter.Interpret();
- pDest->SetResultToken(aInterpreter.GetResultToken().get());
- pDest->ResetDirty();
- pDest->SetChanged(true);
+ const formula::FormulaToken* pResToken = aInterpreter.GetResultToken().get();
+ aResults.push_back(pResToken->GetDouble());
}
+ mrDoc.SetFormulaResults(maTopPos, &aResults[0], aResults.size());
+
return true;
}
More information about the Libreoffice-commits
mailing list