~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to kchart/kdchart/KDChartAxesPainter.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C++ -*-
2
 
 
3
 
  $Id: KDChartAxesPainter.h,v 1.3.2.1 2001/12/08 12:15:40 khz Exp $
4
 
 
5
 
  KDChart - a multi-platform charting engine
6
 
 
7
 
  Copyright (C) 2001 by Klarļæ½lvdalens Datakonsult AB
8
 
*/
9
 
 
 
2
   KDChart - a multi-platform charting engine
 
3
   */
 
4
 
 
5
/****************************************************************************
 
6
 ** Copyright (C) 2001-2003 Klarļæ½lvdalens Datakonsult AB.  All rights reserved.
 
7
 **
 
8
 ** This file is part of the KDChart library.
 
9
 **
 
10
 ** This file may be distributed and/or modified under the terms of the
 
11
 ** GNU General Public License version 2 as published by the Free Software
 
12
 ** Foundation and appearing in the file LICENSE.GPL included in the
 
13
 ** packaging of this file.
 
14
 **
 
15
 ** Licensees holding valid commercial KDChart licenses may use this file in
 
16
 ** accordance with the KDChart Commercial License Agreement provided with
 
17
 ** the Software.
 
18
 **
 
19
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
20
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
21
 **
 
22
 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
 
23
 **   information about KDChart Commercial License Agreements.
 
24
 **
 
25
 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
 
26
 ** licensing are not clear to you.
 
27
 **
 
28
 **********************************************************************/
10
29
#ifndef __KDCHARTAXESPAINTER_H__
11
30
#define __KDCHARTAXESPAINTER_H__
12
31
 
17
36
#include <KDChartTable.h>
18
37
#include <KDChartAxisParams.h>
19
38
 
 
39
class QDateTime;
20
40
class KDChartParams;
21
41
 
22
42
class KDChartAxesPainter : public KDChartPainter
23
43
{
24
 
protected:
25
 
    KDChartAxesPainter( KDChartParams* params );
26
 
    virtual ~KDChartAxesPainter();
27
 
 
28
 
    virtual void paintAxes( QPainter* painter, KDChartTableData* data );
29
 
private:
30
 
public:
31
 
    static void saveDrawLine( QPainter& painter,
32
 
                              QPoint pA,
33
 
                              QPoint pZ,
34
 
                              QPen pen );
35
 
    static void calculateLabelTexts( QPainter& painter,
36
 
                                      const KDChartTableData& data,
37
 
                                      const KDChartParams& params,
38
 
                                      uint axisNumber,
39
 
                                      double averageValueP1000,
40
 
                                      KDChartAxisParams::AxisPos basicPos,
41
 
                                      const QPoint& orig,
42
 
                                      double delimLen,
43
 
                                      // start of return parameters
44
 
                                      double& nSubDelimFactor,
45
 
                                      double& pDelimDelta,
46
 
                                      double& nTxtHeight,
47
 
                                      double& pTextsX,
48
 
                                      double& pTextsY,
49
 
                                      double& pTextsW,
50
 
                                      double& pTextsH,
51
 
                                      int& textAlign );
52
 
    static void calculateBasicTextFactors( double nTxtHeight,
53
 
                                            const KDChartAxisParams& para,
54
 
                                            double averageValueP1000,
55
 
                                            KDChartAxisParams::AxisPos basicPos,
56
 
                                            const QPoint& orig,
57
 
                                            double delimLen,
58
 
                                            uint nLabels,
59
 
                                            // start of return parameters
60
 
                                            double& pDelimDelta,
61
 
                                            double& pTextsX,
62
 
                                            double& pTextsY,
63
 
                                            double& pTextsW,
64
 
                                            double& pTextsH,
65
 
                                            int& textAlign );
66
 
    static QString trunctateBehindComma( const double nVal,
67
 
                                  const int    behindComma,
68
 
                                  const double nDelta,
69
 
                                  int& trueBehindComma );
70
 
    static void calculateOrdinateFactors( const KDChartAxisParams& para,
71
 
                                   double& nDist,
72
 
                                   double& nDivisor,
73
 
                                   double& nRound,
74
 
                                   double& nDelta,
75
 
                                   double& nSubDelimFactor,
76
 
                                   double& nLow,
77
 
                                   double& nHigh,
78
 
                                   bool findNextRound = false );
79
 
    static void findInfos( double averageValueP1000,
80
 
                    const KDChartAxisParams& para,
81
 
                    uint axisPos,
82
 
                    KDChartAxisParams::AxisPos& basicPos,
83
 
                    QPoint& orig,
84
 
                    QPoint& dest );
 
44
    protected:
 
45
        KDChartAxesPainter( KDChartParams* params );
 
46
        virtual ~KDChartAxesPainter();
 
47
 
 
48
        virtual void paintAxes( QPainter* painter,
 
49
                KDChartTableDataBase* data );
 
50
 
 
51
        virtual void paintData( QPainter* painter,
 
52
                KDChartTableDataBase* data,
 
53
                bool paint2nd,
 
54
                KDChartDataRegionList* regions );
 
55
 
 
56
        // note: Classes inheriting from KDChartAxesPainter
 
57
        //       MUST implement the following abstract functions:
 
58
 
 
59
        // Returns whether a normal chart is to be drawn
 
60
        // or a stacked or percentage (or ... ) chart            .
 
61
        virtual bool isNormalMode() const = 0;
 
62
 
 
63
        // Returns the number of pixels to be added to the clipping area's height
 
64
        // to make room for special arrows indicating oversized, cut data entries.
 
65
        // Chart classes not drawing such indicators must return 0.
 
66
        virtual int clipShiftUp( bool normalMode, double areaWidthP1000 ) const = 0;
 
67
 
 
68
        // The actual, chart type specific drawing of the data.
 
69
        virtual void specificPaintData( QPainter* painter,
 
70
                const QRect& ourClipRect,
 
71
                KDChartTableDataBase* data,
 
72
                KDChartDataRegionList* regions,
 
73
                const KDChartAxisParams* axisPara,
 
74
                bool bNormalMode,
 
75
                uint chart,
 
76
                double logWidth,
 
77
                double areaWidthP1000,
 
78
                double logHeight,
 
79
                double axisYOffset,
 
80
                double minColumnValue,
 
81
                double maxColumnValue,
 
82
                double columnValueDistance,
 
83
                uint chartDatasetStart,
 
84
                uint chartDatasetEnd,
 
85
                uint datasetStart,
 
86
                uint datasetEnd ) = 0;
 
87
 
 
88
        virtual bool calculateAllAxesLabelTextsAndCalcValues(
 
89
                          KDChartTableDataBase* data,
 
90
                          double areaWidthP1000,
 
91
                          double areaHeightP1000,
 
92
                          double& delimLen );
 
93
 
 
94
    private:
 
95
        int axisGapX( int axis );
 
96
        int axisGapY( int axis );
 
97
    public:
 
98
        // special infos needed by the different painters' implementations
 
99
        // of the specificPaintData() function
 
100
        struct abscissaInfos{
 
101
            const KDChartAxisParams* abscissaPara;
 
102
            bool bCenterThePoints;
 
103
            bool bAbscissaIsLogarithmic;
 
104
            bool bCellsHaveSeveralCoordinates;
 
105
            int numValues;
 
106
            int numLabels;
 
107
            bool bAbscissaHasTrueAxisValues;
 
108
            double abscissaStart;
 
109
            double abscissaEnd;
 
110
            double abscissaSpan;
 
111
            double abscissaDelta;
 
112
            bool bAbscissaHasTrueAxisDtValues;
 
113
            double dtLowPos;
 
114
            double dtHighPos;
 
115
            QDateTime abscissaDtStart;
 
116
            QDateTime abscissaDtEnd;
 
117
            bool bScaleLessThanDay;
 
118
            double abscissaDtSpan;
 
119
            double abscissaDtPixelsPerScaleUnit;
 
120
            double pointDist;
 
121
            double abscissaPixelsPerUnit;
 
122
            double abscissaZeroPos;
 
123
        };
 
124
        static void calculateAbscissaInfos(
 
125
                const KDChartParams& params,
 
126
                const KDChartTableDataBase& data,
 
127
                uint datasetStart,
 
128
                uint datasetEnd,
 
129
                double logWidth,
 
130
                const QRect& dataRect,
 
131
                abscissaInfos& infos );
 
132
        static bool calculateAbscissaAxisValue( const KDChartData& cell,
 
133
                                                abscissaInfos& ai,
 
134
                                                int colNumber,
 
135
                                                double& xValue );
 
136
 
 
137
        static void saveDrawLine( QPainter& painter,
 
138
                QPoint pA,
 
139
                QPoint pZ,
 
140
                QPen pen );
 
141
        static void calculateLabelTexts( const KDChartTableDataBase& data,
 
142
                const KDChartParams& params,
 
143
                uint axisNumber,
 
144
                double averageValueP1000,
 
145
                double delimLen,
 
146
                // start of return parameters
 
147
                KDChartAxisParams::AxisPos& basicPos,
 
148
                QPoint& orig,
 
149
                QPoint& dest,
 
150
                double& pXDeltaFactor,
 
151
                double& pYDeltaFactor,
 
152
                double& pXDelimDeltaFaktor,
 
153
                double& pYDelimDeltaFaktor,
 
154
                double& nSubDelimFactor,
 
155
                double& pDelimDelta,
 
156
                double& nTxtHeight,
 
157
                double& pTextsX,
 
158
                double& pTextsY,
 
159
                double& pTextsW,
 
160
                double& pTextsH,
 
161
                int& textAlign,
 
162
                bool& isLogarithmic,
 
163
                bool& isDateTime,
 
164
                bool& autoDtLabels,
 
165
                QDateTime& dtLow,
 
166
                QDateTime& dtHigh,
 
167
                KDChartAxisParams::ValueScale& dtDeltaScale,
 
168
                bool adjustTheValues = false,
 
169
                double trueDelta     = 0.0,
 
170
                double trueDeltaPix  = 0.0 );
 
171
                static void calculateBasicTextFactors( double nTxtHeight,
 
172
                        const KDChartAxisParams& para,
 
173
                        double averageValueP1000,
 
174
                        KDChartAxisParams::AxisPos basicPos,
 
175
                        const QPoint& orig,
 
176
                        double delimLen,
 
177
                        uint nLabels,
 
178
                        // start of return parameters
 
179
                        double& pDelimDelta,
 
180
                        double& pTextsX,
 
181
                        double& pTextsY,
 
182
                        double& pTextsW,
 
183
                        double& pTextsH,
 
184
                        int& textAlign );
 
185
                static QString truncateBehindComma( const double nVal,
 
186
                        const int    behindComma,
 
187
                        const double nDelta,
 
188
                        int& trueBehindComma );
 
189
                static QString applyLabelsFormat( const double nVal,
 
190
                        int   divPow10,
 
191
                        int   behindComma,
 
192
                        double nDelta,
 
193
                        int& trueBehindComma,
 
194
                        const QString& decimalPoint,
 
195
                        const QString& thousandsPoint,
 
196
                        const QString& prefix,
 
197
                        const QString& postfix,
 
198
                        int            totalLen,
 
199
                        const QChar&   padFill,
 
200
                        bool           blockAlign );
 
201
                static void calculateOrdinateFactors( const KDChartAxisParams& para,
 
202
                        bool bLogarithmic,
 
203
                        double& nDist,
 
204
                        double& nDivisor,
 
205
                        double& nRound,
 
206
                        double& nDelta,
 
207
                        double& nSubDelimFactor,
 
208
                        double& nLow,
 
209
                        double& nHigh,
 
210
                        bool findNextRound = false );
 
211
                static void dtAddSecs(   const QDateTime& org, const int secs,   QDateTime& dest );
 
212
                static void dtAddDays(   const QDateTime& org, const int days,   QDateTime& dest );
 
213
                static void dtAddMonths( const QDateTime& org, const int months, QDateTime& dest );
 
214
                static void dtAddYears(  const QDateTime& org, const int years,  QDateTime& dest );
85
215
};
86
216
 
87
217
#endif