1
/****************************************************************************
2
** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB. All rights reserved.
4
** This file is part of the KD Chart library.
6
** Licensees holding valid commercial KD Chart licenses may use this file in
7
** accordance with the KD Chart Commercial License Agreement provided with
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 and version 3 as published by the
13
** Free Software Foundation and appearing in the file LICENSE.GPL included.
15
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18
** Contact info@kdab.com if any conditions of this licensing are not
21
**********************************************************************/
23
#include "KDChartPolarGrid.h"
24
#include "KDChartPaintContext.h"
25
#include "KDChartPolarDiagram.h"
26
#include "KDChartPieDiagram.h"
27
#include "KDChartPrintingParameters.h"
31
#include <KDABLibFakes>
33
using namespace KDChart;
36
DataDimensionsList PolarGrid::calculateGrid(
37
const DataDimensionsList& rawDataDimensions ) const
39
qDebug("Calling PolarGrid::calculateGrid()");
42
//FIXME(khz): do the real calculation
44
l = rawDataDimensions;
50
void PolarGrid::drawGrid( PaintContext* context )
52
// if ( d->coordinateTransformations.size () <= 0 ) return;
54
const QBrush backupBrush( context->painter()->brush() );
55
context->painter()->setBrush( QBrush() );
56
PolarCoordinatePlane* plane = dynamic_cast<PolarCoordinatePlane*>(context->coordinatePlane());
57
Q_ASSERT_X ( plane, "PolarGrid::drawGrid",
58
"Bad function call: PaintContext::coodinatePlane() NOT a polar plane." );
60
const GridAttributes gridAttrsCircular( plane->gridAttributes( true ) );
61
const GridAttributes gridAttrsSagittal( plane->gridAttributes( false ) );
64
if ( !gridAttrsCircular.isGridVisible() && !gridAttrsSagittal.isGridVisible() ) return;
67
// FIXME: we paint the rulers to the settings of the first diagram for now:
68
AbstractPolarDiagram* dgr = dynamic_cast<AbstractPolarDiagram*> (plane->diagrams().first() );
69
Q_ASSERT ( dgr ); // only polar diagrams are allowed here
72
// Do not draw a grid for pie diagrams
73
if( dynamic_cast<PieDiagram*> (plane->diagrams().first() ) ) return;
76
context->painter()->setPen ( PrintingParameters::scalePen( QColor ( Qt::lightGray ) ) );
77
const double min = dgr->dataBoundaries().first.y();
78
QPointF origin = plane->translate( QPointF( min, 0 ) ) + context->rectangle().topLeft();
79
//qDebug() << "origin" << origin;
81
const double r = qAbs( min ) + dgr->dataBoundaries().second.y(); // use the full extents
83
if ( gridAttrsSagittal.isGridVisible() ){
84
const int numberOfSpokes = ( int ) ( 360 / plane->angleUnit() );
85
for ( int i = 0; i < numberOfSpokes ; ++i ) {
86
context->painter()->drawLine( origin, plane->translate( QPointF( r - qAbs( min ), i ) ) + context->rectangle().topLeft() );
90
if ( gridAttrsCircular.isGridVisible() )
92
const qreal startPos = plane->startPosition();
93
plane->setStartPosition( 0.0 );
94
const int numberOfGridRings = ( int )dgr->numberOfGridRings();
95
for ( int j = 0; j < numberOfGridRings; ++j ) {
96
const double rad = min - ( ( j + 1) * r / numberOfGridRings );
102
QPointF topLeftPoint;
103
QPointF bottomRightPoint;
105
topLeftPoint = plane->translate( QPointF( rad, 0 ) );
106
topLeftPoint.setX( plane->translate( QPointF( rad, 90 / plane->angleUnit() ) ).x() );
107
bottomRightPoint = plane->translate( QPointF( rad, 180 / plane->angleUnit() ) );
108
bottomRightPoint.setX( plane->translate( QPointF( rad, 270 / plane->angleUnit() ) ).x() );
110
rect.setTopLeft( topLeftPoint + context->rectangle().topLeft() );
111
rect.setBottomRight( bottomRightPoint + context->rectangle().topLeft() );
113
context->painter()->drawEllipse( rect );
115
plane->setStartPosition( startPos );
117
context->painter()->setBrush( backupBrush );