diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-02 18:29:27 -0400 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-07-15 16:16:01 +0000 |
commit | 5c3bcc6fe3653aed79a11abbead66f11896e7ee8 (patch) | |
tree | cedabc7d8e4c5b990a9514556ba0b881bdb0aef4 /sc/inc | |
parent | cd278ead4d8865bc886f6641012f10d459601e71 (diff) |
fdo#81309: Adjust references during sort.
(cherry picked from commit 5c6ee09126631342939ae8766fe36083d8c011e3)
Conflicts:
sc/inc/sortparam.hxx
sc/source/ui/docshell/dbdocfun.cxx
sc/source/ui/undo/undodat.cxx
Change-Id: I2b98610f6b774400ecfaffe2905201c27fcab33f
Reviewed-on: https://gerrit.libreoffice.org/10305
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/inc')
-rw-r--r-- | sc/inc/document.hxx | 35 | ||||
-rw-r--r-- | sc/inc/formulacell.hxx | 2 | ||||
-rw-r--r-- | sc/inc/listenerquery.hxx | 50 | ||||
-rw-r--r-- | sc/inc/listenerqueryids.hxx | 17 | ||||
-rw-r--r-- | sc/inc/refhint.hxx | 30 | ||||
-rw-r--r-- | sc/inc/sharedformula.hxx | 9 | ||||
-rw-r--r-- | sc/inc/sortparam.hxx | 27 | ||||
-rw-r--r-- | sc/inc/table.hxx | 16 | ||||
-rw-r--r-- | sc/inc/tokenarray.hxx | 8 | ||||
-rw-r--r-- | sc/inc/types.hxx | 2 | ||||
-rw-r--r-- | sc/inc/undosort.hxx | 37 |
11 files changed, 210 insertions, 23 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 3db9fb9def52..bfeefc399730 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -29,7 +29,6 @@ #include "rangenam.hxx" #include "brdcst.hxx" #include "tabopparams.hxx" -#include "sortparam.hxx" #include "types.hxx" #include <formula/grammar.hxx> #include <formula/types.hxx> @@ -79,6 +78,8 @@ class CellValues; class RowHeightContext; struct SetFormulaDirtyContext; class RefMovedHint; +struct SortUndoParam; +struct ReorderParam; } @@ -181,6 +182,8 @@ class EditTextObject; struct ScRefCellValue; class ScDocumentImport; class ScPostIt; +struct ScSubTotalParam; +struct ScQueryParam; namespace com { namespace sun { namespace star { namespace lang { @@ -1678,7 +1681,9 @@ public: SC_DLLPUBLIC SvNumberFormatter* GetFormatTable() const; SC_DLLPUBLIC SvNumberFormatter* CreateFormatTable() const; - void Sort( SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress ); + void Sort( SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress, sc::ReorderParam* pUndo ); + void Reorder( const sc::ReorderParam& rParam, ScProgress* pProgress ); + SCSIZE Query( SCTAB nTab, const ScQueryParam& rQueryParam, bool bKeepSub ); SC_DLLPUBLIC bool CreateQueryParam( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, ScQueryParam& rQueryParam ); @@ -2036,8 +2041,8 @@ public: void InvalidateStyleSheetUsage() { bStyleSheetUsageInvalid = true; } - void GetSortParam( ScSortParam& rParam, SCTAB nTab ); - void SetSortParam( ScSortParam& rParam, SCTAB nTab ); + void SC_DLLPUBLIC GetSortParam( ScSortParam& rParam, SCTAB nTab ); + void SC_DLLPUBLIC SetSortParam( ScSortParam& rParam, SCTAB nTab ); inline void SetVbaEventProcessor( const com::sun::star::uno::Reference< com::sun::star::script::vba::XVBAEventProcessor >& rxVbaEvents ) { mxVbaEvents = rxVbaEvents; } @@ -2066,6 +2071,19 @@ public: size_t GetFormulaHash( const ScAddress& rPos ) const; + /** + * Make specified formula cells non-grouped. + * + * @param nTab sheet index + * @param nCol column index + * @param rRows list of row indices at which formula cells are to be + * unshared. This call sorts the passed row indices and + * removes duplicates, which is why the caller must pass it + * as reference. + */ + void UnshareFormulaCells( SCTAB nTab, SCCOL nCol, std::vector<SCROW>& rRows ); + void RegroupFormulaCells( SCTAB nTab, SCCOL nCol ); + ScFormulaVectorState GetFormulaVectorState( const ScAddress& rPos ) const; formula::FormulaTokenRef ResolveStaticReference( const ScAddress& rPos ); @@ -2151,15 +2169,6 @@ private: // CLOOK-Impl-methods void SharePooledResources( ScDocument* pSrcDoc ); }; -inline void ScDocument::GetSortParam( ScSortParam& rParam, SCTAB nTab ) -{ - rParam = mSheetSortParams[ nTab ]; -} - -inline void ScDocument::SetSortParam( ScSortParam& rParam, SCTAB nTab ) -{ - mSheetSortParams[ nTab ] = rParam; -} #endif diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 49b20b120f72..959779a788bb 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -321,6 +321,8 @@ public: void SetNextTrack( ScFormulaCell* pF ); virtual void Notify( const SfxHint& rHint ) SAL_OVERRIDE; + virtual void Query( SvtListener::QueryBase& rQuery ) const SAL_OVERRIDE; + void SetCompile( bool bVal ); ScDocument* GetDocument() const; void SetMatColsRows( SCCOL nCols, SCROW nRows, bool bDirtyFlag=true ); diff --git a/sc/inc/listenerquery.hxx b/sc/inc/listenerquery.hxx new file mode 100644 index 000000000000..2cbc95731be1 --- /dev/null +++ b/sc/inc/listenerquery.hxx @@ -0,0 +1,50 @@ +/* -*- 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_LISTENERQUERY_HXX +#define SC_LISTENERQUERY_HXX + +#include <address.hxx> +#include <svl/listener.hxx> + +namespace sc { + +/** + * Used to collect positions of formula cells that belong to a formula + * group. + */ +class RefQueryFormulaGroup : public SvtListener::QueryBase +{ +public: + typedef std::vector<SCROW> ColType; + typedef boost::unordered_map<SCCOL,ColType> ColsType; + typedef boost::unordered_map<SCTAB,ColsType> TabsType; + + RefQueryFormulaGroup(); + virtual ~RefQueryFormulaGroup(); + + void setSkipRange( const ScRange& rRange ); + void add( const ScAddress& rPos ); + + /** + * Row positions in each column may contain duplicates. Caller must + * remove duplicates if necessary. + */ + const TabsType& getAllPositions() const; + +private: + ScRange maSkipRange; + TabsType maTabs; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/listenerqueryids.hxx b/sc/inc/listenerqueryids.hxx new file mode 100644 index 000000000000..48f240b13fd8 --- /dev/null +++ b/sc/inc/listenerqueryids.hxx @@ -0,0 +1,17 @@ +/* -*- 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_LISTENERQUERYIDS_HXX +#define SC_LISTENERQUERYIDS_HXX + +#define SC_LISTENER_QUERY_FORMULA_GROUP_POS 0 + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/refhint.hxx b/sc/inc/refhint.hxx index 1f927312327b..1eff90631de6 100644 --- a/sc/inc/refhint.hxx +++ b/sc/inc/refhint.hxx @@ -18,7 +18,11 @@ namespace sc { class RefHint : public SfxSimpleHint { public: - enum Type { Moved, ColumnReordered }; + enum Type { + Moved, + ColumnReordered, + RowReordered + }; private: Type meType; @@ -57,22 +61,40 @@ public: class RefColReorderHint : public RefHint { - const sc::ColReorderMapType& mrColMap; + const sc::ColRowReorderMapType& mrColMap; SCTAB mnTab; SCROW mnRow1; SCROW mnRow2; public: - RefColReorderHint( const sc::ColReorderMapType& rColMap, SCTAB nTab, SCROW nRow1, SCROW nRow2 ); + RefColReorderHint( const sc::ColRowReorderMapType& rColMap, SCTAB nTab, SCROW nRow1, SCROW nRow2 ); virtual ~RefColReorderHint(); - const sc::ColReorderMapType& getColMap() const; + const sc::ColRowReorderMapType& getColMap() const; SCTAB getTab() const; SCROW getStartRow() const; SCROW getEndRow() const; }; +class RefRowReorderHint : public RefHint +{ + const sc::ColRowReorderMapType& mrRowMap; + SCTAB mnTab; + SCCOL mnCol1; + SCCOL mnCol2; + +public: + RefRowReorderHint( const sc::ColRowReorderMapType& rRowMap, SCTAB nTab, SCCOL nCol1, SCCOL nCol2 ); + virtual ~RefRowReorderHint(); + + const sc::ColRowReorderMapType& getRowMap() const; + + SCTAB getTab() const; + SCCOL getStartColumn() const; + SCCOL getEndColumn() const; +}; + } #endif diff --git a/sc/inc/sharedformula.hxx b/sc/inc/sharedformula.hxx index 840b63b9bbe4..b29843f8547a 100644 --- a/sc/inc/sharedformula.hxx +++ b/sc/inc/sharedformula.hxx @@ -100,6 +100,15 @@ public: * @param rCell formula cell instance */ static void unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell); + + /** + * Make specified formula cells non-shared ones, and split them off from + * their respective adjacent formula cell groups. + * + * @param rCells cell storage container + * @param rRows row positions at which to unshare formula cells. + */ + static void unshareFormulaCells(CellStoreType& rCells, std::vector<SCROW>& rRows); }; } diff --git a/sc/inc/sortparam.hxx b/sc/inc/sortparam.hxx index f566aca799f9..e61528bed0b3 100644 --- a/sc/inc/sortparam.hxx +++ b/sc/inc/sortparam.hxx @@ -79,6 +79,33 @@ struct SC_DLLPUBLIC ScSortParam inline sal_uInt16 GetSortKeyCount() const { return maKeyState.size(); } }; +namespace sc { + +struct SC_DLLPUBLIC ReorderParam +{ + /** + * This sort range already takes into account the presence or absence of + * header row / column i.e. if a header row / column is present, it + * excludes that row / column. + */ + ScRange maSortRange; + + /** + * List of original column / row positions after reordering. + */ + std::vector<SCCOLROW> maOrderIndices; + bool mbByRow; + bool mbPattern; + bool mbHiddenFiltered; + + /** + * Reorder the position indices such that it can be used to undo the + * original reordering. + */ + void reverse(); +}; + +} #endif // INCLUDED_SC_INC_SORTPARAM_HXX diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 6492f817e54c..c4ad09e9b6b3 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -73,6 +73,7 @@ class RowHeightContext; class CompileFormulaContext; struct SetFormulaDirtyContext; class RefMovedHint; +struct ReorderParam; } @@ -824,7 +825,10 @@ public: void StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 ); void ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 ); - void Sort(const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress); + void Sort( + const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress, sc::ReorderParam* pUndo ); + void Reorder( const sc::ReorderParam& rParam, ScProgress* pProgress ); + bool ValidQuery( SCROW nRow, const ScQueryParam& rQueryParam, ScRefCellValue* pCell = NULL, bool* pbTestEqualCondition = NULL); @@ -880,6 +884,9 @@ public: formula::FormulaTokenRef ResolveStaticReference( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ); formula::VectorRefArray FetchVectorRefArray( SCCOL nCol, SCROW nRow1, SCROW nRow2 ); + void UnshareFormulaCells( SCCOL nCol, std::vector<SCROW>& rRows ); + void RegroupFormulaCells( SCCOL nCol ); + ScRefCellValue GetRefCellValue( SCCOL nCol, SCROW nRow ); SvtBroadcaster* GetBroadcaster( SCCOL nCol, SCROW nRow ); @@ -1014,10 +1021,11 @@ private: ScRefCellValue& rCell2, SCCOL nCell2Col, SCROW nCell2Row ) const; short Compare(SCCOLROW nIndex1, SCCOLROW nIndex2) const; short Compare( ScSortInfoArray*, SCCOLROW nIndex1, SCCOLROW nIndex2) const; - ScSortInfoArray* CreateSortInfoArray( SCCOLROW nInd1, SCCOLROW nInd2, bool bKeepQuery ); + ScSortInfoArray* CreateSortInfoArray( const sc::ReorderParam& rParam ); + ScSortInfoArray* CreateSortInfoArray( const ScSortParam& rSortParam, SCCOLROW nInd1, SCCOLROW nInd2, bool bKeepQuery ); void QuickSort( ScSortInfoArray*, SCsCOLROW nLo, SCsCOLROW nHi); - void SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress ); - void SortReorderByRow( ScSortInfoArray* pArray, ScProgress* pProgress ); + void SortReorderByColumn( ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2, bool bPattern, ScProgress* pProgress ); + void SortReorderByRow( ScSortInfoArray* pArray, SCCOL nCol1, SCCOL nCol2, ScProgress* pProgress ); bool CreateExcelQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); bool CreateStarQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 9538819e7733..0ce6f7151669 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -169,7 +169,13 @@ public: * @param nRow2 bottom row of reordered range. * @param rColMap old-to-new column mapping. */ - void MoveReference( const ScAddress& rPos, SCTAB nTab, SCROW nRow1, SCROW nRow2, const sc::ColReorderMapType& rColMap ); + void MoveReferenceColReorder( + const ScAddress& rPos, SCTAB nTab, SCROW nRow1, SCROW nRow2, + const sc::ColRowReorderMapType& rColMap ); + + void MoveReferenceRowReorder( + const ScAddress& rPos, SCTAB nTab, SCCOL nCol1, SCCOL nCol2, + const sc::ColRowReorderMapType& rRowMap ); /** * Adjust all references in named expression. In named expression, we only diff --git a/sc/inc/types.hxx b/sc/inc/types.hxx index 8d37ad45e6a3..37784dc2f6ca 100644 --- a/sc/inc/types.hxx +++ b/sc/inc/types.hxx @@ -98,7 +98,7 @@ struct RangeMatrix bool isRangeValid() const; }; -typedef boost::unordered_map<SCCOL,SCCOL> ColReorderMapType; +typedef boost::unordered_map<SCCOLROW,SCCOLROW> ColRowReorderMapType; } diff --git a/sc/inc/undosort.hxx b/sc/inc/undosort.hxx new file mode 100644 index 000000000000..388fcfa48bc9 --- /dev/null +++ b/sc/inc/undosort.hxx @@ -0,0 +1,37 @@ +/* -*- 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 INCLUDED_SC_UNDOSORT_HXX +#define INCLUDED_SC_UNDOSORT_HXX + +#include <undobase.hxx> +#include <sortparam.hxx> + +namespace sc { + +class UndoSort : public ScSimpleUndo +{ + ReorderParam maParam; + +public: + UndoSort( ScDocShell* pDocSh, const ReorderParam& rParam ); + + virtual OUString GetComment() const; + virtual void Undo(); + virtual void Redo(); + +private: + void Execute( bool bUndo ); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |