KD Chart API Documentation  3.1
Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
KDChart::Chart Class Reference

A chart with one or more diagrams. More...

#include <KDChartChart>

Inheritance diagram for KDChart::Chart:

Signals

void finishedDrawing ()
 
void propertiesChanged ()
 

Public Member Functions

 Chart (QWidget *parent=nullptr)
 
 ~Chart () override
 
void addCoordinatePlane (AbstractCoordinatePlane *plane)
 
void addHeaderFooter (HeaderFooter *headerFooter)
 
void addLegend (Legend *legend)
 
BackgroundAttributes backgroundAttributes () const
 
AbstractCoordinatePlanecoordinatePlane ()
 
QLayout * coordinatePlaneLayout ()
 
CoordinatePlaneList coordinatePlanes ()
 
FrameAttributes frameAttributes () const
 
int globalLeadingBottom () const
 
int globalLeadingLeft () const
 
int globalLeadingRight () const
 
int globalLeadingTop () const
 
HeaderFooterheaderFooter ()
 
HeaderFooterList headerFooters ()
 
void insertCoordinatePlane (int index, AbstractCoordinatePlane *plane)
 
Legendlegend ()
 
LegendList legends () const
 
void paint (QPainter *painter, const QRect &target)
 
void reLayoutFloatingLegends ()
 
void replaceCoordinatePlane (AbstractCoordinatePlane *plane, AbstractCoordinatePlane *oldPlane=nullptr)
 
void replaceHeaderFooter (HeaderFooter *headerFooter, HeaderFooter *oldHeaderFooter=nullptr)
 
void replaceLegend (Legend *legend, Legend *oldLegend=nullptr)
 
void setBackgroundAttributes (const BackgroundAttributes &a)
 Specify the background attributes to be used, by default there is no background. More...
 
void setCoordinatePlaneLayout (QLayout *layout)
 
void setFrameAttributes (const FrameAttributes &a)
 Specify the frame attributes to be used, by default is it a thin black line. More...
 
void setGlobalLeading (int left, int top, int right, int bottom)
 
void setGlobalLeadingBottom (int leading)
 
void setGlobalLeadingLeft (int leading)
 
void setGlobalLeadingRight (int leading)
 
void setGlobalLeadingTop (int leading)
 
void setUseNewLayoutSystem (bool value)
 
void takeCoordinatePlane (AbstractCoordinatePlane *plane)
 
void takeHeaderFooter (HeaderFooter *headerFooter)
 
void takeLegend (Legend *legend)
 
bool useNewLayoutSystem () const
 useNewLayoutSystem Be very careful activating the new layout system, its still experimental and works only if the user knows what he is doing. The reason is that the system does not prevent the user from creating sharing graphs that are not layoutable in a plane and still needs assistance from the user. More...
 

Protected Member Functions

