23 #include "PaintingHelpers_p.h" 28 #include "KDChartAbstractDiagram_p.h" 31 #include "KDChartLineDiagram_p.h" 34 #include "KDChartPainterSaver_p.h" 41 namespace PaintingHelpers {
53 return QPointF( point.x() * cos( yrad ) + tdAttributes.
depth() * sin( yrad ),
54 point.y() * cos( xrad ) - tdAttributes.
depth() * sin( xrad ) );
57 QPainterPath
fitPoints(
const QPolygonF &points, qreal tension, SplineDirection splineDirection )
60 path.moveTo( points.at( 0 ) );
61 const int count = points.size();
68 dataAtLambda(
const QPolygonF &points,
int count)
73 const QPolygonF &points;
76 QPointF operator() (
int i)
const 78 return i < 0 || i >= count ? QPointF(NAN, NAN) : points.at( i );
82 dataAtLambda dataAt(points, count);
84 for (
int i = 1; i < count; ++i) {
85 addSplineChunkTo( path, tension, dataAt( i - 2 ), points.at( i - 1 ), points.at( i ), dataAt( i + 1 ), splineDirection );
93 ctx->
painter()->setBrush( brush );
95 QPen( pen.color(), pen.width(), pen.style(), Qt::FlatCap, Qt::MiterJoin ) ) );
96 #if QT_VERSION > 0x040299 97 ctx->
painter()->drawPolyline( points );
102 for (
int i = 0; i < points.size()-1; ++i ) {
103 ctx->
painter()->drawLine( points.at( i ), points.at( i + 1 ) );
108 void paintSpline(
PaintContext* ctx,
const QBrush& brush,
const QPen& pen,
const QPolygonF& points, qreal tension, SplineDirection splineDirection )
110 if (points.size() < 3) {
115 ctx->
painter()->setBrush( brush );
116 ctx->
painter()->setBrush( QBrush() );
118 QPen( pen.color(), pen.width(), pen.style(), Qt::FlatCap, Qt::MiterJoin ) ) );
127 const QPointF topLeft =
project( from, tdAttributes );
128 const QPointF topRight =
project ( to, tdAttributes );
129 const QPolygonF segment = QPolygonF() << from << topLeft << topRight << to;
131 QBrush indexBrush( diagram->
brush( index ) );
132 indexBrush = tdAttributes.
threeDBrush( indexBrush, QRectF(topLeft, topRight) );
134 const PainterSaver painterSaver( ctx->
painter() );
137 ctx->
painter()->setBrush( indexBrush );
140 reverseMapper->
addPolygon( index.row(), index.column(), segment );
141 ctx->
painter()->drawPolygon( segment );
153 gridDimensions.at( 0 ).end :
154 gridDimensions.at( 0 ).start,
156 gridDimensions.at( 1 ).end :
157 gridDimensions.at( 1 ).start ) ) );
160 gridDimensions.at( 0 ).start :
161 gridDimensions.at( 0 ).end,
163 gridDimensions.at( 1 ).start :
164 gridDimensions.at( 1 ).end ) ) );
165 const QPointF markerPoint = at;
169 startPoint = QPointF( bottomLeft.x(), at.y() );
171 startPoint = QPointF( at.x(), topRight.y() );
176 endPoint = QPointF( at.x(), bottomLeft.y() );
178 endPoint = QPointF( topRight.x(), at.y() );
182 const QRectF ellipseMarker = QRectF( at.x() - markerSize.width() / 2,
183 at.y() - markerSize.height() / 2,
184 markerSize.width(), markerSize.height() );
186 QPointF startMarker[3];
188 startMarker[0] = startPoint + QPointF( 0, markerSize.height() / 2 );
189 startMarker[1] = startPoint + QPointF( markerSize.width() / 2, 0 );
190 startMarker[2] = startPoint - QPointF( 0, markerSize.height() / 2 );
192 startMarker[0] = startPoint + QPointF( 0, markerSize.height() / 2 );
193 startMarker[1] = startPoint + QPointF( markerSize.width() / 2, 0 );
194 startMarker[2] = startPoint - QPointF( markerSize.width() / 2, 0 );
197 QPointF endMarker[3];
200 endMarker[0] = endPoint + QPointF( markerSize.width() / 2, 0 );
201 endMarker[1] = endPoint - QPointF( 0, markerSize.height() / 2 );
202 endMarker[2] = endPoint - QPointF( markerSize.width() / 2, 0 );
204 endMarker[0] = endPoint + QPointF( 0, markerSize.width() / 2 );
205 endMarker[1] = endPoint - QPointF( 0, markerSize.height() / 2 );
206 endMarker[2] = endPoint - QPointF( markerSize.width() / 2, 0 );
209 QPointF topLeft = startPoint;
210 QPointF bottomRightOffset = endPoint - topLeft;
211 QSizeF size( bottomRightOffset.x(), bottomRightOffset.y() );
212 QRectF area( topLeft, size );
214 PainterSaver painterSaver( ctx->
painter() );
216 ctx->
painter()->setBrush( QBrush() );
217 ctx->
painter()->drawLine( markerPoint, startPoint );
218 ctx->
painter()->drawLine( markerPoint, endPoint );
224 ctx->
painter()->drawEllipse( ellipseMarker );
228 ctx->
painter()->drawPolygon( startMarker, 3 );
229 ctx->
painter()->drawPolygon( endMarker, 3 );
236 if (
Plotter *plotter = qobject_cast< Plotter* >( diagram ) ) {
237 return plotter->threeDLineAttributes( index );
238 }
else if (
LineDiagram *lineDiagram = qobject_cast< LineDiagram* >( diagram ) ) {
239 return lineDiagram->threeDLineAttributes( index );
247 if (
Plotter *plotter = qobject_cast< Plotter* >( diagram ) ) {
248 return plotter->valueTrackerAttributes( index );
249 }
else if (
LineDiagram *lineDiagram = qobject_cast< LineDiagram* >( diagram ) ) {
250 return lineDiagram->valueTrackerAttributes( index );
256 void paintObject ( AbstractDiagram::Private *diagramPrivate,
PaintContext* ctx,
const QBrush& brush,
const QPen& pen,
const QPolygonF& points )
259 SplineDirection splineDirection = NormalSplineDirection;
261 if ( LineDiagram::Private* lineDiagram = dynamic_cast<LineDiagram::Private*>( diagramPrivate ) ) {
262 tension = lineDiagram->tension;
263 Q_ASSERT(dynamic_cast<CartesianCoordinatePlane*>(ctx->
coordinatePlane()));
268 if ( qFuzzyIsNull(tension) ) {
271 paintSpline( ctx, brush, pen, points, tension, splineDirection );
276 const LabelPaintCache& lpc,
const LineAttributesInfoList& lineList )
280 const PainterSaver painterSaver( ctx->
painter() );
286 KDAB_FOREACH (
const LineAttributesInfo& lineInfo, lineList ) {
287 const QModelIndex& index = lineInfo.index;
292 lineInfo.nextValue, td, &diagramPrivate->reverseMapper );
294 const QBrush brush( diagram->
brush( index ) );
295 const QPen pen( diagram->
pen( index ) );
301 if (pen.style() != Qt::NoPen)
302 diagramPrivate->reverseMapper.addLine( lineInfo.index.row(), lineInfo.index.column(),
303 lineInfo.value, lineInfo.nextValue );
305 if ( points.count() && points.last() == lineInfo.value && curBrush == brush && curPen == pen ) {
309 if ( points.count() ) {
310 paintObject( diagramPrivate, ctx, curBrush, curPen, points );
315 points << lineInfo.value;
317 points << lineInfo.nextValue;
320 if ( points.count() ) {
322 paintObject( diagramPrivate, ctx, curBrush, curPen, points );
325 KDAB_FOREACH (
const LineAttributesInfo& lineInfo, lineList ) {
333 diagramPrivate->paintDataValueTextsAndMarkers( ctx, lpc,
true );
341 for (
int i = 0; i < areas.count(); ++i )
343 const QPolygonF& p = areas[ i ];
344 path.addPolygon( p );
345 diagramPrivate->reverseMapper.addPolygon( index.row(), index.column(), p );
350 QBrush trans = diagram->
brush( index );
352 trans = threeDAttrs.
threeDBrush( trans, path.boundingRect() );
354 QColor transColor = trans.color();
355 transColor.setAlpha( opacity );
356 trans.setColor(transColor);
357 QPen indexPen = diagram->
pen(index);
358 indexPen.setBrush( trans );
359 const PainterSaver painterSaver( ctx->
painter() );
363 ctx->
painter()->setBrush( trans );
365 ctx->
painter()->drawPath( path );
373 for (
int i = 0; i < areas.count(); ++i )
379 QBrush trans = diagram->
brush( index );
380 QColor transColor = trans.color();
381 transColor.setAlpha( opacity );
382 trans.setColor( transColor );
383 QPen indexPen = diagram->
pen( index );
384 indexPen.setBrush( trans );
385 const PainterSaver painterSaver( ctx->
painter() );
389 ctx->
painter()->setBrush( trans );
391 ctx->
painter()->drawPath( path );
bool isVerticalRangeReversed() const
void paintElements(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const LabelPaintCache &lpc, const LineAttributesInfoList &lineList)
const QPointF project(const QPointF &point, const ThreeDLineAttributes &tdAttributes)
virtual const QPointF translate(const QPointF &diagramPoint) const =0
Translate the given point in value space coordinates to a position in pixel space.
AbstractCoordinatePlane * coordinatePlane() const
static ValueTrackerAttributes valueTrackerAttributes(AbstractDiagram *diagram, const QModelIndex &index)
QPainter * painter() const
QBrush markerBrush() const
Plotter defines a diagram type plotting two-dimensional data.
AbstractDiagram defines the interface for diagram classes.
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
bool isHorizontalRangeReversed() const
The ReverseMapper stores information about objects on a chart and their respective model indexes...
uint lineXRotation() const
void paintAreas(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const QModelIndex &index, const QList< QPolygonF > &areas, uint opacity)
LineDiagram defines a common line diagram.
bool antiAliasing() const
Cell-specific attributes regarding value tracking.
Stores information about painting diagrams.
uint lineYRotation() const
void paintObject(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const QBrush &brush, const QPen &pen, const QPolygonF &points)
Qt::Orientations orientations() const
QPen pen() const
Retrieve the pen to be used for painting datapoints globally.
virtual QBrush threeDBrush(const QBrush &brush, const QRectF &rect) const
DataDimensionsList gridDimensionsList()
Returns the dimensions used for drawing the grid lines.
void addPolygon(int row, int column, const QPolygonF &polygon)
void paintPolyline(PaintContext *ctx, const QBrush &brush, const QPen &pen, const QPolygonF &points)
static QPen scalePen(const QPen &pen)
void paintValueTracker(PaintContext *ctx, const ValueTrackerAttributes &vt, const QPointF &at)
Cartesian coordinate plane.
void paintThreeDLines(PaintContext *ctx, AbstractDiagram *diagram, const QModelIndex &index, const QPointF &from, const QPointF &to, const ThreeDLineAttributes &tdAttributes, ReverseMapper *reverseMapper)
QBrush arrowBrush() const
void paintSpline(PaintContext *ctx, const QBrush &brush, const QPen &pen, const QPolygonF &points, qreal tension, SplineDirection splineDirection)
static ThreeDLineAttributes threeDLineAttributes(AbstractDiagram *diagram, const QModelIndex &index)
QSizeF markerSize() const
A set of 3D line attributes.
QPainterPath fitPoints(const QPolygonF &points, qreal tension, SplineDirection splineDirection)