##// END OF EJS Templates
Remove obsolete setBackgroundColor form QChart
Remove obsolete setBackgroundColor form QChart

File last commit:

r137:c3223f1ab305
r137:c3223f1ab305
Show More
qchart.cpp
425 lines | 12.1 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
One more alternative for changing themes
r108 #include "chartitem_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"
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "chartpresenter_p.h"
#include "chartdataset_p.h"
Tero Ahola
Integrated scatter type series...
r42 #include <QGraphicsScene>
Michal Klocek
Adds layout support for charts....
r115 #include <QGraphicsSceneResizeEvent>
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
Michal Klocek
Adds layout support for charts....
r115 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
Michal Klocek
Adds title support
r87 m_backgroundItem(0),
m_titleItem(0),
Tero Ahola
Refactored the test app
r110 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),
Michal Klocek
Refactors qchart , adds line animation...
r131 m_chartTheme(new ChartTheme(this)),
Michal Klocek
block presenter code for now
r135 m_dataset(0),
//m_dataset(new ChartDataSet(this)),
m_presenter(0)
//m_presenter(new ChartPresenter(this,m_dataset))
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
One more alternative for changing themes
r108 m_chartItems << m_axisXItem;
m_chartItems << 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 void QChart::addSeries(QChartSeries* series)
Michal Klocek
adds missing files form previous commit
r12 {
Michal Klocek
Refactors qchart , adds line animation...
r131 if(m_dataset) {
m_dataset->addSeries(series);
return;
}
Tero Ahola
Proof-of-concept for QML api...
r120 Q_ASSERT(series);
Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid);
Michal Klocek
Changes reinterpret_cast to static_cast
r45
Michal Klocek
Refactors qchart , adds line animation...
r131 // TODO: we should check the series not already added
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
Tero Ahola
Scaling for scatter series
r111 m_plotDataIndex = 0 ;
m_plotDomainList.resize(1);
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
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);
Tero Ahola
One more alternative for changing themes
r108 for (int i = 0 ; i < xyseries->count() ; i++) {
Michal Klocek
Removes hardcoded values for xydomain
r47 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);
}
Michal Klocek
Refactors qchart , adds line animation...
r131 //XYLineChartItem* item = new XYLineChartItem(xyseries,0,this);
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactors qchart , adds line animation...
r131 //m_chartItems << item;
Tero Ahola
One more alternative for changing themes
r108 // TODO:
//m_chartTheme->addObserver(xyseries);
Michal Klocek
Add zoom support...
r67
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
One more alternative for changing themes
r108 m_chartItems << barGroup;
sauimone
Added bar chart example
r78 childItems().append(barGroup);
sauimone
domain applied to barcharts. x-axis domain doesn't make sense in this case
r107
qreal x = barSeries->countColumns();
qreal y = barSeries->max();
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);
sauimone
prototyping separators with stacked bars
r119 m_axisXItem->setVisible(false);
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
One more alternative for changing themes
r108 m_chartItems << stackedBarGroup;
sauimone
added example for stacked bar chart.
r95 childItems().append(stackedBarGroup);
sauimone
domain applied to barcharts. x-axis domain doesn't make sense in this case
r107
qreal x = stackedBarSeries->countColumns();
qreal y = stackedBarSeries->maxColumnSum();
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);
sauimone
prototyping separators with stacked bars
r119 m_axisXItem->setVisible(false);
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
One more alternative for changing themes
r108 m_chartItems << percentBarGroup;
sauimone
percent bar chart
r101 childItems().append(percentBarGroup);
sauimone
domain applied to barcharts. x-axis domain doesn't make sense in this case
r107
qreal x = percentBarSeries->countColumns();
domain.m_minX = qMin(domain.m_minX,x);
domain.m_minY = 0;
domain.m_maxX = qMax(domain.m_maxX,x);
domain.m_maxY = 100;
sauimone
prototyping separators with stacked bars
r119 m_axisXItem->setVisible(false);
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
One more alternative for changing themes
r108 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
Scaling for scatter series
r111 scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
Tero Ahola
One more alternative for changing themes
r108 m_chartItems << scatterSeries->d;
m_chartTheme->addObserver(scatterSeries->d);
Tero Ahola
Scaling for scatter series
r111
foreach (qreal x, scatterSeries->d->m_x) {
domain.m_minX = qMin(domain.m_minX, x);
domain.m_maxX = qMax(domain.m_maxX, x);
}
foreach (qreal y, scatterSeries->d->m_y) {
domain.m_minY = qMin(domain.m_minY, y);
domain.m_maxY = qMax(domain.m_maxY, y);
}
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
One more alternative for changing themes
r108 pieSeries->d->setParentItem(this);
m_chartItems << pieSeries->d;
pieSeries->d->m_chartTheme = m_chartTheme;
m_chartTheme->addObserver(pieSeries->d);
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
Proof-of-concept for QML api...
r120 default:
break;
Tero Ahola
Fixed line series usage in the test app
r65 }
Tero Ahola
One more alternative for changing themes
r108
// Update all the items to match the new visible area of the chart
foreach(ChartItem* i, m_chartItems)
i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
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
Change background gradient to use ObjectBoundingMode...
r122 void QChart::setChartBackgroundBrush(const QBrush& brush)
{
if(!m_backgroundItem){
m_backgroundItem = new QGraphicsRectItem(this);
m_backgroundItem->setZValue(-1);
}
m_backgroundItem->setBrush(brush);
m_backgroundItem->update();
}
void QChart::setChartBackgroundPen(const QPen& pen)
{
if(!m_backgroundItem){
m_backgroundItem = new QGraphicsRectItem(this);
m_backgroundItem->setZValue(-1);
}
m_backgroundItem->setPen(pen);
m_backgroundItem->update();
}
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
One more alternative for changing themes
r108 m_chartTheme->setTheme(theme);
Michal Klocek
Remove obsolete setBackgroundColor form QChart
r137
QLinearGradient backgroundGradient;
backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor);
backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor);
backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
setChartBackgroundBrush(backgroundGradient);
Tero Ahola
One more alternative for changing themes
r108
// TODO: Move the controlling of the series presentations into private implementation of the
// series instead of QChart controlling themes for each
// In other words, the following should be used when creating xy series:
// m_chartTheme->addObserver(xyseries)
foreach (QChartSeries *series, m_chartSeries) {
if (series->type() == QChartSeries::SeriesTypeLine) {
QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series);
SeriesTheme seriesTheme = m_chartTheme->themeForSeries();
xyseries->setPen(seriesTheme.linePen);
}
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 }
Tero Ahola
One more alternative for changing themes
r108
update();
Tero Ahola
Draft implementation for setting color themes for a chart
r64 }
Tero Ahola
Proof-of-concept for QML api...
r120 QChart::ChartThemeId QChart::theme()
{
return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme;
}
Michal Klocek
Adds layout support for charts....
r115 void QChart::zoomInToRect(const QRectF& rectangle)
Michal Klocek
Add zoom support...
r67 {
if(!rectangle.isValid()) return;
qreal margin = this->margin();
Michal Klocek
Adds layout support for charts....
r115 QRectF rect = rectangle.normalized();
Michal Klocek
Add zoom support...
r67 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
One more alternative for changing themes
r108 foreach (ChartItem* item, m_chartItems)
item->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
One more alternative for changing themes
r108 foreach (ChartItem* item, m_chartItems)
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
Adds layout support for charts....
r115 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
Michal Klocek
Add zoom support...
r67 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
One more alternative for changing themes
r108 foreach (ChartItem* item, m_chartItems)
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
One more alternative for changing themes
r108 foreach (ChartItem* item, m_chartItems)
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());
}
Michal Klocek
Adds layout support for charts....
r115 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
{
m_rect = QRectF(QPoint(0,0),event->newSize());
QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
// recalculate title position
if (m_titleItem) {
QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
}
//recalculate background gradient
if (m_backgroundItem) {
m_backgroundItem->setRect(rect);
}
// resize and reposition childs
foreach (ChartItem *item, m_chartItems) {
item->setPos(rect.topLeft());
item->setSize(rect.size());
}
Michal Klocek
Removes obsolate methods from qchart
r117 QGraphicsWidget::resizeEvent(event);
Michal Klocek
Adds layout support for charts....
r115 update();
}
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