1 | /* This file is part of the KDE project |
2 | Copyright 2009 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 | #include "RegionModel.h" |
21 | |
22 | // KSpread |
23 | #include "Region.h" |
24 | #include "Sheet.h" |
25 | |
26 | using namespace Calligra::Sheets; |
27 | |
28 | class RegionModel::Private |
29 | { |
30 | public: |
31 | Sheet* sheet; |
32 | QRect range; |
33 | bool overwriteMode; |
34 | }; |
35 | |
36 | |
37 | RegionModel::RegionModel(const Region& region) |
38 | : SheetModel(region.lastSheet()) |
39 | , d(new Private) |
40 | { |
41 | Q_ASSERT(region.isContiguous()); |
42 | Q_ASSERT(!region.isEmpty()); |
43 | Q_ASSERT(region.lastSheet()); |
44 | d->sheet = region.lastSheet(); |
45 | d->range = region.lastRange(); |
46 | d->overwriteMode = true; |
47 | } |
48 | |
49 | RegionModel::~RegionModel() |
50 | { |
51 | delete d; |
52 | } |
53 | |
54 | int RegionModel::columnCount(const QModelIndex &parent) const |
55 | { |
56 | if (parent.isValid() && parent.internalPointer() != d->sheet->map()) { |
57 | return false; |
58 | } |
59 | if (d->overwriteMode) { |
60 | return SheetModel::columnCount(parent) - d->range.left() + 1; |
61 | } |
62 | return d->range.width(); |
63 | } |
64 | |
65 | QModelIndex RegionModel::index(int row, int column, const QModelIndex &parent) const |
66 | { |
67 | return SheetModel::index(row + d->range.top() - 1, column + d->range.left() - 1, parent); |
68 | } |
69 | |
70 | int RegionModel::rowCount(const QModelIndex &parent) const |
71 | { |
72 | if (parent.isValid() && parent.internalPointer() != d->sheet->map()) { |
73 | return false; |
74 | } |
75 | if (d->overwriteMode) { |
76 | return SheetModel::rowCount(parent) - d->range.top() + 1; |
77 | } |
78 | return d->range.height(); |
79 | } |
80 | |