##// END OF EJS Templates
Updated customchart example. Now it uses QIntervalsAxis
Updated customchart example. Now it uses QIntervalsAxis

File last commit:

r1699:0af2d08df7ac
r1702:f2951e50a7b8
Show More
chartdataset.cpp
434 lines | 11.0 KiB | text/x-c | CppLexer
/ src / chartdataset.cpp
Michal Klocek
Updates chartdataset unit test
r771 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "chartdataset_p.h"
Jani Honkonen
Implemented QAbstractSeries::chart()...
r1314 #include "qchart.h"
Michal Klocek
Refactors QAxis to QAbstractAxis...
r1541 #include "qvaluesaxis.h"
Michal Klocek
Refactor CategoriesAxis to BarCategoriesAxis part 2 of 2
r1613 #include "qbarcategoriesaxis.h"
Michal Klocek
Refactors QAxis to QAbstractAxis...
r1541 #include "qvaluesaxis_p.h"
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 #include "qabstractseries_p.h"
sauimone
renamed barseries files to abstractbarseries
r1586 #include "qabstractbarseries.h"
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 #include "qstackedbarseries.h"
#include "qpercentbarseries.h"
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 #include "qpieseries.h"
Michal Klocek
Refactors qchart , adds line animation...
r131
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Adds axis domain intialization
r1695 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556
Michal Klocek
Refactors qchart , adds line animation...
r131 }
ChartDataSet::~ChartDataSet()
{
Michal Klocek
Adds if series deleted , remove series from chart
r1062 removeAllSeries();
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Refactors QAxis to QAbstractAxis...
r1541 void ChartDataSet::addSeries(QAbstractSeries* series)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactor QChart API...
r1577 Domain* domain = m_seriesDomainMap.value(series);
Michal Klocek
Fix indexing issue of series
r910
Michal Klocek
Refactor QChart API...
r1577 if(domain) {
Michal Klocek
Refactor domain model...
r439 qWarning() << "Can not add series. Series already on the chart";
return;
}
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Adds axis domain intialization
r1695 domain = new Domain(series);
m_seriesDomainMap.insert(series,domain);
series->d_ptr->scaleDomain(*domain);
createSeriesIndex(series);
Michal Klocek
Krazy reported errors...
r974 series->setParent(this); // take ownership
Michal Klocek
Adds axis domain intialization
r1695 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
series->d_ptr->m_dataset = this;
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Adds axis domain intialization
r1695 emit seriesAdded(series,domain);
Michal Klocek
Adds area chart...
r421
Michal Klocek
Adds axis domain intialization
r1695 }
void ChartDataSet::removeSeries(QAbstractSeries* series)
{
if(!m_seriesDomainMap.contains(series)) {
qWarning()<<"Can not remove series. Series not found on the chart.";
return;
}
emit seriesRemoved(series);
Domain* domain = m_seriesDomainMap.take(series);
delete domain;
domain = 0;
removeSeriesIndex(series);
series->setParent(0);
series->d_ptr->m_chart = 0;
series->d_ptr->m_dataset = 0;
removeAxes(series);
}
Michal Klocek
Adds area chart...
r421
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943
Michal Klocek
Adds axis domain intialization
r1695
void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
{
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
Michal Klocek
Fix indexing issue of series
r910
int key=0;
while (i.hasNext()) {
i.next();
if(i.key()!=key) {
break;
}
key++;
}
m_indexSeriesMap.insert(key,series);
Michal Klocek
Adds axis domain intialization
r1695 }
Michal Klocek
Fix indexing issue of series
r910
Michal Klocek
Adds axis domain intialization
r1695 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
{
int key = seriesIndex(series);
Q_ASSERT(key!=-1);
m_indexSeriesMap.remove(key);
Michal Klocek
Refactor domain model...
r439 }
Jani Honkonen
Pie chart refactoring
r142
Michal Klocek
Refactor QChart API...
r1577 void ChartDataSet::createDefaultAxes()
{
Michal Klocek
Adds createDefaultAxes logic
r1588 if(m_seriesDomainMap.isEmpty()) return;
QAbstractAxis::AxisTypes typeX(0);
QAbstractAxis::AxisTypes typeY(0);
QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
Michal Klocek
Refactor QChart API...
r1577 while (i.hasNext()) {
Michal Klocek
Adds createDefaultAxes logic
r1588 i.next();
removeAxes(i.key());
}
Michal Klocek
Refactor QChart API...
r1577
Michal Klocek
Adds createDefaultAxes logic
r1588 i.toFront();
Michal Klocek
Refactor QChart API...
r1577
Michal Klocek
Adds createDefaultAxes logic
r1588 while (i.hasNext()) {
i.next();
QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
if(axisX) typeX&=axisX->type();
Michal Klocek
Adds axis domain intialization
r1695 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
Michal Klocek
Adds createDefaultAxes logic
r1588 if(axisY) typeY&=axisY->type();
Michal Klocek
Adds axis domain intialization
r1695 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
Michal Klocek
Adds createDefaultAxes logic
r1588 }
Michal Klocek
Refactor QChart API...
r1577
Michal Klocek
Adds axis domain intialization
r1695 createAxes(typeX,Qt::Horizontal);
createAxes(typeY,Qt::Vertical);
}
Michal Klocek
Refactor QChart API...
r1577
Michal Klocek
Adds axis domain intialization
r1695 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
{
QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
Michal Klocek
Adds createDefaultAxes logic
r1588 {
while (i.hasNext()) {
Michal Klocek
Adds axis domain intialization
r1695 i.next();
QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
if(!axis) continue;
initializeAxis(axis,i.key());
emit axisAdded(axis,i.value());
Michal Klocek
Refactor QChart API...
r1577 }
Michal Klocek
Adds createDefaultAxes logic
r1588 }
Michal Klocek
Adds axis domain intialization
r1695 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
Michal Klocek
Adds createDefaultAxes logic
r1588 i.toFront();
while (i.hasNext()) {
Michal Klocek
Adds axis domain intialization
r1695 i.next();
initializeAxis(axis,i.key());
Michal Klocek
Refactor QChart API...
r1577 }
Michal Klocek
Adds axis domain intialization
r1695 emit axisAdded(axis,i.value());
Michal Klocek
Refactor QChart API...
r1577 }
}
Michal Klocek
Adds axis domain intialization
r1695 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
Michal Klocek
Adds createDefaultAxes logic
r1588 {
QAbstractAxis* axis =0;
switch(type) {
case QAbstractAxis::AxisTypeValues:
axis = new QValuesAxis(this);
break;
case QAbstractAxis::AxisTypeCategories:
Michal Klocek
Refactor CategoriesAxis to BarCategoriesAxis part 1 of 2
r1612 axis = new QBarCategoriesAxis(this);
Michal Klocek
Adds createDefaultAxes logic
r1588 break;
default:
axis = 0;
break;
}
Michal Klocek
Adds axis domain intialization
r1695 if(axis)
Michal Klocek
Refactors Domain and Axis...
r1698 axis->d_ptr->setOrientation(orientation);
Michal Klocek
Adds createDefaultAxes logic
r1588
Michal Klocek
Adds axis domain intialization
r1695 return axis;
Michal Klocek
Adds createDefaultAxes logic
r1588 }
Michal Klocek
Adds axis domain intialization
r1695 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
Michal Klocek
Refactor domain model...
r439 {
Michal Klocek
Adds axis domain intialization
r1695 Domain* domain = m_seriesDomainMap.value(series);
axis->d_ptr->intializeDomain(domain);
series->d_ptr->initializeAxis(axis);
if(axis->orientation()==Qt::Horizontal) {
Michal Klocek
Refactors Domain and Axis...
r1698 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
Michal Klocek
Adds axis domain intialization
r1695 m_seriesAxisXMap.insert(series,axis);
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556 }
Michal Klocek
Adds axis domain intialization
r1695 else {
Michal Klocek
Refactors Domain and Axis...
r1698 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
Michal Klocek
Adds axis domain intialization
r1695 m_seriesAxisYMap.insert(series,axis);
}
Michal Klocek
Refactors Domain and Axis...
r1698 axis->d_ptr->emitUpdated();
Michal Klocek
Adds createDefaultAxes logic
r1588 }
void ChartDataSet::removeAxes(QAbstractSeries* series)
{
Michal Klocek
Update of chartdataset_tst
r1564 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
Michal Klocek
Fix indexing issue of series
r910
Michal Klocek
Update of chartdataset_tst
r1564 if(axisX) {
QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
int x = axesX.indexOf(axisX);
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Update of chartdataset_tst
r1564 if(x==-1) {
emit axisRemoved(axisX);
Michal Klocek
Fix deleteLater in case presenter keeps deleteLater objects
r1569 axisX->deleteLater();
Michal Klocek
Update of chartdataset_tst
r1564 }
Michal Klocek
Refactor domain model...
r439 }
Michal Klocek
Refactors axis handling...
r223
Michal Klocek
Update of chartdataset_tst
r1564 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
if(axisY) {
QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
int y = axesY.indexOf(axisY);
if(y==-1) {
emit axisRemoved(axisY);
Michal Klocek
Fix deleteLater in case presenter keeps deleteLater objects
r1569 axisY->deleteLater();
Michal Klocek
Update of chartdataset_tst
r1564 }
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
Refactors core to support mulitpile axis and domains...
r1556 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 foreach(QAbstractSeries *s , series) {
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556 removeSeries(s);
Michal Klocek
Refactored for MVP...
r139 }
sauimone
added map for yaxises methods to set axis
r1554 Q_ASSERT(m_seriesAxisXMap.count()==0);
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556 Q_ASSERT(m_seriesAxisXMap.count()==0);
Q_ASSERT(m_seriesDomainMap.count()==0);
Michal Klocek
Fix indexing issue of series
r910
Michal Klocek
Krazy reported errors...
r974 qDeleteAll(series);
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
Fix all tst_chartdataset test cases
r1593 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
Michal Klocek
Fixes tst_qchartview
r1652
Michal Klocek
Fix all tst_chartdataset test cases
r1593 blockAxisSignals(true);
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
Michal Klocek
Fix all tst_chartdataset test cases
r1593
Michal Klocek
Refactor domain model...
r439 while (i.hasNext()) {
i.next();
i.value()->zoomIn(rect,size);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Fix all tst_chartdataset test cases
r1593
blockAxisSignals(false);
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)
{
Michal Klocek
Fix all tst_chartdataset test cases
r1593 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
blockAxisSignals(true);
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
Michal Klocek
Fix all tst_chartdataset test cases
r1593
Michal Klocek
Refactor domain model...
r439 while (i.hasNext()) {
i.next();
i.value()->zoomOut(rect,size);
}
Michal Klocek
Fix all tst_chartdataset test cases
r1593
blockAxisSignals(false);
}
void ChartDataSet::blockAxisSignals(bool enabled)
{
QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
while (i.hasNext()) {
i.next();
QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
Michal Klocek
Adds axis domain intialization
r1695 if(axisX) axisX->d_ptr->blockSignals(enabled);
if(axisY) axisY->d_ptr->blockSignals(enabled);
Michal Klocek
Fix all tst_chartdataset test cases
r1593 }
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Fixes to API , QSeriesType -> SeriesType , add missing getters
r1107 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
Michal Klocek
Fix indexing issue of series
r910 {
int count=0;
Michal Klocek
Refactor QChart API...
r1577 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
Michal Klocek
Fix indexing issue of series
r910 while (i.hasNext()) {
i.next();
if(i.key()->type()==type) count++;
}
return count;
}
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 int ChartDataSet::seriesIndex(QAbstractSeries *series)
Tero Ahola
Fixed bug with changing theme when several series exist
r538 {
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
Michal Klocek
Fix indexing issue of series
r910 while (i.hasNext()) {
i.next();
if (i.value() == series)
return i.key();
Tero Ahola
Fixed bug with changing theme when several series exist
r538 }
Tero Ahola
Reserve ordering of chart series internally....
r825 return -1;
Tero Ahola
Fixed bug with changing theme when several series exist
r538 }
sauimone
added map for yaxises methods to set axis
r1554 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
{
Michal Klocek
Adds return of visible axes
r1641 if(series == 0) {
QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
while (i.hasNext()) {
i.next();
if(i.value()->isVisible()) return i.value();
}
return 0;
}
sauimone
added map for yaxises methods to set axis
r1554 return m_seriesAxisXMap.value(series);
}
Michal Klocek
Refactors QAxis to QAbstractAxis...
r1541 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
Michal Klocek
Refactors axis handling...
r223 {
Michal Klocek
Adds return of visible axes
r1641 if(series == 0) {
QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
while (i.hasNext()) {
i.next();
if(i.value()->isVisible()) return i.value();
}
return 0;
}
sauimone
added map for yaxises methods to set axis
r1554 return m_seriesAxisYMap.value(series);
Michal Klocek
Refactors axis handling...
r223 }
Michal Klocek
Adds axis domain intialization
r1695 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
sauimone
added map for yaxises methods to set axis
r1554 {
Michal Klocek
Update of chartdataset_tst
r1564 Q_ASSERT(axis);
Michal Klocek
Adds axis domain intialization
r1695
Michal Klocek
Adds tst_qvaluesaxis stub implementation
r1699 if(!series) {
qWarning() << "Series not found on the chart.";
return;
}
Michal Klocek
Refactor QChart API...
r1577 Domain* domain = m_seriesDomainMap.value(series);
Michal Klocek
Update of chartdataset_tst
r1564
Michal Klocek
Refactor QChart API...
r1577 if(!domain) {
qWarning() << "Series not found on the chart.";
return;
Michal Klocek
Update of chartdataset_tst
r1564 }
Michal Klocek
Adds axis domain intialization
r1695 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
Michal Klocek
Refactor QChart API...
r1577 qWarning()<<"Axis already defined as axis Y";
return;
Michal Klocek
Update of chartdataset_tst
r1564 }
Michal Klocek
Adds axis domain intialization
r1695 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
qWarning()<<"Axis already defined as axis X";
return;
Michal Klocek
Update of chartdataset_tst
r1564 }
Michal Klocek
Refactors Domain and Axis...
r1698 axis->d_ptr->setOrientation(orientation);
sauimone
added map for yaxises methods to set axis
r1554
Michal Klocek
Adds axis domain intialization
r1695 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
Michal Klocek
Update of chartdataset_tst
r1564
Michal Klocek
Adds axis domain intialization
r1695 if(orientation==Qt::Vertical) {
seriesAxisMap= &m_seriesAxisYMap;
Michal Klocek
Update of chartdataset_tst
r1564
Michal Klocek
Adds axis domain intialization
r1695 }else{
seriesAxisMap= &m_seriesAxisXMap;
Michal Klocek
Update of chartdataset_tst
r1564 }
Michal Klocek
Adds axis domain intialization
r1695 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
QList<QAbstractAxis*> axes = seriesAxisMap->values();
Michal Klocek
Update of chartdataset_tst
r1564
Michal Klocek
Refactor QChart API...
r1577 if(oldAxis) {
Michal Klocek
Adds axis domain intialization
r1695 if(axes.indexOf(oldAxis)==-1) {
Michal Klocek
Refactor QChart API...
r1577 emit axisRemoved(oldAxis);
oldAxis->deleteLater();
}
}
Michal Klocek
Update of chartdataset_tst
r1564
Michal Klocek
Adds axis domain intialization
r1695 if(axes.indexOf(axis)==-1) {
initializeAxis(axis,series);
Michal Klocek
Update of chartdataset_tst
r1564 emit axisAdded(axis,domain);
Michal Klocek
Adds axis domain intialization
r1695 }else{
initializeAxis(axis,series);
Michal Klocek
Update of chartdataset_tst
r1564 }
}
Domain* ChartDataSet::domain(QAbstractSeries *series) const
{
return m_seriesDomainMap.value(series);
Michal Klocek
Adds missing functions to qchart API
r1542 }
Michal Klocek
Fix precision issue when scrolling domain
r1267 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
Michal Klocek
Adds scroll support...
r531 {
Michal Klocek
Fix all tst_chartdataset test cases
r1593 blockAxisSignals(true);
Michal Klocek
Refactors core to support mulitpile axis and domains...
r1556 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
Michal Klocek
Refactor axis hadnling...
r1078 while (i.hasNext()) {
i.next();
i.value()->move(dx,dy,size);
}
Michal Klocek
Fix all tst_chartdataset test cases
r1593 blockAxisSignals(false);
Michal Klocek
Refactor axis hadnling...
r1078 }
QList<QAbstractSeries*> ChartDataSet::series() const
{
Michal Klocek
Creates default initalization of axes
r1661 return m_seriesDomainMap.keys();
Michal Klocek
Adds scroll support...
r531 }
sauimone
legend detach example. Bug fixes to legend.
r1263 void ChartDataSet::updateSeries(QAbstractSeries *series)
{
emit seriesUpdated(series);
}
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "moc_chartdataset_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE