From 1855aba16ab8008e10d9074f7719dedb91139283 2012-03-22 08:30:34 From: Michal Klocek Date: 2012-03-22 08:30:34 Subject: [PATCH] Changes public API for nice nuumbers -> setNiceNumbers(bool enabled) --- diff --git a/src/axis/qchartaxis.cpp b/src/axis/qchartaxis.cpp index 3a300a7..65216d7 100644 --- a/src/axis/qchartaxis.cpp +++ b/src/axis/qchartaxis.cpp @@ -150,7 +150,7 @@ m_shadesOpacity(1.0), m_min(0), m_max(0), m_ticksCount(5), -m_selection(NativeLabelsSelection) +m_niceNumbers(false) { } @@ -344,7 +344,7 @@ void QChartAxis::setRange(qreal min, qreal max) if(changed) { emit rangeChanged(m_min,m_max); - emit this->changed(m_min, m_max, m_ticksCount, m_selection); + emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers); } } @@ -356,7 +356,7 @@ void QChartAxis::setTicksCount(int count) if(m_ticksCount!=count) { m_ticksCount=count; emit ticksCountChanged(count); - emit changed(m_min, m_max, m_ticksCount, m_selection); + emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); } } @@ -390,11 +390,11 @@ void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count) setTicksCount(count); } -void QChartAxis::setLabelsSelectionMode(LabelsSelection mode) +void QChartAxis::setNiceNumbers(bool enabled) { - if(m_selection!=mode){ - m_selection=mode; - emit changed(m_min, m_max, m_ticksCount, m_selection); + if(m_niceNumbers!=enabled){ + m_niceNumbers=enabled; + emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); } } diff --git a/src/axis/qchartaxis.h b/src/axis/qchartaxis.h index 8dac320..3f78f4b 100644 --- a/src/axis/qchartaxis.h +++ b/src/axis/qchartaxis.h @@ -12,7 +12,6 @@ class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject { Q_OBJECT public: - enum LabelsSelection{ NativeLabelsSelection, LooseLabelsSelection}; QChartAxis(QObject* parent =0); ~QChartAxis(); @@ -62,8 +61,8 @@ public: void setTicksCount(int count); int ticksCount() const { return m_ticksCount;} - void setLabelsSelectionMode(LabelsSelection mode); - LabelsSelection labelsSelectionMode() const { return m_selection;} + void setNiceNumbers(bool enabled); + bool niceNumbers() const { return m_niceNumbers;} QChartAxisCategories* categories() { return &m_category; } @@ -78,7 +77,7 @@ signals: //interal signal void updated(); - void changed(qreal min, qreal max, int tickCount,QChartAxis::LabelsSelection mode); + void changed(qreal min, qreal max, int tickCount,bool niceNumbers); //internal slot public slots: void handleAxisRangeChanged(qreal min, qreal max,int count); @@ -108,7 +107,7 @@ private: int m_ticksCount; QChartAxisCategories m_category; - LabelsSelection m_selection; + bool m_niceNumbers; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/domain.cpp b/src/domain.cpp index f8677d2..4dc2e12 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -10,7 +10,7 @@ m_minY(0), m_maxY(0), m_tickXCount(5), m_tickYCount(5), -m_selection(QChartAxis::NativeLabelsSelection) +m_niceNumbers(false) { } @@ -40,7 +40,7 @@ void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo } if(m_minX!=minX || m_maxX!=maxX) { - niceNumbers(minX, maxX, m_tickXCount); + if(m_niceNumbers) looseNiceNumbers(minX, maxX, m_tickXCount); m_minX=minX; m_maxX=maxX; domainChanged=true; @@ -49,7 +49,7 @@ void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo } if(m_minY!=minY || m_maxY!=maxY) { - niceNumbers(minY, maxY, m_tickYCount); + if(m_niceNumbers) looseNiceNumbers(minY, maxY, m_tickYCount); m_minY=minY; m_maxY=maxY; domainChanged=true; @@ -137,8 +137,10 @@ void Domain::zoomIn(const QRectF& rect, const QSizeF& size) m_minY = m_maxY - dy * rect.bottom(); m_maxY = m_maxY - dy * rect.top(); - niceNumbers(m_minX, m_maxX, m_tickXCount); - niceNumbers(m_minY, m_maxY, m_tickYCount); + if(m_niceNumbers) { + looseNiceNumbers(m_minX, m_maxX, m_tickXCount); + looseNiceNumbers(m_minY, m_maxY, m_tickYCount); + } emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); emit rangeXChanged(m_minX, m_maxX, m_tickXCount); @@ -155,8 +157,10 @@ void Domain::zoomOut(const QRectF& rect, const QSizeF& size) m_maxY = m_minY + dy * rect.bottom(); m_minY = m_maxY - dy * size.height(); - niceNumbers(m_minX, m_maxX, m_tickXCount); - niceNumbers(m_minY, m_maxY, m_tickYCount); + if(m_niceNumbers) { + looseNiceNumbers(m_minX, m_maxX, m_tickXCount); + looseNiceNumbers(m_minY, m_maxY, m_tickYCount); + } emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); emit rangeXChanged(m_minX, m_maxX, m_tickXCount); @@ -182,26 +186,20 @@ void Domain::move(int dx,int dy,const QSizeF& size) emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); } -void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,QChartAxis::LabelsSelection mode) +void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers) { - m_selection=mode; + m_niceNumbers=niceNumbers; setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount); } -void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,QChartAxis::LabelsSelection mode) +void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers) { - m_selection=mode; + m_niceNumbers=niceNumbers; setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount); } //algorithm defined by Paul S.Heckbert GraphicalGems I -void Domain::niceNumbers(qreal &min, qreal &max, int &ticksCount) -{ - if(m_selection!=QChartAxis::NativeLabelsSelection) - looseNiceNumbers(min,max,ticksCount); -} - void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) { qreal range = niceNumber(max-min,true); //range with ceiling diff --git a/src/domain_p.h b/src/domain_p.h index 0a6c1ba..ecdec4a 100644 --- a/src/domain_p.h +++ b/src/domain_p.h @@ -1,7 +1,6 @@ #ifndef DOMAIN_H_ #define DOMAIN_H_ #include "qchartglobal.h" -#include "qchartaxis.h" #include #include @@ -50,11 +49,10 @@ signals: void rangeYChanged(qreal min, qreal max, int tickYCount); public slots: - void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,QChartAxis::LabelsSelection mode = QChartAxis::NativeLabelsSelection); - void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,QChartAxis::LabelsSelection mode = QChartAxis::NativeLabelsSelection); + void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,bool niceNumbers = false); + void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,bool niceNumbers = false); private: - void niceNumbers(qreal &min, qreal &max, int &ticksCount); void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); qreal niceNumber(qreal x,bool celing); @@ -65,7 +63,7 @@ private: qreal m_maxY; int m_tickXCount; int m_tickYCount; - QChartAxis::LabelsSelection m_selection; + bool m_niceNumbers; }; QTCOMMERCIALCHART_END_NAMESPACE