1 | /* This file is part of the KDE project |
2 | Copyright 2008 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 KSPREAD_ODF_SAVING_CONTEXT |
21 | #define KSPREAD_ODF_SAVING_CONTEXT |
22 | |
23 | #include "Cell.h" |
24 | #include "GenValidationStyle.h" |
25 | #include "Sheet.h" |
26 | #include "calligra_sheets_limits.h" |
27 | |
28 | #include <KoShapeSavingContext.h> |
29 | |
30 | #include <QMap> |
31 | #include <QMultiHash> |
32 | |
33 | class KoShape; |
34 | |
35 | namespace Calligra |
36 | { |
37 | namespace Sheets |
38 | { |
39 | |
40 | /** |
41 | * \ingroup OpenDocument |
42 | * Data used while saving. |
43 | */ |
44 | class OdfSavingContext |
45 | { |
46 | public: |
47 | explicit OdfSavingContext(KoShapeSavingContext &shapeContext) |
48 | : shapeContext(shapeContext) {} |
49 | |
50 | void insertCellAnchoredShape(const Sheet *sheet, int row, int column, KoShape* shape) { |
51 | Q_ASSERT_X(1 <= column && column <= KS_colMax, __FUNCTION__, QString("%1 out of bounds" ).arg(column).toLocal8Bit()); |
52 | Q_ASSERT_X(1 <= row && row <= KS_rowMax, __FUNCTION__, QString("%1 out of bounds" ).arg(row).toLocal8Bit()); |
53 | m_cellAnchoredShapes[sheet][row].insert(column, shape); |
54 | } |
55 | |
56 | bool rowHasCellAnchoredShapes(const Sheet* sheet, int row) const { |
57 | AnchoredShapes::const_iterator it = m_cellAnchoredShapes.constFind(sheet); |
58 | if (it == m_cellAnchoredShapes.constEnd()) |
59 | return false; |
60 | return (*it).contains(row); |
61 | } |
62 | |
63 | bool cellHasAnchoredShapes(const Sheet *sheet, int row, int column) const { |
64 | AnchoredShapes::const_iterator it = m_cellAnchoredShapes.constFind(sheet); |
65 | if (it == m_cellAnchoredShapes.constEnd()) |
66 | return false; |
67 | AnchoredShape::const_iterator rit = (*it).constFind(row); |
68 | if (rit == (*it).constEnd()) |
69 | return false; |
70 | return (*rit).contains(column); |
71 | } |
72 | |
73 | int nextAnchoredShape(const Sheet *sheet, int row, int column) const { |
74 | AnchoredShapes::const_iterator it = m_cellAnchoredShapes.constFind(sheet); |
75 | if (it != m_cellAnchoredShapes.constEnd()) { |
76 | AnchoredShape::const_iterator rit = (*it).constFind(row); |
77 | if (rit != (*it).constEnd()) { |
78 | QMultiHash<int, KoShape*>::const_iterator cit((*rit).constBegin()), cend((*rit).constEnd()); |
79 | for (; cit != cend; ++cit) |
80 | if (cit.key() > column) return cit.key(); // found one |
81 | |
82 | } |
83 | } |
84 | return 0; |
85 | } |
86 | |
87 | QList<KoShape*> cellAnchoredShapes(const Sheet *sheet, int row, int column) const { |
88 | AnchoredShapes::const_iterator it = m_cellAnchoredShapes.constFind(sheet); |
89 | if (it != m_cellAnchoredShapes.constEnd()) { |
90 | AnchoredShape::const_iterator rit = (*it).constFind(row); |
91 | if (rit != (*it).constEnd()) { |
92 | return (*rit).values(column); |
93 | } |
94 | } |
95 | return QList<KoShape*>(); |
96 | } |
97 | |
98 | public: |
99 | KoShapeSavingContext& shapeContext; |
100 | GenValidationStyles valStyle; |
101 | QMap<int, Style> columnDefaultStyles; |
102 | QMap<int, Style> rowDefaultStyles; |
103 | |
104 | private: |
105 | typedef QHash < int /*row*/, QMultiHash < int /*col*/, KoShape* > > AnchoredShape; |
106 | typedef QHash < const Sheet*, AnchoredShape > AnchoredShapes; |
107 | AnchoredShapes m_cellAnchoredShapes; |
108 | }; |
109 | |
110 | } // namespace Sheets |
111 | } // namespace Calligra |
112 | |
113 | #endif // KSPREAD_ODF_SAVING_CONTEXT |
114 | |