24 #include "KDChartPolarDiagram_p.h" 28 #include "KDChartPainterSaver_p.h" 30 #include <KDABLibFakes> 34 PolarDiagram::Private::Private() :
35 rotateCircularLabels( false ),
36 closeDatasets( false )
40 PolarDiagram::Private::~Private() {}
55 void PolarDiagram::init()
99 const int rowCount = model()->rowCount(rootIndex());
100 const int colCount = model()->columnCount(rootIndex());
102 qreal xMax = colCount;
103 qreal yMin = 0, yMax = 0;
104 for (
int iCol=0; iCol<colCount; ++iCol ) {
105 for (
int iRow=0; iRow<
rowCount; ++iRow ) {
106 qreal value = model()->data( model()->index( iRow, iCol, rootIndex() ) ).toReal();
107 yMax = qMax( yMax, value );
108 yMin = qMin( yMin, value );
111 QPointF bottomLeft ( QPointF( xMin, yMin ) );
112 QPointF topRight ( QPointF( xMax, yMax ) );
120 QPainter painter ( viewport() );
140 qreal dummy1, dummy2;
141 paint( ctx,
true, dummy1, dummy2 );
142 paint( ctx,
false, dummy1, dummy2 );
146 bool calculateListAndReturnScale,
147 qreal& newZoomX, qreal& newZoomY )
153 d->reverseMapper.clear();
155 const int rowCount = model()->rowCount( rootIndex() );
156 const int colCount = model()->columnCount( rootIndex() );
158 if ( calculateListAndReturnScale ) {
160 d->labelPaintCache.clear();
162 for (
int iCol = 0; iCol < colCount; ++iCol ) {
163 for (
int iRow=0; iRow <
rowCount; ++iRow ) {
164 QModelIndex index = model()->index( iRow, iCol, rootIndex() );
165 const qreal value = model()->data( index ).toReal();
167 QPointF( value, iRow ) ) + ctx->
rectangle().topLeft();
177 if (
d->labelPaintCache.paintReplay.count() ) {
179 const qreal oldZoomX = newZoomX;
180 const qreal oldZoomY = newZoomY;
183 d->paintDataValueTextsAndMarkers( ctx,
d->labelPaintCache,
true,
true, &txtRectF );
184 const QRect txtRect = txtRectF.toRect();
186 const qreal gapX = qMin( txtRect.left() - curRect.left(), curRect.right() - txtRect.right() );
187 const qreal gapY = qMin( txtRect.top() - curRect.top(), curRect.bottom() - txtRect.bottom() );
189 newZoomX = oldZoomX * ( 1.0 + ( gapX - 1.0 ) / curRect.width() );
192 newZoomY = oldZoomY * ( 1.0 + ( gapY - 1.0 ) / curRect.height() );
197 for (
int iCol = 0; iCol < colCount; ++iCol ) {
204 for (
int iRow = 0; iRow <
rowCount; ++iRow ) {
205 QModelIndex index = model()->index( iRow, iCol, rootIndex() );
206 const qreal value = model()->data( index ).toReal();
209 polygon.append( point );
214 polygon.append( polygon.first() );
217 PainterSaver painterSaver( ctx->
painter() );
218 ctx->
painter()->setRenderHint ( QPainter::Antialiasing );
219 ctx->
painter()->setBrush( brush );
221 if ( p.style() != Qt::NoPen )
224 ctx->
painter()->drawPolyline( polygon );
227 d->paintDataValueTextsAndMarkers( ctx,
d->labelPaintCache,
true );
238 return model()->rowCount(rootIndex());
244 return model() ? model()->rowCount(rootIndex()) : 0.0;
256 qWarning() <<
"Deprecated PolarDiagram::setZeroDegreePosition() called, setting ignored.";
261 qWarning() <<
"Deprecated PolarDiagram::zeroDegreePosition() called.";
272 return d->rotateCircularLabels;
282 return d->closeDatasets;
286 bool showDelimiters )
288 d->showDelimitersAtPosition[position.
value()] = showDelimiters;
294 d->showLabelsAtPosition[position.
value()] = showLabels;
299 return d->showDelimitersAtPosition[position.
value()];
304 return d->showLabelsAtPosition[position.
value()];
static const Position & East
void setCloseDatasets(bool closeDatasets)
Close each of the data series by connecting the last point to its respective start point...
KDChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
const QRectF rectangle() const
void setPainter(QPainter *painter)
virtual bool checkInvariants(bool justReturnTheStatus=false) const
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
static const Position & South
QPainter * painter() const
static const Position & Center
qreal numberOfGridRings() const override
[reimplemented]
virtual void paintPolarMarkers(PaintContext *ctx, const QPolygonF &polygon)
bool closeDatasets() const
PolarDiagram defines a common polar diagram.
void setRotateCircularLabels(bool rotateCircularLabels)
AbstractCoordinatePlane * coordinatePlane() const
The coordinate plane associated with the diagram.
void setZeroDegreePosition(int degrees)
PolarDiagram(QWidget *parent=0, PolarCoordinatePlane *plane=0)
const QPair< QPointF, QPointF > calculateDataBoundaries() const override
[reimplemented]
bool rotateCircularLabels() const
Base class for diagrams based on a polar coordinate system.
void resizeEvent(QResizeEvent *) override
int zeroDegreePosition() const
virtual PolarDiagram * clone() const
Creates an exact copy of this diagram.
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
static const Position & Unknown
qreal valueTotals() const override
[reimplemented]
bool showLabelsAtPosition(Position position) const
bool showDelimitersAtPosition(Position position) const
void paint(PaintContext *paintContext) override
[reimplemented]
static const Position & NorthWest
void paintEvent(QPaintEvent *) override
static const Position & West
void setShowDelimitersAtPosition(Position position, bool showDelimiters)
Stores information about painting diagrams.
Stores the absolute target points of a Position.
virtual qreal zoomFactorY() const
static const Position & NorthEast
void resize(const QSizeF &area) override
[reimplemented]
static const Position & North
qreal numberOfValuesPerDataset() const override
[reimplemented]
static QPen scalePen(const QPen &pen)
Defines a position, using compass terminology.
static const Position & SouthEast
void setShowLabelsAtPosition(Position position, bool showLabels)
void setRectangle(const QRectF &rect)
static const Position & Floating
virtual qreal zoomFactorX() const
static const Position & SouthWest