24 #include "KDChartRadarDiagram_p.h"
28 #include "KDChartPainterSaver_p.h"
30 #include <KDABLibFakes>
32 using namespace KDChart;
34 RadarDiagram::Private::Private() :
35 closeDatasets( false ),
41 RadarDiagram::Private::~Private() {}
56 void RadarDiagram::init()
75 const int rowCount = model()->rowCount(rootIndex());
76 const int colCount = model()->columnCount(rootIndex());
78 qreal xMax = colCount;
79 qreal yMin = 0, yMax = 0;
80 for (
int iCol=0; iCol<colCount; ++iCol ) {
81 for (
int iRow=0; iRow<
rowCount; ++iRow ) {
82 qreal value = model()->data( model()->index( iRow, iCol, rootIndex() ) ).toReal();
83 yMax = qMax( yMax, value );
84 yMin = qMin( yMin, value );
87 QPointF bottomLeft ( QPointF( xMin, yMin ) );
88 QPointF topRight ( QPointF( xMax, yMax ) );
96 QPainter painter ( viewport() );
105 qreal dummy1, dummy2;
106 paint( ctx,
true, dummy1, dummy2 );
107 paint( ctx,
false, dummy1, dummy2 );
113 const qreal origResult = f.pointSizeF();
114 qreal result = origResult;
115 const QSizeF mySize = geometry.size();
116 if ( mySize.isNull() )
119 const QString t = text;
120 QFontMetrics fm( f );
123 const QSizeF textSize =
rotatedRect( fm.boundingRect( t ), ta.
rotation() ).normalized().size();
125 if ( textSize.height() <= mySize.height() && textSize.width() <= mySize.width() )
131 f.setPointSizeF( result );
132 fm = QFontMetrics( f );
138 QPointF result = plane.
translate( origin );
139 result -= sourceRect.topLeft();
140 result.setX( result.x() / sourceRect.width() * destRect.width() );
141 result.setY( result.y() / sourceRect.height() * destRect.height() );
142 result += destRect.topLeft();
148 d->reverseData = val;
152 return d->reverseData;
160 Polygon(
const QPolygonF &polygon,
const QBrush &brush,
const QPen &pen) : polygon(polygon), brush(brush), pen(pen) {}
164 bool calculateListAndReturnScale,
165 qreal& newZoomX, qreal& newZoomY )
171 d->reverseMapper.clear();
173 const int rowCount = model()->rowCount( rootIndex() );
174 const int colCount = model()->columnCount( rootIndex() );
185 fontRect.setSize( QSizeF( fontRect.width(), step / 2.0 ) );
187 QFont labelFont = ta.
font();
189 labelFont.setPointSizeF( labelFontSize );
190 const QFontMetricsF metric( labelFont );
191 const qreal labelHeight = metric.height();
196 destRect.setY( destRect.y() + 2 * labelHeight );
197 destRect.setHeight( destRect.height() - 4 * labelHeight );
200 if ( calculateListAndReturnScale ) {
204 d->labelPaintCache.clear();
206 for ( iCol=0; iCol < colCount; ++iCol ) {
207 for ( iRow=0; iRow <
rowCount; ++iRow ) {
208 QModelIndex index = model()->index( iRow, iCol, rootIndex() );
209 const qreal value = model()->data( index ).toReal();
220 if (
d->labelPaintCache.paintReplay.count() ) {
222 d->paintDataValueTextsAndMarkers( ctx,
d->labelPaintCache,
true,
true, &txtRectF );
223 const QRect txtRect = txtRectF.toRect();
225 const qreal gapX = qMin( txtRect.left() - curRect.left(), curRect.right() - txtRect.right() );
226 const qreal gapY = qMin( txtRect.top() - curRect.top(), curRect.bottom() - txtRect.bottom() );
230 newZoomX *= 1.0 + (gapX-1.0) / curRect.width();
232 newZoomY *= 1.0 + (gapY-1.0) / curRect.height();
239 for ( iCol=0; iCol < colCount; ++iCol ) {
246 for ( iRow=0; iRow <
rowCount; ++iRow ) {
247 QModelIndex index = model()->index( iRow, iCol, rootIndex() );
248 const qreal value = model()->data( index ).toReal();
250 polygon.append( point );
255 polygon.append( point0 );
259 if ( p.style() != Qt::NoPen )
266 if (
d->fillAlpha > 0.0) {
267 Q_FOREACH(
const Polygon& p, polygons) {
268 PainterSaver painterSaver( ctx->
painter() );
269 ctx->
painter()->setRenderHint ( QPainter::Antialiasing );
271 QColor c = br.color();
272 c.setAlphaF(
d->fillAlpha);
274 ctx->
painter()->setBrush( br );
275 ctx->
painter()->setPen( p.pen );
276 ctx->
painter()->drawPolygon( p.polygon );
281 Q_FOREACH(
const Polygon& p, polygons) {
282 PainterSaver painterSaver( ctx->
painter() );
283 ctx->
painter()->setRenderHint ( QPainter::Antialiasing );
284 ctx->
painter()->setBrush( p.brush );
285 ctx->
painter()->setPen( p.pen );
286 ctx->
painter()->drawPolyline( p.polygon );
289 d->paintDataValueTextsAndMarkers( ctx,
d->labelPaintCache,
true );
300 return model()->rowCount(rootIndex());
306 return model() ? model()->rowCount(rootIndex()) : 0.0;
322 return d->closeDatasets;
332 d->fillAlpha = alphaF;