KD Chart 2  [rev.2.5]
KDChartLineDiagram_p.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #include "KDChartLineDiagram.h"
00024 #include "KDChartDataValueAttributes.h"
00025 
00026 #include "KDChartLineDiagram_p.h"
00027 #include "KDChartPainterSaver_p.h"
00028 #include "PaintingHelpers_p.h"
00029 
00030 using namespace KDChart;
00031 using namespace std;
00032 
00033 LineDiagram::Private::Private( const Private& rhs )
00034     : AbstractCartesianDiagram::Private( rhs )
00035 {
00036 }
00037 
00038 AttributesModel* LineDiagram::LineDiagramType::attributesModel() const
00039 {
00040     return m_private->attributesModel;
00041 }
00042 
00043 QModelIndex LineDiagram::LineDiagramType::attributesModelRootIndex() const
00044 {
00045     return diagram()->attributesModelRootIndex();
00046 }
00047 
00048 int LineDiagram::LineDiagramType::datasetDimension() const
00049 {
00050     return m_private->datasetDimension;
00051 }
00052 
00053 ReverseMapper& LineDiagram::LineDiagramType::reverseMapper()
00054 {
00055     return m_private->reverseMapper;
00056 }
00057 
00058 LineDiagram* LineDiagram::LineDiagramType::diagram() const
00059 {
00060     return static_cast< LineDiagram* >( m_private->diagram );
00061 }
00062 
00063 qreal LineDiagram::LineDiagramType::valueForCell( int row, int column ) const
00064 {
00065     return diagram()->valueForCell( row, column );
00066 }
00067 
00068 void LineDiagram::LineDiagramType::addLabel( LabelPaintCache* lpc,
00069                                              const QModelIndex & index,
00070                                              const CartesianDiagramDataCompressor::CachePosition* position,
00071                                              const PositionPoints& points,
00072                                              const Position& autoPositionPositive,
00073                                              const Position& autoPositionNegative, qreal value )
00074 {
00075     m_private->addLabel( lpc, index, position, points,
00076                          autoPositionPositive, autoPositionNegative, value );
00077 }
00078 
00079 CartesianDiagramDataCompressor& LineDiagram::LineDiagramType::compressor() const
00080 {
00081     return m_private->compressor;
00082 }
00083 
00084 qreal LineDiagram::LineDiagramType::interpolateMissingValue( const CartesianDiagramDataCompressor::CachePosition& pos ) const
00085 {
00086     qreal leftValue = std::numeric_limits< qreal >::quiet_NaN();
00087     qreal rightValue = std::numeric_limits< qreal >::quiet_NaN();
00088     int missingCount = 1;
00089 
00090     const int column = pos.column;
00091     const int row = pos.row;
00092     const int rowCount = compressor().modelDataRows();
00093 
00094     // iterate back and forth to find valid values
00095     for( int r1 = row - 1; r1 > 0; --r1 )
00096     {
00097         const CartesianDiagramDataCompressor::CachePosition position( r1, column );
00098         const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00099         leftValue = point.value;
00100         if( !ISNAN( point.value ) )
00101             break;
00102         ++missingCount;
00103     }
00104     for( int r2 = row + 1; r2 < rowCount; ++r2 )
00105     {
00106         const CartesianDiagramDataCompressor::CachePosition position( r2, column );
00107         const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00108         rightValue = point.value;
00109         if( !ISNAN( point.value ) )
00110             break;
00111         ++missingCount;
00112     }
00113     if( !ISNAN( leftValue ) && !ISNAN( rightValue ) )
00114         return leftValue + ( rightValue - leftValue ) / ( missingCount + 1 );
00115     else
00116         return std::numeric_limits< qreal >::quiet_NaN();
00117 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

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