File indexing completed on 2024-05-12 04:20:16

0001 /**
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "ModelParamVsParamPlot.h"
0010 
0011 #include <QAbstractItemModel>
0012 
0013 #include <KChartGlobal>
0014 
0015 
0016 using namespace KChart;
0017 
0018 
0019 static int  nrOfValid(0);
0020 static int  nrOfInvalid(0);
0021 static int  nrOfQt(0);
0022 static int  nrOfKChart(0);
0023 
0024 
0025 ModelParamVsParamPlot::ModelParamVsParamPlot(
0026     QAbstractItemModel  *p_sourceModel,
0027     int                     p_column1,
0028     int                     p_column2,
0029     QObject                 *p_parent)
0030 : QSortFilterProxyModel(p_parent),
0031     m_column1(p_column1),
0032     m_column2(p_column2)
0033 {
0034     setSourceModel(p_sourceModel);
0035 } // ModelParamVsParamPlot::ModelParamVsParamPlot()
0036 
0037 
0038 int ModelParamVsParamPlot::columnCount(
0039     const QModelIndex   &/*p_parent*/) const
0040 {
0041     return 2;
0042 } // ModelParamVsParamPlot::columnCount()
0043 
0044 
0045 QVariant ModelParamVsParamPlot::data(
0046     const QModelIndex       &p_index,
0047     int                     p_role) const
0048 {
0049     QVariant            ret;
0050 
0051     if (p_index.isValid())
0052     {
0053         nrOfValid++;
0054 
0055         switch (p_role)
0056         {
0057             case Qt::DisplayRole:
0058             case Qt::EditRole:
0059                 nrOfQt++;
0060 
0061                 switch (p_index.column())
0062                 {
0063                     case 0: // Parameter1
0064                         ret = sourceModel()->data(sourceModel()->index(p_index.row(), m_column1));
0065                     break;
0066 
0067                     case 1: // Parameter2
0068                         ret = sourceModel()->data(sourceModel()->index(p_index.row(), m_column2));
0069                     break;
0070 
0071                     default:
0072                         ret = "Invalid column index";
0073                         // Invalid column index cannot occur.
0074                     break;
0075                 } // switch column
0076             break;
0077 
0078             default:
0079                 nrOfKChart++;
0080         } // switch role
0081     } // if index valid
0082     else
0083     {
0084         nrOfInvalid++;
0085     }
0086 
0087     return ret;
0088 } // ModelParamVsParamPlot::data()
0089 
0090 
0091 bool ModelParamVsParamPlot::filterAcceptsColumn(
0092     int                     p_source_column,
0093     const QModelIndex       &/*p_source_parent*/) const
0094 {
0095     return p_source_column == m_column1 || p_source_column == m_column2;
0096 } // ModelParamVsParamPlot::filterAcceptsColumn()