diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-12 15:23:28 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-12 19:46:29 -0400 |
commit | 2624788f23d265f0dfeda544f57b9d90a2ab2979 (patch) | |
tree | fe2885a75a7bfbde4936f9cac8df21412c0f0da0 | |
parent | 30503611efc30ac7a3b09744913f048bf28ef70a (diff) |
Do the splitting of formula groups.
Change-Id: I5a8661895b558b67abc19cdc39de9eb027bc1c34
-rw-r--r-- | sc/inc/sharedformula.hxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 9 | ||||
-rw-r--r-- | sc/source/core/tool/sharedformula.cxx | 28 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 2 |
4 files changed, 40 insertions, 9 deletions
diff --git a/sc/inc/sharedformula.hxx b/sc/inc/sharedformula.hxx index 9423384faab3..0b49751e7bd8 100644 --- a/sc/inc/sharedformula.hxx +++ b/sc/inc/sharedformula.hxx @@ -63,7 +63,15 @@ public: */ static void splitFormulaCellGroup(const CellStoreType::position_type& aPos); - static void splitFormulaCellGroups(CellStoreType& rCells, const std::vector<SCROW>& rBounds); + /** + * Split existing shared formula ranges at specified row positions. + * + * @param rCells cell storage container + * @param rBounds row positions at which to split existing shared formula + * ranges. Note that this method will directly modify this + * parameter to sort and remove duplicates. + */ + static void splitFormulaCellGroups(CellStoreType& rCells, std::vector<SCROW>& rBounds); /** * See if two specified adjacent formula cells can be merged, and if they diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index a395c78b4753..e4ad8c71b22b 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2364,6 +2364,10 @@ bool ScColumn::UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pU if (rCxt.meMode == URM_COPY) return UpdateReferenceOnCopy(rCxt, pUndoDoc); + if (IsEmptyData()) + // Cells in this column are all empty. + return false; + std::vector<SCROW> aBounds; bool bThisColShifted = (rCxt.maRange.aStart.Tab() <= nTab && nTab <= rCxt.maRange.aEnd.Tab() && @@ -2387,11 +2391,6 @@ bool ScColumn::UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pU UpdateRefGroupBoundChecker aBoundChecker(rCxt, aBounds); std::for_each(maCells.begin(), maCells.end(), aBoundChecker); - // Sort and remove duplicates. - std::sort(aBounds.begin(), aBounds.end()); - std::vector<SCROW>::iterator it = std::unique(aBounds.begin(), aBounds.end()); - aBounds.erase(it, aBounds.end()); - // Do the actual splitting. sc::SharedFormulaUtil::splitFormulaCellGroups(maCells, aBounds); diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx index d9f3a2595f67..9299e3349aa2 100644 --- a/sc/source/core/tool/sharedformula.cxx +++ b/sc/source/core/tool/sharedformula.cxx @@ -64,9 +64,33 @@ void SharedFormulaUtil::splitFormulaCellGroup(const CellStoreType::position_type } } -void SharedFormulaUtil::splitFormulaCellGroups(CellStoreType& rCells, const std::vector<SCROW>& rBounds) +void SharedFormulaUtil::splitFormulaCellGroups(CellStoreType& rCells, std::vector<SCROW>& rBounds) { - // TODO: Implement this. + if (rBounds.empty()) + return; + + // Sort and remove duplicates. + std::sort(rBounds.begin(), rBounds.end()); + std::vector<SCROW>::iterator it = std::unique(rBounds.begin(), rBounds.end()); + rBounds.erase(it, rBounds.end()); + + it = rBounds.begin(); + SCROW nRow = *it; + CellStoreType::position_type aPos = rCells.position(nRow); + if (aPos.first == rCells.end()) + return; + + splitFormulaCellGroup(aPos); + std::vector<SCROW>::iterator itEnd = rBounds.end(); + for (++it; it != itEnd; ++it) + { + nRow = *it; + aPos = rCells.position(aPos.first, nRow); + if (aPos.first == rCells.end()) + return; + + splitFormulaCellGroup(aPos); + } } void SharedFormulaUtil::joinFormulaCells(const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 1fbf32581dbf..e5627ff5a0d6 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2981,7 +2981,7 @@ void checkBounds( SCROW nOffset = rCxt.maRange.aStart.Row() - aAbs.aStart.Row(); rBounds.push_back(rPos.Row()+nOffset); // Ditto. - nOffset = rCxt.maRange.aEnd.Row() - aAbs.aStart.Row(); + nOffset = rCxt.maRange.aEnd.Row() + 1 - aAbs.aStart.Row(); rBounds.push_back(rPos.Row()+nOffset); } |