# KDChart::Chart Class Reference

`#include <KDChartChart>`

Inheritance diagram for KDChart::Chart:

[legend]
Collaboration diagram for KDChart::Chart:

[legend]
List of all members.

## 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 layed 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 72 of file KDChartChart.h.

## Signals

void | propertiesChanged ()
| Emitted upon change of a property of the Chart or any of its components.

## Public Member Functions

void | addCoordinatePlane (AbstractCoordinatePlane *plane)
| Adds a coordinate plane to the chart.
void | addHeaderFooter (HeaderFooter *headerFooter)
| Adds a header or a footer to the chart.
void | addLegend (Legend *legend)
| Add the given legend to the chart.
BackgroundAttributes | backgroundAttributes () const
| Chart (QWidget *parent=0)
AbstractCoordinatePlane * | coordinatePlane ()
| Each chart must have at least one coordinate plane.
QLayout * | coordinatePlaneLayout ()
CoordinatePlaneList | coordinatePlanes ()
| The list of coordinate planes.
FrameAttributes | frameAttributes () const
int | globalLeadingBottom () const
| The padding between the start of the widget and the start of the area that is used for drawing at the bottom.
int | globalLeadingLeft () const
| The padding between the start of the widget and the start of the area that is used for drawing on the left.
int | globalLeadingRight () const
| The padding between the start of the widget and the start of the area that is used for drawing on the right.
int | globalLeadingTop () const
| The padding between the start of the widget and the start of the area that is used for drawing at the top.
HeaderFooter * | headerFooter ()
| The first header or footer of the chart.
HeaderFooterList | headerFooters ()
| The list of headers and footers associated with the chart.
Legend * | legend ()
| The first legend of the chart or 0 if there was none added to the chart.
LegendList | legends ()
| The list of all legends associated with the chart.
void | paint (QPainter *painter, const QRect &target)
| Paints all the contents of the chart.
void | reLayoutFloatingLegends ()
void | replaceCoordinatePlane (AbstractCoordinatePlane *plane, AbstractCoordinatePlane *oldPlane=0)
| Replaces the old coordinate plane, or appends the plane, it there is none yet.
void | replaceHeaderFooter (HeaderFooter *headerFooter, HeaderFooter *oldHeaderFooter=0)
| Replaces the old header (or footer, resp.
void | replaceLegend (Legend *legend, Legend *oldLegend=0)
| Replaces the old legend, or appends the new legend, it there is none yet.
void | setBackgroundAttributes (const BackgroundAttributes &a)
| Specify the background attributes to be used, by default there is no background.
void | setCoordinatePlaneLayout (QLayout *layout)
void | setFrameAttributes (const FrameAttributes &a)
| Specify the frame attributes to be used, by default is it a thin black line.
void | 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.
void | 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.
void | 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.
void | 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.
void | 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.
void | takeCoordinatePlane (AbstractCoordinatePlane *plane)
| Removes the coordinate plane from the chart, without deleting it.
void | takeHeaderFooter (HeaderFooter *headerFooter)
| Removes the header (or footer, resp.
void | takeLegend (Legend *legend)
| Removes the legend from the chart, without deleting it.
| ~Chart ()

## Protected Member Functions

void | mouseDoubleClickEvent (QMouseEvent *event)
| reimp
void | mouseMoveEvent (QMouseEvent *event)
| reimp
void | mousePressEvent (QMouseEvent *event)
| reimp
void | mouseReleaseEvent (QMouseEvent *event)
| reimp
void | paintEvent (QPaintEvent *event)
| Draws the background and frame, then calls paint().
void | resizeEvent (QResizeEvent *event)
| Adjusts the internal layout when the chart is resized.

## Properties

int | globalLeadingBottom `[]`
int | globalLeadingLeft `[]`
int | globalLeadingRight `[]`
int | globalLeadingTop `[]`

## Constructor & Destructor Documentation

Chart::Chart | ( | QWidget * | parent = `0` | ) | `[explicit]`

Definition at line 783 of file KDChartChart.cpp.

References addCoordinatePlane(), setFrameAttributes(), KDChart::FrameAttributes::setPadding(), KDChart::FrameAttributes::setPen(), and KDChart::FrameAttributes::setVisible().

    00784     : QWidget ( parent )
    00785     , _d( new Private( this ) )
    00786 {
    00787 #if defined KDAB_EVAL
    00788     EvalDialog::checkEvalLicense( "KD Chart" );
    00789 #endif
    00790
    00791     FrameAttributes frameAttrs;
    00792     frameAttrs.setVisible( true );
    00793     frameAttrs.setPen( QPen( Qt::black ) );
    00794     frameAttrs.setPadding( 1 );
    00795     setFrameAttributes( frameAttrs );
    00796
    00797     addCoordinatePlane( new CartesianCoordinatePlane ( this ) );
    00798 }

Chart::~Chart | ( |  | ) |

Definition at line 800 of file KDChartChart.cpp.

    00801 {
    00802     delete _d;
    00803 }

## Member Function Documentation

void Chart::addCoordinatePlane | ( | AbstractCoordinatePlane * | plane | ) |

Adds a coordinate plane to the chart.

The chart takes ownership.

Parameters:

  | plane | The coordinate plane to add.

See also:
  replaceCoordinatePlane, takeCoordinatePlane

Definition at line 848 of file KDChartChart.cpp.

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

Referenced by Chart(), and replaceCoordinatePlane().

    00849 {
    00850     connect( plane, SIGNAL( destroyedCoordinatePlane( AbstractCoordinatePlane* ) ),
    00851              d,   SLOT( slotUnregisterDestroyedPlane( AbstractCoordinatePlane* ) ) );
    00852     connect( plane, SIGNAL( needUpdate() ),       this,   SLOT( update() ) );
    00853     connect( plane, SIGNAL( needRelayout() ),     d,      SLOT( slotRelayout() ) ) ;
    00854     connect( plane, SIGNAL( needLayoutPlanes() ), d,      SLOT( slotLayoutPlanes() ) ) ;
    00855     connect( plane, SIGNAL( propertiesChanged() ),this, SIGNAL( propertiesChanged() ) );
    00856     d->coordinatePlanes.append( plane );
    00857     plane->setParent( this );
    00858     d->slotLayoutPlanes();
    00859 }

void Chart::addHeaderFooter | ( | HeaderFooter * | headerFooter | ) |

Adds a header or a footer to the chart.

The chart takes ownership.

Parameters:

  | headerFooter | The header (or footer, resp.) to add.

See also:
  replaceHeaderFooter, takeHeaderFooter

Definition at line 1057 of file KDChartChart.cpp.

References d, headerFooter(), and KDChart::HeaderFooter::setParent().

Referenced by replaceHeaderFooter().

    01058 {
    01059     d->headerFooters.append( headerFooter );
    01060     headerFooter->setParent( this );
    01061     connect( headerFooter, SIGNAL( destroyedHeaderFooter( HeaderFooter* ) ),
    01062              d, SLOT( slotUnregisterDestroyedHeaderFooter( HeaderFooter* ) ) );
    01063     connect( headerFooter, SIGNAL( positionChanged( HeaderFooter* ) ),
    01064              d, SLOT( slotRelayout() ) );
    01065     d->slotRelayout();
    01066 }

void Chart::addLegend | ( | Legend * | legend | ) |

Add the given legend to the chart.

The chart takes ownership.

Parameters:

  | legend | The legend to add.

See also:
  replaceLegend, takeLegend

Definition at line 1109 of file KDChartChart.cpp.

References d, legend(), KDChartEnums::MeasureOrientationMinimum, propertiesChanged(), KDChart::TextAttributes::setFontSize(), KDChart::Legend::setReferenceArea(), KDChart::Legend::setTextAttributes(), KDChart::Legend::setTitleTextAttributes(), KDChart::Legend::setVisible(), KDChart::Legend::textAttributes(), and KDChart::Legend::titleTextAttributes().

Referenced by replaceLegend().

    01110 {
    01111     if( ! legend ) return;
    01112
    01113     //qDebug() << "adding the legend";
    01114     d->legends.append( legend );
    01115     legend->setParent( this );
    01116
    01117     TextAttributes textAttrs( legend->textAttributes() );
    01118
    01119     KDChart::Measure measure( textAttrs.fontSize() );
    01120     measure.setRelativeMode( this, KDChartEnums::MeasureOrientationMinimum );
    01121     measure.setValue( 20 );
    01122     textAttrs.setFontSize( measure );
    01123     legend->setTextAttributes( textAttrs );
    01124
    01125     textAttrs = legend->titleTextAttributes();
    01126     measure.setRelativeMode( this, KDChartEnums::MeasureOrientationMinimum );
    01127     measure.setValue( 24 );
    01128     textAttrs.setFontSize( measure );
    01129
    01130     legend->setTitleTextAttributes( textAttrs );
    01131
    01132     legend->setReferenceArea( this );
    01133
    01134 /*
    01135     future: Use relative sizes for the markers too!
    01136
    01137     const uint nMA = Legend::datasetCount();
    01138     for( uint iMA = 0; iMA < nMA; ++iMA ){
    01139         MarkerAttributes ma( legend->markerAttributes( iMA ) );
    01140         ma.setMarkerSize( ... )
    01141         legend->setMarkerAttributes( iMA, ma )
    01142     }
    01143 */
    01144
    01145     connect( legend, SIGNAL( destroyedLegend( Legend* ) ),
    01146              d, SLOT( slotUnregisterDestroyedLegend( Legend* ) ) );
    01147     connect( legend, SIGNAL( positionChanged( AbstractAreaWidget* ) ),
    01148              d, SLOT( slotLayoutPlanes() ) ); //slotRelayout() ) );
    01149     connect( legend, SIGNAL( propertiesChanged() ),this, SIGNAL( propertiesChanged() ) );
    01150     legend->setVisible( true );
    01151     d->slotRelayout();
    01152 }

BackgroundAttributes Chart::backgroundAttributes | ( |  | ) | const

Definition at line 822 of file KDChartChart.cpp.

References d.

    00823 {
    00824     return d->backgroundAttributes;
    00825 }

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 832 of file KDChartChart.cpp.

References d.

    00833 {
    00834     if ( d->coordinatePlanes.isEmpty() )
    00835     {
    00836         qWarning() << "Chart::coordinatePlane: warning: no coordinate plane defined.";
    00837         return 0;
    00838     } else {
    00839         return d->coordinatePlanes.first();
    00840     }
    00841 }

QLayout * Chart::coordinatePlaneLayout | ( |  | ) |

Definition at line 827 of file KDChartChart.cpp.

References d.

    00828 {
    00829     return d->planesLayout;
    00830 }

CoordinatePlaneList Chart::coordinatePlanes | ( |  | ) |

The list of coordinate planes.

Returns:
  The list of coordinate planes.

Definition at line 843 of file KDChartChart.cpp.

References d.

    00844 {
    00845     return d->coordinatePlanes;
    00846 }

FrameAttributes Chart::frameAttributes | ( |  | ) | const

Definition at line 812 of file KDChartChart.cpp.

References d.

    00813 {
    00814     return d->frameAttributes;
    00815 }

int KDChart::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

int KDChart::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

int KDChart::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

int KDChart::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

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 1095 of file KDChartChart.cpp.

References d.

Referenced by addHeaderFooter(), replaceHeaderFooter(), and takeHeaderFooter().

    01096 {
    01097     if( d->headerFooters.isEmpty() ) {
    01098         return 0;
    01099     } else {
    01100         return d->headerFooters.first();
    01101     }
    01102 }

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 1104 of file KDChartChart.cpp.

References d.

    01105 {
    01106     return d->headerFooters;
    01107 }

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 1181 of file KDChartChart.cpp.

References d.

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

    01182 {
    01183     if ( d->legends.isEmpty() )
    01184     {
    01185         return 0;
    01186     } else {
    01187         return d->legends.first();
    01188     }
    01189 }

LegendList Chart::legends | ( |  | ) |

The list of all legends associated with the chart.

Returns:
  The list of all legends associated with the chart.

Definition at line 1191 of file KDChartChart.cpp.

References d.

    01192 {
    01193     return d->legends;
    01194 }

void Chart::mouseDoubleClickEvent | ( | QMouseEvent * | event | ) | `[protected]`

reimp

Definition at line 1388 of file KDChartChart.cpp.

References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mouseDoubleClickEvent().

    01389 {
    01390     const QPoint pos = mapFromGlobal( event->globalPos() );
    01391
    01392     KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes )
    01393     {
    01394         if ( plane->geometry().contains( event->pos() ) )
    01395         {
    01396             if ( plane->diagrams().size() > 0 )
    01397             {
    01398                 QMouseEvent ev( QEvent::MouseButtonPress, pos, event->globalPos(),
    01399                                 event->button(), event->buttons(),
    01400                                 event->modifiers() );
    01401                 plane->mouseDoubleClickEvent( &ev );
    01402             }
    01403         }
    01404     }
    01405 }

void Chart::mouseMoveEvent | ( | QMouseEvent * | event | ) | `[protected]`

reimp

Definition at line 1407 of file KDChartChart.cpp.

References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mouseMoveEvent().

    01408 {
    01409     QSet< AbstractCoordinatePlane* > eventReceivers = QSet< AbstractCoordinatePlane* >::fromList( d->mouseClickedPlanes );
    01410
    01411     KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes )
    01412     {
    01413         if( plane->geometry().contains( event->pos() ) )
    01414         {
    01415             if( plane->diagrams().size() > 0 )
    01416             {
    01417                 eventReceivers.insert( plane );
    01418             }
    01419         }
    01420     }
    01421
    01422     const QPoint pos = mapFromGlobal( event->globalPos() );
    01423
    01424     KDAB_FOREACH( AbstractCoordinatePlane* plane, eventReceivers )
    01425     {
    01426         QMouseEvent ev( QEvent::MouseMove, pos, event->globalPos(),
    01427                          event->button(), event->buttons(),
    01428                          event->modifiers() );
    01429         plane->mouseMoveEvent( &ev );
    01430     }
    01431 }

void Chart::mousePressEvent | ( | QMouseEvent * | event | ) | `[protected]`

reimp

Definition at line 1197 of file KDChartChart.cpp.

References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mousePressEvent().

    01198 {
    01199     const QPoint pos = mapFromGlobal( event->globalPos() );
    01200
    01201     KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes )
    01202     {
    01203         if ( plane->geometry().contains( event->pos() ) )
    01204         {
    01205             if ( plane->diagrams().size() > 0 )
    01206             {
    01207                 QMouseEvent ev( QEvent::MouseButtonPress, pos, event->globalPos(),
    01208                                 event->button(), event->buttons(),
    01209                                 event->modifiers() );
    01210
    01211                 plane->mousePressEvent( &ev );
    01212                 d->mouseClickedPlanes.append( plane );
    01213            }
    01214        }
    01215     }
    01216 }

void Chart::mouseReleaseEvent | ( | QMouseEvent * | event | ) | `[protected]`

reimp

Definition at line 1433 of file KDChartChart.cpp.

References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mouseReleaseEvent().

    01434 {
    01435     QSet< AbstractCoordinatePlane* > eventReceivers = QSet< AbstractCoordinatePlane* >::fromList( d->mouseClickedPlanes );
    01436
    01437     KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes )
    01438     {
    01439         if ( plane->geometry().contains( event->pos() ) )
    01440         {
    01441             if( plane->diagrams().size() > 0 )
    01442             {
    01443                 eventReceivers.insert( plane );
    01444             }
    01445         }
    01446     }
    01447
    01448     const QPoint pos = mapFromGlobal( event->globalPos() );
    01449
    01450     KDAB_FOREACH( AbstractCoordinatePlane* plane, eventReceivers )
    01451     {
    01452         QMouseEvent ev( QEvent::MouseButtonRelease, pos, event->globalPos(),
    01453                          event->button(), event->buttons(),
    01454                          event->modifiers() );
    01455         plane->mouseReleaseEvent( &ev );
    01456     }
    01457
    01458     d->mouseClickedPlanes.clear();
    01459 }

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:

  | painter | The painter to be drawn into.
  | target | The rectangle to be filled by the Chart's drawing.

See also:
  setGlobalLeading

Definition at line 942 of file KDChartChart.cpp.

References d, KDChart::GlobalMeasureScaling::instance(), legend(), KDChart::AbstractAreaWidget::paintIntoRect(), KDChart::GlobalMeasureScaling::resetFactors(), KDChart::GlobalMeasureScaling::setFactors(), and KDChart::GlobalMeasureScaling::setPaintDevice().

    00943 {
    00944     if( target.isEmpty() || !painter ) return;
    00945     //qDebug() << "Chart::paint( ..," << target << ")";
    00946
    00947     GlobalMeasureScaling::setPaintDevice( painter->device() );
    00948
    00949     // Output on a widget
    00950     if( dynamic_cast< QWidget* >( painter->device() ) != 0 )
    00951     {
    00952         GlobalMeasureScaling::setFactors(
    00953                 static_cast< qreal >( target.width() ) /
    00954                 static_cast< qreal >( geometry().size().width() ),
    00955                 static_cast< qreal >( target.height() ) /
    00956                 static_cast< qreal >( geometry().size().height() ) );
    00957     }
    00958     // Output onto a QPixmap
    00959     else
    00960     {
    00961         const qreal resX = static_cast< qreal >( logicalDpiX() ) / static_cast< qreal >( painter->device()->logicalDpiX() );
    00962         const qreal resY = static_cast< qreal >( logicalDpiY() ) / static_cast< qreal >( painter->device()->logicalDpiY() );
    00963
    00964         GlobalMeasureScaling::setFactors(
    00965                 static_cast< qreal >( target.width() ) /
    00966                 static_cast< qreal >( geometry().size().width() ) * resX,
    00967                 static_cast< qreal >( target.height() ) /
    00968                 static_cast< qreal >( geometry().size().height() ) * resY );
    00969     }
    00970
    00971
    00972     if( target.size() != d->currentLayoutSize ){
    00973         d->resizeLayout( target.size() );
    00974     }
    00975     const QPoint translation = target.topLeft();
    00976     painter->translate( translation );
    00977
    00978     d->paintAll( painter );
    00979
    00980     // for debugging:
    00981     //painter->setPen(QPen(Qt::blue, 8));
    00982     //painter->drawRect(target.adjusted(12,12,-12,-12));
    00983
    00984     KDAB_FOREACH( Legend *legend, d->legends ) {
    00985         const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide);
    00986         if ( !hidden ) {
    00987             //qDebug() << "painting legend at " << legend->geometry();
    00988             legend->paintIntoRect( *painter, legend->geometry() );
    00989             //testing:
    00990             //legend->paintIntoRect( *painter, legend->geometry().adjusted(-100,0,-100,0) );
    00991         }
    00992     }
    00993
    00994     painter->translate( -translation.x(), -translation.y() );
    00995
    00996     GlobalMeasureScaling::instance()->resetFactors();
    00997
    00998     //qDebug() << "KDChart::Chart::paint() done.\n";
    00999 }

void Chart::paintEvent | ( | QPaintEvent * | event | ) | `[protected]`

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 1043 of file KDChartChart.cpp.

References d, and reLayoutFloatingLegends().

    01044 {
    01045     QPainter painter( this );
    01046
    01047     if( size() != d->currentLayoutSize ){
    01048         d->resizeLayout( size() );
    01049         reLayoutFloatingLegends();
    01050     }
    01051
    01052     //FIXME(khz): Paint the background/frame too!
    01053     //            (can we derive Chart from AreaWidget ??)
    01054     d->paintAll( &painter );
    01055 }

void KDChart::Chart::propertiesChanged | ( |  | ) | `[signal]`

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

Referenced by addCoordinatePlane(), and addLegend().

void Chart::reLayoutFloatingLegends | ( |  | ) |

Definition at line 1011 of file KDChartChart.cpp.

References d, KDChart::Legend::floatingPosition(), KDChart::Position::isFloating(), legend(), KDChart::Legend::position(), and KDChart::Legend::sizeHint().

Referenced by paintEvent(), and resizeEvent().

    01012 {
    01013     KDAB_FOREACH( Legend *legend, d->legends ) {
    01014         const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide);
    01015         if ( legend->position().isFloating() && !hidden ){
    01016             // resize the legend
    01017             const QSize legendSize( legend->sizeHint() );
    01018             legend->setGeometry( QRect( legend->geometry().topLeft(), legendSize ) );
    01019             // find the legends corner point (reference point plus any paddings)
    01020             const RelativePosition relPos( legend->floatingPosition() );
    01021             QPointF pt( relPos.calculatedPoint( size() ) );
    01022             qDebug() << pt;
    01023             // calculate the legend's top left point
    01024             const Qt::Alignment alignTopLeft = Qt::AlignBottom | Qt::AlignLeft;
    01025             if( (relPos.alignment() & alignTopLeft) != alignTopLeft ){
    01026                 if( relPos.alignment() & Qt::AlignRight )
    01027                     pt.rx() -= legendSize.width();
    01028                 else if( relPos.alignment() & Qt::AlignHCenter )
    01029                     pt.rx() -= 0.5 * legendSize.width();
    01030
    01031                 if( relPos.alignment() & Qt::AlignBottom )
    01032                     pt.ry() -= legendSize.height();
    01033                 else if( relPos.alignment() & Qt::AlignVCenter )
    01034                     pt.ry() -= 0.5 * legendSize.height();
    01035             }
    01036             qDebug() << pt << endl;
    01037             legend->move( static_cast<int>(pt.x()), static_cast<int>(pt.y()) );
    01038         }
    01039     }
    01040 }

void Chart::replaceCoordinatePlane | ( | AbstractCoordinatePlane * | plane,
|  | AbstractCoordinatePlane * | oldPlane = `0` |
| ) |  |  |

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

Parameters:

  | plane | The coordinate plane to be used instead of the old plane. This parameter must not be zero, or the method will do nothing.
  | oldPlane | The 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 861 of file KDChartChart.cpp.

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

    00863 {
    00864     if( plane && oldPlane_ != plane ){
    00865         AbstractCoordinatePlane* oldPlane = oldPlane_;
    00866         if( d->coordinatePlanes.count() ){
    00867             if( ! oldPlane )
    00868                 oldPlane = d->coordinatePlanes.first();
    00869             takeCoordinatePlane( oldPlane );
    00870         }
    00871         delete oldPlane;
    00872         addCoordinatePlane( plane );
    00873     }
    00874 }

void Chart::replaceHeaderFooter | ( | HeaderFooter * | headerFooter,
|  | HeaderFooter * | oldHeaderFooter = `0` |
| ) |  |  |

Replaces the old header (or footer, resp.

), or appends the new header or footer, it there is none yet.

Parameters:

  | headerFooter | The header or footer to be used instead of the old one. This parameter must not be zero, or the method will do nothing.
  | oldHeaderFooter | The 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 1068 of file KDChartChart.cpp.

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

    01070 {
    01071     if( headerFooter && oldHeaderFooter_ != headerFooter ){
    01072         HeaderFooter* oldHeaderFooter = oldHeaderFooter_;
    01073         if( d->headerFooters.count() ){
    01074             if( ! oldHeaderFooter )
    01075                 oldHeaderFooter =  d->headerFooters.first();
    01076             takeHeaderFooter( oldHeaderFooter );
    01077         }
    01078         delete oldHeaderFooter;
    01079         addHeaderFooter( headerFooter );
    01080     }
    01081 }

