##// END OF EJS Templates
Fixed a bug with last two control points calculation
Fixed a bug with last two control points calculation

File last commit:

r428:acd7ae840ecc
r429:cbe57d7d97d6
Show More
chartdataset.cpp
448 lines | 12.4 KiB | text/x-c | CppLexer
/ src / chartdataset.cpp
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "chartdataset_p.h"
Michal Klocek
Refactors axis handling...
r223 #include "qchartaxis.h"
Michal Klocek
Refactored for MVP...
r139 //series
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 #include "qlineseries.h"
Michal Klocek
Adds area chart...
r421 #include "qareaseries.h"
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 #include "qbarseries.h"
#include "qstackedbarseries.h"
#include "qpercentbarseries.h"
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 #include "qpieseries.h"
Tero Ahola
Integrated scatter again. Missing functionality....
r158 #include "qscatterseries.h"
Marek Rosa
Spline working somewhat
r401 #include "qsplineseries.h"
Michal Klocek
Refactors qchart , adds line animation...
r131
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors axis handling...
r223 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
Marek Rosa
Spline working somewhat
r401 m_axisX(new QChartAxis(this)),
m_axisY(new QChartAxis(this)),
m_domainIndex(0),
m_axisXInitialized(false)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
}
ChartDataSet::~ChartDataSet()
{
// TODO Auto-generated destructor stub
}
Michal Klocek
Refactors axis handling...
r223 const Domain ChartDataSet::domain(QChartAxis *axisY) const
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Marek Rosa
Spline working somewhat
r401 int i = m_domainMap.count(axisY);
if(i == 0){
return Domain();
}
i = i - m_domainIndex -1;
Michal Klocek
Refactors axis handling...
r223 return m_domainMap.values(axisY).at(i);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Rename QChartSeries to QSeries
r360 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactored for MVP...
r139 // TODO: we should check the series not already added
Michal Klocek
minor. formating
r420 series->setParent(this);// take ownership
Michal Klocek
Refactors axis handling...
r223 clearDomains();
if(axisY==0) axisY = m_axisY;
Michal Klocek
minor. formating
r420 axisY->setParent(this);// take ownership
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
minor. formating
r420 QList<QSeries*> seriesList = m_seriesMap.values(axisY);
Michal Klocek
Refactors axis handling...
r223
QList<Domain> domainList = m_domainMap.values(axisY);
Q_ASSERT(domainList.size()<=1);
Domain domain;
if(domainList.size()>0) domain = domainList.at(0);
Michal Klocek
Refactored for MVP...
r139
switch(series->type())
{
Marek Rosa
Marge spline
r418 case QSeries::SeriesTypeLine: {
Marek Rosa
Spline working somewhat
r401
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
Marek Rosa
Spline working somewhat
r401
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 for (int i = 0; i < lineSeries->count(); i++)
Marek Rosa
Spline working somewhat
r401 {
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 qreal x = lineSeries->x(i);
qreal y = lineSeries->y(i);
Michal Klocek
Refactored for MVP...
r139 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);
}
Marek Rosa
Spline working somewhat
r401 break;
}
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 case QSeries::SeriesTypeArea: {
Michal Klocek
Adds area chart...
r421
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
Michal Klocek
Adds area chart...
r421
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 QLineSeries* upperSeries = areaSeries->upperSeries();
QLineSeries* lowerSeries = areaSeries->lowerSeries();
Michal Klocek
Adds area chart...
r421
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 for (int i = 0; i < upperSeries->count(); i++)
{
qreal x = upperSeries->x(i);
qreal y = upperSeries->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);
}
if(lowerSeries){
Michal Klocek
Adds area chart...
r421 for (int i = 0; i < lowerSeries->count(); i++)
{
qreal x = lowerSeries->x(i);
qreal y = lowerSeries->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);
}}
Marek Rosa
Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts...
r426 break;
}
case QSeries::SeriesTypeBar: {
qDebug() << "QChartSeries::SeriesTypeBar";
QBarSeries* barSeries = static_cast<QBarSeries*>(series);
qreal x = barSeries->categoryCount();
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);
break;
}
Marek Rosa
Marge spline
r418 case QSeries::SeriesTypeStackedBar: {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 qDebug() << "QChartSeries::SeriesTypeStackedBar";
Michal Klocek
Refactored for MVP...
r139
Marek Rosa
Marge spline
r418 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
qreal x = stackedBarSeries->categoryCount();
Marek Rosa
Spline working somewhat
r401 qreal y = stackedBarSeries->maxCategorySum();
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);
break;
}
Marek Rosa
Marge spline
r418 case QSeries::SeriesTypePercentBar: {
sauimone
fixed bug in category implementation. model now owns the category and sets
r173 qDebug() << "QChartSeries::SeriesTypePercentBar";
Michal Klocek
Refactored for MVP...
r139
Marek Rosa
Marge spline
r418 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
qreal x = percentBarSeries->categoryCount();
Marek Rosa
Spline working somewhat
r401 domain.m_minX = qMin(domain.m_minX,x);
domain.m_minY = 0;
domain.m_maxX = qMax(domain.m_maxX,x);
domain.m_maxY = 100;
break;
}
Michal Klocek
Refactored for MVP...
r139
Marek Rosa
Marge spline
r418 case QSeries::SeriesTypePie: {
Marek Rosa
Spline working somewhat
r401 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
// TODO: domain stuff
break;
}
Jani Honkonen
Pie chart refactoring
r142
Marek Rosa
Marge spline
r418 case QSeries::SeriesTypeScatter: {
Marek Rosa
Spline working somewhat
r401 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
Q_ASSERT(scatterSeries);
foreach (QPointF point, scatterSeries->data()) {
domain.m_minX = qMin(domain.m_minX, point.x());
domain.m_maxX = qMax(domain.m_maxX, point.x());
domain.m_minY = qMin(domain.m_minY, point.y());
domain.m_maxY = qMax(domain.m_maxY, point.y());
Tero Ahola
Integrated scatter again. Missing functionality....
r158 }
Marek Rosa
Spline working somewhat
r401 break;
}
Tero Ahola
Integrated scatter again. Missing functionality....
r158
Marek Rosa
Spline with problems
r419 case QSeries::SeriesTypeSpline: {
Marek Rosa
Spline working somewhat
r401 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
for (int i = 0; i < splineSeries->count(); i++)
{
Marek Rosa
Spline with problems
r419 qreal x = splineSeries->x(i);
qreal y = splineSeries->y(i);
Marek Rosa
Spline working somewhat
r401 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
Refactored for MVP...
r139 }
Marek Rosa
Spline working somewhat
r401 break;
}
default: {
qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
return;
break;
}
Michal Klocek
Refactored for MVP...
r139
}
Michal Klocek
Refactors axis handling...
r223 if(!m_domainMap.contains(axisY))
{
emit axisAdded(axisY);
Michal Klocek
Adds axis setRange implementation
r400 QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
Michal Klocek
Refactors axis handling...
r223 QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
}
if(!m_axisXInitialized)
{
emit axisAdded(axisX());
Michal Klocek
Adds axis setRange implementation
r400 QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
Michal Klocek
Refactors axis handling...
r223 QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
m_axisXInitialized=true;
}
Michal Klocek
Adds axis setRange implementation
r400 m_domainMap.replace(axisY,domain);
m_seriesMap.insert(axisY,series);
Michal Klocek
Rewrite animation hadnling in line series...
r389 emit seriesAdded(series);
Michal Klocek
Fix unit test
r411 setDomain(m_domainIndex,axisY);
Michal Klocek
Refactors axis handling...
r223
}
Michal Klocek
Rename QChartSeries to QSeries
r360 void ChartDataSet::removeSeries(QSeries* series)
Michal Klocek
Refactors axis handling...
r223 {
QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
foreach(QChartAxis* axis , keys) {
Michal Klocek
minor. formating
r420 if(m_seriesMap.contains(axis,series)) {
Michal Klocek
Refactors axis handling...
r223 emit seriesRemoved(series);
m_seriesMap.remove(axis,series);
//remove axis if no longer there
Michal Klocek
minor. formating
r420 if(!m_seriesMap.contains(axis)) {
Michal Klocek
Refactors axis handling...
r223 emit axisRemoved(axis);
m_domainMap.remove(axis);
Michal Klocek
Adds RemoveAllSeries method to API
r258 if(axis != m_axisY)
Marek Rosa
Spline working somewhat
r401 delete axis;
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Adds RemoveAllSeries method to API
r258 series->setParent(0);
Michal Klocek
Refactors axis handling...
r223 break;
}
}
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Adds RemoveAllSeries method to API
r258 void ChartDataSet::removeAllSeries()
{
QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
foreach(QChartAxis* axis , keys) {
Michal Klocek
Rename QChartSeries to QSeries
r360 QList<QSeries*> seriesList = m_seriesMap.values(axis);
Michal Klocek
minor. formating
r420 for(int i =0; i < seriesList.size();i++ )
Michal Klocek
Adds RemoveAllSeries method to API
r258 {
emit seriesRemoved(seriesList.at(i));
delete(seriesList.at(i));
}
m_seriesMap.remove(axis);
m_domainMap.remove(axis);
emit axisRemoved(axis);
if(axis != m_axisY) delete axis;
Marek Rosa
Spline working somewhat
r401 }
Michal Klocek
Adds RemoveAllSeries method to API
r258 m_domainIndex=0;
}
Michal Klocek
Refactored for MVP...
r139 bool ChartDataSet::nextDomain()
{
Michal Klocek
Refactors axis handling...
r223 int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1;
if (m_domainIndex < limit) {
Michal Klocek
Refactored for MVP...
r139 m_domainIndex++;
Michal Klocek
Refactors axis handling...
r223 setDomain(m_domainIndex);
Michal Klocek
Refactored for MVP...
r139 return true;
}
else {
return false;
}
}
bool ChartDataSet::previousDomain()
{
if (m_domainIndex > 0) {
m_domainIndex--;
Michal Klocek
Refactors axis handling...
r223 setDomain(m_domainIndex);
Michal Klocek
Refactored for MVP...
r139 return true;
}
else {
return false;
}
}
Michal Klocek
Refactors axis handling...
r223 void ChartDataSet::setDomain(int index)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactors axis handling...
r223 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
Michal Klocek
Bugfix missing xaxis label update on zoomOut
r265
Michal Klocek
Bugfix: check series count before changing domain
r373 if(domainList.count()==0) return;
Michal Klocek
Bugfix missing xaxis label update on zoomOut
r265 Domain domain;
Michal Klocek
Refactors axis handling...
r223 foreach (QChartAxis* axis , domainList) {
int i = m_domainMap.count(axis) - index -1;
Q_ASSERT(i>=0);
Michal Klocek
Bugfix missing xaxis label update on zoomOut
r265 domain = m_domainMap.values(axis).at(i);
Michal Klocek
Refactors axis handling...
r223 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
Michal Klocek
Rename QChartSeries to QSeries
r360 QList<QSeries*> seriesList = m_seriesMap.values(axis);
foreach(QSeries* series, seriesList) {
Michal Klocek
Refactors axis handling...
r223 emit seriesDomainChanged(series,domain);
}
Michal Klocek
Bugfix updateRange missing
r403 axis->updateRange(domain.m_minY,domain.m_maxY);
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 emit axisRangeChanged(axis,labels);
Michal Klocek
Adds axis setRange implementation
r400
Michal Klocek
Refactors axis handling...
r223 }
QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
Michal Klocek
Bugfix updateRange missing
r403 axisX()->updateRange(domain.m_minX,domain.m_maxY);
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 emit axisRangeChanged(axisX(),labels);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Fix unit test
r411 void ChartDataSet::setDomain(int index,QChartAxis* axis)
{
int i = m_domainMap.count(axis) - index -1;
Q_ASSERT(i>=0);
Domain domain = m_domainMap.values(axis).at(i);
{
Marek Rosa
Marge spline
r418 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
QList<QSeries*> seriesList = m_seriesMap.values(axis);
foreach(QSeries* series, seriesList) {
emit seriesDomainChanged(series,domain);
}
axis->updateRange(domain.m_minY,domain.m_maxY);
emit axisRangeChanged(axis,labels);
Michal Klocek
Fix unit test
r411 }
QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
axisX()->updateRange(domain.m_minX,domain.m_maxY);
emit axisRangeChanged(axisX(),labels);
}
Michal Klocek
Refactors axis handling...
r223 void ChartDataSet::clearDomains(int toIndex)
{
Q_ASSERT(toIndex>=0);
m_domainIndex = toIndex;
QList<QChartAxis*> keys = m_domainMap.uniqueKeys();
foreach (QChartAxis* key , keys)
{
QList<Domain> domains = m_domainMap.values(key);
m_domainMap.remove(key);
int i = domains.size() - toIndex - 1;
Michal Klocek
minor. formating
r420 while(i--) {
Michal Klocek
Refactors axis handling...
r223 domains.removeFirst();
}
Michal Klocek
minor. formating
r420 for(int j=domains.size()-1; j>=0;j--)
Michal Klocek
Refactors axis handling...
r223 m_domainMap.insert(key,domains.at(j));
Michal Klocek
Refactored for MVP...
r139 }
}
Michal Klocek
Refactors axis handling...
r223 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactors axis handling...
r223 Q_ASSERT(rect.isValid());
Q_ASSERT(viewport.isValid());
clearDomains(m_domainIndex);
QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
Michal Klocek
minor. small optimatization in addDomain
r266 Domain domain;
Michal Klocek
minor. formating
r420 foreach (QChartAxis* axis , domainList) {
Michal Klocek
minor. small optimatization in addDomain
r266 domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height());
Michal Klocek
Refactors axis handling...
r223 m_domainMap.insert(axis,domain);
}
Michal Klocek
Adds axis setRange implementation
r400 setDomain(++m_domainIndex);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Rename QChartSeries to QSeries
r360 QChartAxis* ChartDataSet::axisY(QSeries* series) const
Michal Klocek
Refactors axis handling...
r223 {
if(series == 0) return m_axisY;
QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
foreach(QChartAxis* axis , keys) {
Michal Klocek
minor. formating
r420 if(m_seriesMap.contains(axis,series)) {
Michal Klocek
Refactors axis handling...
r223 return axis;
}
}
return 0;
}
QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max)
{
Q_ASSERT(max>=min);
Michal Klocek
Refactored for MVP...
r139
Michal Klocek
Refactors axis handling...
r223 QStringList labels;
Michal Klocek
Bugfix shades not updated aftet tick changed
r241 int ticks = axis->ticksCount()-1;
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
minor. formating
r420 for(int i=0; i<= ticks; i++) {
Michal Klocek
Refactors axis handling...
r223 qreal value = min + (i * (max - min)/ ticks);
QString label = axis->axisTickLabel(value);
Michal Klocek
minor. formating
r420 if(label.isEmpty()) {
Michal Klocek
Refactors axis handling...
r223 labels << QString::number(value);
Michal Klocek
minor. formating
r420 }
else {
Michal Klocek
Refactors axis handling...
r223 labels << label;
}
}
return labels;
}
Michal Klocek
Adds axis setRange implementation
r400 void ChartDataSet::handleRangeChanged(QChartAxis* axis)
Michal Klocek
Refactors axis handling...
r223 {
Michal Klocek
Adds axis setRange implementation
r400 qreal min = axis->min();
qreal max = axis->max();
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Adds axis setRange implementation
r400 if(axis==axisX()) {
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Adds axis setRange implementation
r400 m_domainIndex=0;
clearDomains(m_domainIndex);
QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
foreach (QChartAxis* axis , domainList) {
Q_ASSERT(m_domainMap.values(axis).size()==1);
Domain domain = m_domainMap.value(axis);
domain.m_minX=min;
domain.m_maxX=max;
m_domainMap.replace(axis,domain);
}
Michal Klocek
Fix unit test
r411 setDomain(m_domainIndex);
Michal Klocek
Adds axis setRange implementation
r400 }
else {
QList<Domain> domains = m_domainMap.values(axis);
m_domainMap.remove(axis);
for(int i=0;i<domains.size();i++)
{
domains[i].m_minY=min;
domains[i].m_maxY=max;
}
for(int j=domains.size()-1; j>=0;j--)
Marek Rosa
Marge spline
r418 m_domainMap.insert(axis,domains.at(j));
Michal Klocek
Fix unit test
r411
setDomain(m_domainIndex,axis);
Michal Klocek
Adds axis setRange implementation
r400 }
Michal Klocek
Refactors axis handling...
r223
}
void ChartDataSet::handleTickChanged(QChartAxis* axis)
{
Michal Klocek
minor. formating
r420 if(axis==axisX()) {
Michal Klocek
Adds axis setRange implementation
r400 Domain domain = m_domainMap.value(axisY());
Michal Klocek
Refactors axis handling...
r223 QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX);
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 emit axisRangeChanged(axis,labels);
Michal Klocek
minor. formating
r420 }
else {
Michal Klocek
Adds axis setRange implementation
r400 Domain domain = m_domainMap.value(axis);
Michal Klocek
Refactors axis handling...
r223 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
Michal Klocek
Rename axisLabelsChanged to axisRangeChanged
r399 emit axisRangeChanged(axis,labels);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactors qchart , adds line animation...
r131 }
#include "moc_chartdataset_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE