File indexing completed on 2024-05-12 16:33:30

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2007, 2010  Inge Wallin <inge@lysator.liu.se>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 // Own
0022 #include "ChartTool.h"
0023 
0024 // Qt
0025 #include <QAction>
0026 #include <QGridLayout>
0027 #include <QToolButton>
0028 #include <QCheckBox>
0029 #include <QTabWidget>
0030 #include <QPen>
0031 #include <QBrush>
0032 #include <QPainter>
0033 
0034 // KF5
0035 #include <klocalizedstring.h>
0036 
0037 // Calligra
0038 #include <KoCanvasBase.h>
0039 #include <KoSelection.h>
0040 #include <KoShapeManager.h>
0041 #include <KoPointerEvent.h>
0042 #include <KoTextShapeData.h>
0043 #include <KoViewConverter.h>
0044 #include <KoInteractionTool.h>
0045 
0046 // KChart
0047 #include <KChartChart>
0048 #include <KChartCartesianAxis>
0049 #include <KChartGridAttributes>
0050 #include <KChartAbstractCartesianDiagram>
0051 #include <KChartCartesianCoordinatePlane>
0052 #include <KChartPosition>
0053 #include <KChartPieAttributes>
0054 
0055 // KoChart
0056 #include "Surface.h"
0057 #include "PlotArea.h"
0058 #include "ChartLayout.h"
0059 #include "Axis.h"
0060 #include "DataSet.h"
0061 #include "Legend.h"
0062 #include "ChartProxyModel.h"
0063 #include "TitlesConfigWidget.h"
0064 #include "LegendConfigWidget.h"
0065 #include "PlotAreaConfigWidget.h"
0066 #include "AxesConfigWidget.h"
0067 #include "DataSetConfigWidget.h"
0068 #include "PieConfigWidget.h"
0069 #include "RingConfigWidget.h"
0070 #include "RadarDataSetConfigWidget.h"
0071 #include "KChartConvertions.h"
0072 #include "commands/ChartTypeCommand.h"
0073 #include "commands/LegendCommand.h"
0074 #include "commands/AxisCommand.h"
0075 #include "commands/DatasetCommand.h"
0076 #include "commands/ChartTextShapeCommand.h"
0077 #include "commands/AddRemoveAxisCommand.h"
0078 #include "commands/GapCommand.h"
0079 #include "commands/PlotAreaCommand.h"
0080 #include "commands/DatasetCommand.h"
0081 #include "ChartDebug.h"
0082 
0083 
0084 using namespace KoChart;
0085 
0086 
0087 class ChartTool::Private
0088 {
0089 public:
0090     Private();
0091     ~Private();
0092 
0093     ChartShape  *shape;
0094     QModelIndex  datasetSelection;
0095     QPen         datasetSelectionPen;
0096     QBrush       datasetSelectionBrush;
0097 
0098 };
0099 
0100 ChartTool::Private::Private()
0101     : shape(0)
0102 {
0103 }
0104 
0105 ChartTool::Private::~Private()
0106 {
0107 }
0108 
0109 ChartTool::ChartTool(KoCanvasBase *canvas)
0110     : KoToolBase(canvas),
0111       d(new Private())
0112 {
0113     // Create QActions here.
0114 #if 0
0115     QActionGroup *group = new QActionGroup(this);
0116     m_foo  = new QAction(koIcon("this-action"), i18n("Do something"), this);
0117     m_foo->setCheckable(true);
0118     group->addAction(m_foo);
0119     connect(m_foo, SIGNAL(toggled(bool)), this, SLOT(catchFoo(bool)));
0120 
0121     m_bar  = new QAction(koIcon("that-action"), i18n("Do something else"), this);
0122     m_bar->setCheckable(true);
0123     group->addAction(m_bar);
0124     connect(m_foo, SIGNAL(toggled(bool)), this, SLOT(catchBar(bool)));
0125 
0126 #endif
0127     connect(canvas->shapeManager(), SIGNAL(selectionChanged()), this, SLOT(shapeSelectionChanged()));
0128 }
0129 
0130 ChartTool::~ChartTool()
0131 {
0132     delete d;
0133 }
0134 
0135 void ChartTool::shapeSelectionChanged()
0136 {
0137     // When this chart tool is activated with one chart and a new chart is created,
0138     // the new chart is selected but the deactivate method is not called,
0139     // so this tool will still operate on the old chart.
0140     // We activate the default tool to rectify this.
0141     // FIXME: could probably be done in KoToolBase (or wherever appropriate)
0142 
0143     if (!d->shape) {
0144         return;
0145     }
0146     QList<KoShape*> lst = canvas()->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
0147     if (lst.contains(d->shape)) {
0148         return;
0149     }
0150     for (KoShape *s : lst) {
0151         ChartShape *chart = dynamic_cast<ChartShape*>(s);
0152         if (chart && chart != d->shape) {
0153             activateTool(KoInteractionTool_ID);
0154         }
0155     }
0156 }
0157 
0158 void ChartTool::paint(QPainter &painter, const KoViewConverter &converter)
0159 {
0160     if (d->shape) {
0161         QPen pen;
0162         //Use the #00adf5 color with 50% opacity
0163         pen.setColor(QColor(0, 173, 245, 127));
0164         pen.setWidth(qMax((uint)1, handleRadius() / 2));
0165         pen.setJoinStyle(Qt::RoundJoin);
0166         painter.setPen(pen);
0167 
0168         QTransform painterMatrix = painter.worldTransform();
0169         painter.setWorldTransform(d->shape->absoluteTransformation(&converter) * painterMatrix);
0170         KoShape::applyConversion(painter, converter);
0171         painter.drawRect(QRectF(QPointF(), d->shape->size()));
0172     }
0173 }
0174 
0175 void ChartTool::mousePressEvent(KoPointerEvent *event)
0176 {
0177 #if 1  // disabled
0178     Q_UNUSED(event);
0179     return;
0180 #else
0181     // Select dataset
0182     if (!d->shape || !d->shape->kdChart() || ! d->shape->kdChart()->coordinatePlane()
0183         || !d->shape->kdChart()->coordinatePlane()->diagram())
0184         return;
0185     QPointF point = event->point - d->shape->position();
0186     QModelIndex selection = d->shape->kdChart()->coordinatePlane()->diagram()->indexAt(point.toPoint());
0187     // Note: the dataset will always stay column() due to the transformations being
0188     // done internally by the ChartProxyModel
0189     int dataset = selection.column();
0190 
0191     if (d->datasetSelection.isValid()) {
0192         d->shape->kdChart()->coordinatePlane()->diagram()->setPen(d->datasetSelection.column(), d->datasetSelectionPen);
0193         //d->shape->kdChart()->coordinatePlane()->diagram()->setBrush(d->datasetSelection, d->datasetSelectionBrush);
0194     }
0195     if (selection.isValid()) {
0196         d->datasetSelection = selection;
0197 
0198         QPen pen(Qt::DotLine);
0199         pen.setColor(Qt::darkGray);
0200         pen.setWidth(1);
0201 
0202         d->datasetSelectionBrush = d->shape->kdChart()->coordinatePlane()->diagram()->brush(selection);
0203         d->datasetSelectionPen   = d->shape->kdChart()->coordinatePlane()->diagram()->pen(dataset);
0204 
0205         d->shape->kdChart()->coordinatePlane()->diagram()->setPen(dataset, pen);
0206         //d->shape->kdChart()->coordinatePlane()->diagram()->setBrush(selection, QBrush(Qt::lightGray));
0207     }
0208     ((ChartConfigWidget*)optionWidget())->selectDataset(dataset);
0209 
0210     d->shape->update();
0211 #endif
0212 }
0213 
0214 void ChartTool::mouseMoveEvent(KoPointerEvent *event)
0215 {
0216     event->ignore();
0217 }
0218 
0219 void ChartTool::mouseReleaseEvent(KoPointerEvent *event)
0220 {
0221     event->ignore();
0222 }
0223 
0224 
0225 void ChartTool::activate(ToolActivation, const QSet<KoShape*> &shapes)
0226 {
0227     debugChartTool<<shapes;
0228     d->shape = 0;
0229     for (KoShape *s : shapes) {
0230         d->shape = dynamic_cast<ChartShape*>(s);
0231         if (!d->shape) {
0232             for (KoShape *parent = s->parent(); parent; parent = parent->parent()) {
0233                 d->shape = dynamic_cast<ChartShape*>(parent);
0234                 if (d->shape) {
0235                     break;
0236                 }
0237             }
0238         }
0239         if (d->shape) {
0240             break;
0241         }
0242     }
0243     debugChartTool<<shapes<<d->shape;
0244     if (!d->shape) {
0245         emit done();
0246         return;
0247     }
0248     useCursor(Qt::ArrowCursor);
0249 
0250     foreach (QWidget *w, optionWidgets()) {
0251         ConfigWidgetBase *widget = dynamic_cast<ConfigWidgetBase*>(w);
0252         Q_ASSERT(widget);
0253         if (widget) {
0254             widget->open(d->shape);
0255         }
0256     }
0257     foreach (QWidget *w, optionWidgets()) {
0258         ConfigWidgetBase *widget = dynamic_cast<ConfigWidgetBase*>(w);
0259         Q_ASSERT(widget);
0260         if (widget) {
0261             widget->updateData();
0262         }
0263     }
0264     d->shape->update(); // to paint decoration
0265 }
0266 
0267 void ChartTool::deactivate()
0268 {
0269     debugChartTool<<d->shape;
0270     if (!d->shape) {
0271         // activated without shape
0272         return;
0273     }
0274     foreach (QWidget *w, optionWidgets()) {
0275         ConfigWidgetBase *configWidget = dynamic_cast<ConfigWidgetBase*>(w);
0276         if (configWidget)
0277             configWidget->deactivate();
0278     }
0279     if (d->shape) {
0280         d->shape->update(); // to get rid of decoration
0281     }
0282     d->shape = 0;
0283 }
0284 
0285 QList<QPointer<QWidget> > ChartTool::createOptionWidgets()
0286 {
0287     QList<QPointer<QWidget> > widgets;
0288 
0289     TitlesConfigWidget *titles = new TitlesConfigWidget();
0290     titles->setWindowTitle(i18n("Titles"));
0291     widgets.append(titles);
0292     connect(titles->ui.showTitle, SIGNAL(toggled(bool)), this, SLOT(setShowTitle(bool)));
0293     connect(titles->ui.titlePositioning, SIGNAL(currentIndexChanged(int)), this, SLOT(setTitlePositioning(int)));
0294     connect(titles->ui.titleResize, SIGNAL(currentIndexChanged(int)), this, SLOT(setTitleResize(int)));
0295     connect(titles->ui.showSubTitle, SIGNAL(toggled(bool)), this, SLOT(setShowSubTitle(bool)));
0296     connect(titles->ui.subtitlePositioning, SIGNAL(currentIndexChanged(int)), this, SLOT(setSubTitlePositioning(int)));
0297     connect(titles->ui.subtitleResize, SIGNAL(currentIndexChanged(int)), this, SLOT(setSubTitleResize(int)));
0298     connect(titles->ui.showFooter, SIGNAL(toggled(bool)), this, SLOT(setShowFooter(bool)));
0299     connect(titles->ui.footerPositioning, SIGNAL(currentIndexChanged(int)), this, SLOT(setFooterPositioning(int)));
0300     connect(titles->ui.footerResize, SIGNAL(currentIndexChanged(int)), this, SLOT(setFooterResize(int)));
0301 
0302     connect(d->shape, SIGNAL(updateConfigWidget()), titles, SLOT(updateData()));
0303 
0304     LegendConfigWidget *legend = new LegendConfigWidget();
0305     legend->setWindowTitle(i18n("Legend"));
0306     widgets.append(legend);
0307     connect(legend, SIGNAL(showLegendChanged(bool)),
0308             this,   SLOT(setShowLegend(bool)));
0309     connect(legend, SIGNAL(legendTitleChanged(QString)),
0310             this,   SLOT(setLegendTitle(QString)));
0311     connect(legend, SIGNAL(legendFontChanged(QFont)),
0312             this,   SLOT(setLegendFont(QFont)));
0313     connect(legend, SIGNAL(legendFontSizeChanged(int)),
0314             this,   SLOT(setLegendFontSize(int)));
0315     connect(legend, SIGNAL(legendOrientationChanged(Qt::Orientation)),
0316             this,   SLOT(setLegendOrientation(Qt::Orientation)));
0317     connect(legend, SIGNAL(legendPositionChanged(Position)),
0318             this,   SLOT(setLegendPosition(Position)));
0319     connect(legend, SIGNAL(legendAlignmentChanged(Qt::Alignment)),
0320             this,   SLOT(setLegendAlignment(Qt::Alignment)));
0321 
0322     connect(d->shape->legend(), SIGNAL(updateConfigWidget()), legend, SLOT(updateData()));
0323 
0324     PlotAreaConfigWidget  *plotarea = new PlotAreaConfigWidget();
0325     plotarea->setWindowTitle(i18n("Plot Area"));
0326     widgets.append(plotarea);
0327 
0328     connect(plotarea, SIGNAL(chartTypeChanged(ChartType,ChartSubtype)),
0329             this,   SLOT(setChartType(ChartType,ChartSubtype)));
0330     connect(plotarea, SIGNAL(chartSubTypeChanged(ChartSubtype)),
0331             this,   SLOT(setChartSubType(ChartSubtype)));
0332     connect(plotarea, SIGNAL(threeDModeToggled(bool)),
0333             this,   SLOT(setThreeDMode(bool)));
0334     connect(plotarea, SIGNAL(chartOrientationChanged(Qt::Orientation)),
0335             this,   SLOT(setChartOrientation(Qt::Orientation)));
0336 
0337     // data set edit dialog
0338     connect(plotarea, SIGNAL(dataSetXDataRegionChanged(DataSet*,CellRegion)),
0339             this,   SLOT(setDataSetXDataRegion(DataSet*,CellRegion)));
0340     connect(plotarea, SIGNAL(dataSetYDataRegionChanged(DataSet*,CellRegion)),
0341             this,   SLOT(setDataSetYDataRegion(DataSet*,CellRegion)));
0342     connect(plotarea, SIGNAL(dataSetCustomDataRegionChanged(DataSet*,CellRegion)),
0343             this,   SLOT(setDataSetCustomDataRegion(DataSet*,CellRegion)));
0344     connect(plotarea, SIGNAL(dataSetLabelDataRegionChanged(DataSet*,CellRegion)),
0345             this,   SLOT(setDataSetLabelDataRegion(DataSet*,CellRegion)));
0346     connect(plotarea, SIGNAL(dataSetCategoryDataRegionChanged(DataSet*,CellRegion)),
0347             this,   SLOT(setDataSetCategoryDataRegion(DataSet*,CellRegion)));
0348 
0349     AxesConfigWidget *axes = plotarea->cartesianAxesConfigWidget();
0350     connect(axes, SIGNAL(axisAdded(AxisDimension,QString)),
0351             this,   SLOT(addAxis(AxisDimension,QString)));
0352     connect(axes, SIGNAL(axisRemoved(Axis*)),
0353             this,   SLOT(removeAxis(Axis*)));
0354     connect(axes, SIGNAL(axisShowTitleChanged(Axis*,bool)),
0355             this,   SLOT(setAxisShowTitle(Axis*,bool)));
0356     connect(axes, SIGNAL(axisShowChanged(Axis*,bool)),
0357             this,   SLOT(setShowAxis(Axis*,bool)));
0358     connect(axes, SIGNAL(axisPositionChanged(Axis*,QString)),
0359             this,   SLOT(setAxisPosition(Axis*,QString)));
0360     connect(axes, SIGNAL(axisLabelsPositionChanged(Axis*,QString)),
0361             this,   SLOT(setAxisLabelsPosition(Axis*,QString)));
0362     connect(axes, SIGNAL(axisShowLabelsChanged(Axis*,bool)),
0363             this,   SLOT(setAxisShowLabels(Axis*,bool)));
0364 
0365     connect(axes, SIGNAL(axisShowMajorGridLinesChanged(Axis*,bool)),
0366             this,   SLOT(setAxisShowMajorGridLines(Axis*,bool)));
0367     connect(axes, SIGNAL(axisShowMinorGridLinesChanged(Axis*,bool)),
0368             this,   SLOT(setAxisShowMinorGridLines(Axis*,bool)));
0369     // scaling dialog
0370     connect(axes, SIGNAL(axisUseLogarithmicScalingChanged(Axis*,bool)),
0371             this,   SLOT(setAxisUseLogarithmicScaling(Axis*,bool)));
0372     connect(axes, SIGNAL(axisStepWidthChanged(Axis*,qreal)),
0373             this,   SLOT(setAxisStepWidth(Axis*,qreal)));
0374     connect(axes, SIGNAL(axisSubStepWidthChanged(Axis*,qreal)),
0375             this,   SLOT(setAxisSubStepWidth(Axis*,qreal)));
0376     connect(axes, SIGNAL(axisUseAutomaticStepWidthChanged(Axis*,bool)),
0377             this,   SLOT(setAxisUseAutomaticStepWidth(Axis*,bool)));
0378     connect(axes, SIGNAL(axisUseAutomaticSubStepWidthChanged(Axis*,bool)),
0379             this,   SLOT(setAxisUseAutomaticSubStepWidth(Axis*,bool)));
0380     // font dialog
0381     connect(axes, SIGNAL(axisLabelsFontChanged(Axis*,QFont)),
0382             this,   SLOT(setAxisLabelsFont(Axis*,QFont)));
0383 
0384     connect(axes, SIGNAL(gapBetweenBarsChanged(Axis*,int)),
0385             this,   SLOT(setGapBetweenBars(Axis*,int)));
0386     connect(axes, SIGNAL(gapBetweenSetsChanged(Axis*,int)),
0387             this,   SLOT(setGapBetweenSets(Axis*,int)));
0388 
0389 
0390     DataSetConfigWidget *dataset = plotarea->cartesianDataSetConfigWidget();
0391     connect(dataset, SIGNAL(dataSetChartTypeChanged(DataSet*,ChartType,ChartSubtype)),
0392             this,   SLOT(setDataSetChartType(DataSet*,ChartType,ChartSubtype)));
0393     connect(dataset, SIGNAL(datasetBrushChanged(DataSet*,QColor,int)),
0394             this, SLOT(setDataSetBrush(DataSet*,QColor,int)));
0395     connect(dataset, SIGNAL(dataSetMarkerChanged(DataSet*,OdfSymbolType,OdfMarkerStyle)),
0396             this, SLOT(setDataSetMarker(DataSet*,OdfSymbolType,OdfMarkerStyle)));
0397     connect(dataset, SIGNAL(datasetPenChanged(DataSet*,QColor,int)),
0398             this, SLOT(setDataSetPen(DataSet*,QColor,int)));
0399     connect(dataset, SIGNAL(datasetShowCategoryChanged(DataSet*,bool,int)),
0400             this, SLOT(setDataSetShowCategory(DataSet*,bool,int)));
0401     connect(dataset, SIGNAL(dataSetShowNumberChanged(DataSet*,bool,int)),
0402             this, SLOT(setDataSetShowNumber(DataSet*,bool,int)));
0403     connect(dataset, SIGNAL(datasetShowPercentChanged(DataSet*,bool,int)),
0404             this, SLOT(setDataSetShowPercent(DataSet*,bool,int)));
0405     connect(dataset, SIGNAL(datasetShowSymbolChanged(DataSet*,bool,int)),
0406             this, SLOT(setDataSetShowSymbol(DataSet*,bool,int)));
0407     connect(dataset, SIGNAL(dataSetAxisChanged(DataSet*,Axis*)),
0408             this, SLOT(setDataSetAxis(DataSet*,Axis*)));
0409     connect(dataset, SIGNAL(axisAdded(AxisDimension,QString)),
0410             this,   SLOT(addAxis(AxisDimension,QString)));
0411 
0412 
0413     PieConfigWidget *pie = plotarea->pieConfigWidget();
0414     connect(pie, SIGNAL(explodeFactorChanged(DataSet*,int, int)), this, SLOT(setPieExplodeFactor(DataSet*,int, int)));
0415     connect(pie, SIGNAL(brushChanged(DataSet*,QColor,int)), this, SLOT(setDataSetBrush(DataSet*,QColor,int)));
0416     connect(pie, SIGNAL(penChanged(DataSet*,QColor,int)), this, SLOT(setDataSetPen(DataSet*,QColor,int)));
0417     connect(pie, SIGNAL(showCategoryChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowCategory(DataSet*,bool,int)));
0418     connect(pie, SIGNAL(showNumberChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowNumber(DataSet*,bool,int)));
0419     connect(pie, SIGNAL(showPercentChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowPercent(DataSet*,bool,int)));
0420 
0421     RingConfigWidget *ring = plotarea->ringConfigWidget();
0422     connect(ring, SIGNAL(explodeFactorChanged(DataSet*,int, int)), this, SLOT(setPieExplodeFactor(DataSet*,int, int)));
0423     connect(ring, SIGNAL(brushChanged(DataSet*,QColor,int)), this, SLOT(setDataSetBrush(DataSet*,QColor,int)));
0424     connect(ring, SIGNAL(penChanged(DataSet*,QColor,int)), this, SLOT(setDataSetPen(DataSet*,QColor,int)));
0425     connect(ring, SIGNAL(showCategoryChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowCategory(DataSet*,bool,int)));
0426     connect(ring, SIGNAL(showNumberChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowNumber(DataSet*,bool,int)));
0427     connect(ring, SIGNAL(showPercentChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowPercent(DataSet*,bool,int)));
0428 
0429     axes = plotarea->stockAxesConfigWidget();
0430     connect(axes, SIGNAL(axisAdded(AxisDimension,QString)),
0431             this,   SLOT(addAxis(AxisDimension,QString)));
0432     connect(axes, SIGNAL(axisRemoved(Axis*)),
0433             this,   SLOT(removeAxis(Axis*)));
0434     connect(axes, SIGNAL(axisShowTitleChanged(Axis*,bool)),
0435             this,   SLOT(setAxisShowTitle(Axis*,bool)));
0436     connect(axes, SIGNAL(axisShowChanged(Axis*,bool)),
0437             this,   SLOT(setShowAxis(Axis*,bool)));
0438     connect(axes, SIGNAL(axisPositionChanged(Axis*,QString)),
0439             this,   SLOT(setAxisPosition(Axis*,QString)));
0440     connect(axes, SIGNAL(axisLabelsPositionChanged(Axis*,QString)),
0441             this,   SLOT(setAxisLabelsPosition(Axis*,QString)));
0442     connect(axes, SIGNAL(axisShowLabelsChanged(Axis*,bool)),
0443             this,   SLOT(setAxisShowLabels(Axis*,bool)));
0444 
0445     connect(axes, SIGNAL(axisShowMajorGridLinesChanged(Axis*,bool)),
0446             this,   SLOT(setAxisShowMajorGridLines(Axis*,bool)));
0447     connect(axes, SIGNAL(axisShowMinorGridLinesChanged(Axis*,bool)),
0448             this,   SLOT(setAxisShowMinorGridLines(Axis*,bool)));
0449     // scaling dialog
0450     connect(axes, SIGNAL(axisUseLogarithmicScalingChanged(Axis*,bool)),
0451             this,   SLOT(setAxisUseLogarithmicScaling(Axis*,bool)));
0452     connect(axes, SIGNAL(axisStepWidthChanged(Axis*,qreal)),
0453             this,   SLOT(setAxisStepWidth(Axis*,qreal)));
0454     connect(axes, SIGNAL(axisSubStepWidthChanged(Axis*,qreal)),
0455             this,   SLOT(setAxisSubStepWidth(Axis*,qreal)));
0456     connect(axes, SIGNAL(axisUseAutomaticStepWidthChanged(Axis*,bool)),
0457             this,   SLOT(setAxisUseAutomaticStepWidth(Axis*,bool)));
0458     connect(axes, SIGNAL(axisUseAutomaticSubStepWidthChanged(Axis*,bool)),
0459             this,   SLOT(setAxisUseAutomaticSubStepWidth(Axis*,bool)));
0460     // font dialog
0461     connect(axes, SIGNAL(axisLabelsFontChanged(Axis*,QFont)),
0462             this,   SLOT(setAxisLabelsFont(Axis*,QFont)));
0463 
0464     // Radar
0465     RadarDataSetConfigWidget *rdataset = plotarea->radarDataSetConfigWidget();
0466     connect(rdataset, SIGNAL(datasetBrushChanged(DataSet*,QColor,int)),
0467             this, SLOT(setDataSetBrush(DataSet*,QColor,int)));
0468     connect(rdataset, SIGNAL(dataSetMarkerChanged(DataSet*,OdfSymbolType,OdfMarkerStyle)),
0469             this, SLOT(setDataSetMarker(DataSet*,OdfSymbolType,OdfMarkerStyle)));
0470     connect(rdataset, SIGNAL(datasetPenChanged(DataSet*,QColor,int)),
0471             this, SLOT(setDataSetPen(DataSet*,QColor,int)));
0472     connect(rdataset, SIGNAL(datasetShowCategoryChanged(DataSet*,bool,int)),
0473             this, SLOT(setDataSetShowCategory(DataSet*,bool,int)));
0474     connect(rdataset, SIGNAL(dataSetShowNumberChanged(DataSet*,bool,int)),
0475             this, SLOT(setDataSetShowNumber(DataSet*,bool,int)));
0476     connect(rdataset, SIGNAL(datasetShowPercentChanged(DataSet*,bool,int)),
0477             this, SLOT(setDataSetShowPercent(DataSet*,bool,int)));
0478     connect(rdataset, SIGNAL(datasetShowSymbolChanged(DataSet*,bool,int)),
0479             this, SLOT(setDataSetShowSymbol(DataSet*,bool,int)));
0480 
0481     connect(d->shape, SIGNAL(updateConfigWidget()), plotarea, SLOT(updateData()));
0482 
0483     return widgets;
0484 }
0485 
0486 
0487 void ChartTool::setChartType(ChartType type, ChartSubtype subtype)
0488 {
0489     Q_ASSERT(d->shape);
0490     if (!d->shape) {
0491         return;
0492     }
0493     ChartTypeCommand *command = new ChartTypeCommand(d->shape);
0494     if (command!=0) {
0495         command->setChartType(type, subtype);
0496         canvas()->addCommand(command);
0497     }
0498     foreach (QWidget *w, optionWidgets()) {
0499         ConfigWidgetBase *cw = dynamic_cast<ConfigWidgetBase*>(w);
0500         if (cw) {
0501             cw->updateData();
0502         }
0503     }
0504 }
0505 
0506 
0507 void ChartTool::setChartSubType(ChartSubtype subtype)
0508 {
0509     Q_ASSERT(d->shape);
0510     if (!d->shape)
0511         return;
0512 
0513     d->shape->setChartSubType(subtype);
0514     d->shape->update();
0515 }
0516 
0517 
0518 void ChartTool::setDataSetXDataRegion(DataSet *dataSet, const CellRegion &region)
0519 {
0520     debugChartTool<<dataSet<<region.toString();
0521     if (!dataSet)
0522         return;
0523 
0524     dataSet->setXDataRegion(region);
0525     d->shape->update();
0526 }
0527 
0528 void ChartTool::setDataSetYDataRegion(DataSet *dataSet, const CellRegion &region)
0529 {
0530     if (!dataSet)
0531         return;
0532 
0533     dataSet->setYDataRegion(region);
0534     d->shape->update();
0535 }
0536 
0537 void ChartTool::setDataSetCustomDataRegion(DataSet *dataSet, const CellRegion &region)
0538 {
0539     if (!dataSet)
0540         return;
0541 
0542     dataSet->setCustomDataRegion(region);
0543 }
0544 
0545 void ChartTool::setDataSetLabelDataRegion(DataSet *dataSet, const CellRegion &region)
0546 {
0547     if (!dataSet)
0548         return;
0549 
0550     dataSet->setLabelDataRegion(region);
0551     d->shape->update();
0552     d->shape->legend()->update();
0553 }
0554 
0555 void ChartTool::setDataSetCategoryDataRegion(DataSet *dataSet, const CellRegion &region)
0556 {
0557     if (!dataSet) {
0558         return;
0559     }
0560     if (isCartesian(d->shape->chartType())) {
0561         // FIXME: Seems strange the way things are stored in multiple places
0562         // Categories are labels on the categories axis
0563         dataSet->setCategoryDataRegion(region); // probably should not be stored here, as datasets cannot have individual categories
0564         d->shape->plotArea()->proxyModel()->setCategoryDataRegion(region); // this seems to be for odf only!?
0565     } else {
0566         // Categories are legend texts
0567         dataSet->setCategoryDataRegion(region);
0568     }
0569     d->shape->update();
0570     d->shape->legend()->update();
0571 }
0572 
0573 
0574 void ChartTool::setDataSetChartType(DataSet *dataSet, ChartType type, ChartSubtype subType)
0575 {
0576     Q_ASSERT(d->shape);
0577     Q_ASSERT(dataSet);
0578     if (dataSet) {
0579         DatasetCommand *cmd = new DatasetCommand(dataSet, d->shape);
0580         cmd->setDataSetChartType(type, subType);
0581         canvas()->addCommand(cmd);
0582     }
0583     d->shape->update();
0584     d->shape->legend()->update();
0585 }
0586 
0587 
0588 void ChartTool::setDataSetBrush(DataSet *dataSet, const QColor& color, int section)
0589 {
0590     Q_ASSERT(d->shape);
0591     Q_ASSERT(dataSet || section >= 0);
0592     debugChartTool<<dataSet<<color<<section;
0593     if (!dataSet) {
0594         QList<DataSet*> lst = d->shape->proxyModel()->dataSets();
0595         if (lst.isEmpty()) {
0596             return;
0597         }
0598         // we set brush for section in all datasets
0599         KUndo2Command *command = new KUndo2Command();
0600         for (int i = 0; i < lst.count(); ++i) {
0601             DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command);
0602             cmd->setDataSetBrush(color);
0603             command->setText(cmd->text());
0604         }
0605         canvas()->addCommand(command);
0606     } else {
0607         DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section);
0608         command->setDataSetBrush(color);
0609         canvas()->addCommand(command);
0610     }
0611 }
0612 
0613 void ChartTool::setDataSetPen(DataSet *dataSet, const QColor& color, int section)
0614 {
0615     Q_ASSERT(d->shape);
0616     Q_ASSERT(dataSet || section >= 0);
0617     debugChartTool<<color<<section;
0618     if (!dataSet) {
0619         QList<DataSet*> lst = d->shape->proxyModel()->dataSets();
0620         if (lst.isEmpty()) {
0621             return;
0622         }
0623         // we set brush for section in all datasets
0624         KUndo2Command *command = new KUndo2Command();
0625         for (int i = 0; i < lst.count(); ++i) {
0626             DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command);
0627             cmd->setDataSetPen(color);
0628             command->setText(cmd->text());
0629         }
0630         canvas()->addCommand(command);
0631     } else {
0632         DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section);
0633         command->setDataSetPen(color);
0634         canvas()->addCommand(command);
0635     }
0636 }
0637 
0638 void ChartTool::setDataSetMarker(DataSet *dataSet, OdfSymbolType type, OdfMarkerStyle style)
0639 {
0640     Q_ASSERT(d->shape);
0641     if (!dataSet) {
0642         return;
0643     }
0644     DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
0645     command->setDataSetMarker(type, style);
0646     canvas()->addCommand(command);
0647 }
0648 void ChartTool::setDataSetAxis(DataSet *dataSet, Axis *axis)
0649 {
0650     Q_ASSERT(d->shape);
0651     if (!dataSet || !axis)
0652         return;
0653 
0654     DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
0655     command->setDataSetAxis(axis);
0656     canvas()->addCommand(command);
0657 }
0658 
0659 void ChartTool::setDataSetShowCategory(DataSet *dataSet, bool b, int section)
0660 {
0661     Q_ASSERT(d->shape);
0662     Q_ASSERT(dataSet || section >= 0);
0663     if (!dataSet) {
0664         QList<DataSet*> lst = d->shape->proxyModel()->dataSets();
0665         if (lst.isEmpty()) {
0666             return;
0667         }
0668         // we set brush for section in all datasets
0669         KUndo2Command *command = new KUndo2Command();
0670         for (int i = 0; i < lst.count(); ++i) {
0671             DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command);
0672             cmd->setDataSetShowCategory(b);
0673             command->setText(cmd->text());
0674         }
0675         canvas()->addCommand(command);
0676     } else {
0677         DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section);
0678         command->setDataSetShowCategory(b);
0679         canvas()->addCommand(command);
0680     }
0681 
0682     debugChartTool<<section<<b<<':'<<dataSet->valueLabelType(section).category;
0683 }
0684 
0685 void ChartTool::setDataSetShowNumber(DataSet *dataSet, bool b, int section)
0686 {
0687     debugChartTool<<b<<section<<dataSet;
0688     Q_ASSERT(d->shape);
0689     Q_ASSERT(dataSet || section >= 0);
0690     if (!dataSet) {
0691         QList<DataSet*> lst = d->shape->proxyModel()->dataSets();
0692         if (lst.isEmpty()) {
0693             return;
0694         }
0695         // we set brush for section in all datasets
0696         KUndo2Command *command = new KUndo2Command();
0697         for (int i = 0; i < lst.count(); ++i) {
0698             DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command);
0699             cmd->setDataSetShowNumber(b);
0700             command->setText(cmd->text());
0701         }
0702         canvas()->addCommand(command);
0703     } else {
0704         DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section);
0705         command->setDataSetShowNumber(b);
0706         canvas()->addCommand(command);
0707     }
0708     debugChartTool<<section<<b<<':'<<dataSet->valueLabelType(section).number;
0709 }
0710 
0711 void ChartTool::setDataSetShowPercent(DataSet *dataSet, bool b, int section)
0712 {
0713     Q_ASSERT(d->shape);
0714     Q_ASSERT(dataSet || section >= 0);
0715     if (!dataSet) {
0716         QList<DataSet*> lst = d->shape->proxyModel()->dataSets();
0717         if (lst.isEmpty()) {
0718             return;
0719         }
0720         // we set brush for section in all datasets
0721         KUndo2Command *command = new KUndo2Command();
0722         for (int i = 0; i < lst.count(); ++i) {
0723             DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command);
0724             cmd->setDataSetShowPercent(b);
0725             command->setText(cmd->text());
0726         }
0727         canvas()->addCommand(command);
0728     } else {
0729         DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section);
0730         command->setDataSetShowPercent(b);
0731         canvas()->addCommand(command);
0732     }
0733 
0734     debugChartTool<<section<<b<<':'<<dataSet->valueLabelType(section).percentage;
0735 }
0736 
0737 void ChartTool::setDataSetShowSymbol(DataSet *dataSet, bool b, int section)
0738 {
0739     Q_ASSERT(d->shape);
0740     Q_ASSERT(dataSet || section >= 0);
0741     if (!dataSet) {
0742         QList<DataSet*> lst = d->shape->proxyModel()->dataSets();
0743         if (lst.isEmpty()) {
0744             return;
0745         }
0746         // we set brush for section in all datasets
0747         KUndo2Command *command = new KUndo2Command();
0748         for (int i = 0; i < lst.count(); ++i) {
0749             DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command);
0750             cmd->setDataSetShowSymbol(b);
0751             command->setText(cmd->text());
0752         }
0753         canvas()->addCommand(command);
0754     } else {
0755         DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section);
0756         command->setDataSetShowSymbol(b);
0757         canvas()->addCommand(command);
0758     }
0759     debugChartTool<<section<<b<<':'<<dataSet->valueLabelType(section).symbol;
0760 }
0761 
0762 void ChartTool::setThreeDMode(bool threeD)
0763 {
0764     Q_ASSERT(d->shape);
0765     if (!d->shape)
0766         return;
0767 
0768     d->shape->setThreeD(threeD);
0769     d->shape->update();
0770 }
0771 
0772 void ChartTool::setShowTitle(bool show)
0773 {
0774     Q_ASSERT(d->shape);
0775     if (!d->shape)
0776         return;
0777 
0778     ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->title(), d->shape, show);
0779     canvas()->addCommand(command);
0780 }
0781 
0782 void ChartTool::setTitlePositioning(int index)
0783 {
0784     Q_ASSERT(d->shape);
0785     if (!d->shape) {
0786         return;
0787     }
0788     // TODD: undo command
0789     d->shape->title()->setAdditionalStyleAttribute("chart:auto-position", index == 0 ? "true" : "false");
0790     d->shape->layout()->scheduleRelayout();
0791     d->shape->layout()->layout();
0792     d->shape->update();
0793 }
0794 
0795 void ChartTool::setTitleResize(int index)
0796 {
0797     Q_ASSERT(d->shape);
0798     if (!d->shape) {
0799         return;
0800     }
0801     // TODD: undo command
0802     TextLabelData *labelData = dynamic_cast<TextLabelData*>(d->shape->title()->userData());
0803     if (labelData == 0) {
0804         return;
0805     }
0806     labelData->setResizeMethod(index == 0 ? KoTextShapeDataBase::AutoResize : KoTextShapeDataBase::NoResize);
0807     d->shape->layout()->scheduleRelayout();
0808     d->shape->layout()->layout();
0809     d->shape->update();
0810 }
0811 
0812 void ChartTool::setShowSubTitle(bool show)
0813 {
0814     Q_ASSERT(d->shape);
0815     if (!d->shape)
0816         return;
0817 
0818     ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->subTitle(), d->shape, show);
0819     canvas()->addCommand(command);
0820 }
0821 
0822 void ChartTool::setSubTitlePositioning(int index)
0823 {
0824     Q_ASSERT(d->shape);
0825     if (!d->shape) {
0826         return;
0827     }
0828     // TODD: undo command
0829     d->shape->subTitle()->setAdditionalStyleAttribute("chart:auto-position", index == 0 ? "true" : "false");
0830     d->shape->layout()->scheduleRelayout();
0831     d->shape->layout()->layout();
0832     d->shape->update();
0833 }
0834 
0835 void ChartTool::setSubTitleResize(int index)
0836 {
0837     Q_ASSERT(d->shape);
0838     if (!d->shape) {
0839         return;
0840     }
0841     // TODD: undo command
0842     TextLabelData *labelData = dynamic_cast<TextLabelData*>(d->shape->subTitle()->userData());
0843     if (labelData == 0) {
0844         return;
0845     }
0846     labelData->setResizeMethod(index == 0 ? KoTextShapeDataBase::AutoResize : KoTextShapeDataBase::NoResize);
0847     d->shape->layout()->scheduleRelayout();
0848     d->shape->layout()->layout();
0849     d->shape->update();
0850 }
0851 
0852 void ChartTool::setShowFooter(bool show)
0853 {
0854     Q_ASSERT(d->shape);
0855     if (!d->shape)
0856         return;
0857 
0858     ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->footer(), d->shape, show);
0859     canvas()->addCommand(command);
0860 }
0861 
0862 void ChartTool::setFooterPositioning(int index)
0863 {
0864     Q_ASSERT(d->shape);
0865     if (!d->shape) {
0866         return;
0867     }
0868     // TODD: undo command
0869     d->shape->footer()->setAdditionalStyleAttribute("chart:auto-position", index == 0 ? "true" : "false");
0870     d->shape->layout()->scheduleRelayout();
0871     d->shape->layout()->layout();
0872     d->shape->update();
0873 }
0874 
0875 void ChartTool::setFooterResize(int index)
0876 {
0877     Q_ASSERT(d->shape);
0878     if (!d->shape) {
0879         return;
0880     }
0881     // TODD: undo command
0882     TextLabelData *labelData = dynamic_cast<TextLabelData*>(d->shape->footer()->userData());
0883     if (labelData == 0) {
0884         return;
0885     }
0886     labelData->setResizeMethod(index == 0 ? KoTextShapeDataBase::AutoResize : KoTextShapeDataBase::NoResize);
0887     d->shape->layout()->scheduleRelayout();
0888     d->shape->layout()->layout();
0889     d->shape->update();
0890 }
0891 
0892 void ChartTool::setDataDirection(Qt::Orientation direction)
0893 {
0894     Q_ASSERT(d->shape);
0895     if (!d->shape)
0896         return;
0897 
0898     d->shape->proxyModel()->setDataDirection(direction);
0899     d->shape->relayout();
0900 }
0901 
0902 void ChartTool::setChartOrientation(Qt::Orientation direction)
0903 {
0904     Q_ASSERT(d->shape);
0905     if (!d->shape) {
0906         return;
0907     }
0908     PlotAreaCommand *command = new PlotAreaCommand(d->shape->plotArea());
0909     command->setOrientation(direction);
0910     canvas()->addCommand(command);
0911 }
0912 
0913 void ChartTool::setLegendTitle(const QString &title)
0914 {
0915     Q_ASSERT(d->shape);
0916     Q_ASSERT(d->shape->legend());
0917 
0918     LegendCommand *command = new LegendCommand(d->shape->legend());
0919     command->setLegendTitle(title);
0920     canvas()->addCommand(command);
0921 }
0922 
0923 void ChartTool::setLegendFont(const QFont &font)
0924 {
0925     Q_ASSERT(d->shape);
0926     Q_ASSERT(d->shape->legend());
0927 
0928     // There only is a general font, for the legend items and the legend title
0929     LegendCommand *command = new LegendCommand(d->shape->legend());
0930     command->setLegendFont(font);
0931     canvas()->addCommand(command);
0932 }
0933 
0934 void ChartTool::setLegendFontSize(int size)
0935 {
0936     Q_ASSERT(d->shape);
0937     Q_ASSERT(d->shape->legend());
0938 
0939     LegendCommand *command = new LegendCommand(d->shape->legend());
0940     command->setLegendFontSize(size);
0941     canvas()->addCommand(command);
0942 }
0943 
0944 void ChartTool::setLegendOrientation(Qt::Orientation orientation)
0945 {
0946     Q_ASSERT(d->shape);
0947     Q_ASSERT(d->shape->legend());
0948 
0949     LegendCommand *command = new LegendCommand(d->shape->legend());
0950     command->setLegendExpansion(QtOrientationToLegendExpansion(orientation));
0951     canvas()->addCommand(command);
0952 }
0953 
0954 void ChartTool::setLegendPosition(Position pos)
0955 {
0956     Q_ASSERT(d->shape);
0957     Q_ASSERT(d->shape->legend());
0958 
0959     // TODO undo command
0960     d->shape->legend()->setLegendPosition(pos);
0961     d->shape->legend()->update();
0962     d->shape->layout()->scheduleRelayout();
0963     d->shape->layout()->layout();
0964 }
0965 
0966 void ChartTool::setLegendAlignment(Qt::Alignment alignment)
0967 {
0968     Q_ASSERT(d->shape);
0969     Q_ASSERT(d->shape->legend());
0970 
0971     // TODO undo command
0972     d->shape->legend()->setAlignment(alignment);
0973     d->shape->legend()->update();
0974     d->shape->layout()->scheduleRelayout();
0975     d->shape->layout()->layout();
0976 }
0977 
0978 void ChartTool::addAxis(AxisDimension dimension, const QString& title)
0979 {
0980     Q_ASSERT(d->shape);
0981 
0982     Axis *axis = new Axis(d->shape->plotArea(), dimension); // automatically adds axis to plot area
0983     if (axis == d->shape->plotArea()->secondaryYAxis()) {
0984         axis->setOdfAxisPosition("end"); // right
0985     } else if (axis == d->shape->plotArea()->secondaryXAxis()) {
0986         axis->setOdfAxisPosition("end"); // top
0987         axis->updateKChartAxisPosition();
0988     }
0989     d->shape->plotArea()->takeAxis(axis); // so we remove it again, sigh
0990     axis->setTitleText(title);
0991     AddRemoveAxisCommand *command = new AddRemoveAxisCommand(axis, d->shape, true, canvas()->shapeManager());
0992     canvas()->addCommand(command);
0993 }
0994 
0995 void ChartTool::removeAxis(Axis *axis)
0996 {
0997     Q_ASSERT(d->shape);
0998 
0999     AddRemoveAxisCommand *command = new AddRemoveAxisCommand(axis, d->shape, false, canvas()->shapeManager());
1000     canvas()->addCommand(command);
1001 }
1002 
1003 void ChartTool::setAxisShowTitle(Axis *axis, bool show)
1004 {
1005     Q_ASSERT(d->shape);
1006     if (show && axis->titleText().isEmpty()) {
1007         axis->setTitleText(i18n("Axistitle"));
1008     }
1009     AxisCommand *command = new AxisCommand(axis, d->shape);
1010     command->setAxisShowTitle(show);
1011     canvas()->addCommand(command);
1012 }
1013 
1014 void ChartTool::setShowAxis(Axis *axis, bool show)
1015 {
1016     Q_ASSERT(d->shape);
1017     debugChartTool<<axis<<show;
1018     AxisCommand *command = new AxisCommand(axis, d->shape);
1019     command->setShowAxis(show);
1020     canvas()->addCommand(command);
1021 }
1022 
1023 void ChartTool::setAxisPosition(Axis *axis, const QString &pos)
1024 {
1025     Q_ASSERT(d->shape);
1026     debugChartTool<<axis<<pos;
1027     AxisCommand *command = new AxisCommand(axis, d->shape);
1028     command->setAxisPosition(pos);
1029     canvas()->addCommand(command);
1030 }
1031 
1032 void ChartTool::setAxisLabelsPosition(Axis *axis, const QString &pos)
1033 {
1034     Q_ASSERT(d->shape);
1035     debugChartTool<<axis<<pos;
1036     AxisCommand *command = new AxisCommand(axis, d->shape);
1037     command->setAxisLabelsPosition(pos);
1038     canvas()->addCommand(command);
1039 }
1040 
1041 void ChartTool::setAxisShowLabels(Axis *axis, bool b)
1042 {
1043     Q_ASSERT(d->shape);
1044 
1045     AxisCommand *command = new AxisCommand(axis, d->shape);
1046     command->setAxisShowLabels(b);
1047     canvas()->addCommand(command);
1048 }
1049 
1050 void ChartTool::setAxisShowMajorGridLines(Axis *axis, bool b)
1051 {
1052     Q_ASSERT(d->shape);
1053 
1054     AxisCommand *command = new AxisCommand(axis, d->shape);
1055     command->setAxisShowMajorGridLines(b);
1056     canvas()->addCommand(command);
1057 }
1058 
1059 void ChartTool::setAxisShowMinorGridLines(Axis *axis, bool b)
1060 {
1061     Q_ASSERT(d->shape);
1062 
1063     AxisCommand *command = new AxisCommand(axis, d->shape);
1064     command->setAxisShowMinorGridLines(b);
1065     canvas()->addCommand(command);
1066 }
1067 
1068 void ChartTool::setAxisUseLogarithmicScaling(Axis *axis, bool b)
1069 {
1070     Q_ASSERT(d->shape);
1071 
1072     AxisCommand *command = new AxisCommand(axis, d->shape);
1073     command->setAxisUseLogarithmicScaling(b);
1074     canvas()->addCommand(command);
1075 }
1076 
1077 void ChartTool::setAxisStepWidth(Axis *axis, qreal width)
1078 {
1079     Q_ASSERT(d->shape);
1080 
1081     AxisCommand *command = new AxisCommand(axis, d->shape);
1082     command->setAxisStepWidth(width);
1083     canvas()->addCommand(command);
1084 }
1085 
1086 void ChartTool::setAxisSubStepWidth(Axis *axis, qreal width)
1087 {
1088     Q_ASSERT(d->shape);
1089 
1090     AxisCommand *command = new AxisCommand(axis, d->shape);
1091     command->setAxisSubStepWidth(width);
1092     canvas()->addCommand(command);
1093 }
1094 
1095 void ChartTool::setAxisUseAutomaticStepWidth(Axis *axis, bool automatic)
1096 {
1097     Q_ASSERT(d->shape);
1098 
1099     AxisCommand *command = new AxisCommand(axis, d->shape);
1100     command->setAxisUseAutomaticStepWidth(automatic);
1101     canvas()->addCommand(command);
1102 }
1103 
1104 void ChartTool::setAxisUseAutomaticSubStepWidth(Axis *axis, bool automatic)
1105 {
1106     Q_ASSERT(d->shape);
1107 
1108     AxisCommand *command = new AxisCommand(axis, d->shape);
1109     command->setAxisUseAutomaticSubStepWidth(automatic);
1110     canvas()->addCommand(command);
1111 }
1112 
1113 void ChartTool::setAxisLabelsFont(Axis *axis, const QFont &font)
1114 {
1115     Q_ASSERT(d->shape);
1116 
1117     AxisCommand *command = new AxisCommand(axis, d->shape);
1118     command->setAxisLabelsFont(font);
1119     canvas()->addCommand(command);
1120 }
1121 
1122 
1123 void ChartTool::setGapBetweenBars(Axis *axis, int percent)
1124 {
1125     Q_ASSERT(d->shape);
1126     debugChartTool<<axis<<percent;
1127     GapCommand *command = new GapCommand(axis, d->shape);
1128     command->setGapBetweenBars(percent);
1129     canvas()->addCommand(command);
1130 }
1131 
1132 void ChartTool::setGapBetweenSets(Axis *axis, int percent)
1133 {
1134     Q_ASSERT(d->shape);
1135     debugChartTool<<axis<<percent;
1136     GapCommand *command = new GapCommand(axis, d->shape);
1137     command->setGapBetweenSets(percent);
1138     canvas()->addCommand(command);
1139 }
1140 
1141 void ChartTool::setPieExplodeFactor(DataSet *dataSet, int section, int percent)
1142 {
1143     Q_ASSERT(d->shape);
1144 
1145     dataSet->setPieExplodeFactor(section, percent);
1146     d->shape->update();
1147 }
1148 
1149 void ChartTool::setShowLegend(bool show)
1150 {
1151     Q_ASSERT(d->shape);
1152 
1153     ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->legend(), d->shape, show);
1154     if (show) {
1155         command->setText(kundo2_i18n("Show Legend"));
1156     } else {
1157         command->setText(kundo2_i18n("Hide Legend"));
1158     }
1159     canvas()->addCommand(command);
1160 }