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;
182 const int step = rev ? -1 : 1;
183 const int end = rev ? -1 : columnCount;
184 for (
int column = rev ? columnCount - 1 : 0; column != end; column += step ) {
186 CartesianDiagramDataCompressor::DataPoint lastPoint;
187 qreal lastAreaBoundingValue = 0;
192 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
193 for (
int row = 0; row < rowCount; ++row ) {
194 const CartesianDiagramDataCompressor::CachePosition position( row, column );
196 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
197 if ( point.hidden ) {
201 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
203 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
207 qreal areaBoundingValue;
209 const CartesianDiagramDataCompressor::CachePosition areaBoundingCachePosition( row, laCell.
areaBoundingDataset() );
210 areaBoundingValue = compressor().data( areaBoundingCachePosition ).value;
213 areaBoundingValue = minYValue;
216 if ( ISNAN( point.value ) )
236 if ( !ISNAN( point.value ) ) {
238 const qreal offset = diagram()->centerDataPoints() ? 0.5 : 0;
239 const QPointF a( plane->
translate( QPointF( lastPoint.key + offset, lastPoint.value ) ) );
240 const QPointF b( plane->
translate( QPointF( point.key + offset, point.value ) ) );
241 const QPointF c( plane->
translate( QPointF( lastPoint.key + offset, lastAreaBoundingValue ) ) );
242 const QPointF
d( plane->
translate( QPointF( point.key + offset, areaBoundingValue ) ) );
250 if ( !ISNAN( lastPoint.value ) ) {
251 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
265 struct dataAtLambda {
267 : rowCount( rowCount )
279 NormalLineDiagram* _this;
281 QPointF operator() (
int i )
const 283 if ( i < 0 || i >= rowCount ) {
284 return QPointF( NAN, NAN );
286 const KDChart::CartesianDiagramDataCompressor::DataPoint data = _this->compressor().data( CartesianDiagramDataCompressor::CachePosition( i, column ) );
287 return QPointF( plane->
translate( QPointF( data.key + offset, data.value ) ) );
291 dataAtLambda dataAt( rowCount, column, offset, plane,
this );
295 addSplineChunkTo( path, tension, dataAt( row - 2 ), a, b, dataAt( row + 1 ) );
306 previousCellPosition = position;
307 laPreviousCell = laCell;
308 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.
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