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

« back to all changes in this revision

Viewing changes to kchart/shape/ChartTool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
 *
3
 
 * Copyright (C) 2007, 2010  Inge Wallin <inge@lysator.liu.se>
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public License
16
 
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
// Own
22
 
#include "ChartTool.h"
23
 
 
24
 
// Qt
25
 
#include <QAction>
26
 
#include <QGridLayout>
27
 
#include <QToolButton>
28
 
#include <QCheckBox>
29
 
#include <QTabWidget>
30
 
#include <QPen>
31
 
#include <QBrush>
32
 
#include <QPainter>
33
 
 
34
 
// KDE
35
 
#include <KLocale>
36
 
#include <KIcon>
37
 
#include <KDebug>
38
 
 
39
 
// KOffice
40
 
#include <KoCanvasBase.h>
41
 
#include <KoSelection.h>
42
 
#include <KoShapeManager.h>
43
 
#include <KoPointerEvent.h>
44
 
#include <KoTextShapeData.h>
45
 
#include <KoViewConverter.h>
46
 
 
47
 
// KDChart
48
 
#include <KDChartChart>
49
 
#include <KDChartCartesianAxis>
50
 
#include <KDChartGridAttributes>
51
 
#include <KDChartAbstractCartesianDiagram>
52
 
#include <KDChartCartesianCoordinatePlane>
53
 
#include <KDChartPosition>
54
 
 
55
 
// KChart
56
 
#include "Surface.h"
57
 
#include "PlotArea.h"
58
 
#include "Axis.h"
59
 
#include "DataSet.h"
60
 
#include "Legend.h"
61
 
#include "ChartProxyModel.h"
62
 
#include "ChartConfigWidget.h"
63
 
#include "KDChartConvertions.h"
64
 
 
65
 
 
66
 
using namespace KChart;
67
 
 
68
 
 
69
 
class ChartTool::Private
70
 
{
71
 
public:
72
 
    Private();
73
 
    ~Private();
74
 
 
75
 
    ChartShape  *shape;
76
 
    QModelIndex  datasetSelection;
77
 
    QPen         datasetSelectionPen;
78
 
    QBrush       datasetSelectionBrush;
79
 
};
80
 
 
81
 
ChartTool::Private::Private()
82
 
    : shape(0)
83
 
{
84
 
}
85
 
 
86
 
ChartTool::Private::~Private()
87
 
{
88
 
}
89
 
 
90
 
ChartTool::ChartTool( KoCanvasBase *canvas )
91
 
    : KoToolBase( canvas ),
92
 
      d( new Private() )
93
 
{
94
 
    // Create QActions here.
95
 
#if 0
96
 
    QActionGroup *group = new QActionGroup(this);
97
 
    m_foo  = new QAction(KIcon("this-action"), i18n("Do something"), this);
98
 
    m_foo->setCheckable(true);
99
 
    group->addAction(m_foo);
100
 
    connect( m_foo, SIGNAL(toggled(bool)), this, SLOT(catchFoo(bool)) );
101
 
 
102
 
    m_bar  = new QAction(KIcon("that-action"), i18n("Do something else"), this);
103
 
    m_bar->setCheckable(true);
104
 
    group->addAction(m_bar);
105
 
    connect( m_foo, SIGNAL(toggled(bool)), this, SLOT(catchBar(bool)) );
106
 
 
107
 
#endif
108
 
    connect( canvas->shapeManager()->selection(), SIGNAL( selectionChanged() ),
109
 
             this, SLOT( shapeSelectionChanged() ) );
110
 
}
111
 
 
112
 
ChartTool::~ChartTool()
113
 
{
114
 
    delete d;
115
 
}
116
 
 
117
 
void ChartTool::shapeSelectionChanged()
118
 
{
119
 
    KoShape *selectedShape = 0;
120
 
    
121
 
    // Get the chart shape that the tool is working on. 
122
 
    // Let d->shape point to it.
123
 
    KoSelection  *selection = canvas()->shapeManager()->selection();
124
 
    foreach ( KoShape *shape, selection->selectedShapes() ) {
125
 
        // Find out which type of shape that the user clicked on.
126
 
        // We support several here, since the chart shape is comprised
127
 
        // of several subshapes (plotarea, legend)
128
 
        d->shape = dynamic_cast<ChartShape*>( shape );
129
 
        if ( !d->shape ) {
130
 
            PlotArea *plotArea = dynamic_cast<PlotArea*>( shape );
131
 
            if ( plotArea ) {
132
 
                selectedShape = plotArea;
133
 
                d->shape = plotArea->parent();
134
 
            }
135
 
            else {
136
 
                Legend *legend = dynamic_cast<Legend*>( shape );
137
 
                if ( legend ) {
138
 
                    selectedShape = legend;
139
 
                    d->shape = dynamic_cast<ChartShape*>( shape->parent() );
140
 
                }
141
 
            }
142
 
        // The selected shape is the chart
143
 
        } else
144
 
            selectedShape = shape;
145
 
        
146
 
        // Insert the values from the selected shape (note: not only
147
 
        // chart shape, but also plotarea or legend) into the tool
148
 
        // option widget.
149
 
        if ( selectedShape ) {
150
 
            foreach ( QWidget *w, optionWidgets() ) {
151
 
                KoShapeConfigWidgetBase *widget = dynamic_cast<KoShapeConfigWidgetBase*>(w);
152
 
                Q_ASSERT( widget );
153
 
                if ( widget )
154
 
                    widget->open( selectedShape );
155
 
            }
156
 
 
157
 
        // We support only one selected chart at the time, so once
158
 
        // we found one, we don't need to search for any more
159
 
        // among the selected shapes.
160
 
        break;
161
 
        }
162
 
    }
163
 
 
164
 
    // If we couldn't determine a chart shape, then there is nothing to do.
165
 
    if ( !d->shape ) { // none found
166
 
        emit done();
167
 
        return;
168
 
    }
169
 
}
170
 
 
171
 
 
172
 
void ChartTool::paint( QPainter &painter, const KoViewConverter &converter)
173
 
{
174
 
    Q_UNUSED( painter );
175
 
    Q_UNUSED( converter );
176
 
}
177
 
 
178
 
void ChartTool::mousePressEvent( KoPointerEvent *event )
179
 
{
180
 
#if 1  // disabled
181
 
    Q_UNUSED( event );
182
 
    return;
183
 
#else
184
 
    // Select dataset
185
 
    if (    !d->shape || !d->shape->kdChart() || ! d->shape->kdChart()->coordinatePlane()
186
 
         || !d->shape->kdChart()->coordinatePlane()->diagram() )
187
 
        return;
188
 
    QPointF point = event->point - d->shape->position();
189
 
    QModelIndex selection = d->shape->kdChart()->coordinatePlane()->diagram()->indexAt( point.toPoint() );
190
 
    // Note: the dataset will always stay column() due to the transformations being
191
 
    // done internally by the ChartProxyModel
192
 
    int dataset = selection.column();
193
 
    
194
 
    if ( d->datasetSelection.isValid() ) {
195
 
        d->shape->kdChart()->coordinatePlane()->diagram()->setPen( d->datasetSelection.column(), d->datasetSelectionPen );
196
 
        //d->shape->kdChart()->coordinatePlane()->diagram()->setBrush( d->datasetSelection, d->datasetSelectionBrush );
197
 
    }
198
 
    if ( selection.isValid() ) {
199
 
        d->datasetSelection = selection;
200
 
        
201
 
        QPen pen( Qt::DotLine );
202
 
        pen.setColor( Qt::darkGray );
203
 
        pen.setWidth( 1 );
204
 
        
205
 
        d->datasetSelectionBrush = d->shape->kdChart()->coordinatePlane()->diagram()->brush( selection );
206
 
        d->datasetSelectionPen   = d->shape->kdChart()->coordinatePlane()->diagram()->pen( dataset );
207
 
        
208
 
        d->shape->kdChart()->coordinatePlane()->diagram()->setPen( dataset, pen );
209
 
        //d->shape->kdChart()->coordinatePlane()->diagram()->setBrush( selection, QBrush( Qt::lightGray ) );
210
 
    }
211
 
    ((ChartConfigWidget*)optionWidget())->selectDataset( dataset );
212
 
        
213
 
    d->shape->update();
214
 
#endif
215
 
}
216
 
 
217
 
void ChartTool::mouseMoveEvent( KoPointerEvent *event )
218
 
{
219
 
    event->ignore();
220
 
}
221
 
 
222
 
void ChartTool::mouseReleaseEvent( KoPointerEvent *event )
223
 
{
224
 
    event->ignore();
225
 
}
226
 
 
227
 
 
228
 
void ChartTool::activate(ToolActivation, const QSet<KoShape*> &)
229
 
{
230
 
    useCursor(Qt::ArrowCursor);
231
 
}
232
 
 
233
 
void ChartTool::deactivate()
234
 
{
235
 
    d->shape = 0;
236
 
 
237
 
    // Tell the config widget to delete all open dialogs.
238
 
    //
239
 
    // The reason why we want to do that explicitly here is because
240
 
    // they are connected to the models, which may disappear when the
241
 
    // chart shape is destructed.
242
 
    foreach (QWidget *w, optionWidgets()) {
243
 
        ChartConfigWidget *configWidget = dynamic_cast<ChartConfigWidget*>(w);
244
 
        if ( configWidget )
245
 
            configWidget->deleteSubDialogs();
246
 
    }
247
 
}
248
 
 
249
 
 
250
 
QWidget *ChartTool::createOptionWidget()
251
 
{
252
 
    ChartConfigWidget  *widget = new ChartConfigWidget();
253
 
    widget->open( d->shape );
254
 
    
255
 
    connect( widget, SIGNAL( dataSetXDataRegionChanged( DataSet*, const QString& ) ),
256
 
             this,   SLOT( setDataSetXDataRegion( DataSet*, const QString& ) ) );
257
 
    connect( widget, SIGNAL( dataSetYDataRegionChanged( DataSet*, const QString& ) ),
258
 
             this,   SLOT( setDataSetYDataRegion( DataSet*, const QString& ) ) );
259
 
    connect( widget, SIGNAL( dataSetCustomDataRegionChanged( DataSet*, const QString& ) ),
260
 
             this,   SLOT( setDataSetCustomDataRegion( DataSet*, const QString& ) ) );
261
 
    connect( widget, SIGNAL( dataSetLabelDataRegionChanged( DataSet*, const QString& ) ),
262
 
             this,   SLOT( setDataSetLabelDataRegion( DataSet*, const QString& ) ) );
263
 
    connect( widget, SIGNAL( dataSetCategoryDataRegionChanged( DataSet*, const QString& ) ),
264
 
             this,   SLOT( setDataSetCategoryDataRegion( DataSet*, const QString& ) ) );
265
 
    connect( widget, SIGNAL( dataSetChartTypeChanged( DataSet*, ChartType ) ),
266
 
             this,   SLOT( setDataSetChartType( DataSet*, ChartType ) ) );
267
 
    connect( widget, SIGNAL( dataSetChartSubTypeChanged( DataSet*, ChartSubtype ) ),
268
 
             this,   SLOT( setDataSetChartSubType( DataSet*, ChartSubtype ) ) );
269
 
    connect( widget, SIGNAL( datasetColorChanged( DataSet*, const QColor& ) ),
270
 
             this, SLOT( setDataSetColor( DataSet*, const QColor& ) ) );
271
 
    connect( widget, SIGNAL( datasetShowValuesChanged( DataSet*, bool ) ),
272
 
             this, SLOT( setDataSetShowValues( DataSet*, bool ) ) );
273
 
    connect( widget, SIGNAL( datasetShowLabelsChanged( DataSet*, bool ) ),
274
 
             this, SLOT( setDataSetShowLabels( DataSet*, bool ) ) );
275
 
    connect( widget, SIGNAL( dataSetAxisChanged( DataSet*, Axis* ) ),
276
 
             this, SLOT( setDataSetAxis( DataSet*, Axis* ) ) );
277
 
    connect( widget, SIGNAL( gapBetweenBarsChanged( int ) ),
278
 
             this,   SLOT( setGapBetweenBars( int ) ) );
279
 
    connect( widget, SIGNAL( gapBetweenSetsChanged( int ) ),
280
 
             this,   SLOT( setGapBetweenSets( int ) ) );
281
 
    connect( widget, SIGNAL( pieExplodeFactorChanged( DataSet*, int ) ),
282
 
             this,   SLOT( setPieExplodeFactor( DataSet*, int ) ) );
283
 
    
284
 
    connect( widget, SIGNAL( showLegendChanged( bool ) ),
285
 
             this,   SLOT( setShowLegend( bool ) ));
286
 
 
287
 
    connect( widget, SIGNAL( chartTypeChanged( ChartType ) ),
288
 
             this,   SLOT( setChartType( ChartType ) ) );
289
 
    connect( widget, SIGNAL( chartSubTypeChanged( ChartSubtype ) ),
290
 
             this,   SLOT( setChartSubType( ChartSubtype ) ) );
291
 
    connect( widget, SIGNAL( threeDModeToggled( bool ) ),
292
 
             this,   SLOT( setThreeDMode( bool ) ) );
293
 
    connect( widget, SIGNAL( showTitleChanged( bool ) ),
294
 
             this,   SLOT( setShowTitle( bool ) ) );
295
 
    connect( widget, SIGNAL( showSubTitleChanged( bool ) ),
296
 
             this,   SLOT( setShowSubTitle( bool ) ) );
297
 
    connect( widget, SIGNAL( showFooterChanged( bool ) ),
298
 
             this,   SLOT( setShowFooter( bool ) ) );
299
 
 
300
 
    connect( widget, SIGNAL( axisAdded( AxisPosition, const QString& ) ),
301
 
             this,   SLOT( addAxis( AxisPosition, const QString& ) ) );
302
 
    connect( widget, SIGNAL( axisRemoved( Axis* ) ),
303
 
             this,   SLOT( removeAxis( Axis* ) ) );
304
 
    connect( widget, SIGNAL( axisTitleChanged( Axis*, const QString& ) ),
305
 
                 this,   SLOT( setAxisTitle( Axis*, const QString& ) ) );
306
 
    connect( widget, SIGNAL( axisShowTitleChanged( Axis*, bool ) ),
307
 
             this,   SLOT( setAxisShowTitle( Axis*, bool ) ) );
308
 
    connect( widget, SIGNAL( axisShowGridLinesChanged( Axis*, bool ) ),
309
 
                 this,   SLOT( setAxisShowGridLines( Axis*, bool ) ) );
310
 
    connect( widget, SIGNAL( axisUseLogarithmicScalingChanged( Axis*, bool ) ),
311
 
                 this,   SLOT( setAxisUseLogarithmicScaling( Axis*, bool ) ) );
312
 
    connect( widget, SIGNAL( axisStepWidthChanged( Axis*, qreal ) ),
313
 
                 this,   SLOT( setAxisStepWidth( Axis*, qreal ) ) );
314
 
    connect( widget, SIGNAL( axisSubStepWidthChanged( Axis*, qreal ) ),
315
 
                 this,   SLOT( setAxisSubStepWidth( Axis*, qreal ) ) );
316
 
    connect( widget, SIGNAL( axisUseAutomaticStepWidthChanged( Axis*, bool ) ),
317
 
                 this,   SLOT( setAxisUseAutomaticStepWidth( Axis*, bool ) ) );
318
 
    connect( widget, SIGNAL( axisUseAutomaticSubStepWidthChanged( Axis*, bool ) ),
319
 
                 this,   SLOT( setAxisUseAutomaticSubStepWidth( Axis*, bool ) ) );
320
 
 
321
 
    connect( widget, SIGNAL( legendTitleChanged( const QString& ) ),
322
 
             this,   SLOT( setLegendTitle( const QString& ) ) );
323
 
    connect( widget, SIGNAL( legendFontChanged( const QFont& ) ),
324
 
             this,   SLOT( setLegendFont( const QFont& ) ) );
325
 
    connect( widget, SIGNAL( legendFontSizeChanged( int ) ),
326
 
             this,   SLOT( setLegendFontSize( int ) ) );
327
 
 
328
 
    connect( widget, SIGNAL( legendOrientationChanged( Qt::Orientation ) ),
329
 
             this,   SLOT( setLegendOrientation( Qt::Orientation ) ) );
330
 
    connect( widget, SIGNAL( legendAlignmentChanged( Qt::Alignment ) ),
331
 
             this,   SLOT( setLegendAlignment( Qt::Alignment ) ) );
332
 
 
333
 
    connect( widget, SIGNAL( legendFixedPositionChanged( LegendPosition ) ),
334
 
             this,   SLOT( setLegendFixedPosition( LegendPosition ) ) );
335
 
    
336
 
    connect( widget, SIGNAL( legendBackgroundColorChanged( const QColor& ) ) ,
337
 
             this,   SLOT( setLegendBackgroundColor( const QColor& ) ) );
338
 
    connect( widget, SIGNAL( legendFrameColorChanged( const QColor& ) ) ,
339
 
             this,   SLOT( setLegendFrameColor( const QColor& ) ) );
340
 
    connect( widget, SIGNAL( legendShowFrameChanged( bool ) ) ,
341
 
             this,   SLOT( setLegendShowFrame( bool ) ) );
342
 
 
343
 
    return widget;
344
 
}
345
 
 
346
 
 
347
 
void ChartTool::setChartType( ChartType type, ChartSubtype subtype )
348
 
{
349
 
    Q_ASSERT( d->shape );
350
 
    if ( !d->shape )
351
 
        return;
352
 
    
353
 
    d->shape->setChartType( type );
354
 
    d->shape->setChartSubType( subtype );
355
 
    d->shape->update();
356
 
    d->shape->legend()->update();
357
 
    
358
 
    foreach (QWidget *w, optionWidgets())
359
 
        w->update();
360
 
}
361
 
 
362
 
 
363
 
void ChartTool::setChartSubType( ChartSubtype subtype )
364
 
{
365
 
    Q_ASSERT( d->shape );
366
 
    if ( !d->shape )
367
 
        return;
368
 
 
369
 
    d->shape->setChartSubType( subtype );
370
 
    d->shape->update();
371
 
}
372
 
 
373
 
 
374
 
void ChartTool::setDataSetXDataRegion( DataSet *dataSet, const QString &region )
375
 
{
376
 
    if ( !dataSet )
377
 
        return;
378
 
 
379
 
    dataSet->setXDataRegionString( region );
380
 
}
381
 
 
382
 
void ChartTool::setDataSetYDataRegion( DataSet *dataSet, const QString &region )
383
 
{
384
 
    if ( !dataSet )
385
 
        return;
386
 
 
387
 
    dataSet->setYDataRegionString( region );
388
 
}
389
 
 
390
 
void ChartTool::setDataSetCustomDataRegion( DataSet *dataSet, const QString &region )
391
 
{
392
 
    if ( !dataSet )
393
 
        return;
394
 
 
395
 
    dataSet->setCustomDataRegionString( region );
396
 
}
397
 
 
398
 
void ChartTool::setDataSetLabelDataRegion( DataSet *dataSet, const QString &region )
399
 
{
400
 
    if ( !dataSet )
401
 
        return;
402
 
 
403
 
    dataSet->setLabelDataRegionString( region );
404
 
}
405
 
 
406
 
void ChartTool::setDataSetCategoryDataRegion( DataSet *dataSet, const QString &region )
407
 
{
408
 
    if ( !dataSet )
409
 
        return;
410
 
 
411
 
    dataSet->setCategoryDataRegionString( region );
412
 
}
413
 
 
414
 
 
415
 
void ChartTool::setDataSetChartType( DataSet *dataSet, ChartType type )
416
 
{
417
 
    Q_ASSERT( dataSet );
418
 
 
419
 
    if ( dataSet )
420
 
        dataSet->setChartType( type );
421
 
    d->shape->update();
422
 
    d->shape->legend()->update();
423
 
}
424
 
 
425
 
void ChartTool::setDataSetChartSubType( DataSet *dataSet, ChartSubtype subType )
426
 
{
427
 
    Q_ASSERT( dataSet );
428
 
    if ( dataSet )
429
 
        dataSet->setChartSubType( subType );
430
 
    d->shape->update();
431
 
}
432
 
 
433
 
 
434
 
void ChartTool::setDataSetColor( DataSet *dataSet, const QColor& color )
435
 
{
436
 
    if ( !dataSet )
437
 
        return;
438
 
 
439
 
    dataSet->setColor( color );
440
 
    d->shape->update();
441
 
}
442
 
 
443
 
void ChartTool::setDataSetAxis( DataSet *dataSet, Axis *axis )
444
 
{
445
 
    if ( !dataSet || !axis )
446
 
        return;
447
 
 
448
 
    dataSet->attachedAxis()->detachDataSet( dataSet );
449
 
    axis->attachDataSet( dataSet );
450
 
    d->shape->update();
451
 
}
452
 
 
453
 
void ChartTool::setDataSetShowValues( DataSet *dataSet, bool b )
454
 
{
455
 
    if ( !dataSet )
456
 
        return;
457
 
 
458
 
    dataSet->setShowValues( b );
459
 
    d->shape->update();
460
 
}
461
 
 
462
 
void ChartTool::setDataSetShowLabels( DataSet *dataSet, bool b )
463
 
{
464
 
    if ( !dataSet )
465
 
        return;
466
 
 
467
 
    dataSet->setShowLabels( b );
468
 
    d->shape->update();
469
 
}
470
 
 
471
 
 
472
 
void ChartTool::setThreeDMode( bool threeD )
473
 
{
474
 
    Q_ASSERT( d->shape );
475
 
    if ( !d->shape )
476
 
        return;
477
 
 
478
 
    d->shape->setThreeD( threeD );
479
 
    d->shape->update();
480
 
}
481
 
 
482
 
void ChartTool::setShowTitle( bool show )
483
 
{
484
 
    Q_ASSERT( d->shape );
485
 
    if ( !d->shape )
486
 
        return;
487
 
 
488
 
    d->shape->showTitle(show);
489
 
    d->shape->update();
490
 
}
491
 
 
492
 
void ChartTool::setShowSubTitle( bool show )
493
 
{
494
 
    Q_ASSERT( d->shape );
495
 
    if ( !d->shape )
496
 
        return;
497
 
 
498
 
    d->shape->showSubTitle(show);
499
 
    d->shape->update();
500
 
}
501
 
 
502
 
void ChartTool::setShowFooter( bool show )
503
 
{
504
 
    Q_ASSERT( d->shape );
505
 
    if ( !d->shape )
506
 
        return;
507
 
 
508
 
    d->shape->showFooter(show);
509
 
    d->shape->update();
510
 
}
511
 
 
512
 
void ChartTool::setDataDirection( Qt::Orientation direction )
513
 
{
514
 
    Q_ASSERT( d->shape );
515
 
    if ( !d->shape )
516
 
        return;
517
 
 
518
 
    d->shape->proxyModel()->setDataDirection( direction );
519
 
    d->shape->relayout();
520
 
}
521
 
 
522
 
void ChartTool::setFirstRowIsLabel( bool b )
523
 
{
524
 
    Q_ASSERT( d->shape );
525
 
    if ( d->shape != 0 )
526
 
        d->shape->proxyModel()->setFirstRowIsLabel( b );
527
 
    d->shape->relayout();
528
 
}
529
 
 
530
 
void ChartTool::setFirstColumnIsLabel( bool b )
531
 
{
532
 
    Q_ASSERT( d->shape );
533
 
    if ( d->shape != 0 )
534
 
        d->shape->proxyModel()->setFirstColumnIsLabel( b );
535
 
 
536
 
    d->shape->relayout();
537
 
}
538
 
 
539
 
 
540
 
void ChartTool::setLegendTitle( const QString &title )
541
 
{
542
 
    Q_ASSERT( d->shape );
543
 
    Q_ASSERT( d->shape->legend() );
544
 
 
545
 
    d->shape->legend()->setTitle( title );
546
 
    d->shape->legend()->update();
547
 
}
548
 
 
549
 
void ChartTool::setLegendFont( const QFont &font )
550
 
{
551
 
    Q_ASSERT( d->shape );
552
 
    Q_ASSERT( d->shape->legend() );
553
 
 
554
 
    // There only is a general font, for the legend items and the legend title
555
 
    d->shape->legend()->setFont( font );
556
 
    d->shape->legend()->update();
557
 
}
558
 
 
559
 
void ChartTool::setLegendFontSize( int size )
560
 
{
561
 
    Q_ASSERT( d->shape );
562
 
    Q_ASSERT( d->shape->legend() );
563
 
 
564
 
    d->shape->legend()->setFontSize( size );
565
 
    d->shape->legend()->update();
566
 
}
567
 
 
568
 
void ChartTool::setLegendOrientation( Qt::Orientation orientation )
569
 
{
570
 
    Q_ASSERT( d->shape );
571
 
    Q_ASSERT( d->shape->legend() );
572
 
 
573
 
    d->shape->legend()->setExpansion( QtOrientationToLegendExpansion( orientation ) );
574
 
    d->shape->legend()->update();
575
 
}
576
 
 
577
 
void ChartTool::setLegendAlignment( Qt::Alignment alignment )
578
 
{
579
 
    Q_ASSERT( d->shape );
580
 
    Q_ASSERT( d->shape->legend() );
581
 
 
582
 
    d->shape->legend()->setAlignment( alignment );
583
 
    d->shape->legend()->update();
584
 
}
585
 
 
586
 
void ChartTool::setLegendFixedPosition( LegendPosition position )
587
 
{
588
 
    Q_ASSERT( d->shape );
589
 
    Q_ASSERT( d->shape->legend() );
590
 
 
591
 
    d->shape->legend()->setLegendPosition( position );
592
 
 
593
 
    foreach (QWidget *w, optionWidgets()) {
594
 
        ( ( ChartConfigWidget* ) w )->updateFixedPosition( position );
595
 
    }
596
 
 
597
 
    d->shape->legend()->update();
598
 
}
599
 
 
600
 
void ChartTool::setLegendBackgroundColor( const QColor& color )
601
 
{
602
 
    Q_ASSERT( d->shape );
603
 
    Q_ASSERT( d->shape->legend() );
604
 
 
605
 
    d->shape->legend()->setBackgroundColor( color );
606
 
    d->shape->legend()->update();
607
 
}
608
 
 
609
 
void ChartTool::setLegendFrameColor( const QColor& color )
610
 
{
611
 
    Q_ASSERT( d->shape );
612
 
    Q_ASSERT( d->shape->legend() );
613
 
 
614
 
    d->shape->legend()->setFrameColor( color );
615
 
    d->shape->legend()->update();
616
 
}
617
 
 
618
 
void ChartTool::setLegendShowFrame( bool show )
619
 
{
620
 
    Q_ASSERT( d->shape );
621
 
    Q_ASSERT( d->shape->legend() );
622
 
 
623
 
    d->shape->legend()->setShowFrame( show );
624
 
    d->shape->legend()->update();
625
 
}
626
 
 
627
 
 
628
 
void ChartTool::addAxis( AxisPosition position, const QString& title )
629
 
{
630
 
    Q_ASSERT( d->shape );
631
 
 
632
 
    Axis *axis = new Axis( d->shape->plotArea() );
633
 
    axis->setPosition( position );
634
 
    axis->setTitleText( title );
635
 
    
636
 
    d->shape->plotArea()->addAxis( axis );
637
 
    d->shape->updateChildrenPositions();
638
 
    d->shape->update();
639
 
}
640
 
 
641
 
void ChartTool::removeAxis( Axis *axis )
642
 
{
643
 
    Q_ASSERT( d->shape );
644
 
 
645
 
    d->shape->plotArea()->removeAxis( axis );
646
 
    d->shape->update();
647
 
}
648
 
 
649
 
void ChartTool::setAxisTitle( Axis *axis, const QString& title )
650
 
{
651
 
    axis->setTitleText( title );
652
 
    d->shape->update();
653
 
}
654
 
 
655
 
void ChartTool::setAxisShowTitle( Axis *axis, bool show )
656
 
{
657
 
    Q_ASSERT( d->shape );
658
 
 
659
 
    axis->title()->setVisible( show );
660
 
    d->shape->update();
661
 
}
662
 
 
663
 
void ChartTool::setAxisShowGridLines( Axis *axis, bool b )
664
 
{
665
 
    axis->setShowMajorGrid( b );
666
 
    axis->setShowMinorGrid( b );
667
 
    d->shape->update();
668
 
}
669
 
 
670
 
void ChartTool::setAxisUseLogarithmicScaling( Axis *axis, bool b )
671
 
{
672
 
    axis->setScalingLogarithmic( b );
673
 
    d->shape->update();
674
 
}
675
 
 
676
 
void ChartTool::setAxisStepWidth( Axis *axis, qreal width )
677
 
{
678
 
    axis->setMajorInterval( width );
679
 
    d->shape->update();
680
 
}
681
 
 
682
 
void ChartTool::setAxisSubStepWidth( Axis *axis, qreal width )
683
 
{
684
 
    axis->setMinorInterval( width );
685
 
    d->shape->update();
686
 
}
687
 
 
688
 
void ChartTool::setAxisUseAutomaticStepWidth( Axis *axis, bool automatic )
689
 
{
690
 
    axis->setUseAutomaticMajorInterval( automatic );
691
 
    d->shape->update();
692
 
}
693
 
 
694
 
void ChartTool::setAxisUseAutomaticSubStepWidth( Axis *axis, bool automatic )
695
 
{
696
 
    axis->setUseAutomaticMinorInterval( automatic );
697
 
    d->shape->update();
698
 
}
699
 
 
700
 
 
701
 
void ChartTool::setGapBetweenBars( int percent )
702
 
{
703
 
    Q_ASSERT( d->shape );
704
 
 
705
 
    d->shape->plotArea()->setGapBetweenBars( percent );
706
 
    d->shape->update();
707
 
}
708
 
 
709
 
void ChartTool::setGapBetweenSets( int percent )
710
 
{
711
 
    Q_ASSERT( d->shape );
712
 
 
713
 
    d->shape->plotArea()->setGapBetweenSets( percent );
714
 
    d->shape->update();
715
 
}
716
 
 
717
 
void ChartTool::setPieExplodeFactor( DataSet *dataSet, int percent )
718
 
{
719
 
    Q_ASSERT( d->shape );
720
 
 
721
 
    d->shape->plotArea()->setPieExplodeFactor( dataSet, percent );
722
 
    d->shape->update();
723
 
}
724
 
 
725
 
void ChartTool::setShowLegend( bool b )
726
 
{
727
 
    Q_ASSERT( d->shape );
728
 
 
729
 
    d->shape->legend()->setVisible( b );
730
 
    d->shape->legend()->update();
731
 
}
732
 
 
733
 
#include "ChartTool.moc"