kchart

KDChartAxesPainter.h

00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDChart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KDChart licenses may use this file in
00016  ** accordance with the KDChart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
00023  **   information about KDChart Commercial License Agreements.
00024  **
00025  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 #ifndef __KDCHARTAXESPAINTER_H__
00030 #define __KDCHARTAXESPAINTER_H__
00031 
00032 #include <qpen.h>
00033 #include <qpainter.h>
00034 
00035 #include <KDChartPainter.h>
00036 #include <KDChartTable.h>
00037 #include <KDChartAxisParams.h>
00038 
00039 class QDateTime;
00040 class KDChartParams;
00041 
00042 class KDChartAxesPainter : public KDChartPainter
00043 {
00044     protected:
00045         KDChartAxesPainter( KDChartParams* params );
00046         virtual ~KDChartAxesPainter();
00047 
00048         virtual void paintAxes( QPainter* painter,
00049                 KDChartTableDataBase* data );
00050 
00051         virtual void paintData( QPainter* painter,
00052                 KDChartTableDataBase* data,
00053                 bool paint2nd,
00054                 KDChartDataRegionList* regions );
00055 
00056         // note: Classes inheriting from KDChartAxesPainter
00057         //       MUST implement the following abstract functions:
00058 
00059         // Returns whether a normal chart is to be drawn
00060         // or a stacked or percentage (or ... ) chart            .
00061         virtual bool isNormalMode() const = 0;
00062 
00063         // Returns the number of pixels to be added to the clipping area's height
00064         // to make room for special arrows indicating oversized, cut data entries.
00065         // Chart classes not drawing such indicators must return 0.
00066         virtual int clipShiftUp( bool normalMode, double areaWidthP1000 ) const = 0;
00067 
00068         // The actual, chart type specific drawing of the data.
00069         virtual void specificPaintData( QPainter* painter,
00070                 const QRect& ourClipRect,
00071                 KDChartTableDataBase* data,
00072                 KDChartDataRegionList* regions,
00073                 const KDChartAxisParams* axisPara,
00074                 bool bNormalMode,
00075                 uint chart,
00076                 double logWidth,
00077                 double areaWidthP1000,
00078                 double logHeight,
00079                 double axisYOffset,
00080                 double minColumnValue,
00081                 double maxColumnValue,
00082                 double columnValueDistance,
00083                 uint chartDatasetStart,
00084                 uint chartDatasetEnd,
00085                 uint datasetStart,
00086                 uint datasetEnd ) = 0;
00087 
00088         virtual bool calculateAllAxesLabelTextsAndCalcValues(
00089                           QPainter* painter,
00090                           KDChartTableDataBase* data,
00091                           double areaWidthP1000,
00092                           double areaHeightP1000,
00093                           double& delimLen );
00094 
00095     private:
00096     public:
00097         // special infos needed by the different painters' implementations
00098         // of the specificPaintData() function
00099         struct abscissaInfos{
00100             const KDChartAxisParams* abscissaPara;
00101             bool bCenterThePoints;
00102             bool bAbscissaDecreasing;
00103             bool bAbscissaIsLogarithmic;
00104             bool bCellsHaveSeveralCoordinates;
00105             int numValues;
00106             int numLabels;
00107             bool bAbscissaHasTrueAxisValues;
00108             double abscissaStart;
00109             double abscissaEnd;
00110             double abscissaSpan;
00111             double abscissaDelta;
00112             bool bAbscissaHasTrueAxisDtValues;
00113             double dtLowPos;
00114             double dtHighPos;
00115             QDateTime abscissaDtStart;
00116             QDateTime abscissaDtEnd;
00117             bool bScaleLessThanDay;
00118             double abscissaDtSpan;
00119             double abscissaDtPixelsPerScaleUnit;
00120             double pointDist;
00121             double abscissaPixelsPerUnit;
00122             double abscissaZeroPos;
00123         };
00124         static void calculateAbscissaInfos(
00125                 const KDChartParams& params,
00126                 const KDChartTableDataBase& data,
00127                 uint datasetStart,
00128                 uint datasetEnd,
00129                 double logWidth,
00130                 const QRect& dataRect,
00131                 abscissaInfos& infos );
00132         static bool calculateAbscissaAxisValue( const QVariant& value,
00133                                                 abscissaInfos& ai,
00134                                                 int colNumber,
00135                                                 double& xValue );
00136 
00137         static void saveDrawLine( QPainter& painter,
00138                 QPoint pA,
00139                 QPoint pZ,
00140                 QPen pen );
00141         static void calculateLabelTexts(
00142                 QPainter* painter,
00143                 const KDChartTableDataBase& data,
00144                 const KDChartParams& params,
00145                 uint axisNumber,
00146                 double averageValueP1000,
00147                 double delimLen,
00148                 // start of return parameters
00149                 KDChartAxisParams::AxisPos& basicPos,
00150                 QPoint& orig,
00151                 QPoint& dest,
00152                 double& pXDeltaFactor,
00153                 double& pYDeltaFactor,
00154                 double& pXDelimDeltaFaktor,
00155                 double& pYDelimDeltaFaktor,
00156                 double& nSubDelimFactor,
00157                 double& pDelimDelta,
00158                 double& nTxtHeight,
00159                 double& pTextsX,
00160                 double& pTextsY,
00161                 double& pTextsW,
00162                 double& pTextsH,
00163                 int& textAlign,
00164                 bool& isLogarithmic,
00165                 bool& isDateTime,
00166                 bool& autoDtLabels,
00167                 QDateTime& dtLow,
00168                 QDateTime& dtHigh,
00169                 KDChartAxisParams::ValueScale& dtDeltaScale,
00170                 bool adjustTheValues = false,
00171                 double trueDelta     = 0.0,
00172                 double trueDeltaPix  = 0.0 );
00173                 static void calculateBasicTextFactors( double nTxtHeight,
00174                         const KDChartAxisParams& para,
00175                         double averageValueP1000,
00176                         KDChartAxisParams::AxisPos basicPos,
00177                         const QPoint& orig,
00178                         double delimLen,
00179                         uint nLabels,
00180                         // start of return parameters
00181                         double& pDelimDelta,
00182                         double& pTextsX,
00183                         double& pTextsY,
00184                         double& pTextsW,
00185                         double& pTextsH,
00186                         int& textAlign );
00187                 static QString truncateBehindComma( const double nVal,
00188                         const int    behindComma,
00189                         const double nDelta,
00190                         int& trueBehindComma );
00191                 static QString applyLabelsFormat( const double nVal,
00192                         int   divPow10,
00193                         int   behindComma,
00194                         double nDelta,
00195                         int& trueBehindComma,
00196                         const QString& decimalPoint,
00197                         const QString& thousandsPoint,
00198                         const QString& prefix,
00199                         const QString& postfix,
00200                         int            totalLen,
00201                         const QChar&   padFill,
00202                         bool           blockAlign );
00203                 static void calculateOrdinateFactors( const KDChartAxisParams& para,
00204                         bool bLogarithmic,
00205                         double& nDist,
00206                         double& nDivisor,
00207                         double& nRound,
00208                         double& nDelta,
00209                         double& nSubDelimFactor,
00210                         double& nLow,
00211                         double& nHigh,
00212                         bool findNextRound = false );
00213                 static void dtAddSecs(   const QDateTime& org, const int secs,   QDateTime& dest );
00214                 static void dtAddDays(   const QDateTime& org, const int days,   QDateTime& dest );
00215                 static void dtAddMonths( const QDateTime& org, const int months, QDateTime& dest );
00216                 static void dtAddYears(  const QDateTime& org, const int years,  QDateTime& dest );
00217 };
00218 
00219 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys