##// END OF EJS Templates
Fixes line uder grid issue
Fixes line uder grid issue

File last commit:

r182:0dd3fe4314e9
r190:3ea3ba4a3395
Show More
chartpresenter.cpp
272 lines | 9.2 KiB | text/x-c | CppLexer
/ src / chartpresenter.cpp
Michal Klocek
Refactored for MVP...
r139 #include "qchart.h"
Michal Klocek
Adds refactored axis to presenter
r140 #include "qchartaxis.h"
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "chartpresenter_p.h"
#include "chartdataset_p.h"
Michal Klocek
Refactor themes...
r143 #include "charttheme_p.h"
Michal Klocek
Refactored for MVP...
r139 //series
#include "barchartseries.h"
#include "stackedbarchartseries.h"
#include "percentbarchartseries.h"
Michal Klocek
Fix previous broken commit
r145 #include "qlinechartseries.h"
Jani Honkonen
Pie chart refactoring
r142 #include "qpieseries.h"
Tero Ahola
Integrated scatter again. Missing functionality....
r158 #include "qscatterseries.h"
Michal Klocek
Refactored for MVP...
r139 //items
Michal Klocek
Adds refactored axis to presenter
r140 #include "axisitem_p.h"
Michal Klocek
Refactored for MVP...
r139 #include "bargroup.h"
#include "stackedbargroup.h"
Michal Klocek
Fix previous broken commit
r145 #include "linechartitem_p.h"
Michal Klocek
Refactored for MVP...
r139 #include "percentbargroup.h"
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "linechartanimationitem_p.h"
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 #include "piepresenter.h"
Tero Ahola
Integrated scatter again. Missing functionality....
r158 #include "scatterpresenter.h"
Michal Klocek
Refactors qchart , adds line animation...
r131
QTCOMMERCIALCHART_BEGIN_NAMESPACE
ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
m_chart(chart),
m_dataset(dataset),
Michal Klocek
Refactor themes...
r143 m_chartTheme(0),
Michal Klocek
Adds more axis handling...
r176 m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)),
m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)),
Michal Klocek
Refactored for MVP...
r139 m_domainIndex(0),
m_marginSize(0),
Michal Klocek
Refactors qchart , adds line animation...
r131 m_rect(QRectF(QPoint(0,0),m_chart->size()))
{
Michal Klocek
Adds missing ids to theme classes
r153 setChartTheme(QChart::ChartThemeDefault);
Michal Klocek
Adds refactored axis to presenter
r140 createConnections();
Michal Klocek
Refactors qchart , adds line animation...
r131 }
ChartPresenter::~ChartPresenter()
{
}
Michal Klocek
Adds refactored axis to presenter
r140 void ChartPresenter::createConnections()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
Michal Klocek
Adds more axis handling...
r176 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&)));
QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&)));
Michal Klocek
Refactors qchart , adds line animation...
r131 }
void ChartPresenter::handleGeometryChanged()
{
m_rect = QRectF(QPoint(0,0),m_chart->size());
Michal Klocek
Refactored for MVP...
r139 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
Michal Klocek
Fix test application to have valid window size
r147 Q_ASSERT(m_rect.isValid());
Michal Klocek
Refactored for MVP...
r139 emit geometryChanged(m_rect);
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactored for MVP...
r139 int ChartPresenter::margin() const
{
return m_marginSize;
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactored for MVP...
r139 void ChartPresenter::setMargin(int margin)
{
m_marginSize = margin;
Michal Klocek
Refactors qchart , adds line animation...
r131 }
void ChartPresenter::handleSeriesAdded(QChartSeries* series)
{
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 qDebug() << " ChartPresenter::handleSeriesAdded";
Michal Klocek
Refactors qchart , adds line animation...
r131 switch(series->type())
{
case QChartSeries::SeriesTypeLine: {
Michal Klocek
Fix previous broken commit
r145 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart);
Michal Klocek
Refactor themes...
r143 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
Michal Klocek
Refactored for MVP...
r139 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
m_chartItems.insert(series,item);
break;
}
case QChartSeries::SeriesTypeBar: {
BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
sauimone
removed barchartseriesbase. functionality is now in model
r172 BarGroup* item = new BarGroup(barSeries->model(),m_chart);
Michal Klocek
Refactor themes...
r143 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
Michal Klocek
Refactored for MVP...
r139 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
Michal Klocek
Refactors qchart , adds line animation...
r131 m_chartItems.insert(series,item);
Michal Klocek
Refactored for MVP...
r139 // m_axisXItem->setVisible(false);
Michal Klocek
Refactors qchart , adds line animation...
r131 break;
}
Michal Klocek
Refactored for MVP...
r139 case QChartSeries::SeriesTypeStackedBar: {
StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
sauimone
removed barchartseriesbase. functionality is now in model
r172 StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart);
Michal Klocek
Refactor themes...
r143 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
Michal Klocek
Refactored for MVP...
r139 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
m_chartItems.insert(series,item);
break;
}
case QChartSeries::SeriesTypePercentBar: {
PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
sauimone
removed barchartseriesbase. functionality is now in model
r172 PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart);
Michal Klocek
Refactor themes...
r143 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
Michal Klocek
Refactored for MVP...
r139 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
m_chartItems.insert(series,item);
break;
Michal Klocek
Adds refactored axis to presenter
r140 }
Tero Ahola
Integrated scatter again. Missing functionality....
r158 case QChartSeries::SeriesTypeScatter: {
QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)),
scatterPresenter, SLOT(handleDomainChanged(const Domain&)));
Tero Ahola
Enabled theme colors in scatter again
r182 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
Tero Ahola
Integrated scatter again. Missing functionality....
r158 // scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
// scatterSeries->d->setParentItem(this);
// scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
m_chartItems.insert(scatterSeries, scatterPresenter);
break;
}
Jani Honkonen
Pie chart refactoring
r142 case QChartSeries::SeriesTypePie: {
Jani Honkonen
Make pie work better with chartwidgettest
r163 QPieSeries *s = qobject_cast<QPieSeries *>(series);
PiePresenter* pie = new PiePresenter(m_chart, s);
Jani Honkonen
Drafting pie theme stuff
r166 m_chartTheme->decorate(pie, s, m_chartItems.count());
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&)));
m_chartItems.insert(series, pie);
Jani Honkonen
Pie chart refactoring
r142 break;
}
Michal Klocek
Refactors qchart , adds line animation...
r131 default: {
Michal Klocek
Refactored for MVP...
r139 qDebug()<< "Series type" << series->type() << "not implemented.";
break;
Michal Klocek
Refactors qchart , adds line animation...
r131 }
}
Michal Klocek
Adds default gemoetry change call in case of new series
r148
if(m_rect.isValid()) emit geometryChanged(m_rect);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
void ChartPresenter::handleSeriesChanged(QChartSeries* series)
{
Michal Klocek
Adds refactored axis to presenter
r140 //TODO:
Michal Klocek
Refactored for MVP...
r139 }
void ChartPresenter::zoomInToRect(const QRectF& rect)
{
if(!rect.isValid()) return;
QRectF r = rect.normalized();
r.translate(-m_marginSize, -m_marginSize);
Michal Klocek
Bugfix for wrong rubberband rect size
r151 Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height()));
Michal Klocek
Refactored for MVP...
r139 m_dataset->addDomain(domain);
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactored for MVP...
r139 void ChartPresenter::zoomIn()
{
if (!m_dataset->nextDomain()) {
QRectF rect = m_rect;
rect.setWidth(rect.width()/2);
rect.setHeight(rect.height()/2);
rect.moveCenter(m_rect.center());
Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height()));
m_dataset->addDomain(domain);
}
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactored for MVP...
r139 void ChartPresenter::zoomOut()
{
m_dataset->previousDomain();
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Refactored for MVP...
r139 void ChartPresenter::zoomReset()
{
m_dataset->clearDomains();
}
Michal Klocek
Adds missing ids to theme classes
r153 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
Michal Klocek
Refactor themes...
r143 {
delete m_chartTheme;
m_chartTheme = ChartTheme::createTheme(theme);
m_chartTheme->decorate(m_chart);
QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems);
int index=0;
while (i.hasNext()) {
i.next();
index++;
m_chartTheme->decorate(i.value(),i.key(),index);
}
Michal Klocek
Adds more axis handling...
r176 m_chartTheme->decorate(m_axisX, m_axisXItem);
m_chartTheme->decorate(m_axisY, m_axisYItem);
}
Michal Klocek
Refactor themes...
r143
Michal Klocek
Adds missing ids to theme classes
r153 QChart::ChartTheme ChartPresenter::chartTheme()
Michal Klocek
Refactor themes...
r143 {
Michal Klocek
Adds missing ids to theme classes
r153 return m_chartTheme->id();
}
Michal Klocek
Adds more axis handling...
r176 void ChartPresenter::setDefaultAxisX(const QChartAxis& axis)
Michal Klocek
Adds missing ids to theme classes
r153 {
Michal Klocek
Adds more axis handling...
r176 //if(m_axisX != axis) {
m_axisX = axis;
m_axisXItem->handleAxisChanged(m_axisX);
//}
Michal Klocek
Add public function for axis hadnling to qchart
r155 }
Michal Klocek
Adds missing ids to theme classes
r153
Michal Klocek
Adds more axis handling...
r176 void ChartPresenter::setDefaultAxisY(const QChartAxis& axis)
Michal Klocek
Add public function for axis hadnling to qchart
r155 {
Michal Klocek
Adds more axis handling...
r176 // if(m_axisY != axis) {
m_axisY = axis;
m_axisYItem->handleAxisChanged(m_axisY);
//}
Michal Klocek
Add public function for axis hadnling to qchart
r155 }
Michal Klocek
Adds more axis handling...
r176 QChartAxis ChartPresenter::defaultAxisX() const
Michal Klocek
Add public function for axis hadnling to qchart
r155 {
Michal Klocek
Adds more axis handling...
r176 return m_axisX;
Michal Klocek
Adds missing ids to theme classes
r153 }
Michal Klocek
Adds more axis handling...
r176 QChartAxis ChartPresenter::defaultAxisY() const
Michal Klocek
Adds missing ids to theme classes
r153 {
Michal Klocek
Adds more axis handling...
r176 return m_axisY;
}
Michal Klocek
Add public function for axis hadnling to qchart
r155
Michal Klocek
Adds more axis handling...
r176 QChartAxis ChartPresenter::axisY(int id) const
{
return m_axis.value(id);
Michal Klocek
Add public function for axis hadnling to qchart
r155 }
Michal Klocek
Adds missing ids to theme classes
r153
Michal Klocek
Adds more axis handling...
r176 int ChartPresenter::addAxisY(const QChartAxis& axis)
Michal Klocek
Add public function for axis hadnling to qchart
r155 {
Michal Klocek
Adds more axis handling...
r176 int key =0 ;
while(m_axis.contains(key)){
key++;
//TODO overflow
Michal Klocek
Add public function for axis hadnling to qchart
r155 }
Michal Klocek
Adds more axis handling...
r176
m_axis.insert(key,axis);
m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart));
return key;
}
void ChartPresenter::removeAxisY(int id)
{
m_axis.remove(id);
delete m_axisItems.take(id);
Michal Klocek
Refactor themes...
r143 }
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "moc_chartpresenter_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE