/src/libreoffice/sc/inc/SheetView.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include "scdllapi.h" |
13 | | #include "types.hxx" |
14 | | #include <rtl/string.hxx> |
15 | | #include <rtl/ustring.hxx> |
16 | | #include "SheetViewTypes.hxx" |
17 | | #include "sortparam.hxx" |
18 | | #include <optional> |
19 | | #include <vector> |
20 | | #include <memory> |
21 | | |
22 | | class ScTable; |
23 | | |
24 | | namespace sc |
25 | | { |
26 | | /** Contains the information of an performed sort action */ |
27 | | struct SC_DLLPUBLIC SortOrderInfo |
28 | | { |
29 | | SCCOL mnFirstColumn = -1; |
30 | | SCCOL mnLastColumn = -1; |
31 | | SCROW mnFirstRow = -1; |
32 | | SCROW mnLastRow = -1; |
33 | | std::vector<SCCOLROW> maOrder; // Remember the sort order |
34 | | std::vector<ScSortKeyState> maKeyStates; // Each column sort information |
35 | | }; |
36 | | |
37 | | /** Stores the sort order and can reverse the sorting of rows (unsorting). */ |
38 | | struct SC_DLLPUBLIC SortOrderReverser |
39 | | { |
40 | | public: |
41 | | SortOrderInfo maSortInfo; |
42 | | |
43 | | /** Reverse the sort for the input row and output the unsorted row. |
44 | | * |
45 | | * Uses the sort order. The row must be between range of [first row, last row] |
46 | | * or it will return the input row without modification. |
47 | | **/ |
48 | | SCROW unsort(SCROW nRow, SCCOL nColumn) const; |
49 | | SCROW resort(SCROW nRow, SCCOL nColumn) const; |
50 | | |
51 | | /** Adds or combines the order indices. |
52 | | * |
53 | | * Adds the indices if none are present, or combines the indices if the order indices |
54 | | * were already added previously. |
55 | | **/ |
56 | | void addOrderIndices(SortOrderInfo const& rSortInfo); |
57 | | |
58 | | /** Update data when rows are inserted. */ |
59 | | void insertedRows(SCROW nStartRow, SCROW nRowCount); |
60 | | |
61 | | /** Update data when rows are deleted. */ |
62 | | void deletedRows(SCROW nStartRow, SCROW nRowCount); |
63 | | |
64 | | /** Update data when columns are inserted. */ |
65 | | void insertedColumns(SCCOL nStartCol, SCCOL nColCount); |
66 | | |
67 | | /** Update data when columns are deleted. */ |
68 | | void deletedColumns(SCCOL nStartCol, SCCOL nColCount); |
69 | | }; |
70 | | |
71 | | /** Sort data holder. */ |
72 | | struct SC_DLLPUBLIC SheetViewSortData |
73 | | { |
74 | | SortOrderReverser maSortOrder; |
75 | | ReorderParam maOriginalReorderParams; |
76 | | ScSortParam maSortParam; |
77 | | }; |
78 | | |
79 | | /** Stores information of a sheet view. |
80 | | * |
81 | | * A sheet view is a special view of a sheet that can be filtered and sorted |
82 | | * independently from other views of the sheet. |
83 | | **/ |
84 | | class SC_DLLPUBLIC SheetView |
85 | | { |
86 | | private: |
87 | | ScTable* mpTable = nullptr; |
88 | | OUString maName; |
89 | | SheetViewID mnID; |
90 | | |
91 | | // GUIDs |
92 | | OString maGUID; |
93 | | OString maFilterGUID; |
94 | | |
95 | | /** Sort data - nullptr when no sort has been performed. */ |
96 | | std::shared_ptr<SheetViewSortData> mpSortData; |
97 | | |
98 | | /** Ensure sort data is allocated. */ |
99 | | SheetViewSortData& ensureSortData(); |
100 | | |
101 | | void adjustReorderParamsForInsertRows(SCROW nStartRow, SCROW nRowCount); |
102 | | void adjustReorderParamsForInsertColumns(SCCOL nStartCol, SCCOL nColCount); |
103 | | void adjustReorderParamsForDeleteRows(SCROW nStartRow, SCROW nRowCount); |
104 | | void adjustReorderParamsForDeleteColumns(SCCOL nStartCol, SCCOL nColCount); |
105 | | |
106 | | void adjustSortParamForInsertRows(SCROW nStartRow, SCROW nRowCount); |
107 | | void adjustSortParamForInsertColumns(SCCOL nStartCol, SCCOL nColCount); |
108 | | void adjustSortParamForDeleteRows(SCROW nStartRow, SCROW nRowCount); |
109 | | void adjustSortParamForDeleteColumns(SCCOL nStartCol, SCCOL nColCount); |
110 | | |
111 | | public: |
112 | | SheetView(ScTable* pTable, OUString const& rName, SheetViewID nID); |
113 | | |
114 | | ScTable* getTablePointer() const; |
115 | | SCTAB getTableNumber() const; |
116 | | |
117 | 0 | SheetViewID getID() const { return mnID; } |
118 | | |
119 | 0 | OUString const& GetName() const { return maName; } |
120 | 0 | void SetName(OUString const& rName) { maName = rName; } |
121 | | |
122 | 0 | OString const& GetGUID() const { return maGUID; } |
123 | 0 | void SetGUID(OString const& rGUID) { maGUID = rGUID; } |
124 | | |
125 | 0 | OString const& GetFilterGUID() const { return maFilterGUID; } |
126 | 0 | void SetFilterGUID(OString const& rGUID) { maFilterGUID = rGUID; } |
127 | | |
128 | | SortOrderReverser const* getSortOrder() const; |
129 | | void resetSortOrder(); |
130 | | |
131 | | /** Adds or combines the order indices. |
132 | | * |
133 | | * Adds the indices if none are present, or combines the indices if the order indices |
134 | | * were already added previously. |
135 | | **/ |
136 | | void addOrderIndices(SortOrderInfo const& rSortInfo); |
137 | | |
138 | | /** Merges the reorder parameters */ |
139 | | void mergeReorderParameters(ReorderParam const& rReorderParameters); |
140 | | ReorderParam const* getReorderParameters() const; |
141 | | |
142 | | /** Reverses the complete (sheet view and default view) sorting order for the input row */ |
143 | | SCROW reverseSortingToDefaultView(SCROW nRow, SCCOL nColumn) const; |
144 | | |
145 | | /** Converts a row from the default view to the row in this sheet view, taking sorting data into account. */ |
146 | | SCROW reverseDefaultViewToSheetView(SCROW nRow, SCCOL nColumn) const; |
147 | | |
148 | | /** Update stored sort ranges when rows are inserted. */ |
149 | | void insertedRows(SCROW nStartRow, SCROW nRowCount); |
150 | | |
151 | | /** Update stored sort ranges when rows are deleted. */ |
152 | | void deletedRows(SCROW nStartRow, SCROW nRowCount); |
153 | | |
154 | | /** Update stored sort ranges when columns are inserted. */ |
155 | | void insertedColumns(SCCOL nStartCol, SCCOL nColCount); |
156 | | |
157 | | /** Update stored sort ranges when columns are deleted. */ |
158 | | void deletedColumns(SCCOL nStartCol, SCCOL nColCount); |
159 | | |
160 | | /** Last used sort parameters */ |
161 | | ScSortParam const* getSortParam() const; |
162 | | |
163 | | /** Remember last used sort parameters when sheet view was sorted. */ |
164 | | void setSortParam(ScSortParam const& rSortParam); |
165 | | |
166 | | /** Reset all sort data. */ |
167 | | void resetSortData(); |
168 | | |
169 | | /** Capture current sort state (and deep copy). */ |
170 | | std::shared_ptr<SheetViewSortData> captureSortData() const; |
171 | | |
172 | | /** Restore sort state from a previous capture. */ |
173 | | void restoreSortData(std::shared_ptr<SheetViewSortData> const& pData); |
174 | | }; |
175 | | } |
176 | | |
177 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |