##// END OF EJS Templates
QML bar series categories
QML bar series categories

File last commit:

r703:44befe5b9760
r726:5bffcd7b4ba5
Show More
chartdataset.cpp
331 lines | 8.5 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()
{
}
Michal Klocek
Rename QChartSeries to QSeries
r360 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactor domain model...
r439 if(axisY==0) axisY = m_axisY;
Michal Klocek
Refactored for MVP...
r139
Michal Klocek
Refactor domain model...
r439 QChartAxis* axis = m_seriesAxisMap.value(series);
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 if(axis) {
qWarning() << "Can not add series. Series already on the chart";
return;
}
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 if(!series->parent()){
series->setParent(this); // take ownership
};
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 if(!axisY->parent()){
axisY->setParent(this); // take ownership
}
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 Domain* domain = m_axisDomainMap.value(axisY);
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 if(!domain) {
domain = new Domain();
Michal Klocek
Fix worng slot signature in axis initilization
r688 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
Michal Klocek
Adds loosenumber algorithm...
r678 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
Michal Klocek
Bugfix missing min max intialization when axis added to domain
r442 //initialize
Michal Klocek
Refactor domain model...
r439 m_axisDomainMap.insert(axisY,domain);
emit axisAdded(axisY,domain);
Marek Rosa
Spline working somewhat
r401 }
Michal Klocek
Adds area chart...
r421
Michal Klocek
Refactor domain model...
r439 if(!m_axisXInitialized){
emit axisAdded(axisX(),domain);
m_axisXInitialized=true;
}
Michal Klocek
Adds area chart...
r421
Michal Klocek
Refactor domain model...
r439 calculateDomain(series,domain);
Michal Klocek
Adds area chart...
r421
Michal Klocek
Refactor domain model...
r439 m_seriesAxisMap.insert(series,axisY);
emit seriesAdded(series,domain);
Michal Klocek
Refactored for MVP...
r139
Michal Klocek
Refactor domain model...
r439 }
Jani Honkonen
Pie chart refactoring
r142
Michal Klocek
Refactor domain model...
r439 void ChartDataSet::removeSeries(QSeries* series)
{
Tero Ahola
Integrated scatter again. Missing functionality....
r158
Michal Klocek
Refactor domain model...
r439 QChartAxis* axis = m_seriesAxisMap.value(series);
Marek Rosa
Spline working somewhat
r401
Michal Klocek
Refactor domain model...
r439 if(!axis){
qWarning()<<"Can not remove series. Series not found on the chart.";
Marek Rosa
Spline working somewhat
r401 return;
}
Michal Klocek
Refactor domain model...
r439 emit seriesRemoved(series);
m_seriesAxisMap.remove(series);
Michal Klocek
Refactored for MVP...
r139
Michal Klocek
Refactor domain model...
r439 if(series->parent()==this){
delete series;
series=0;
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Refactor domain model...
r439 QList<QChartAxis*> axes = m_seriesAxisMap.values();
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 int i = axes.indexOf(axis);
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 if(i==-1){
Domain* domain = m_axisDomainMap.take(axis);
emit axisRemoved(axis);
Michal Klocek
Fix ownership handling: if object has a parent do not delete it
r444 if(axis!=axisY()){
if(axis->parent()==this){
delete axis;
axis=0;
}
}
Michal Klocek
Refactor domain model...
r439 delete domain;
}
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 if(m_seriesAxisMap.values().size()==0)
{
m_axisXInitialized=false;
emit axisRemoved(axisX());
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Adds RemoveAllSeries method to API
r258 void ChartDataSet::removeAllSeries()
{
Michal Klocek
Refactor domain model...
r439 QList<QSeries*> series = m_seriesAxisMap.keys();
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 foreach(QSeries* s , series) {
removeSeries(s);
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Refactor domain model...
r439 Q_ASSERT(m_seriesAxisMap.count()==0);
Q_ASSERT(m_axisDomainMap.count()==0);
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Refactor domain model...
r439 //to be removed with PIMPL
Michal Klocek
Adds back reimplemnted categories handling
r701 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Adds back reimplemnted categories handling
r701 qreal minX(domain->minX());
qreal minY(domain->minY());
qreal maxX(domain->maxX());
qreal maxY(domain->maxY());
int tickXCount(domain->tickXCount());
int tickYCount(domain->tickYCount());
Michal Klocek
Refactor domain model...
r439 switch(series->type())
{
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 case QSeries::SeriesTypeLine:
case QSeries::SeriesTypeSpline:
case QSeries::SeriesTypeScatter:
{
Michal Klocek
Bugfix: check series count before changing domain
r373
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 QXYSeries* xySeries = static_cast<QXYSeries*>(series);
Michal Klocek
Bugfix missing xaxis label update on zoomOut
r265
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 for (int i = 0; i < xySeries->count(); i++)
Michal Klocek
Refactor domain model...
r439 {
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 qreal x = xySeries->x(i);
qreal y = xySeries->y(i);
minX = qMin(minX, x);
minY = qMin(minY, y);
maxX = qMax(maxX, x);
maxY = qMax(maxY, y);
Michal Klocek
Refactor domain model...
r439 }
break;
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactor domain model...
r439 case QSeries::SeriesTypeArea: {
Michal Klocek
Adds axis setRange implementation
r400
Michal Klocek
Refactor domain model...
r439 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
QLineSeries* upperSeries = areaSeries->upperSeries();
QLineSeries* lowerSeries = areaSeries->lowerSeries();
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 for (int i = 0; i < upperSeries->count(); i++)
{
qreal x = upperSeries->x(i);
qreal y = upperSeries->y(i);
Michal Klocek
Adds back reimplemnted categories handling
r701 minX = qMin(minX, x);
minY = qMin(minY, y);
maxX = qMax(maxX, x);
maxY = qMax(maxY, y);
Michal Klocek
Refactor domain model...
r439 }
if(lowerSeries) {
for (int i = 0; i < lowerSeries->count(); i++)
{
qreal x = lowerSeries->x(i);
qreal y = lowerSeries->y(i);
Michal Klocek
Adds back reimplemnted categories handling
r701 minX = qMin(minX, x);
minY = qMin(minY, y);
maxX = qMax(maxX, x);
maxY = qMax(maxY, y);
Michal Klocek
Refactor domain model...
r439 }}
break;
}
case QSeries::SeriesTypeBar: {
Michal Klocek
Adds back reimplemnted categories handling
r701
Michal Klocek
Refactor domain model...
r439 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
qreal x = barSeries->categoryCount();
qreal y = barSeries->max();
Michal Klocek
Adds back reimplemnted categories handling
r701 minX = qMin(minX, x);
minY = qMin(minY, y);
maxX = qMax(maxX, x);
maxY = qMax(maxY, y);
tickXCount = x+1;
setupCategories(barSeries);
Michal Klocek
Refactor domain model...
r439 break;
}
case QSeries::SeriesTypeStackedBar: {
Michal Klocek
Adds back reimplemnted categories handling
r701
Michal Klocek
Refactor domain model...
r439 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
qreal x = stackedBarSeries->categoryCount();
qreal y = stackedBarSeries->maxCategorySum();
Michal Klocek
Adds back reimplemnted categories handling
r701 minX = qMin(minX, x);
minY = qMin(minY, y);
maxX = qMax(maxX, x);
maxY = qMax(maxY, y);
tickXCount = x+1;
setupCategories(stackedBarSeries);
Michal Klocek
Refactor domain model...
r439 break;
}
case QSeries::SeriesTypePercentBar: {
Michal Klocek
Adds back reimplemnted categories handling
r701
Michal Klocek
Refactor domain model...
r439 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
qreal x = percentBarSeries->categoryCount();
Michal Klocek
Adds back reimplemnted categories handling
r701 minX = qMin(minX, x);
maxX = qMax(maxX, x);
minY = 0;
maxY = 100;
setupCategories(percentBarSeries);
Michal Klocek
Refactor domain model...
r439 break;
Marek Rosa
Marge spline
r418 }
Michal Klocek
Fix unit test
r411
Michal Klocek
Refactor domain model...
r439 case QSeries::SeriesTypePie: {
Jani Honkonen
We have so many stupid warnings that "treat warnings as errors" flag is needed...
r609 //QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
Michal Klocek
Refactor domain model...
r439 // TODO: domain stuff
break;
}
Michal Klocek
Fix unit test
r411
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 default: {
qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
return;
break;
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactor domain model...
r439
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Adds back reimplemnted categories handling
r701
domain->setRangeX(minX,maxX,tickXCount);
domain->setRangeY(minY,maxY,tickYCount);
}
void ChartDataSet::setupCategories(QBarSeries* series)
{
QChartAxisCategories* categories = axisX()->categories();
categories->clear();
Michal Klocek
Adds BarCategories typedef
r703 categories->insert(series->categories());
Michal Klocek
Refactored for MVP...
r139 }
Michal Klocek
Refactor domain model...
r439 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactor domain model...
r439 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
while (i.hasNext()) {
i.next();
i.value()->zoomIn(rect,size);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactor domain model...
r439 }
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Refactor domain model...
r439 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
{
QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
while (i.hasNext()) {
i.next();
i.value()->zoomOut(rect,size);
}
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Adds proper series counter for theme initialization
r533 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
{
int count=0;
QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap);
while (i.hasNext()) {
i.next();
if(i.key()->type()==type) count++;
}
return count;
}
Tero Ahola
Fixed bug with changing theme when several series exist
r538 int ChartDataSet::seriesIndex(QSeries *series)
{
int count(-1);
QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
while (i.hasNext()) {
i.next();
count++;
if (i.key() == series)
return count;
}
return count;
}
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;
Michal Klocek
Refactor domain model...
r439 return m_seriesAxisMap.value(series);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactor domain model...
r439 Domain* ChartDataSet::domain(QSeries* series) const
Michal Klocek
Refactors axis handling...
r223 {
Michal Klocek
Refactor domain model...
r439 QChartAxis* axis = m_seriesAxisMap.value(series);
if(axis){
return m_axisDomainMap.value(axis);
}else
return 0;
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactor domain model...
r439 Domain* ChartDataSet::domain(QChartAxis* axis) const
Michal Klocek
Refactors axis handling...
r223 {
Michal Klocek
Fix ownership handling: if object has a parent do not delete it
r444 if(axis==axisX()) {
return m_axisDomainMap.value(axisY());
}
else {
return m_axisDomainMap.value(axis);
}
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Refactor domain model...
r439 QChartAxis* ChartDataSet::axis(QSeries* series) const
Michal Klocek
Refactors axis handling...
r223 {
Michal Klocek
Refactor domain model...
r439 return m_seriesAxisMap.value(series);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Adds scroll support...
r531 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
{
QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
while (i.hasNext()) {
i.next();
i.value()->move(dx,dy,size);
}
}
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "moc_chartdataset_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE