KD Chart 2 [rev.2.4]

KDChartNormalPlotter_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 "KDChartNormalPlotter_p.h"
00024 #include "KDChartPlotter.h"
00025 
00026 #include <limits>
00027 
00028 using namespace KDChart;
00029 using namespace std;
00030 
00031 NormalPlotter::NormalPlotter( Plotter* d )
00032     : PlotterType( d )
00033 {
00034 }
00035 
00036 Plotter::PlotType NormalPlotter::type() const
00037 {
00038     return Plotter::Normal;
00039 }
00040 
00041 const QPair< QPointF, QPointF > NormalPlotter::calculateDataBoundaries() const
00042 {
00043     return compressor().dataBoundaries();
00044 }
00045 
00046 void NormalPlotter::paint( PaintContext* ctx )
00047 {
00048     reverseMapper().clear();
00049 
00050     Q_ASSERT( dynamic_cast< CartesianCoordinatePlane* >( ctx->coordinatePlane() ) );
00051     const CartesianCoordinatePlane* const plane = static_cast< CartesianCoordinatePlane* >( ctx->coordinatePlane() );
00052     const int colCount = compressor().modelDataColumns();
00053     const int rowCount = compressor().modelDataRows();
00054 
00055     if( colCount == 0 || rowCount == 0 )
00056         return;
00057 
00058     DataValueTextInfoList textInfoList;
00059 
00060     for( int column = 0; column < colCount; ++column )
00061     {
00062         LineAttributesInfoList lineList;
00063         LineAttributes laPreviousCell;
00064         CartesianDiagramDataCompressor::CachePosition previousCellPosition;
00065         CartesianDiagramDataCompressor::DataPoint lastPoint;
00066 
00067         for( int row = 0; row < rowCount; ++row )
00068         {
00069             const CartesianDiagramDataCompressor::CachePosition position( row, column );
00070             const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00071 
00072             const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
00073             LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
00074             const LineAttributes::MissingValuesPolicy policy = laCell.missingValuesPolicy();
00075 
00076             if( ISNAN( point.key ) || ISNAN( point.value ) )
00077             {
00078                 switch( policy )
00079                 {
00080                 case LineAttributes::MissingValuesAreBridged: // we just bridge both values
00081                     continue;
00082                 case LineAttributes::MissingValuesShownAsZero: // fall-through since that attribute makes no sense for the plotter
00083                 case LineAttributes::MissingValuesHideSegments: // fall-through since they're just hidden
00084                 default:
00085                     previousCellPosition = CartesianDiagramDataCompressor::CachePosition();
00086                     lastPoint = CartesianDiagramDataCompressor::DataPoint();
00087                     continue;
00088                 }
00089             }
00090 
00091             // area corners, a + b are the line ends:
00092             const QPointF a( plane->translate( QPointF( lastPoint.key, lastPoint.value ) ) );
00093             const QPointF b( plane->translate( QPointF( point.key, point.value ) ) );
00094             if( a.toPoint() == b.toPoint() )
00095                 continue;
00096 
00097             const QPointF c( plane->translate( QPointF( lastPoint.key, 0.0 ) ) );
00098             const QPointF d( plane->translate( QPointF( point.key, 0.0 ) ) );
00099 
00100             // add the pieces to painting if this is not hidden:
00101             if ( !point.hidden /*&& !ISNAN( lastPoint.key ) && !ISNAN( lastPoint.value ) */) {
00102                 // add data point labels:
00103                 const PositionPoints pts = PositionPoints( b, a, d, c );
00104                 // if necessary, add the area to the area list:
00105                 QList<QPolygonF> areas;
00106                 if ( laCell.displayArea() ) {
00107                     QPolygonF polygon;
00108                     polygon << a << b << d << c;
00109                     areas << polygon;
00110                 }
00111                 appendDataValueTextInfoToList( diagram(), textInfoList, sourceIndex, pts,
00112                                                Position::NorthWest, Position::SouthWest,
00113                                                point.value );
00114                 if( !ISNAN( lastPoint.key ) && !ISNAN( lastPoint.value ) )
00115                 {
00116                     paintAreas( ctx, attributesModel()->mapToSource( lastPoint.index ), areas, laCell.transparency() );
00117                     lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
00118                 }
00119             }
00120 
00121             // wrap it up:
00122             previousCellPosition = position;
00123             laPreviousCell = laCell;
00124             lastPoint = point;
00125         }
00126         LineAttributes::MissingValuesPolicy policy = LineAttributes::MissingValuesAreBridged; //unused
00127         paintElements( ctx, textInfoList, lineList, policy );
00128     }
00129 }
 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/