25 #include <QAbstractItemModel>
32 #include "KDChartNormalLineDiagram_p.h"
33 #include "PaintingHelpers_p.h"
35 using namespace KDChart;
39 : LineDiagramType( d )
50 const int rowCount = compressor().modelDataRows();
51 const int colCount = compressor().modelDataColumns();
52 const qreal xMin = 0.0;
53 qreal xMax = diagram()->model() ? diagram()->model()->rowCount( diagram()->rootIndex() ) : 0;
54 if ( !diagram()->centerDataPoints() && diagram()->model() )
56 qreal yMin = std::numeric_limits< qreal >::quiet_NaN();
57 qreal yMax = std::numeric_limits< qreal >::quiet_NaN();
59 for (
int column = 0; column < colCount; ++column )
61 for (
int row = 0; row < rowCount; ++row )
63 const CartesianDiagramDataCompressor::CachePosition position( row, column );
64 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
65 const qreal value = ISNAN( point.value ) ? 0.0 : point.value;
67 if ( ISNAN( yMin ) ) {
71 yMin = qMin( yMin, value );
72 yMax = qMax( yMax, value );
80 const QPointF bottomLeft( QPointF( xMin, yMin ) );
81 const QPointF topRight( QPointF( xMax, yMax ) );
87 reverseMapper().clear();
88 Q_ASSERT( dynamic_cast<CartesianCoordinatePlane*>( ctx->
coordinatePlane() ) );
90 const int columnCount = compressor().modelDataColumns();
91 const int rowCount = compressor().modelDataRows();
92 if ( columnCount == 0 || rowCount == 0 )
return;
95 bool rev = diagram()->reverseDatasetOrder();
97 LineAttributesInfoList lineList;
98 for (
int column = rev ? columnCount - 1 : 0;
99 rev ? (column >= 0) : (column < columnCount);
100 rev ? --column : ++column ) {
102 CartesianDiagramDataCompressor::DataPoint lastPoint;
103 qreal lastAreaBoundingValue = 0;
108 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
109 for (
int row = 0; row < rowCount; ++row ) {
110 const CartesianDiagramDataCompressor::CachePosition position( row, column );
112 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
113 if ( point.hidden ) {
117 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
119 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
123 qreal areaBoundingValue;
125 const CartesianDiagramDataCompressor::CachePosition areaBoundingCachePosition( row, laCell.
areaBoundingDataset() );
126 areaBoundingValue = compressor().data( areaBoundingCachePosition ).value;
129 areaBoundingValue = minYValue;
132 if ( ISNAN( point.value ) )
152 if ( !ISNAN( point.value ) ) {
154 const qreal offset = diagram()->centerDataPoints() ? 0.5 : 0;
155 const QPointF a( plane->
translate( QPointF( lastPoint.key + offset, lastPoint.value ) ) );
156 const QPointF b( plane->
translate( QPointF( point.key + offset, point.value ) ) );
157 const QPointF c( plane->
translate( QPointF( lastPoint.key + offset, lastAreaBoundingValue ) ) );
158 const QPointF
d( plane->
translate( QPointF( point.key + offset, areaBoundingValue ) ) );
166 if ( !ISNAN( lastPoint.value ) ) {
167 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
171 areas << ( QPolygonF() << a << b <<
d << c );
178 previousCellPosition = position;
179 laPreviousCell = laCell;
180 lastAreaBoundingValue = areaBoundingValue;