~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kchart/kdchart/src/KDChartWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
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>
54
52
      layout( q ),
55
53
      m_model( q ),
56
54
      m_chart( q ),
 
55
      m_cartPlane( &m_chart ),
 
56
      m_polPlane( &m_chart ),
57
57
      usedDatasetWidth( 0 )
58
58
{
59
59
    KDAB_SET_OBJECT_NAME( layout );
386
386
 
387
387
static bool isCartesian( KDChart::Widget::ChartType type )
388
388
{
389
 
    return (type == KDChart::Widget::Bar || type == KDChart::Widget::Line);
 
389
    return (type == KDChart::Widget::Bar) || (type == KDChart::Widget::Line);
390
390
}
391
391
 
392
392
static bool isPolar( KDChart::Widget::ChartType type )
393
393
{
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);
397
397
}
398
398
 
399
399
void Widget::setType( ChartType chartType, SubType chartSubType )
400
400
{
401
401
    AbstractDiagram* diag = 0;
402
 
    CartesianCoordinatePlane* cartPlane = 0;
403
 
    PolarCoordinatePlane* polPlane = 0;
404
 
 
405
 
 
406
 
    if ( chartType != type() ){
407
 
        switch ( chartType )
408
 
        {
 
402
    const ChartType oldType = type();
 
403
 
 
404
    if ( chartType != oldType ){
 
405
        if( chartType != NoType ){
 
406
            if ( isCartesian( chartType ) && ! isCartesian( oldType ) )
 
407
            {
 
408
                if( coordinatePlane() == &d->m_polPlane ){
 
409
                    d->m_chart.takeCoordinatePlane( &d->m_polPlane );
 
410
                    d->m_chart.addCoordinatePlane(  &d->m_cartPlane );
 
411
                }else{
 
412
                    d->m_chart.replaceCoordinatePlane( &d->m_cartPlane );
 
413
                }
 
414
            }
 
415
            else if ( isPolar( chartType ) && ! isPolar( oldType ) )
 
416
            {
 
417
                if( coordinatePlane() == &d->m_cartPlane ){
 
418
                    d->m_chart.takeCoordinatePlane( &d->m_cartPlane );
 
419
                    d->m_chart.addCoordinatePlane(  &d->m_polPlane );
 
420
                }else{
 
421
                    d->m_chart.replaceCoordinatePlane( &d->m_polPlane );
 
422
                }
 
423
            }
 
424
        }
 
425
        switch ( chartType ){
409
426
            case Bar:
410
 
              diag = new BarDiagram( &d->m_chart, cartPlane );
411
 
              break;
 
427
                diag = new BarDiagram( &d->m_chart, &d->m_cartPlane );
 
428
                break;
412
429
            case Line:
413
 
                diag = new LineDiagram( &d->m_chart, cartPlane );
 
430
                diag = new LineDiagram( &d->m_chart, &d->m_cartPlane );
414
431
                break;
415
432
            case Plot:
416
 
                diag = new Plotter( &d->m_chart, cartPlane );
 
433
                diag = new Plotter( &d->m_chart, &d->m_cartPlane );
417
434
                break;
418
435
            case Pie:
419
 
              diag = new PieDiagram( &d->m_chart, polPlane );
420
 
              break;
 
436
                diag = new PieDiagram( &d->m_chart, &d->m_polPlane );
 
437
                break;
421
438
            case Polar:
422
 
              diag = new PolarDiagram( &d->m_chart, polPlane );
423
 
              break;
 
439
                diag = new PolarDiagram( &d->m_chart, &d->m_polPlane );
 
440
                break;
424
441
            case Ring:
425
 
              diag = new RingDiagram( &d->m_chart, polPlane );
426
 
              break;
 
442
                diag = new RingDiagram( &d->m_chart, &d->m_polPlane );
 
443
                break;
427
444
            case NoType:
428
 
              break;
 
445
                break;
429
446
        }
430
 
        if ( diag != NULL )
431
 
        {
432
 
            if ( isPolar( type() ) && isCartesian( chartType ) )
433
 
            {
434
 
                cartPlane = new CartesianCoordinatePlane( &d->m_chart );
435
 
                d->m_chart.replaceCoordinatePlane( cartPlane );
436
 
            }
437
 
            else if ( isCartesian( type() ) && isPolar( chartType ) )
438
 
            {
439
 
                polPlane = new PolarCoordinatePlane( &d->m_chart );
440
 
                d->m_chart.replaceCoordinatePlane( polPlane );
441
 
            }
442
 
            else if ( isCartesian( type() ) && isCartesian( chartType ) )
443
 
            {
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 );
 
447
        if ( diag != NULL ){
 
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 );
449
456
                }
450
457
            }
451
458
            diag->setModel( &d->m_model );
456
463
                l->setDiagram( diag );
457
464
            //checkDatasetWidth( d->usedDatasetWidth );
458
465
        }
 
466
        //coordinatePlane()->setGridNeedsRecalculate();
459
467
    }
460
468
 
461
 
    if ( chartSubType != subType() )
462
 
        setSubType( chartSubType );
463
 
//    coordinatePlane()->show();
 
469
    if ( chartType != NoType ){
 
470
        if ( chartType != oldType || chartSubType != subType() )
 
471
            setSubType( chartSubType );
 
472
        d->m_chart.resize( size() ); // triggering immediate update
 
473
    }
464
474
}
465
475
 
466
476
void Widget::setSubType( SubType subType )
566
576
            break;
567
577
        case Plot:
568
578
            TEST_SUB_TYPE( plotterDia, Plotter::Normal,  Normal );
 
579
            TEST_SUB_TYPE( plotterDia, Plotter::Percent, Percent );
569
580
            break;
570
581
        case Pie:
571
582
           // no impl. yet
586
597
 
587
598
 
588
599
/**
589
 
 * Checks, whether the given width matches with the one used until now.
 
600
 * Checks whether the given width matches with the one used until now.
590
601
 */
591
602
bool Widget::checkDatasetWidth( int width )
592
603
{