File indexing completed on 2024-04-28 16:21:27
0001 /* This file is part of the KDE project 0002 Copyright 2009 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 #include "RegionModel.h" 0021 0022 // Sheets 0023 #include "Region.h" 0024 #include "Sheet.h" 0025 0026 using namespace Calligra::Sheets; 0027 0028 class RegionModel::Private 0029 { 0030 public: 0031 Sheet* sheet; 0032 QRect range; 0033 bool overwriteMode; 0034 }; 0035 0036 0037 RegionModel::RegionModel(const Region& region) 0038 : SheetModel(region.lastSheet()) 0039 , d(new Private) 0040 { 0041 Q_ASSERT(region.isContiguous()); 0042 Q_ASSERT(!region.isEmpty()); 0043 Q_ASSERT(region.lastSheet()); 0044 d->sheet = region.lastSheet(); 0045 d->range = region.lastRange(); 0046 d->overwriteMode = true; 0047 } 0048 0049 RegionModel::~RegionModel() 0050 { 0051 delete d; 0052 } 0053 0054 int RegionModel::columnCount(const QModelIndex &parent) const 0055 { 0056 if (parent.isValid() && parent.internalPointer() != d->sheet->map()) { 0057 return false; 0058 } 0059 if (d->overwriteMode) { 0060 return SheetModel::columnCount(parent) - d->range.left() + 1; 0061 } 0062 return d->range.width(); 0063 } 0064 0065 QModelIndex RegionModel::index(int row, int column, const QModelIndex &parent) const 0066 { 0067 return SheetModel::index(row + d->range.top() - 1, column + d->range.left() - 1, parent); 0068 } 0069 0070 int RegionModel::rowCount(const QModelIndex &parent) const 0071 { 0072 if (parent.isValid() && parent.internalPointer() != d->sheet->map()) { 0073 return false; 0074 } 0075 if (d->overwriteMode) { 0076 return SheetModel::rowCount(parent) - d->range.top() + 1; 0077 } 0078 return d->range.height(); 0079 }