KD Chart 2  [rev.2.6]
KDChartLineDiagram_p.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2019 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "KDChartLineDiagram.h"
25 
26 #include "KDChartLineDiagram_p.h"
27 #include "KDChartPainterSaver_p.h"
28 #include "PaintingHelpers_p.h"
29 
30 using namespace KDChart;
31 using namespace std;
32 
33 LineDiagram::Private::Private( const Private& rhs )
34  : AbstractCartesianDiagram::Private( rhs )
35 {
36 }
37 
38 AttributesModel* LineDiagram::LineDiagramType::attributesModel() const
39 {
40  return m_private->attributesModel;
41 }
42 
43 QModelIndex LineDiagram::LineDiagramType::attributesModelRootIndex() const
44 {
45  return diagram()->attributesModelRootIndex();
46 }
47 
48 int LineDiagram::LineDiagramType::datasetDimension() const
49 {
50  return m_private->datasetDimension;
51 }
52 
53 ReverseMapper& LineDiagram::LineDiagramType::reverseMapper()
54 {
55  return m_private->reverseMapper;
56 }
57 
58 LineDiagram* LineDiagram::LineDiagramType::diagram() const
59 {
60  return static_cast< LineDiagram* >( m_private->diagram );
61 }
62 
63 qreal LineDiagram::LineDiagramType::valueForCell( int row, int column ) const
64 {
65  return diagram()->valueForCell( row, column );
66 }
67 
68 CartesianDiagramDataCompressor& LineDiagram::LineDiagramType::compressor() const
69 {
70  return m_private->compressor;
71 }
72 
73 qreal LineDiagram::LineDiagramType::interpolateMissingValue( const CartesianDiagramDataCompressor::CachePosition& pos ) const
74 {
75  qreal leftValue = std::numeric_limits< qreal >::quiet_NaN();
76  qreal rightValue = std::numeric_limits< qreal >::quiet_NaN();
77  int missingCount = 1;
78 
79  const int column = pos.column;
80  const int row = pos.row;
81  const int rowCount = compressor().modelDataRows();
82 
83  // iterate back and forth to find valid values
84  for ( int r1 = row - 1; r1 > 0; --r1 )
85  {
86  const CartesianDiagramDataCompressor::CachePosition position( r1, column );
87  const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
88  leftValue = point.value;
89  if ( !ISNAN( point.value ) )
90  break;
91  ++missingCount;
92  }
93  for ( int r2 = row + 1; r2 < rowCount; ++r2 )
94  {
95  const CartesianDiagramDataCompressor::CachePosition position( r2, column );
96  const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
97  rightValue = point.value;
98  if ( !ISNAN( point.value ) )
99  break;
100  ++missingCount;
101  }
102  if ( !ISNAN( leftValue ) && !ISNAN( rightValue ) )
103  return leftValue + ( rightValue - leftValue ) / ( missingCount + 1 );
104  else
105  return std::numeric_limits< qreal >::quiet_NaN();
106 }
Declaring the class KDChart::DataValueAttributes.
qreal valueForCell(int row, int column) const
Helper method, retrieving the data value (DisplayRole) for a given row and column.
The ReverseMapper stores information about objects on a chart and their respective model indexes...
Definition: ReverseMapper.h:44
A proxy model used for decorating data with attributes.
LineDiagram defines a common line diagram.
Base class for diagrams based on a cartesian coordianate system.

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
https://www.kdab.com/
https://www.kdab.com/products/kd-chart/