KD Chart API Documentation 3.0
Loading...
Searching...
No Matches
KDChartPolarGrid.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
11#include "KDChartPolarGrid.h"
12#include "KDChartPaintContext.h"
13#include "KDChartPieDiagram.h"
14#include "KDChartPolarDiagram.h"
16
17#include <QPainter>
18
19#include <KDABLibFakes>
20
21using namespace KDChart;
22
23DataDimensionsList PolarGrid::calculateGrid(
24 const DataDimensionsList &rawDataDimensions) const
25{
26 qDebug("Calling PolarGrid::calculateGrid()");
27 Q_ASSERT_X(rawDataDimensions.count() == 2, "PolarGrid::calculateGrid",
28 "calculateGrid() expects a list with exactly two entries.");
29 Q_ASSERT_X(dynamic_cast<PolarCoordinatePlane *>(mPlane), "PolarGrid::calculateGrid",
30 "PaintContext::calculatePlane() called, but no polar plane set.");
31
33
34 // FIXME(khz): do the real calculation
35
36 l = rawDataDimensions;
37
38 return l;
39}
40
42{
43 // if ( d->coordinateTransformations.size () <= 0 ) return;
44
45 const QBrush backupBrush(context->painter()->brush());
46 context->painter()->setBrush(QBrush());
47 auto *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())
56 return;
57 // qDebug() << "A";
58
59 // FIXME: we paint the rulers to the settings of the first diagram for now:
60 AbstractPolarDiagram *dgr = dynamic_cast<AbstractPolarDiagram *>(plane->diagrams().first());
61 Q_ASSERT(dgr); // only polar diagrams are allowed here
62
63 // Do not draw a grid for pie diagrams
64 if (dynamic_cast<PieDiagram *>(plane->diagrams().first()))
65 return;
66
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 const qreal startPos = plane->startPosition();
83 plane->setStartPosition(0.0);
84 const int numberOfGridRings = ( int )dgr->numberOfGridRings();
85 for (int j = 0; j < numberOfGridRings; ++j) {
86 const qreal rad = min - ((j + 1) * r / numberOfGridRings);
87
88 if (rad == 0)
89 continue;
90
91 QRectF rect;
92 QPointF topLeftPoint;
93 QPointF bottomRightPoint;
94
95 topLeftPoint = plane->translate(QPointF(rad, 0));
96 topLeftPoint.setX(plane->translate(QPointF(rad, 90 / plane->angleUnit())).x());
97 bottomRightPoint = plane->translate(QPointF(rad, 180 / plane->angleUnit()));
98 bottomRightPoint.setX(plane->translate(QPointF(rad, 270 / plane->angleUnit())).x());
99
100 rect.setTopLeft(topLeftPoint + context->rectangle().topLeft());
101 rect.setBottomRight(bottomRightPoint + context->rectangle().topLeft());
102
103 context->painter()->drawEllipse(rect);
104 }
105 plane->setStartPosition(startPos);
106 }
107 context->painter()->setBrush(backupBrush);
108}
const QPair< QPointF, QPointF > dataBoundaries() const
Return the bottom left and top right data point, that the diagram will display (unless the grid adjus...
AbstractCoordinatePlane * mPlane
Base class for diagrams based on a polar coordinate system.
virtual qreal numberOfGridRings() const =0
A set of attributes controlling the appearance of grids.
Stores information about painting diagrams.
const QRectF rectangle() const
AbstractCoordinatePlane * coordinatePlane() const
PieDiagram defines a common pie diagram.
void drawGrid(PaintContext *context) override
static QPen scalePen(const QPen &pen)
int count(const T &value) const const
const QBrush & brush() const const
void drawEllipse(const QRectF &rectangle)
void drawLine(const QLineF &line)
void setBrush(const QBrush &brush)
void setPen(const QColor &color)
void setX(qreal x)
void setBottomRight(const QPointF &position)
void setTopLeft(const QPointF &position)
QPointF topLeft() const const
lightGray

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Fri Feb 23 2024 00:02:59 for KD Chart API Documentation by doxygen 1.9.8