1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "KChartModelDataCache_p.h"
21 
22 #include <limits>
23 
24 using namespace KChart::ModelDataCachePrivate;
25 
ModelSignalMapperConnector(ModelSignalMapper & mapper)26 ModelSignalMapperConnector::ModelSignalMapperConnector( ModelSignalMapper& mapper )
27     : QObject( nullptr ),
28       m_mapper( mapper )
29 {
30 }
31 
~ModelSignalMapperConnector()32 ModelSignalMapperConnector::~ModelSignalMapperConnector()
33 {
34 }
35 
connectSignals(QAbstractItemModel * model)36 void ModelSignalMapperConnector::connectSignals( QAbstractItemModel* model )
37 {
38     connect( model, SIGNAL(destroyed()),                              this, SLOT(resetModel()) );
39     connect( model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(columnsInserted(QModelIndex,int,int)) );
40     connect( model, SIGNAL(columnsRemoved(QModelIndex,int,int)),  this, SLOT(columnsRemoved(QModelIndex,int,int)) );
41     connect( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),  this, SLOT(dataChanged(QModelIndex,QModelIndex)) );
42     connect( model, SIGNAL(layoutChanged()),                          this, SLOT(layoutChanged()) );
43     connect( model, SIGNAL(modelReset()),                             this, SLOT(modelReset()) );
44     connect( model, SIGNAL(rowsInserted(QModelIndex,int,int)),    this, SLOT(rowsInserted(QModelIndex,int,int)) );
45     connect( model, SIGNAL(rowsRemoved(QModelIndex,int,int)),     this, SLOT(rowsRemoved(QModelIndex,int,int)) );
46 }
47 
disconnectSignals(QAbstractItemModel * model)48 void ModelSignalMapperConnector::disconnectSignals( QAbstractItemModel* model )
49 {
50     disconnect( model, SIGNAL(destroyed()),                              this, SLOT(resetModel()) );
51     disconnect( model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(columnsInserted(QModelIndex,int,int)) );
52     disconnect( model, SIGNAL(columnsRemoved(QModelIndex,int,int)),  this, SLOT(columnsRemoved(QModelIndex,int,int)) );
53     disconnect( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),  this, SLOT(dataChanged(QModelIndex,QModelIndex)) );
54     disconnect( model, SIGNAL(layoutChanged()),                          this, SLOT(layoutChanged()) );
55     disconnect( model, SIGNAL(modelReset()),                             this, SLOT(modelReset()) );
56     disconnect( model, SIGNAL(rowsInserted(QModelIndex,int,int)),    this, SLOT(rowsInserted(QModelIndex,int,int)) );
57     disconnect( model, SIGNAL(rowsRemoved(QModelIndex,int,int)),     this, SLOT(rowsRemoved(QModelIndex,int,int)) );
58 }
59 
resetModel()60 void ModelSignalMapperConnector::resetModel()
61 {
62     m_mapper.resetModel();
63 }
64 
columnsInserted(const QModelIndex & parent,int start,int end)65 void ModelSignalMapperConnector::columnsInserted( const QModelIndex& parent, int start, int end )
66 {
67     m_mapper.columnsInserted( parent, start, end );
68 }
69 
columnsRemoved(const QModelIndex & parent,int start,int end)70 void ModelSignalMapperConnector::columnsRemoved( const QModelIndex& parent, int start, int end )
71 {
72     m_mapper.columnsRemoved( parent, start, end );
73 }
74 
dataChanged(const QModelIndex & topLeft,const QModelIndex & bottomRight)75 void ModelSignalMapperConnector::dataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight )
76 {
77     m_mapper.dataChanged( topLeft, bottomRight );
78 }
79 
layoutChanged()80 void ModelSignalMapperConnector::layoutChanged()
81 {
82     m_mapper.layoutChanged();
83 }
84 
modelReset()85 void ModelSignalMapperConnector::modelReset()
86 {
87     m_mapper.modelReset();
88 }
89 
rowsInserted(const QModelIndex & parent,int start,int end)90 void ModelSignalMapperConnector::rowsInserted( const QModelIndex& parent, int start, int end )
91 {
92     m_mapper.rowsInserted( parent, start, end );
93 }
94 
rowsRemoved(const QModelIndex & parent,int start,int end)95 void ModelSignalMapperConnector::rowsRemoved( const QModelIndex& parent, int start, int end )
96 {
97     m_mapper.rowsRemoved( parent, start, end );
98 }
99