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

0001 /* This file is part of the KDE project
0002    Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2004 Ariya Hidayat <ariya@kde.org>
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; only
0008    version 2 of the License.
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 // Local
0022 #include "Damages.h"
0023 
0024 #include <QPoint>
0025 
0026 #include "Cell.h"
0027 #include "Sheet.h"
0028 #include "Region.h"
0029 
0030 using namespace Calligra::Sheets;
0031 
0032 class Q_DECL_HIDDEN WorkbookDamage::Private
0033 {
0034 public:
0035     Calligra::Sheets::Map* map;
0036     Changes changes;
0037 };
0038 
0039 class Q_DECL_HIDDEN SheetDamage::Private
0040 {
0041 public:
0042     Calligra::Sheets::Sheet* sheet;
0043     Changes changes;
0044 };
0045 
0046 class Q_DECL_HIDDEN CellDamage::Private
0047 {
0048 public:
0049     Calligra::Sheets::Sheet* sheet;
0050     Region region;
0051     Changes changes;
0052 };
0053 
0054 class Q_DECL_HIDDEN SelectionDamage::Private
0055 {
0056 public:
0057     Region region;
0058 };
0059 
0060 CellDamage::CellDamage(const Calligra::Sheets::Cell& cell, Changes changes)
0061         : d(new Private)
0062 {
0063     d->sheet = cell.sheet();
0064     if (Region::isValid(QPoint(cell.column(), cell.row())))
0065         d->region = Region(cell.column(), cell.row(), d->sheet);
0066     d->changes = changes;
0067 }
0068 
0069 CellDamage::CellDamage(Calligra::Sheets::Sheet* sheet, const Region& region, Changes changes)
0070         : d(new Private)
0071 {
0072     d->sheet = sheet;
0073     d->region = region;
0074     d->changes = changes;
0075 }
0076 
0077 CellDamage::~CellDamage()
0078 {
0079     delete d;
0080 }
0081 
0082 Sheet* CellDamage::sheet() const
0083 {
0084     return d->sheet;
0085 }
0086 
0087 const Calligra::Sheets::Region& CellDamage::region() const
0088 {
0089     return d->region;
0090 }
0091 
0092 CellDamage::Changes CellDamage::changes() const
0093 {
0094     return d->changes;
0095 }
0096 
0097 
0098 SheetDamage::SheetDamage(Calligra::Sheets::Sheet* sheet, Changes changes)
0099         : d(new Private)
0100 {
0101     d->sheet = sheet;
0102     d->changes = changes;
0103 }
0104 
0105 SheetDamage::~SheetDamage()
0106 {
0107     delete d;
0108 }
0109 
0110 Sheet* SheetDamage::sheet() const
0111 {
0112     return d->sheet;
0113 }
0114 
0115 SheetDamage::Changes SheetDamage::changes() const
0116 {
0117     return d->changes;
0118 }
0119 
0120 
0121 WorkbookDamage::WorkbookDamage(Calligra::Sheets::Map* map, Changes changes)
0122         : d(new Private)
0123 {
0124     d->map = map;
0125     d->changes = changes;
0126 }
0127 
0128 WorkbookDamage::~WorkbookDamage()
0129 {
0130     delete d;
0131 }
0132 
0133 Map* WorkbookDamage::map() const
0134 {
0135     return d->map;
0136 }
0137 
0138 WorkbookDamage::Changes WorkbookDamage::changes() const
0139 {
0140     return d->changes;
0141 }
0142 
0143 
0144 SelectionDamage::SelectionDamage(const Region& region)
0145         : d(new Private)
0146 {
0147     d->region = region;
0148 }
0149 
0150 SelectionDamage::~SelectionDamage()
0151 {
0152     delete d;
0153 }
0154 
0155 const Calligra::Sheets::Region& SelectionDamage::region() const
0156 {
0157     return d->region;
0158 }
0159 
0160 
0161 /***************************************************************************
0162   QDebug support
0163 ****************************************************************************/
0164 
0165 QDebug operator<<(QDebug str, const Calligra::Sheets::Damage& d)
0166 {
0167     switch (d.type()) {
0168     case Damage::Nothing:   return str << "NoDamage";
0169     case Damage::Document:  return str << "Document";
0170     case Damage::Workbook:  return str << "Workbook";
0171     case Damage::Sheet:     return str << "Sheet";
0172     case Damage::Range:     return str << "Range";
0173     case Damage::Cell:      return str << "Cell";
0174     case Damage::Selection: return str << "Selection";
0175     }
0176     return str;
0177 }
0178 
0179 QDebug operator<<(QDebug str, const Calligra::Sheets::CellDamage& d)
0180 {
0181     str << "CellDamage: " << d.region().name(d.sheet());
0182     if (d.changes() & CellDamage::Appearance) str << " Appearance";
0183     if (d.changes() & CellDamage::Binding)    str << " Binding";
0184     if (d.changes() & CellDamage::Formula)    str << " Formula";
0185     if (d.changes() & CellDamage::Value)      str << " Value";
0186     return str;
0187 }
0188 
0189 QDebug operator<<(QDebug str, const Calligra::Sheets::SheetDamage& d)
0190 {
0191     str << "SheetDamage: " << (d.sheet() ? d.sheet()->sheetName() : "NULL POINTER!");
0192     switch (d.changes()) {
0193     case SheetDamage::None:               return str << " None";
0194     case SheetDamage::ContentChanged:     return str << " Content";
0195     case SheetDamage::PropertiesChanged:  return str << " Properties";
0196     case SheetDamage::Hidden:             return str << " Hidden";
0197     case SheetDamage::Shown:              return str << " Shown";
0198     case SheetDamage::Name:               return str << "Name";
0199     case SheetDamage::ColumnsChanged:     return str << "Columns";
0200     case SheetDamage::RowsChanged:        return str << "Rows";
0201     }
0202     return str;
0203 }
0204 
0205 QDebug operator<<(QDebug str, const Calligra::Sheets::SelectionDamage& d)
0206 {
0207     str << "SelectionDamage: " << d.region().name();
0208     return str;
0209 }