diff --git a/src/areachart/areachartitem.cpp b/src/areachart/areachartitem.cpp index 3e086bb..dadb980 100644 --- a/src/areachart/areachartitem.cpp +++ b/src/areachart/areachartitem.cpp @@ -23,6 +23,7 @@ #include "qareaseries_p.h" #include "qlineseries.h" #include "chartpresenter_p.h" +#include "domain_p.h" #include #include #include @@ -41,8 +42,9 @@ AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) { setZValue(ChartPresenter::LineChartZValue); m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); - if (m_series->lowerSeries()) + if (m_series->lowerSeries()){ m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); + } QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); @@ -100,11 +102,14 @@ void AreaChartItem::handleUpdated() update(); } -void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) +void AreaChartItem::handleDomainUpdated() { - m_upper->handleDomainChanged(minX,maxX,minY,maxY); - if (m_lower) - m_lower->handleDomainChanged(minX,maxX,minY,maxY); + m_upper->setDomain(domain()); + m_upper->handleDomainUpdated(); + if (m_lower){ + m_lower->setDomain(domain()); + m_lower->handleDomainUpdated(); + } } void AreaChartItem::handleGeometryChanged(const QRectF &rect) diff --git a/src/areachart/areachartitem_p.h b/src/areachart/areachartitem_p.h index 66d3823..6e87ca1 100644 --- a/src/areachart/areachartitem_p.h +++ b/src/areachart/areachartitem_p.h @@ -64,7 +64,7 @@ Q_SIGNALS: public Q_SLOTS: void handleUpdated(); - void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); + void handleDomainUpdated(); void handleGeometryChanged(const QRectF &size); private: diff --git a/src/areachart/qareaseries.cpp b/src/areachart/qareaseries.cpp index 88a3fdf..3d291c6 100644 --- a/src/areachart/qareaseries.cpp +++ b/src/areachart/qareaseries.cpp @@ -321,8 +321,6 @@ void QAreaSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); QLineSeries* upperSeries = q->upperSeries(); QLineSeries* lowerSeries = q->lowerSeries(); @@ -352,7 +350,7 @@ void QAreaSeriesPrivate::scaleDomain(Domain& domain) maxY = qMax(maxY, y); }} - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) diff --git a/src/axis/axis.pri b/src/axis/axis.pri index ce59901..5d41458 100644 --- a/src/axis/axis.pri +++ b/src/axis/axis.pri @@ -1,30 +1,16 @@ +include(valuesaxis/valuesaxis.pri) +include(categoriesaxis/categoriesaxis.pri) + INCLUDEPATH += $$PWD DEPENDPATH += $$PWD SOURCES += \ $$PWD/chartaxis.cpp \ - $$PWD/chartvaluesaxisx.cpp \ - $$PWD/chartvaluesaxisy.cpp \ - $$PWD/chartcategoriesaxisx.cpp \ - $$PWD/chartcategoriesaxisy.cpp \ - $$PWD/qbarcategoriesaxis.cpp \ - # $$PWD/qintervalaxis.cpp \ - $$PWD/qvaluesaxis.cpp \ $$PWD/qabstractaxis.cpp PRIVATE_HEADERS += \ $$PWD/chartaxis_p.h \ - $$PWD/chartvaluesaxisx_p.h \ - $$PWD/chartvaluesaxisy_p.h \ - $$PWD/chartcategoriesaxisx_p.h \ - $$PWD/chartcategoriesaxisy_p.h \ - $$PWD/qbarcategoriesaxis_p.h \ - # $$PWD/qintervalaxis_p.h \ - $$PWD/qvaluesaxis_p.h \ $$PWD/qabstractaxis_p.h PUBLIC_HEADERS += \ - $$PWD/qbarcategoriesaxis.h \ -# $$PWD/qintervalaxis.h \ - $$PWD/qvaluesaxis.h \ $$PWD/qabstractaxis.h diff --git a/src/axis/categoriesaxis/categoriesaxis.pri b/src/axis/categoriesaxis/categoriesaxis.pri new file mode 100644 index 0000000..2a40483 --- /dev/null +++ b/src/axis/categoriesaxis/categoriesaxis.pri @@ -0,0 +1,15 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +SOURCES += \ + $$PWD/chartcategoriesaxisx.cpp \ + $$PWD/chartcategoriesaxisy.cpp \ + $$PWD/qbarcategoriesaxis.cpp + +PRIVATE_HEADERS += \ + $$PWD/chartcategoriesaxisx_p.h \ + $$PWD/chartcategoriesaxisy_p.h \ + $$PWD/qbarcategoriesaxis_p.h + +PUBLIC_HEADERS += \ + $$PWD/qbarcategoriesaxis.h \ No newline at end of file diff --git a/src/axis/chartcategoriesaxisx.cpp b/src/axis/categoriesaxis/chartcategoriesaxisx.cpp similarity index 96% rename from src/axis/chartcategoriesaxisx.cpp rename to src/axis/categoriesaxis/chartcategoriesaxisx.cpp index 318fa55..fdffe51 100644 --- a/src/axis/chartcategoriesaxisx.cpp +++ b/src/axis/categoriesaxis/chartcategoriesaxisx.cpp @@ -41,14 +41,14 @@ ChartCategoriesAxisX::~ChartCategoriesAxisX() QVector ChartCategoriesAxisX::calculateLayout() const { - Q_ASSERT(m_ticksCount>=2); + Q_ASSERT(m_categoriesAxis->categories().count()>=2); QVector points; - points.resize(m_ticksCount); + points.resize(m_categoriesAxis->categories().count()); // TODO: shift logic - const qreal deltaX = m_rect.width()/(m_ticksCount-1); - for (int i = 0; i < m_ticksCount; ++i) { + const qreal deltaX = m_rect.width()/(m_categoriesAxis->categories().count()-1); + for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { int x = i * deltaX + m_rect.left(); points[i] = x; } diff --git a/src/axis/chartcategoriesaxisx_p.h b/src/axis/categoriesaxis/chartcategoriesaxisx_p.h similarity index 100% rename from src/axis/chartcategoriesaxisx_p.h rename to src/axis/categoriesaxis/chartcategoriesaxisx_p.h diff --git a/src/axis/chartcategoriesaxisy.cpp b/src/axis/categoriesaxis/chartcategoriesaxisy.cpp similarity index 96% rename from src/axis/chartcategoriesaxisy.cpp rename to src/axis/categoriesaxis/chartcategoriesaxisy.cpp index 49c880b..af3aa83 100644 --- a/src/axis/chartcategoriesaxisy.cpp +++ b/src/axis/categoriesaxis/chartcategoriesaxisy.cpp @@ -41,13 +41,13 @@ ChartCategoriesAxisY::~ChartCategoriesAxisY() QVector ChartCategoriesAxisY::calculateLayout() const { - Q_ASSERT(m_ticksCount>=2); + Q_ASSERT(m_categoriesAxis->categories().count()>=2); QVector points; - points.resize(m_ticksCount); + points.resize(m_categoriesAxis->categories().count()); - const qreal deltaY = m_rect.height()/(m_ticksCount-1); - for (int i = 0; i < m_ticksCount; ++i) { + const qreal deltaY = m_rect.height()/(m_categoriesAxis->categories().count()-1); + for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { int y = i * -deltaY + m_rect.bottom(); points[i] = y; } diff --git a/src/axis/chartcategoriesaxisy_p.h b/src/axis/categoriesaxis/chartcategoriesaxisy_p.h similarity index 100% rename from src/axis/chartcategoriesaxisy_p.h rename to src/axis/categoriesaxis/chartcategoriesaxisy_p.h diff --git a/src/axis/qbarcategoriesaxis.cpp b/src/axis/categoriesaxis/qbarcategoriesaxis.cpp similarity index 92% rename from src/axis/qbarcategoriesaxis.cpp rename to src/axis/categoriesaxis/qbarcategoriesaxis.cpp index aeac932..351e4fb 100644 --- a/src/axis/qbarcategoriesaxis.cpp +++ b/src/axis/categoriesaxis/qbarcategoriesaxis.cpp @@ -251,7 +251,12 @@ QString QBarCategoriesAxis::at(int index) const void QBarCategoriesAxis::setMin(const QString& min) { Q_D(QBarCategoriesAxis); - setRange(min,d->m_maxCategory); + if (d->m_minCategory!=min && d->m_categories.contains(min)) { + d->m_minCategory = min; + d->emitUpdated(); + emit minChanged(min); + } + } /*! @@ -269,7 +274,12 @@ QString QBarCategoriesAxis::min() const void QBarCategoriesAxis::setMax(const QString& max) { Q_D(QBarCategoriesAxis); - setRange(d->m_minCategory,max); + if (d->m_maxCategory!=max && d->m_categories.contains(max)) { + d->m_maxCategory = max; + d->emitUpdated(); + emit maxChanged(max); + } + } /*! @@ -286,40 +296,8 @@ QString QBarCategoriesAxis::max() const */ void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) { - Q_D(QBarCategoriesAxis); - - int minIndex = d->m_categories.indexOf(minCategory); - if (minIndex == -1) { - return; - } - int maxIndex = d->m_categories.indexOf(maxCategory); - if (maxIndex == -1) { - return; - } - - if (maxIndex <= minIndex) { - // max must be greater than min - return; - } - - bool changed = false; - if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { - d->m_minCategory = minCategory; - d->m_min = minIndex; - emit minChanged(minCategory); - changed = true; - } - - if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { - d->m_max = maxIndex; - d->m_maxCategory = maxCategory; - emit maxChanged(maxCategory); - changed = true; - } - - if (changed) { - d->emitRange(); - } + setMin(minCategory); + setMax(maxCategory); } /*! @@ -361,17 +339,22 @@ void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &ma q->setRange(value1,value2); } -int QBarCategoriesAxisPrivate::ticksCount() const +qreal QBarCategoriesAxisPrivate::min() +{ + //TODO:: cache it + return m_categories.indexOf(m_minCategory) + 0.5; +} + +qreal QBarCategoriesAxisPrivate::max() { - return m_categories.count()+1; + //TODO:: cache it + return m_categories.indexOf(m_maxCategory) + 0.5; } -void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) +void QBarCategoriesAxisPrivate::handleDomainUpdated() { // Q_Q(QBarCategoriesAxis); - m_min = min; - m_max = max; - m_ticksCount = count; + // TODO: causes crash in some situations. added to known issues /* int minIndex = qFloor(min); @@ -416,10 +399,12 @@ ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) } } +/* void QBarCategoriesAxisPrivate::emitRange() { emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); } +*/ void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) { diff --git a/src/axis/qbarcategoriesaxis.h b/src/axis/categoriesaxis/qbarcategoriesaxis.h similarity index 100% rename from src/axis/qbarcategoriesaxis.h rename to src/axis/categoriesaxis/qbarcategoriesaxis.h diff --git a/src/axis/qbarcategoriesaxis_p.h b/src/axis/categoriesaxis/qbarcategoriesaxis_p.h similarity index 92% rename from src/axis/qbarcategoriesaxis_p.h rename to src/axis/categoriesaxis/qbarcategoriesaxis_p.h index 16e7c77..6a237bb 100644 --- a/src/axis/qbarcategoriesaxis_p.h +++ b/src/axis/categoriesaxis/qbarcategoriesaxis_p.h @@ -48,20 +48,15 @@ public: public: ChartAxis* createGraphics(ChartPresenter* presenter); void intializeDomain(Domain* domain); - void emitRange(); + void handleDomainUpdated(); + qreal min(); + qreal max(); private: //range handling void setMin(const QVariant &min); void setMax(const QVariant &max); void setRange(const QVariant &min, const QVariant &max); - int ticksCount() const; - -Q_SIGNALS: - void changed(qreal min, qreal max, int tickCount,bool niceNumbers); - -public Q_SLOTS: - void handleAxisRangeChanged(qreal min, qreal max,int count); private: QStringList m_categories; diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index e3d2705..69d85e1 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -23,6 +23,7 @@ #include "qabstractaxis_p.h" #include "chartpresenter_p.h" #include "chartanimator_p.h" +#include "domain_p.h" #include #include #include @@ -38,7 +39,6 @@ ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres m_axis(new QGraphicsItemGroup(presenter->rootItem())), m_min(0), m_max(0), - m_ticksCount(0), m_animation(0), m_minWidth(0), m_minHeight(0) @@ -54,8 +54,6 @@ ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres QGraphicsSimpleTextItem item; m_font = item.font(); - - handleAxisUpdated(); } ChartAxis::~ChartAxis() @@ -110,7 +108,7 @@ void ChartAxis::updateLayout(QVector &layout) createItems(-diff); } - if( diff!=0) handleAxisUpdated(); + if(diff<0) handleAxisUpdated(); if (m_animation) { switch(presenter()->state()){ @@ -244,21 +242,40 @@ void ChartAxis::setGridPen(const QPen &pen) bool ChartAxis::isEmpty() { - return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; + return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max); } -//handlers - -void ChartAxis::handleAxisCategoriesUpdated() +void ChartAxis::handleDomainUpdated() { - if (isEmpty()) return; - updateLayout(m_layoutVector); + Domain* domain = qobject_cast(sender()); + qreal min(0); + qreal max(0); + + if(m_chartAxis->orientation()==Qt::Horizontal) { + min = domain->minX(); + max = domain->maxX(); + } + else if (m_chartAxis->orientation()==Qt::Vertical) + { + min = domain->minY(); + max = domain->maxY(); + } + + if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) + { + m_min = min; + m_max = max; + + if (!isEmpty()) { + QVector layout = calculateLayout(); + updateLayout(layout); + } + } } void ChartAxis::handleAxisUpdated() { - - if (isEmpty()) return; + if(isEmpty()) return; if (!m_chartAxis->isVisible()) { setAxisOpacity(0); @@ -296,6 +313,7 @@ void ChartAxis::handleAxisUpdated() setShadesOpacity(0); } } + setLabelsAngle(m_chartAxis->labelsAngle()); setAxisPen(m_chartAxis->axisPen()); setLabelsPen(m_chartAxis->labelsPen()); @@ -307,20 +325,6 @@ void ChartAxis::handleAxisUpdated() } -void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) -{ - if (qFuzzyIsNull(min - max) || tickCount < 2) - return; - - m_min = min; - m_max = max; - m_ticksCount= tickCount; - - if (isEmpty()) return; - QVector layout = calculateLayout(); - updateLayout(layout); -} - void ChartAxis::handleGeometryChanged(const QRectF &rect) { if(m_rect != rect) @@ -374,7 +378,7 @@ void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,co int count = 0; // Try to find category for x coordinate - while (count < m_ticksCount) { + while (count < categories.count()) { if ((x < categories.count()) && (x >= 0)) { labels << categories.at(x); } else { diff --git a/src/axis/chartaxis_p.h b/src/axis/chartaxis_p.h index e0bd406..eb44c6c 100644 --- a/src/axis/chartaxis_p.h +++ b/src/axis/chartaxis_p.h @@ -96,8 +96,7 @@ protected: public Q_SLOTS: virtual void handleAxisUpdated(); - void handleAxisCategoriesUpdated(); - void handleRangeChanged(qreal min , qreal max,int tickCount); + virtual void handleDomainUpdated(); void handleGeometryChanged(const QRectF &size); private: @@ -118,7 +117,6 @@ protected: QVector m_layoutVector; qreal m_min; qreal m_max; - int m_ticksCount; AxisAnimation *m_animation; qreal m_minWidth; qreal m_minHeight; diff --git a/src/axis/intervalsaxis/intervalsaxis.pri b/src/axis/intervalsaxis/intervalsaxis.pri new file mode 100644 index 0000000..66c2c0b --- /dev/null +++ b/src/axis/intervalsaxis/intervalsaxis.pri @@ -0,0 +1,12 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +SOURCES += \ + $$PWD/qintervalsaxis.cpp + + +PRIVATE_HEADERS += \ + $$PWD/qintervalaxis_p.h + +PUBLIC_HEADERS += \ + $$PWD/qintervalaxis.h diff --git a/src/axis/qintervalaxis.cpp b/src/axis/intervalsaxis/qintervalaxis.cpp similarity index 100% rename from src/axis/qintervalaxis.cpp rename to src/axis/intervalsaxis/qintervalaxis.cpp diff --git a/src/axis/qintervalaxis.h b/src/axis/intervalsaxis/qintervalaxis.h similarity index 100% rename from src/axis/qintervalaxis.h rename to src/axis/intervalsaxis/qintervalaxis.h diff --git a/src/axis/qintervalaxis_p.h b/src/axis/intervalsaxis/qintervalaxis_p.h similarity index 100% rename from src/axis/qintervalaxis_p.h rename to src/axis/intervalsaxis/qintervalaxis_p.h diff --git a/src/axis/qabstractaxis.cpp b/src/axis/qabstractaxis.cpp index f7f7294..9d5bb81 100644 --- a/src/axis/qabstractaxis.cpp +++ b/src/axis/qabstractaxis.cpp @@ -279,7 +279,7 @@ void QAbstractAxis::setAxisPen(const QPen &pen) { if (d_ptr->m_axisPen!=pen) { d_ptr->m_axisPen = pen; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -313,7 +313,7 @@ void QAbstractAxis::setArrowVisible(bool visible) { if (d_ptr->m_arrowVisible != visible) { d_ptr->m_arrowVisible = visible; - emit d_ptr->updated(); + d_ptr->emitUpdated(); emit arrowVisibleChanged(visible); } } @@ -327,7 +327,7 @@ void QAbstractAxis::setGridLineVisible(bool visible) { if (d_ptr->m_gridLineVisible != visible) { d_ptr->m_gridLineVisible = visible; - emit d_ptr->updated(); + d_ptr->emitUpdated(); emit gridVisibleChanged(visible); } } @@ -344,7 +344,7 @@ void QAbstractAxis::setGridLinePen(const QPen &pen) { if (d_ptr->m_gridLinePen != pen) { d_ptr->m_gridLinePen = pen; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -360,7 +360,7 @@ void QAbstractAxis::setLabelsVisible(bool visible) { if (d_ptr->m_labelsVisible != visible) { d_ptr->m_labelsVisible = visible; - emit d_ptr->updated(); + d_ptr->emitUpdated(); emit labelsVisibleChanged(visible); } } @@ -377,7 +377,7 @@ void QAbstractAxis::setLabelsPen(const QPen &pen) { if (d_ptr->m_labelsPen != pen) { d_ptr->m_labelsPen = pen; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -396,7 +396,7 @@ void QAbstractAxis::setLabelsBrush(const QBrush &brush) { if (d_ptr->m_labelsBrush != brush) { d_ptr->m_labelsBrush = brush; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -415,7 +415,7 @@ void QAbstractAxis::setLabelsFont(const QFont &font) { if (d_ptr->m_labelsFont != font) { d_ptr->m_labelsFont = font; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -431,7 +431,7 @@ void QAbstractAxis::setLabelsAngle(int angle) { if (d_ptr->m_labelsAngle != angle) { d_ptr->m_labelsAngle = angle; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -459,7 +459,7 @@ void QAbstractAxis::setShadesVisible(bool visible) { if (d_ptr->m_shadesVisible != visible) { d_ptr->m_shadesVisible = visible; - emit d_ptr->updated(); + d_ptr->emitUpdated(); emit shadesVisibleChanged(visible); } } @@ -476,7 +476,7 @@ void QAbstractAxis::setShadesPen(const QPen &pen) { if (d_ptr->m_shadesPen != pen) { d_ptr->m_shadesPen = pen; - emit d_ptr->updated(); + d_ptr->emitUpdated(); } } @@ -495,7 +495,7 @@ void QAbstractAxis::setShadesBrush(const QBrush &brush) { if (d_ptr->m_shadesBrush != brush) { d_ptr->m_shadesBrush = brush; - emit d_ptr->updated(); + d_ptr->emitUpdated(); emit shadesColorChanged(brush.color()); } } @@ -545,8 +545,8 @@ void QAbstractAxis::setVisible(bool visible) { if(d_ptr->m_visible!=visible){ d_ptr->m_visible=visible; + d_ptr->emitUpdated(); emit visibleChanged(visible); - emit d_ptr->updated(); } } @@ -607,6 +607,7 @@ Qt::Orientation QAbstractAxis::orientation() QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): q_ptr(q), + m_orientation(Qt::Orientation(0)), m_visible(false), m_arrowVisible(true), m_gridLineVisible(true), @@ -615,10 +616,7 @@ QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): m_shadesVisible(false), m_shadesBrush(Qt::SolidPattern), m_shadesOpacity(1.0), - m_orientation(Qt::Orientation(0)), - m_min(0), - m_max(0), - m_ticksCount(5) + m_dirty(false) { } @@ -628,6 +626,25 @@ QAbstractAxisPrivate::~QAbstractAxisPrivate() } +void QAbstractAxisPrivate::emitUpdated() +{ + if(!m_dirty){ + m_dirty=true; + emit updated(); + } +} + +void QAbstractAxisPrivate::setDirty(bool dirty) +{ + m_dirty=dirty; +} + +void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) +{ + m_orientation=orientation; +} + + #include "moc_qabstractaxis.cpp" #include "moc_qabstractaxis_p.cpp" diff --git a/src/axis/qabstractaxis_p.h b/src/axis/qabstractaxis_p.h index 2b43d04..ac57082 100644 --- a/src/axis/qabstractaxis_p.h +++ b/src/axis/qabstractaxis_p.h @@ -38,29 +38,43 @@ class ChartPresenter; class ChartAxis; class Domain; -class QAbstractAxisPrivate : public QObject +class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject { Q_OBJECT public: QAbstractAxisPrivate(QAbstractAxis *q); ~QAbstractAxisPrivate(); -Q_SIGNALS: - void updated(); - public: + virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; - virtual void emitRange() = 0; virtual void intializeDomain(Domain* domain) = 0; -protected: + void emitUpdated(); + void setDirty(bool dirty); + bool isDirty(){ return m_dirty; }; + void setOrientation(Qt::Orientation orientation); + Qt::Orientation orientation() const { return m_orientation; } + virtual void setMin(const QVariant &min) = 0; + virtual qreal min() = 0; + virtual void setMax(const QVariant &max) = 0; + virtual qreal max() = 0; + virtual void setRange(const QVariant &min, const QVariant &max) = 0; - virtual int ticksCount() const = 0; -public: +public Q_SLOTS: + virtual void handleDomainUpdated() = 0; + +Q_SIGNALS: + void updated(); + +protected: QAbstractAxis *q_ptr; + Qt::Orientation m_orientation; + +private: bool m_visible; bool m_arrowVisible; @@ -81,12 +95,7 @@ public: QBrush m_shadesBrush; qreal m_shadesOpacity; - Qt::Orientation m_orientation; - - // range - qreal m_min; - qreal m_max; - int m_ticksCount; + bool m_dirty; friend class QAbstractAxis; }; diff --git a/src/axis/chartvaluesaxisx.cpp b/src/axis/valuesaxis/chartvaluesaxisx.cpp similarity index 90% rename from src/axis/chartvaluesaxisx.cpp rename to src/axis/valuesaxis/chartvaluesaxisx.cpp index f086cea..3d41a60 100644 --- a/src/axis/chartvaluesaxisx.cpp +++ b/src/axis/valuesaxis/chartvaluesaxisx.cpp @@ -22,6 +22,7 @@ #include "qabstractaxis.h" #include "chartpresenter_p.h" #include "chartanimator_p.h" +#include "qvaluesaxis.h" #include #include #include @@ -31,7 +32,8 @@ static int label_padding = 5; QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) +ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), +m_tickCount(0) { } @@ -41,13 +43,13 @@ ChartValuesAxisX::~ChartValuesAxisX() QVector ChartValuesAxisX::calculateLayout() const { - Q_ASSERT(m_ticksCount>=2); + Q_ASSERT(m_tickCount>=2); QVector points; - points.resize(m_ticksCount); + points.resize(m_tickCount); - const qreal deltaX = m_rect.width()/(m_ticksCount-1); - for (int i = 0; i < m_ticksCount; ++i) { + const qreal deltaX = m_rect.width()/(m_tickCount-1); + for (int i = 0; i < m_tickCount; ++i) { int x = i * deltaX + m_rect.left(); points[i] = x; } @@ -109,4 +111,12 @@ void ChartValuesAxisX::updateGeometry() } } +void ChartValuesAxisX::handleAxisUpdated() +{ + //TODO:: fix this + QValuesAxis* axis = qobject_cast(m_chartAxis); + m_tickCount = axis->ticksCount(); + ChartAxis::handleAxisUpdated(); +} + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartvaluesaxisx_p.h b/src/axis/valuesaxis/chartvaluesaxisx_p.h similarity index 96% rename from src/axis/chartvaluesaxisx_p.h rename to src/axis/valuesaxis/chartvaluesaxisx_p.h index 0723820..14791f5 100644 --- a/src/axis/chartvaluesaxisx_p.h +++ b/src/axis/valuesaxis/chartvaluesaxisx_p.h @@ -46,11 +46,12 @@ public: AxisType axisType() const { return X_AXIS;} protected: + void handleAxisUpdated(); QVector calculateLayout() const; void updateGeometry(); private: - void createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; + int m_tickCount; }; diff --git a/src/axis/chartvaluesaxisy.cpp b/src/axis/valuesaxis/chartvaluesaxisy.cpp similarity index 90% rename from src/axis/chartvaluesaxisy.cpp rename to src/axis/valuesaxis/chartvaluesaxisy.cpp index b2d54c7..c7d1fed 100644 --- a/src/axis/chartvaluesaxisy.cpp +++ b/src/axis/valuesaxis/chartvaluesaxisy.cpp @@ -22,6 +22,7 @@ #include "qabstractaxis.h" #include "chartpresenter_p.h" #include "chartanimator_p.h" +#include "qvaluesaxis.h" #include #include #include @@ -31,7 +32,8 @@ static int label_padding = 5; QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) +ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), +m_tickCount(0) { } @@ -41,13 +43,13 @@ ChartValuesAxisY::~ChartValuesAxisY() QVector ChartValuesAxisY::calculateLayout() const { - Q_ASSERT(m_ticksCount>=2); + Q_ASSERT(m_tickCount>=2); QVector points; - points.resize(m_ticksCount); + points.resize(m_tickCount); - const qreal deltaY = m_rect.height()/(m_ticksCount-1); - for (int i = 0; i < m_ticksCount; ++i) { + const qreal deltaY = m_rect.height()/(m_tickCount-1); + for (int i = 0; i < m_tickCount; ++i) { int y = i * -deltaY + m_rect.bottom(); points[i] = y; } @@ -114,4 +116,13 @@ void ChartValuesAxisY::updateGeometry() } } +void ChartValuesAxisY::handleAxisUpdated() +{ + //TODO:: fix this + QValuesAxis* axis = qobject_cast(m_chartAxis); + m_tickCount = axis->ticksCount(); + ChartAxis::handleAxisUpdated(); +} + + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartvaluesaxisy_p.h b/src/axis/valuesaxis/chartvaluesaxisy_p.h similarity index 96% rename from src/axis/chartvaluesaxisy_p.h rename to src/axis/valuesaxis/chartvaluesaxisy_p.h index 9f643cf..809e0a9 100644 --- a/src/axis/chartvaluesaxisy_p.h +++ b/src/axis/valuesaxis/chartvaluesaxisy_p.h @@ -48,6 +48,9 @@ public: protected: QVector calculateLayout() const; void updateGeometry(); + void handleAxisUpdated(); +private: + int m_tickCount; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/qvaluesaxis.cpp b/src/axis/valuesaxis/qvaluesaxis.cpp similarity index 82% rename from src/axis/qvaluesaxis.cpp rename to src/axis/valuesaxis/qvaluesaxis.cpp index 8b3c4a1..0bdfed8 100644 --- a/src/axis/qvaluesaxis.cpp +++ b/src/axis/valuesaxis/qvaluesaxis.cpp @@ -23,6 +23,7 @@ #include "chartvaluesaxisx_p.h" #include "chartvaluesaxisy_p.h" #include "domain_p.h" +#include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -172,6 +173,7 @@ void QValuesAxis::setRange(qreal min, qreal max) { Q_D(QValuesAxis); bool changed = false; + if (!qFuzzyIsNull(d->m_min - min)) { d->m_min = min; changed = true; @@ -184,9 +186,11 @@ void QValuesAxis::setRange(qreal min, qreal max) emit maxChanged(max); } + if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); + if (changed) { - d->emitRange(); emit rangeChanged(d->m_min,d->m_max); + d->emitUpdated(); } } @@ -196,9 +200,9 @@ void QValuesAxis::setRange(qreal min, qreal max) void QValuesAxis::setTicksCount(int count) { Q_D(QValuesAxis); - if (d->m_ticksCount != count) { - d->m_ticksCount = count; - emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); + if (d->m_tickCount != count) { + d->m_tickCount = count; + d->emitUpdated(); } } @@ -209,7 +213,7 @@ void QValuesAxis::setTicksCount(int count) int QValuesAxis::ticksCount() const { Q_D(const QValuesAxis); - return d->m_ticksCount; + return d->m_tickCount; } void QValuesAxis::setNiceNumbersEnabled(bool enable) @@ -217,7 +221,7 @@ void QValuesAxis::setNiceNumbersEnabled(bool enable) Q_D(QValuesAxis); if (d->m_niceNumbers != enable){ d->m_niceNumbers = enable; - emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); + if(enable) setRange(d->min(),d->max()); } } @@ -239,6 +243,9 @@ QAbstractAxis::AxisType QValuesAxis::type() const QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): QAbstractAxisPrivate(q), + m_min(0), + m_max(0), + m_tickCount(5), m_niceNumbers(false) { @@ -249,11 +256,17 @@ QValuesAxisPrivate::~QValuesAxisPrivate() } -void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) +void QValuesAxisPrivate::handleDomainUpdated() { Q_Q(QValuesAxis); - q->setRange(min,max); - q->setTicksCount(count); + Domain* domain = qobject_cast(sender()); + Q_ASSERT(domain); + + if(orientation()==Qt::Horizontal){ + q->setRange(domain->minX(),domain->maxX()); + }else if(orientation()==Qt::Vertical){ + q->setRange(domain->minY(),domain->maxY()); + } } @@ -284,11 +297,6 @@ void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) if(ok1&&ok2) q->setRange(value1,value2); } -int QValuesAxisPrivate::ticksCount() const -{ - return m_ticksCount; -} - ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) { Q_Q(QValuesAxis); @@ -300,26 +308,54 @@ ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) } -void QValuesAxisPrivate::emitRange() -{ - emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); -} - void QValuesAxisPrivate::intializeDomain(Domain* domain) { if(qFuzzyCompare(m_max,m_min)) { if(m_orientation==Qt::Vertical){ m_min = domain->minY(); m_max = domain->maxY(); - m_ticksCount = domain->tickYCount(); }else{ m_min = domain->minX(); m_max = domain->maxX(); - m_ticksCount = domain->tickXCount(); } } } +//algorithm defined by Paul S.Heckbert GraphicalGems I + +void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const +{ + qreal range = niceNumber(max-min,true); //range with ceiling + qreal step = niceNumber(range/(ticksCount-1),false); + min = floor(min/step); + max = ceil(max/step); + ticksCount = int(max-min) +1; + min*=step; + max*=step; +} + +//nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n + +qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const +{ + qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x + qreal q = x/z;//q<10 && q>=1; + + if(ceiling) { + if(q <= 1.0) q=1; + else if(q <= 2.0) q=2; + else if(q <= 5.0) q=5; + else q=10; + } + else { + if(q < 1.5) q=1; + else if(q < 3.0) q=2; + else if(q < 7.0) q=5; + else q=10; + } + return q*z; +} + #include "moc_qvaluesaxis.cpp" #include "moc_qvaluesaxis_p.cpp" diff --git a/src/axis/qvaluesaxis.h b/src/axis/valuesaxis/qvaluesaxis.h similarity index 100% rename from src/axis/qvaluesaxis.h rename to src/axis/valuesaxis/qvaluesaxis.h diff --git a/src/axis/qvaluesaxis_p.h b/src/axis/valuesaxis/qvaluesaxis_p.h similarity index 88% rename from src/axis/qvaluesaxis_p.h rename to src/axis/valuesaxis/qvaluesaxis_p.h index e3c5b17..8b7e71c 100644 --- a/src/axis/qvaluesaxis_p.h +++ b/src/axis/valuesaxis/qvaluesaxis_p.h @@ -42,16 +42,12 @@ public: QValuesAxisPrivate(QValuesAxis *q); ~QValuesAxisPrivate(); -Q_SIGNALS: - void changed(qreal min, qreal max, int tickCount,bool niceNumbers); - -public Q_SLOTS: - void handleAxisRangeChanged(qreal min, qreal max,int count); - public: ChartAxis* createGraphics(ChartPresenter* presenter); void intializeDomain(Domain* domain); - void emitRange(); + void handleDomainUpdated(); + qreal min(){ return m_min; }; + qreal max(){ return m_max; }; protected: void setMin(const QVariant &min); @@ -60,6 +56,13 @@ protected: int ticksCount() const; private: + void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const; + qreal niceNumber(qreal x,bool ceiling) const; + +private: + qreal m_min; + qreal m_max; + int m_tickCount; bool m_niceNumbers; Q_DECLARE_PUBLIC(QValuesAxis) }; diff --git a/src/axis/valuesaxis/valuesaxis.pri b/src/axis/valuesaxis/valuesaxis.pri new file mode 100644 index 0000000..18c037a --- /dev/null +++ b/src/axis/valuesaxis/valuesaxis.pri @@ -0,0 +1,15 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +SOURCES += \ + $$PWD/chartvaluesaxisx.cpp \ + $$PWD/chartvaluesaxisy.cpp \ + $$PWD/qvaluesaxis.cpp \ + +PRIVATE_HEADERS += \ + $$PWD/chartvaluesaxisx_p.h \ + $$PWD/chartvaluesaxisy_p.h \ + $$PWD/qvaluesaxis_p.h + +PUBLIC_HEADERS += \ + $$PWD/qvaluesaxis.h \ No newline at end of file diff --git a/src/barchart/abstractbarchartitem.cpp b/src/barchart/abstractbarchartitem.cpp index 6acf10b..3ce5e82 100644 --- a/src/barchart/abstractbarchartitem.cpp +++ b/src/barchart/abstractbarchartitem.cpp @@ -85,7 +85,7 @@ void AbstractBarChartItem::setLayout(const QVector &layout) if (layout.count() != m_bars.count()) return; - m_layout = layout; + m_layout = layout; for (int i=0; i < m_bars.count(); i++) { m_bars.at(i)->setRect(layout.at(i)); @@ -93,12 +93,12 @@ void AbstractBarChartItem::setLayout(const QVector &layout) } //handlers -void AbstractBarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) +void AbstractBarChartItem::handleDomainUpdated() { - m_domainMinX = minX; - m_domainMaxX = maxX; - m_domainMinY = minY; - m_domainMaxY = maxY; + m_domainMinX = domain()->minX(); + m_domainMaxX = domain()->maxX(); + m_domainMinY = domain()->minY(); + m_domainMaxY = domain()->maxY(); handleLayoutChanged(); } diff --git a/src/barchart/abstractbarchartitem_p.h b/src/barchart/abstractbarchartitem_p.h index 5b9699b..c9d3a37 100644 --- a/src/barchart/abstractbarchartitem_p.h +++ b/src/barchart/abstractbarchartitem_p.h @@ -59,12 +59,10 @@ public: virtual void setAnimation(AbstractBarAnimation* animation); void setLayout(const QVector &layout); void updateLayout(const QVector &layout); - - QRectF geometry() const { return m_rect;} public Q_SLOTS: - void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); + void handleDomainUpdated(); void handleGeometryChanged(const QRectF &size); void handleLayoutChanged(); void handleLabelsVisibleChanged(bool visible); diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 85df10a..deabc73 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -561,8 +561,6 @@ void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal seriesMinX = this->minX(); qreal seriesMaxX = this->maxX(); @@ -571,9 +569,8 @@ void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) minY = qMin(minY, y); maxX = qMax(maxX, seriesMaxX + (qreal)0.5); maxY = qMax(maxY, y); - tickXCount = categoryCount()+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 8292405..2b8814f 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -85,8 +85,6 @@ void QBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal x = categoryCount(); qreal y = max(); @@ -94,9 +92,8 @@ void QBarSeriesPrivate::scaleDomain(Domain& domain) minY = qMin(minY, y); maxX = qMax(maxX, x - (qreal)0.5); maxY = qMax(maxY, y); - tickXCount = x+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } diff --git a/src/barchart/qhorizontalbarseries.cpp b/src/barchart/qhorizontalbarseries.cpp index d11366b..e69c4b5 100644 --- a/src/barchart/qhorizontalbarseries.cpp +++ b/src/barchart/qhorizontalbarseries.cpp @@ -35,8 +35,6 @@ void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal y = categoryCount(); qreal x = max(); @@ -44,9 +42,8 @@ void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) minY = qMin(minY, - (qreal)0.5); maxX = qMax(maxX, x); maxY = qMax(maxY, y - (qreal)0.5); - tickYCount = y+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } diff --git a/src/barchart/qhorizontalpercentbarseries.cpp b/src/barchart/qhorizontalpercentbarseries.cpp index 244ce02..69db799 100644 --- a/src/barchart/qhorizontalpercentbarseries.cpp +++ b/src/barchart/qhorizontalpercentbarseries.cpp @@ -33,17 +33,14 @@ void QHorizontalPercentBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal y = categoryCount(); minX = 0; maxX = 100; minY = qMin(minY, - (qreal)0.5); maxY = qMax(maxY, y - (qreal)0.5); - tickYCount = y+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) diff --git a/src/barchart/qhorizontalstackedbarseries.cpp b/src/barchart/qhorizontalstackedbarseries.cpp index aa2521c..f39d15d 100644 --- a/src/barchart/qhorizontalstackedbarseries.cpp +++ b/src/barchart/qhorizontalstackedbarseries.cpp @@ -33,8 +33,6 @@ void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal y = categoryCount(); qreal x = maxCategorySum(); @@ -42,9 +40,8 @@ void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain& domain) minY = qMin(minY, - (qreal)0.5); maxX = qMax(maxX, x); maxY = qMax(maxY, y - (qreal)0.5); - tickYCount = y+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } Chart* QHorizontalStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) diff --git a/src/barchart/qpercentbarseries.cpp b/src/barchart/qpercentbarseries.cpp index 477e9ad..aa52c78 100644 --- a/src/barchart/qpercentbarseries.cpp +++ b/src/barchart/qpercentbarseries.cpp @@ -85,17 +85,14 @@ void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal x = categoryCount(); minX = qMin(minX, - (qreal)0.5); maxX = qMax(maxX, x - (qreal)0.5); minY = 0; maxY = 100; - tickXCount = x+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } diff --git a/src/barchart/qstackedbarseries.cpp b/src/barchart/qstackedbarseries.cpp index 949c7da..9170293 100644 --- a/src/barchart/qstackedbarseries.cpp +++ b/src/barchart/qstackedbarseries.cpp @@ -86,8 +86,6 @@ void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) qreal minY(domain.minY()); qreal maxX(domain.maxX()); qreal maxY(domain.maxY()); - int tickXCount(domain.tickXCount()); - int tickYCount(domain.tickYCount()); qreal x = categoryCount(); qreal y = maxCategorySum(); @@ -95,9 +93,8 @@ void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) minY = qMin(minY, y); maxX = qMax(maxX, x - (qreal)0.5); maxY = qMax(maxY, y); - tickXCount = x+1; - domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + domain.setRange(minX,maxX,minY,maxY); } diff --git a/src/chart.cpp b/src/chart.cpp index ff949b0..89b3a47 100644 --- a/src/chart.cpp +++ b/src/chart.cpp @@ -77,6 +77,12 @@ void Chart::handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY) qWarning()<<"Slot not implemented"; } +void Chart::handleDomainUpdated() +{ + qWarning()<<"Slot not implemented"; +} + + #include "moc_chart_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/chart_p.h b/src/chart_p.h index 9b0d081..40bbaf0 100644 --- a/src/chart_p.h +++ b/src/chart_p.h @@ -50,6 +50,7 @@ public: public Q_SLOTS: virtual void handleGeometryChanged(const QRectF& rect); virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY); + virtual void handleDomainUpdated(); void setAnimator(ChartAnimator* animator); ChartAnimator* animator() const; diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 161e2e6..8bf2380 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -186,7 +186,7 @@ QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orienta } if(axis) - axis->d_ptr->m_orientation=orientation; + axis->d_ptr->setOrientation(orientation); return axis; } @@ -197,16 +197,16 @@ void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) axis->d_ptr->intializeDomain(domain); series->d_ptr->initializeAxis(axis); if(axis->orientation()==Qt::Horizontal) { - QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); - QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); + QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); + QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); m_seriesAxisXMap.insert(series,axis); } else { - QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); - QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); + QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); + QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); m_seriesAxisYMap.insert(series,axis); } - axis->d_ptr->emitRange(); + axis->d_ptr->emitUpdated(); } void ChartDataSet::removeAxes(QAbstractSeries* series) @@ -369,7 +369,7 @@ void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori return; } - axis->d_ptr->m_orientation=orientation; + axis->d_ptr->setOrientation(orientation); QMap *seriesAxisMap; diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 97b76f8..54888ce 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -78,28 +78,19 @@ void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) item->setAnimation(new AxisAnimation(item)); } - if(item->axisType()==ChartAxis::X_AXIS){ - m_chartTheme->decorate(axis,true); - QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); - //initialize - item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); - - } - else{ - m_chartTheme->decorate(axis,false); - QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); - //initialize - item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); - } - QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); + QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); + //initialize + domain->emitUpdated(); + m_chartTheme->decorate(axis); + axis->d_ptr->setDirty(false); + axis->d_ptr->emitUpdated(); if(m_rect.isValid()) item->handleGeometryChanged(m_rect); - //reload visiblity + m_axisItems.insert(axis, item); selectVisibleAxis(); - } void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) @@ -119,9 +110,10 @@ void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) item->setDomain(domain); QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); - QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); + QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); //initialize - item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); + item->handleDomainUpdated(); + if(m_rect.isValid()) item->handleGeometryChanged(m_rect); m_chartItems.insert(series,item); } @@ -159,11 +151,11 @@ void ChartPresenter::selectVisibleAxis() while (i.hasNext()) { i.next(); - if(i.key()->d_ptr->m_orientation==Qt::Vertical && !axisY) { + if(i.key()->orientation()==Qt::Vertical && !axisY) { axisY=true; i.key()->show(); } - if(i.key()->d_ptr->m_orientation==Qt::Horizontal && !axisX) { + if(i.key()->orientation()==Qt::Horizontal && !axisX) { axisX=true; i.key()->show(); } @@ -185,7 +177,7 @@ void ChartPresenter::handleAxisVisibleChanged(bool visible) if(i.key()==axis) { continue; } - if(i.key()->d_ptr->m_orientation==axis->d_ptr->m_orientation) { + if(i.key()->orientation()==axis->orientation()) { i.key()->setVisible(false); } } diff --git a/src/charttheme.cpp b/src/charttheme.cpp index b412312..65f269b 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -256,12 +256,14 @@ void ChartTheme::decorate(QSplineSeries *series, int index) } } -void ChartTheme::decorate(QAbstractAxis *axis,bool axisX) +void ChartTheme::decorate(QAbstractAxis *axis) { QPen pen; QBrush brush; QFont font; + bool axisX = axis->orientation()== Qt::Horizontal; + if (axis->isArrowVisible()) { if(brush == axis->labelsBrush() || m_force){ diff --git a/src/charttheme_p.h b/src/charttheme_p.h index ec75d55..cdc6a20 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -78,7 +78,7 @@ public: void decorate(QScatterSeries *series, int index); void decorate(QPieSeries *series, int index); void decorate(QSplineSeries *series, int index); - void decorate(QAbstractAxis *axis, bool axisX); + void decorate(QAbstractAxis *axis); void setForced(bool enabled); bool isForced() { return m_force; } diff --git a/src/domain.cpp b/src/domain.cpp index 551515a..be38098 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -19,7 +19,7 @@ ****************************************************************************/ #include "domain_p.h" -#include +#include "qabstractaxis_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -27,11 +27,7 @@ Domain::Domain(QObject* parent) : QObject(parent), m_minX(0), m_maxX(0), m_minY(0), - m_maxY(0), - m_tickXCount(5), - m_tickYCount(5), - m_niceXNumbers(false), - m_niceYNumbers(false) + m_maxY(0) { } @@ -41,48 +37,25 @@ Domain::~Domain() void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) { - setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount); -} - -void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount) -{ bool axisXChanged = false; bool axisYChanged = false; - if(m_tickXCount!=tickXCount) { - m_tickXCount=tickXCount; - axisXChanged=true; - } - - if(m_tickYCount!=tickYCount) { - m_tickYCount=tickYCount; - axisYChanged=true; - } - if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { - if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount); m_minX=minX; m_maxX=maxX; axisXChanged=true; + emit rangeXChanged(m_minX,m_maxX); } if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { - if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount); m_minY=minY; m_maxY=maxY; axisYChanged=true; + emit rangeYChanged(m_minY,m_maxY); } if(axisXChanged || axisYChanged) { - emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY); - } - - if(axisXChanged) { - emit rangeXChanged(minX,maxX, m_tickXCount); - } - - if(axisYChanged) { - emit rangeYChanged(minY,maxY, m_tickYCount); + emit updated(); } } @@ -91,21 +64,11 @@ void Domain::setRangeX(qreal min, qreal max) setRange(min,max,m_minY, m_maxY); } -void Domain::setRangeX(qreal min, qreal max, int tickCount) -{ - setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount); -} - void Domain::setRangeY(qreal min, qreal max) { setRange(m_minX, m_maxX, min, max); } -void Domain::setRangeY(qreal min, qreal max,int tickCount) -{ - setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount); -} - void Domain::setMinX(qreal min) { setRange(min, m_maxX, m_minY, m_maxY); @@ -158,16 +121,7 @@ void Domain::zoomIn(const QRectF& rect, const QSizeF& size) minY = maxY - dy * rect.bottom(); maxY = maxY - dy * rect.top(); - int tickXCount = m_tickXCount; - int tickYCount = m_tickYCount; - - if(m_niceXNumbers) { - looseNiceNumbers(minX, maxX, tickXCount); - } - if(m_niceYNumbers) { - looseNiceNumbers(minY, maxY, tickYCount); - } - setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + setRange(minX,maxX,minY,maxY); } void Domain::zoomOut(const QRectF& rect, const QSizeF& size) @@ -185,16 +139,7 @@ void Domain::zoomOut(const QRectF& rect, const QSizeF& size) maxY = minY + dy * rect.bottom(); minY = maxY - dy * size.height(); - int tickXCount = m_tickXCount; - int tickYCount = m_tickYCount; - - if(m_niceXNumbers) { - looseNiceNumbers(minX, maxX, tickXCount); - } - if(m_niceYNumbers) { - looseNiceNumbers(minY, maxY, tickYCount); - } - setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); + setRange(minX,maxX,minY,maxY); } void Domain::move(qreal dx,qreal dy,const QSizeF& size) @@ -218,64 +163,24 @@ void Domain::move(qreal dx,qreal dy,const QSizeF& size) setRange(minX,maxX,minY,maxY); } -void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers) +void Domain::emitUpdated() { - if (m_niceXNumbers != niceNumbers) { - m_niceXNumbers = niceNumbers; - //force recalculation - m_minX = 0; - m_maxX = 0; - } - setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount); + emit updated(); } -void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers) +void Domain::handleAxisUpdated() { - if (m_niceYNumbers != niceNumbers) { - m_niceYNumbers = niceNumbers; - //force recalculation - m_minY = 0; - m_maxY = 0; + QAbstractAxisPrivate* axis = qobject_cast(sender()); + Q_ASSERT(axis); + axis->setDirty(false); + if(axis->orientation()==Qt::Horizontal){ + setRangeX(axis->min(),axis->max()); + }else if(axis->orientation()==Qt::Vertical){ + setRangeY(axis->min(),axis->max()); } - setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount); -} -//algorithm defined by Paul S.Heckbert GraphicalGems I - -void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const -{ - qreal range = niceNumber(max-min,true); //range with ceiling - qreal step = niceNumber(range/(ticksCount-1),false); - min = floor(min/step); - max = ceil(max/step); - ticksCount = int(max-min) +1; - min*=step; - max*=step; } -//nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n - -qreal Domain::niceNumber(qreal x,bool ceiling) const -{ - qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x - qreal q = x/z;//q<10 && q>=1; - - if(ceiling) { - if(q <= 1.0) q=1; - else if(q <= 2.0) q=2; - else if(q <= 5.0) q=5; - else q=10; - } - else { - if(q < 1.5) q=1; - else if(q < 3.0) q=2; - else if(q < 7.0) q=5; - else q=10; - } - return q*z; -} - - bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2) { return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && @@ -293,7 +198,7 @@ bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain) { - dbg.nospace() << "Domain("< QXYSeriesPrivate::createLegendMarker(QLegend* legend) diff --git a/src/xychart/xychart.cpp b/src/xychart/xychart.cpp index 5a5d61f..2c2ae1f 100644 --- a/src/xychart/xychart.cpp +++ b/src/xychart/xychart.cpp @@ -23,6 +23,7 @@ #include "qxyseries_p.h" #include "chartpresenter_p.h" #include "chartanimator_p.h" +#include "domain_p.h" #include #include #include "qxymodelmapper.h" @@ -185,12 +186,12 @@ void XYChart::handlePointReplaced(int index) updateChart(m_points,points,index); } -void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) +void XYChart::handleDomainUpdated() { - m_minX=minX; - m_maxX=maxX; - m_minY=minY; - m_maxY=maxY; + m_minX=domain()->minX(); + m_maxX=domain()->maxX(); + m_minY=domain()->minY(); + m_maxY=domain()->maxY(); if (isEmpty()) return; QVector points = calculateGeometryPoints(); diff --git a/src/xychart/xychart_p.h b/src/xychart/xychart_p.h index b46168c..8d1758a 100644 --- a/src/xychart/xychart_p.h +++ b/src/xychart/xychart_p.h @@ -68,7 +68,7 @@ public Q_SLOTS: void handlePointAdded(int index); void handlePointRemoved(int index); void handlePointReplaced(int index); - void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); + void handleDomainUpdated(); void handleGeometryChanged(const QRectF &size); Q_SIGNALS: diff --git a/tests/auto/chartdataset/tst_chartdataset.cpp b/tests/auto/chartdataset/tst_chartdataset.cpp index eed180c..5252062 100644 --- a/tests/auto/chartdataset/tst_chartdataset.cpp +++ b/tests/auto/chartdataset/tst_chartdataset.cpp @@ -538,7 +538,7 @@ void tst_ChartDataSet::zoomInDomain() QList spyList; foreach(QAbstractSeries* series, seriesList) { - spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated())); } m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); @@ -572,7 +572,7 @@ void tst_ChartDataSet::zoomOutDomain() QList spyList; foreach(QAbstractSeries* series, seriesList) { - spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated())); } m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); @@ -606,7 +606,7 @@ void tst_ChartDataSet::scrollDomain() foreach(QAbstractSeries* series, seriesList) { spyList << new QSignalSpy(m_dataset->domain(series), - SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + SIGNAL(updated())); } m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); diff --git a/tests/auto/domain/tst_domain.cpp b/tests/auto/domain/tst_domain.cpp index 4682b29..44bfbde 100644 --- a/tests/auto/domain/tst_domain.cpp +++ b/tests/auto/domain/tst_domain.cpp @@ -20,6 +20,7 @@ #include #include +#include #include QTCOMMERCIALCHART_USE_NAMESPACE @@ -27,6 +28,26 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(Domain*) Q_DECLARE_METATYPE(QSizeF) + +class AxisMock: public QAbstractAxisPrivate +{ +Q_OBJECT +public: + AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);}; + ChartAxis* createGraphics(ChartPresenter* presenter){}; + void intializeDomain(Domain* domain){}; + void setMin(const QVariant &min){} + qreal min() { return m_min;} + void setMax(const QVariant &max){} + qreal max() { return m_max; } + void setRange(const QVariant &min, const QVariant &max){}; + + void handleDomainUpdated(){}; +public: + qreal m_min; + qreal m_max; +}; + class tst_Domain: public QObject { Q_OBJECT @@ -39,10 +60,10 @@ public Q_SLOTS: private Q_SLOTS: void domain(); - void handleAxisRangeXChanged_data(); - void handleAxisRangeXChanged(); - void handleAxisRangeYChanged_data(); - void handleAxisRangeYChanged(); + void handleAxisUpdatedX_data(); + void handleAxisUpdatedX(); + void handleAxisUpdatedY_data(); + void handleAxisUpdatedY(); void isEmpty_data(); void isEmpty(); void maxX_data(); @@ -69,10 +90,6 @@ private Q_SLOTS: void zoom(); void move_data(); void move(); - void handleAxisXChanged_data(); - void handleAxisXChanged(); - void handleAxisYChanged_data(); - void handleAxisYChanged(); }; void tst_Domain::initTestCase() @@ -102,7 +119,7 @@ void tst_Domain::domain() QCOMPARE(domain.minY(), 0.0); } -void tst_Domain::handleAxisRangeXChanged_data() +void tst_Domain::handleAxisUpdatedX_data() { QTest::addColumn("min"); QTest::addColumn("max"); @@ -111,22 +128,25 @@ void tst_Domain::handleAxisRangeXChanged_data() QTest::newRow("-1 0") << -1.0 << 0.0; } -void tst_Domain::handleAxisRangeXChanged() +void tst_Domain::handleAxisUpdatedX() { QFETCH(qreal, min); QFETCH(qreal, max); Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); - domain.handleAxisXChanged(min, max); + AxisMock axis(Qt::Horizontal); + QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated())); + axis.m_min=min; + axis.m_max=max; + axis.emitUpdated(); - QList arg0 = spy0.first(); - QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); - QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); + QVERIFY(qFuzzyIsNull(domain.minX() - min)); + QVERIFY(qFuzzyIsNull(domain.maxX() - max)); QList arg1 = spy1.first(); QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); @@ -138,7 +158,7 @@ void tst_Domain::handleAxisRangeXChanged() } -void tst_Domain::handleAxisRangeYChanged_data() +void tst_Domain::handleAxisUpdatedY_data() { QTest::addColumn("min"); QTest::addColumn("max"); @@ -147,22 +167,25 @@ void tst_Domain::handleAxisRangeYChanged_data() QTest::newRow("-1 0") << -1.0 << 0.0; } -void tst_Domain::handleAxisRangeYChanged() +void tst_Domain::handleAxisUpdatedY() { QFETCH(qreal, min); QFETCH(qreal, max); Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); - domain.handleAxisYChanged(min, max, 5); + AxisMock axis(Qt::Vertical); + QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated())); + axis.m_min = min; + axis.m_max = max; + axis.emitUpdated(); - QList arg0 = spy0.first(); - QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); - QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); + QVERIFY(qFuzzyIsNull(domain.minY() - min)); + QVERIFY(qFuzzyIsNull(domain.maxY() - max)); QList arg1 = spy2.first(); QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); @@ -217,9 +240,9 @@ void tst_Domain::maxX() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setMaxX(maxX1); QCOMPARE(domain.maxX(), maxX1); @@ -250,9 +273,9 @@ void tst_Domain::maxY() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setMaxY(maxY1); QCOMPARE(domain.maxY(), maxY1); @@ -282,9 +305,9 @@ void tst_Domain::minX() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setMinX(minX1); QCOMPARE(domain.minX(), minX1); @@ -314,9 +337,9 @@ void tst_Domain::minY() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setMinY(minY1); QCOMPARE(domain.minY(), minY1); @@ -364,9 +387,9 @@ void tst_Domain::operatorEquals() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); QCOMPARE(*domain1==*domain2, equals); QCOMPARE(*domain1!=*domain2, notEquals); @@ -396,9 +419,9 @@ void tst_Domain::setRange() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setRange(minX, maxX, minY, maxY); @@ -429,15 +452,14 @@ void tst_Domain::setRangeX() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setRangeX(min, max); - QList arg0 = spy0.first(); - QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); - QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); + QVERIFY(qFuzzyIsNull(domain.minX() - min)); + QVERIFY(qFuzzyIsNull(domain.maxX() - max)); QList arg1 = spy1.first(); QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); @@ -464,15 +486,14 @@ void tst_Domain::setRangeY() Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.setRangeY(min, max); - QList arg0 = spy0.first(); - QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); - QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); + QVERIFY(qFuzzyIsNull(domain.minY() - min)); + QVERIFY(qFuzzyIsNull(domain.maxY() - max)); QList arg1 = spy2.first(); QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); @@ -502,9 +523,9 @@ void tst_Domain::spanX() domain.setRangeX(minX, maxX); - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); QCOMPARE(domain.spanX(), spanX); @@ -532,9 +553,9 @@ void tst_Domain::spanY() domain.setRangeY(minY, maxY); - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); QCOMPARE(domain.spanY(), spanY); @@ -574,9 +595,9 @@ void tst_Domain::zoom() domain.setRange(0, 1000, 0, 1000); - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); Domain domain0; domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); @@ -620,9 +641,9 @@ void tst_Domain::move() domain.setRange(0, size.width(), 0, size.height()); - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); domain.move(dx, dy, size); @@ -635,6 +656,7 @@ void tst_Domain::move() TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); } +/* void tst_Domain::handleAxisXChanged_data() { QTest::addColumn("min"); @@ -661,15 +683,15 @@ void tst_Domain::handleAxisXChanged() QFETCH(int, resultTickCount); Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); - domain.handleAxisXChanged(min, max, tickCount, niceNumbers); + // domain.handleAxisXChanged(min, max, tickCount, niceNumbers); QCOMPARE(resultMin, domain.minX()); QCOMPARE(resultMax, domain.maxX()); - QCOMPARE(resultTickCount, domain.tickXCount()); + // QCOMPARE(resultTickCount, domain.tickXCount()); TRY_COMPARE(spy0.count(), 1); TRY_COMPARE(spy1.count(), 1); TRY_COMPARE(spy2.count(), 0); @@ -692,20 +714,20 @@ void tst_Domain::handleAxisYChanged() QFETCH(int, resultTickCount); Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); + QSignalSpy spy0(&domain, SIGNAL(updated())); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); - domain.handleAxisYChanged(min, max, tickCount, niceNumbers); + // domain.handleAxisYChanged(min, max, tickCount, niceNumbers); QCOMPARE(resultMin, domain.minY()); QCOMPARE(resultMax, domain.maxY()); - QCOMPARE(resultTickCount, domain.tickYCount()); + // QCOMPARE(resultTickCount, domain.tickYCount()); TRY_COMPARE(spy0.count(), 1); TRY_COMPARE(spy1.count(), 0); TRY_COMPARE(spy2.count(), 1); } - +*/ QTEST_MAIN(tst_Domain) #include "tst_domain.moc"