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_RECALC_MANAGER |
21 | #define CALLIGRA_SHEETS_RECALC_MANAGER |
22 | |
23 | #include <Region.h> |
24 | |
25 | #include <QObject> |
26 | |
27 | class KoUpdater; |
28 | |
29 | namespace Calligra |
30 | { |
31 | namespace Sheets |
32 | { |
33 | class Cell; |
34 | class Map; |
35 | class Sheet; |
36 | |
37 | /** |
38 | * \class RecalcManager |
39 | * \brief Manages the recalculations of cells containing a formula. |
40 | * \ingroup Value |
41 | * |
42 | * The recalculations of a cell region, a sheet or the map are based |
43 | * on the following principle: |
44 | * |
45 | * A cell could refer to other cells, which need to be recalculated |
46 | * before. The order of recalculation is determined by the depth of |
47 | * references, i.e. first the cells, which do not refer to other cells, |
48 | * are recalculated. Cells referring to those are next. Then cells, which |
49 | * refer to the ones in the last step follow and so on until all cells |
50 | * have been updated. |
51 | * |
52 | * Cell value changes are blocked while doing this, i.e. they do not |
53 | * trigger a new recalculation event. |
54 | */ |
55 | class CALLIGRA_SHEETS_ODF_EXPORT RecalcManager : public QObject |
56 | { |
57 | Q_OBJECT |
58 | public: |
59 | /** |
60 | * Creates a RecalcManager. It is used for a whole map. |
61 | * |
62 | * \param map The Map which this RecalcManager belongs to. |
63 | */ |
64 | explicit RecalcManager(Map *const map); |
65 | |
66 | /** |
67 | * Destructor. |
68 | */ |
69 | ~RecalcManager(); |
70 | |
71 | /** |
72 | * Recalculates the cells referring to cells in \p region . |
73 | * The cells are recalculated sorted by the reference depth in ascending order. |
74 | * |
75 | * \see recalc() |
76 | */ |
77 | void regionChanged(const Region& region); |
78 | |
79 | /** |
80 | * Recalculates the sheet \p sheet . |
81 | * The cells are recalculated sorted by the reference depth in ascending order. |
82 | * |
83 | * \see recalc() |
84 | */ |
85 | void recalcSheet(Sheet* const sheet); |
86 | |
87 | /** |
88 | * Recalculates the whole map. |
89 | * The cells are recalculated sorted by the reference depth in ascending order. |
90 | * |
91 | * \see recalc() |
92 | */ |
93 | void recalcMap(KoUpdater *updater = 0); |
94 | |
95 | /** |
96 | * Returns the recalculation state. |
97 | * \return \c true, if recalculations are in progress |
98 | */ |
99 | bool isActive() const; |
100 | |
101 | /** |
102 | * Prints out the cell depths in the current recalculation event. |
103 | */ |
104 | void dump() const; |
105 | |
106 | public Q_SLOTS: |
107 | /** |
108 | * Called after a sheet was added. |
109 | */ |
110 | void addSheet(Sheet *sheet); |
111 | |
112 | /** |
113 | * Called after a sheet was removed. |
114 | */ |
115 | void removeSheet(Sheet *sheet); |
116 | |
117 | protected: |
118 | /** |
119 | * Iterates over the map of cell with their reference depths |
120 | * and calls recalcCell(). |
121 | * |
122 | * \see recalcCell() |
123 | */ |
124 | void recalc(KoUpdater *updater = 0); |
125 | |
126 | private: |
127 | Q_DISABLE_COPY(RecalcManager) |
128 | |
129 | class Private; |
130 | Private * const d; |
131 | }; |
132 | |
133 | } // namespace Sheets |
134 | } // namespace Calligra |
135 | |
136 | #endif // CALLIGRA_SHEETS_RECALC_MANAGER |
137 | |