Commit fe17926c authored by Brijesh Patel's avatar Brijesh Patel

Add the following commands for charts :

i) Axis commands
ii) Legend commands
iii) Dataset commands
iv) Chart type command
v) Textshape command
parent 2a91ffc5
......@@ -44,6 +44,10 @@ SET (chartshape_LIB_SRCS
dialogs/FontEditorDialog.cpp
dialogs/FormatErrorBarDialog.cpp
commands/ChartTypeCommand.cpp
commands/LegendCommand.cpp
commands/AxisCommand.cpp
commands/DatasetCommand.cpp
commands/ChartTextShapeCommand.cpp
)
kde4_add_ui_files(chartshape_LIB_SRCS
......
......@@ -1145,6 +1145,9 @@ void ChartConfigWidget::update()
d->ui.showSubTitle->setChecked(d->shape->subTitle()->isVisible());
d->ui.showFooter->setChecked(d->shape->footer()->isVisible());
// Update properties in "Data Sets" tab
ui_dataSetSelectionChanged(d->selectedDataSet);
// Update "Bar Properties" in "Data Sets" tab
d->ui.gapBetweenBars->setValue(d->shape->plotArea()->gapBetweenBars());
d->ui.gapBetweenSets->setValue(d->shape->plotArea()->gapBetweenSets());
......@@ -1239,9 +1242,23 @@ void ChartConfigWidget::update()
d->ui.threeDLook->setEnabled(enableThreeDOption);
if (d->shape->legend()) {
d->ui.legendTitle->blockSignals(true);
d->ui.showLegend->setChecked(d->shape->legend()->isVisible());
d->ui.legendTitle->blockSignals(false);
d->ui.legendTitle->blockSignals(true);
d->ui.legendTitle->setText(d->shape->legend()->title());
d->ui.legendTitle->blockSignals(false);
d->ui.legendTitle->blockSignals(true);
d->ui.legendShowFrame->setChecked(d->shape->legend()->showFrame());
d->ui.legendTitle->blockSignals(false);
if (d->shape->legend()->expansion() == HighLegendExpansion) {
d->ui.legendOrientationIsVertical->setChecked(true);
} else {
d->ui.legendOrientationIsHorizontal->setChecked(true);
}
}
bool enableMarkers = !(d->type == BarChartType || d->type == StockChartType || d->type == CircleChartType
......@@ -1763,15 +1780,15 @@ void ChartConfigWidget::ui_axisLabelsFontChanged()
{
QFont font = d->axisFontEditorDialog.fontChooser->font();
Axis *axis = d->axes[d->ui.axes->currentIndex()];
axis->setFont(font);
axis->setFontSize(font.pointSizeF());
emit axisLabelsFontChanged(axis, font);
}
void ChartConfigWidget::ui_legendFontChanged()
{
QFont font = d->legendFontEditorDialog.fontChooser->font();
d->shape->legend()->setFont(font);
d->shape->legend()->setFontSize(font.pointSizeF());
emit legendFontChanged(font);
}
void ChartConfigWidget::ui_axisAdded()
......
......@@ -168,6 +168,7 @@ signals:
void axisSubStepWidthChanged(Axis *axis, qreal width);
void axisUseAutomaticStepWidthChanged(Axis *axis, bool automatic);
void axisUseAutomaticSubStepWidthChanged(Axis *axis, bool automatic);
void axisLabelsFontChanged(Axis *axis, const QFont& font);
void legendTitleChanged(const QString&);
void legendFontChanged(const QFont& font);
......
......@@ -1337,6 +1337,8 @@ void ChartShape::saveOdfData(KoXmlWriter &bodyWriter, KoGenStyles &mainStyles) c
void ChartShape::update() const
{
KoShape::update();
emit updateConfigWidget();
}
void ChartShape::relayout() const
......
......@@ -235,7 +235,7 @@ public:
signals:
void chartTypeChanged(ChartType);
void updateConfigWidget();
void updateConfigWidget() const;
private:
bool loadEmbeddedDocument(KoStore *store, const KoXmlElement &objectElement,
......
......@@ -61,6 +61,10 @@
#include "ChartConfigWidget.h"
#include "KDChartConvertions.h"
#include "commands/ChartTypeCommand.h"
#include "commands/LegendCommand.h"
#include "commands/AxisCommand.h"
#include "commands/DatasetCommand.h"
#include "commands/ChartTextShapeCommand.h"
using namespace KChart;
......@@ -332,6 +336,8 @@ QWidget *ChartTool::createOptionWidget()
this, SLOT(setAxisUseAutomaticStepWidth(Axis*, bool)));
connect(widget, SIGNAL(axisUseAutomaticSubStepWidthChanged(Axis*, bool)),
this, SLOT(setAxisUseAutomaticSubStepWidth(Axis*, bool)));
connect(widget, SIGNAL(axisLabelsFontChanged(Axis*, const QFont&)),
this, SLOT(setAxisLabelsFont(Axis*, const QFont&)));
connect(widget, SIGNAL(legendTitleChanged(const QString&)),
this, SLOT(setLegendTitle(const QString&)));
......@@ -356,7 +362,9 @@ QWidget *ChartTool::createOptionWidget()
this, SLOT(setLegendShowFrame(bool)));
connect(d->shape, SIGNAL(updateConfigWidget()),
widget, SLOT(update()));
widget, SLOT(update()));
connect(d->shape->legend(), SIGNAL(updateConfigWidget()),
widget, SLOT(update()));
return widget;
......@@ -457,7 +465,10 @@ void ChartTool::setDataSetBrush(DataSet *dataSet, const QColor& color)
if (!dataSet)
return;
dataSet->setBrush(QBrush(color));
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetBrush(color);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setDataSetPen(DataSet *dataSet, const QColor& color)
......@@ -466,7 +477,10 @@ void ChartTool::setDataSetPen(DataSet *dataSet, const QColor& color)
if (!dataSet)
return;
dataSet->setPen(QPen(color));
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetPen(color);
canvas()->addCommand(command);
d->shape->update();
}
......@@ -476,7 +490,10 @@ void ChartTool::setDataSetMarker(DataSet *dataSet, OdfMarkerStyle style)
if (!dataSet)
return;
dataSet->setMarkerStyle(style);
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetMarker(style);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setDataSetAxis(DataSet *dataSet, Axis *axis)
......@@ -520,22 +537,58 @@ void ChartTool::Private::setDataSetShowLabel(DataSet *dataSet, bool *number, boo
void ChartTool::setDataSetShowCategory(DataSet *dataSet, bool b)
{
d->setDataSetShowLabel(dataSet, 0, 0, &b, 0);
//d->setDataSetShowLabel(dataSet, 0, 0, &b, 0);
Q_ASSERT(d->shape);
if (!dataSet)
return;
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetShowCategory(b);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setDataSetShowNumber(DataSet *dataSet, bool b)
{
d->setDataSetShowLabel(dataSet, &b, 0, 0, 0);
//d->setDataSetShowLabel(dataSet, &b, 0, 0, 0);
Q_ASSERT(d->shape);
if (!dataSet)
return;
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetShowNumber(b);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setDataSetShowPercent(DataSet *dataSet, bool b)
{
d->setDataSetShowLabel(dataSet, 0, &b, 0, 0);
//d->setDataSetShowLabel(dataSet, 0, &b, 0, 0);
Q_ASSERT(d->shape);
if (!dataSet)
return;
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetShowPercent(b);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setDataSetShowSymbol(DataSet *dataSet, bool b)
{
d->setDataSetShowLabel(dataSet, 0, 0, 0, &b);
//d->setDataSetShowLabel(dataSet, 0, 0, 0, &b);
Q_ASSERT(d->shape);
if (!dataSet)
return;
DatasetCommand *command = new DatasetCommand(dataSet, d->shape);
command->setDataSetShowSymbol(b);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setThreeDMode(bool threeD)
......@@ -554,7 +607,9 @@ void ChartTool::setShowTitle(bool show)
if (!d->shape)
return;
d->shape->showTitle(show);
ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->title(), d->shape, show);
canvas()->addCommand(command);
d->shape->update();
}
......@@ -564,7 +619,9 @@ void ChartTool::setShowSubTitle(bool show)
if (!d->shape)
return;
d->shape->showSubTitle(show);
ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->subTitle(), d->shape, show);
canvas()->addCommand(command);
d->shape->update();
}
......@@ -574,7 +631,9 @@ void ChartTool::setShowFooter(bool show)
if (!d->shape)
return;
d->shape->showFooter(show);
ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->footer(), d->shape, show);
canvas()->addCommand(command);
d->shape->update();
}
......@@ -594,8 +653,9 @@ void ChartTool::setLegendTitle(const QString &title)
Q_ASSERT(d->shape);
Q_ASSERT(d->shape->legend());
d->shape->legend()->setTitle(title);
d->shape->legend()->update();
LegendCommand *command = new LegendCommand(d->shape->legend());
command->setLegendTitle(title);
canvas()->addCommand(command);
}
void ChartTool::setLegendFont(const QFont &font)
......@@ -604,8 +664,9 @@ void ChartTool::setLegendFont(const QFont &font)
Q_ASSERT(d->shape->legend());
// There only is a general font, for the legend items and the legend title
d->shape->legend()->setFont(font);
d->shape->legend()->update();
LegendCommand *command = new LegendCommand(d->shape->legend());
command->setLegendFont(font);
canvas()->addCommand(command);
}
void ChartTool::setLegendFontSize(int size)
......@@ -613,8 +674,9 @@ void ChartTool::setLegendFontSize(int size)
Q_ASSERT(d->shape);
Q_ASSERT(d->shape->legend());
d->shape->legend()->setFontSize(size);
d->shape->legend()->update();
LegendCommand *command = new LegendCommand(d->shape->legend());
command->setLegendFontSize(size);
canvas()->addCommand(command);
}
void ChartTool::setLegendOrientation(Qt::Orientation orientation)
......@@ -622,8 +684,9 @@ void ChartTool::setLegendOrientation(Qt::Orientation orientation)
Q_ASSERT(d->shape);
Q_ASSERT(d->shape->legend());
d->shape->legend()->setExpansion(QtOrientationToLegendExpansion(orientation));
d->shape->legend()->update();
LegendCommand *command = new LegendCommand(d->shape->legend());
command->setLegendExpansion(QtOrientationToLegendExpansion(orientation));
canvas()->addCommand(command);
}
void ChartTool::setLegendAlignment(Qt::Alignment alignment)
......@@ -672,8 +735,9 @@ void ChartTool::setLegendShowFrame(bool show)
Q_ASSERT(d->shape);
Q_ASSERT(d->shape->legend());
d->shape->legend()->setShowFrame(show);
d->shape->legend()->update();
LegendCommand *command = new LegendCommand(d->shape->legend());
command->setLegendShowFrame(show);
canvas()->addCommand(command);
}
......@@ -696,7 +760,12 @@ void ChartTool::removeAxis(Axis *axis)
void ChartTool::setAxisTitle(Axis *axis, const QString& title)
{
axis->setTitleText(title);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisTitle(title);
canvas()->addCommand(command);
d->shape->update();
}
......@@ -704,44 +773,87 @@ void ChartTool::setAxisShowTitle(Axis *axis, bool show)
{
Q_ASSERT(d->shape);
axis->title()->setVisible(show);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisShowTitle(show);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setAxisShowGridLines(Axis *axis, bool b)
{
axis->setShowMajorGrid(b);
axis->setShowMinorGrid(b);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisShowGridLines(b);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setAxisUseLogarithmicScaling(Axis *axis, bool b)
{
axis->setScalingLogarithmic(b);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisUseLogarithmicScaling(b);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setAxisStepWidth(Axis *axis, qreal width)
{
axis->setMajorInterval(width);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisStepWidth(width);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setAxisSubStepWidth(Axis *axis, qreal width)
{
axis->setMinorInterval(width);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisSubStepWidth(width);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setAxisUseAutomaticStepWidth(Axis *axis, bool automatic)
{
axis->setUseAutomaticMajorInterval(automatic);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisUseAutomaticStepWidth(automatic);
canvas()->addCommand(command);
d->shape->update();
}
void ChartTool::setAxisUseAutomaticSubStepWidth(Axis *axis, bool automatic)
{
axis->setUseAutomaticMinorInterval(automatic);
Q_ASSERT(d->shape);
AxisCommand *command = new AxisCommand(axis, d->shape);
command->setAxisUseAutomaticSubStepWidth(automatic);
canvas()->addCommand(command);
d->shape->update();
}
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);
d->shape->update();
}
......@@ -770,11 +882,13 @@ void ChartTool::setPieExplodeFactor(DataSet *dataSet, int percent)
d->shape->update();
}
void ChartTool::setShowLegend(bool b)
void ChartTool::setShowLegend(bool show)
{
Q_ASSERT(d->shape);
d->shape->legend()->setVisible(b);
ChartTextShapeCommand *command = new ChartTextShapeCommand(d->shape->legend(), d->shape, show);
canvas()->addCommand(command);
d->shape->legend()->update();
}
......
......@@ -107,9 +107,10 @@ private slots:
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 b);
void setShowLegend(bool show);
void setLegendTitle(const QString& title);
void setLegendFont(const QFont& font);
void setLegendFontSize(int size);
......
......@@ -95,7 +95,7 @@ public:
Legend::Private::Private()
{
lineBorder = new KoShapeStroke(0.5, Qt::black);
showFrame = true;
showFrame = false;
framePen = QPen();
backgroundBrush = QBrush();
expansion = HighLegendExpansion;
......@@ -154,6 +154,8 @@ void Legend::setTitle(const QString &title)
d->title = title;
d->kdLegend->setTitleText(title);
d->pixmapRepaintRequested = true;
emit updateConfigWidget();
}
bool Legend::showFrame() const
......@@ -165,6 +167,8 @@ void Legend::setShowFrame(bool show)
{
d->showFrame = show;
setStroke(show ? d->lineBorder : 0);
emit updateConfigWidget();
}
QPen Legend::framePen() const
......@@ -257,6 +261,7 @@ void Legend::setFont(const QFont &font)
d->kdLegend->setTextAttributes(attributes);
d->pixmapRepaintRequested = true;
emit updateConfigWidget();
}
qreal Legend::fontSize() const
......@@ -276,6 +281,7 @@ void Legend::setFontSize(qreal size)
d->kdLegend->setTextAttributes(attributes);
d->pixmapRepaintRequested = true;
emit updateConfigWidget();
}
void Legend::setFontColor(const QColor &color)
......@@ -340,6 +346,8 @@ void Legend::setExpansion(LegendExpansion expansion)
d->expansion = expansion;
d->kdLegend->setOrientation(LegendExpansionToQtOrientation(expansion));
d->pixmapRepaintRequested = true;
emit updateConfigWidget();
}
Qt::Alignment Legend::alignment() const
......
......@@ -85,6 +85,9 @@ public:
using KoShape::update;
void update() const;
signals:
void updateConfigWidget();
private slots:
void slotChartTypeChanged(ChartType chartType );
void slotKdLegendChanged();
......
/* This file is part of the KDE project
Copyright 2012 Brijesh Patel <brijesh3105@gmail.com>
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 "AxisCommand.h"
// KDE
#include <kdebug.h>
#include <klocalizedstring.h>
// KChart
#include "Axis.h"
using namespace KChart;
using namespace KDChart;
AxisCommand::AxisCommand(Axis* axis, ChartShape* chart)
: m_axis(axis)
, m_chart(chart)
{
m_newShowTitle = m_axis->title()->isVisible();
m_newTitleText = m_axis->titleText();
m_newShowGridLines = m_axis->showMajorGrid();
m_newUseLogarithmicScaling = m_axis->scalingIsLogarithmic();
m_newLabelsFont = m_axis->font();
}
AxisCommand::~AxisCommand()
{
}
void AxisCommand::redo()
{
// save the old type
m_oldShowTitle = m_axis->title()->isVisible();
m_oldTitleText = m_axis->titleText();
m_oldShowGridLines = m_axis->showMajorGrid();
m_oldUseLogarithmicScaling = m_axis->scalingIsLogarithmic();
m_oldLabelsFont = m_axis->font();
/*m_oldStepWidth = m_axis->majorInterval();
m_oldSubStepWidth = m_axis->minorInterval();
m_oldUseAutomaticStepWidth = m_axis->useAutomaticMajorInterval();
m_oldUseAutomaticSubStepWidth = m_axis->useAutomaticMinorInterval();*/
if (m_oldShowTitle == m_newShowTitle && m_oldTitleText == m_newTitleText && m_oldShowGridLines == m_newShowGridLines
&& m_oldUseLogarithmicScaling == m_newUseLogarithmicScaling && m_oldLabelsFont == m_newLabelsFont)
return;
// Actually do the work
m_axis->title()->setVisible(m_newShowTitle);
m_axis->setTitleText(m_newTitleText);
m_axis->setShowMajorGrid(m_newShowGridLines);
m_axis->setShowMinorGrid(m_newShowGridLines);
m_axis->setScalingLogarithmic(m_oldUseLogarithmicScaling);
m_axis->setFont(m_newLabelsFont);
m_axis->setFontSize(m_newLabelsFont.pointSize());
/*m_axis->setMajorInterval(m_newStepWidth);
m_axis->setMinorInterval(m_newSubStepWidth);
m_axis->setUseAutomaticMajorInterval(m_newUseAutomaticStepWidth);
m_axis->setUseAutomaticMinorInterval(m_newUseAutomaticSubStepWidth);*/
m_chart->update();
}
void AxisCommand::undo()
{
if (m_oldShowTitle == m_newShowTitle && m_oldTitleText == m_newTitleText && m_oldShowGridLines == m_newShowGridLines
&& m_oldUseLogarithmicScaling == m_newUseLogarithmicScaling && m_oldLabelsFont == m_newLabelsFont)
return;
m_axis->title()->setVisible(m_oldShowTitle);
m_axis->setTitleText(m_oldTitleText);
m_axis->setShowMajorGrid(m_oldShowGridLines);
m_axis->setShowMinorGrid(m_oldShowGridLines);
m_axis->setScalingLogarithmic(m_oldUseLogarithmicScaling);
m_axis->setFont(m_oldLabelsFont);
m_axis->setFontSize(m_oldLabelsFont.pointSize());
/*m_axis->setMajorInterval(m_oldStepWidth);
m_axis->setMinorInterval(m_oldSubStepWidth);
m_axis->setUseAutomaticMajorInterval(m_oldUseAutomaticStepWidth);
m_axis->setUseAutomaticMinorInterval(m_oldUseAutomaticSubStepWidth);*/
m_chart->update();
}