24 #include "KDChartPolarDiagram_p.h"
28 #include "KDChartPainterSaver_p.h"
30 #include <KDABLibFakes>
32 using namespace KDChart;
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()];