void Chart::replaceLegend | ( | Legend * | legend,
|  | Legend * | oldLegend = `0` |
| ) |  |  |

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

Parameters:

  | legend | The legend to be used instead of the old one. This parameter must not be zero, or the method will do nothing.
  | oldLegend | The 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 1155 of file KDChartChart.cpp.

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

    01156 {
    01157     if( legend && oldLegend_ != legend ){
    01158         Legend* oldLegend = oldLegend_;
    01159         if( d->legends.count() ){
    01160             if( ! oldLegend )
    01161                 oldLegend = d->legends.first();
    01162             takeLegend( oldLegend );
    01163         }
    01164         delete oldLegend;
    01165         addLegend( legend );
    01166     }
    01167 }

void Chart::resizeEvent | ( | QResizeEvent * | event | ) | `[protected]`

Adjusts the internal layout when the chart is resized.

Definition at line 1001 of file KDChartChart.cpp.

References d, reLayoutFloatingLegends(), and KDChart::AbstractCoordinatePlane::setGridNeedsRecalculate().

    01002 {
    01003     d->resizeLayout( size() );
    01004     KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ){
    01005         plane->setGridNeedsRecalculate();
    01006     }
    01007     reLayoutFloatingLegends();
    01008 }

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 817 of file KDChartChart.cpp.

References d.

    00818 {
    00819     d->backgroundAttributes = a;
    00820 }

