##// END OF EJS Templates
fixed naming mixup with percent and stacked groups
fixed naming mixup with percent and stacked groups

File last commit:

r105:37fe9cea6214
r105:37fe9cea6214
Show More
qchart.cpp
392 lines | 11.6 KiB | text/x-c | CppLexer
Michal Klocek
adds missing files form previous commit
r12 #include "qchart.h"
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "qchartseries.h"
Tero Ahola
Integrated scatter type series...
r42 #include "qscatterseries.h"
#include "qscatterseries_p.h"
Tero Ahola
Integrated draft version of pie series
r51 #include "qpieseries.h"
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 #include "qpieseries_p.h"
Michal Klocek
Changes reinterpret_cast to static_cast
r45 #include "qxychartseries.h"
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 #include "qchartaxis.h"
sauimone
Integrating bar chart. Cleaned up old implementation. TODO: show this in test application. how?
r56 #include "barchartseries.h"
#include "bargroup.h"
sauimone
added example for stacked bar chart.
r95 #include "stackedbarchartseries.h"
#include "stackedbargroup.h"
sauimone
percent bar chart
r101 #include "percentbarchartseries.h"
#include "percentbargroup.h"
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 #include "charttheme_p.h"
Tero Ahola
Refactoring continued: restored ChartItem class
r104 #include "chartobjectinterface_p.h"
sauimone
Integrating bar chart. Cleaned up old implementation. TODO: show this in test application. how?
r56
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "xylinechartitem_p.h"
Michal Klocek
Add zoom support...
r67 #include "plotdomain_p.h"
#include "axisitem_p.h"
Tero Ahola
Integrated scatter type series...
r42 #include <QGraphicsScene>
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include <QDebug>
Michal Klocek
adds missing files form previous commit
r12
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
adds missing files form previous commit
r12
Tero Ahola
Resizing of QGraphicItems now possible by resize signal from QChart
r48 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
Michal Klocek
Adds title support
r87 m_backgroundItem(0),
m_titleItem(0),
m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
Tero Ahola
Draft implementation for setting color themes for a chart
r64 m_plotDataIndex(0),
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 m_marginSize(0),
m_chartTheme(new ChartTheme())
Michal Klocek
adds missing files form previous commit
r12 {
Tero Ahola
Draft implementation for setting color themes for a chart
r64 // TODO: the default theme?
Tero Ahola
Enabled color themes again
r91 setTheme(QChart::ChartThemeDefault);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Add zoom support...
r67 PlotDomain domain;
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 m_plotDomainList << domain;
Michal Klocek
Adds title support
r87 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
Tero Ahola
Refactoring continued: restored ChartItem class
r104 m_chartObjectInterfaces << m_axisXItem;
m_chartObjectInterfaces << m_axisYItem.at(0);
Michal Klocek
adds missing files form previous commit
r12 }
QChart::~QChart(){}
Michal Klocek
Refactor current draft to fit int current design specs...
r21 QRectF QChart::boundingRect() const
{
Michal Klocek
Removes PIMPL for now...
r53 return m_rect;
Michal Klocek
Refactor current draft to fit int current design specs...
r21 }
Michal Klocek
adds missing files form previous commit
r12
Michal Klocek
Refactor current draft to fit int current design specs...
r21 void QChart::addSeries(QChartSeries* series)
Michal Klocek
adds missing files form previous commit
r12 {
Tero Ahola
Resizing of QGraphicItems now possible by resize signal from QChart
r48 // TODO: we should check the series not already added
Michal Klocek
Changes reinterpret_cast to static_cast
r45
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 m_chartSeries << series;
Michal Klocek
Refactor current draft to fit int current design specs...
r21
switch(series->type())
{
Tero Ahola
Renamed to QtCommercialChart
r30 case QChartSeries::SeriesTypeLine: {
Michal Klocek
Removes hardcoded values for xydomain
r47
QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
Michal Klocek
Add zoom support...
r67 m_plotDataIndex = 0 ;
m_plotDomainList.resize(1);
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
Michal Klocek
Removes hardcoded values for xydomain
r47
for (int i = 0 ; i < xyseries->count() ; i++)
{
qreal x = xyseries->x(i);
qreal y = xyseries->y(i);
domain.m_minX = qMin(domain.m_minX,x);
domain.m_minY = qMin(domain.m_minY,y);
domain.m_maxX = qMax(domain.m_maxX,x);
domain.m_maxY = qMax(domain.m_maxY,y);
}
XYLineChartItem* item = new XYLineChartItem(xyseries,this);
Michal Klocek
Add zoom support...
r67
Tero Ahola
Refactoring continued: restored ChartItem class
r104 // TODO: combine ChartObjectInterface and ChartItem apis
m_chartObjectInterfaces << item;
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 item->setTheme(m_chartTheme);
Tero Ahola
Refactoring continued: restored ChartItem class
r104 foreach(ChartObjectInterface* i, m_chartObjectInterfaces)
Michal Klocek
Add zoom support...
r67 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
Michal Klocek
Refactor current draft to fit int current design specs...
r21 break;
Michal Klocek
adds missing files form previous commit
r12 }
sauimone
Integrating bar chart. Cleaned up old implementation. TODO: show this in test application. how?
r56 case QChartSeries::SeriesTypeBar: {
qDebug() << "barSeries added";
BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
sauimone
Added bar chart example
r78 BarGroup* barGroup = new BarGroup(*barSeries,this);
sauimone
correct drawing for barchart
r82
// Add some fugly colors for 5 fist series...
barGroup->addColor(QColor(255,0,0,128));
barGroup->addColor(QColor(255,255,0,128));
barGroup->addColor(QColor(0,255,0,128));
barGroup->addColor(QColor(0,0,255,128));
barGroup->addColor(QColor(255,128,0,128));
Tero Ahola
Refactoring continued: restored ChartItem class
r104 m_chartObjectInterfaces << barGroup;
sauimone
Added bar chart example
r78 childItems().append(barGroup);
sauimone
fixed naming mixup with percent and stacked groups
r105
m_plotDataIndex = 0 ;
m_plotDomainList.resize(1);
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
foreach(ChartItem* i ,m_chartItems)
i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
sauimone
Integrating bar chart. Cleaned up old implementation. TODO: show this in test application. how?
r56 break;
}
sauimone
added example for stacked bar chart.
r95 case QChartSeries::SeriesTypeStackedBar: {
qDebug() << "barSeries added";
StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this);
// Add some fugly colors for 5 fist series...
stackedBarGroup->addColor(QColor(255,0,0,128));
stackedBarGroup->addColor(QColor(255,255,0,128));
stackedBarGroup->addColor(QColor(0,255,0,128));
stackedBarGroup->addColor(QColor(0,0,255,128));
stackedBarGroup->addColor(QColor(255,128,0,128));
Tero Ahola
Refactoring continued: restored ChartItem class
r104 m_chartObjectInterfaces << stackedBarGroup;
sauimone
added example for stacked bar chart.
r95 childItems().append(stackedBarGroup);
sauimone
fixed naming mixup with percent and stacked groups
r105 m_plotDataIndex = 0 ;
m_plotDomainList.resize(1);
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
foreach(ChartItem* i ,m_chartItems)
i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
sauimone
added example for stacked bar chart.
r95 break;
}
sauimone
percent bar chart
r101 case QChartSeries::SeriesTypePercentBar: {
qDebug() << "barSeries added";
PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this);
// Add some fugly colors for 5 fist series...
percentBarGroup->addColor(QColor(255,0,0,128));
percentBarGroup->addColor(QColor(255,255,0,128));
percentBarGroup->addColor(QColor(0,255,0,128));
percentBarGroup->addColor(QColor(0,0,255,128));
percentBarGroup->addColor(QColor(255,128,0,128));
Tero Ahola
Refactoring continued: restored ChartItem class
r104 m_chartObjectInterfaces << percentBarGroup;
sauimone
percent bar chart
r101 childItems().append(percentBarGroup);
sauimone
fixed naming mixup with percent and stacked groups
r105 m_plotDataIndex = 0 ;
m_plotDomainList.resize(1);
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
foreach(ChartItem* i ,m_chartItems)
i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
sauimone
percent bar chart
r101 break;
}
Tero Ahola
Integrated scatter type series...
r42 case QChartSeries::SeriesTypeScatter: {
Tero Ahola
Fixed line series usage in the test app
r65 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 scatterSeries->d->setParentItem(this);
Tero Ahola
Refactoring continued: restored ChartItem class
r104 m_chartObjectInterfaces << scatterSeries->d;
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1;
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 break;
Tero Ahola
Fixed line series usage in the test app
r65 }
Tero Ahola
Integrated draft version of pie series
r51 case QChartSeries::SeriesTypePie: {
Tero Ahola
Fixed line series usage in the test app
r65 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 // for (int i(0); i < pieSeries->sliceCount(); i++) {
// if (!pieSeries->sliceColor(i).isValid())
// pieSeries->setSliceColor(i, nextColor());
// }
pieSeries->d->setTheme(m_chartTheme);
Tero Ahola
Refactoring continued: restored ChartItem class
r104 m_chartObjectInterfaces << pieSeries->d;
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75
// Set pre-defined colors in case the series has no colors defined
Tero Ahola
Draft implementation for setting color themes for a chart
r64 // TODO: how to define the color for all the slices of a pie?
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 // for (int (i); i < pieSeries.sliceCount(); i++)
break;
Tero Ahola
Fixed line series usage in the test app
r65 }
}
}
QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
{
// TODO: support also other types; not only scatter and pie
QChartSeries *series(0);
switch (type) {
case QChartSeries::SeriesTypeLine: {
series = QXYChartSeries::create();
break;
}
case QChartSeries::SeriesTypeBar: {
series = new BarChartSeries(this);
break;
}
sauimone
added example for stacked bar chart.
r95 case QChartSeries::SeriesTypeStackedBar: {
series = new StackedBarChartSeries(this);
break;
}
sauimone
percent bar chart
r101 case QChartSeries::SeriesTypePercentBar: {
series = new PercentBarChartSeries(this);
break;
}
Tero Ahola
Fixed line series usage in the test app
r65 case QChartSeries::SeriesTypeScatter: {
series = new QScatterSeries(this);
break;
}
case QChartSeries::SeriesTypePie: {
series = new QPieSeries(this);
break;
Tero Ahola
Integrated scatter type series...
r42 }
default:
Tero Ahola
Refactored series creation with QChart
r61 Q_ASSERT(false);
Tero Ahola
Integrated scatter type series...
r42 break;
}
Tero Ahola
Fixed line series usage in the test app
r65 addSeries(series);
return series;
Tero Ahola
Integrated scatter type series...
r42 }
Tero Ahola
Resizing of QGraphicItems now possible by resize signal from QChart
r48
Michal Klocek
Add zoom support...
r67 void QChart::setSize(const QSize& size)
Michal Klocek
Adds pimpl to qchart class
r28 {
Michal Klocek
Add zoom support...
r67 m_rect = QRect(QPoint(0,0),size);
QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
Tero Ahola
Refactoring continued: restored ChartItem class
r104 // recalculate title position
if (m_titleItem) {
Michal Klocek
Adds title support
r87 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
Michal Klocek
Add gradient bacground support...
r86 }
Michal Klocek
Add background to chart...
r69
//recalculate background gradient
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 if (m_backgroundItem) {
Michal Klocek
Adds title support
r87 m_backgroundItem->setRect(rect);
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 if (m_bacgroundOrinetation == HorizonatlGradientOrientation)
m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0);
Michal Klocek
Add gradient bacground support...
r86 else
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height());
Michal Klocek
Adds title support
r87 m_backgroundItem->setBrush(m_backgroundGradient);
Michal Klocek
Add gradient bacground support...
r86 }
Michal Klocek
Add background to chart...
r69
Tero Ahola
Refactoring continued: restored ChartItem class
r104 // resize and reposition childs
foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) {
QGraphicsItem *item = ctrl->graphicsItem();
if (item)
item->setPos(rect.topLeft());
ctrl->setSize(rect.size());
Michal Klocek
Add zoom support...
r67 }
Tero Ahola
Resizing of QGraphicItems now possible by resize signal from QChart
r48
Michal Klocek
Refactor current draft to fit int current design specs...
r21 update();
Michal Klocek
adds missing files form previous commit
r12 }
Michal Klocek
Add gradient bacground support...
r86 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
Michal Klocek
Add background to chart...
r69 {
Michal Klocek
Add gradient bacground support...
r86
Michal Klocek
Adds title support
r87 if(!m_backgroundItem){
m_backgroundItem = new QGraphicsRectItem(this);
m_backgroundItem->setZValue(-1);
Michal Klocek
Add gradient bacground support...
r86 }
m_bacgroundOrinetation = orientation;
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 m_backgroundGradient.setColorAt(0.0, startColor);
m_backgroundGradient.setColorAt(1.0, endColor);
Michal Klocek
Add gradient bacground support...
r86 m_backgroundGradient.setStart(0,0);
if(orientation == VerticalGradientOrientation){
m_backgroundGradient.setFinalStop(0,m_rect.height());
}else{
m_backgroundGradient.setFinalStop(m_rect.width(),0);
}
Michal Klocek
Adds title support
r87 m_backgroundItem->setBrush(m_backgroundGradient);
m_backgroundItem->setPen(Qt::NoPen);
m_backgroundItem->update();
Michal Klocek
Add background to chart...
r69 }
Michal Klocek
Adds title support
r87 void QChart::setTitle(const QString& title,const QFont& font)
Michal Klocek
Add background to chart...
r69 {
Michal Klocek
Adds title support
r87 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
m_titleItem->setPlainText(title);
m_titleItem->setFont(font);
Michal Klocek
Add background to chart...
r69 }
Michal Klocek
Adds pimpl to qchart class
r28 int QChart::margin() const
{
Michal Klocek
Removes PIMPL for now...
r53 return m_marginSize;
Michal Klocek
Adds pimpl to qchart class
r28 }
Michal Klocek
adds missing files form previous commit
r12 void QChart::setMargin(int margin)
{
Michal Klocek
Removes PIMPL for now...
r53 m_marginSize = margin;
Michal Klocek
adds missing files form previous commit
r12 }
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 void QChart::setTheme(QChart::ChartThemeId theme)
Tero Ahola
Draft implementation for setting color themes for a chart
r64 {
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 if (theme != m_chartTheme->d->m_currentTheme) {
m_chartTheme->d->setTheme(theme);
setBackground(m_chartTheme->d->m_gradientStartColor,
m_chartTheme->d->m_gradientEndColor,
m_bacgroundOrinetation);
Tero Ahola
Refactoring continued: restored ChartItem class
r104 foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces)
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 ctrl->setTheme(m_chartTheme);
update();
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 }
Tero Ahola
Draft implementation for setting color themes for a chart
r64 }
Michal Klocek
Add zoom support...
r67 void QChart::zoomInToRect(const QRect& rectangle)
{
if(!rectangle.isValid()) return;
qreal margin = this->margin();
QRect rect = rectangle.normalized();
rect.translate(-margin, -margin);
PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
Michal Klocek
Small refactor, adds subDomain to plotDomain
r76 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
Michal Klocek
Add zoom support...
r67
m_plotDomainList.resize(m_plotDataIndex + 1);
Michal Klocek
Small refactor, adds subDomain to plotDomain
r76 m_plotDomainList<<domain;
Michal Klocek
Add zoom support...
r67 m_plotDataIndex++;
Tero Ahola
Refactoring continued: restored ChartItem class
r104 foreach (ChartObjectInterface* ctrl, m_chartObjectInterfaces)
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
Michal Klocek
Add zoom support...
r67 update();
}
void QChart::zoomIn()
{
if (m_plotDataIndex < m_plotDomainList.count() - 1) {
m_plotDataIndex++;
Tero Ahola
Refactoring continued: restored ChartItem class
r104 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
Michal Klocek
Add zoom support...
r67 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
update();
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 } else {
Michal Klocek
Add zoom support...
r67 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
rect.setWidth(rect.width()/2);
rect.setHeight(rect.height()/2);
rect.moveCenter(m_rect.center());
zoomInToRect(rect);
}
}
void QChart::zoomOut()
{
if (m_plotDataIndex > 0) {
m_plotDataIndex--;
Tero Ahola
Refactoring continued: restored ChartItem class
r104 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
Michal Klocek
Add zoom support...
r67 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
update();
}
}
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 void QChart::zoomReset()
{
if (m_plotDataIndex > 0) {
m_plotDataIndex = 0;
Tero Ahola
Refactoring continued: restored ChartItem class
r104 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
update();
}
}
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 void QChart::setAxisX(const QChartAxis& axis)
{
Michal Klocek
Adds title support
r87 setAxis(m_axisXItem,axis);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 }
void QChart::setAxisY(const QChartAxis& axis)
{
Michal Klocek
Adds title support
r87 setAxis(m_axisYItem.at(0),axis);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 }
void QChart::setAxisY(const QList<QChartAxis>& axis)
{
//TODO not implemented
}
void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
{
item->setVisible(axis.isAxisVisible());
}
Tero Ahola
Draft implementation for setting color themes for a chart
r64 #include "moc_qchart.cpp"
Tero Ahola
Resizing of QGraphicItems now possible by resize signal from QChart
r48
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_END_NAMESPACE