bool event (QEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 Draws the background and frame, then calls paint(). More...
 
void resizeEvent (QResizeEvent *event) override
 

Properties

int globalLeadingBottom
 
int globalLeadingLeft
 
int globalLeadingRight
 
int globalLeadingTop
 
bool useNewLayoutSystem
 

Detailed Description

A chart with one or more diagrams.

The Chart class represents a drawing consisting of one or more diagrams and various optional elements such as legends, axes, text boxes, headers or footers. It takes ownership of all these elements when they are assigned to it. Each diagram is associated with a coordinate plane, of which the chart can have more than one. The coordinate planes (and thus the associated diagrams) can be laid out in various ways.

The Chart class makes heavy use of the Qt Interview framework for model/view programming, and thus requires data to be presented to it in a QAbstractItemModel compatible way. For many simple charts, especially if the visualized data is static, KDChart::Widget provides an abstracted interface, that hides the complexity of Interview to a large extent.

Definition at line 83 of file KDChartChart.h.

Constructor & Destructor Documentation

◆ Chart()

Chart::Chart ( QWidget *  parent = nullptr)
explicit

◆ ~Chart()

Chart::~Chart ( )
override

Definition at line 1139 of file KDChartChart.cpp.

References d.

Member Function Documentation

◆ addCoordinatePlane()

void Chart::addCoordinatePlane ( AbstractCoordinatePlane plane)

Adds a coordinate plane to the chart. The chart takes ownership.

Parameters
planeThe coordinate plane to add.
See also
replaceCoordinatePlane, takeCoordinatePlane

Definition at line 1201 of file KDChartChart.cpp.

References d, and insertCoordinatePlane().

Referenced by Chart(), and replaceCoordinatePlane().

◆ addHeaderFooter()

void Chart::addHeaderFooter ( HeaderFooter headerFooter)

◆ addLegend()

void Chart::addLegend ( Legend legend)

Add the given legend to the chart. The chart takes ownership.

Parameters
legendThe legend to add.
See also
replaceLegend, takeLegend

Definition at line 1524 of file KDChartChart.cpp.

References legend(), and propertiesChanged().

Referenced by replaceLegend().

◆ backgroundAttributes()

BackgroundAttributes Chart::backgroundAttributes ( ) const

Definition at line 1159 of file KDChartChart.cpp.

References d.

◆ coordinatePlane()

AbstractCoordinatePlane * Chart::coordinatePlane ( )

Each chart must have at least one coordinate plane. Initially a default CartesianCoordinatePlane is created. Use replaceCoordinatePlane() to replace it with a different one, such as a PolarCoordinatePlane.

Returns
The first coordinate plane of the chart.

Definition at line 1186 of file KDChartChart.cpp.

References d.

◆ coordinatePlaneLayout()

QLayout * Chart::coordinatePlaneLayout ( )

Definition at line 1181 of file KDChartChart.cpp.

References d.

◆ coordinatePlanes()

CoordinatePlaneList Chart::coordinatePlanes ( )

The list of coordinate planes.

Returns
The list of coordinate planes.

Definition at line 1196 of file KDChartChart.cpp.

References d.

◆ event()

bool Chart::event ( QEvent *  event)
overrideprotected

reimp

Definition at line 1747 of file KDChartChart.cpp.

References d.

Referenced by mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and resizeEvent().

◆ finishedDrawing

void KDChart::Chart::finishedDrawing ( )
signal

Referenced by paintEvent().

◆ frameAttributes()

FrameAttributes Chart::frameAttributes ( ) const

Definition at line 1149 of file KDChartChart.cpp.

References d.

◆ globalLeadingBottom()

int Chart::globalLeadingBottom ( ) const

The padding between the start of the widget and the start of the area that is used for drawing at the bottom.

Returns
The padding between the start of the widget and the start of the area that is used for drawing at the bottom.
See also
setGlobalLeading

Definition at line 1310 of file KDChartChart.cpp.

References d.

◆ globalLeadingLeft()

int Chart::globalLeadingLeft ( ) const

The padding between the start of the widget and the start of the area that is used for drawing on the left.

Returns
The padding between the start of the widget and the start of the area that is used for drawing on the left.
See also
setGlobalLeading

Definition at line 1274 of file KDChartChart.cpp.

References d.

◆ globalLeadingRight()

int Chart::globalLeadingRight ( ) const

The padding between the start of the widget and the start of the area that is used for drawing on the right.

Returns
The padding between the start of the widget and the start of the area that is used for drawing on the right.
See also
setGlobalLeading

Definition at line 1298 of file KDChartChart.cpp.

References d.

◆ globalLeadingTop()

int Chart::globalLeadingTop ( ) const

The padding between the start of the widget and the start of the area that is used for drawing at the top.

Returns
The padding between the start of the widget and the start of the area that is used for drawing at the top.
See also
setGlobalLeading

Definition at line 1286 of file KDChartChart.cpp.

References d.

◆ headerFooter()

HeaderFooter * Chart::headerFooter ( )

The first header or footer of the chart. By default there is none.

Returns
The first header or footer of the chart or 0 if there was none added to the chart.

Definition at line 1502 of file KDChartChart.cpp.

References d.

Referenced by replaceHeaderFooter(), and takeHeaderFooter().

◆ headerFooters()

HeaderFooterList Chart::headerFooters ( )

The list of headers and footers associated with the chart.

Returns
The list of headers and footers associated with the chart.

Definition at line 1511 of file KDChartChart.cpp.

References d.

◆ insertCoordinatePlane()

void Chart::insertCoordinatePlane ( int  index,
AbstractCoordinatePlane plane 
)

◆ legend()

Legend * Chart::legend ( )

The first legend of the chart or 0 if there was none added to the chart.

Returns
The first legend of the chart or 0 if none exists.

Definition at line 1660 of file KDChartChart.cpp.

References d.

Referenced by addLegend(), reLayoutFloatingLegends(), replaceLegend(), and takeLegend().

◆ legends()

LegendList Chart::legends ( ) const

The list of all legends associated with the chart.

Returns
The list of all legends associated with the chart.

Definition at line 1665 of file KDChartChart.cpp.

References d.

◆ mouseDoubleClickEvent()

void Chart::mouseDoubleClickEvent ( QMouseEvent *  event)
overrideprotected

reimp

Definition at line 1684 of file KDChartChart.cpp.

References d, and event().

◆ mouseMoveEvent()

void Chart::mouseMoveEvent ( QMouseEvent *  event)
overrideprotected

reimp

Definition at line 1697 of file KDChartChart.cpp.

References d, and event().

◆ mousePressEvent()

void Chart::mousePressEvent ( QMouseEvent *  event)
overrideprotected

reimp

Definition at line 1670 of file KDChartChart.cpp.

References d, and event().

◆ mouseReleaseEvent()

void Chart::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected

reimp

Definition at line 1721 of file KDChartChart.cpp.

References d, and event().

◆ paint()

void Chart::paint ( QPainter *  painter,
const QRect &  target 
)

Paints all the contents of the chart. Use this method to make KDChart draw into your QPainter.

Note
Any global leading settings will be used by the paint method too, so make sure to set them to zero, if you want the drawing to have the exact size of the target rectangle.
Parameters
painterThe painter to be drawn into.
targetThe rectangle to be filled by the Chart's drawing.
See also
setGlobalLeading

Definition at line 1315 of file KDChartChart.cpp.

References d, KDChart::GlobalMeasureScaling::instance(), invalidateLayoutTree(), KDChart::GlobalMeasureScaling::paintDevice(), KDChart::GlobalMeasureScaling::resetFactors(), KDChart::PrintingParameters::resetScaleFactor(), KDChart::GlobalMeasureScaling::setFactors(), KDChart::GlobalMeasureScaling::setPaintDevice(), and KDChart::PrintingParameters::setScaleFactor().

◆ paintEvent()

void Chart::paintEvent ( QPaintEvent *  event)
overrideprotected

Draws the background and frame, then calls paint().

In most cases there is no need to override this method in a derived class, but if you do, do not forget to call paint().

See also
paint

Definition at line 1415 of file KDChartChart.cpp.

References d, and finishedDrawing().

◆ propertiesChanged

void KDChart::Chart::propertiesChanged ( )
signal

Emitted upon change of a property of the Chart or any of its components.

Referenced by addLegend(), insertCoordinatePlane(), takeCoordinatePlane(), and takeLegend().

◆ reLayoutFloatingLegends()

void Chart::reLayoutFloatingLegends ( )

◆ replaceCoordinatePlane()

void Chart::replaceCoordinatePlane ( AbstractCoordinatePlane plane,
AbstractCoordinatePlane oldPlane = nullptr 
)

Replaces the old coordinate plane, or appends the plane, it there is none yet.

Parameters
planeThe coordinate plane to be used instead of the old plane. This parameter must not be zero, or the method will do nothing.
oldPlaneThe coordinate plane to be removed by the new plane. This plane will be deleted automatically. If the parameter is omitted, the very first coordinate plane will be replaced. In case, there was no plane yet, the new plane will just be added.
Note
If you want to re-use the old coordinate plane, call takeCoordinatePlane and addCoordinatePlane, instead of using replaceCoordinatePlane.
See also
addCoordinatePlane, takeCoordinatePlane

Definition at line 1224 of file KDChartChart.cpp.

References addCoordinatePlane(), d, and takeCoordinatePlane().

◆ replaceHeaderFooter()

void Chart::replaceHeaderFooter ( HeaderFooter headerFooter,
HeaderFooter oldHeaderFooter = nullptr 
)

Replaces the old header (or footer, resp.), or appends the new header or footer, it there is none yet.

Parameters
headerFooterThe header or footer to be used instead of the old one. This parameter must not be zero, or the method will do nothing.
oldHeaderFooterThe header or footer to be removed by the new one. This header or footer will be deleted automatically. If the parameter is omitted, the very first header or footer will be replaced. In case, there was no header and no footer yet, the new header or footer will just be added.
Note
If you want to re-use the old header or footer, call takeHeaderFooter and addHeaderFooter, instead of using replaceHeaderFooter.
See also
addHeaderFooter, takeHeaderFooter

Definition at line 1461 of file KDChartChart.cpp.

References addHeaderFooter(), d, headerFooter(), and takeHeaderFooter().

◆ replaceLegend()

void Chart::replaceLegend ( Legend legend,
Legend oldLegend = nullptr 
)

Replaces the old legend, or appends the new legend, it there is none yet.

Parameters
legendThe legend to be used instead of the old one. This parameter must not be zero, or the method will do nothing.
oldLegendThe legend to be removed by the new one. This legend will be deleted automatically. If the parameter is omitted, the very first legend will be replaced. In case, there was no legend yet, the new legend will just be added.

If you want to re-use the old legend, call takeLegend and addLegend, instead of using replaceLegend.

Note
Whenever addLegend is called the font sizes used by the Legend are set to relative and they get coupled to the Chart's size, with their relative values being 20 for the item texts and 24 to the title text. So if you want to use custom font sizes for the Legend make sure to set them after calling addLegend.
See also
addLegend, takeLegend

Definition at line 1626 of file KDChartChart.cpp.

References addLegend(), d, legend(), and takeLegend().

◆ resizeEvent()

void Chart::resizeEvent ( QResizeEvent *  event)
overrideprotected

Adjusts the internal layout when the chart is resized.

Definition at line 1377 of file KDChartChart.cpp.

References d, and event().

◆ setBackgroundAttributes()

void Chart::setBackgroundAttributes ( const BackgroundAttributes a)

Specify the background attributes to be used, by default there is no background.

To set a light blue background, you could do something like this:

KDChart::BackgroundAttributes backgroundAttrs( my_chart->backgroundAttributes() );
backgroundAttrs.setVisible( true );
backgroundAttrs.setBrush( QColor(0xd0,0xd0,0xff) );
my_chart->setBackgroundAttributes( backgroundAttrs );
See also
setFrameAttributes

Definition at line 1154 of file KDChartChart.cpp.

References d.

◆ setCoordinatePlaneLayout()

void Chart::setCoordinatePlaneLayout ( QLayout *  layout)

Set the coordinate plane layout that should be used as model for the internal used layout. The layout needs to be an instance of QHBoxLayout or QVBoxLayout.

Definition at line 1165 of file KDChartChart.cpp.

References d.

◆ setFrameAttributes()

void Chart::setFrameAttributes ( const FrameAttributes a)

Specify the frame attributes to be used, by default is it a thin black line.

To hide the frame line, you could do something like this:

KDChart::FrameAttributes frameAttrs( my_chart->frameAttributes() );
frameAttrs.setVisible( false );
my_chart->setFrameAttributes( frameAttrs );
See also
setBackgroundAttributes

Definition at line 1144 of file KDChartChart.cpp.

References d.

Referenced by Chart().

◆ setGlobalLeading()

void Chart::setGlobalLeading ( int  left,
int  top,
int  right,
int  bottom 
)

Set the padding between the margin of the widget and the area that the contents are drawn into.

Parameters
leftThe padding on the left side.
topThe padding at the top.
rightThe padding on the left hand side.
bottomThe padding on the bottom.
Note
Using previous versions of KD Chart you might have called setGlobalLeading() to make room for long Abscissa labels (or for an overlapping top label of an Ordinate axis, resp.) that would not fit into the normal axis area. This is no longer needed because KD Chart now is using hidden auto-spacer items reserving as much free space as is needed for axes with overlapping content at the respective sides.
See also
setGlobalLeadingTop, setGlobalLeadingBottom, setGlobalLeadingLeft, setGlobalLeadingRight
globalLeadingTop, globalLeadingBottom, globalLeadingLeft, globalLeadingRight

Definition at line 1259 of file KDChartChart.cpp.

References setGlobalLeadingBottom(), setGlobalLeadingLeft(), setGlobalLeadingRight(), and setGlobalLeadingTop().

◆ setGlobalLeadingBottom()

void Chart::setGlobalLeadingBottom ( int  leading)

Set the padding between the start of the widget and the start of the area that is used for drawing on the bottom.

Parameters
leadingThe padding value.
See also
setGlobalLeading

Definition at line 1303 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

◆ setGlobalLeadingLeft()

void Chart::setGlobalLeadingLeft ( int  leading)

Set the padding between the start of the widget and the start of the area that is used for drawing on the left.

Parameters
leadingThe padding value.
See also
setGlobalLeading

Definition at line 1267 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

◆ setGlobalLeadingRight()

void Chart::setGlobalLeadingRight ( int  leading)

Set the padding between the start of the widget and the start of the area that is used for drawing on the right.

Parameters
leadingThe padding value.
See also
setGlobalLeading

Definition at line 1291 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

◆ setGlobalLeadingTop()

void Chart::setGlobalLeadingTop ( int  leading)

Set the padding between the start of the widget and the start of the area that is used for drawing at the top.

Parameters
leadingThe padding value.
See also
setGlobalLeading

Definition at line 1279 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

◆ setUseNewLayoutSystem()

void Chart::setUseNewLayoutSystem ( bool  value)

Definition at line 1784 of file KDChartChart.cpp.

References useNewLayoutSystem.

◆ takeCoordinatePlane()

void Chart::takeCoordinatePlane ( AbstractCoordinatePlane plane)

Removes the coordinate plane from the chart, without deleting it.

The chart no longer owns the plane, so it is the caller's responsibility to delete the plane.

See also
addCoordinatePlane, takeCoordinatePlane

Definition at line 1242 of file KDChartChart.cpp.

References d, propertiesChanged(), KDChart::AbstractLayoutItem::removeFromParentLayout(), and KDChart::AbstractCoordinatePlane::setParent().

Referenced by replaceCoordinatePlane().

◆ takeHeaderFooter()

void Chart::takeHeaderFooter ( HeaderFooter headerFooter)

Removes the header (or footer, resp.) from the chart, without deleting it.

The chart no longer owns the header or footer, so it is the caller's responsibility to delete the header or footer.

See also
addHeaderFooter, replaceHeaderFooter

Definition at line 1479 of file KDChartChart.cpp.

References d, KDChart::HeaderFooter::destroyedHeaderFooter(), headerFooter(), KDChart::AbstractLayoutItem::removeFromParentLayout(), and KDChart::AbstractLayoutItem::setParentLayout().

Referenced by replaceHeaderFooter().

◆ takeLegend()

void Chart::takeLegend ( Legend legend)

Removes the legend from the chart, without deleting it.

The chart no longer owns the legend, so it is the caller's responsibility to delete the legend.

See also
addLegend, takeLegend

Definition at line 1643 of file KDChartChart.cpp.

References d, legend(), and propertiesChanged().

Referenced by replaceLegend().

◆ useNewLayoutSystem()

bool Chart::useNewLayoutSystem ( ) const

useNewLayoutSystem Be very careful activating the new layout system, its still experimental and works only if the user knows what he is doing. The reason is that the system does not prevent the user from creating sharing graphs that are not layoutable in a plane and still needs assistance from the user.

Definition at line 1780 of file KDChartChart.cpp.

Property Documentation

◆ globalLeadingBottom

int KDChart::Chart::globalLeadingBottom
readwrite

Definition at line 64 of file KDChartChart.h.

◆ globalLeadingLeft

int KDChart::Chart::globalLeadingLeft
readwrite

Definition at line 64 of file KDChartChart.h.

◆ globalLeadingRight

int KDChart::Chart::globalLeadingRight
readwrite

Definition at line 64 of file KDChartChart.h.

◆ globalLeadingTop

int KDChart::Chart::globalLeadingTop
readwrite

Definition at line 64 of file KDChartChart.h.

◆ useNewLayoutSystem

bool KDChart::Chart::useNewLayoutSystem
readwrite

Definition at line 64 of file KDChartChart.h.

Referenced by setUseNewLayoutSystem().


The documentation for this class was generated from the following files:

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated by doxygen 1.9.1