1 | /* This file is part of the KDE project |
2 | Copyright 2006,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef CALLIGRA_SHEETS_STYLE_STORAGE |
21 | #define CALLIGRA_SHEETS_STYLE_STORAGE |
22 | |
23 | #include <QObject> |
24 | #include <QPair> |
25 | #include <QPoint> |
26 | #include <QRect> |
27 | |
28 | #include "calligra_sheets_export.h" |
29 | #include <Region.h> |
30 | #include <Style.h> |
31 | |
32 | namespace Calligra |
33 | { |
34 | namespace Sheets |
35 | { |
36 | class Map; |
37 | class OdfSavingContext; |
38 | class Style; |
39 | class StyleManager; |
40 | class SubStyle; |
41 | class StyleStorageLoaderJob; |
42 | |
43 | /** |
44 | * \ingroup Storage |
45 | * \ingroup Style |
46 | * The style storage. |
47 | * Acts mainly as a wrapper around the R-Tree data structure to allow a future |
48 | * replacement of this backend. Decorated with some additional features like |
49 | * garbage collection, caching, used area tracking, etc. |
50 | */ |
51 | class CALLIGRA_SHEETS_ODF_EXPORT StyleStorage : public QObject |
52 | { |
53 | Q_OBJECT |
54 | |
55 | public: |
56 | explicit StyleStorage(Map* map); |
57 | StyleStorage(const StyleStorage& other); |
58 | virtual ~StyleStorage(); |
59 | |
60 | /** |
61 | * Composes the style for \p point. All substyles intersecting \p point are considered. |
62 | * \return the Style at the position \p point . |
63 | */ |
64 | Style contains(const QPoint& point) const; |
65 | |
66 | /** |
67 | * Composes the style for \p rect. Only substyles which fill out \p rect completely are |
68 | * considered. In contrast to intersects(const QRect&). |
69 | * Especially useful on saving cell styles assigned to columns or rows. |
70 | * \return the Style for the area \p rect . |
71 | * \see intersects |
72 | */ |
73 | Style contains(const QRect& rect) const; |
74 | |
75 | /** |
76 | * Composes the style for \p rect. All substyles which intersect \p rect are considered. |
77 | * In contrast to contains(const QRect&). |
78 | * \return the Style for the area \p rect . |
79 | * \see contains |
80 | */ |
81 | Style intersects(const QRect& rect) const; |
82 | |
83 | /** |
84 | * Collects all substyle/range pairs, that intersect \p rect. With this data one can |
85 | * reconstruct the former state of the storage after modification. |
86 | * \return all substyle/range pairs intersecting \p rect |
87 | */ |
88 | QList< QPair<QRectF, SharedSubStyle> > undoData(const Region& rect) const; |
89 | |
90 | /** |
91 | * Returns the area, which got a style attached. |
92 | * \return the area using styles |
93 | */ |
94 | QRect usedArea() const; |
95 | |
96 | /** |
97 | * \return the OpenDocument column/row default cell styles |
98 | * \ingroup OpenDocument |
99 | */ |
100 | void saveOdfCreateDefaultStyles(int& maxCols, int& maxRows, OdfSavingContext& tableContext) const; |
101 | |
102 | /** |
103 | * Returns the index of the next column-wide cell style after \p column or zero |
104 | * if there's none. |
105 | * \return the index of the next styled column |
106 | */ |
107 | int nextColumnStyleIndex(int column) const; |
108 | |
109 | /** |
110 | * Returns the index of the next row-wide cell style after \p row or zero |
111 | * if there's none. |
112 | * \return the index of the next styled row |
113 | */ |
114 | int nextRowStyleIndex(int row) const; |
115 | |
116 | /** |
117 | * Returns the index of the first cell style in \p row or zero |
118 | * if there's none. |
119 | * \return the index of the next styled column |
120 | */ |
121 | int firstColumnIndexInRow(int row) const; |
122 | |
123 | /** |
124 | * Returns the index of the next cell style in \p row after \p column or zero |
125 | * if there's none. |
126 | * \return the index of the next styled column |
127 | */ |
128 | int nextColumnIndexInRow(int column, int row) const; |
129 | |
130 | /** |
131 | * Assigns \p subStyle to the area \p rect . |
132 | */ |
133 | void insert(const QRect& rect, const SharedSubStyle& subStyle, bool markRegionChanged = true); |
134 | |
135 | /** |
136 | * Assigns the substyles contained in \p style to the area \p region . |
137 | */ |
138 | void insert(const Region& region, const Style& style); |
139 | |
140 | /** |
141 | * Replaces the current styles with those in \p styles |
142 | */ |
143 | void load(const QList<QPair<QRegion, Style> >& styles); |
144 | |
145 | /** |
146 | * Inserts \p number rows at the position \p position . |
147 | * It extends or shifts rectangles, respectively. |
148 | */ |
149 | QList< QPair<QRectF, SharedSubStyle> > insertRows(int position, int number = 1); |
150 | |
151 | /** |
152 | * Inserts \p number columns at the position \p position . |
153 | * It extends or shifts rectangles, respectively. |
154 | */ |
155 | QList< QPair<QRectF, SharedSubStyle> > insertColumns(int position, int number = 1); |
156 | |
157 | /** |
158 | * Deletes \p number rows at the position \p position . |
159 | * It shrinks or shifts rectangles, respectively. |
160 | */ |
161 | QList< QPair<QRectF, SharedSubStyle> > removeRows(int position, int number = 1); |
162 | |
163 | /** |
164 | * Deletes \p number columns at the position \p position . |
165 | * It shrinks or shifts rectangles, respectively. |
166 | */ |
167 | QList< QPair<QRectF, SharedSubStyle> > removeColumns(int position, int number = 1); |
168 | |
169 | /** |
170 | * Shifts the rows right of \p rect to the right by the width of \p rect . |
171 | * It extends or shifts rectangles, respectively. |
172 | */ |
173 | QList< QPair<QRectF, SharedSubStyle> > insertShiftRight(const QRect& rect); |
174 | |
175 | /** |
176 | * Shifts the columns at the bottom of \p rect to the bottom by the height of \p rect . |
177 | * It extends or shifts rectangles, respectively. |
178 | */ |
179 | QList< QPair<QRectF, SharedSubStyle> > insertShiftDown(const QRect& rect); |
180 | |
181 | /** |
182 | * Shifts the rows left of \p rect to the left by the width of \p rect . |
183 | * It shrinks or shifts rectangles, respectively. |
184 | * \return the former rectangle/data pairs |
185 | */ |
186 | QList< QPair<QRectF, SharedSubStyle> > removeShiftLeft(const QRect& rect); |
187 | |
188 | /** |
189 | * Shifts the columns on top of \p rect to the top by the height of \p rect . |
190 | * It shrinks or shifts rectangles, respectively. |
191 | * \return the former rectangle/data pairs |
192 | */ |
193 | QList< QPair<QRectF, SharedSubStyle> > removeShiftUp(const QRect& rect); |
194 | |
195 | /** |
196 | * Invalidates all cached styles. |
197 | */ |
198 | void invalidateCache(); |
199 | |
200 | protected Q_SLOTS: |
201 | void garbageCollection(); |
202 | |
203 | protected: |
204 | /** |
205 | * Triggers all necessary actions after a change of \p rect . |
206 | * Calls invalidateCache() and adds the substyles in |
207 | * \p rect to the list of possible garbage. |
208 | */ |
209 | void regionChanged(const QRect& rect); |
210 | |
211 | /** |
212 | * Invalidates all cached styles lying in \p rect . |
213 | */ |
214 | void invalidateCache(const QRect& rect); |
215 | |
216 | /** |
217 | * Composes a style of \p substyles . |
218 | * \return the composed style |
219 | */ |
220 | Style composeStyle(const QList<SharedSubStyle>& subStyles) const; |
221 | |
222 | /** |
223 | * Convenience method. |
224 | * \return the StyleManager |
225 | */ |
226 | StyleManager* styleManager() const; |
227 | |
228 | private: |
229 | friend class StyleStorageLoaderJob; |
230 | // disable assignment |
231 | void operator=(const StyleStorage& other); |
232 | |
233 | class Private; |
234 | Private * const d; |
235 | }; |
236 | |
237 | } // namespace Sheets |
238 | } // namespace Calligra |
239 | |
240 | #endif // CALLIGRA_SHEETS_STYLE_STORAGE |
241 | |