From 251205c7e45d7171bf02a15ebc4913df5a812566 2012-07-20 16:08:25 From: Michal Klocek Date: 2012-07-20 16:08:25 Subject: [PATCH] Implements qbarcategoriesaxis logic * adds min max QString setting support * adds logic to remove series when axis acidently deleted * adds tst_qbarcategoriesaxis stub --- diff --git a/src/axis/categoriesaxis/chartcategoriesaxisx.cpp b/src/axis/categoriesaxis/chartcategoriesaxisx.cpp index 6b5eba7..d912d28 100644 --- a/src/axis/categoriesaxis/chartcategoriesaxisx.cpp +++ b/src/axis/categoriesaxis/chartcategoriesaxisx.cpp @@ -40,12 +40,14 @@ ChartCategoriesAxisX::~ChartCategoriesAxisX() QVector ChartCategoriesAxisX::calculateLayout() const { - Q_ASSERT(m_categoriesAxis->categories().count()>=1); + int count = m_categoriesAxis->d_ptr->count(); + + Q_ASSERT(count>=1); QVector points; - points.resize(m_categoriesAxis->categories().count()+2); + points.resize(count+2); - const qreal delta = m_rect.width()/(m_categoriesAxis->categories().count()); + const qreal delta = m_rect.width()/(count); qreal offset =-m_min-0.5; if(offset<=0) { @@ -56,9 +58,9 @@ QVector ChartCategoriesAxisX::calculateLayout() const } points[0] = m_rect.left(); - points[m_categoriesAxis->categories().count()+1] = m_rect.right(); + points[count+1] = m_rect.right(); - for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { + for (int i = 0; i < count; ++i) { qreal x = offset + i * delta + m_rect.left(); points[i+1] = x; } @@ -103,7 +105,7 @@ void ChartCategoriesAxisX::updateGeometry() Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); - const qreal delta = m_rect.width()/(m_categoriesAxis->categories().count()); + const qreal delta = m_rect.width()/(m_categoriesAxis->d_ptr->count()); QGraphicsLineItem *lineItem = static_cast(axis.at(0)); lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); @@ -149,7 +151,7 @@ void ChartCategoriesAxisX::handleAxisUpdated() if(m_categoriesAxis->categories()!=m_categories) { m_categories=m_categoriesAxis->categories(); - if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); + if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry(); } ChartAxis::handleAxisUpdated(); } diff --git a/src/axis/categoriesaxis/chartcategoriesaxisy.cpp b/src/axis/categoriesaxis/chartcategoriesaxisy.cpp index 2c009fa..bd9ff14 100644 --- a/src/axis/categoriesaxis/chartcategoriesaxisy.cpp +++ b/src/axis/categoriesaxis/chartcategoriesaxisy.cpp @@ -38,12 +38,14 @@ ChartCategoriesAxisY::~ChartCategoriesAxisY() QVector ChartCategoriesAxisY::calculateLayout() const { - Q_ASSERT(m_categoriesAxis->categories().count()>=1); + int count = m_categoriesAxis->d_ptr->count(); + + Q_ASSERT(count>=1); QVector points; - points.resize(m_categoriesAxis->categories().count()+2); + points.resize(count+2); - const qreal delta = m_rect.height()/(m_categoriesAxis->categories().count()); + const qreal delta = m_rect.height()/(count); qreal offset = - m_min - 0.5; if(offset<=0) { @@ -54,9 +56,9 @@ QVector ChartCategoriesAxisY::calculateLayout() const } points[0] = m_rect.bottom(); - points[m_categoriesAxis->categories().count()+1] = m_rect.top(); + points[count+1] = m_rect.top(); - for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { + for (int i = 0; i < count; ++i) { int y = m_rect.bottom() - i * delta - offset; points[i+1] = y; } @@ -100,7 +102,7 @@ void ChartCategoriesAxisY::updateGeometry() Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); - const qreal delta = m_rect.height()/(m_categoriesAxis->categories().count()); + const qreal delta = m_rect.height()/(m_categoriesAxis->d_ptr->count()); QGraphicsLineItem *lineItem = static_cast(axis.at(0)); lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); @@ -148,8 +150,7 @@ void ChartCategoriesAxisY::handleAxisUpdated() if(m_categoriesAxis->categories()!=m_categories) { m_categories=m_categoriesAxis->categories(); - if(ChartAxis::layout().count()==m_categories.size()+1) { - + if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) { updateGeometry(); } } diff --git a/src/axis/categoriesaxis/chartcategoriesaxisy_p.h b/src/axis/categoriesaxis/chartcategoriesaxisy_p.h index 899006b..0acbed0 100644 --- a/src/axis/categoriesaxis/chartcategoriesaxisy_p.h +++ b/src/axis/categoriesaxis/chartcategoriesaxisy_p.h @@ -55,7 +55,6 @@ Q_SLOTS void handleAxisUpdated(); private: QStringList m_categories; - QVector m_labelIndex; QBarCategoriesAxis *m_categoriesAxis; }; diff --git a/src/axis/categoriesaxis/qbarcategoriesaxis.cpp b/src/axis/categoriesaxis/qbarcategoriesaxis.cpp index dbdcdf2..5307346 100644 --- a/src/axis/categoriesaxis/qbarcategoriesaxis.cpp +++ b/src/axis/categoriesaxis/qbarcategoriesaxis.cpp @@ -23,8 +23,8 @@ #include "chartcategoriesaxisx_p.h" #include "chartcategoriesaxisy_p.h" #include "domain_p.h" +#include "chartdataset_p.h" #include -#include QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! @@ -124,6 +124,10 @@ QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): */ QBarCategoriesAxis::~QBarCategoriesAxis() { + Q_D(QBarCategoriesAxis); + if(d->m_dataset){ + d->m_dataset->removeAxis(this); + } } /*! @@ -176,7 +180,10 @@ void QBarCategoriesAxis::remove(const QString &category) Q_D(QBarCategoriesAxis); if (d->m_categories.contains(category)) { d->m_categories.removeAt(d->m_categories.indexOf(category)); - setRange(d->m_categories.first(),d->m_categories.last()); + if(!d->m_categories.isEmpty()) + setRange(d->m_categories.first(),d->m_categories.last()); + else + setRange(QString::null,QString::null); emit d->updated(); emit categoriesChanged(); } @@ -251,12 +258,7 @@ QString QBarCategoriesAxis::at(int index) const void QBarCategoriesAxis::setMin(const QString& min) { Q_D(QBarCategoriesAxis); - if (d->m_minCategory!=min && d->m_categories.contains(min)) { - d->m_minCategory = min; - d->emitUpdated(); - emit minChanged(min); - } - + setRange(min,d->m_maxCategory); } /*! @@ -274,12 +276,7 @@ QString QBarCategoriesAxis::min() const void QBarCategoriesAxis::setMax(const QString& max) { Q_D(QBarCategoriesAxis); - if (d->m_maxCategory!=max && d->m_categories.contains(max)) { - d->m_maxCategory = max; - d->emitUpdated(); - emit maxChanged(max); - } - + setRange(d->m_minCategory,max); } /*! @@ -296,8 +293,31 @@ QString QBarCategoriesAxis::max() const */ void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) { - setMin(minCategory); - setMax(maxCategory); + Q_D(QBarCategoriesAxis); + + if(d->m_categories.indexOf(d->m_maxCategory)m_categories.indexOf(d->m_minCategory)) return; + + bool changed = false; + + if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { + d->m_minCategory = minCategory; + d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; + changed = true; + emit minChanged(minCategory); + } + + if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { + d->m_maxCategory = maxCategory; + d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; + changed = true; + emit maxChanged(maxCategory); + } + + if (changed) { + d->m_count=d->m_max - d->m_min; + emit rangeChanged(d->m_minCategory,d->m_maxCategory); + d->emitUpdated(); + } } /*! @@ -313,7 +333,8 @@ QAbstractAxis::AxisType QBarCategoriesAxis::type() const QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): QAbstractAxisPrivate(q), m_min(0.0), - m_max(0.0) + m_max(0.0), + m_count(0) { } @@ -341,64 +362,43 @@ void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &ma q->setRange(value1,value2); } -qreal QBarCategoriesAxisPrivate::min() -{ - //TODO:: cache it - return m_min;//m_categories.indexOf(m_minCategory) - 0.5; -} - -qreal QBarCategoriesAxisPrivate::max() -{ - //TODO:: cache it - return m_max;//m_categories.indexOf(m_maxCategory) + 0.5; -} - void QBarCategoriesAxisPrivate::handleDomainUpdated() { + Q_Q(QBarCategoriesAxis); Domain* domain = qobject_cast(sender()); - if(m_orientation==Qt::Horizontal){ + if(m_orientation==Qt::Horizontal) { m_min = domain->minX(); m_max = domain->maxX(); - }else if(m_orientation==Qt::Vertical){ + } + else if(m_orientation==Qt::Vertical) { m_min = domain->minY(); m_max = domain->maxY(); } -// Q_Q(QBarCategoriesAxis); - - // TODO: causes crash in some situations. added to known issues - /* - int minIndex = qFloor(min); - int maxIndex = qFloor(max); + bool changed = false; - if (minIndex < 0) { - minIndex = 0; - } - if (maxIndex > m_categories.count()-1){ - maxIndex = m_categories.count()-1; - if (maxIndex<0) { - maxIndex = 0; + int min = m_min + 0.5; + if(min>=0 && minminChanged(minCategory); } } - - bool changed = false; - if (m_minCategory != m_categories.at(minIndex)) { - m_minCategory = m_categories.at(minIndex); - emit q->minChanged(m_minCategory); - changed = true; - } - - if (m_maxCategory != m_categories.at(maxIndex)) { - m_maxCategory = m_categories.at(maxIndex); - emit q->maxChanged(m_maxCategory); - changed = true; + int max = m_max - 0.5; + if(max>=0 && maxmaxChanged(maxCategory); + } } if (changed) { - emit q->rangeChanged(m_minCategory, m_maxCategory); + emit q->rangeChanged(m_minCategory,m_maxCategory); } - */ } ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) @@ -411,13 +411,6 @@ 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) { Q_UNUSED(domain); diff --git a/src/axis/categoriesaxis/qbarcategoriesaxis.h b/src/axis/categoriesaxis/qbarcategoriesaxis.h index 9fb35e2..03fe182 100644 --- a/src/axis/categoriesaxis/qbarcategoriesaxis.h +++ b/src/axis/categoriesaxis/qbarcategoriesaxis.h @@ -69,6 +69,8 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QBarCategoriesAxis) Q_DISABLE_COPY(QBarCategoriesAxis) + friend class ChartCategoriesAxisX; + friend class ChartCategoriesAxisY; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/categoriesaxis/qbarcategoriesaxis_p.h b/src/axis/categoriesaxis/qbarcategoriesaxis_p.h index 445c1f2..a7b8f73 100644 --- a/src/axis/categoriesaxis/qbarcategoriesaxis_p.h +++ b/src/axis/categoriesaxis/qbarcategoriesaxis_p.h @@ -49,8 +49,9 @@ public: ChartAxis* createGraphics(ChartPresenter* presenter); void intializeDomain(Domain* domain); void handleDomainUpdated(); - qreal min(); - qreal max(); + qreal min() { return m_min;}; + qreal max() { return m_max;}; + int count() const { return m_count; }; private: //range handling @@ -64,9 +65,10 @@ private: QString m_maxCategory; qreal m_min; qreal m_max; + int m_count; private: - Q_DECLARE_PUBLIC(QBarCategoriesAxis) + Q_DECLARE_PUBLIC(QBarCategoriesAxis); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/datetimeaxis/qdatetimeaxis_p.h b/src/axis/datetimeaxis/qdatetimeaxis_p.h index b61775b..7673ec4 100644 --- a/src/axis/datetimeaxis/qdatetimeaxis_p.h +++ b/src/axis/datetimeaxis/qdatetimeaxis_p.h @@ -49,6 +49,7 @@ class QDateTimeAxisPrivate : public QAbstractAxisPrivate void handleDomainUpdated(); qreal min(){ return m_min.toMSecsSinceEpoch(); } qreal max(){ return m_max.toMSecsSinceEpoch(); } + int count() const { /*TODO:*/ return 0;}; protected: void setMin(const QVariant &min); diff --git a/src/axis/intervalsaxis/qintervalsaxis.cpp b/src/axis/intervalsaxis/qintervalsaxis.cpp index 6b5bb7f..ab2a5df 100644 --- a/src/axis/intervalsaxis/qintervalsaxis.cpp +++ b/src/axis/intervalsaxis/qintervalsaxis.cpp @@ -190,8 +190,10 @@ int QIntervalsAxisPrivate::ticksCount() const void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) { Q_UNUSED(count); - m_min = min; - m_max = max; + Q_UNUSED(min); + Q_UNUSED(max); + //m_min = min; + //m_max = max; } ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter) diff --git a/src/axis/qabstractaxis.cpp b/src/axis/qabstractaxis.cpp index 9d5bb81..c38e043 100644 --- a/src/axis/qabstractaxis.cpp +++ b/src/axis/qabstractaxis.cpp @@ -270,6 +270,7 @@ d_ptr(&d) QAbstractAxis::~QAbstractAxis() { + if(d_ptr->m_dataset) qFatal("Still binded axis detected !"); } /*! @@ -608,6 +609,7 @@ Qt::Orientation QAbstractAxis::orientation() QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): q_ptr(q), m_orientation(Qt::Orientation(0)), + m_dataset(0), m_visible(false), m_arrowVisible(true), m_gridLineVisible(true), diff --git a/src/axis/qabstractaxis_p.h b/src/axis/qabstractaxis_p.h index ac57082..99bb3ce 100644 --- a/src/axis/qabstractaxis_p.h +++ b/src/axis/qabstractaxis_p.h @@ -37,6 +37,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class ChartPresenter; class ChartAxis; class Domain; +class ChartDataSet; class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject { @@ -62,6 +63,8 @@ public: virtual void setMax(const QVariant &max) = 0; virtual qreal max() = 0; + virtual int count() const = 0; + virtual void setRange(const QVariant &min, const QVariant &max) = 0; public Q_SLOTS: @@ -73,6 +76,7 @@ Q_SIGNALS: protected: QAbstractAxis *q_ptr; Qt::Orientation m_orientation; + ChartDataSet *m_dataset; private: bool m_visible; @@ -98,6 +102,7 @@ private: bool m_dirty; friend class QAbstractAxis; + friend class ChartDataSet; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/valuesaxis/qvaluesaxis.cpp b/src/axis/valuesaxis/qvaluesaxis.cpp index 45d0721..1d9a42b 100644 --- a/src/axis/valuesaxis/qvaluesaxis.cpp +++ b/src/axis/valuesaxis/qvaluesaxis.cpp @@ -23,8 +23,9 @@ #include "chartvaluesaxisx_p.h" #include "chartvaluesaxisy_p.h" #include "domain_p.h" -#include -#include +#include "chartdataset_p.h" +#include + QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! @@ -139,7 +140,10 @@ QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis( */ QValuesAxis::~QValuesAxis() { - + Q_D(QValuesAxis); + if(d->m_dataset) { + d->m_dataset->removeAxis(this); + } } void QValuesAxis::setMin(qreal min) @@ -171,6 +175,8 @@ qreal QValuesAxis::max() const */ void QValuesAxis::setRange(qreal min, qreal max) { + if(max=1; if(ceiling) { diff --git a/src/axis/valuesaxis/qvaluesaxis_p.h b/src/axis/valuesaxis/qvaluesaxis_p.h index e23bf7a..9aad136 100644 --- a/src/axis/valuesaxis/qvaluesaxis_p.h +++ b/src/axis/valuesaxis/qvaluesaxis_p.h @@ -48,18 +48,18 @@ public: void handleDomainUpdated(); qreal min(){ return m_min; }; qreal max(){ return m_max; }; + int count() const { return m_tickCount;} protected: void setMin(const QVariant &min); void setMax(const QVariant &max); void setRange(const QVariant &min, const QVariant &max); - int ticksCount() const; private: void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const; qreal niceNumber(qreal x,bool ceiling) const; -protected: +private: qreal m_min; qreal m_max; int m_tickCount; diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 1a3a5c4..39b07ca 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -201,10 +201,7 @@ QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : */ QAbstractBarSeries::~QAbstractBarSeries() { - Q_D(QAbstractBarSeries); - if(d->m_dataset){ - d->m_dataset->removeSeries(this); - } + } /*! diff --git a/src/barchart/vertical/bar/qbarseries.cpp b/src/barchart/vertical/bar/qbarseries.cpp index dac5043..cfb4d6d 100644 --- a/src/barchart/vertical/bar/qbarseries.cpp +++ b/src/barchart/vertical/bar/qbarseries.cpp @@ -73,6 +73,14 @@ QAbstractSeries::SeriesType QBarSeries::type() const return QAbstractSeries::SeriesTypeBar; } +QBarSeries::~QBarSeries() { + + Q_D(QBarSeries); + if(d->m_dataset) { + d->m_dataset->removeSeries(this); + } + +} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) diff --git a/src/barchart/vertical/bar/qbarseries.h b/src/barchart/vertical/bar/qbarseries.h index 8435f07..76c2ec5 100644 --- a/src/barchart/vertical/bar/qbarseries.h +++ b/src/barchart/vertical/bar/qbarseries.h @@ -32,6 +32,7 @@ class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries Q_OBJECT public: explicit QBarSeries(QObject *parent = 0); + ~QBarSeries(); QAbstractSeries::SeriesType type() const; private: diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 342bfd2..a4c924e 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -202,6 +202,7 @@ QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orienta void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) { Domain* domain = m_seriesDomainMap.value(series); + axis->d_ptr->m_dataset = this; axis->d_ptr->intializeDomain(domain); series->d_ptr->initializeAxis(axis); if(axis->orientation()==Qt::Horizontal) { @@ -227,6 +228,7 @@ void ChartDataSet::removeAxes(QAbstractSeries* series) if(x==-1) { emit axisRemoved(axisX); + axisX->d_ptr->m_dataset=0; axisX->deleteLater(); } } @@ -240,11 +242,38 @@ void ChartDataSet::removeAxes(QAbstractSeries* series) if(y==-1) { emit axisRemoved(axisY); + axisY->d_ptr->m_dataset=0; axisY->deleteLater(); } } } +void ChartDataSet::removeAxis(QAbstractAxis* axis) +{ + if(!axis->d_ptr->m_dataset) { + qWarning()<<"UnBound axis found !"; + return; + } + + QMap *seriesAxisMap; + + if(axis->orientation()==Qt::Vertical) { + seriesAxisMap= &m_seriesAxisYMap; + } + else { + seriesAxisMap= &m_seriesAxisXMap; + } + + QMapIterator i(*seriesAxisMap); + + while (i.hasNext()) { + i.next(); + if(i.value()==axis) { + removeSeries(i.key()); + } + } +} + void ChartDataSet::removeAllSeries() { QList series = m_seriesDomainMap.keys(); @@ -398,6 +427,7 @@ void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori if(oldAxis) { if(axes.indexOf(oldAxis)==-1) { emit axisRemoved(oldAxis); + oldAxis->d_ptr->m_dataset=0; oldAxis->deleteLater(); } } diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 8563a09..0b8e5d9 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -66,6 +66,7 @@ public: QList series() const; Domain* domain(QAbstractSeries *series) const; + void removeAxis(QAbstractAxis* axis); void createDefaultAxes(); Q_SIGNALS: diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index fc0fc85..3528af2 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -22,7 +22,8 @@ SUBDIRS += \ qhorizontalpercentbarseries \ qvaluesaxis \ qintervalsaxis \ - qdatetimeaxis + qdatetimeaxis \ + qbarcategoriesaxis test_private:{ SUBDIRS += domain chartdataset diff --git a/tests/auto/qabstractaxis/tst_qabstractaxis.cpp b/tests/auto/qabstractaxis/tst_qabstractaxis.cpp index 776d721..b44098e 100644 --- a/tests/auto/qabstractaxis/tst_qabstractaxis.cpp +++ b/tests/auto/qabstractaxis/tst_qabstractaxis.cpp @@ -41,7 +41,6 @@ void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series) void tst_QAbstractAxis::cleanup() { - delete m_view; m_view = 0; m_chart = 0; diff --git a/tests/auto/qbarcategoriesaxis/qbarcategoriesaxis.pro b/tests/auto/qbarcategoriesaxis/qbarcategoriesaxis.pro new file mode 100644 index 0000000..6e05d9f --- /dev/null +++ b/tests/auto/qbarcategoriesaxis/qbarcategoriesaxis.pro @@ -0,0 +1,5 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} +HEADERS += ../qabstractaxis/tst_qabstractaxis.h +SOURCES += tst_qbarcategoriesaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp diff --git a/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp b/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp new file mode 100644 index 0000000..0d800e1 --- /dev/null +++ b/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp @@ -0,0 +1,702 @@ +/**************************************************************************** + ** + ** Copyright (C) 2012 Digia Plc + ** All rights reserved. + ** For any questions to Digia, please use contact form at http://qt.digia.com + ** + ** This file is part of the Qt Commercial Charts Add-on. + ** + ** $QT_BEGIN_LICENSE$ + ** Licensees holding valid Qt Commercial licenses may use this file in + ** accordance with the Qt Commercial License Agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and Digia. + ** + ** If you have questions regarding the use of this file, please use + ** contact form at http://qt.digia.com + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include "../qabstractaxis/tst_qabstractaxis.h" +#include +#include +#include + +class tst_QBarCategoriesAxis: public tst_QAbstractAxis +{ +Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void qbarcategoriesaxis_data(); + void qbarcategoriesaxis(); + + void append_data(); + void append(); + void at_data(); + void at(); + void categories_data(); + void categories(); + void clear_data(); + void clear(); + void count_data(); + void count(); + void insert_data(); + void insert(); + void max_data(); + void max(); + void min_data(); + void min(); + void remove_data(); + void remove(); + void setCategories_data(); + void setCategories(); + void setMax_data(); + void setMax(); + void setMin_data(); + void setMin(); + void setRange_data(); + void setRange(); + void type_data(); + void type(); + void categoriesChanged_data(); + void categoriesChanged(); + void maxChanged_data(); + void maxChanged(); + void minChanged_data(); + void minChanged(); + void rangeChanged_data(); + void rangeChanged(); +private: + QBarCategoriesAxis* m_baraxis; + QBarSeries* m_series; +}; + +void tst_QBarCategoriesAxis::initTestCase() +{ +} + +void tst_QBarCategoriesAxis::cleanupTestCase() +{ +} + +void tst_QBarCategoriesAxis::init() +{ + m_baraxis = new QBarCategoriesAxis(); + m_series = new QBarSeries(); + + QBarSet *set0 = new QBarSet("Jane"); + QBarSet *set1 = new QBarSet("John"); + QBarSet *set2 = new QBarSet("Axel"); + QBarSet *set3 = new QBarSet("Mary"); + QBarSet *set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + + m_series->append(set0); + m_series->append(set1); + m_series->append(set2); + m_series->append(set3); + m_series->append(set4); + + QStringList categories; + categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; + + m_baraxis->append(categories); + + tst_QAbstractAxis::init(m_baraxis, m_series); + m_chart->addSeries(m_series); + m_chart->createDefaultAxes(); +} + +void tst_QBarCategoriesAxis::cleanup() +{ + delete m_series; + delete m_baraxis; + m_series = 0; + m_baraxis = 0; + tst_QAbstractAxis::cleanup(); +} + +void tst_QBarCategoriesAxis::qbarcategoriesaxis_data() +{ +} + +void tst_QBarCategoriesAxis::qbarcategoriesaxis() +{ + qabstractaxis(); + QBarCategoriesAxis axis; + axis.append(QStringList()); + axis.append(QString()); + QCOMPARE(axis.at(0), QString()); + QStringList test; + test.append(QString()); + QCOMPARE(axis.categories(),test); + axis.clear(); + QCOMPARE(axis.count(), 0); + axis.insert(-1, QString()); + QCOMPARE(axis.max(), QString()); + QCOMPARE(axis.min(), QString()); + axis.remove(QString()); + axis.setCategories(QStringList()); + axis.setMax(QString()); + axis.setMin(QString()); + axis.setRange(QString(), QString()); + QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories); +} + +void tst_QBarCategoriesAxis::append_data() +{ + QTest::addColumn("categories"); + QTest::newRow("null") << QStringList(); +} + +// public void append(QStringList const& categories) +void tst_QBarCategoriesAxis::append() +{ +#if 0 + QFETCH(QStringList, categories); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.append(categories); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::at_data() +{ + QTest::addColumn("index"); + QTest::addColumn("at"); + QTest::newRow("null") << 0 << QString(); +} + +// public QString at(int index) const +void tst_QBarCategoriesAxis::at() +{ +#if 0 + QFETCH(int, index); + QFETCH(QString, at); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + QCOMPARE(axis.at(index), at); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::categories_data() +{ + QTest::addColumn("categories"); + QTest::newRow("null") << QStringList(); +} + +// public QStringList categories() +void tst_QBarCategoriesAxis::categories() +{ +#if 0 + QFETCH(QStringList, categories); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + QCOMPARE(axis.categories(), categories); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::clear_data() +{ + QTest::addColumn("foo"); + QTest::newRow("0") << 0; + QTest::newRow("-1") << -1; +} + +// public void clear() +void tst_QBarCategoriesAxis::clear() +{ +#if 0 + QFETCH(int, foo); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.clear(); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::count_data() +{ + QTest::addColumn("count"); + QTest::newRow("0") << 0; + QTest::newRow("-1") << -1; +} + +// public int count() const +void tst_QBarCategoriesAxis::count() +{ +#if 0 + QFETCH(int, count); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + QCOMPARE(axis.count(), count); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::insert_data() +{ + QTest::addColumn("index"); + QTest::addColumn("category"); + QTest::newRow("null") << 0 << QString(); +} + +// public void insert(int index, QString const& category) +void tst_QBarCategoriesAxis::insert() +{ +#if 0 + QFETCH(int, index); + QFETCH(QString, category); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.insert(index, category); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::max_data() +{ + QTest::addColumn("max"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// public QString max() const +void tst_QBarCategoriesAxis::max() +{ +#if 0 + QFETCH(QString, max); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + QCOMPARE(axis.max(), max); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::min_data() +{ + QTest::addColumn("min"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// public QString min() const +void tst_QBarCategoriesAxis::min() +{ +#if 0 + QFETCH(QString, min); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + QCOMPARE(axis.min(), min); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::remove_data() +{ + QTest::addColumn("category"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// public void remove(QString const& category) +void tst_QBarCategoriesAxis::remove() +{ +#if 0 + QFETCH(QString, category); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.remove(category); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::setCategories_data() +{ + QTest::addColumn("categories"); + QTest::newRow("null") << QStringList(); +} + +// public void setCategories(QStringList const& categories) +void tst_QBarCategoriesAxis::setCategories() +{ +#if 0 + QFETCH(QStringList, categories); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.setCategories(categories); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::setMax_data() +{ + QTest::addColumn("maxCategory"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// public void setMax(QString const& maxCategory) +void tst_QBarCategoriesAxis::setMax() +{ +#if 0 + QFETCH(QString, maxCategory); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.setMax(maxCategory); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::setMin_data() +{ + QTest::addColumn("minCategory"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// public void setMin(QString const& minCategory) +void tst_QBarCategoriesAxis::setMin() +{ +#if 0 + QFETCH(QString, minCategory); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.setMin(minCategory); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::setRange_data() +{ + QTest::addColumn("minCategory"); + QTest::addColumn("maxCategory"); + QTest::newRow("null") << QString() << QString(); +} + +// public void setRange(QString const& minCategory, QString const& maxCategory) +void tst_QBarCategoriesAxis::setRange() +{ +#if 0 + QFETCH(QString, minCategory); + QFETCH(QString, maxCategory); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.setRange(minCategory, maxCategory); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::type_data() +{ +#if 0 + QTest::addColumn("type"); + QTest::newRow("null") << AxisType(); +#endif +} + +// public AxisType type() const +void tst_QBarCategoriesAxis::type() +{ +#if 0 + QFETCH(AxisType, type); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + QCOMPARE(axis.type(), type); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::categoriesChanged_data() +{ + QTest::addColumn("foo"); + QTest::newRow("0") << 0; + QTest::newRow("-1") << -1; +} + +// protected void categoriesChanged() +void tst_QBarCategoriesAxis::categoriesChanged() +{ +#if 0 + QFETCH(int, foo); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.call_categoriesChanged(); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::maxChanged_data() +{ + QTest::addColumn("max"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// protected void maxChanged(QString const& max) +void tst_QBarCategoriesAxis::maxChanged() +{ +#if 0 + QFETCH(QString, max); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.call_maxChanged(max); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::minChanged_data() +{ + QTest::addColumn("min"); + QTest::newRow("null") << QString(); + QTest::newRow("foo") << QString("foo"); +} + +// protected void minChanged(QString const& min) +void tst_QBarCategoriesAxis::minChanged() +{ +#if 0 + QFETCH(QString, min); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.call_minChanged(min); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +void tst_QBarCategoriesAxis::rangeChanged_data() +{ + QTest::addColumn("min"); + QTest::addColumn("max"); + QTest::newRow("null") << QString() << QString(); +} + +// protected void rangeChanged(QString const& min, QString const& max) +void tst_QBarCategoriesAxis::rangeChanged() +{ +#if 0 + QFETCH(QString, min); + QFETCH(QString, max); + + SubQBarCategoriesAxis axis; + + QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); + QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); + QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); + QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); + + axis.call_rangeChanged(min, max); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +#endif + QSKIP("Test is not implemented.", SkipAll); +} + +QTEST_MAIN(tst_QBarCategoriesAxis) +#include "tst_qbarcategoriesaxis.moc" +