1 /* This file is part of the KDE project
2 Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 Copyright 2004 Ariya Hidayat <ariya@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; only
8 version 2 of the License.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20
21 // Local
22 #include "Damages.h"
23
24 #include <QPoint>
25
26 #include "Cell.h"
27 #include "Sheet.h"
28 #include "Region.h"
29
30 using namespace Calligra::Sheets;
31
32 class Q_DECL_HIDDEN WorkbookDamage::Private
33 {
34 public:
35 Calligra::Sheets::Map* map;
36 Changes changes;
37 };
38
39 class Q_DECL_HIDDEN SheetDamage::Private
40 {
41 public:
42 Calligra::Sheets::Sheet* sheet;
43 Changes changes;
44 };
45
46 class Q_DECL_HIDDEN CellDamage::Private
47 {
48 public:
49 Calligra::Sheets::Sheet* sheet;
50 Region region;
51 Changes changes;
52 };
53
54 class Q_DECL_HIDDEN SelectionDamage::Private
55 {
56 public:
57 Region region;
58 };
59
CellDamage(const Calligra::Sheets::Cell & cell,Changes changes)60 CellDamage::CellDamage(const Calligra::Sheets::Cell& cell, Changes changes)
61 : d(new Private)
62 {
63 d->sheet = cell.sheet();
64 if (Region::isValid(QPoint(cell.column(), cell.row())))
65 d->region = Region(cell.column(), cell.row(), d->sheet);
66 d->changes = changes;
67 }
68
CellDamage(Calligra::Sheets::Sheet * sheet,const Region & region,Changes changes)69 CellDamage::CellDamage(Calligra::Sheets::Sheet* sheet, const Region& region, Changes changes)
70 : d(new Private)
71 {
72 d->sheet = sheet;
73 d->region = region;
74 d->changes = changes;
75 }
76
~CellDamage()77 CellDamage::~CellDamage()
78 {
79 delete d;
80 }
81
sheet() const82 Sheet* CellDamage::sheet() const
83 {
84 return d->sheet;
85 }
86
region() const87 const Calligra::Sheets::Region& CellDamage::region() const
88 {
89 return d->region;
90 }
91
changes() const92 CellDamage::Changes CellDamage::changes() const
93 {
94 return d->changes;
95 }
96
97
SheetDamage(Calligra::Sheets::Sheet * sheet,Changes changes)98 SheetDamage::SheetDamage(Calligra::Sheets::Sheet* sheet, Changes changes)
99 : d(new Private)
100 {
101 d->sheet = sheet;
102 d->changes = changes;
103 }
104
~SheetDamage()105 SheetDamage::~SheetDamage()
106 {
107 delete d;
108 }
109
sheet() const110 Sheet* SheetDamage::sheet() const
111 {
112 return d->sheet;
113 }
114
changes() const115 SheetDamage::Changes SheetDamage::changes() const
116 {
117 return d->changes;
118 }
119
120
WorkbookDamage(Calligra::Sheets::Map * map,Changes changes)121 WorkbookDamage::WorkbookDamage(Calligra::Sheets::Map* map, Changes changes)
122 : d(new Private)
123 {
124 d->map = map;
125 d->changes = changes;
126 }
127
~WorkbookDamage()128 WorkbookDamage::~WorkbookDamage()
129 {
130 delete d;
131 }
132
map() const133 Map* WorkbookDamage::map() const
134 {
135 return d->map;
136 }
137
changes() const138 WorkbookDamage::Changes WorkbookDamage::changes() const
139 {
140 return d->changes;
141 }
142
143
SelectionDamage(const Region & region)144 SelectionDamage::SelectionDamage(const Region& region)
145 : d(new Private)
146 {
147 d->region = region;
148 }
149
~SelectionDamage()150 SelectionDamage::~SelectionDamage()
151 {
152 delete d;
153 }
154
region() const155 const Calligra::Sheets::Region& SelectionDamage::region() const
156 {
157 return d->region;
158 }
159
160
161 /***************************************************************************
162 QDebug support
163 ****************************************************************************/
164
operator <<(QDebug str,const Calligra::Sheets::Damage & d)165 QDebug operator<<(QDebug str, const Calligra::Sheets::Damage& d)
166 {
167 switch (d.type()) {
168 case Damage::Nothing: return str << "NoDamage";
169 case Damage::Document: return str << "Document";
170 case Damage::Workbook: return str << "Workbook";
171 case Damage::Sheet: return str << "Sheet";
172 case Damage::Range: return str << "Range";
173 case Damage::Cell: return str << "Cell";
174 case Damage::Selection: return str << "Selection";
175 }
176 return str;
177 }
178
operator <<(QDebug str,const Calligra::Sheets::CellDamage & d)179 QDebug operator<<(QDebug str, const Calligra::Sheets::CellDamage& d)
180 {
181 str << "CellDamage: " << d.region().name(d.sheet());
182 if (d.changes() & CellDamage::Appearance) str << " Appearance";
183 if (d.changes() & CellDamage::Binding) str << " Binding";
184 if (d.changes() & CellDamage::Formula) str << " Formula";
185 if (d.changes() & CellDamage::Value) str << " Value";
186 return str;
187 }
188
operator <<(QDebug str,const Calligra::Sheets::SheetDamage & d)189 QDebug operator<<(QDebug str, const Calligra::Sheets::SheetDamage& d)
190 {
191 str << "SheetDamage: " << (d.sheet() ? d.sheet()->sheetName() : "NULL POINTER!");
192 switch (d.changes()) {
193 case SheetDamage::None: return str << " None";
194 case SheetDamage::ContentChanged: return str << " Content";
195 case SheetDamage::PropertiesChanged: return str << " Properties";
196 case SheetDamage::Hidden: return str << " Hidden";
197 case SheetDamage::Shown: return str << " Shown";
198 case SheetDamage::Name: return str << "Name";
199 case SheetDamage::ColumnsChanged: return str << "Columns";
200 case SheetDamage::RowsChanged: return str << "Rows";
201 }
202 return str;
203 }
204
operator <<(QDebug str,const Calligra::Sheets::SelectionDamage & d)205 QDebug operator<<(QDebug str, const Calligra::Sheets::SelectionDamage& d)
206 {
207 str << "SelectionDamage: " << d.region().name();
208 return str;
209 }
210