25 #include <QAbstractItemModel> 32 #include "KDChartNormalLineDiagram_p.h" 33 #include "PaintingHelpers_p.h" 39 : LineDiagramType( d )
50 return compressor().dataBoundaries();
55 if ( qFuzzyIsNull( m_private->tension ) ) {
56 paintWithLines( ctx );
59 paintWithSplines( ctx, m_private->tension );
63 void NormalLineDiagram::paintWithLines(
PaintContext* ctx )
65 reverseMapper().clear();
66 Q_ASSERT( dynamic_cast<CartesianCoordinatePlane*>( ctx->
coordinatePlane() ) );
68 const int columnCount = compressor().modelDataColumns();
69 const int rowCount = compressor().modelDataRows();
70 if ( columnCount == 0 || rowCount == 0 )
return;
73 bool rev = diagram()->reverseDatasetOrder();
75 LineAttributesInfoList lineList;
77 const int step = rev ? -1 : 1;
78 const int end = rev ? -1 : columnCount;
79 for (
int column = rev ? columnCount - 1 : 0; column != end; column += step ) {
81 CartesianDiagramDataCompressor::DataPoint lastPoint;
82 qreal lastAreaBoundingValue = 0;
87 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
88 for (
int row = 0; row < rowCount; ++row ) {
89 const CartesianDiagramDataCompressor::CachePosition position( row, column );
91 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
96 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
98 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
102 qreal areaBoundingValue;
104 const CartesianDiagramDataCompressor::CachePosition areaBoundingCachePosition( row, laCell.
areaBoundingDataset() );
105 areaBoundingValue = compressor().data( areaBoundingCachePosition ).value;
108 areaBoundingValue = minYValue;
111 if ( ISNAN( point.value ) )
131 if ( !ISNAN( point.value ) ) {
133 const qreal offset = diagram()->centerDataPoints() ? 0.5 : 0;
134 const QPointF a( plane->
translate( QPointF( lastPoint.key + offset, lastPoint.value ) ) );
135 const QPointF b( plane->
translate( QPointF( point.key + offset, point.value ) ) );
136 const QPointF c( plane->
translate( QPointF( lastPoint.key + offset, lastAreaBoundingValue ) ) );
137 const QPointF
d( plane->
translate( QPointF( point.key + offset, areaBoundingValue ) ) );
145 if ( !ISNAN( lastPoint.value ) ) {
146 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
150 areas << ( QPolygonF() << a << b <<
d << c );
157 previousCellPosition = position;
158 laPreviousCell = laCell;
159 lastAreaBoundingValue = areaBoundingValue;
168 void NormalLineDiagram::paintWithSplines(
PaintContext* ctx, qreal tension )
170 reverseMapper().clear();
171 Q_ASSERT( dynamic_cast<CartesianCoordinatePlane*>( ctx->
coordinatePlane() ) );
173 const int columnCount = compressor().modelDataColumns();
174 const int rowCount = compressor().modelDataRows();
175 if ( columnCount == 0 || rowCount == 0 )
return;
178 bool rev = diagram()->reverseDatasetOrder();
180 LineAttributesInfoList lineList;
184 const int step = rev ? -1 : 1;
185 const int end = rev ? -1 : columnCount;
186 for (
int column = rev ? columnCount - 1 : 0; column != end; column += step ) {
188 CartesianDiagramDataCompressor::DataPoint lastPoint;
189 qreal lastAreaBoundingValue = 0;
194 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
195 for (
int row = 0; row < rowCount; ++row ) {
196 const CartesianDiagramDataCompressor::CachePosition position( row, column );
198 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
199 if ( point.hidden ) {
203 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
205 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
209 qreal areaBoundingValue;
211 const CartesianDiagramDataCompressor::CachePosition areaBoundingCachePosition( row, laCell.
areaBoundingDataset() );
212 areaBoundingValue = compressor().data( areaBoundingCachePosition ).value;
215 areaBoundingValue = minYValue;
218 if ( ISNAN( point.value ) )
238 if ( !ISNAN( point.value ) ) {
240 const qreal offset = diagram()->centerDataPoints() ? 0.5 : 0;
241 const QPointF a( plane->
translate( QPointF( lastPoint.key + offset, lastPoint.value ) ) );
242 const QPointF b( plane->
translate( QPointF( point.key + offset, point.value ) ) );
243 const QPointF c( plane->
translate( QPointF( lastPoint.key + offset, lastAreaBoundingValue ) ) );
244 const QPointF
d( plane->
translate( QPointF( point.key + offset, areaBoundingValue ) ) );
252 if ( !ISNAN( lastPoint.value ) ) {
253 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
267 struct dataAtLambda {
269 : rowCount( rowCount )
281 NormalLineDiagram* _this;
283 QPointF operator() (
int i )
const 285 if ( i < 0 || i >= rowCount ) {
286 return QPointF( NAN, NAN );
288 const KDChart::CartesianDiagramDataCompressor::DataPoint data = _this->compressor().data( CartesianDiagramDataCompressor::CachePosition( i, column ) );
289 return QPointF( plane->
translate( QPointF( data.key + offset, data.value ) ) );
293 dataAtLambda dataAt( rowCount, column, offset, plane,
this );
297 addSplineChunkTo( path, tension, dataAt( row - 2 ), a, b, dataAt( row + 1 ), mainSplineDirection );
308 previousCellPosition = position;
309 laPreviousCell = laCell;
310 lastAreaBoundingValue = areaBoundingValue;
int areaBoundingDataset() const
KDChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
void paintElements(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const LabelPaintCache &lpc, const LineAttributesInfoList &lineList)
AbstractCoordinatePlane * coordinatePlane() const
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
Set of attributes for changing the appearance of line charts.
bool isHorizontalRangeReversed() const
void paintAreas(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const QModelIndex &index, const QList< QPolygonF > &areas, uint opacity)
static const Position & NorthWest
LineDiagram defines a common line diagram.
Stores information about painting diagrams.
Stores the absolute target points of a Position.
MissingValuesPolicy
MissingValuesPolicy specifies how a missing value will be shown in a line diagram.
Cartesian coordinate plane.
QRectF visibleDataRange() const
Returns the currently visible data range.
uint transparency() const
MissingValuesPolicy missingValuesPolicy() const