summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-07-27 14:35:37 -0400
committerAndras Timar <andras.timar@collabora.com>2014-08-21 21:24:19 +0200
commit19f89b8aa1fc5bb16d3c56dd09e0c803b39ecb82 (patch)
treed2d0e351d1f1e58f79a828d415bcf694b6bef6e9
parent524736adc0108bb657faca051e2598b75d18f7a0 (diff)
fdo#81617: Split formula groups at sort range boundaries.
Otherwise, partially sorting a range may crash, or at best incorrectly update formula references. Change-Id: Iefcb86d205d83ccc5b684048bfd9aadabf6e13eb (cherry picked from commit a3fc7f20089062afa4f778e70ba8be84032a30a7) Reviewed-on: https://gerrit.libreoffice.org/10583 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/inc/table.hxx1
-rw-r--r--sc/source/core/data/table3.cxx8
-rw-r--r--sc/source/core/data/table7.cxx8
3 files changed, 17 insertions, 0 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index b7fc47570872..2d00ebd9f843 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -888,6 +888,7 @@ public:
formula::FormulaTokenRef ResolveStaticReference( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
formula::VectorRefArray FetchVectorRefArray( SCCOL nCol, SCROW nRow1, SCROW nRow2 );
+ void SplitFormulaGroups( SCCOL nCol, std::vector<SCROW>& rRows );
void UnshareFormulaCells( SCCOL nCol, std::vector<SCROW>& rRows );
void RegroupFormulaCells( SCCOL nCol );
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 31cfe2eb225e..3b63f7e4b4dd 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -755,6 +755,14 @@ void ScTable::SortReorderByRow(
ScSortInfoArray::RowsType* pRows = pArray->GetDataRows();
assert(pRows); // In sort-by-row mode we must have data rows already populated.
+ // Split formula groups at the sort range boundaries (if applicable).
+ std::vector<SCROW> aRowBounds;
+ aRowBounds.reserve(2);
+ aRowBounds.push_back(nRow1);
+ aRowBounds.push_back(nRow2+1);
+ for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+ SplitFormulaGroups(nCol, aRowBounds);
+
// Cells in the data rows only reference values in the document. Make
// a copy before updating the document.
diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx
index f3528dd448cf..b42761722e20 100644
--- a/sc/source/core/data/table7.cxx
+++ b/sc/source/core/data/table7.cxx
@@ -79,6 +79,14 @@ bool ScTable::HasUniformRowHeight( SCROW nRow1, SCROW nRow2 ) const
return nRow2 <= aData.mnRow2;
}
+void ScTable::SplitFormulaGroups( SCCOL nCol, std::vector<SCROW>& rRows )
+{
+ if (!ValidCol(nCol))
+ return;
+
+ sc::SharedFormulaUtil::splitFormulaCellGroups(aCol[nCol].maCells, rRows);
+}
+
void ScTable::UnshareFormulaCells( SCCOL nCol, std::vector<SCROW>& rRows )
{
if (!ValidCol(nCol))