diff --git a/example/axischart/main.cpp b/example/axischart/main.cpp index 26b4b65..f011406 100644 --- a/example/axischart/main.cpp +++ b/example/axischart/main.cpp @@ -51,6 +51,8 @@ int main(int argc, char *argv[]) axisX->addAxisTickLabel(0,"low"); axisX->addAxisTickLabel(50,"medium"); axisX->addAxisTickLabel(100,"High"); + axisX->setMin(-10); + axisX->setMax(200); QChartAxis* axisY = chartView->axisY(); axisY->setLabelsAngle(45); @@ -58,6 +60,8 @@ int main(int argc, char *argv[]) axisY->addAxisTickLabel(0,"low"); axisY->addAxisTickLabel(50,"medium"); axisY->addAxisTickLabel(100,"High"); + axisY->setMin(-10); + axisY->setMax(200); window.setCentralWidget(chartView); window.resize(400, 300); diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index c6f3899..1141f98 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -134,28 +134,22 @@ void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) if(!m_domainMap.contains(axisY)) { emit axisAdded(axisY); - QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); - QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); + QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); } - m_domainMap.replace(axisY,domain); - m_seriesMap.insert(axisY,series); if(!m_axisXInitialized) { emit axisAdded(axisX()); - QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); - QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); + QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); m_axisXInitialized=true; } - QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); - QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); - emit axisRangeChanged(axisY,ylabels); - emit axisRangeChanged(axisX(),xlabels); + m_domainMap.replace(axisY,domain); + m_seriesMap.insert(axisY,series); emit seriesAdded(series); - emit seriesDomainChanged(series,domain); + setDomain(m_domainIndex); } @@ -240,10 +234,13 @@ void ChartDataSet::setDomain(int index) foreach(QSeries* series, seriesList) { emit seriesDomainChanged(series,domain); } + axis->setRange(domain.m_minY,domain.m_maxY); emit axisRangeChanged(axis,labels); + } QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); + axisX()->setRange(domain.m_minX,domain.m_maxY); emit axisRangeChanged(axisX(),labels); } @@ -281,19 +278,10 @@ void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) foreach (QChartAxis* axis , domainList){ domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); - QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); - QList seriesList = m_seriesMap.values(axis); - foreach(QSeries* series, seriesList){ - emit seriesDomainChanged(series,domain); - } - emit axisRangeChanged(axis,labels); m_domainMap.insert(axis,domain); } - QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); - emit axisRangeChanged(axisX(),labels); - - m_domainIndex++; + setDomain(++m_domainIndex); } QChartAxis* ChartDataSet::axisY(QSeries* series) const @@ -331,23 +319,56 @@ QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) } -void ChartDataSet::handleMinChanged(qreal min) +void ChartDataSet::handleRangeChanged(QChartAxis* axis) { + qreal min = axis->min(); + qreal max = axis->max(); -} + if(axis==axisX()) { -void ChartDataSet::handleMaxChanged(qreal max) -{ + m_domainIndex=0; + + clearDomains(m_domainIndex); + + QList domainList = m_domainMap.uniqueKeys(); + + foreach (QChartAxis* axis , domainList) { + + Q_ASSERT(m_domainMap.values(axis).size()==1); + + Domain domain = m_domainMap.value(axis); + domain.m_minX=min; + domain.m_maxX=max; + m_domainMap.replace(axis,domain); + } + + } + else { + + QList domains = m_domainMap.values(axis); + m_domainMap.remove(axis); + + for(int i=0;i=0;j--) + m_domainMap.insert(axis,domains.at(j)); + } + setDomain(m_domainIndex); } void ChartDataSet::handleTickChanged(QChartAxis* axis) { - Domain domain = m_domainMap.value(axisY()); if(axis==axisX()){ + Domain domain = m_domainMap.value(axisY()); QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); emit axisRangeChanged(axis,labels); }else{ + Domain domain = m_domainMap.value(axis); QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); emit axisRangeChanged(axis,labels); } diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 75c4ab4..8116e67 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -39,8 +39,7 @@ signals: void seriesDomainChanged(QSeries* series,const Domain& domain); private slots: - void handleMinChanged(qreal min); - void handleMaxChanged(qreal max); + void handleRangeChanged(QChartAxis*); void handleTickChanged(QChartAxis*); private: diff --git a/src/linechart/qlineseries.cpp b/src/linechart/qlineseries.cpp index e38d046..a41b0ec 100644 --- a/src/linechart/qlineseries.cpp +++ b/src/linechart/qlineseries.cpp @@ -58,7 +58,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \fn void QLineSeries::updated(int index) + \fn void QLineSeries::updated() \brief \internal */ diff --git a/src/qchartaxis.cpp b/src/qchartaxis.cpp index 15d34bd..72b399f 100644 --- a/src/qchartaxis.cpp +++ b/src/qchartaxis.cpp @@ -130,6 +130,16 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \fn void QChartAxis::rangeChanged(QChartAxis*) + \brief \internal +*/ + +/*! + \fn void QChartAxis::updateRange(qreal min, qreal max) + \brief \internal \a min \a max +*/ + +/*! Constructs new axis object which is a child of \a parent. Ownership is taken by QChatView or QChart when axis added. */ @@ -274,25 +284,25 @@ void QChartAxis::setShadesOpacity(qreal opacity) } /*! - Sets \a min value on the axis. + Sets \a min value on the axis. */ void QChartAxis::setMin(qreal min) { - if(m_min!=min){ - m_min=min; - emit minChanged(m_min); - } + if(m_min!=min) { + m_min=min; + emit rangeChanged(this); + } } /*! - Sets \a max value on the axis. + Sets \a max value on the axis. */ void QChartAxis::setMax(qreal max) { - if(m_max!=max){ - m_max=max; - emit maxChanged(m_max); - } + if(m_max!=max) { + m_max=max; + emit rangeChanged(this); + } } /*! @@ -300,8 +310,22 @@ void QChartAxis::setMax(qreal max) */ void QChartAxis::setRange(qreal min, qreal max) { - setMin(min); - setMax(max); + setMin(min); + setMax(max); +} + +void QChartAxis::updateRange(qreal min, qreal max) +{ + if(m_max!=max){ + emit maxChanged(max); + } + + if(m_min!=min){ + emit minChanged(min); + } + + m_max=max; + m_min=min; } /*! diff --git a/src/qchartaxis.h b/src/qchartaxis.h index 98cb2ba..85e259c 100644 --- a/src/qchartaxis.h +++ b/src/qchartaxis.h @@ -64,11 +64,15 @@ public: QString axisTickLabel(qreal value) const ; void clearAxisTickLabels(); + //internal + void updateRange(qreal min, qreal max); + signals: void minChanged(qreal min); void maxChanged(qreal max); //private signal void update(QChartAxis*); + void rangeChanged(QChartAxis*); void ticksChanged(QChartAxis*); private: