KD Chart 2  [rev.2.7]
KDChartLineDiagram_p.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 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  , tension(rhs.tension)
36 {
37 }
38 
39 AttributesModel* LineDiagram::LineDiagramType::attributesModel() const
40 {
41  return m_private->attributesModel;
42 }
43 
44 QModelIndex LineDiagram::LineDiagramType::attributesModelRootIndex() const
45 {
46  return diagram()->attributesModelRootIndex();
47 }
48 
49 int LineDiagram::LineDiagramType::datasetDimension() const
50 {
51  return m_private->datasetDimension;
52 }
53 
54 ReverseMapper& LineDiagram::LineDiagramType::reverseMapper()
55 {
56  return m_private->reverseMapper;
57 }
58 
59 LineDiagram* LineDiagram::LineDiagramType::diagram() const
60 {
61  return static_cast< LineDiagram* >( m_private->diagram );
62 }
63 
64 qreal LineDiagram::LineDiagramType::valueForCell( int row, int column ) const
65 {
66  return diagram()->valueForCell( row, column );
67 }
68 
69 CartesianDiagramDataCompressor& LineDiagram::LineDiagramType::compressor() const
70 {
71  return m_private->compressor;
72 }
73 
74 qreal LineDiagram::LineDiagramType::interpolateMissingValue( const CartesianDiagramDataCompressor::CachePosition& pos ) const
75 {
76  qreal leftValue = std::numeric_limits< qreal >::quiet_NaN();
77  qreal rightValue = std::numeric_limits< qreal >::quiet_NaN();
78  int missingCount = 1;
79 
80  const int column = pos.column;
81  const int row = pos.row;
82  const int rowCount = compressor().modelDataRows();
83 
84  // iterate back and forth to find valid values
85  for ( int r1 = row - 1; r1 > 0; --r1 )
86  {
87  const CartesianDiagramDataCompressor::CachePosition position( r1, column );
88  const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
89  leftValue = point.value;
90  if ( !ISNAN( point.value ) )
91  break;
92  ++missingCount;
93  }
94  for ( int r2 = row + 1; r2 < rowCount; ++r2 )
95  {
96  const CartesianDiagramDataCompressor::CachePosition position( r2, column );
97  const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
98  rightValue = point.value;
99  if ( !ISNAN( point.value ) )
100  break;
101  ++missingCount;
102  }
103  if ( !ISNAN( leftValue ) && !ISNAN( rightValue ) )
104  return leftValue + ( rightValue - leftValue ) / ( missingCount + 1 );
105  else
106  return std::numeric_limits< qreal >::quiet_NaN();
107 }
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)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/