##// END OF EJS Templates
typos in docs
typos in docs

File last commit:

r421:fe0a0dc06876
r424:97360b2df7f1
Show More
chartpresenter.cpp
300 lines | 10.3 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
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 #include "qbarseries.h"
#include "qstackedbarseries.h"
#include "qpercentbarseries.h"
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 #include "qlineseries.h"
Michal Klocek
Adds area chart...
r421 #include "qareaseries.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
Adds animation settings handling
r298 #include "axisanimationitem_p.h"
Michal Klocek
Adds area chart...
r421 #include "areachartitem_p.h"
sauimone
added _p to private class headers
r381 #include "barpresenter_p.h"
#include "stackedbarpresenter_p.h"
#include "percentbarpresenter_p.h"
Michal Klocek
Fix previous broken commit
r145 #include "linechartitem_p.h"
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "linechartanimationitem_p.h"
Jani Honkonen
Add _p to pie internal headers
r353 #include "piepresenter_p.h"
Tero Ahola
Moved scatter impl into a subfolder
r194 #include "scatterpresenter_p.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
Refactored for MVP...
r139 m_marginSize(0),
Michal Klocek
Adds animation settings handling
r298 m_rect(QRectF(QPoint(0,0),m_chart->size())),
m_options(0)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactors axis handling...
r223 createConnections();
Michal Klocek
Adds missing ids to theme classes
r153 setChartTheme(QChart::ChartThemeDefault);
Michal Klocek
Refactors axis handling...
r223
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()));
Michal Klocek
Rename QChartSeries to QSeries
r360 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*)));
QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
Michal Klocek
Refactors axis handling...
r223 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
Michal Klocek
Rename QChartSeries to QSeries
r360 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&)));
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&)));
Michal Klocek
Refactors axis handling...
r223 }
QRectF ChartPresenter::geometry() const
{
return m_rect;
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 }
Michal Klocek
Refactors axis handling...
r223 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
{
Michal Klocek
Adds animation settings handling
r298
Michal Klocek
Refactors axis handling...
r223 AxisItem* item ;
Michal Klocek
Adds animation settings handling
r298 if(!m_options.testFlag(QChart::GridAxisAnimations))
{
item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
Michal Klocek
Refactors axis handling...
r223 }else{
Michal Klocek
Adds animation settings handling
r298 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Adds animation settings handling
r298
Michal Klocek
Refactors axis handling...
r223 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
Michal Klocek
Bugfix no geometry call when axis removed and added again
r259
item->handleAxisUpdate(axis);
item->handleGeometryChanged(m_rect);
Michal Klocek
Refactors axis handling...
r223 m_chartTheme->decorate(axis,item);
m_axisItems.insert(axis,item);
}
void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
{
AxisItem* item = m_axisItems.take(axis);
Q_ASSERT(item);
delete item;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 void ChartPresenter::handleSeriesAdded(QSeries* series)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
switch(series->type())
{
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeLine: {
Michal Klocek
Adds area chart...
r421
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
Michal Klocek
Adds animation settings handling
r298 LineChartItem* item;
if(m_options.testFlag(QChart::SeriesAnimations)){
item = new LineChartAnimationItem(this,lineSeries,m_chart);
}else{
item = new LineChartItem(this,lineSeries,m_chart);
}
Michal Klocek
Refactor themes...
r143 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
Michal Klocek
Refactored for MVP...
r139 m_chartItems.insert(series,item);
Michal Klocek
Rewrite animation hadnling in line series...
r389 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
Michal Klocek
Adds area chart...
r421 break;
}
case QSeries::SeriesTypeArea: {
QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
AreaChartItem* item;
if(m_options.testFlag(QChart::SeriesAnimations)) {
item = new AreaChartItem(this,areaSeries,m_chart);
}
else {
item = new AreaChartItem(this,areaSeries,m_chart);
}
m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
m_chartItems.insert(series,item);
if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
Michal Klocek
Refactored for MVP...
r139 break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeBar: {
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
sauimone
moved tooltip to presenter
r288 BarPresenter* item = new BarPresenter(barSeries,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(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
Rewrite animation hadnling in line series...
r389 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
Michal Klocek
Refactors qchart , adds line animation...
r131 break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeStackedBar: {
Michal Klocek
Refactored for MVP...
r139
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
sauimone
moved tooltip to presenter
r288 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,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(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
m_chartItems.insert(series,item);
Michal Klocek
Rewrite animation hadnling in line series...
r389 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
Michal Klocek
Refactored for MVP...
r139 break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypePercentBar: {
Michal Klocek
Refactored for MVP...
r139
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
sauimone
moved tooltip to presenter
r288 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,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(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
m_chartItems.insert(series,item);
Michal Klocek
Rewrite animation hadnling in line series...
r389 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
Michal Klocek
Refactored for MVP...
r139 break;
Michal Klocek
Adds refactored axis to presenter
r140 }
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::SeriesTypeScatter: {
Tero Ahola
Integrated scatter again. Missing functionality....
r158 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)),
scatterSeries, SIGNAL(clicked(QPointF)));
Tero Ahola
Integrated scatter again. Missing functionality....
r158 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
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 m_chartItems.insert(scatterSeries, scatterPresenter);
Michal Klocek
Rewrite animation hadnling in line series...
r389 if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect);
Tero Ahola
Integrated scatter again. Missing functionality....
r158 break;
}
Michal Klocek
Rename QChartSeries to QSeries
r360 case QSeries::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&)));
Jani Honkonen
Clear background when there is only pie chart.
r293
// Hide all from background when there is only piechart
// TODO: refactor this ugly code... should be one setting for this
if (m_chartItems.count() == 0) {
m_chart->axisX()->setAxisVisible(false);
m_chart->axisY()->setAxisVisible(false);
m_chart->axisX()->setGridVisible(false);
m_chart->axisY()->setGridVisible(false);
m_chart->axisX()->setLabelsVisible(false);
m_chart->axisY()->setLabelsVisible(false);
m_chart->axisX()->setShadesVisible(false);
m_chart->axisY()->setShadesVisible(false);
m_chart->setChartBackgroundBrush(Qt::transparent);
}
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 m_chartItems.insert(series, pie);
Michal Klocek
Rewrite animation hadnling in line series...
r389 pie->handleGeometryChanged(m_rect);
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
Rename QChartSeries to QSeries
r360 void ChartPresenter::handleSeriesRemoved(QSeries* series)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactors axis handling...
r223 ChartItem* item = m_chartItems.take(series);
delete item;
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Rename QChartSeries to QSeries
r360 void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactors axis handling...
r223 m_chartItems.value(series)->handleDomainChanged(domain);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 m_axisItems.value(axis)->handleRangeChanged(axis,labels);
Michal Klocek
Refactored for MVP...
r139 }
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);
Michal Klocek
Rename QChartSeries to QSeries
r360 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
Michal Klocek
Refactor themes...
r143
int index=0;
while (i.hasNext()) {
i.next();
m_chartTheme->decorate(i.value(),i.key(),index);
Tero Ahola
Fixed bug in setting chart theme...
r312 index++;
Michal Klocek
Refactor themes...
r143 }
Michal Klocek
Refactors axis handling...
r223 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
while (j.hasNext()) {
j.next();
m_chartTheme->decorate(j.key(),j.value());
}
Michal Klocek
Adds more axis handling...
r176 }
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 animation settings handling
r298 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
{
if(m_options!=options) {
m_options=options;
//recreate elements
QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
Michal Klocek
Rename QChartSeries to QSeries
r360 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
Michal Klocek
Adds animation settings handling
r298
foreach(QChartAxis* axis, axisList) {
handleAxisRemoved(axis);
handleAxisAdded(axis);
}
Michal Klocek
Rename QChartSeries to QSeries
r360 foreach(QSeries* series, seriesList) {
Michal Klocek
Adds animation settings handling
r298 handleSeriesRemoved(series);
handleSeriesAdded(series);
}
//now reintialize view data
//TODO: make it more nice
m_dataset->setDomain(m_dataset->domainIndex());
}
}
QChart::AnimationOptions ChartPresenter::animationOptions() const
{
return m_options;
}
Michal Klocek
Refactor themes...
r143
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "moc_chartpresenter_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE