#include <KDChartChart>
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 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) |
Set the coordinate plane layout that should be used as model for the internal used 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 | |
bool | event (QEvent *event) |
reimp | |
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 |
Chart::Chart | ( | QWidget * | parent = 0 |
) | [explicit] |
Definition at line 861 of file KDChartChart.cpp.
References addCoordinatePlane(), setFrameAttributes(), KDChart::FrameAttributes::setPadding(), and KDChart::FrameAttributes::setPen().
00862 : QWidget ( parent ) 00863 , _d( new Private( this ) ) 00864 { 00865 FrameAttributes frameAttrs; 00866 // no frame per default... 00867 // frameAttrs.setVisible( true ); 00868 frameAttrs.setPen( QPen( Qt::black ) ); 00869 frameAttrs.setPadding( 1 ); 00870 setFrameAttributes( frameAttrs ); 00871 00872 addCoordinatePlane( new CartesianCoordinatePlane ( this ) ); 00873 }
Chart::~Chart | ( | ) |
void Chart::addCoordinatePlane | ( | AbstractCoordinatePlane * | plane | ) |
Adds a coordinate plane to the chart.
The chart takes ownership.
plane | The coordinate plane to add. |
Definition at line 931 of file KDChartChart.cpp.
References d, propertiesChanged(), and KDChart::AbstractCoordinatePlane::setParent().
Referenced by Chart(), and replaceCoordinatePlane().
00932 { 00933 connect( plane, SIGNAL( destroyedCoordinatePlane( AbstractCoordinatePlane* ) ), 00934 d, SLOT( slotUnregisterDestroyedPlane( AbstractCoordinatePlane* ) ) ); 00935 connect( plane, SIGNAL( needUpdate() ), this, SLOT( update() ) ); 00936 connect( plane, SIGNAL( needRelayout() ), d, SLOT( slotRelayout() ) ) ; 00937 connect( plane, SIGNAL( needLayoutPlanes() ), d, SLOT( slotLayoutPlanes() ) ) ; 00938 connect( plane, SIGNAL( propertiesChanged() ),this, SIGNAL( propertiesChanged() ) ); 00939 d->coordinatePlanes.append( plane ); 00940 plane->setParent( this ); 00941 d->slotLayoutPlanes(); 00942 }
void Chart::addHeaderFooter | ( | HeaderFooter * | headerFooter | ) |
Adds a header or a footer to the chart.
The chart takes ownership.
headerFooter | The header (or footer, resp.) to add. |
Definition at line 1151 of file KDChartChart.cpp.
References d, and KDChart::HeaderFooter::setParent().
Referenced by replaceHeaderFooter().
01152 { 01153 d->headerFooters.append( headerFooter ); 01154 headerFooter->setParent( this ); 01155 connect( headerFooter, SIGNAL( destroyedHeaderFooter( HeaderFooter* ) ), 01156 d, SLOT( slotUnregisterDestroyedHeaderFooter( HeaderFooter* ) ) ); 01157 connect( headerFooter, SIGNAL( positionChanged( HeaderFooter* ) ), 01158 d, SLOT( slotRelayout() ) ); 01159 d->slotRelayout(); 01160 }
void Chart::addLegend | ( | Legend * | legend | ) |
Add the given legend to the chart.
The chart takes ownership.
legend | The legend to add. |
Definition at line 1209 of file KDChartChart.cpp.
References d, 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().
01210 { 01211 if( ! legend ) return; 01212 01213 //qDebug() << "adding the legend"; 01214 d->legends.append( legend ); 01215 legend->setParent( this ); 01216 01217 TextAttributes textAttrs( legend->textAttributes() ); 01218 01219 KDChart::Measure measure( textAttrs.fontSize() ); 01220 measure.setRelativeMode( this, KDChartEnums::MeasureOrientationMinimum ); 01221 measure.setValue( 20 ); 01222 textAttrs.setFontSize( measure ); 01223 legend->setTextAttributes( textAttrs ); 01224 01225 textAttrs = legend->titleTextAttributes(); 01226 measure.setRelativeMode( this, KDChartEnums::MeasureOrientationMinimum ); 01227 measure.setValue( 24 ); 01228 textAttrs.setFontSize( measure ); 01229 01230 legend->setTitleTextAttributes( textAttrs ); 01231 01232 legend->setReferenceArea( this ); 01233 01234 /* 01235 future: Use relative sizes for the markers too! 01236 01237 const uint nMA = Legend::datasetCount(); 01238 for( uint iMA = 0; iMA < nMA; ++iMA ){ 01239 MarkerAttributes ma( legend->markerAttributes( iMA ) ); 01240 ma.setMarkerSize( ... ) 01241 legend->setMarkerAttributes( iMA, ma ) 01242 } 01243 */ 01244 01245 connect( legend, SIGNAL( destroyedLegend( Legend* ) ), 01246 d, SLOT( slotUnregisterDestroyedLegend( Legend* ) ) ); 01247 connect( legend, SIGNAL( positionChanged( AbstractAreaWidget* ) ), 01248 d, SLOT( slotLayoutPlanes() ) ); //slotRelayout() ) ); 01249 connect( legend, SIGNAL( propertiesChanged() ), 01250 this, SIGNAL( propertiesChanged() ) ); 01251 legend->setVisible( true ); 01252 d->slotRelayout(); 01253 }
BackgroundAttributes Chart::backgroundAttributes | ( | ) | const |
Definition at line 897 of file KDChartChart.cpp.
References d.
00898 { 00899 return d->backgroundAttributes; 00900 }
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.
Definition at line 915 of file KDChartChart.cpp.
References d.
00916 { 00917 if ( d->coordinatePlanes.isEmpty() ) 00918 { 00919 qWarning() << "Chart::coordinatePlane: warning: no coordinate plane defined."; 00920 return 0; 00921 } else { 00922 return d->coordinatePlanes.first(); 00923 } 00924 }
QLayout * Chart::coordinatePlaneLayout | ( | ) |
Definition at line 910 of file KDChartChart.cpp.
References d.
00911 { 00912 return d->planesLayout; 00913 }
CoordinatePlaneList Chart::coordinatePlanes | ( | ) |
The list of coordinate planes.
Definition at line 926 of file KDChartChart.cpp.
References d.
00927 { 00928 return d->coordinatePlanes; 00929 }
bool Chart::event | ( | QEvent * | event | ) | [protected] |
reimp
Definition at line 1576 of file KDChartChart.cpp.
References d, KDChart::AbstractCoordinatePlane::diagrams(), and KDChart::AbstractDiagram::indexAt().
01577 { 01578 switch( event->type() ) 01579 { 01580 case QEvent::ToolTip: 01581 { 01582 const QHelpEvent* const helpEvent = static_cast< QHelpEvent* >( event ); 01583 KDAB_FOREACH( const AbstractCoordinatePlane* const plane, d->coordinatePlanes ) 01584 { 01585 KDAB_FOREACH( const AbstractDiagram* const diag, plane->diagrams() ) 01586 { 01587 const QModelIndex index = diag->indexAt( helpEvent->pos() ); 01588 const QVariant toolTip = index.data( Qt::ToolTipRole ); 01589 if( toolTip.isValid() ) 01590 { 01591 QToolTip::showText( helpEvent->globalPos(), toolTip.toString() ); 01592 return true; 01593 } 01594 } 01595 } 01596 // fall-through intended 01597 } 01598 default: 01599 return QWidget::event( event ); 01600 } 01601 }
FrameAttributes Chart::frameAttributes | ( | ) | const |
Definition at line 887 of file KDChartChart.cpp.
References d.
00888 { 00889 return d->frameAttributes; 00890 }
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.
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.
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.
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.
HeaderFooter * Chart::headerFooter | ( | ) |
The first header or footer of the chart.
By default there is none.
Definition at line 1195 of file KDChartChart.cpp.
References d.
01196 { 01197 if( d->headerFooters.isEmpty() ) { 01198 return 0; 01199 } else { 01200 return d->headerFooters.first(); 01201 } 01202 }
HeaderFooterList Chart::headerFooters | ( | ) |
The list of headers and footers associated with the chart.
Definition at line 1204 of file KDChartChart.cpp.
References d.
01205 { 01206 return d->headerFooters; 01207 }
Legend * Chart::legend | ( | ) |
The first legend of the chart or 0 if there was none added to the chart.
Definition at line 1296 of file KDChartChart.cpp.
References d.
01297 { 01298 if ( d->legends.isEmpty() ) 01299 { 01300 return 0; 01301 } else { 01302 return d->legends.first(); 01303 } 01304 }
LegendList Chart::legends | ( | ) |
The list of all legends associated with the chart.
Definition at line 1306 of file KDChartChart.cpp.
References d.
01307 { 01308 return d->legends; 01309 }
void Chart::mouseDoubleClickEvent | ( | QMouseEvent * | event | ) | [protected] |
reimp
Definition at line 1503 of file KDChartChart.cpp.
References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mouseDoubleClickEvent().
01504 { 01505 const QPoint pos = mapFromGlobal( event->globalPos() ); 01506 01507 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ) 01508 { 01509 if ( plane->geometry().contains( event->pos() ) ) 01510 { 01511 if ( plane->diagrams().size() > 0 ) 01512 { 01513 QMouseEvent ev( QEvent::MouseButtonPress, pos, event->globalPos(), 01514 event->button(), event->buttons(), 01515 event->modifiers() ); 01516 plane->mouseDoubleClickEvent( &ev ); 01517 } 01518 } 01519 } 01520 }
void Chart::mouseMoveEvent | ( | QMouseEvent * | event | ) | [protected] |
reimp
Definition at line 1522 of file KDChartChart.cpp.
References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mouseMoveEvent().
01523 { 01524 QSet< AbstractCoordinatePlane* > eventReceivers = QSet< AbstractCoordinatePlane* >::fromList( d->mouseClickedPlanes ); 01525 01526 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ) 01527 { 01528 if( plane->geometry().contains( event->pos() ) ) 01529 { 01530 if( plane->diagrams().size() > 0 ) 01531 { 01532 eventReceivers.insert( plane ); 01533 } 01534 } 01535 } 01536 01537 const QPoint pos = mapFromGlobal( event->globalPos() ); 01538 01539 KDAB_FOREACH( AbstractCoordinatePlane* plane, eventReceivers ) 01540 { 01541 QMouseEvent ev( QEvent::MouseMove, pos, event->globalPos(), 01542 event->button(), event->buttons(), 01543 event->modifiers() ); 01544 plane->mouseMoveEvent( &ev ); 01545 } 01546 }
void Chart::mousePressEvent | ( | QMouseEvent * | event | ) | [protected] |
reimp
Definition at line 1312 of file KDChartChart.cpp.
References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mousePressEvent().
01313 { 01314 const QPoint pos = mapFromGlobal( event->globalPos() ); 01315 01316 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ) 01317 { 01318 if ( plane->geometry().contains( event->pos() ) ) 01319 { 01320 if ( plane->diagrams().size() > 0 ) 01321 { 01322 QMouseEvent ev( QEvent::MouseButtonPress, pos, event->globalPos(), 01323 event->button(), event->buttons(), 01324 event->modifiers() ); 01325 01326 plane->mousePressEvent( &ev ); 01327 d->mouseClickedPlanes.append( plane ); 01328 } 01329 } 01330 } 01331 }
void Chart::mouseReleaseEvent | ( | QMouseEvent * | event | ) | [protected] |
reimp
Definition at line 1548 of file KDChartChart.cpp.
References d, KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mouseReleaseEvent().
01549 { 01550 QSet< AbstractCoordinatePlane* > eventReceivers = QSet< AbstractCoordinatePlane* >::fromList( d->mouseClickedPlanes ); 01551 01552 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ) 01553 { 01554 if ( plane->geometry().contains( event->pos() ) ) 01555 { 01556 if( plane->diagrams().size() > 0 ) 01557 { 01558 eventReceivers.insert( plane ); 01559 } 01560 } 01561 } 01562 01563 const QPoint pos = mapFromGlobal( event->globalPos() ); 01564 01565 KDAB_FOREACH( AbstractCoordinatePlane* plane, eventReceivers ) 01566 { 01567 QMouseEvent ev( QEvent::MouseButtonRelease, pos, event->globalPos(), 01568 event->button(), event->buttons(), 01569 event->modifiers() ); 01570 plane->mouseReleaseEvent( &ev ); 01571 } 01572 01573 d->mouseClickedPlanes.clear(); 01574 }
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.
painter | The painter to be drawn into. | |
target | The rectangle to be filled by the Chart's drawing. |
Definition at line 1031 of file KDChartChart.cpp.
References d, KDChart::GlobalMeasureScaling::instance(), KDChart::GlobalMeasureScaling::paintDevice(), KDChart::AbstractAreaWidget::paintIntoRect(), KDChart::GlobalMeasureScaling::resetFactors(), KDChart::PrintingParameters::resetScaleFactor(), KDChart::GlobalMeasureScaling::setFactors(), KDChart::GlobalMeasureScaling::setPaintDevice(), and KDChart::PrintingParameters::setScaleFactor().
01032 { 01033 if( target.isEmpty() || !painter ) return; 01034 //qDebug() << "Chart::paint( ..," << target << ")"; 01035 01036 QPaintDevice* prevDevice = GlobalMeasureScaling::paintDevice(); 01037 GlobalMeasureScaling::setPaintDevice( painter->device() ); 01038 01039 // Output on a widget 01040 if( dynamic_cast< QWidget* >( painter->device() ) != 0 ) 01041 { 01042 GlobalMeasureScaling::setFactors( 01043 static_cast< qreal >( target.width() ) / 01044 static_cast< qreal >( geometry().size().width() ), 01045 static_cast< qreal >( target.height() ) / 01046 static_cast< qreal >( geometry().size().height() ) ); 01047 } 01048 // Output onto a QPixmap 01049 else 01050 { 01051 PrintingParameters::setScaleFactor( static_cast< qreal >( painter->device()->logicalDpiX() ) / static_cast< qreal >( logicalDpiX() ) ); 01052 01053 const qreal resX = static_cast< qreal >( logicalDpiX() ) / static_cast< qreal >( painter->device()->logicalDpiX() ); 01054 const qreal resY = static_cast< qreal >( logicalDpiY() ) / static_cast< qreal >( painter->device()->logicalDpiY() ); 01055 01056 GlobalMeasureScaling::setFactors( 01057 static_cast< qreal >( target.width() ) / 01058 static_cast< qreal >( geometry().size().width() ) * resX, 01059 static_cast< qreal >( target.height() ) / 01060 static_cast< qreal >( geometry().size().height() ) * resY ); 01061 } 01062 01063 01064 if( target.size() != d->currentLayoutSize ){ 01065 d->resizeLayout( target.size() ); 01066 } 01067 const QPoint translation = target.topLeft(); 01068 painter->translate( translation ); 01069 01070 d->paintAll( painter ); 01071 01072 // for debugging: 01073 //painter->setPen(QPen(Qt::blue, 8)); 01074 //painter->drawRect(target.adjusted(12,12,-12,-12)); 01075 01076 KDAB_FOREACH( Legend *legend, d->legends ) { 01077 const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide); 01078 if ( !hidden ) { 01079 //qDebug() << "painting legend at " << legend->geometry(); 01080 legend->paintIntoRect( *painter, legend->geometry() ); 01081 //testing: 01082 //legend->paintIntoRect( *painter, legend->geometry().adjusted(-100,0,-100,0) ); 01083 } 01084 } 01085 01086 painter->translate( -translation.x(), -translation.y() ); 01087 01088 GlobalMeasureScaling::instance()->resetFactors(); 01089 PrintingParameters::resetScaleFactor(); 01090 GlobalMeasureScaling::setPaintDevice( prevDevice ); 01091 01092 //qDebug() << "KDChart::Chart::paint() done.\n"; 01093 }
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().
Definition at line 1137 of file KDChartChart.cpp.
References d, and reLayoutFloatingLegends().
01138 { 01139 QPainter painter( this ); 01140 01141 if( size() != d->currentLayoutSize ){ 01142 d->resizeLayout( size() ); 01143 reLayoutFloatingLegends(); 01144 } 01145 01146 //FIXME(khz): Paint the background/frame too! 01147 // (can we derive Chart from AreaWidget ??) 01148 d->paintAll( &painter ); 01149 }
void KDChart::Chart::propertiesChanged | ( | ) | [signal] |
Emitted upon change of a property of the Chart or any of its components.
Referenced by addCoordinatePlane(), addLegend(), takeCoordinatePlane(), takeHeaderFooter(), and takeLegend().
void Chart::reLayoutFloatingLegends | ( | ) |
Definition at line 1105 of file KDChartChart.cpp.
References d, KDChart::Legend::floatingPosition(), KDChart::Position::isFloating(), KDChart::Legend::position(), and KDChart::Legend::sizeHint().
Referenced by paintEvent(), and resizeEvent().
01106 { 01107 KDAB_FOREACH( Legend *legend, d->legends ) { 01108 const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide); 01109 if ( legend->position().isFloating() && !hidden ){ 01110 // resize the legend 01111 const QSize legendSize( legend->sizeHint() ); 01112 legend->setGeometry( QRect( legend->geometry().topLeft(), legendSize ) ); 01113 // find the legends corner point (reference point plus any paddings) 01114 const RelativePosition relPos( legend->floatingPosition() ); 01115 QPointF pt( relPos.calculatedPoint( size() ) ); 01116 //qDebug() << pt; 01117 // calculate the legend's top left point 01118 const Qt::Alignment alignTopLeft = Qt::AlignBottom | Qt::AlignLeft; 01119 if( (relPos.alignment() & alignTopLeft) != alignTopLeft ){ 01120 if( relPos.alignment() & Qt::AlignRight ) 01121 pt.rx() -= legendSize.width(); 01122 else if( relPos.alignment() & Qt::AlignHCenter ) 01123 pt.rx() -= 0.5 * legendSize.width(); 01124 01125 if( relPos.alignment() & Qt::AlignBottom ) 01126 pt.ry() -= legendSize.height(); 01127 else if( relPos.alignment() & Qt::AlignVCenter ) 01128 pt.ry() -= 0.5 * legendSize.height(); 01129 } 01130 //qDebug() << pt << endl; 01131 legend->move( static_cast<int>(pt.x()), static_cast<int>(pt.y()) ); 01132 } 01133 } 01134 }
void Chart::replaceCoordinatePlane | ( | AbstractCoordinatePlane * | plane, | |
AbstractCoordinatePlane * | oldPlane = 0 | |||
) |
Replaces the old coordinate plane, or appends the plane, it there is none yet.
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. |
Definition at line 944 of file KDChartChart.cpp.
References addCoordinatePlane(), d, and takeCoordinatePlane().
00946 { 00947 if( plane && oldPlane_ != plane ){ 00948 AbstractCoordinatePlane* oldPlane = oldPlane_; 00949 if( d->coordinatePlanes.count() ){ 00950 if( ! oldPlane ){ 00951 oldPlane = d->coordinatePlanes.first(); 00952 if( oldPlane == plane ) 00953 return; 00954 } 00955 takeCoordinatePlane( oldPlane ); 00956 } 00957 delete oldPlane; 00958 addCoordinatePlane( plane ); 00959 } 00960 }
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.
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. |
Definition at line 1162 of file KDChartChart.cpp.
References addHeaderFooter(), d, and takeHeaderFooter().
01164 { 01165 if( headerFooter && oldHeaderFooter_ != headerFooter ){ 01166 HeaderFooter* oldHeaderFooter = oldHeaderFooter_; 01167 if( d->headerFooters.count() ){ 01168 if( ! oldHeaderFooter ){ 01169 oldHeaderFooter = d->headerFooters.first(); 01170 if( oldHeaderFooter == headerFooter ) 01171 return; 01172 } 01173 takeHeaderFooter( oldHeaderFooter ); 01174 } 01175 delete oldHeaderFooter; 01176 addHeaderFooter( headerFooter ); 01177 } 01178 }
Replaces the old legend, or appends the new legend, it there is none yet.
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. |
Definition at line 1256 of file KDChartChart.cpp.
References addLegend(), d, and takeLegend().
01257 { 01258 if( legend && oldLegend_ != legend ){ 01259 Legend* oldLegend = oldLegend_; 01260 if( d->legends.count() ){ 01261 if( ! oldLegend ){ 01262 oldLegend = d->legends.first(); 01263 if( oldLegend == legend ) 01264 return; 01265 } 01266 takeLegend( oldLegend ); 01267 } 01268 delete oldLegend; 01269 addLegend( legend ); 01270 } 01271 }
void Chart::resizeEvent | ( | QResizeEvent * | event | ) | [protected] |
Adjusts the internal layout when the chart is resized.
Definition at line 1095 of file KDChartChart.cpp.
References d, reLayoutFloatingLegends(), and KDChart::AbstractCoordinatePlane::setGridNeedsRecalculate().
01096 { 01097 d->resizeLayout( size() ); 01098 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ){ 01099 plane->setGridNeedsRecalculate(); 01100 } 01101 reLayoutFloatingLegends(); 01102 }
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 );
Definition at line 892 of file KDChartChart.cpp.
References d.
00893 { 00894 d->backgroundAttributes = a; 00895 }
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 903 of file KDChartChart.cpp.
References d.
00904 { 00905 delete d->planesLayout; 00906 d->planesLayout = dynamic_cast<QBoxLayout*>( layout ); 00907 d->slotLayoutPlanes(); 00908 }
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 );
Definition at line 882 of file KDChartChart.cpp.
References d.
Referenced by Chart().
00883 { 00884 d->frameAttributes = a; 00885 }
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.
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. |
globalLeadingTop, globalLeadingBottom, globalLeadingLeft, globalLeadingRight
Definition at line 978 of file KDChartChart.cpp.
References d, setGlobalLeadingBottom(), setGlobalLeadingLeft(), setGlobalLeadingRight(), and setGlobalLeadingTop().
00979 { 00980 setGlobalLeadingLeft( left ); 00981 setGlobalLeadingTop( top ); 00982 setGlobalLeadingRight( right ); 00983 setGlobalLeadingBottom( bottom ); 00984 d->slotRelayout(); 00985 }
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.
leading | The padding value. |
Definition at line 1020 of file KDChartChart.cpp.
References d.
Referenced by setGlobalLeading().
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.
leading | The padding value. |
Definition at line 987 of file KDChartChart.cpp.
References d.
Referenced by setGlobalLeading().
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.
leading | The padding value. |
Definition at line 1009 of file KDChartChart.cpp.
References d.
Referenced by setGlobalLeading().
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.
leading | The padding value. |
Definition at line 998 of file KDChartChart.cpp.
References d.
Referenced by setGlobalLeading().
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.
Definition at line 962 of file KDChartChart.cpp.
References d, propertiesChanged(), KDChart::AbstractLayoutItem::removeFromParentLayout(), and KDChart::AbstractCoordinatePlane::setParent().
Referenced by replaceCoordinatePlane().
00963 { 00964 const int idx = d->coordinatePlanes.indexOf( plane ); 00965 if( idx != -1 ){ 00966 d->coordinatePlanes.takeAt( idx ); 00967 disconnect( plane, SIGNAL( destroyedCoordinatePlane( AbstractCoordinatePlane* ) ), 00968 d, SLOT( slotUnregisterDestroyedPlane( AbstractCoordinatePlane* ) ) ); 00969 plane->removeFromParentLayout(); 00970 plane->setParent( 0 ); 00971 } 00972 d->slotLayoutPlanes(); 00973 // Need to emit the signal: In case somebody has connected the signal 00974 // to her own slot for e.g. calling update() on a widget containing the chart. 00975 emit propertiesChanged(); 00976 }
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.
Definition at line 1180 of file KDChartChart.cpp.
References d, propertiesChanged(), and KDChart::HeaderFooter::setParent().
Referenced by replaceHeaderFooter().
01181 { 01182 const int idx = d->headerFooters.indexOf( headerFooter ); 01183 if( idx != -1 ){ 01184 d->headerFooters.takeAt( idx ); 01185 disconnect( headerFooter, SIGNAL( destroyedHeaderFooter( HeaderFooter* ) ), 01186 d, SLOT( slotUnregisterDestroyedHeaderFooter( HeaderFooter* ) ) ); 01187 headerFooter->setParent( 0 ); 01188 } 01189 d->slotRelayout(); 01190 // Need to emit the signal: In case somebody has connected the signal 01191 // to her own slot for e.g. calling update() on a widget containing the chart. 01192 emit propertiesChanged(); 01193 }
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.
Definition at line 1273 of file KDChartChart.cpp.
References d, propertiesChanged(), and KDChart::Legend::setVisible().
Referenced by replaceLegend().
01274 { 01275 const int idx = d->legends.indexOf( legend ); 01276 if( idx != -1 ){ 01277 d->legends.takeAt( idx ); 01278 disconnect( legend, SIGNAL( destroyedLegend( Legend* ) ), 01279 d, SLOT( slotUnregisterDestroyedLegend( Legend* ) ) ); 01280 disconnect( legend, SIGNAL( positionChanged( AbstractAreaWidget* ) ), 01281 d, SLOT( slotLayoutPlanes() ) ); //slotRelayout() ) ); 01282 disconnect( legend, SIGNAL( propertiesChanged() ), 01283 this, SIGNAL( propertiesChanged() ) ); 01284 legend->setParent( 0 ); 01285 legend->setVisible( false ); 01286 } 01287 d->slotRelayout(); 01288 01289 // Need to emit the signal: In case somebody has connected the signal 01290 // to her own slot for e.g. calling update() on a widget containing the chart. 01291 // Note: 01292 // We do this ourselves in examples/DrawIntoPainter/mainwindow.cpp 01293 emit propertiesChanged(); 01294 }
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.