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
#ifndef KDCHARTCHART_H
24
#define KDCHARTCHART_H
28
#include "kdchart_export.h"
29
#include "KDChartGlobal.h"
31
/** \file KDChartChart.h
32
* \brief Declaring the class KDChart::Chart.
40
class BackgroundAttributes;
41
class FrameAttributes;
42
class AbstractDiagram;
43
class AbstractCoordinatePlane;
47
typedef QList<AbstractCoordinatePlane*> CoordinatePlaneList;
48
typedef QList<HeaderFooter*> HeaderFooterList;
49
typedef QList<Legend*> LegendList;
53
* @class Chart KDChartChart.h KDChartChart
54
* @brief A chart with one or more diagrams.
56
* The Chart class represents a drawing consisting of one or more diagrams
57
* and various optional elements such as legends, axes, text boxes, headers
58
* or footers. It takes ownership of all these elements when they are assigned
59
* to it. Each diagram is associated with a coordinate plane, of which the chart
60
* can have more than one. The coordinate planes (and thus the associated diagrams)
61
* can be laid out in various ways.
63
* The Chart class makes heavy use of the Qt Interview framework for model/view
64
* programming, and thus requires data to be presented to it in a QAbstractItemModel
65
* compatible way. For many simple charts, especially if the visualized data is
66
* static, KDChart::Widget provides an abstracted interface, that hides the complexity
67
* of Interview to a large extent.
69
class KDCHART_EXPORT Chart : public QWidget
72
Q_PROPERTY( int globalLeadingTop READ globalLeadingTop WRITE setGlobalLeadingTop )
73
Q_PROPERTY( int globalLeadingBottom READ globalLeadingBottom WRITE setGlobalLeadingBottom )
74
Q_PROPERTY( int globalLeadingLeft READ globalLeadingLeft WRITE setGlobalLeadingLeft )
75
Q_PROPERTY( int globalLeadingRight READ globalLeadingRight WRITE setGlobalLeadingRight )
77
KDCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( Chart )
80
explicit Chart ( QWidget* parent = 0 );
84
\brief Specify the frame attributes to be used, by default is it a thin black line.
86
To hide the frame line, you could do something like this:
88
KDChart::FrameAttributes frameAttrs( my_chart->frameAttributes() );
89
frameAttrs.setVisible( false );
90
my_chart->setFrameAttributes( frameAttrs );
93
\sa setBackgroundAttributes
95
void setFrameAttributes( const FrameAttributes &a );
96
FrameAttributes frameAttributes() const;
99
\brief Specify the background attributes to be used, by default there is no background.
101
To set a light blue background, you could do something like this:
103
KDChart::BackgroundAttributes backgroundAttrs( my_chart->backgroundAttributes() );
104
backgroundAttrs.setVisible( true );
105
backgroundAttrs.setBrush( QColor(0xd0,0xd0,0xff) );
106
my_chart->setBackgroundAttributes( backgroundAttrs );
109
\sa setFrameAttributes
111
void setBackgroundAttributes( const BackgroundAttributes &a );
112
BackgroundAttributes backgroundAttributes() const;
115
* Each chart must have at least one coordinate plane.
116
* Initially a default CartesianCoordinatePlane is created.
117
* Use replaceCoordinatePlane() to replace it with a different
118
* one, such as a PolarCoordinatePlane.
119
* @return The first coordinate plane of the chart.
121
AbstractCoordinatePlane* coordinatePlane();
124
* The list of coordinate planes.
125
* @return The list of coordinate planes.
127
CoordinatePlaneList coordinatePlanes();
130
* Adds a coordinate plane to the chart. The chart takes ownership.
131
* @param plane The coordinate plane to add.
133
* \sa replaceCoordinatePlane, takeCoordinatePlane
135
void addCoordinatePlane( AbstractCoordinatePlane* plane );
138
* Replaces the old coordinate plane, or appends the
139
* plane, it there is none yet.
141
* @param plane The coordinate plane to be used instead of the old plane.
142
* This parameter must not be zero, or the method will do nothing.
144
* @param oldPlane The coordinate plane to be removed by the new plane. This
145
* plane will be deleted automatically. If the parameter is omitted,
146
* the very first coordinate plane will be replaced. In case, there was no
147
* plane yet, the new plane will just be added.
149
* \note If you want to re-use the old coordinate plane, call takeCoordinatePlane and
150
* addCoordinatePlane, instead of using replaceCoordinatePlane.
152
* \sa addCoordinatePlane, takeCoordinatePlane
154
void replaceCoordinatePlane( AbstractCoordinatePlane* plane,
155
AbstractCoordinatePlane* oldPlane = 0 );
158
* Removes the coordinate plane from the chart, without deleting it.
160
* The chart no longer owns the plane, so it is
161
* the caller's responsibility to delete the plane.
163
* \sa addCoordinatePlane, takeCoordinatePlane
165
void takeCoordinatePlane( AbstractCoordinatePlane* plane );
168
* Set the coordinate plane layout that should be used as model for
169
* the internal used layout. The layout needs to be an instance of
170
* QHBoxLayout or QVBoxLayout.
172
void setCoordinatePlaneLayout( QLayout * layout );
173
QLayout* coordinatePlaneLayout();
176
* The first header or footer of the chart. By default there is none.
177
* @return The first header or footer of the chart or 0 if there was none
178
* added to the chart.
180
HeaderFooter* headerFooter();
183
* The list of headers and footers associated with the chart.
184
* @return The list of headers and footers associated with the chart.
186
HeaderFooterList headerFooters();
189
* Adds a header or a footer to the chart. The chart takes ownership.
190
* @param headerFooter The header (or footer, resp.) to add.
192
* \sa replaceHeaderFooter, takeHeaderFooter
194
void addHeaderFooter( HeaderFooter* headerFooter );
197
* Replaces the old header (or footer, resp.), or appends the
198
* new header or footer, it there is none yet.
200
* @param headerFooter The header or footer to be used instead of the old one.
201
* This parameter must not be zero, or the method will do nothing.
203
* @param oldHeaderFooter The header or footer to be removed by the new one. This
204
* header or footer will be deleted automatically. If the parameter is omitted,
205
* the very first header or footer will be replaced. In case, there was no
206
* header and no footer yet, the new header or footer will just be added.
208
* \note If you want to re-use the old header or footer, call takeHeaderFooter and
209
* addHeaderFooter, instead of using replaceHeaderFooter.
211
* \sa addHeaderFooter, takeHeaderFooter
213
void replaceHeaderFooter ( HeaderFooter* headerFooter,
214
HeaderFooter* oldHeaderFooter = 0 );
217
* Removes the header (or footer, resp.) from the chart, without deleting it.
219
* The chart no longer owns the header or footer, so it is
220
* the caller's responsibility to delete the header or footer.
222
* \sa addHeaderFooter, replaceHeaderFooter
224
void takeHeaderFooter( HeaderFooter* headerFooter );
227
* The first legend of the chart or 0 if there was none added to the chart.
228
* @return The first legend of the chart or 0 if none exists.
233
* The list of all legends associated with the chart.
234
* @return The list of all legends associated with the chart.
236
LegendList legends();
239
* Add the given legend to the chart. The chart takes ownership.
240
* @param legend The legend to add.
242
* \sa replaceLegend, takeLegend
244
void addLegend( Legend* legend );
247
* Replaces the old legend, or appends the
248
* new legend, it there is none yet.
250
* @param legend The legend to be used instead of the old one.
251
* This parameter must not be zero, or the method will do nothing.
253
* @param oldLegend The legend to be removed by the new one. This
254
* legend will be deleted automatically. If the parameter is omitted,
255
* the very first legend will be replaced. In case, there was no
256
* legend yet, the new legend will just be added.
258
* If you want to re-use the old legend, call takeLegend and
259
* addLegend, instead of using replaceLegend.
261
* \note Whenever addLegend is called the font sizes used by the
262
* Legend are set to relative and they get coupled to the Chart's size,
263
* with their relative values being 20 for the item texts and 24 to the
264
* title text. So if you want to use custom font sizes for the Legend
265
* make sure to set them after calling addLegend.
267
* \sa addLegend, takeLegend
269
void replaceLegend ( Legend* legend, Legend* oldLegend = 0 );
272
* Removes the legend from the chart, without deleting it.
274
* The chart no longer owns the legend, so it is
275
* the caller's responsibility to delete the legend.
277
* \sa addLegend, takeLegend
279
void takeLegend( Legend* legend );
282
* Set the padding between the margin of the widget and the area that
283
* the contents are drawn into.
284
* @param left The padding on the left side.
285
* @param top The padding at the top.
286
* @param right The padding on the left hand side.
287
* @param bottom The padding on the bottom.
289
* \note Using previous versions of KD Chart you might have called
290
* setGlobalLeading() to make room for long Abscissa labels (or for an
291
* overlapping top label of an Ordinate axis, resp.) that would not fit
292
* into the normal axis area. This is \em no \em longer \em needed
293
* because KD Chart now is using hidden auto-spacer items reserving
294
* as much free space as is needed for axes with overlaping content
295
* at the respective sides.
297
* \sa setGlobalLeadingTop, setGlobalLeadingBottom, setGlobalLeadingLeft, setGlobalLeadingRight
298
* \sa globalLeadingTop, globalLeadingBottom, globalLeadingLeft, globalLeadingRight
300
void setGlobalLeading( int left, int top, int right, int bottom );
303
* Set the padding between the start of the widget and the start
304
* of the area that is used for drawing on the left.
305
* @param leading The padding value.
307
* \sa setGlobalLeading
309
void setGlobalLeadingLeft( int leading );
312
* The padding between the start of the widget and the start
313
* of the area that is used for drawing on the left.
314
* @return The padding between the start of the widget and the start
315
* of the area that is used for drawing on the left.
317
* \sa setGlobalLeading
319
int globalLeadingLeft() const;
322
* Set the padding between the start of the widget and the start
323
* of the area that is used for drawing at the top.
324
* @param leading The padding value.
326
* \sa setGlobalLeading
328
void setGlobalLeadingTop( int leading );
331
* The padding between the start of the widget and the start
332
* of the area that is used for drawing at the top.
333
* @return The padding between the start of the widget and the start
334
* of the area that is used for drawing at the top.
336
* \sa setGlobalLeading
338
int globalLeadingTop() const;
341
* Set the padding between the start of the widget and the start
342
* of the area that is used for drawing on the right.
343
* @param leading The padding value.
345
* \sa setGlobalLeading
347
void setGlobalLeadingRight( int leading );
350
* The padding between the start of the widget and the start
351
* of the area that is used for drawing on the right.
352
* @return The padding between the start of the widget and the start
353
* of the area that is used for drawing on the right.
355
* \sa setGlobalLeading
357
int globalLeadingRight() const;
360
* Set the padding between the start of the widget and the start
361
* of the area that is used for drawing on the bottom.
362
* @param leading The padding value.
364
* \sa setGlobalLeading
366
void setGlobalLeadingBottom( int leading );
369
* The padding between the start of the widget and the start
370
* of the area that is used for drawing at the bottom.
371
* @return The padding between the start of the widget and the start
372
* of the area that is used for drawing at the bottom.
374
* \sa setGlobalLeading
376
int globalLeadingBottom() const;
379
* Paints all the contents of the chart. Use this method, to make KDChart
380
* draw into your QPainter.
382
* \note Any global leading settings will be used by the paint method too,
383
* so make sure to set them to zero, if you want the drawing to have the exact
384
* size of the target rectangle.
386
* \param painter The painter to be drawn into.
387
* \param target The rectangle to be filled by the Chart's drawing.
389
* \sa setGlobalLeading
391
void paint( QPainter* painter, const QRect& target );
393
void reLayoutFloatingLegends();
396
/** Emitted upon change of a property of the Chart or any of its components. */
397
void propertiesChanged();
401
* Adjusts the internal layout when the chart is resized.
403
/* reimp */ void resizeEvent ( QResizeEvent * event );
406
* @brief Draws the background and frame, then calls paint().
408
* In most cases there is no need to override this method in a derived
409
* class, but if you do, do not forget to call paint().
412
/* reimp */ void paintEvent( QPaintEvent* event );
415
void mousePressEvent( QMouseEvent* event );
417
void mouseDoubleClickEvent( QMouseEvent* event );
419
void mouseMoveEvent( QMouseEvent* event );
421
void mouseReleaseEvent( QMouseEvent* event );
423
bool event( QEvent* event );
426
// Here we have a few docu block to be included into the API documentation:
429
* \brief Implementation directory of KDChart.
431
* This directory contains the header files and the source files of both,
432
* the private and the public classes.
434
* \note Only classes that have an include wrapper in the \c $KDCHARTDIR/include
435
* directory are part of the supported API.
436
* All other classes are to be considered as implemntation details, they
437
* could be changed in future versions of KDChart without notice.
439
* In other words: No class that is not mentioned in the \c $KDCHARTDIR/include
440
* directory may be directly used by your application.
442
* The recommended way to include classes of the KDChart API is including
443
* them by class name, so instead of including KDChartChart.h you would say:
446
#include <KDChartChart>
449
* When following this there is no reason to include the \c $KDCHARTDIR/src
450
* directory, it is sufficient to include \c $KDCHARTDIR/include
454
* @class QAbstractItemView "(do not include)"
455
* @brief Class only listed here to document inheritance of some KDChart classes.
457
* Please consult the respective Qt documentation for details:
458
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
461
* @class QAbstractProxyModel "(do not include)"
462
* @brief Class only listed here to document inheritance of some KDChart classes.
464
* Please consult the respective Qt documentation for details:
465
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
468
* @class QFrame "(do not include)"
469
* @brief Class only listed here to document inheritance of some KDChart classes.
471
* Please consult the respective Qt documentation for details:
472
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
475
* @class QObject "(do not include)"
476
* @brief Class only listed here to document inheritance of some KDChart classes.
478
* Please consult the respective Qt documentation for details:
479
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
482
* @class QSortFilterProxyModel "(do not include)"
483
* @brief Class only listed here to document inheritance of some KDChart classes.
485
* Please consult the respective Qt documentation for details:
486
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
489
* @class QWidget "(do not include)"
490
* @brief Class only listed here to document inheritance of some KDChart classes.
492
* Please consult the respective Qt documentation for details:
493
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
496
* @class QTextDocument "(do not include)"
497
* @brief Class only listed here to document inheritance of some KDChart classes.
499
* Please consult the respective Qt documentation for details:
500
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
503
* @class QLayoutItem "(do not include)"
504
* @brief Class only listed here to document inheritance of some KDChart classes.
506
* Please consult the respective Qt documentation for details:
507
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>
510
* @class QGraphicsPolygonItem "(do not include)"
511
* @brief Class only listed here to document inheritance of some KDChart classes.
513
* Please consult the respective Qt documentation for details:
514
* <A HREF="http://doc.trolltech.com/">http://doc.trolltech.com/</A>