void KDChart::Chart::setCoordinatePlaneLayout | ( | QLayout * | layout | ) |

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 807 of file KDChartChart.cpp.

References d.

Referenced by Chart().

    00808 {
    00809     d->frameAttributes = a;
    00810 }

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:

  | left | The padding on the left side.
  | top | The padding at the top.
  | right | The padding on the left hand side.
  | bottom | The 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 overlaping content at the respective sides.

See also:
  setGlobalLeadingTop, setGlobalLeadingBottom, setGlobalLeadingLeft, setGlobalLeadingRight

  globalLeadingTop, globalLeadingBottom, globalLeadingLeft, globalLeadingRight

Definition at line 889 of file KDChartChart.cpp.

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

    00890 {
    00891     setGlobalLeadingLeft( left );
    00892     setGlobalLeadingTop( top );
    00893     setGlobalLeadingRight( right );
    00894     setGlobalLeadingBottom( bottom );
    00895     d->slotRelayout();
    00896 }

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:

  | leading | The padding value.

See also:
  setGlobalLeading

Definition at line 931 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

    00932 {
    00933     d->globalLeadingBottom = leading;
    00934     d->slotRelayout();
    00935 }

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:

  | leading | The padding value.

See also:
  setGlobalLeading

Definition at line 898 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

    00899 {
    00900     d->globalLeadingLeft = leading;
    00901     d->slotRelayout();
    00902 }

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:

  | leading | The padding value.

See also:
  setGlobalLeading

Definition at line 920 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

    00921 {
    00922     d->globalLeadingRight = leading;
    00923     d->slotRelayout();
    00924 }

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:

  | leading | The padding value.

See also:
  setGlobalLeading

Definition at line 909 of file KDChartChart.cpp.

References d.

Referenced by setGlobalLeading().

    00910 {
    00911     d->globalLeadingTop = leading;
    00912     d->slotRelayout();
    00913 }

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 876 of file KDChartChart.cpp.

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

Referenced by replaceCoordinatePlane().

    00877 {
    00878     const int idx = d->coordinatePlanes.indexOf( plane );
    00879     if( idx != -1 ){
    00880         d->coordinatePlanes.takeAt( idx );
    00881         disconnect( plane, SIGNAL( destroyedCoordinatePlane( AbstractCoordinatePlane* ) ),
    00882                     d, SLOT( slotUnregisterDestroyedPlane( AbstractCoordinatePlane* ) ) );
    00883         plane->removeFromParentLayout();
    00884         plane->setParent( 0 );
    00885     }
    00886     d->slotLayoutPlanes();
    00887 }

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 1083 of file KDChartChart.cpp.

References d, headerFooter(), and KDChart::HeaderFooter::setParent().

Referenced by replaceHeaderFooter().

    01084 {
    01085     const int idx = d->headerFooters.indexOf( headerFooter );
    01086     if( idx != -1 ){
    01087         d->headerFooters.takeAt( idx );
    01088         disconnect( headerFooter, SIGNAL( destroyedHeaderFooter( HeaderFooter* ) ),
    01089                     d, SLOT( slotUnregisterDestroyedHeaderFooter( HeaderFooter* ) ) );
    01090         headerFooter->setParent( 0 );
    01091     }
    01092     d->slotRelayout();
    01093 }

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 1169 of file KDChartChart.cpp.

References d, and legend().

Referenced by replaceLegend().

    01170 {
    01171     const int idx = d->legends.indexOf( legend );
    01172     if( idx != -1 ){
    01173         d->legends.takeAt( idx );
    01174         disconnect( legend, SIGNAL( destroyedLegend( Legend* ) ),
    01175                     d, SLOT( slotUnregisterDestroyedLegend( Legend* ) ) );
    01176         legend->setParent( 0 );
    01177     }
    01178     d->slotRelayout();
    01179 }

## Property Documentation

int Chart::globalLeadingBottom`[read, write]`

Definition at line 76 of file KDChartChart.h.

int Chart::globalLeadingLeft`[read, write]`

Definition at line 77 of file KDChartChart.h.

int Chart::globalLeadingRight`[read, write]`

Definition at line 78 of file KDChartChart.h.

int Chart::globalLeadingTop`[read, write]`

Definition at line 75 of file KDChartChart.h.

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

- KDChartChart.h
- KDChartChart.cpp