summaryrefslogtreecommitdiff
path: root/sc/inc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-06-02 18:29:27 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-07-13 18:07:14 -0400
commit5c6ee09126631342939ae8766fe36083d8c011e3 (patch)
tree48081d36ae5000542adb49cc037267992f59ec66 /sc/inc
parentb5bb15013617c6b9f1cdd089acae0bfb7104fa3a (diff)
fdo#81309: Adjust references during sort.
Change-Id: I2b98610f6b774400ecfaffe2905201c27fcab33f
Diffstat (limited to 'sc/inc')
-rw-r--r--sc/inc/document.hxx35
-rw-r--r--sc/inc/formulacell.hxx2
-rw-r--r--sc/inc/listenerquery.hxx50
-rw-r--r--sc/inc/listenerqueryids.hxx17
-rw-r--r--sc/inc/refhint.hxx30
-rw-r--r--sc/inc/sharedformula.hxx9
-rw-r--r--sc/inc/sortparam.hxx28
-rw-r--r--sc/inc/table.hxx16
-rw-r--r--sc/inc/tokenarray.hxx8
-rw-r--r--sc/inc/types.hxx2
-rw-r--r--sc/inc/undosort.hxx37
11 files changed, 211 insertions, 23 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index d7f87520c39f..44e88c073a33 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 {
@@ -1676,7 +1679,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 );
@@ -2033,8 +2038,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; }
@@ -2063,6 +2068,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 );
@@ -2148,15 +2166,6 @@ private:
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 e13e2bb78a76..cc234c9ce0e9 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 { return pDocument;}
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 55b09a6ca2ba..ab26d10aacb0 100644
--- a/sc/inc/sortparam.hxx
+++ b/sc/inc/sortparam.hxx
@@ -78,6 +78,34 @@ 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
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 412c6ca01d5f..44c4951b62fd 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 a83e11549eb5..8ae61450c95a 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -168,7 +168,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: */