KChart

KChartPolarGrid.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "KChartPolarGrid.h"
10
11#include "KChartPaintContext.h"
12#include "KChartPolarDiagram.h"
13#include "KChartPieDiagram.h"
14#include "KChartPrintingParameters.h"
15#include "KChartMath_p.h"
16
17#include <QPainter>
18
19using namespace KChart;
20
21
22DataDimensionsList PolarGrid::calculateGrid(
23 const DataDimensionsList& rawDataDimensions ) const
24{
25 qDebug("Calling PolarGrid::calculateGrid()");
26 Q_ASSERT_X( rawDataDimensions.count() == 2, "PolarGrid::calculateGrid",
27 "calculateGrid() expects a list with exactly two entries." );
28 Q_ASSERT_X( dynamic_cast< PolarCoordinatePlane* >( mPlane ), "PolarGrid::calculateGrid",
29 "PaintContext::calculatePlane() called, but no polar plane set." );
30
32
33 //FIXME(khz): do the real calculation
34
35 l = rawDataDimensions;
36
37 return l;
38}
39
40
42{
43// if ( d->coordinateTransformations.size () <= 0 ) return;
44
45 const QBrush backupBrush( context->painter()->brush() );
46 context->painter()->setBrush( QBrush() );
47 PolarCoordinatePlane* plane = dynamic_cast<PolarCoordinatePlane*>(context->coordinatePlane());
48 Q_ASSERT_X ( plane, "PolarGrid::drawGrid",
49 "Bad function call: PaintContext::coodinatePlane() NOT a polar plane." );
50
51 const GridAttributes gridAttrsCircular( plane->gridAttributes( true ) );
52 const GridAttributes gridAttrsSagittal( plane->gridAttributes( false ) );
53
54 //qDebug() << "OK:";
55 if ( !gridAttrsCircular.isGridVisible() && !gridAttrsSagittal.isGridVisible() ) return;
56 //qDebug() << "A";
57
58 // FIXME: we paint the rulers to the settings of the first diagram for now:
59 AbstractPolarDiagram* dgr = dynamic_cast<AbstractPolarDiagram*> (plane->diagrams().first() );
60 Q_ASSERT ( dgr ); // only polar diagrams are allowed here
61
62
63 // Do not draw a grid for pie diagrams
64 if ( dynamic_cast<PieDiagram*> (plane->diagrams().first() ) ) return;
65
66
67 context->painter()->setPen ( PrintingParameters::scalePen( QColor ( Qt::lightGray ) ) );
68 const qreal min = dgr->dataBoundaries().first.y();
69 QPointF origin = plane->translate( QPointF( min, 0 ) ) + context->rectangle().topLeft();
70 //qDebug() << "origin" << origin;
71
72 const qreal r = qAbs( min ) + dgr->dataBoundaries().second.y(); // use the full extents
73
74 if ( gridAttrsSagittal.isGridVisible() ) {
75 const int numberOfSpokes = ( int ) ( 360 / plane->angleUnit() );
76 for ( int i = 0; i < numberOfSpokes ; ++i ) {
77 context->painter()->drawLine( origin, plane->translate( QPointF( r - qAbs( min ), i ) ) + context->rectangle().topLeft() );
78 }
79 }
80
81 if ( gridAttrsCircular.isGridVisible() )
82 {
83 const qreal startPos = plane->startPosition();
84 plane->setStartPosition( 0.0 );
85 const int numberOfGridRings = ( int )dgr->numberOfGridRings();
86 for ( int j = 0; j < numberOfGridRings; ++j ) {
87 const qreal rad = min - ( ( j + 1) * r / numberOfGridRings );
88
89 if ( rad == 0 )
90 continue;
91
92 QRectF rect;
93 QPointF topLeftPoint;
94 QPointF bottomRightPoint;
95
96 topLeftPoint = plane->translate( QPointF( rad, 0 ) );
97 topLeftPoint.setX( plane->translate( QPointF( rad, 90 / plane->angleUnit() ) ).x() );
98 bottomRightPoint = plane->translate( QPointF( rad, 180 / plane->angleUnit() ) );
99 bottomRightPoint.setX( plane->translate( QPointF( rad, 270 / plane->angleUnit() ) ).x() );
100
101 rect.setTopLeft( topLeftPoint + context->rectangle().topLeft() );
102 rect.setBottomRight( bottomRightPoint + context->rectangle().topLeft() );
103
104 context->painter()->drawEllipse( rect );
105 }
106 plane->setStartPosition( startPos );
107 }
108 context->painter()->setBrush( backupBrush );
109}
const QPair< QPointF, QPointF > dataBoundaries() const
Return the bottom left and top right data point, that the diagram will display (unless the grid adjus...
Base class for diagrams based on a polar coordinate system.
A set of attributes controlling the appearance of grids.
Stores information about painting diagrams.
PieDiagram defines a common pie diagram.
qreal startPosition() const
Retrieve the rotation of the coordinate plane.
const GridAttributes gridAttributes(bool circular) const
void setStartPosition(qreal degrees)
Specify the rotation of the coordinate plane.
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
void drawGrid(PaintContext *context) override
Doing the actual drawing.
qsizetype count() const const
T & first()
const QBrush & brush() const const
void drawEllipse(const QPoint &center, int rx, int ry)
void drawLine(const QLine &line)
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
void setX(qreal x)
qreal x() const const
void setBottomRight(const QPointF &position)
void setTopLeft(const QPointF &position)
QPointF topLeft() const const
lightGray
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.