31
31
#include <KDChartAbstractDiagram.h>
32
32
#include <KDChartBarDiagram.h>
33
#include <KDChartCartesianCoordinatePlane.h>
34
33
#include <KDChartChart.h>
35
34
#include <KDChartAbstractCoordinatePlane.h>
36
35
#include <KDChartLineDiagram.h>
37
36
#include <KDChartPlotter.h>
38
37
#include <KDChartPieDiagram.h>
39
#include <KDChartPolarCoordinatePlane.h>
40
38
#include <KDChartPolarDiagram.h>
41
39
#include <KDChartRingDiagram.h>
42
40
#include <KDChartLegend.h>
387
387
static bool isCartesian( KDChart::Widget::ChartType type )
389
return (type == KDChart::Widget::Bar || type == KDChart::Widget::Line);
389
return (type == KDChart::Widget::Bar) || (type == KDChart::Widget::Line);
392
392
static bool isPolar( KDChart::Widget::ChartType type )
394
return (type == KDChart::Widget::Pie
395
|| type == KDChart::Widget::Ring
396
|| type == KDChart::Widget::Polar );
394
return (type == KDChart::Widget::Pie)
395
|| (type == KDChart::Widget::Ring)
396
|| (type == KDChart::Widget::Polar);
399
399
void Widget::setType( ChartType chartType, SubType chartSubType )
401
401
AbstractDiagram* diag = 0;
402
CartesianCoordinatePlane* cartPlane = 0;
403
PolarCoordinatePlane* polPlane = 0;
406
if ( chartType != type() ){
402
const ChartType oldType = type();
404
if ( chartType != oldType ){
405
if( chartType != NoType ){
406
if ( isCartesian( chartType ) && ! isCartesian( oldType ) )
408
if( coordinatePlane() == &d->m_polPlane ){
409
d->m_chart.takeCoordinatePlane( &d->m_polPlane );
410
d->m_chart.addCoordinatePlane( &d->m_cartPlane );
412
d->m_chart.replaceCoordinatePlane( &d->m_cartPlane );
415
else if ( isPolar( chartType ) && ! isPolar( oldType ) )
417
if( coordinatePlane() == &d->m_cartPlane ){
418
d->m_chart.takeCoordinatePlane( &d->m_cartPlane );
419
d->m_chart.addCoordinatePlane( &d->m_polPlane );
421
d->m_chart.replaceCoordinatePlane( &d->m_polPlane );
425
switch ( chartType ){
410
diag = new BarDiagram( &d->m_chart, cartPlane );
427
diag = new BarDiagram( &d->m_chart, &d->m_cartPlane );
413
diag = new LineDiagram( &d->m_chart, cartPlane );
430
diag = new LineDiagram( &d->m_chart, &d->m_cartPlane );
416
diag = new Plotter( &d->m_chart, cartPlane );
433
diag = new Plotter( &d->m_chart, &d->m_cartPlane );
419
diag = new PieDiagram( &d->m_chart, polPlane );
436
diag = new PieDiagram( &d->m_chart, &d->m_polPlane );
422
diag = new PolarDiagram( &d->m_chart, polPlane );
439
diag = new PolarDiagram( &d->m_chart, &d->m_polPlane );
425
diag = new RingDiagram( &d->m_chart, polPlane );
442
diag = new RingDiagram( &d->m_chart, &d->m_polPlane );
432
if ( isPolar( type() ) && isCartesian( chartType ) )
434
cartPlane = new CartesianCoordinatePlane( &d->m_chart );
435
d->m_chart.replaceCoordinatePlane( cartPlane );
437
else if ( isCartesian( type() ) && isPolar( chartType ) )
439
polPlane = new PolarCoordinatePlane( &d->m_chart );
440
d->m_chart.replaceCoordinatePlane( polPlane );
442
else if ( isCartesian( type() ) && isCartesian( chartType ) )
444
AbstractCartesianDiagram *old =
445
qobject_cast<AbstractCartesianDiagram*>( d->m_chart.coordinatePlane()->diagram() );
446
Q_FOREACH( CartesianAxis* axis, old->axes() ) {
447
old->takeAxis( axis );
448
qobject_cast<AbstractCartesianDiagram*>(diag)->addAxis( axis );
448
if ( isCartesian( oldType ) && isCartesian( chartType ) ){
449
AbstractCartesianDiagram *oldDiag =
450
qobject_cast<AbstractCartesianDiagram*>( coordinatePlane()->diagram() );
451
AbstractCartesianDiagram *newDiag =
452
qobject_cast<AbstractCartesianDiagram*>( diag );
453
Q_FOREACH( CartesianAxis* axis, oldDiag->axes() ) {
454
oldDiag->takeAxis( axis );
455
newDiag->addAxis ( axis );
451
458
diag->setModel( &d->m_model );