File indexing completed on 2024-05-12 15:53:55

0001 /**
0002  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "ModelParamVsParamPlot.h"
0021 
0022 #include <QAbstractItemModel>
0023 
0024 #include <KChartGlobal>
0025 
0026 
0027 using namespace KChart;
0028 
0029 
0030 static int  nrOfValid(0);
0031 static int  nrOfInvalid(0);
0032 static int  nrOfQt(0);
0033 static int  nrOfKChart(0);
0034 
0035 
0036 ModelParamVsParamPlot::ModelParamVsParamPlot(
0037     QAbstractItemModel  *p_sourceModel,
0038     int                     p_column1,
0039     int                     p_column2,
0040     QObject                 *p_parent)
0041 : QSortFilterProxyModel(p_parent),
0042     m_column1(p_column1),
0043     m_column2(p_column2)
0044 {
0045     setSourceModel(p_sourceModel);
0046 } // ModelParamVsParamPlot::ModelParamVsParamPlot()
0047 
0048 
0049 int ModelParamVsParamPlot::columnCount(
0050     const QModelIndex   &/*p_parent*/) const
0051 {
0052     return 2;
0053 } // ModelParamVsParamPlot::columnCount()
0054 
0055 
0056 QVariant ModelParamVsParamPlot::data(
0057     const QModelIndex       &p_index,
0058     int                     p_role) const
0059 {
0060     QVariant            ret;
0061 
0062     if (p_index.isValid())
0063     {
0064         nrOfValid++;
0065 
0066         switch (p_role)
0067         {
0068             case Qt::DisplayRole:
0069             case Qt::EditRole:
0070                 nrOfQt++;
0071 
0072                 switch (p_index.column())
0073                 {
0074                     case 0: // Parameter1
0075                         ret = sourceModel()->data(sourceModel()->index(p_index.row(), m_column1));
0076                     break;
0077 
0078                     case 1: // Parameter2
0079                         ret = sourceModel()->data(sourceModel()->index(p_index.row(), m_column2));
0080                     break;
0081 
0082                     default:
0083                         ret = "Invalid column index";
0084                         // Invalid column index cannot occur.
0085                     break;
0086                 } // switch column
0087             break;
0088 
0089             default:
0090                 nrOfKChart++;
0091         } // switch role
0092     } // if index valid
0093     else
0094     {
0095         nrOfInvalid++;
0096     }
0097 
0098     return ret;
0099 } // ModelParamVsParamPlot::data()
0100 
0101 
0102 bool ModelParamVsParamPlot::filterAcceptsColumn(
0103     int                     p_source_column,
0104     const QModelIndex       &/*p_source_parent*/) const
0105 {
0106     return p_source_column == m_column1 || p_source_column == m_column2;
0107 } // ModelParamVsParamPlot::filterAcceptsColumn()