From 9a708aa57671b8bbb86dc6050a4f05fc7b2139f3 2012-06-27 11:34:47 From: sauimone Date: 2012-06-27 11:34:47 Subject: [PATCH] added map for yaxises methods to set axis --- diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index d097448..aab0c13 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -53,14 +53,14 @@ ChartDataSet::~ChartDataSet() void ChartDataSet::addSeries(QAbstractSeries* series) { - QAbstractAxis* axis = m_seriesAxisMap.value(series); + QAbstractAxis* axis = m_seriesAxisXMap.value(series); if(axis) { qWarning() << "Can not add series. Series already on the chart"; return; } - QAbstractAxis* axisX = m_axisX ; //series->d_ptr->createAxisX(); + QAbstractAxis* axisX = series->d_ptr->createAxisX(); QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY(); series->setParent(this); // take ownership @@ -80,7 +80,8 @@ void ChartDataSet::addSeries(QAbstractSeries* series) if(!m_axisXInitialized){ m_axisXInitialized=true; - emit axisAdded(m_axisX,domain); +// emit axisAdded(m_axisX,domain); + emit axisAdded(axisX,domain); } if(!m_axisYInitialized && axisY==m_axisY){ @@ -90,12 +91,12 @@ void ChartDataSet::addSeries(QAbstractSeries* series) series->d_ptr->scaleDomain(*domain); - if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { + if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisXMap.count() == 0) { axisX->hide(); axisY->hide(); } - m_seriesAxisMap.insert(series,axisY); + m_seriesAxisXMap.insert(series,axisY); QMapIterator i(m_indexSeriesMap); @@ -119,7 +120,7 @@ void ChartDataSet::addSeries(QAbstractSeries* series) QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) { - QAbstractAxis* axis = m_seriesAxisMap.value(series); + QAbstractAxis* axis = m_seriesAxisXMap.value(series); if(!axis){ qWarning()<<"Can not remove series. Series not found on the chart."; @@ -128,7 +129,7 @@ QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) emit seriesRemoved(series); - m_seriesAxisMap.remove(series); + m_seriesAxisXMap.remove(series); int key = seriesIndex(series); Q_ASSERT(key!=-1); @@ -138,7 +139,7 @@ QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) series->d_ptr->m_chart = 0; series->d_ptr->m_dataset = 0; - QList axes = m_seriesAxisMap.values(); + QList axes = m_seriesAxisXMap.values(); int i = axes.indexOf(axis); @@ -154,7 +155,7 @@ QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) } } - if(m_seriesAxisMap.values().size()==0) + if(m_seriesAxisXMap.values().size()==0) { m_axisXInitialized=false; emit axisRemoved(m_axisX); @@ -165,7 +166,7 @@ QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) void ChartDataSet::removeAllSeries() { - QList series = m_seriesAxisMap.keys(); + QList series = m_seriesAxisXMap.keys(); QList axes; foreach(QAbstractSeries *s , series) { QAbstractAxis* axis = removeSeries(s); @@ -176,7 +177,7 @@ void ChartDataSet::removeAllSeries() } } - Q_ASSERT(m_seriesAxisMap.count()==0); + Q_ASSERT(m_seriesAxisXMap.count()==0); Q_ASSERT(m_axisDomainMap.count()==1); qDeleteAll(series); @@ -214,7 +215,7 @@ void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) { int count=0; - QMapIterator i(m_seriesAxisMap); + QMapIterator i(m_seriesAxisXMap); while (i.hasNext()) { i.next(); if(i.key()->type()==type) count++; @@ -233,21 +234,32 @@ int ChartDataSet::seriesIndex(QAbstractSeries *series) return -1; } +QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const +{ + qDebug() << "axisX"; + if (series == 0) return m_axisX; + return m_seriesAxisXMap.value(series); +} + QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const { if(series == 0) return m_axisY; - return m_seriesAxisMap.value(series); + return m_seriesAxisYMap.value(series); } -QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const +void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) +{ + m_seriesAxisXMap.insert(series,axis); +} + +void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) { - Q_UNUSED(series) - return m_axisX; + m_seriesAxisYMap.insert(series,axis); } Domain* ChartDataSet::domain(QAbstractSeries *series) const { - QAbstractAxis* axis = m_seriesAxisMap.value(series); + QAbstractAxis* axis = m_seriesAxisXMap.value(series); if(axis){ return m_axisDomainMap.value(axis); }else @@ -279,7 +291,7 @@ void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) QList ChartDataSet::series() const { - return m_seriesAxisMap.keys(); + return m_seriesAxisXMap.keys(); } void ChartDataSet::updateSeries(QAbstractSeries *series) diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 331b1fe..e6e425c 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -63,6 +63,9 @@ public: QAbstractAxis* axisX(QAbstractSeries *series) const; QAbstractAxis* axisY(QAbstractSeries *series) const; + void setAxisX(QAbstractSeries *series, QAbstractAxis *axis); + void setAxisY(QAbstractSeries *series, QAbstractAxis *axis); + QList series() const; Q_SIGNALS: @@ -77,7 +80,8 @@ private: void calculateDomain(QAbstractSeries* series,Domain* domain); private: - QMap m_seriesAxisMap; + QMap m_seriesAxisXMap; + QMap m_seriesAxisYMap; QMap m_axisDomainMap; QMap m_indexSeriesMap; QAbstractAxis* m_axisX; diff --git a/src/qchart.cpp b/src/qchart.cpp index a9698a8..bc9d9c5 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -398,14 +398,16 @@ void QChart::setMarginsMinimum(const QRectF& margins) void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis) { - Q_UNUSED(series); - Q_UNUSED(axis); +// Q_UNUSED(series); +// Q_UNUSED(axis); + d_ptr->m_dataset->setAxisX(series, axis); } void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis) { - Q_UNUSED(series); - Q_UNUSED(axis); +// Q_UNUSED(series); +// Q_UNUSED(axis); + d_ptr->m_dataset->setAxisY(series, axis); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////