File indexing completed on 2024-04-28 16:21:34
0001 /* This file is part of the KDE project 0002 Copyright 2006,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef CALLIGRA_SHEETS_STYLE_STORAGE 0021 #define CALLIGRA_SHEETS_STYLE_STORAGE 0022 0023 #include <QObject> 0024 #include <QPair> 0025 #include <QPoint> 0026 #include <QRect> 0027 0028 #include "sheets_odf_export.h" 0029 #include <Region.h> 0030 #include <Style.h> 0031 0032 namespace Calligra 0033 { 0034 namespace Sheets 0035 { 0036 class Map; 0037 class Style; 0038 class StyleManager; 0039 class SubStyle; 0040 class StyleStorageLoaderJob; 0041 0042 /** 0043 * \ingroup Storage 0044 * \ingroup Style 0045 * The style storage. 0046 * Acts mainly as a wrapper around the R-Tree data structure to allow a future 0047 * replacement of this backend. Decorated with some additional features like 0048 * garbage collection, caching, used area tracking, etc. 0049 */ 0050 class CALLIGRA_SHEETS_ODF_EXPORT StyleStorage : public QObject 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 explicit StyleStorage(Map* map); 0056 StyleStorage(const StyleStorage& other); 0057 ~StyleStorage() override; 0058 0059 /** 0060 * Composes the style for \p point. All substyles intersecting \p point are considered. 0061 * \return the Style at the position \p point . 0062 */ 0063 Style contains(const QPoint& point) const; 0064 0065 /** 0066 * Composes the style for \p rect. Only substyles which fill out \p rect completely are 0067 * considered. In contrast to intersects(const QRect&). 0068 * Especially useful on saving cell styles assigned to columns or rows. 0069 * \return the Style for the area \p rect . 0070 * \see intersects 0071 */ 0072 Style contains(const QRect& rect) const; 0073 0074 /** 0075 * Composes the style for \p rect. All substyles which intersect \p rect are considered. 0076 * In contrast to contains(const QRect&). 0077 * \return the Style for the area \p rect . 0078 * \see contains 0079 */ 0080 Style intersects(const QRect& rect) const; 0081 0082 /** 0083 * Collects all substyle/range pairs, that intersect \p rect. With this data one can 0084 * reconstruct the former state of the storage after modification. 0085 * \return all substyle/range pairs intersecting \p rect 0086 */ 0087 QList< QPair<QRectF, SharedSubStyle> > undoData(const Region& rect) const; 0088 0089 /** 0090 * Returns the area, which got a style attached. 0091 * \return the area using styles 0092 */ 0093 QRect usedArea() const; 0094 0095 /** 0096 * \return the OpenDocument column/row default cell styles 0097 * \ingroup OpenDocument 0098 */ 0099 void saveCreateDefaultStyles(int& maxCols, int& maxRows, QMap<int, Style> &columnDefaultStyles, QMap<int, Style> &rowDefaultStyles) const; 0100 0101 /** 0102 * Returns the index of the next column-wide cell style after \p column or zero 0103 * if there's none. 0104 * \return the index of the next styled column 0105 */ 0106 int nextColumnStyleIndex(int column) const; 0107 0108 /** 0109 * Returns the index of the next row-wide cell style after \p row or zero 0110 * if there's none. 0111 * \return the index of the next styled row 0112 */ 0113 int nextRowStyleIndex(int row) const; 0114 0115 /** 0116 * Returns the index of the first cell style in \p row or zero 0117 * if there's none. 0118 * \return the index of the next styled column 0119 */ 0120 int firstColumnIndexInRow(int row) const; 0121 0122 /** 0123 * Returns the index of the next cell style in \p row after \p column or zero 0124 * if there's none. 0125 * \return the index of the next styled column 0126 */ 0127 int nextColumnIndexInRow(int column, int row) const; 0128 0129 /** 0130 * Assigns \p subStyle to the area \p rect . 0131 */ 0132 void insert(const QRect& rect, const SharedSubStyle& subStyle, bool markRegionChanged = true); 0133 0134 /** 0135 * Assigns the substyles contained in \p style to the area \p region . 0136 */ 0137 void insert(const Region& region, const Style& style); 0138 0139 /** 0140 * Replaces the current styles with those in \p styles 0141 */ 0142 void load(const QList<QPair<QRegion, Style> >& styles); 0143 0144 /** 0145 * Inserts \p number rows at the position \p position . 0146 * It extends or shifts rectangles, respectively. 0147 */ 0148 QList< QPair<QRectF, SharedSubStyle> > insertRows(int position, int number = 1); 0149 0150 /** 0151 * Inserts \p number columns at the position \p position . 0152 * It extends or shifts rectangles, respectively. 0153 */ 0154 QList< QPair<QRectF, SharedSubStyle> > insertColumns(int position, int number = 1); 0155 0156 /** 0157 * Deletes \p number rows at the position \p position . 0158 * It shrinks or shifts rectangles, respectively. 0159 */ 0160 QList< QPair<QRectF, SharedSubStyle> > removeRows(int position, int number = 1); 0161 0162 /** 0163 * Deletes \p number columns at the position \p position . 0164 * It shrinks or shifts rectangles, respectively. 0165 */ 0166 QList< QPair<QRectF, SharedSubStyle> > removeColumns(int position, int number = 1); 0167 0168 /** 0169 * Shifts the rows right of \p rect to the right by the width of \p rect . 0170 * It extends or shifts rectangles, respectively. 0171 */ 0172 QList< QPair<QRectF, SharedSubStyle> > insertShiftRight(const QRect& rect); 0173 0174 /** 0175 * Shifts the columns at the bottom of \p rect to the bottom by the height of \p rect . 0176 * It extends or shifts rectangles, respectively. 0177 */ 0178 QList< QPair<QRectF, SharedSubStyle> > insertShiftDown(const QRect& rect); 0179 0180 /** 0181 * Shifts the rows left of \p rect to the left by the width of \p rect . 0182 * It shrinks or shifts rectangles, respectively. 0183 * \return the former rectangle/data pairs 0184 */ 0185 QList< QPair<QRectF, SharedSubStyle> > removeShiftLeft(const QRect& rect); 0186 0187 /** 0188 * Shifts the columns on top of \p rect to the top by the height of \p rect . 0189 * It shrinks or shifts rectangles, respectively. 0190 * \return the former rectangle/data pairs 0191 */ 0192 QList< QPair<QRectF, SharedSubStyle> > removeShiftUp(const QRect& rect); 0193 0194 /** 0195 * Invalidates all cached styles. 0196 */ 0197 void invalidateCache(); 0198 0199 protected Q_SLOTS: 0200 void garbageCollection(); 0201 0202 protected: 0203 /** 0204 * Triggers all necessary actions after a change of \p rect . 0205 * Calls invalidateCache() and adds the substyles in 0206 * \p rect to the list of possible garbage. 0207 */ 0208 void regionChanged(const QRect& rect); 0209 0210 /** 0211 * Invalidates all cached styles lying in \p rect . 0212 */ 0213 void invalidateCache(const QRect& rect); 0214 0215 /** 0216 * Composes a style of \p substyles . 0217 * \return the composed style 0218 */ 0219 Style composeStyle(const QList<SharedSubStyle>& subStyles) const; 0220 0221 /** 0222 * Convenience method. 0223 * \return the StyleManager 0224 */ 0225 StyleManager* styleManager() const; 0226 0227 private: 0228 friend class StyleStorageLoaderJob; 0229 // disable assignment 0230 void operator=(const StyleStorage& other); 0231 0232 class Private; 0233 Private * const d; 0234 }; 0235 0236 } // namespace Sheets 0237 } // namespace Calligra 0238 0239 #endif // CALLIGRA_SHEETS_STYLE_STORAGE