chartdataset.cpp
243 lines
| 6.3 KiB
| text/x-c
|
CppLexer
/ src / chartdataset.cpp
Michal Klocek
|
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
|
r131 | #include "chartdataset_p.h" | ||
Jani Honkonen
|
r1314 | #include "qchart.h" | ||
Michal Klocek
|
r1541 | #include "qvaluesaxis.h" | ||
#include "qvaluesaxis_p.h" | ||||
Tero Ahola
|
r988 | #include "qabstractseries_p.h" | ||
sauimone
|
r338 | #include "qbarseries.h" | ||
#include "qstackedbarseries.h" | ||||
#include "qpercentbarseries.h" | ||||
Jani Honkonen
|
r146 | #include "qpieseries.h" | ||
Michal Klocek
|
r131 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Jani Honkonen
|
r1314 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | ||
Michal Klocek
|
r1556 | m_domainIndex(0) | ||
Michal Klocek
|
r131 | { | ||
Michal Klocek
|
r1556 | |||
Michal Klocek
|
r131 | } | ||
ChartDataSet::~ChartDataSet() | ||||
{ | ||||
Michal Klocek
|
r1062 | removeAllSeries(); | ||
Michal Klocek
|
r131 | } | ||
Michal Klocek
|
r1541 | void ChartDataSet::addSeries(QAbstractSeries* series) | ||
Michal Klocek
|
r131 | { | ||
sauimone
|
r1554 | QAbstractAxis* axis = m_seriesAxisXMap.value(series); | ||
Michal Klocek
|
r910 | |||
if(axis) { | ||||
Michal Klocek
|
r439 | qWarning() << "Can not add series. Series already on the chart"; | ||
return; | ||||
} | ||||
Michal Klocek
|
r223 | |||
Michal Klocek
|
r1556 | QAbstractAxis* axisX = series->d_ptr->createAxisX(this); | ||
QAbstractAxis* axisY = series->d_ptr->createAxisY(this); | ||||
Michal Klocek
|
r1542 | |||
Michal Klocek
|
r974 | series->setParent(this); // take ownership | ||
Michal Klocek
|
r223 | |||
Michal Klocek
|
r1556 | Domain* domain = new Domain(series); | ||
Michal Klocek
|
r910 | |||
Michal Klocek
|
r1556 | if(axisX){ | ||
QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | ||||
QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | ||||
axisX->d_ptr->m_orientation=Qt::Horizontal; | ||||
emit axisAdded(axisX,domain); | ||||
Michal Klocek
|
r1557 | m_seriesAxisXMap.insert(series,axisX); | ||
Michal Klocek
|
r1556 | } | ||
if(axisY){ | ||||
Michal Klocek
|
r963 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | ||
QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | ||||
Michal Klocek
|
r1556 | axisY->d_ptr->m_orientation=Qt::Vertical; | ||
Michal Klocek
|
r439 | emit axisAdded(axisY,domain); | ||
Michal Klocek
|
r1556 | m_seriesAxisYMap.insert(series,axisY); | ||
Marek Rosa
|
r401 | } | ||
Michal Klocek
|
r421 | |||
Michal Klocek
|
r1556 | m_seriesDomainMap.insert(series,domain); | ||
Michal Klocek
|
r421 | |||
Michal Klocek
|
r943 | series->d_ptr->scaleDomain(*domain); | ||
Tero Ahola
|
r988 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | ||
Michal Klocek
|
r910 | |||
int key=0; | ||||
while (i.hasNext()) { | ||||
i.next(); | ||||
if(i.key()!=key) { | ||||
break; | ||||
} | ||||
key++; | ||||
} | ||||
m_indexSeriesMap.insert(key,series); | ||||
Jani Honkonen
|
r1314 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | ||
series->d_ptr->m_dataset = this; | ||||
Michal Klocek
|
r1062 | |||
Michal Klocek
|
r910 | emit seriesAdded(series,domain); | ||
Michal Klocek
|
r139 | |||
Michal Klocek
|
r439 | } | ||
Jani Honkonen
|
r142 | |||
Michal Klocek
|
r1556 | void ChartDataSet::removeSeries(QAbstractSeries* series) | ||
Michal Klocek
|
r439 | { | ||
Michal Klocek
|
r1556 | Domain* domain = m_seriesDomainMap.take(series); | ||
Michal Klocek
|
r910 | |||
Michal Klocek
|
r1556 | if(!domain) { | ||
Michal Klocek
|
r910 | qWarning()<<"Can not remove series. Series not found on the chart."; | ||
Michal Klocek
|
r1556 | } | ||
Michal Klocek
|
r974 | |||
Michal Klocek
|
r910 | emit seriesRemoved(series); | ||
Michal Klocek
|
r974 | |||
Michal Klocek
|
r1558 | delete domain; | ||
domain = 0; | ||||
Michal Klocek
|
r1556 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | ||
QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | ||||
Michal Klocek
|
r910 | int key = seriesIndex(series); | ||
Q_ASSERT(key!=-1); | ||||
Michal Klocek
|
r139 | |||
Michal Klocek
|
r910 | m_indexSeriesMap.remove(key); | ||
Jani Honkonen
|
r1314 | |||
Michal Klocek
|
r974 | series->setParent(0); | ||
Jani Honkonen
|
r1314 | series->d_ptr->m_chart = 0; | ||
series->d_ptr->m_dataset = 0; | ||||
Michal Klocek
|
r139 | |||
Michal Klocek
|
r1556 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | ||
QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | ||||
Michal Klocek
|
r910 | |||
Michal Klocek
|
r1556 | int x = axesX.indexOf(axisX); | ||
int y = axesY.indexOf(axisY); | ||||
Michal Klocek
|
r223 | |||
Michal Klocek
|
r1556 | if(x==-1) { | ||
emit axisRemoved(axisX); | ||||
delete axisX; | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r223 | |||
Michal Klocek
|
r1556 | if(y==-1) { | ||
emit axisRemoved(axisY); | ||||
delete axisY; | ||||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r139 | } | ||
Michal Klocek
|
r258 | void ChartDataSet::removeAllSeries() | ||
{ | ||||
Michal Klocek
|
r1556 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | ||
Tero Ahola
|
r988 | foreach(QAbstractSeries *s , series) { | ||
Michal Klocek
|
r1556 | removeSeries(s); | ||
Michal Klocek
|
r139 | } | ||
sauimone
|
r1554 | Q_ASSERT(m_seriesAxisXMap.count()==0); | ||
Michal Klocek
|
r1556 | Q_ASSERT(m_seriesAxisXMap.count()==0); | ||
Q_ASSERT(m_seriesDomainMap.count()==0); | ||||
Michal Klocek
|
r910 | |||
Michal Klocek
|
r974 | qDeleteAll(series); | ||
Michal Klocek
|
r139 | } | ||
Michal Klocek
|
r439 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | ||
Michal Klocek
|
r139 | { | ||
Michal Klocek
|
r1556 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | ||
Michal Klocek
|
r439 | while (i.hasNext()) { | ||
i.next(); | ||||
i.value()->zoomIn(rect,size); | ||||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r223 | |||
Michal Klocek
|
r439 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | ||
{ | ||||
Michal Klocek
|
r1556 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | ||
Michal Klocek
|
r439 | while (i.hasNext()) { | ||
i.next(); | ||||
i.value()->zoomOut(rect,size); | ||||
} | ||||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r1107 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | ||
Michal Klocek
|
r910 | { | ||
int count=0; | ||||
sauimone
|
r1554 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap); | ||
Michal Klocek
|
r910 | while (i.hasNext()) { | ||
i.next(); | ||||
if(i.key()->type()==type) count++; | ||||
} | ||||
return count; | ||||
} | ||||
Tero Ahola
|
r988 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | ||
Tero Ahola
|
r538 | { | ||
Tero Ahola
|
r988 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | ||
Michal Klocek
|
r910 | while (i.hasNext()) { | ||
i.next(); | ||||
if (i.value() == series) | ||||
return i.key(); | ||||
Tero Ahola
|
r538 | } | ||
Tero Ahola
|
r825 | return -1; | ||
Tero Ahola
|
r538 | } | ||
sauimone
|
r1554 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | ||
{ | ||||
Michal Klocek
|
r1557 | if(series == 0) return m_seriesAxisXMap.begin().value(); | ||
sauimone
|
r1554 | return m_seriesAxisXMap.value(series); | ||
} | ||||
Michal Klocek
|
r1541 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | ||
Michal Klocek
|
r223 | { | ||
Michal Klocek
|
r1557 | if(series == 0) return m_seriesAxisYMap.begin().value(); | ||
sauimone
|
r1554 | return m_seriesAxisYMap.value(series); | ||
Michal Klocek
|
r223 | } | ||
sauimone
|
r1554 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) | ||
{ | ||||
Michal Klocek
|
r1558 | Q_UNUSED(series); | ||
Q_UNUSED(axis); | ||||
// m_seriesAxisXMap.insert(series,axis); | ||||
sauimone
|
r1554 | } | ||
void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | ||||
Michal Klocek
|
r1542 | { | ||
Michal Klocek
|
r1558 | Q_UNUSED(series); | ||
Q_UNUSED(axis); | ||||
// m_seriesAxisYMap.insert(series,axis); | ||||
Michal Klocek
|
r1542 | } | ||
Michal Klocek
|
r1267 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | ||
Michal Klocek
|
r531 | { | ||
Michal Klocek
|
r1556 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | ||
Michal Klocek
|
r1078 | while (i.hasNext()) { | ||
i.next(); | ||||
i.value()->move(dx,dy,size); | ||||
} | ||||
} | ||||
QList<QAbstractSeries*> ChartDataSet::series() const | ||||
{ | ||||
sauimone
|
r1554 | return m_seriesAxisXMap.keys(); | ||
Michal Klocek
|
r531 | } | ||
sauimone
|
r1263 | void ChartDataSet::updateSeries(QAbstractSeries *series) | ||
{ | ||||
emit seriesUpdated(series); | ||||
} | ||||
Michal Klocek
|
r131 | #include "moc_chartdataset_p.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||