File indexing completed on 2024-05-12 16:35:35
0001 /* This file is part of the KDE project 0002 Copyright 2008 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 "ReadOnlyRegionModel.h" 0021 0022 // Sheets 0023 #include "Region.h" 0024 #include "Sheet.h" 0025 0026 using namespace KSpread; 0027 0028 class ReadOnlyRegionModel::Private 0029 { 0030 public: 0031 Region region; 0032 ReadOnlyRegionModel test(Region()); 0033 }; 0034 0035 ReadOnlyRegionModel::ReadOnlyRegionModel(const Region& region) 0036 : QAbstractProxyModel(region.firstSheet()) 0037 , d(new Private) 0038 { 0039 Q_ASSERT(region.isContiguous()); 0040 d->region = region; 0041 } 0042 0043 ReadOnlyRegionModel::~ReadOnlyRegionModel() 0044 { 0045 delete d; 0046 } 0047 0048 int ReadOnlyRegionModel::columnCount(const QModelIndex& parent) const 0049 { 0050 Q_UNUSED(parent); 0051 return d->region.firstRange().width(); 0052 } 0053 0054 int ReadOnlyRegionModel::rowCount(const QModelIndex& parent) const 0055 { 0056 Q_UNUSED(parent); 0057 return d->region.firstRange().height(); 0058 } 0059 0060 QModelIndex ReadOnlyRegionModel::index(int row, int column, const QModelIndex& parent) const 0061 { 0062 Q_UNUSED(row); 0063 Q_UNUSED(column); 0064 Q_UNUSED(parent); 0065 return QModelIndex(); 0066 } 0067 0068 QModelIndex ReadOnlyRegionModel::parent(const QModelIndex& index) const 0069 { 0070 Q_UNUSED(index); 0071 return QModelIndex(); 0072 } 0073 0074 QModelIndex ReadOnlyRegionModel::mapFromSource(const QModelIndex& sourceIndex) const 0075 { 0076 if (!d->region.contains(QPoint(sourceIndex.column() + 1, sourceIndex.row() + 1))) { 0077 return QModelIndex(); 0078 } 0079 const QPoint offset = d->region.firstRange().topLeft(); 0080 return createIndex(sourceIndex.column() - offset.x() + 1, sourceIndex.row() - offset.y() + 1); 0081 } 0082 0083 QModelIndex ReadOnlyRegionModel::mapToSource(const QModelIndex& proxyIndex) const 0084 { 0085 const QPoint offset = d->region.firstRange().topLeft(); 0086 // return createIndex(proxyIndex.column() + offset.x() - 1, proxyIndex.row() + offset.y() - 1); 0087 return sourceModel()->index(proxyIndex.column() + offset.x() - 1, proxyIndex.row() + offset.y() - 1); 0088 }