kchart

KDChartPainter.h
1/*
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 **********************************************************************/
29#ifndef __KDCHARTPAINTER_H__
30#define __KDCHARTPAINTER_H__
31
32#include <tqmap.h>
33#include <tqrect.h>
34#include <tqdatetime.h>
35#include <tqregion.h>
36#include <tqstring.h>
37
38#include "KDChartGlobal.h"
39#include "KDChartUnknownTypeException.h"
40#include "KDChartNotEnoughSpaceException.h"
41#include "KDChartTable.h"
42#include "KDChartDataRegion.h"
43#include "KDChartParams.h"
44
47class KDChartTextPiece;
50class TQPainter;
51
52
53struct internal__KDChart__CalcValues {
54 bool processThisAxis;
55 bool bSteadyCalc;
56 bool bLogarithmic;
57 bool bDecreasing;
58 KDChartAxisParams::AxisPos basicPos;
59 TQPoint orig;
60 TQPoint dest;
61 double pXDeltaFactor;
62 double pYDeltaFactor;
63 double pXDelimDeltaFaktor;
64 double pYDelimDeltaFaktor;
65 double nSubDelimFactor;
66 double pDelimDelta;
67 double nTxtHeight;
68 double pTextsX;
69 double pTextsY;
70 double pTextsW;
71 double pTextsH;
72 int textAlign;
73 bool isDateTime;
74 bool autoDtLabels;
75 TQDateTime dtLow;
76 TQDateTime dtHigh;
77 KDChartAxisParams::ValueScale dtDeltaScale;
78 double nLow;
79 double nHigh;
80 double nDelta;
81 double nDeltaPix;
82 double pLastX;
83 double pLastY;
84};
85
86
87class KDCHART_EXPORT KDChartPainter
88{
89 public:
90 static KDChartPainter* create( KDChartParams* params,
91 bool make2nd = false );
92
93 virtual ~KDChartPainter();
94
95 static void registerPainter( const TQString& painterName,
96 KDChartPainter* painter );
97 static void unregisterPainter( const TQString& painterName );
98
99 virtual void setupGeometry ( TQPainter* painter,
101 const TQRect& rect );
102
103 virtual void paint( TQPainter* painter, KDChartTableDataBase* data,
104 bool paintFirst,
105 bool paintLast,
106 KDChartDataRegionList* regions = 0,
107 const TQRect* rect = 0,
108 bool mustCalculateGeometry = true );
109
110 virtual TQRect outermostRect() const { return _outermostRect; }
111
112 static void drawMarker( TQPainter* painter,
113 int style,
114 const TQColor& color,
115 const TQPoint& p,
116 const TQSize& size,
117 uint align = TQt::AlignCenter );
118
119 protected:
121
122 // Note: dataRow, dataCol (and data3rd, resp.)
123 // must only be set if area == KDChartEnums::AreaChartDataRegion
124 virtual void paintArea( TQPainter* painter,
125 uint area,
126 KDChartDataRegionList* regions = 0,
127 uint dataRow = 0,
128 uint dataCol = 0,
129 uint data3rd = 0 );
130
131 virtual void paintDataRegionAreas( TQPainter* painter,
132 KDChartDataRegionList* regions );
133
134 virtual void paintAreaWithGap( TQPainter* painter,
135 TQRect rect,
136 const KDChartParams::KDChartFrameSettings& settings );
137 virtual void paintCustomBoxes( TQPainter* painter,
138 KDChartDataRegionList* regions );
139
140 virtual void paintData( TQPainter* painter, KDChartTableDataBase* data,
141 bool paint2nd,
142 KDChartDataRegionList* regions = 0 ) = 0;
143 virtual void paintDataValues( TQPainter* painter,
145 KDChartDataRegionList* regions );
146 virtual void paintAxes( TQPainter* painter,
147 KDChartTableDataBase* data );
148 virtual void paintLegend( TQPainter* painter,
149 KDChartTableDataBase* data );
150 virtual void paintHeaderFooter( TQPainter* painter,
151 KDChartTableDataBase* data );
152 virtual bool axesOverlapping( int axis1, int axis2 );
153
154 virtual void findChartDatasets( KDChartTableDataBase* data,
155 bool paint2nd,
156 uint chart,
157 uint& chartDatasetStart,
158 uint& chartDatasetEnd );
159
160 virtual void calculateAllAxesRects( TQPainter* painter,
161 bool finalPrecision,
162 KDChartTableDataBase* data );
163
164 virtual TQPoint calculateAnchor( const KDChartCustomBox & box,
165 KDChartDataRegionList* regions = 0 ) const;
166 virtual TQRect calculateAreaRect( bool & allCustomBoxes,
167 uint area,
168 uint dataRow,
169 uint dataCol,
170 uint data3rd,
171 KDChartDataRegionList* regions ) const;
172
173 virtual TQString fallbackLegendText( uint dataset ) const;
174 virtual uint numLegendFallbackTexts( KDChartTableDataBase* data ) const;
175
176 static TQPoint pointOnCircle( const TQRect& rect, double angle );
177 static void makeArc( TQPointArray& points,
178 const TQRect& rect,
179 double startAngle, double angles );
180
181 const KDChartParams* params() const
182 {
183 return _params;
184 }
185
186 TQRect _outermostRect; /* The Outermost rect covers the complete
187 area of the painter. */
188
189 TQRect _innermostRect; /* The Innermost rect covers the area of
190 the painter MINUS the the global
191 left/top/right/bottom leading.
192 ALL following ones are INSIDE the Innermost.
193 */
194
195 TQRect _dataRect;
196
197 TQRect _axesRect; /* The Axes rect contains the Data rect. Up to 4
198 axes might be at the left and bottom as well
199 as at the right and/or at the to top of the
200 chart.
201 */
202
203 TQRect _legendRect; /* The legend position depends on the parameter
204 settings. If it is not directly to the left or
205 to the right of the data display, it will be
206 below the headers and on top of the footers.
207 */
208 int _legendEMSpace; // an em space in the legend font
209 int _legendSpacing; // the line spacing in the legend font
210 int _legendHeight; // the font height in the legend font
211 int _legendLeading; // the font leading in the legend font
212 // int _legendTitleSpacing; // the line spacing in the legend title font
213 // int _legendTitleLeading; // the font leading in the legend title font
214 KDChartTextPiece* _legendTitle;
215
216 int _numLegendTexts; // the number of legend items to show
217
218 int _logicalWidth;
219 int _logicalHeight;
220 double _areaWidthP1000;
221 double _areaHeightP1000;
222
223 TQMap < int, TQString > _legendTexts; // precomputed legend texts
224
225 internal__KDChart__CalcValues calcVal[ KDCHART_MAX_AXES ];
226 virtual bool calculateAllAxesLabelTextsAndCalcValues(
227 TQPainter* painter,
229 double areaWidthP1000,
230 double areaHeightP1000,
231 double& delimLen );
232
233 virtual void drawExtraLinesAndMarkers(
234 KDChartPropertySet& propSet,
235 const TQPen& defaultPen,
236 const KDChartParams::LineMarkerStyle& defaultMarkerStyle,
237 int myPointX,
238 int myPointY,
239 TQPainter* painter,
240 const KDChartAxisParams* abscissaPara,
241 const KDChartAxisParams* ordinatePara,
242 const double areaWidthP1000,
243 const double areaHeightP1000,
244 bool bDrawInFront = false );
245
246 static KDChartDataRegion* drawMarker( TQPainter* painter,
247 const KDChartParams* params,
248 double areaWidthP1000,
249 double areaHeightP1000,
250 int deltaX,
251 int deltaY,
252 int style,
253 const TQColor& color,
254 const TQPoint& p,
255 uint dataset, uint value, uint chart,
256 KDChartDataRegionList* regions = 0,
257 int* width = 0,
258 int* height = 0,
259 uint align = TQt::AlignCenter );
260
261 private:
262 // disallow copy-construction and assignment
264 KDChartPainter& operator=( const KDChartPainter& );
265
266
267 TQMap < TQString, KDChartPainter* > _customPainters;
268 KDChartParams* _params;
269
270 TQRect trueFrameRect( const TQRect& orgRect,
271 const KDChartParams::KDChartFrameSettings* settings ) const;
272
273 int legendTitleVertGap() const;
274 TQFont trueLegendTitleFont() const;
275 TQFont trueLegendFont() const;
276 void calculateHorizontalLegendSize( TQPainter* painter,
277 TQSize& size,
278 bool& legendNewLinesStartAtLeft ) const;
279 bool mustDrawVerticalLegend() const;
280 void findLegendTexts( KDChartTableDataBase* );
281 int calculateHdFtRects( TQPainter* painter,
282 double averageValueP1000,
283 int xposLeft,
284 int xposRight,
285 bool bHeader,
286 int& yposTop,
287 int& yposBottom );
288 bool _legendNewLinesStartAtLeft;
289 int _legendTitleHeight;
290 int _legendTitleWidth;
291 int _legendTitleMetricsHeight; // the font height in the legend title font
292 int _hdLeading;
293 int _ftLeading;
294};
295
296#endif
Header for all common chart parameters.
#define KDCHART_MAX_AXES
Charts have up to 12 axes: up to two axes on both sides for X, Y and Z (if data is 3-dimensional).
access the chart axis parameters.
Class for specifying and drawing custom boxes.
The collection class used by KD Chart to store data region information.
virtual void paintAxes(TQPainter *painter, KDChartTableDataBase *data)
Paints the axes for the chart.
virtual void setupGeometry(TQPainter *painter, KDChartTableDataBase *data, const TQRect &rect)
This method will be called whenever any parameters that affect geometry have been changed.
virtual void paintHeaderFooter(TQPainter *painter, KDChartTableDataBase *data)
Paints the header and footers for the chart.
virtual void paintAreaWithGap(TQPainter *painter, TQRect rect, const KDChartParams::KDChartFrameSettings &settings)
Paints an area frame.
static void drawMarker(TQPainter *painter, int style, const TQColor &color, const TQPoint &p, const TQSize &size, uint align=TQt::AlignCenter)
Draws the marker for one data point according to the specified style, color, size.
virtual TQString fallbackLegendText(uint dataset) const
This method provides a fallback legend text for the specified dataset, if there was no other way to d...
virtual TQRect calculateAreaRect(bool &allCustomBoxes, uint area, uint dataRow, uint dataCol, uint data3rd, KDChartDataRegionList *regions) const
Calculated the rectangle covered by an area.
KDChartPainter(KDChartParams *)
Constructor.
virtual void paintArea(TQPainter *painter, uint area, KDChartDataRegionList *regions=0, uint dataRow=0, uint dataCol=0, uint data3rd=0)
Paints an area frame.
virtual void paintCustomBoxes(TQPainter *painter, KDChartDataRegionList *regions)
Paints all custom boxes.
virtual void paintDataValues(TQPainter *painter, KDChartTableDataBase *data, KDChartDataRegionList *regions)
Paints the data value texts near the data representations.
virtual TQPoint calculateAnchor(const KDChartCustomBox &box, KDChartDataRegionList *regions=0) const
Calculated the top left corner of a custom box.
virtual void paintLegend(TQPainter *painter, KDChartTableDataBase *data)
Paints the legend for the chart.
virtual uint numLegendFallbackTexts(KDChartTableDataBase *data) const
This methods returns the number of elements to be shown in the legend in case fallback texts are used...
virtual void paint(TQPainter *painter, KDChartTableDataBase *data, bool paintFirst, bool paintLast, KDChartDataRegionList *regions=0, const TQRect *rect=0, bool mustCalculateGeometry=true)
Paints the chart for which this chart painter is configured on a TQPainter.
static KDChartPainter * create(KDChartParams *params, bool make2nd=false)
Creates an object of a concrete subclass of KDChartPainter that KDChart::paint() (and consequently,...
static void unregisterPainter(const TQString &painterName)
Unregisters a user-defined painter implementation.
static void registerPainter(const TQString &painterName, KDChartPainter *painter)
Registers a user-defined painter implementation which is identified by a string.
Stores the frame settings for one of the chart areas:
Bundles the display parameters of a chart.
LineMarkerStyle
The available line marker styles.
Property settings of a single KDChart data cell.
KD Chart's build-in table data for an easy way of storing data values.