diff --git a/plugins/chartshape/ChartTool.cpp b/plugins/chartshape/ChartTool.cpp index 424c0a09695..a3767eccf3f 100644 --- a/plugins/chartshape/ChartTool.cpp +++ b/plugins/chartshape/ChartTool.cpp @@ -1,1164 +1,1158 @@ /* This file is part of the KDE project * * Copyright (C) 2007, 2010 Inge Wallin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ // Own #include "ChartTool.h" // Qt #include #include #include #include #include #include #include #include // KF5 #include // Calligra #include #include #include #include #include #include #include // KChart #include #include #include #include #include #include #include // KoChart #include "Surface.h" #include "PlotArea.h" #include "ChartLayout.h" #include "Axis.h" #include "DataSet.h" #include "Legend.h" #include "ChartProxyModel.h" #include "TitlesConfigWidget.h" #include "LegendConfigWidget.h" #include "PlotAreaConfigWidget.h" #include "AxesConfigWidget.h" #include "DataSetConfigWidget.h" #include "PieConfigWidget.h" #include "RingConfigWidget.h" #include "RadarDataSetConfigWidget.h" #include "KChartConvertions.h" #include "commands/ChartTypeCommand.h" #include "commands/LegendCommand.h" #include "commands/AxisCommand.h" #include "commands/DatasetCommand.h" #include "commands/ChartTextShapeCommand.h" #include "commands/AddRemoveAxisCommand.h" #include "commands/GapCommand.h" #include "commands/PlotAreaCommand.h" +#include "commands/DatasetCommand.h" #include "ChartDebug.h" using namespace KoChart; class ChartTool::Private { public: Private(); ~Private(); ChartShape *shape; QModelIndex datasetSelection; QPen datasetSelectionPen; QBrush datasetSelectionBrush; }; ChartTool::Private::Private() : shape(0) { } ChartTool::Private::~Private() { } ChartTool::ChartTool(KoCanvasBase *canvas) : KoToolBase(canvas), d(new Private()) { // Create QActions here. #if 0 QActionGroup *group = new QActionGroup(this); m_foo = new QAction(koIcon("this-action"), i18n("Do something"), this); m_foo->setCheckable(true); group->addAction(m_foo); connect(m_foo, SIGNAL(toggled(bool)), this, SLOT(catchFoo(bool))); m_bar = new QAction(koIcon("that-action"), i18n("Do something else"), this); m_bar->setCheckable(true); group->addAction(m_bar); connect(m_foo, SIGNAL(toggled(bool)), this, SLOT(catchBar(bool))); #endif connect(canvas->shapeManager(), SIGNAL(selectionChanged()), this, SLOT(shapeSelectionChanged())); } ChartTool::~ChartTool() { delete d; } void ChartTool::shapeSelectionChanged() { // When this chart tool is activated with one chart and a new chart is created, // the new chart is selected but the deactivate method is not called, // so this tool will still operate on the old chart. // We activate the default tool to rectify this. // FIXME: could probably be done in KoToolBase (or wherever appropriate) if (!d->shape) { return; } QList lst = canvas()->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection); if (lst.contains(d->shape)) { return; } for (KoShape *s : lst) { ChartShape *chart = dynamic_cast(s); if (chart && chart != d->shape) { activateTool(KoInteractionTool_ID); } } } void ChartTool::paint(QPainter &painter, const KoViewConverter &converter) { if (d->shape) { QPen pen; //Use the #00adf5 color with 50% opacity pen.setColor(QColor(0, 173, 245, 127)); pen.setWidth(qMax((uint)1, handleRadius() / 2)); pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen); QTransform painterMatrix = painter.worldTransform(); painter.setWorldTransform(d->shape->absoluteTransformation(&converter) * painterMatrix); KoShape::applyConversion(painter, converter); painter.drawRect(QRectF(QPointF(), d->shape->size())); } } void ChartTool::mousePressEvent(KoPointerEvent *event) { #if 1 // disabled Q_UNUSED(event); return; #else // Select dataset if (!d->shape || !d->shape->kdChart() || ! d->shape->kdChart()->coordinatePlane() || !d->shape->kdChart()->coordinatePlane()->diagram()) return; QPointF point = event->point - d->shape->position(); QModelIndex selection = d->shape->kdChart()->coordinatePlane()->diagram()->indexAt(point.toPoint()); // Note: the dataset will always stay column() due to the transformations being // done internally by the ChartProxyModel int dataset = selection.column(); if (d->datasetSelection.isValid()) { d->shape->kdChart()->coordinatePlane()->diagram()->setPen(d->datasetSelection.column(), d->datasetSelectionPen); //d->shape->kdChart()->coordinatePlane()->diagram()->setBrush(d->datasetSelection, d->datasetSelectionBrush); } if (selection.isValid()) { d->datasetSelection = selection; QPen pen(Qt::DotLine); pen.setColor(Qt::darkGray); pen.setWidth(1); d->datasetSelectionBrush = d->shape->kdChart()->coordinatePlane()->diagram()->brush(selection); d->datasetSelectionPen = d->shape->kdChart()->coordinatePlane()->diagram()->pen(dataset); d->shape->kdChart()->coordinatePlane()->diagram()->setPen(dataset, pen); //d->shape->kdChart()->coordinatePlane()->diagram()->setBrush(selection, QBrush(Qt::lightGray)); } ((ChartConfigWidget*)optionWidget())->selectDataset(dataset); d->shape->update(); #endif } void ChartTool::mouseMoveEvent(KoPointerEvent *event) { event->ignore(); } void ChartTool::mouseReleaseEvent(KoPointerEvent *event) { event->ignore(); } void ChartTool::activate(ToolActivation, const QSet &shapes) { debugChartTool<shape = 0; for (KoShape *s : shapes) { d->shape = dynamic_cast(s); if (!d->shape) { for (KoShape *parent = s->parent(); parent; parent = parent->parent()) { d->shape = dynamic_cast(parent); if (d->shape) { break; } } } if (d->shape) { break; } } debugChartTool<shape; if (!d->shape) { emit done(); return; } useCursor(Qt::ArrowCursor); foreach (QWidget *w, optionWidgets()) { ConfigWidgetBase *widget = dynamic_cast(w); Q_ASSERT(widget); if (widget) { widget->open(d->shape); } } foreach (QWidget *w, optionWidgets()) { ConfigWidgetBase *widget = dynamic_cast(w); Q_ASSERT(widget); if (widget) { widget->updateData(); } } d->shape->update(); // to paint decoration } void ChartTool::deactivate() { debugChartTool<shape; foreach (QWidget *w, optionWidgets()) { ConfigWidgetBase *configWidget = dynamic_cast(w); if (configWidget) configWidget->deactivate(); } if (d->shape) { d->shape->update(); // to get rid of decoration } d->shape = 0; } QList > ChartTool::createOptionWidgets() { QList > widgets; TitlesConfigWidget *titles = new TitlesConfigWidget(); titles->setWindowTitle(i18n("Titles")); widgets.append(titles); connect(titles->ui.showTitle, SIGNAL(toggled(bool)), this, SLOT(setShowTitle(bool))); connect(titles->ui.titlePositioning, SIGNAL(currentIndexChanged(int)), this, SLOT(setTitlePositioning(int))); connect(titles->ui.titleResize, SIGNAL(currentIndexChanged(int)), this, SLOT(setTitleResize(int))); connect(titles->ui.showSubTitle, SIGNAL(toggled(bool)), this, SLOT(setShowSubTitle(bool))); connect(titles->ui.subtitlePositioning, SIGNAL(currentIndexChanged(int)), this, SLOT(setSubTitlePositioning(int))); connect(titles->ui.subtitleResize, SIGNAL(currentIndexChanged(int)), this, SLOT(setSubTitleResize(int))); connect(titles->ui.showFooter, SIGNAL(toggled(bool)), this, SLOT(setShowFooter(bool))); connect(titles->ui.footerPositioning, SIGNAL(currentIndexChanged(int)), this, SLOT(setFooterPositioning(int))); connect(titles->ui.footerResize, SIGNAL(currentIndexChanged(int)), this, SLOT(setFooterResize(int))); connect(d->shape, SIGNAL(updateConfigWidget()), titles, SLOT(updateData())); LegendConfigWidget *legend = new LegendConfigWidget(); legend->setWindowTitle(i18n("Legend")); widgets.append(legend); connect(legend, SIGNAL(showLegendChanged(bool)), this, SLOT(setShowLegend(bool))); connect(legend, SIGNAL(legendTitleChanged(QString)), this, SLOT(setLegendTitle(QString))); connect(legend, SIGNAL(legendFontChanged(QFont)), this, SLOT(setLegendFont(QFont))); connect(legend, SIGNAL(legendFontSizeChanged(int)), this, SLOT(setLegendFontSize(int))); connect(legend, SIGNAL(legendOrientationChanged(Qt::Orientation)), this, SLOT(setLegendOrientation(Qt::Orientation))); connect(legend, SIGNAL(legendPositionChanged(Position)), this, SLOT(setLegendPosition(Position))); connect(legend, SIGNAL(legendAlignmentChanged(Qt::Alignment)), this, SLOT(setLegendAlignment(Qt::Alignment))); connect(d->shape->legend(), SIGNAL(updateConfigWidget()), legend, SLOT(updateData())); PlotAreaConfigWidget *plotarea = new PlotAreaConfigWidget(); plotarea->setWindowTitle(i18n("Plot Area")); widgets.append(plotarea); connect(plotarea, SIGNAL(chartTypeChanged(ChartType,ChartSubtype)), this, SLOT(setChartType(ChartType,ChartSubtype))); connect(plotarea, SIGNAL(chartSubTypeChanged(ChartSubtype)), this, SLOT(setChartSubType(ChartSubtype))); connect(plotarea, SIGNAL(threeDModeToggled(bool)), this, SLOT(setThreeDMode(bool))); connect(plotarea, SIGNAL(chartOrientationChanged(Qt::Orientation)), this, SLOT(setChartOrientation(Qt::Orientation))); // data set edit dialog connect(plotarea, SIGNAL(dataSetXDataRegionChanged(DataSet*,CellRegion)), this, SLOT(setDataSetXDataRegion(DataSet*,CellRegion))); connect(plotarea, SIGNAL(dataSetYDataRegionChanged(DataSet*,CellRegion)), this, SLOT(setDataSetYDataRegion(DataSet*,CellRegion))); connect(plotarea, SIGNAL(dataSetCustomDataRegionChanged(DataSet*,CellRegion)), this, SLOT(setDataSetCustomDataRegion(DataSet*,CellRegion))); connect(plotarea, SIGNAL(dataSetLabelDataRegionChanged(DataSet*,CellRegion)), this, SLOT(setDataSetLabelDataRegion(DataSet*,CellRegion))); connect(plotarea, SIGNAL(dataSetCategoryDataRegionChanged(DataSet*,CellRegion)), this, SLOT(setDataSetCategoryDataRegion(DataSet*,CellRegion))); AxesConfigWidget *axes = plotarea->cartesianAxesConfigWidget(); connect(axes, SIGNAL(axisAdded(AxisDimension,QString)), this, SLOT(addAxis(AxisDimension,QString))); connect(axes, SIGNAL(axisRemoved(Axis*)), this, SLOT(removeAxis(Axis*))); connect(axes, SIGNAL(axisShowTitleChanged(Axis*,bool)), this, SLOT(setAxisShowTitle(Axis*,bool))); connect(axes, SIGNAL(axisShowChanged(Axis*,bool)), this, SLOT(setShowAxis(Axis*,bool))); connect(axes, SIGNAL(axisPositionChanged(Axis*,QString)), this, SLOT(setAxisPosition(Axis*,QString))); connect(axes, SIGNAL(axisLabelsPositionChanged(Axis*,QString)), this, SLOT(setAxisLabelsPosition(Axis*,QString))); connect(axes, SIGNAL(axisShowLabelsChanged(Axis*,bool)), this, SLOT(setAxisShowLabels(Axis*,bool))); connect(axes, SIGNAL(axisShowMajorGridLinesChanged(Axis*,bool)), this, SLOT(setAxisShowMajorGridLines(Axis*,bool))); connect(axes, SIGNAL(axisShowMinorGridLinesChanged(Axis*,bool)), this, SLOT(setAxisShowMinorGridLines(Axis*,bool))); // scaling dialog connect(axes, SIGNAL(axisUseLogarithmicScalingChanged(Axis*,bool)), this, SLOT(setAxisUseLogarithmicScaling(Axis*,bool))); connect(axes, SIGNAL(axisStepWidthChanged(Axis*,qreal)), this, SLOT(setAxisStepWidth(Axis*,qreal))); connect(axes, SIGNAL(axisSubStepWidthChanged(Axis*,qreal)), this, SLOT(setAxisSubStepWidth(Axis*,qreal))); connect(axes, SIGNAL(axisUseAutomaticStepWidthChanged(Axis*,bool)), this, SLOT(setAxisUseAutomaticStepWidth(Axis*,bool))); connect(axes, SIGNAL(axisUseAutomaticSubStepWidthChanged(Axis*,bool)), this, SLOT(setAxisUseAutomaticSubStepWidth(Axis*,bool))); // font dialog connect(axes, SIGNAL(axisLabelsFontChanged(Axis*,QFont)), this, SLOT(setAxisLabelsFont(Axis*,QFont))); connect(axes, SIGNAL(gapBetweenBarsChanged(Axis*,int)), this, SLOT(setGapBetweenBars(Axis*,int))); connect(axes, SIGNAL(gapBetweenSetsChanged(Axis*,int)), this, SLOT(setGapBetweenSets(Axis*,int))); DataSetConfigWidget *dataset = plotarea->cartesianDataSetConfigWidget(); - connect(dataset, SIGNAL(dataSetChartTypeChanged(DataSet*,ChartType)), - this, SLOT(setDataSetChartType(DataSet*,ChartType))); - connect(dataset, SIGNAL(dataSetChartSubTypeChanged(DataSet*,ChartSubtype)), - this, SLOT(setDataSetChartSubType(DataSet*,ChartSubtype))); + connect(dataset, SIGNAL(dataSetChartTypeChanged(DataSet*,ChartType,ChartSubtype)), + this, SLOT(setDataSetChartType(DataSet*,ChartType,ChartSubtype))); connect(dataset, SIGNAL(datasetBrushChanged(DataSet*,QColor,int)), this, SLOT(setDataSetBrush(DataSet*,QColor,int))); connect(dataset, SIGNAL(dataSetMarkerChanged(DataSet*,OdfSymbolType,OdfMarkerStyle)), this, SLOT(setDataSetMarker(DataSet*,OdfSymbolType,OdfMarkerStyle))); connect(dataset, SIGNAL(datasetPenChanged(DataSet*,QColor,int)), this, SLOT(setDataSetPen(DataSet*,QColor,int))); connect(dataset, SIGNAL(datasetShowCategoryChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowCategory(DataSet*,bool,int))); connect(dataset, SIGNAL(dataSetShowNumberChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowNumber(DataSet*,bool,int))); connect(dataset, SIGNAL(datasetShowPercentChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowPercent(DataSet*,bool,int))); connect(dataset, SIGNAL(datasetShowSymbolChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowSymbol(DataSet*,bool,int))); connect(dataset, SIGNAL(dataSetAxisChanged(DataSet*,Axis*)), this, SLOT(setDataSetAxis(DataSet*,Axis*))); connect(dataset, SIGNAL(axisAdded(AxisDimension,QString)), this, SLOT(addAxis(AxisDimension,QString))); PieConfigWidget *pie = plotarea->pieConfigWidget(); connect(pie, SIGNAL(explodeFactorChanged(DataSet*,int, int)), this, SLOT(setPieExplodeFactor(DataSet*,int, int))); connect(pie, SIGNAL(brushChanged(DataSet*,QColor,int)), this, SLOT(setDataSetBrush(DataSet*,QColor,int))); connect(pie, SIGNAL(penChanged(DataSet*,QColor,int)), this, SLOT(setDataSetPen(DataSet*,QColor,int))); connect(pie, SIGNAL(showCategoryChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowCategory(DataSet*,bool,int))); connect(pie, SIGNAL(showNumberChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowNumber(DataSet*,bool,int))); connect(pie, SIGNAL(showPercentChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowPercent(DataSet*,bool,int))); RingConfigWidget *ring = plotarea->ringConfigWidget(); connect(ring, SIGNAL(explodeFactorChanged(DataSet*,int, int)), this, SLOT(setPieExplodeFactor(DataSet*,int, int))); connect(ring, SIGNAL(brushChanged(DataSet*,QColor,int)), this, SLOT(setDataSetBrush(DataSet*,QColor,int))); connect(ring, SIGNAL(penChanged(DataSet*,QColor,int)), this, SLOT(setDataSetPen(DataSet*,QColor,int))); connect(ring, SIGNAL(showCategoryChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowCategory(DataSet*,bool,int))); connect(ring, SIGNAL(showNumberChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowNumber(DataSet*,bool,int))); connect(ring, SIGNAL(showPercentChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowPercent(DataSet*,bool,int))); axes = plotarea->stockAxesConfigWidget(); connect(axes, SIGNAL(axisAdded(AxisDimension,QString)), this, SLOT(addAxis(AxisDimension,QString))); connect(axes, SIGNAL(axisRemoved(Axis*)), this, SLOT(removeAxis(Axis*))); connect(axes, SIGNAL(axisShowTitleChanged(Axis*,bool)), this, SLOT(setAxisShowTitle(Axis*,bool))); connect(axes, SIGNAL(axisShowChanged(Axis*,bool)), this, SLOT(setShowAxis(Axis*,bool))); connect(axes, SIGNAL(axisPositionChanged(Axis*,QString)), this, SLOT(setAxisPosition(Axis*,QString))); connect(axes, SIGNAL(axisLabelsPositionChanged(Axis*,QString)), this, SLOT(setAxisLabelsPosition(Axis*,QString))); connect(axes, SIGNAL(axisShowLabelsChanged(Axis*,bool)), this, SLOT(setAxisShowLabels(Axis*,bool))); connect(axes, SIGNAL(axisShowMajorGridLinesChanged(Axis*,bool)), this, SLOT(setAxisShowMajorGridLines(Axis*,bool))); connect(axes, SIGNAL(axisShowMinorGridLinesChanged(Axis*,bool)), this, SLOT(setAxisShowMinorGridLines(Axis*,bool))); // scaling dialog connect(axes, SIGNAL(axisUseLogarithmicScalingChanged(Axis*,bool)), this, SLOT(setAxisUseLogarithmicScaling(Axis*,bool))); connect(axes, SIGNAL(axisStepWidthChanged(Axis*,qreal)), this, SLOT(setAxisStepWidth(Axis*,qreal))); connect(axes, SIGNAL(axisSubStepWidthChanged(Axis*,qreal)), this, SLOT(setAxisSubStepWidth(Axis*,qreal))); connect(axes, SIGNAL(axisUseAutomaticStepWidthChanged(Axis*,bool)), this, SLOT(setAxisUseAutomaticStepWidth(Axis*,bool))); connect(axes, SIGNAL(axisUseAutomaticSubStepWidthChanged(Axis*,bool)), this, SLOT(setAxisUseAutomaticSubStepWidth(Axis*,bool))); // font dialog connect(axes, SIGNAL(axisLabelsFontChanged(Axis*,QFont)), this, SLOT(setAxisLabelsFont(Axis*,QFont))); // Radar RadarDataSetConfigWidget *rdataset = plotarea->radarDataSetConfigWidget(); connect(rdataset, SIGNAL(datasetBrushChanged(DataSet*,QColor,int)), this, SLOT(setDataSetBrush(DataSet*,QColor,int))); connect(rdataset, SIGNAL(dataSetMarkerChanged(DataSet*,OdfSymbolType,OdfMarkerStyle)), this, SLOT(setDataSetMarker(DataSet*,OdfSymbolType,OdfMarkerStyle))); connect(rdataset, SIGNAL(datasetPenChanged(DataSet*,QColor,int)), this, SLOT(setDataSetPen(DataSet*,QColor,int))); connect(rdataset, SIGNAL(datasetShowCategoryChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowCategory(DataSet*,bool,int))); connect(rdataset, SIGNAL(dataSetShowNumberChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowNumber(DataSet*,bool,int))); connect(rdataset, SIGNAL(datasetShowPercentChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowPercent(DataSet*,bool,int))); connect(rdataset, SIGNAL(datasetShowSymbolChanged(DataSet*,bool,int)), this, SLOT(setDataSetShowSymbol(DataSet*,bool,int))); connect(d->shape, SIGNAL(updateConfigWidget()), plotarea, SLOT(updateData())); return widgets; } void ChartTool::setChartType(ChartType type, ChartSubtype subtype) { Q_ASSERT(d->shape); if (!d->shape) { return; } ChartTypeCommand *command = new ChartTypeCommand(d->shape); if (command!=0) { command->setChartType(type, subtype); canvas()->addCommand(command); } foreach (QWidget *w, optionWidgets()) { ConfigWidgetBase *cw = dynamic_cast(w); if (cw) { cw->updateData(); } } } void ChartTool::setChartSubType(ChartSubtype subtype) { Q_ASSERT(d->shape); if (!d->shape) return; d->shape->setChartSubType(subtype); d->shape->update(); } void ChartTool::setDataSetXDataRegion(DataSet *dataSet, const CellRegion ®ion) { debugChartTool<setXDataRegion(region); d->shape->update(); } void ChartTool::setDataSetYDataRegion(DataSet *dataSet, const CellRegion ®ion) { if (!dataSet) return; dataSet->setYDataRegion(region); d->shape->update(); } void ChartTool::setDataSetCustomDataRegion(DataSet *dataSet, const CellRegion ®ion) { if (!dataSet) return; dataSet->setCustomDataRegion(region); } void ChartTool::setDataSetLabelDataRegion(DataSet *dataSet, const CellRegion ®ion) { if (!dataSet) return; dataSet->setLabelDataRegion(region); d->shape->update(); d->shape->legend()->update(); } void ChartTool::setDataSetCategoryDataRegion(DataSet *dataSet, const CellRegion ®ion) { if (!dataSet) { return; } if (isCartesian(d->shape->chartType())) { // FIXME: Seems strange the way things are stored in multiple places // Categories are labels on the categories axis dataSet->setCategoryDataRegion(region); // probably should not be stored here, as datasets cannot have individual categories d->shape->plotArea()->proxyModel()->setCategoryDataRegion(region); // this seems to be for odf only!? } else { // Categories are legend texts dataSet->setCategoryDataRegion(region); } d->shape->update(); d->shape->legend()->update(); } -void ChartTool::setDataSetChartType(DataSet *dataSet, ChartType type) +void ChartTool::setDataSetChartType(DataSet *dataSet, ChartType type, ChartSubtype subType) { Q_ASSERT(d->shape); Q_ASSERT(dataSet); - if (dataSet) - dataSet->setChartType(type); + if (dataSet) { + DatasetCommand *cmd = new DatasetCommand(dataSet, d->shape); + cmd->setDataSetChartType(type, subType); + canvas()->addCommand(cmd); + } d->shape->update(); d->shape->legend()->update(); } -void ChartTool::setDataSetChartSubType(DataSet *dataSet, ChartSubtype subType) -{ - Q_ASSERT(dataSet); - if (dataSet) - dataSet->setChartSubType(subType); - d->shape->update(); -} - void ChartTool::setDataSetBrush(DataSet *dataSet, const QColor& color, int section) { Q_ASSERT(d->shape); Q_ASSERT(dataSet || section >= 0); debugChartTool< lst = d->shape->proxyModel()->dataSets(); if (lst.isEmpty()) { return; } // we set brush for section in all datasets KUndo2Command *command = new KUndo2Command(); for (int i = 0; i < lst.count(); ++i) { DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command); cmd->setDataSetBrush(color); command->setText(cmd->text()); } canvas()->addCommand(command); } else { DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section); command->setDataSetBrush(color); canvas()->addCommand(command); } } void ChartTool::setDataSetPen(DataSet *dataSet, const QColor& color, int section) { Q_ASSERT(d->shape); Q_ASSERT(dataSet || section >= 0); debugChartTool< lst = d->shape->proxyModel()->dataSets(); if (lst.isEmpty()) { return; } // we set brush for section in all datasets KUndo2Command *command = new KUndo2Command(); for (int i = 0; i < lst.count(); ++i) { DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command); cmd->setDataSetPen(color); command->setText(cmd->text()); } canvas()->addCommand(command); } else { DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section); command->setDataSetPen(color); canvas()->addCommand(command); } } void ChartTool::setDataSetMarker(DataSet *dataSet, OdfSymbolType type, OdfMarkerStyle style) { Q_ASSERT(d->shape); if (!dataSet) { return; } DatasetCommand *command = new DatasetCommand(dataSet, d->shape); command->setDataSetMarker(type, style); canvas()->addCommand(command); } void ChartTool::setDataSetAxis(DataSet *dataSet, Axis *axis) { Q_ASSERT(d->shape); if (!dataSet || !axis) return; DatasetCommand *command = new DatasetCommand(dataSet, d->shape); command->setDataSetAxis(axis); canvas()->addCommand(command); } void ChartTool::setDataSetShowCategory(DataSet *dataSet, bool b, int section) { Q_ASSERT(d->shape); Q_ASSERT(dataSet || section >= 0); if (!dataSet) { QList lst = d->shape->proxyModel()->dataSets(); if (lst.isEmpty()) { return; } // we set brush for section in all datasets KUndo2Command *command = new KUndo2Command(); for (int i = 0; i < lst.count(); ++i) { DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command); cmd->setDataSetShowCategory(b); command->setText(cmd->text()); } canvas()->addCommand(command); } else { DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section); command->setDataSetShowCategory(b); canvas()->addCommand(command); } debugChartTool<valueLabelType(section).category; } void ChartTool::setDataSetShowNumber(DataSet *dataSet, bool b, int section) { debugChartTool<shape); Q_ASSERT(dataSet || section >= 0); if (!dataSet) { QList lst = d->shape->proxyModel()->dataSets(); if (lst.isEmpty()) { return; } // we set brush for section in all datasets KUndo2Command *command = new KUndo2Command(); for (int i = 0; i < lst.count(); ++i) { DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command); cmd->setDataSetShowNumber(b); command->setText(cmd->text()); } canvas()->addCommand(command); } else { DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section); command->setDataSetShowNumber(b); canvas()->addCommand(command); } debugChartTool<valueLabelType(section).number; } void ChartTool::setDataSetShowPercent(DataSet *dataSet, bool b, int section) { Q_ASSERT(d->shape); Q_ASSERT(dataSet || section >= 0); if (!dataSet) { QList lst = d->shape->proxyModel()->dataSets(); if (lst.isEmpty()) { return; } // we set brush for section in all datasets KUndo2Command *command = new KUndo2Command(); for (int i = 0; i < lst.count(); ++i) { DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command); cmd->setDataSetShowPercent(b); command->setText(cmd->text()); } canvas()->addCommand(command); } else { DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section); command->setDataSetShowPercent(b); canvas()->addCommand(command); } debugChartTool<valueLabelType(section).percentage; } void ChartTool::setDataSetShowSymbol(DataSet *dataSet, bool b, int section) { Q_ASSERT(d->shape); Q_ASSERT(dataSet || section >= 0); if (!dataSet) { QList lst = d->shape->proxyModel()->dataSets(); if (lst.isEmpty()) { return; } // we set brush for section in all datasets KUndo2Command *command = new KUndo2Command(); for (int i = 0; i < lst.count(); ++i) { DatasetCommand *cmd = new DatasetCommand(lst.at(i), d->shape, section, command); cmd->setDataSetShowSymbol(b); command->setText(cmd->text()); } canvas()->addCommand(command); } else { DatasetCommand *command = new DatasetCommand(dataSet, d->shape, section); command->setDataSetShowSymbol(b); canvas()->addCommand(command); } debugChartTool<valueLabelType(section).symbol; } void ChartTool::setThreeDMode(bool threeD) { Q_ASSERT(d->shape); if (!d->shape) return; d->shape->setThreeD(threeD); d->shape->update(); } void ChartTool::setShowTitle(bool show) { Q_ASSERT(d->shape); if (!d->shape) return; ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->title(), d->shape, show); canvas()->addCommand(command); } void ChartTool::setTitlePositioning(int index) { Q_ASSERT(d->shape); if (!d->shape) { return; } // TODD: undo command d->shape->title()->setAdditionalStyleAttribute("chart:auto-position", index == 0 ? "true" : "false"); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); d->shape->update(); } void ChartTool::setTitleResize(int index) { Q_ASSERT(d->shape); if (!d->shape) { return; } // TODD: undo command TextLabelData *labelData = dynamic_cast(d->shape->title()->userData()); if (labelData == 0) { return; } labelData->setResizeMethod(index == 0 ? KoTextShapeDataBase::AutoResize : KoTextShapeDataBase::NoResize); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); d->shape->update(); } void ChartTool::setShowSubTitle(bool show) { Q_ASSERT(d->shape); if (!d->shape) return; ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->subTitle(), d->shape, show); canvas()->addCommand(command); } void ChartTool::setSubTitlePositioning(int index) { Q_ASSERT(d->shape); if (!d->shape) { return; } // TODD: undo command d->shape->subTitle()->setAdditionalStyleAttribute("chart:auto-position", index == 0 ? "true" : "false"); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); d->shape->update(); } void ChartTool::setSubTitleResize(int index) { Q_ASSERT(d->shape); if (!d->shape) { return; } // TODD: undo command TextLabelData *labelData = dynamic_cast(d->shape->subTitle()->userData()); if (labelData == 0) { return; } labelData->setResizeMethod(index == 0 ? KoTextShapeDataBase::AutoResize : KoTextShapeDataBase::NoResize); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); d->shape->update(); } void ChartTool::setShowFooter(bool show) { Q_ASSERT(d->shape); if (!d->shape) return; ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->footer(), d->shape, show); canvas()->addCommand(command); } void ChartTool::setFooterPositioning(int index) { Q_ASSERT(d->shape); if (!d->shape) { return; } // TODD: undo command d->shape->footer()->setAdditionalStyleAttribute("chart:auto-position", index == 0 ? "true" : "false"); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); d->shape->update(); } void ChartTool::setFooterResize(int index) { Q_ASSERT(d->shape); if (!d->shape) { return; } // TODD: undo command TextLabelData *labelData = dynamic_cast(d->shape->footer()->userData()); if (labelData == 0) { return; } labelData->setResizeMethod(index == 0 ? KoTextShapeDataBase::AutoResize : KoTextShapeDataBase::NoResize); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); d->shape->update(); } void ChartTool::setDataDirection(Qt::Orientation direction) { Q_ASSERT(d->shape); if (!d->shape) return; d->shape->proxyModel()->setDataDirection(direction); d->shape->relayout(); } void ChartTool::setChartOrientation(Qt::Orientation direction) { Q_ASSERT(d->shape); if (!d->shape) { return; } PlotAreaCommand *command = new PlotAreaCommand(d->shape->plotArea()); command->setOrientation(direction); canvas()->addCommand(command); } void ChartTool::setLegendTitle(const QString &title) { Q_ASSERT(d->shape); Q_ASSERT(d->shape->legend()); LegendCommand *command = new LegendCommand(d->shape->legend()); command->setLegendTitle(title); canvas()->addCommand(command); } void ChartTool::setLegendFont(const QFont &font) { Q_ASSERT(d->shape); Q_ASSERT(d->shape->legend()); // There only is a general font, for the legend items and the legend title LegendCommand *command = new LegendCommand(d->shape->legend()); command->setLegendFont(font); canvas()->addCommand(command); } void ChartTool::setLegendFontSize(int size) { Q_ASSERT(d->shape); Q_ASSERT(d->shape->legend()); LegendCommand *command = new LegendCommand(d->shape->legend()); command->setLegendFontSize(size); canvas()->addCommand(command); } void ChartTool::setLegendOrientation(Qt::Orientation orientation) { Q_ASSERT(d->shape); Q_ASSERT(d->shape->legend()); LegendCommand *command = new LegendCommand(d->shape->legend()); command->setLegendExpansion(QtOrientationToLegendExpansion(orientation)); canvas()->addCommand(command); } void ChartTool::setLegendPosition(Position pos) { Q_ASSERT(d->shape); Q_ASSERT(d->shape->legend()); // TODO undo command d->shape->legend()->setLegendPosition(pos); d->shape->legend()->update(); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); } void ChartTool::setLegendAlignment(Qt::Alignment alignment) { Q_ASSERT(d->shape); Q_ASSERT(d->shape->legend()); // TODO undo command d->shape->legend()->setAlignment(alignment); d->shape->legend()->update(); d->shape->layout()->scheduleRelayout(); d->shape->layout()->layout(); } void ChartTool::addAxis(AxisDimension dimension, const QString& title) { Q_ASSERT(d->shape); Axis *axis = new Axis(d->shape->plotArea(), dimension); // automatically adds axis to plot area if (axis == d->shape->plotArea()->secondaryYAxis()) { axis->title()->rotate(90); axis->setOdfAxisPosition("end"); // right } else if (axis == d->shape->plotArea()->secondaryXAxis()) { axis->setOdfAxisPosition("end"); // top axis->updateKChartAxisPosition(); } d->shape->plotArea()->takeAxis(axis); // so we remove it again, sigh axis->setTitleText(title); AddRemoveAxisCommand *command = new AddRemoveAxisCommand(axis, d->shape, true, canvas()->shapeManager()); canvas()->addCommand(command); } void ChartTool::removeAxis(Axis *axis) { Q_ASSERT(d->shape); AddRemoveAxisCommand *command = new AddRemoveAxisCommand(axis, d->shape, false, canvas()->shapeManager()); canvas()->addCommand(command); } void ChartTool::setAxisShowTitle(Axis *axis, bool show) { Q_ASSERT(d->shape); if (show && axis->titleText().isEmpty()) { axis->setTitleText(i18n("Axistitle")); } AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisShowTitle(show); canvas()->addCommand(command); } void ChartTool::setShowAxis(Axis *axis, bool show) { Q_ASSERT(d->shape); debugChartTool<shape); command->setShowAxis(show); canvas()->addCommand(command); } void ChartTool::setAxisPosition(Axis *axis, const QString &pos) { Q_ASSERT(d->shape); debugChartTool<shape); command->setAxisPosition(pos); canvas()->addCommand(command); } void ChartTool::setAxisLabelsPosition(Axis *axis, const QString &pos) { Q_ASSERT(d->shape); debugChartTool<shape); command->setAxisLabelsPosition(pos); canvas()->addCommand(command); } void ChartTool::setAxisShowLabels(Axis *axis, bool b) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisShowLabels(b); canvas()->addCommand(command); } void ChartTool::setAxisShowMajorGridLines(Axis *axis, bool b) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisShowMajorGridLines(b); canvas()->addCommand(command); } void ChartTool::setAxisShowMinorGridLines(Axis *axis, bool b) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisShowMinorGridLines(b); canvas()->addCommand(command); } void ChartTool::setAxisUseLogarithmicScaling(Axis *axis, bool b) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisUseLogarithmicScaling(b); canvas()->addCommand(command); } void ChartTool::setAxisStepWidth(Axis *axis, qreal width) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisStepWidth(width); canvas()->addCommand(command); } void ChartTool::setAxisSubStepWidth(Axis *axis, qreal width) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisSubStepWidth(width); canvas()->addCommand(command); } void ChartTool::setAxisUseAutomaticStepWidth(Axis *axis, bool automatic) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisUseAutomaticStepWidth(automatic); canvas()->addCommand(command); } void ChartTool::setAxisUseAutomaticSubStepWidth(Axis *axis, bool automatic) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisUseAutomaticSubStepWidth(automatic); canvas()->addCommand(command); } void ChartTool::setAxisLabelsFont(Axis *axis, const QFont &font) { Q_ASSERT(d->shape); AxisCommand *command = new AxisCommand(axis, d->shape); command->setAxisLabelsFont(font); canvas()->addCommand(command); } void ChartTool::setGapBetweenBars(Axis *axis, int percent) { Q_ASSERT(d->shape); debugChartTool<shape); command->setGapBetweenBars(percent); canvas()->addCommand(command); } void ChartTool::setGapBetweenSets(Axis *axis, int percent) { Q_ASSERT(d->shape); debugChartTool<shape); command->setGapBetweenSets(percent); canvas()->addCommand(command); } void ChartTool::setPieExplodeFactor(DataSet *dataSet, int section, int percent) { Q_ASSERT(d->shape); dataSet->setPieExplodeFactor(section, percent); d->shape->update(); } void ChartTool::setShowLegend(bool show) { Q_ASSERT(d->shape); ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->legend(), d->shape, show); if (show) { command->setText(kundo2_i18n("Show Legend")); } else { command->setText(kundo2_i18n("Hide Legend")); } canvas()->addCommand(command); } diff --git a/plugins/chartshape/ChartTool.h b/plugins/chartshape/ChartTool.h index b791940ec84..6420622b616 100644 --- a/plugins/chartshape/ChartTool.h +++ b/plugins/chartshape/ChartTool.h @@ -1,142 +1,141 @@ /* This file is part of the KDE project * * Copyright (C) 2007 Inge Wallin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCHART_CHARTTOOL_H #define KCHART_CHARTTOOL_H // Calligra #include // KoChart #include "ChartShape.h" class QAction; namespace KoChart { /** * This is the tool for the chart shape, which is a flake-based plugin. */ class ChartTool : public KoToolBase { Q_OBJECT public: explicit ChartTool(KoCanvasBase *canvas); ~ChartTool(); /// reimplemented from superclass void paint(QPainter &painter, const KoViewConverter &converter) override; /// reimplemented from superclass void mousePressEvent(KoPointerEvent *event) override; /// reimplemented from superclass void mouseMoveEvent(KoPointerEvent *event) override; /// reimplemented from superclass void mouseReleaseEvent(KoPointerEvent *event) override; /// reimplemented from superclass void activate(ToolActivation toolActivation, const QSet &shapes) override; /// reimplemented from superclass void deactivate() override; /// reimplemented from superclass QList > createOptionWidgets() override; private Q_SLOTS: void setChartType(ChartType type, ChartSubtype subtype); void setChartSubType(ChartSubtype subtype); void setThreeDMode(bool threeD); void setDataDirection(Qt::Orientation); void setChartOrientation(Qt::Orientation); void setShowTitle(bool show); void setTitlePositioning(int index); void setTitleResize(int index); void setShowSubTitle(bool show); void setSubTitlePositioning(int index); void setSubTitleResize(int index); void setShowFooter(bool show); void setFooterPositioning(int index); void setFooterResize(int index); // Datasets void setDataSetXDataRegion(DataSet *dataSet, const CellRegion ®ion); void setDataSetYDataRegion(DataSet *dataSet, const CellRegion ®ion); void setDataSetCustomDataRegion(DataSet *dataSet, const CellRegion ®ion); void setDataSetLabelDataRegion(DataSet *dataSet, const CellRegion ®ion); void setDataSetCategoryDataRegion(DataSet *dataSet, const CellRegion ®ion); - void setDataSetChartType(DataSet *dataSet, ChartType type); - void setDataSetChartSubType(DataSet *dataSet, ChartSubtype subType); + void setDataSetChartType(DataSet *dataSet, ChartType type, ChartSubtype subType); void setDataSetShowCategory(DataSet *dataSet, bool b, int section = -1); void setDataSetShowNumber(DataSet *dataSet, bool b, int section = -1); void setDataSetShowPercent(DataSet *dataSet, bool b, int section = -1); void setDataSetShowSymbol(DataSet *dataSet, bool b, int section = -1); void setDataSetPen(DataSet *dataSet, const QColor& color, int section = -1); void setDataSetBrush(DataSet *dataSet, const QColor& color, int section = -1); void setDataSetMarker(DataSet *dataSet, OdfSymbolType type, OdfMarkerStyle style); void setDataSetAxis(DataSet *dataSet, Axis *axis); // Plot Area void setGapBetweenBars(Axis *axis, int percent); void setGapBetweenSets(Axis *axis, int percent); void setPieExplodeFactor(DataSet *dataSet, int section, int percent); // Axes void addAxis(AxisDimension, const QString& title = QString()); void removeAxis(Axis *axis); void setShowAxis(Axis *axis, bool show); void setAxisPosition(Axis *axis, const QString &pos); void setAxisLabelsPosition(Axis *axis, const QString &pos); void setAxisShowTitle(Axis *axis, bool show); void setAxisShowLabels(Axis *axis, bool b); void setAxisShowMajorGridLines(Axis *axis, bool b = true); void setAxisShowMinorGridLines(Axis *axis, bool b = true); void setAxisUseLogarithmicScaling(Axis *axis, bool b = true); void setAxisStepWidth(Axis *axis, qreal width); void setAxisSubStepWidth(Axis *axis, qreal width); void setAxisUseAutomaticStepWidth(Axis *axis, bool automatic); void setAxisUseAutomaticSubStepWidth(Axis *axis, bool automatic); void setAxisLabelsFont(Axis *axis, const QFont& font); // Legend void setShowLegend(bool show); void setLegendTitle(const QString& title); void setLegendFont(const QFont& font); void setLegendFontSize(int size); void setLegendOrientation(Qt::Orientation); void setLegendPosition(Position); void setLegendAlignment(Qt::Alignment); void shapeSelectionChanged(); private: class Private; Private * const d; }; } // namespace KoChart #endif // KCHART_CHARTTOOL_H diff --git a/plugins/chartshape/DataSetConfigWidget.cpp b/plugins/chartshape/DataSetConfigWidget.cpp index d4fbbc9e512..7bd8f04cc42 100644 --- a/plugins/chartshape/DataSetConfigWidget.cpp +++ b/plugins/chartshape/DataSetConfigWidget.cpp @@ -1,796 +1,798 @@ /* This file is part of the KDE project Copyright 2007-2008 Johannes Simon Copyright 2009 Inge Wallin Copyright 2018 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Own #include "DataSetConfigWidget.h" #include "ui_DataSetConfigWidget.h" // Qt #include #include #include // KF5 #include #include #include // Calligra #include #include // KChart #include #include #include #include #include #include #include #include #include #include // KoChart #include "ChartProxyModel.h" #include "PlotArea.h" #include "Legend.h" #include "DataSet.h" #include "Axis.h" #include "ui_ChartTableEditor.h" #include "NewAxisDialog.h" #include "AxisScalingDialog.h" #include "FontEditorDialog.h" #include "FormatErrorBarDialog.h" #include "CellRegionDialog.h" #include "TableEditorDialog.h" #include "commands/ChartTypeCommand.h" #include "CellRegionStringValidator.h" #include "ChartTableModel.h" #include "TableSource.h" #include "ChartDebug.h" using namespace KoChart; class DataSetConfigWidget::Private { public: Private(DataSetConfigWidget *parent); ~Private(); Ui::DataSetConfigWidget ui; QList dataSetAxes; QList dataSets; int selectedDataSet; // Menus QMenu *dataSetBarChartMenu; QMenu *dataSetLineChartMenu; QMenu *dataSetAreaChartMenu; QMenu *dataSetRadarChartMenu; QMenu *dataSetStockChartMenu; // chart type selection actions QAction *normalBarChartAction; QAction *stackedBarChartAction; QAction *percentBarChartAction; QAction *normalLineChartAction; QAction *stackedLineChartAction; QAction *percentLineChartAction; QAction *normalAreaChartAction; QAction *stackedAreaChartAction; QAction *percentAreaChartAction; QAction *circleChartAction; QAction *ringChartAction; QAction *radarChartAction; QAction *filledRadarChartAction; QAction *scatterChartAction; QAction *bubbleChartAction; QAction *hlcStockChartAction; QAction *ohlcStockChartAction; QAction *candlestickStockChartAction; QAction *surfaceChartAction; QAction *ganttChartAction; // chart type selection actions for datasets QAction *dataSetNormalBarChartAction; QAction *dataSetStackedBarChartAction; QAction *dataSetPercentBarChartAction; QAction *dataSetNormalLineChartAction; QAction *dataSetStackedLineChartAction; QAction *dataSetPercentLineChartAction; QAction *dataSetNormalAreaChartAction; QAction *dataSetStackedAreaChartAction; QAction *dataSetPercentAreaChartAction; QAction *dataSetCircleChartAction; QAction *dataSetRingChartAction; QAction *dataSetRadarChartAction; QAction *dataSetFilledRadarChartAction; QAction *dataSetScatterChartAction; QAction *dataSetBubbleChartAction; QAction *dataSetHLCStockChartAction; QAction *dataSetOHLCStockChartAction; QAction *dataSetCandlestickStockChartAction; QAction *dataSetSurfaceChartAction; QAction *dataSetGanttChartAction; // marker selection actions for datasets QAction *dataSetNoMarkerAction; QAction *dataSetAutomaticMarkerAction; QAction *dataSetMarkerCircleAction; QAction *dataSetMarkerSquareAction; QAction *dataSetMarkerDiamondAction; QAction *dataSetMarkerRingAction; QAction *dataSetMarkerCrossAction; QAction *dataSetMarkerFastCrossAction; QAction *dataSetMarkerArrowDownAction; QAction *dataSetMarkerArrowUpAction; QAction *dataSetMarkerArrowRightAction; QAction *dataSetMarkerArrowLeftAction; QAction *dataSetMarkerBowTieAction; QAction *dataSetMarkerHourGlassAction; QAction *dataSetMarkerStarAction; QAction *dataSetMarkerXAction; QAction *dataSetMarkerAsteriskAction; QAction *dataSetMarkerHorizontalBarAction; QAction *dataSetMarkerVerticalBarAction; FormatErrorBarDialog formatErrorBarDialog; }; DataSetConfigWidget::Private::Private(DataSetConfigWidget *parent) : formatErrorBarDialog(parent) { ui.setupUi(parent); selectedDataSet = 0; dataSetBarChartMenu = 0; dataSetLineChartMenu = 0; dataSetAreaChartMenu = 0; dataSetRadarChartMenu = 0; dataSetStockChartMenu = 0; dataSetNormalBarChartAction = 0; dataSetStackedBarChartAction = 0; dataSetPercentBarChartAction = 0; dataSetNormalLineChartAction = 0; dataSetStackedLineChartAction = 0; dataSetPercentLineChartAction = 0; dataSetNormalAreaChartAction = 0; dataSetStackedAreaChartAction = 0; dataSetPercentAreaChartAction = 0; dataSetCircleChartAction = 0; dataSetRingChartAction = 0; dataSetScatterChartAction = 0; dataSetRadarChartAction = 0; dataSetFilledRadarChartAction = 0; dataSetHLCStockChartAction = 0; dataSetOHLCStockChartAction = 0; dataSetCandlestickStockChartAction = 0; dataSetBubbleChartAction = 0; dataSetSurfaceChartAction = 0; dataSetGanttChartAction = 0; // Data set chart type button QMenu *dataSetChartTypeMenu = new QMenu(i18n("Chart Type"), parent); // Default chart type is a bar chart dataSetChartTypeMenu->setIcon(ICON1(BarChartType)); dataSetBarChartMenu = dataSetChartTypeMenu->addMenu(ICON1(BarChartType), i18n("Bar Chart")); dataSetNormalBarChartAction = dataSetBarChartMenu->addAction(ICON2(BarChartType, NormalChartSubtype), i18n("Normal")); dataSetStackedBarChartAction = dataSetBarChartMenu->addAction(ICON2(BarChartType, StackedChartSubtype), i18n("Stacked")); dataSetPercentBarChartAction = dataSetBarChartMenu->addAction(ICON2(BarChartType, PercentChartSubtype), i18n("Percent")); dataSetLineChartMenu = dataSetChartTypeMenu->addMenu(ICON1(LineChartType), i18n("Line Chart")); dataSetNormalLineChartAction = dataSetLineChartMenu->addAction(ICON2(LineChartType, NormalChartSubtype), i18n("Normal")); dataSetStackedLineChartAction = dataSetLineChartMenu->addAction(ICON2(LineChartType, NormalChartSubtype), i18n("Stacked")); dataSetPercentLineChartAction = dataSetLineChartMenu->addAction(ICON2(LineChartType, NormalChartSubtype), i18n("Percent")); dataSetAreaChartMenu = dataSetChartTypeMenu->addMenu(ICON1(AreaChartType), i18n("Area Chart")); dataSetNormalAreaChartAction = dataSetAreaChartMenu->addAction(ICON2(AreaChartType, NormalChartSubtype), i18n("Normal")); dataSetStackedAreaChartAction = dataSetAreaChartMenu->addAction(ICON2(AreaChartType, StackedChartSubtype), i18n("Stacked")); dataSetPercentAreaChartAction = dataSetAreaChartMenu->addAction(ICON2(AreaChartType, PercentChartSubtype), i18n("Percent")); dataSetCircleChartAction = dataSetChartTypeMenu->addAction(ICON1(CircleChartType), i18n("Pie Chart")); dataSetRingChartAction = dataSetChartTypeMenu->addAction(ICON1(RingChartType), i18n("Ring Chart")); dataSetRadarChartMenu = dataSetChartTypeMenu->addMenu(ICON1(RadarChartType), i18n("Polar Chart")); dataSetRadarChartAction = dataSetRadarChartMenu->addAction(ICON2(RadarChartType, NoChartSubtype), i18n("Normal")); dataSetFilledRadarChartAction = dataSetRadarChartMenu->addAction(ICON2(FilledRadarChartType, NoChartSubtype), i18n("Filled")); dataSetStockChartMenu = dataSetChartTypeMenu->addMenu(ICON1(StockChartType), i18n("Stock Chart")); dataSetCandlestickStockChartAction = dataSetStockChartMenu->addAction(ICON2(StockChartType, CandlestickChartSubtype), i18n("Candlestick")); dataSetOHLCStockChartAction = dataSetStockChartMenu->addAction(ICON2(StockChartType, OpenHighLowCloseChartSubtype), i18n("OpenHighLowClose")); dataSetHLCStockChartAction = dataSetStockChartMenu->addAction(ICON2(StockChartType, HighLowCloseChartSubtype), i18n("HighLowClose")); dataSetBubbleChartAction = dataSetChartTypeMenu->addAction(ICON1(BubbleChartType), i18n("Bubble Chart")); dataSetScatterChartAction = dataSetChartTypeMenu->addAction(ICON1(ScatterChartType), i18n("Scatter Chart")); ui.dataSetChartTypeMenu->setMenu(dataSetChartTypeMenu); connect(dataSetChartTypeMenu, SIGNAL(triggered(QAction*)), parent, SLOT(dataSetChartTypeSelected(QAction*))); connect(ui.dataSetHasChartType, SIGNAL(toggled(bool)), parent, SLOT(ui_dataSetHasChartTypeChanged(bool))); // Setup marker menu QMenu *datasetMarkerMenu = new QMenu(parent); // Default marker is Automatic datasetMarkerMenu->setIcon(QIcon()); dataSetNoMarkerAction = datasetMarkerMenu->addAction(i18n("None")); dataSetAutomaticMarkerAction = datasetMarkerMenu->addAction(i18n("Automatic")); QMenu *datasetSelectMarkerMenu = datasetMarkerMenu->addMenu(i18n("Select")); dataSetMarkerSquareAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerDiamondAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerArrowDownAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerArrowUpAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerArrowRightAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerArrowLeftAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerBowTieAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerHourGlassAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerCircleAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerStarAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerXAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerCrossAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerAsteriskAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerHorizontalBarAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerVerticalBarAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerRingAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); dataSetMarkerFastCrossAction = datasetSelectMarkerMenu->addAction(QIcon(), QString()); ui.datasetMarkerMenu->setMenu(datasetMarkerMenu); connect(datasetMarkerMenu, SIGNAL(triggered(QAction*)), parent, SLOT(datasetMarkerSelected(QAction*))); // Insert error bar button ui.formatErrorBar->setEnabled(false); connect(ui.datasetBrush, SIGNAL(changed(QColor)),parent, SLOT(datasetBrushSelected(QColor))); connect(ui.datasetPen, SIGNAL(changed(QColor)), parent, SLOT(datasetPenSelected(QColor))); connect(ui.datasetShowCategory, SIGNAL(toggled(bool)), parent, SLOT(ui_datasetShowCategoryChanged(bool))); connect(ui.datasetShowErrorBar, SIGNAL(toggled(bool)), parent, SLOT(ui_datasetShowErrorBarChanged(bool))); connect(ui.dataSetShowNumber, SIGNAL(toggled(bool)), parent, SLOT(ui_dataSetShowNumberChanged(bool))); connect(ui.datasetShowPercent, SIGNAL(toggled(bool)), parent, SLOT(ui_datasetShowPercentChanged(bool))); // TODO // connect(ui.datasetShowSymbol, SIGNAL(toggled(bool)), parent, SLOT(ui_datasetShowSymbolChanged(bool))); connect(ui.dataSets, SIGNAL(currentIndexChanged(int)), parent, SLOT(ui_dataSetSelectionChanged(int))); connect(ui.dataSetAxes, SIGNAL(currentIndexChanged(int)), parent, SLOT(ui_dataSetAxisSelectionChanged(int))); } DataSetConfigWidget::Private::~Private() { } // ================================================================ // class DataSetConfigWidget DataSetConfigWidget::DataSetConfigWidget(QWidget *parent) : ConfigSubWidgetBase(parent) , d(new Private(this)) { setObjectName("DataSetConfigWidget"); setupDialogs(); createActions(); } DataSetConfigWidget::DataSetConfigWidget(QList types, QWidget *parent) : ConfigSubWidgetBase(types, parent) , d(new Private(this)) { setObjectName("DataSetConfigWidget"); setupDialogs(); createActions(); } DataSetConfigWidget::~DataSetConfigWidget() { delete d; } void DataSetConfigWidget::deleteSubDialogs(ChartType type) { Q_UNUSED(type) } void DataSetConfigWidget::open(ChartShape* shape) { debugChartUiDataSet<dataSetAxes.clear(); d->dataSets.clear(); ConfigSubWidgetBase::open(shape); } QAction *DataSetConfigWidget::createAction() { return 0; } void DataSetConfigWidget::ui_dataSetAxisSelectionChanged(int index) { if (index < 0 || d->ui.dataSets->currentIndex() >= d->dataSets.count()) { return; } debugChartUiDataSet<dataSetAxes; if (index >= d->dataSetAxes.count()) { // Add the axis debugChartUiDataSet<<"create secondary y axis"; emit axisAdded(YAxisDimension, i18n("Axistitle")); } if (index < 0 || index >= d->dataSetAxes.count()) { return; } DataSet *dataSet = d->dataSets[d->ui.dataSets->currentIndex()]; Axis *axis = d->dataSetAxes[index]; emit dataSetAxisChanged(dataSet, axis); } void DataSetConfigWidget::updateMarkers() { DataSet *dataSet = d->dataSets[d->selectedDataSet]; d->dataSetMarkerCircleAction->setIcon(dataSet->markerIcon(MarkerCircle)); d->dataSetMarkerSquareAction->setIcon(dataSet->markerIcon(MarkerSquare)); d->dataSetMarkerDiamondAction->setIcon(dataSet->markerIcon(MarkerDiamond)); d->dataSetMarkerRingAction->setIcon(dataSet->markerIcon(MarkerRing)); d->dataSetMarkerCrossAction->setIcon(dataSet->markerIcon(MarkerCross)); d->dataSetMarkerFastCrossAction->setIcon(dataSet->markerIcon(MarkerFastCross)); d->dataSetMarkerArrowDownAction->setIcon(dataSet->markerIcon(MarkerArrowDown)); d->dataSetMarkerArrowUpAction->setIcon(dataSet->markerIcon(MarkerArrowUp)); d->dataSetMarkerArrowRightAction->setIcon(dataSet->markerIcon(MarkerArrowRight)); d->dataSetMarkerArrowLeftAction->setIcon(dataSet->markerIcon(MarkerArrowLeft)); d->dataSetMarkerBowTieAction->setIcon(dataSet->markerIcon(MarkerBowTie)); d->dataSetMarkerHourGlassAction->setIcon(dataSet->markerIcon(MarkerHourGlass)); d->dataSetMarkerStarAction->setIcon(dataSet->markerIcon(MarkerStar)); d->dataSetMarkerXAction->setIcon(dataSet->markerIcon(MarkerX)); d->dataSetMarkerAsteriskAction->setIcon(dataSet->markerIcon(MarkerAsterisk)); d->dataSetMarkerHorizontalBarAction->setIcon(dataSet->markerIcon(MarkerHorizontalBar)); d->dataSetMarkerVerticalBarAction->setIcon(dataSet->markerIcon(MarkerVerticalBar)); switch(dataSet->odfSymbolType()) { case NoSymbol: d->ui.datasetMarkerMenu->setText(i18n("None")); d->ui.datasetMarkerMenu->setIcon(QIcon()); break; case NamedSymbol: d->ui.datasetMarkerMenu->setIcon(dataSet->markerIcon(dataSet->markerStyle())); d->ui.datasetMarkerMenu->setText(QString()); break; case ImageSymbol: case AutomaticSymbol: d->ui.datasetMarkerMenu->setText(i18n("Auto")); d->ui.datasetMarkerMenu->setIcon(QIcon()); break; } } void DataSetConfigWidget::ui_dataSetErrorBarTypeChanged() { if (d->selectedDataSet < 0) { return; } debugChartUiDataSet; QString type = d->formatErrorBarDialog.widget.errorType->currentText(); d->ui.formatErrorBar->setText(type); } void DataSetConfigWidget::ui_dataSetHasChartTypeChanged(bool b) { if (d->selectedDataSet < 0) { return; } debugChartUiDataSet<dataSets[d->selectedDataSet]; Q_ASSERT(dataSet); if (!dataSet) { return; } - emit dataSetChartTypeChanged(dataSet, b ? chart->chartType() : LastChartType); - emit dataSetChartSubTypeChanged(dataSet, b ? chart->chartSubType() : NoChartSubtype); + if (b) { + emit dataSetChartTypeChanged(dataSet, chart->chartType(), chart->chartSubType()); + } else { + emit dataSetChartTypeChanged(dataSet, LastChartType, NoChartSubtype); + } } void DataSetConfigWidget::dataSetChartTypeSelected(QAction *action) { if (d->selectedDataSet < 0) return; debugChartUiDataSet<dataSetNormalBarChartAction) { type = BarChartType; subtype = NormalChartSubtype; } else if (action == d->dataSetStackedBarChartAction) { type = BarChartType; subtype = StackedChartSubtype; } else if (action == d->dataSetPercentBarChartAction) { type = BarChartType; subtype = PercentChartSubtype; } else if (action == d->dataSetNormalLineChartAction) { type = LineChartType; subtype = NormalChartSubtype; } else if (action == d->dataSetStackedLineChartAction) { type = LineChartType; subtype = StackedChartSubtype; } else if (action == d->dataSetPercentLineChartAction) { type = LineChartType; subtype = PercentChartSubtype; } else if (action == d->dataSetNormalAreaChartAction) { type = AreaChartType; subtype = NormalChartSubtype; } else if (action == d->dataSetStackedAreaChartAction) { type = AreaChartType; subtype = StackedChartSubtype; } else if (action == d->dataSetPercentAreaChartAction) { type = AreaChartType; subtype = PercentChartSubtype; } else if (action == d->dataSetRadarChartAction) type = RadarChartType; else if (action == d->dataSetFilledRadarChartAction) type = FilledRadarChartType; else if (action == d->dataSetCircleChartAction) type = CircleChartType; else if (action == d->dataSetRingChartAction) type = RingChartType; else if (action == d->dataSetScatterChartAction) type = ScatterChartType; else if (action == d->dataSetHLCStockChartAction) { type = StockChartType; subtype = HighLowCloseChartSubtype; } else if (action == d->dataSetStackedAreaChartAction) { type = StockChartType; subtype = OpenHighLowCloseChartSubtype; } else if (action == d->dataSetCandlestickStockChartAction) { type = StockChartType; subtype = CandlestickChartSubtype; } else if (action == d->dataSetBubbleChartAction) type = BubbleChartType; // FIXME: Not supported by KoChart yet: //surface //gantt DataSet *dataSet = d->dataSets[d->selectedDataSet]; Q_ASSERT(dataSet); if (!dataSet) return; const QLatin1String iconName = chartTypeIconName(type, subtype); if (iconName.size() > 0) d->ui.dataSetChartTypeMenu->setIcon(QIcon::fromTheme(iconName)); - emit dataSetChartTypeChanged(dataSet, type); - emit dataSetChartSubTypeChanged(dataSet, subtype); + emit dataSetChartTypeChanged(dataSet, type, subtype); updateData(type, subtype); } void DataSetConfigWidget::datasetMarkerSelected(QAction *action) { if (d->selectedDataSet < 0) return; const int numDefaultMarkerTypes = 15; OdfMarkerStyle style = MarkerSquare; QString type = QString(""); OdfSymbolType symbolType = NamedSymbol; if (action == d->dataSetNoMarkerAction) { symbolType = NoSymbol; type = "None"; } else if (action == d->dataSetAutomaticMarkerAction) { style = (OdfMarkerStyle) (d->selectedDataSet % numDefaultMarkerTypes); type = "Auto"; symbolType = AutomaticSymbol; } else if (action == d->dataSetMarkerCircleAction) { style = MarkerCircle; } else if (action == d->dataSetMarkerSquareAction) { style = MarkerSquare; } else if (action == d->dataSetMarkerDiamondAction) { style = MarkerDiamond; } else if (action == d->dataSetMarkerRingAction) { style = MarkerRing; } else if (action == d->dataSetMarkerCrossAction) { style = MarkerCross; } else if (action == d->dataSetMarkerFastCrossAction) { style = MarkerFastCross; } else if (action == d->dataSetMarkerArrowDownAction) { style = MarkerArrowDown; } else if (action == d->dataSetMarkerArrowUpAction) { style = MarkerArrowUp; } else if (action == d->dataSetMarkerArrowRightAction) { style = MarkerArrowRight; } else if (action == d->dataSetMarkerArrowLeftAction) { style = MarkerArrowLeft; } else if (action == d->dataSetMarkerBowTieAction) { style = MarkerBowTie; } else if (action == d->dataSetMarkerHourGlassAction) { style = MarkerHourGlass; } else if (action == d->dataSetMarkerStarAction) { style = MarkerStar; } else if (action == d->dataSetMarkerXAction) { style = MarkerX; } else if (action == d->dataSetMarkerAsteriskAction) { style = MarkerAsterisk; } else if (action == d->dataSetMarkerHorizontalBarAction) { style = MarkerHorizontalBar; } else if (action == d->dataSetMarkerVerticalBarAction) { style = MarkerVerticalBar; } DataSet *dataSet = d->dataSets[d->selectedDataSet]; Q_ASSERT(dataSet); if (!dataSet) return; if (type.isEmpty()) { d->ui.datasetMarkerMenu->setIcon(dataSet->markerIcon(style)); d->ui.datasetMarkerMenu->setText(""); } else { d->ui.datasetMarkerMenu->setText(type); d->ui.datasetMarkerMenu->setIcon(QIcon()); } emit dataSetMarkerChanged(dataSet, symbolType, style); updateData(dataSet->chartType(), dataSet->chartSubType()); } void DataSetConfigWidget::datasetBrushSelected(const QColor& color) { if (d->selectedDataSet < 0) return; emit datasetBrushChanged(d->dataSets[d->selectedDataSet], color, -1); updateMarkers(); } void DataSetConfigWidget::datasetPenSelected(const QColor& color) { if (d->selectedDataSet < 0) return; emit datasetPenChanged(d->dataSets[d->selectedDataSet], color, -1); updateMarkers(); } void DataSetConfigWidget::updateData(ChartType chartType, ChartSubtype subtype) { Q_UNUSED(subtype) if (!chart) { return; } if (!chartTypes.contains(chartType)) { return; } QList newDataSets = chart->plotArea()->dataSets(); debugChartUiDataSet<selectedDataSet<dataSets<<':'<dataSetAxes.clear(); d->ui.dataSets->clear(); // Update the chart type specific settings in the "Data Sets" tab d->ui.errorBarProperties->hide(); // TODO: error indication is not implemented // if (chartType == BarChartType || chartType == LineChartType || chartType == AreaChartType || chartType == ScatterChartType) { // d->ui.errorBarProperties->show(); // } // TODO // d->ui.datasetShowSymbol->hide(); // if (chartType == LineChartType || chartType == AreaChartType || chartType == ScatterChartType || chartType == RadarChartType || chartType == FilledRadarChartType) { // d->ui.datasetShowSymbol->show(); // } // Make sure we only allow legal chart type combinations if (isPolar(chartType)) { // TODO: check out this claim: // Pie charts and ring charts have no axes but radar charts do. // Disable choosing of attached axis if there is none. bool hasAxes = !(chartType == CircleChartType || chartType == RingChartType); // d->ui.axisConfiguration->setEnabled(hasAxes); d->ui.dataSetAxes->setCurrentIndex(-1); d->ui.dataSetAxes->setEnabled(false); d->ui.dataSetHasChartType->setEnabled(hasAxes); d->ui.dataSetChartTypeMenu->setEnabled(hasAxes); } else { // All the cartesian chart types have axes. // d->ui.axisConfiguration->setEnabled(true); d->dataSetAxes.append(chart->plotArea()->yAxis()); if (chart->plotArea()->secondaryYAxis() && chart->plotArea()->secondaryYAxis()->isVisible()) { d->dataSetAxes.append(chart->plotArea()->secondaryYAxis()); } d->ui.dataSetAxes->setEnabled(true); d->ui.dataSetHasChartType->setEnabled(true); d->ui.dataSetChartTypeMenu->setEnabled(true); } // always update, in case titles have changed foreach (DataSet *dataSet, newDataSets) { QString title = dataSet->labelData().toString(); if (title.isEmpty()) title = i18n("Data Set %1", d->ui.dataSets->count() + 1); d->ui.dataSets->addItem(title); } if (newDataSets != d->dataSets) { d->selectedDataSet = 0; // new datasets, select the first d->dataSets = newDataSets; debugChartUiDataSet<<"new datasets"<ui.dataSets->setCurrentIndex(d->selectedDataSet); blockSignals(false); ui_dataSetSelectionChanged(d->selectedDataSet); } void DataSetConfigWidget::slotShowFormatErrorBarDialog() { d->formatErrorBarDialog.show(); } void DataSetConfigWidget::setupDialogs() { // Format Error Bars connect(d->ui.formatErrorBar, SIGNAL(clicked()), this, SLOT(slotShowFormatErrorBarDialog())); connect(&d->formatErrorBarDialog, SIGNAL(accepted()), this, SLOT(ui_dataSetErrorBarTypeChanged())); } void DataSetConfigWidget::createActions() { } void DataSetConfigWidget::ui_dataSetSelectionChanged(int index) { // Check for valid index debugChartUiDataSet<dataSets; if (index < 0 || index >= d->dataSets.size()) { return; } blockSignals(true); DataSet *dataSet = d->dataSets[index]; //d->ui.datasetColor->setText(axis->titleText()); d->ui.dataSetAxes->setCurrentIndex(d->dataSetAxes.indexOf(dataSet->attachedAxis())); d->ui.datasetBrush->setColor(dataSet->brush().color()); d->ui.datasetPen->setColor(dataSet->pen().color()); debugChartUiDataSet<valueLabelType(); d->ui.datasetShowCategory->setChecked(dataSet->valueLabelType().category); d->ui.dataSetShowNumber->setChecked(dataSet->valueLabelType().number); d->ui.datasetShowPercent->setChecked(dataSet->valueLabelType().percentage); // TODO // d->ui.datasetShowSymbol->setChecked(dataSet->valueLabelType().symbol); d->ui.dataSetHasChartType->setChecked(dataSet->chartType() != LastChartType); d->ui.dataSetChartTypeMenu->setEnabled(dataSet->chartType() != LastChartType); Q_ASSERT(d->ui.dataSetChartTypeMenu->menu()); d->ui.dataSetChartTypeMenu->setIcon(ICON2(dataSet->chartType(), dataSet->chartSubType())); d->selectedDataSet = index; blockSignals(false); updateMarkers(); ChartType chartType = dataSet->chartType(); if (chartType == LastChartType) { chartType = chart->chartType(); } bool disableMarkers = chartType == BarChartType || chartType == StockChartType || chartType == CircleChartType || chartType == RingChartType || chartType == BubbleChartType; d->ui.datasetMarkerMenu->setDisabled(disableMarkers); } void DataSetConfigWidget::ui_datasetShowCategoryChanged(bool b) { if (d->selectedDataSet < 0 || d->selectedDataSet >= d->dataSets.count()) { return; } debugChartUiDataSet<dataSets[d->selectedDataSet], b, -1); } void DataSetConfigWidget::ui_datasetShowErrorBarChanged(bool b) { if (d->selectedDataSet < 0 || d->selectedDataSet >= d->dataSets.count()) { return; } debugChartUiDataSet<ui.formatErrorBar->setEnabled(b); } void DataSetConfigWidget::ui_dataSetShowNumberChanged(bool b) { if (d->selectedDataSet < 0 || d->selectedDataSet >= d->dataSets.count()) { return; } debugChartUiDataSet<dataSets[d->selectedDataSet], b, -1); } void DataSetConfigWidget::ui_datasetShowPercentChanged(bool b) { if (d->selectedDataSet < 0 || d->selectedDataSet >= d->dataSets.count()) { return; } debugChartUiDataSet<dataSets[d->selectedDataSet], b, -1); } void DataSetConfigWidget::ui_datasetShowSymbolChanged(bool b) { if (d->selectedDataSet < 0 || d->selectedDataSet >= d->dataSets.count()) { return; } debugChartUiDataSet<dataSets[d->selectedDataSet], b, -1); } diff --git a/plugins/chartshape/DataSetConfigWidget.h b/plugins/chartshape/DataSetConfigWidget.h index 43cc8467fa8..f3e0d47cf5c 100644 --- a/plugins/chartshape/DataSetConfigWidget.h +++ b/plugins/chartshape/DataSetConfigWidget.h @@ -1,117 +1,116 @@ /* This file is part of the KDE project Copyright 2008 Johannes Simon Copyright 2008 Inge Wallin Copyright 2018 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KOCHART_DATACONFIGWIDGET #define KOCHART_DATACONFIGWIDGET #include "ConfigSubWidgetBase.h" #include "ChartShape.h" class KoShape; class QAction; namespace KChart { class Position; class CartesianAxis; } namespace KoChart { class ChartShape; /** * Chart type configuration widget. */ class DataSetConfigWidget : public ConfigSubWidgetBase { Q_OBJECT public: DataSetConfigWidget(QWidget *parent = 0); DataSetConfigWidget(QList types, QWidget *parent = 0); ~DataSetConfigWidget(); void open(ChartShape* shape) override; QAction * createAction(); /// reimplemented virtual bool showOnShapeCreate() { return true; } /// Delete all open dialogs. /// This is called when e.g. the tool is deactivated. void deleteSubDialogs(ChartType type = LastChartType); void updateMarkers(); public Q_SLOTS: void updateData(ChartType type, ChartSubtype subtype) override; void slotShowFormatErrorBarDialog(); void dataSetChartTypeSelected(QAction *action); void datasetMarkerSelected(QAction *action); void datasetBrushSelected(const QColor& color); void datasetPenSelected(const QColor& color); void ui_datasetShowCategoryChanged(bool b); void ui_datasetShowErrorBarChanged(bool b); void ui_dataSetShowNumberChanged(bool b); void ui_datasetShowPercentChanged(bool b); void ui_datasetShowSymbolChanged(bool b); void ui_dataSetSelectionChanged(int index); void ui_dataSetAxisSelectionChanged(int index); void ui_dataSetHasChartTypeChanged(bool b); void ui_dataSetErrorBarTypeChanged(); Q_SIGNALS: - void dataSetChartTypeChanged(DataSet *dataSet, ChartType type); - void dataSetChartSubTypeChanged(DataSet *dataSet, ChartSubtype subType); + void dataSetChartTypeChanged(DataSet *dataSet, ChartType type, ChartSubtype subType); void showVerticalLinesChanged(bool b); void showHorizontalLinesChanged(bool b); void datasetPenChanged(DataSet *dataSet, const QColor& color, int section); void datasetBrushChanged(DataSet *dataSet, const QColor& color, int section); void dataSetMarkerChanged(DataSet *dataSet, OdfSymbolType type, OdfMarkerStyle style); void datasetShowCategoryChanged(DataSet *dataSet, bool b, int section); void dataSetShowNumberChanged(DataSet *dataSet, bool b, int section); void datasetShowPercentChanged(DataSet *dataSet, bool b, int section); void datasetShowSymbolChanged(DataSet *dataSet, bool b, int section); void dataSetAxisChanged(DataSet *dataSet, Axis *axis); void axisAdded(AxisDimension, const QString& title); private: void setupDialogs(); void createActions(); class Private; Private * const d; }; } // namespace KoChart #endif // KOCHART_DATASETCONFIGWIDGET diff --git a/plugins/chartshape/commands/DatasetCommand.cpp b/plugins/chartshape/commands/DatasetCommand.cpp index 762f13f9de9..5450c1c1906 100644 --- a/plugins/chartshape/commands/DatasetCommand.cpp +++ b/plugins/chartshape/commands/DatasetCommand.cpp @@ -1,223 +1,235 @@ /* This file is part of the KDE project Copyright 2012 Brijesh Patel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "DatasetCommand.h" // KF5 #include // KoChart #include "DataSet.h" #include "Axis.h" #include "ChartDebug.h" using namespace KoChart; using namespace KChart; DatasetCommand::DatasetCommand(DataSet* dataSet, ChartShape* chart, int section, KUndo2Command *parent) : KUndo2Command(parent) , m_dataSet(dataSet) , m_chart(chart) , m_section(section) { m_newType = dataSet->chartType(); m_newSubtype = dataSet->chartSubType(); m_newShowCategory = dataSet->valueLabelType(section).category; m_newShowNumber = dataSet->valueLabelType(section).number; m_newShowPercent = dataSet->valueLabelType(section).percentage; m_newShowSymbol = dataSet->valueLabelType(section).symbol; m_newBrushColor = dataSet->brush(section).color(); m_newPenColor = dataSet->pen(section).color(); m_newOdfSymbolType = dataSet->odfSymbolType(); m_newMarkerStyle = dataSet->markerStyle(); m_newAxis = dataSet->attachedAxis(); } DatasetCommand::~DatasetCommand() { } void DatasetCommand::redo() { // save the old type /*m_oldType = m_dataSet->chartType(); m_oldSubtype = m_dataSet->chartSubType();*/ m_oldShowCategory = m_dataSet->valueLabelType(m_section).category; m_oldShowNumber = m_dataSet->valueLabelType(m_section).number; m_oldShowPercent = m_dataSet->valueLabelType(m_section).percentage; m_oldShowSymbol = m_dataSet->valueLabelType(m_section).symbol; m_oldBrushColor = m_dataSet->brush(m_section).color(); m_oldPenColor = m_dataSet->pen(m_section).color(); m_oldOdfSymbolType = m_dataSet->odfSymbolType(); m_oldMarkerStyle = m_dataSet->markerStyle(); m_oldAxis = m_dataSet->attachedAxis(); + m_oldType = m_dataSet->chartType(); + m_oldSubtype = m_dataSet->chartSubType(); if (m_oldShowCategory != m_newShowCategory || m_oldShowNumber != m_newShowNumber || m_oldShowPercent != m_newShowPercent || m_oldShowSymbol != m_newShowSymbol) { DataSet::ValueLabelType valueLabelType = m_dataSet->valueLabelType(m_section); valueLabelType.category = m_newShowCategory; valueLabelType.number = m_newShowNumber; valueLabelType.percentage = m_newShowPercent; valueLabelType.symbol = m_newShowSymbol; debugChartUiDataSet<<"section:"<valueLabelType(m_section)<<"->"<setValueLabelType(valueLabelType, m_section); } if (m_oldBrushColor != m_newBrushColor) { m_dataSet->setBrush(m_section, QBrush(m_newBrushColor)); } if (m_oldPenColor != m_newPenColor) { m_dataSet->setPen(m_section, QPen(m_newPenColor, 0)); } if (m_oldOdfSymbolType != m_newOdfSymbolType) { m_dataSet->setOdfSymbolType(m_newOdfSymbolType); } if (m_oldMarkerStyle != m_newMarkerStyle) { m_dataSet->setMarkerStyle(m_newMarkerStyle); } if (m_newAxis != m_oldAxis) { m_oldAxis->detachDataSet(m_dataSet); m_newAxis->attachDataSet(m_dataSet); } - + if (m_newType != m_oldType) { + m_dataSet->setChartType(m_newType); + } + if (m_newSubtype != m_oldSubtype) { + m_dataSet->setChartSubType(m_newSubtype); + } m_chart->updateAll(); } void DatasetCommand::undo() { if (m_oldShowCategory != m_newShowCategory || m_oldShowNumber != m_newShowNumber || m_oldShowPercent != m_newShowPercent || m_oldShowSymbol != m_newShowSymbol) { DataSet::ValueLabelType valueLabelType = m_dataSet->valueLabelType(m_section); valueLabelType.category = m_oldShowCategory; valueLabelType.number = m_oldShowNumber; valueLabelType.percentage = m_oldShowPercent; valueLabelType.symbol = m_oldShowSymbol; debugChartUiDataSet<<"section:"<valueLabelType(m_section)<<"->"<setValueLabelType(valueLabelType, m_section); } if (m_oldBrushColor != m_newBrushColor) { m_dataSet->setBrush(m_section, QBrush(m_oldBrushColor)); } if (m_oldPenColor != m_newPenColor) { m_dataSet->setPen(m_section, QPen(m_oldPenColor, 0)); } if (m_oldOdfSymbolType != m_newOdfSymbolType) { m_dataSet->setOdfSymbolType(m_oldOdfSymbolType); } if (m_oldMarkerStyle != m_newMarkerStyle) { m_dataSet->setMarkerStyle(m_oldMarkerStyle); } if (m_newAxis != m_oldAxis) { m_newAxis->detachDataSet(m_dataSet); m_oldAxis->attachDataSet(m_dataSet); } - + if (m_newType != m_oldType) { + m_dataSet->setChartType(m_oldType); + } + if (m_newSubtype != m_oldSubtype) { + m_dataSet->setChartSubType(m_oldSubtype); + } m_chart->updateAll(); } void DatasetCommand::setDataSetChartType(ChartType type, ChartSubtype subtype) { m_newType = type; m_newSubtype = subtype; setText(kundo2_i18n("Set Dataset Chart Type")); } void DatasetCommand::setDataSetShowCategory(bool show) { m_newShowCategory = show; if (show) { setText(kundo2_i18n("Show Dataset Category")); } else { setText(kundo2_i18n("Hide Dataset Category")); } } void DatasetCommand::setDataSetShowNumber(bool show) { m_newShowNumber = show; if (show) { setText(kundo2_i18n("Show Dataset Number")); } else { setText(kundo2_i18n("Hide Dataset Number")); } } void DatasetCommand::setDataSetShowPercent(bool show) { m_newShowPercent = show; if (show) { setText(kundo2_i18n("Show Dataset Percent")); } else { setText(kundo2_i18n("Hide Dataset Percent")); } } void DatasetCommand::setDataSetShowSymbol(bool show) { m_newShowSymbol = show; if (show) { setText(kundo2_i18n("Show Dataset Symbol")); } else { setText(kundo2_i18n("Hide Dataset Symbol")); } } void DatasetCommand::setDataSetBrush(const QColor &color) { m_newBrushColor = color; setText(kundo2_i18n("Set Dataset Brush Color")); } void DatasetCommand::setDataSetPen(const QColor &color) { m_newPenColor = color; setText(kundo2_i18n("Set Dataset Pen Color")); } void DatasetCommand::setDataSetMarker(OdfSymbolType type, OdfMarkerStyle style) { m_newOdfSymbolType = type; m_newMarkerStyle = style; if (type == NoSymbol) { setText(kundo2_i18n("Hide Dataset Marker")); } else { setText(kundo2_i18n("Show Dataset Marker Symbol")); } } void DatasetCommand::setDataSetAxis(Axis *axis) { m_newAxis = axis; setText(kundo2_i18n("Set Dataset Axis")); }