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 )
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 ) );
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 ) );
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 )
260 if ( LineDiagram::Private* lineDiagram = dynamic_cast<LineDiagram::Private*>( diagramPrivate ) ) {
261 tension = lineDiagram->tension;
264 if ( qFuzzyIsNull(tension) ) {
272 const LabelPaintCache& lpc,
const LineAttributesInfoList& lineList )
276 const PainterSaver painterSaver( ctx->
painter() );
282 KDAB_FOREACH (
const LineAttributesInfo& lineInfo, lineList ) {
283 const QModelIndex& index = lineInfo.index;
288 lineInfo.nextValue, td, &diagramPrivate->reverseMapper );
290 const QBrush brush( diagram->
brush( index ) );
291 const QPen pen( diagram->
pen( index ) );
297 if (pen.style() != Qt::NoPen)
298 diagramPrivate->reverseMapper.addLine( lineInfo.index.row(), lineInfo.index.column(),
299 lineInfo.value, lineInfo.nextValue );
301 if ( points.count() && points.last() == lineInfo.value && curBrush == brush && curPen == pen ) {
305 if ( points.count() ) {
306 paintObject( diagramPrivate, ctx, curBrush, curPen, points );
311 points << lineInfo.value;
313 points << lineInfo.nextValue;
316 if ( points.count() ) {
318 paintObject( diagramPrivate, ctx, curBrush, curPen, points );
321 KDAB_FOREACH (
const LineAttributesInfo& lineInfo, lineList ) {
329 diagramPrivate->paintDataValueTextsAndMarkers( ctx, lpc,
true );
337 for (
int i = 0; i < areas.count(); ++i )
339 const QPolygonF& p = areas[ i ];
340 path.addPolygon( p );
341 diagramPrivate->reverseMapper.addPolygon( index.row(), index.column(), p );
346 QBrush trans = diagram->
brush( index );
348 trans = threeDAttrs.
threeDBrush( trans, path.boundingRect() );
350 QColor transColor = trans.color();
351 transColor.setAlpha( opacity );
352 trans.setColor(transColor);
353 QPen indexPen = diagram->
pen(index);
354 indexPen.setBrush( trans );
355 const PainterSaver painterSaver( ctx->
painter() );
359 ctx->
painter()->setBrush( trans );
361 ctx->
painter()->drawPath( path );
369 for (
int i = 0; i < areas.count(); ++i )
375 QBrush trans = diagram->
brush( index );
376 QColor transColor = trans.color();
377 transColor.setAlpha( opacity );
378 trans.setColor( transColor );
379 QPen indexPen = diagram->
pen( index );
380 indexPen.setBrush( trans );
381 const PainterSaver painterSaver( ctx->
painter() );
385 ctx->
painter()->setBrush( trans );
387 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)
QPainterPath fitPoints(const QPolygonF &points, qreal tension)
LineDiagram defines a common line diagram.
void paintSpline(PaintContext *ctx, const QBrush &brush, const QPen &pen, const QPolygonF &points, qreal tension)
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
static ThreeDLineAttributes threeDLineAttributes(AbstractDiagram *diagram, const QModelIndex &index)
QSizeF markerSize() const
A set of 3D line attributes.