9#include "KChartPolarDiagram.h"
10#include "KChartPolarDiagram_p.h"
12#include "KChartPaintContext.h"
13#include "KChartPainterSaver_p.h"
14#include "KChartMath_p.h"
20PolarDiagram::Private::Private() :
21 rotateCircularLabels( false ),
22 closeDatasets( false )
26PolarDiagram::Private::~Private() {}
36PolarDiagram::~PolarDiagram()
41void PolarDiagram::init()
43 setShowDelimitersAtPosition( Position::Unknown,
false );
44 setShowDelimitersAtPosition( Position::Center,
false );
45 setShowDelimitersAtPosition( Position::NorthWest,
false );
46 setShowDelimitersAtPosition( Position::North,
true );
47 setShowDelimitersAtPosition( Position::NorthEast,
false );
48 setShowDelimitersAtPosition( Position::West,
false );
49 setShowDelimitersAtPosition( Position::East,
false );
50 setShowDelimitersAtPosition( Position::SouthWest,
false );
51 setShowDelimitersAtPosition( Position::South,
true );
52 setShowDelimitersAtPosition( Position::SouthEast,
false );
53 setShowDelimitersAtPosition( Position::Floating,
false );
55 setShowLabelsAtPosition( Position::Unknown,
false );
56 setShowLabelsAtPosition( Position::Center,
false );
57 setShowLabelsAtPosition( Position::NorthWest,
false );
58 setShowLabelsAtPosition( Position::North,
true );
59 setShowLabelsAtPosition( Position::NorthEast,
false );
60 setShowLabelsAtPosition( Position::West,
false );
61 setShowLabelsAtPosition( Position::East,
false );
62 setShowLabelsAtPosition( Position::SouthWest,
false );
63 setShowLabelsAtPosition( Position::South,
true );
64 setShowLabelsAtPosition( Position::SouthEast,
false );
65 setShowLabelsAtPosition( Position::Floating,
false );
72 newDiagram->d->showDelimitersAtPosition = d->showDelimitersAtPosition;
73 newDiagram->d->showLabelsAtPosition = d->showLabelsAtPosition;
74 newDiagram->d->rotateCircularLabels = d->rotateCircularLabels;
75 newDiagram->d->closeDatasets = d->closeDatasets;
81 if ( !checkInvariants(
true) )
return QPair<QPointF, QPointF>(
QPointF( 0, 0 ),
QPointF( 0, 0 ) );
85 qreal xMax = colCount;
86 qreal yMin = 0, yMax = 0;
87 for (
int iCol=0; iCol<colCount; ++iCol ) {
88 for (
int iRow=0; iRow< rowCount; ++iRow ) {
90 yMax = qMax( yMax, value );
91 yMin = qMin( yMin, value );
96 return QPair<QPointF, QPointF> ( bottomLeft, topRight );
105 ctx.setPainter ( &painter );
123 qreal dummy1, dummy2;
124 paint( ctx,
true, dummy1, dummy2 );
125 paint( ctx,
false, dummy1, dummy2 );
129 bool calculateListAndReturnScale,
130 qreal& newZoomX, qreal& newZoomY )
134 if ( !checkInvariants(
true) )
136 d->reverseMapper.clear();
141 if ( calculateListAndReturnScale ) {
143 d->labelPaintCache.clear();
145 for (
int iCol = 0; iCol < colCount; ++iCol ) {
146 for (
int iRow=0; iRow < rowCount; ++iRow ) {
152 d->addLabel( &d->labelPaintCache, index,
nullptr,
PositionPoints( point ),
153 Position::Center, Position::Center, value );
160 if ( d->labelPaintCache.paintReplay.count() ) {
162 const qreal oldZoomX = newZoomX;
163 const qreal oldZoomY = newZoomY;
166 d->paintDataValueTextsAndMarkers( ctx, d->labelPaintCache,
true,
true, &txtRectF );
169 const qreal gapX = qMin( txtRect.
left() - curRect.
left(), curRect.
right() - txtRect.
right() );
170 const qreal gapY = qMin( txtRect.
top() - curRect.
top(), curRect.
bottom() - txtRect.
bottom() );
172 newZoomX = oldZoomX * ( 1.0 + ( gapX - 1.0 ) / curRect.
width() );
175 newZoomY = oldZoomY * ( 1.0 + ( gapY - 1.0 ) / curRect.
height() );
180 for (
int iCol = 0; iCol < colCount; ++iCol ) {
185 QBrush brush = d->datasetAttrs( iCol, KChart::DatasetBrushRole ).value<
QBrush>();
187 for (
int iRow = 0; iRow < rowCount; ++iRow ) {
192 polygon.append( point );
195 if ( closeDatasets() && !polygon.isEmpty() ) {
197 polygon.append( polygon.first() );
200 PainterSaver painterSaver( ctx->painter() );
203 QPen p = d->datasetAttrs( iCol, KChart::DatasetPenRole ).value<
QPen >();
206 ctx->painter()->
setPen( PrintingParameters::scalePen( p ) );
210 d->paintDataValueTextsAndMarkers( ctx, d->labelPaintCache,
true );
240 qWarning() <<
"Deprecated PolarDiagram::setZeroDegreePosition() called, setting ignored.";
245 qWarning() <<
"Deprecated PolarDiagram::zeroDegreePosition() called.";
249void PolarDiagram::setRotateCircularLabels(
bool rotateCircularLabels )
251 d->rotateCircularLabels = rotateCircularLabels;
254bool PolarDiagram::rotateCircularLabels()
const
256 return d->rotateCircularLabels;
261 d->closeDatasets = closeDatasets;
264bool PolarDiagram::closeDatasets()
const
266 return d->closeDatasets;
269void PolarDiagram::setShowDelimitersAtPosition(
Position position,
270 bool showDelimiters )
272 d->showDelimitersAtPosition[position.
value()] = showDelimiters;
275void PolarDiagram::setShowLabelsAtPosition(
Position position,
278 d->showLabelsAtPosition[position.
value()] = showLabels;
281bool PolarDiagram::showDelimitersAtPosition(
Position position )
const
283 return d->showDelimitersAtPosition[position.
value()];
286bool PolarDiagram::showLabelsAtPosition(
Position position )
const
288 return d->showLabelsAtPosition[position.
value()];
virtual const QPointF translate(const QPointF &diagramPoint) const =0
Translate the given point in value space coordinates to a position in pixel space.
QRect geometry() const override
pure virtual in QLayoutItem
virtual qreal zoomFactorY() const
virtual qreal zoomFactorX() const
AbstractCoordinatePlane * coordinatePlane() const
The coordinate plane associated with the diagram.
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
Base class for diagrams based on a polar coordinate system.
Stores information about painting diagrams.
PolarDiagram defines a common polar diagram.
int zeroDegreePosition() const
virtual PolarDiagram * clone() const
Creates an exact copy of this diagram.
void paint(PaintContext *paintContext) override
\reimpl
qreal numberOfValuesPerDataset() const override
\reimpl
void setZeroDegreePosition(int degrees)
void resize(const QSizeF &area) override
\reimpl
void setCloseDatasets(bool closeDatasets)
Close each of the data series by connecting the last point to its respective start point.
qreal valueTotals() const override
\reimpl
const QPair< QPointF, QPointF > calculateDataBoundaries() const override
\reimpl
qreal numberOfGridRings() const override
\reimpl
Stores the absolute target points of a Position.
Defines a position, using compass terminology.
KChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
virtual int columnCount(const QModelIndex &parent) const const=0
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual int rowCount(const QModelIndex &parent) const const=0
QAbstractItemModel * model() const const
QModelIndex rootIndex() const const
void drawPolyline(const QPoint *points, int pointCount)
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
Qt::PenStyle style() const const
QRect toRect() const const
QPointF topLeft() const const
qreal toReal(bool *ok) const const