From 6d402eea8412530463fc696163b93c83b27d436a 2012-06-26 18:16:47 From: Michal Klocek Date: 2012-06-26 18:16:47 Subject: [PATCH] Adds missing functions to qchart API --- diff --git a/src/axis/qabstractaxis.cpp b/src/axis/qabstractaxis.cpp index daed62f..46108ed 100644 --- a/src/axis/qabstractaxis.cpp +++ b/src/axis/qabstractaxis.cpp @@ -557,7 +557,8 @@ QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): m_labelsAngle(0), m_shadesVisible(false), m_shadesBrush(Qt::SolidPattern), - m_shadesOpacity(1.0) + m_shadesOpacity(1.0), + m_orientation(Qt::Orientation(0)) { } diff --git a/src/axis/qabstractaxis_p.h b/src/axis/qabstractaxis_p.h index 9ad29b1..11a77f4 100644 --- a/src/axis/qabstractaxis_p.h +++ b/src/axis/qabstractaxis_p.h @@ -65,6 +65,8 @@ protected: QBrush m_shadesBrush; qreal m_shadesOpacity; + Qt::Orientation m_orientation; + friend class QAbstractAxis; }; diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 5ebed62..d097448 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -53,9 +53,6 @@ ChartDataSet::~ChartDataSet() void ChartDataSet::addSeries(QAbstractSeries* series) { - //TODO: if(axisY==0) axisY = m_axisY; - QAbstractAxis* axisY = m_axisY; - QAbstractAxis* axis = m_seriesAxisMap.value(series); if(axis) { @@ -63,15 +60,18 @@ void ChartDataSet::addSeries(QAbstractSeries* series) return; } + QAbstractAxis* axisX = m_axisX ; //series->d_ptr->createAxisX(); + QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY(); + series->setParent(this); // take ownership - axisY->setParent(this); // take ownership + //axisY->setParent(this); // take ownership Domain* domain = m_axisDomainMap.value(axisY); if(!domain) { domain = new Domain(axisY); QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); - QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); + QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); //initialize m_axisDomainMap.insert(axisY,domain); @@ -91,8 +91,8 @@ void ChartDataSet::addSeries(QAbstractSeries* series) series->d_ptr->scaleDomain(*domain); if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { - axisX()->hide(); - this->axisY()->hide(); + axisX->hide(); + axisY->hide(); } m_seriesAxisMap.insert(series,axisY); @@ -157,7 +157,7 @@ QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) if(m_seriesAxisMap.values().size()==0) { m_axisXInitialized=false; - emit axisRemoved(axisX()); + emit axisRemoved(m_axisX); } return axis; @@ -169,7 +169,7 @@ void ChartDataSet::removeAllSeries() QList axes; foreach(QAbstractSeries *s , series) { QAbstractAxis* axis = removeSeries(s); - if(axis==axisY()) continue; + if(axis==m_axisY) continue; int i = axes.indexOf(axis); if(i==-1){ axes< i(m_axisDomainMap); //main domain has to be the last one; - Domain *domain = m_axisDomainMap.value(axisY()); + Domain *domain = m_axisDomainMap.value(m_axisY); Q_ASSERT(domain); while (i.hasNext()) { i.next(); @@ -201,7 +201,7 @@ void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) { QMapIterator i(m_axisDomainMap); //main domain has to be the last one; - Domain *domain = m_axisDomainMap.value(axisY()); + Domain *domain = m_axisDomainMap.value(m_axisY); Q_ASSERT(domain); while (i.hasNext()) { i.next(); @@ -239,6 +239,12 @@ QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const return m_seriesAxisMap.value(series); } +QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const +{ + Q_UNUSED(series) + return m_axisX; +} + Domain* ChartDataSet::domain(QAbstractSeries *series) const { QAbstractAxis* axis = m_seriesAxisMap.value(series); @@ -250,8 +256,8 @@ Domain* ChartDataSet::domain(QAbstractSeries *series) const Domain* ChartDataSet::domain(QAbstractAxis* axis) const { - if(!axis || axis==axisX()) { - return m_axisDomainMap.value(axisY()); + if(!axis || axis==m_axisX) { + return m_axisDomainMap.value(m_axisY); } else { return m_axisDomainMap.value(axis); @@ -262,7 +268,7 @@ void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) { QMapIterator i( m_axisDomainMap); //main domain has to be the last one; - Domain *domain = m_axisDomainMap.value(axisY()); + Domain *domain = m_axisDomainMap.value(m_axisY); while (i.hasNext()) { i.next(); if(i.value()==domain) continue; diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index f385355..331b1fe 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -60,8 +60,8 @@ public: Domain* domain(QAbstractSeries* series) const; Domain* domain(QAbstractAxis* axis) const; - QAbstractAxis* axisX() const { return m_axisX; } - QAbstractAxis* axisY(QAbstractSeries *series = 0) const; + QAbstractAxis* axisX(QAbstractSeries *series) const; + QAbstractAxis* axisY(QAbstractSeries *series) const; QList series() const; diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index d3cfd4b..e5dce39 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -71,7 +71,7 @@ void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) { ChartAxis* item; - if(axis == m_dataset->axisX()){ + if(axis == m_dataset->axisX(0)){ item = new ChartAxisX(axis,this); }else{ item = new ChartAxisY(axis,this); @@ -82,7 +82,7 @@ void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) item->setAnimation(new AxisAnimation(item)); } - if(axis==m_dataset->axisX()){ + if(axis==m_dataset->axisX(0)){ m_chartTheme->decorate(axis,true); QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); //initialize diff --git a/src/qabstractseries_p.h b/src/qabstractseries_p.h index 97a10b0..e65be3d 100644 --- a/src/qabstractseries_p.h +++ b/src/qabstractseries_p.h @@ -40,6 +40,7 @@ class Chart; class LegendMarker; class QLegend; class ChartDataSet; +class QAbstractAxis; class QAbstractSeriesPrivate : public QObject { @@ -51,6 +52,8 @@ public: virtual void scaleDomain(Domain& domain) = 0; virtual Chart* createGraphics(ChartPresenter* presenter) = 0; virtual QList createLegendMarker(QLegend* legend) = 0; + virtual QAbstractAxis* createAxisX() { return 0; } + virtual QAbstractAxis* createAxisY() { return 0; } protected: QAbstractSeries *q_ptr; diff --git a/src/qchart.cpp b/src/qchart.cpp index 54116fb..8e9c4e9 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -308,9 +308,9 @@ void QChart::zoom(qreal factor) /*! Returns the pointer to the x axis object of the chart */ -QAbstractAxis* QChart::axisX() const +QAbstractAxis* QChart::axisX(QAbstractSeries* series) const { - return d_ptr->m_dataset->axisX(); + return d_ptr->m_dataset->axisX(series); } /*! diff --git a/src/qchart.h b/src/qchart.h index f6b153a..2246dcf 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -78,6 +78,9 @@ public: void setAxisX(QAbstractSeries *series, QAbstractAxis* axis); void setAxisY(QAbstractSeries *series, QAbstractAxis* axis); + QAbstractAxis* axisX(QAbstractSeries* series = 0) const; + QAbstractAxis* axisY(QAbstractSeries* series = 0) const; + void setTheme(QChart::ChartTheme theme); QChart::ChartTheme theme() const; @@ -110,9 +113,6 @@ public: void scrollDown(); void scroll(const QPointF &delta); - QAbstractAxis* axisX() const; - QAbstractAxis* axisY(QAbstractSeries* series = 0) const; - QLegend* legend() const; void setMarginsMinimum(const QRectF& margins);