File indexing completed on 2024-04-28 16:21:21

0001 /* This file is part of the KDE project
0002    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2004 Tomas Mecir <mecirt@gmail.com>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef CALLIGRA_SHEETS_DEPENDENCY_MANAGER
0022 #define CALLIGRA_SHEETS_DEPENDENCY_MANAGER
0023 
0024 #include <QObject>
0025 
0026 #include "Region.h"
0027 
0028 class KoUpdater;
0029 
0030 namespace Calligra
0031 {
0032 namespace Sheets
0033 {
0034 class Region;
0035 
0036 /**
0037  * \ingroup Value
0038  * Manages the dependencies between cells caused by references in formulas.
0039  * This dependency information is used for the recalculation of the cells.
0040  */
0041 class CALLIGRA_SHEETS_ODF_EXPORT DependencyManager : public QObject
0042 {
0043     Q_OBJECT
0044     friend class TestDependencies;
0045     friend class RecalcManager;
0046 
0047 public:
0048     /** constructor */
0049     explicit DependencyManager(const Map *map);
0050     /** destructor */
0051     ~DependencyManager() override;
0052 
0053     /** clear all data */
0054     void reset();
0055 
0056     /**
0057      * Handles the fact, that formulas have changed in \p region.
0058      * The \p region needs to contain only those areas, in which
0059      * each cell has a changed formula. That can also be a removed
0060      * formula. This class has no chance to know the old formula
0061      * locations, but the caller of this method has. So, usually the
0062      * \p region consists of several cell locations, not cell ranges.
0063      * The caller has to take care of that, because each and every
0064      * cell in \p region is traversed.
0065      */
0066     void regionChanged(const Region& region);
0067 
0068     /**
0069      * Updates the whole \p map.
0070      */
0071     void updateAllDependencies(const Map* map, KoUpdater *updater = 0);
0072 
0073     /**
0074      * Returns the cell depths.
0075      * \return the cell depths
0076      */
0077     QMap<Cell, int> depths() const;
0078 
0079     /**
0080      * Returns the region, that consumes the value of \p cell.
0081      *
0082      * I.e. the returned region contains all cells, that have
0083      * got a formula referencing \p cell. Even if the formula
0084      * references a complete cell range or a named area, that
0085      * contains \p cell.
0086      *
0087      * \return region consuming \p cell 's value
0088      */
0089     Region consumingRegion(const Cell& cell) const;
0090 
0091     /**
0092      * Returns the region, that is reduced to those parts of \p region, that provide values.
0093      * \return region providing values for others
0094      */
0095     Region reduceToProvidingRegion(const Region& region) const;
0096 
0097     /**
0098      * Adjusts formulas after cut & paste operations or column/row insertions/deletions.
0099      *
0100      * \param movedRegion the region, that was moved
0101      * \param destination the new upper left corner of the region
0102      */
0103     void regionMoved(const Region& movedRegion, const Cell& destination);
0104 
0105 public Q_SLOTS:
0106     void namedAreaModified(const QString&);
0107 
0108     /**
0109      * Called after a sheet was added.
0110      */
0111     void addSheet(Sheet *sheet);
0112 
0113     /**
0114      * Called after a sheet was removed.
0115      */
0116     void removeSheet(Sheet *sheet);
0117 
0118 protected:
0119     /**
0120      * \param cell the cell which formula should  be altered
0121      * \param oldLocation the location/range, that was cut
0122      * \param offset the relative movement and new sheet, if applicable
0123      *
0124      * \see regionMoved()
0125      */
0126     void updateFormula(const Cell& cell, const Region::Element* oldLocation, const Region::Point& offset);
0127 
0128 private:
0129     Q_DISABLE_COPY(DependencyManager)
0130 
0131     class Private;
0132     Private * const d;
0133 };
0134 
0135 } // namespace Sheets
0136 } // namespace Calligra
0137 
0138 #endif // CALLIGRA_SHEETS_DEPENDENCY_MANAGER