~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to plugins/chartshape/kdchart/src/KDChartPolarGrid.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB.  All rights reserved.
 
3
**
 
4
** This file is part of the KD Chart library.
 
5
**
 
6
** Licensees holding valid commercial KD Chart licenses may use this file in
 
7
** accordance with the KD Chart Commercial License Agreement provided with
 
8
** the Software.
 
9
**
 
10
**
 
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.
 
14
**
 
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.
 
17
**
 
18
** Contact info@kdab.com if any conditions of this licensing are not
 
19
** clear to you.
 
20
**
 
21
**********************************************************************/
 
22
 
 
23
#include "KDChartPolarGrid.h"
 
24
#include "KDChartPaintContext.h"
 
25
#include "KDChartPolarDiagram.h"
 
26
#include "KDChartPieDiagram.h"
 
27
#include "KDChartPrintingParameters.h"
 
28
 
 
29
#include <QPainter>
 
30
 
 
31
#include <KDABLibFakes>
 
32
 
 
33
using namespace KDChart;
 
34
 
 
35
 
 
36
DataDimensionsList PolarGrid::calculateGrid(
 
37
    const DataDimensionsList& rawDataDimensions ) const
 
38
{
 
39
    qDebug("Calling PolarGrid::calculateGrid()");
 
40
    DataDimensionsList l;
 
41
 
 
42
    //FIXME(khz): do the real calculation
 
43
 
 
44
    l = rawDataDimensions;
 
45
 
 
46
    return l;
 
47
}
 
48
 
 
49
 
 
50
void PolarGrid::drawGrid( PaintContext* context )
 
51
{
 
52
//    if ( d->coordinateTransformations.size () <= 0 ) return;
 
53
 
 
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." );
 
59
 
 
60
    const GridAttributes gridAttrsCircular( plane->gridAttributes( true ) );
 
61
    const GridAttributes gridAttrsSagittal( plane->gridAttributes( false ) );
 
62
 
 
63
    //qDebug() << "OK:";
 
64
    if ( !gridAttrsCircular.isGridVisible() && !gridAttrsSagittal.isGridVisible() ) return;
 
65
    //qDebug() << "A";
 
66
 
 
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
 
70
 
 
71
 
 
72
    // Do not draw a grid for pie diagrams
 
73
    if( dynamic_cast<PieDiagram*> (plane->diagrams().first() ) ) return;
 
74
 
 
75
 
 
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;
 
80
 
 
81
    const double r = qAbs( min ) + dgr->dataBoundaries().second.y(); // use the full extents
 
82
 
 
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() );
 
87
        }
 
88
    }
 
89
 
 
90
    if ( gridAttrsCircular.isGridVisible() )
 
91
    {
 
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 );
 
97
    
 
98
            if ( rad == 0 )
 
99
                continue;
 
100
    
 
101
            QRectF rect;
 
102
            QPointF topLeftPoint;
 
103
            QPointF bottomRightPoint;
 
104
 
 
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() );
 
109
 
 
110
            rect.setTopLeft( topLeftPoint + context->rectangle().topLeft() );
 
111
            rect.setBottomRight( bottomRightPoint + context->rectangle().topLeft() );
 
112
 
 
113
            context->painter()->drawEllipse( rect );
 
114
        }
 
115
        plane->setStartPosition( startPos );
 
116
    }
 
117
    context->painter()->setBrush( backupBrush );
 
118
}