diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-13 22:53:14 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-13 23:01:21 -0400 |
commit | c4d26f327605b77c8395bdb512d8ddcd8c11bfd1 (patch) | |
tree | a86a61a45d24aef8c8b6e0346ef5c3cee4819da5 /sc | |
parent | f110e4190e575915a584e60cd2fb58dcb5eb5eaa (diff) |
Regroup formula cells later in columns where references are updated.
Change-Id: I4dd6ade18e72d8f57583180463f9dda3603be4c2
Diffstat (limited to 'sc')
-rw-r--r-- | sc/Library_sc.mk | 1 | ||||
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/columnset.hxx | 40 | ||||
-rw-r--r-- | sc/inc/refupdatecontext.hxx | 2 | ||||
-rw-r--r-- | sc/inc/table.hxx | 5 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 5 | ||||
-rw-r--r-- | sc/source/core/data/columnset.cxx | 66 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 26 |
9 files changed, 144 insertions, 15 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 6f559f5bad1e..83e335856bdc 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -108,6 +108,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/core/data/column2 \ sc/source/core/data/column3 \ sc/source/core/data/columniterator \ + sc/source/core/data/columnset \ sc/source/core/data/columnspanset \ sc/source/core/data/compressedarray \ sc/source/core/data/colorscale \ diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 22bb9bdfa2d0..14d0bfee12fd 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -329,7 +329,7 @@ public: * @return true if reference of at least one formula cell has been * updated, false otherwise. */ - bool UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL ); + bool UpdateReference( sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL ); void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); void UpdateInsertTabOnlyCells( sc::RefUpdateInsertTabContext& rCxt ); diff --git a/sc/inc/columnset.hxx b/sc/inc/columnset.hxx new file mode 100644 index 000000000000..fb56303c1049 --- /dev/null +++ b/sc/inc/columnset.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef SC_COLUMNSET_HXX +#define SC_COLUMNSET_HXX + +#include "address.hxx" + +#include <vector> +#include <boost/unordered_set.hpp> +#include <boost/unordered_map.hpp> + +namespace sc { + +/** + * Simple container to keep track of sheet - column pair. + */ +class ColumnSet +{ + typedef boost::unordered_set<SCCOL> ColsType; + typedef boost::unordered_map<SCTAB, ColsType> TabsType; + TabsType maTabs; + +public: + void set(SCTAB nTab, SCCOL nCol); + bool has(SCTAB nTab, SCCOL nCol) const; + void getColumns(SCTAB nTab, std::vector<SCCOL>& rCols) const; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/refupdatecontext.hxx b/sc/inc/refupdatecontext.hxx index f5ca4d03c4be..ba0beedbc161 100644 --- a/sc/inc/refupdatecontext.hxx +++ b/sc/inc/refupdatecontext.hxx @@ -12,6 +12,7 @@ #include "global.hxx" #include "address.hxx" +#include "columnset.hxx" #include <boost/unordered_map.hpp> #include <boost/unordered_set.hpp> @@ -66,6 +67,7 @@ struct RefUpdateContext SCTAB mnTabDelta; UpdatedRangeNames maUpdatedNames; + ColumnSet maRegroupCols; RefUpdateContext(ScDocument& rDoc); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index a95f2bc3b66c..fa6247cb6312 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -58,6 +58,7 @@ namespace sc { class CopyToDocContext; class MixDocContext; class ColumnSpanSet; + class ColumnSet; struct ColumnBlockPosition; struct RefUpdateContext; struct RefUpdateInsertTabContext; @@ -388,8 +389,8 @@ public: bool TestInsertCol( SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ) const; void InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ); - void DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, - bool* pUndoOutline = NULL ); + void DeleteCol( + const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, bool* pUndoOutline = NULL ); void DeleteArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, sal_uInt16 nDelFlag); void CopyToClip( sc::CopyToClipContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pTable ); diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index e4ad8c71b22b..d8c3e6084146 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2359,7 +2359,7 @@ bool ScColumn::UpdateReferenceOnCopy( const sc::RefUpdateContext& rCxt, ScDocume return aHandler.isUpdated(); } -bool ScColumn::UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc ) +bool ScColumn::UpdateReference( sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc ) { if (rCxt.meMode == URM_COPY) return UpdateReferenceOnCopy(rCxt, pUndoDoc); @@ -2396,6 +2396,9 @@ bool ScColumn::UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pU UpdateRefOnNonCopy aHandler(nCol, nTab, rCxt, pUndoDoc); sc::ProcessFormula(maCells, aHandler); + if (aHandler.isUpdated()) + rCxt.maRegroupCols.set(nTab, nCol); + return aHandler.isUpdated(); } diff --git a/sc/source/core/data/columnset.cxx b/sc/source/core/data/columnset.cxx new file mode 100644 index 000000000000..2e1f3aa956e4 --- /dev/null +++ b/sc/source/core/data/columnset.cxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "columnset.hxx" + +namespace sc { + +void ColumnSet::set(SCTAB nTab, SCCOL nCol) +{ + TabsType::iterator itTab = maTabs.find(nTab); + if (itTab == maTabs.end()) + { + std::pair<TabsType::iterator,bool> r = + maTabs.insert(TabsType::value_type(nTab, ColsType())); + + if (!r.second) + // insertion failed. + return; + + itTab = r.first; + } + + ColsType& rCols = itTab->second; + rCols.insert(nCol); +} + +bool ColumnSet::has(SCTAB nTab, SCCOL nCol) const +{ + TabsType::const_iterator itTab = maTabs.find(nTab); + if (itTab == maTabs.end()) + return false; + + const ColsType& rCols = itTab->second; + return rCols.count(nCol) > 0; +} + +void ColumnSet::getColumns(SCTAB nTab, std::vector<SCCOL>& rCols) const +{ + std::vector<SCCOL> aCols; + TabsType::const_iterator itTab = maTabs.find(nTab); + if (itTab == maTabs.end()) + { + rCols.swap(aCols); // empty it. + return; + } + + const ColsType& rTabCols = itTab->second; + aCols.assign(rTabCols.begin(), rTabCols.end()); + + // Sort and remove duplicates. + std::sort(aCols.begin(), aCols.end()); + std::vector<SCCOL>::iterator itCol = std::unique(aCols.begin(), aCols.end()); + aCols.erase(itCol, aCols.end()); + + rCols.swap(aCols); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index a6eb5ef4846c..9fdf84ac46cb 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1474,8 +1474,7 @@ void ScDocument::DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTA nEndTab = static_cast<SCTAB>(maTabs.size())-1; } - bool bOldAutoCalc = GetAutoCalc(); - SetAutoCalc( false ); // avoid multiple calculations + sc::AutoCalcSwitch aACSwitch(*this, false); // avoid multiple calculations // handle chunks of consecutive selected sheets together SCTAB nTabRangeStart = nStartTab; @@ -1499,10 +1498,10 @@ void ScDocument::DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTA } while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) ); + sc::RefUpdateContext aCxt(*this); if ( ValidCol(sal::static_int_cast<SCCOL>(nStartCol+nSize)) ) { lcl_GetFirstTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ); - sc::RefUpdateContext aCxt(*this); aCxt.meMode = URM_INSDEL; aCxt.maRange = ScRange(sal::static_int_cast<SCCOL>(nStartCol+nSize), nStartRow, nTabRangeStart, MAXCOL, nEndRow, nTabRangeEnd); aCxt.mnColDelta = -(static_cast<SCCOL>(nSize)); @@ -1516,9 +1515,11 @@ void ScDocument::DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTA if (pUndoOutline) *pUndoOutline = false; - for ( i = nStartTab; i <= nEndTab && i < static_cast<SCTAB>(maTabs.size()); i++) + for (i = nStartTab; i <= nEndTab && i < static_cast<SCTAB>(maTabs.size()); ++i) + { if (maTabs[i] && (!pTabMark || pTabMark->GetTableSelect(i))) - maTabs[i]->DeleteCol( nStartCol, nStartRow, nEndRow, nSize, pUndoOutline ); + maTabs[i]->DeleteCol(aCxt.maRegroupCols, nStartCol, nStartRow, nEndRow, nSize, pUndoOutline); + } if ( ValidCol(sal::static_int_cast<SCCOL>(nStartCol+nSize)) ) {// Listeners have been removed in UpdateReference @@ -1536,7 +1537,6 @@ void ScDocument::DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTA std::for_each(maTabs.begin(), maTabs.end(), BroadcastRecalcOnRefMoveHandler()); } - SetAutoCalc( bOldAutoCalc ); pChartListenerCollection->UpdateDirtyCharts(); } diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 537f85654082..f900f6286245 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -59,7 +59,21 @@ #include <svl/PasswordHelper.hxx> #include <unotools/transliterationwrapper.hxx> -// STATIC DATA ----------------------------------------------------------- +namespace { + +class ColumnRegroupFormulaCells +{ + ScColumn* mpCols; +public: + ColumnRegroupFormulaCells(ScColumn* pCols) : mpCols(pCols) {} + + void operator() (SCCOL nCol) + { + mpCols[nCol].RegroupFormulaCells(); + } +}; + +} sal_uInt16 ScTable::GetTextWidth(SCCOL nCol, SCROW nRow) const { @@ -425,9 +439,8 @@ void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE SetStreamValid(false); } - -void ScTable::DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, - bool* pUndoOutline ) +void ScTable::DeleteCol( + const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, bool* pUndoOutline ) { if (nStartRow==0 && nEndRow==MAXROW) { @@ -460,7 +473,6 @@ void ScTable::DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE } } - { // scope for bulk broadcast ScBulkBroadcast aBulkBroadcast( pDocument->GetBASM()); for (SCSIZE i = 0; i < nSize; i++) @@ -479,6 +491,10 @@ void ScTable::DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE aCol[nStartCol + nSize + i].MoveTo(nStartRow, nEndRow, aCol[nStartCol + i]); } + std::vector<SCCOL> aRegroupCols; + rRegroupCols.getColumns(nTab, aRegroupCols); + std::for_each(aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol)); + // Transfer those notes that will get shifted into another container. ScNotes aNotes(pDocument); ScNotes::iterator itr = maNotes.begin(); |