Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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:
00081 continue;
00082 case LineAttributes::MissingValuesShownAsZero:
00083 case LineAttributes::MissingValuesHideSegments:
00084 default:
00085 previousCellPosition = CartesianDiagramDataCompressor::CachePosition();
00086 lastPoint = CartesianDiagramDataCompressor::DataPoint();
00087 continue;
00088 }
00089 }
00090
00091
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
00101 if ( !point.hidden ) {
00102
00103 const PositionPoints pts = PositionPoints( b, a, d, c );
00104
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
00122 previousCellPosition = position;
00123 laPreviousCell = laCell;
00124 lastPoint = point;
00125 }
00126 LineAttributes::MissingValuesPolicy policy = LineAttributes::MissingValuesAreBridged;
00127 paintElements( ctx, textInfoList, lineList, policy );
00128 }
00129 }