File indexing completed on 2024-05-12 16:33:36
0001 /* This file is part of the KDE project 0002 0003 Copyright 2010 Johannes Simon <johannes.simon@gmail.com> 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; either 0008 version 2 of the License, or (at your option) any later version. 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 // Own 0022 #include "SingleModelHelper.h" 0023 0024 // Qt 0025 #include <QAbstractItemModel> 0026 0027 // KoChart 0028 #include "TableSource.h" 0029 #include "ChartProxyModel.h" 0030 #include "CellRegion.h" 0031 0032 using namespace KoChart; 0033 0034 SingleModelHelper::SingleModelHelper(Table *table, ChartProxyModel *proxyModel) 0035 : m_table(table) 0036 , m_proxyModel(proxyModel) 0037 { 0038 Q_ASSERT(table); 0039 Q_ASSERT(proxyModel); 0040 0041 QAbstractItemModel *model = table->model(); 0042 connect(model, SIGNAL(modelReset()), 0043 this, SLOT(slotModelStructureChanged())); 0044 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), 0045 this, SLOT(slotModelStructureChanged())); 0046 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 0047 this, SLOT(slotModelStructureChanged())); 0048 connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)), 0049 this, SLOT(slotModelStructureChanged())); 0050 connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), 0051 this, SLOT(slotModelStructureChanged())); 0052 0053 // Initialize the proxy with this model 0054 slotModelStructureChanged(); 0055 } 0056 0057 void SingleModelHelper::slotModelStructureChanged() 0058 { 0059 QAbstractItemModel *model = m_table->model(); 0060 const int columnCount = model->columnCount(); 0061 const int rowCount = model->rowCount(); 0062 CellRegion region(m_table); 0063 if (columnCount >= 1 && rowCount >= 1) { 0064 QPoint topLeft(1, 1); 0065 QPoint bottomRight(columnCount, rowCount); 0066 region.add(QRect(topLeft, bottomRight)); 0067 } 0068 m_proxyModel->reset(region); 0069 }