From da4a379949e0165d7fb240c475c95b080a53903c 2012-07-04 06:33:48 From: Michal Klocek Date: 2012-07-04 06:33:48 Subject: [PATCH] Refactor CategoriesAxis to BarCategoriesAxis part 2 of 2 --- diff --git a/demos/chartthemes/themewidget.cpp b/demos/chartthemes/themewidget.cpp index c22d43e..6b68278 100644 --- a/demos/chartthemes/themewidget.cpp +++ b/demos/chartthemes/themewidget.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include ThemeWidget::ThemeWidget(QWidget* parent) : QWidget(parent), diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index fe00fde..ad1889a 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE diff --git a/examples/barmodelmapper/tablewidget.cpp b/examples/barmodelmapper/tablewidget.cpp index 646c0c3..ede86a3 100644 --- a/examples/barmodelmapper/tablewidget.cpp +++ b/examples/barmodelmapper/tablewidget.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE diff --git a/examples/percentbarchart/main.cpp b/examples/percentbarchart/main.cpp index b66ccdc..bff52d5 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/percentbarchart/main.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE diff --git a/examples/stackedbarchart/main.cpp b/examples/stackedbarchart/main.cpp index e2d7b55..4b76f36 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/stackedbarchart/main.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE diff --git a/examples/stackedbarchartdrilldown/drilldownchart.cpp b/examples/stackedbarchartdrilldown/drilldownchart.cpp index b065beb..5844448 100644 --- a/examples/stackedbarchartdrilldown/drilldownchart.cpp +++ b/examples/stackedbarchartdrilldown/drilldownchart.cpp @@ -19,7 +19,7 @@ ****************************************************************************/ #include "drilldownchart.h" -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 3897114..e491876 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -26,7 +26,7 @@ #include "declarativepieseries.h" #include "declarativesplineseries.h" #include "declarativescatterseries.h" -#include "qcategoriesaxis.h" +#include "qbarcategoriesaxis.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 8542a4b..db8a182 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -23,7 +23,7 @@ #include "qchart.h" #include "qabstractaxis.h" #include "qvaluesaxis.h" -#include "qcategoriesaxis.h" +#include "qbarcategoriesaxis.h" #include "declarativechart.h" #include "declarativexypoint.h" #include "declarativelineseries.h" diff --git a/src/axis/axis.pri b/src/axis/axis.pri index 9f3a6c0..fbefc81 100644 --- a/src/axis/axis.pri +++ b/src/axis/axis.pri @@ -3,29 +3,28 @@ DEPENDPATH += $$PWD SOURCES += \ $$PWD/chartaxis.cpp \ -# $$PWD/chartaxisx.cpp \ -# $$PWD/chartaxisy.cpp \ $$PWD/chartvaluesaxisx.cpp \ $$PWD/chartvaluesaxisy.cpp \ $$PWD/chartcategoriesaxisx.cpp \ $$PWD/chartcategoriesaxisy.cpp \ + $$PWD/qbarcategoriesaxis.cpp \ $$PWD/qcategoriesaxis.cpp \ $$PWD/qvaluesaxis.cpp \ $$PWD/qabstractaxis.cpp PRIVATE_HEADERS += \ $$PWD/chartaxis_p.h \ -# $$PWD/chartaxisx_p.h \ -# $$PWD/chartaxisy_p.h \ $$PWD/chartvaluesaxisx_p.h \ $$PWD/chartvaluesaxisy_p.h \ $$PWD/chartcategoriesaxisx_p.h \ $$PWD/chartcategoriesaxisy_p.h \ + $$PWD/qbarcategoriesaxis_p.h \ $$PWD/qcategoriesaxis_p.h \ $$PWD/qvaluesaxis_p.h \ $$PWD/qabstractaxis_p.h PUBLIC_HEADERS += \ + $$PWD/qbarcategoriesaxis.h \ $$PWD/qcategoriesaxis.h \ $$PWD/qvaluesaxis.h \ $$PWD/qabstractaxis.h diff --git a/src/axis/chartcategoriesaxisx.cpp b/src/axis/chartcategoriesaxisx.cpp index 3d22f1d..c4c0932 100644 --- a/src/axis/chartcategoriesaxisx.cpp +++ b/src/axis/chartcategoriesaxisx.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include static int label_padding = 5; diff --git a/src/axis/chartcategoriesaxisy.cpp b/src/axis/chartcategoriesaxisy.cpp index 535164d..7af1f16 100644 --- a/src/axis/chartcategoriesaxisy.cpp +++ b/src/axis/chartcategoriesaxisy.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include static int label_padding = 5; diff --git a/src/axis/qbarcategoriesaxis.cpp b/src/axis/qbarcategoriesaxis.cpp new file mode 100644 index 0000000..4757217 --- /dev/null +++ b/src/axis/qbarcategoriesaxis.cpp @@ -0,0 +1,299 @@ +/**************************************************************************** +** +** 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 "qbarcategoriesaxis.h" +#include "qbarcategoriesaxis_p.h" +#include "chartcategoriesaxisx_p.h" +#include "chartcategoriesaxisy_p.h" +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): + QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) +{ +} + +QBarCategoriesAxis::~QBarCategoriesAxis() +{ +} + +QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) +{ + +} + +/*! + Appends \a categories to axis +*/ +void QBarCategoriesAxis::append(const QStringList &categories) +{ + Q_D(QBarCategoriesAxis); + if (d->m_categories.isEmpty()) { + d->m_categories.append(categories); + setRange(categories.first(),categories.last()); + }else{ + d->m_categories.append(categories); + } + + emit categoriesChanged(); +} + +/*! + Appends \a category to axis +*/ +void QBarCategoriesAxis::append(const QString &category) +{ + Q_D(QBarCategoriesAxis); + if (d->m_categories.isEmpty()) { + d->m_categories.append(category); + setRange(category,category); + }else{ + d->m_categories.append(category); + } + emit categoriesChanged(); +} + +/*! + Removes \a category from axis +*/ +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()); + emit categoriesChanged(); + } +} + +/*! + Inserts \a category to axis at \a index +*/ +void QBarCategoriesAxis::insert(int index, const QString &category) +{ + Q_D(QBarCategoriesAxis); + if (d->m_categories.isEmpty()) { + d->m_categories.insert(index,category); + setRange(category,category); + }else{ + + } + emit categoriesChanged(); +} + +/*! + Removes all categories. + */ +void QBarCategoriesAxis::clear() +{ + Q_D(QBarCategoriesAxis); + d->m_categories.clear(); + setRange(QString::null,QString::null); + emit categoriesChanged(); +} + +void QBarCategoriesAxis::setCategories(const QStringList &categories) +{ + Q_D(QBarCategoriesAxis); + if(d->m_categories!=categories){ + d->m_categories = categories; + setRange(categories.first(),categories.last()); + emit categoriesChanged(); + } +} + +QStringList QBarCategoriesAxis::categories() +{ + Q_D(QBarCategoriesAxis); + return d->m_categories; +} + +/*! + Returns number of categories. + */ +int QBarCategoriesAxis::count() const +{ + Q_D(const QBarCategoriesAxis); + return d->m_categories.count(); +} + +/*! + Returns category at \a index. Index must be valid. +*/ +QString QBarCategoriesAxis::at(int index) const +{ + Q_D(const QBarCategoriesAxis); + return d->m_categories.at(index); +} + +/*! + Sets minimum category to \a min. +*/ +void QBarCategoriesAxis::setMin(const QString& min) +{ + Q_D(QBarCategoriesAxis); + setRange(min,d->m_maxCategory); +} + +/*! + Returns minimum category. +*/ +QString QBarCategoriesAxis::min() const +{ + Q_D(const QBarCategoriesAxis); + return d->m_minCategory; +} + +/*! + Sets maximum category to \a max. +*/ +void QBarCategoriesAxis::setMax(const QString& max) +{ + Q_D(QBarCategoriesAxis); + setRange(d->m_minCategory,max); +} + +/*! + Returns maximum category +*/ +QString QBarCategoriesAxis::max() const +{ + Q_D(const QBarCategoriesAxis); + return d->m_maxCategory; +} + +/*! + Sets range from \a minCategory to \a maxCategory +*/ +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_min = minIndex; + emit minChanged(minCategory); + changed = true; + } + + if (!qFuzzyIsNull(d->m_max - (maxIndex))) { + d->m_max = maxIndex; + d->m_maxCategory = maxCategory; + emit maxChanged(maxCategory); + changed = true; + } + + if ((changed)) { + d->emitRange(); + emit categoriesChanged(); + } +} + +/*! + Returns the type of axis. +*/ +QAbstractAxis::AxisType QBarCategoriesAxis::type() const +{ + return AxisTypeCategories; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): + QAbstractAxisPrivate(q) +{ + +} + +QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() +{ + +} + +void QBarCategoriesAxisPrivate::setMin(const QVariant &min) +{ + setRange(min,m_maxCategory); +} + +void QBarCategoriesAxisPrivate::setMax(const QVariant &max) +{ + setRange(m_minCategory,max); +} + +void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) +{ + Q_Q(QBarCategoriesAxis); + QString value1 = min.toString(); + QString value2 = max.toString(); + q->setRange(value1,value2); +} + +int QBarCategoriesAxisPrivate::ticksCount() const +{ + return m_categories.count()+1; +} + +void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) +{ + m_min = min; + m_max = max; + m_ticksCount = count; +} + +ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) +{ + Q_Q( QBarCategoriesAxis); + if(m_orientation == Qt::Vertical){ + return new ChartCategoriesAxisY(q,presenter); + }else{ + return new ChartCategoriesAxisX(q,presenter); + } +} + +void QBarCategoriesAxisPrivate::emitRange() +{ + Q_Q( QBarCategoriesAxis); + if(!q->signalsBlocked()) { + emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); + } +} + + +#include "moc_qbarcategoriesaxis.cpp" +#include "moc_qbarcategoriesaxis_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/qbarcategoriesaxis.h b/src/axis/qbarcategoriesaxis.h new file mode 100644 index 0000000..9fb35e2 --- /dev/null +++ b/src/axis/qbarcategoriesaxis.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QBARCATEGORIESAXIS_H +#define QBARCATEGORIESAXIS_H + +#include "qabstractaxis.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QBarCategoriesAxisPrivate; + +class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis +{ + Q_OBJECT + Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged) + Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged) + Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) + +public: + explicit QBarCategoriesAxis(QObject *parent = 0); + ~QBarCategoriesAxis(); + +protected: + QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0); + +public: + AxisType type() const; + void append(const QStringList &categories); + void append(const QString &category); + void remove(const QString &category); + void insert(int index, const QString &category); + void clear(); + void setCategories(const QStringList &categories); + QStringList categories(); + int count() const; + QString at(int index) const; + + //range handling + void setMin(const QString& minCategory); + QString min() const; + void setMax(const QString& maxCategory); + QString max() const; + void setRange(const QString& minCategory, const QString& maxCategory); + +Q_SIGNALS: + void categoriesChanged(); + void minChanged(const QString &min); + void maxChanged(const QString &max); + void rangeChanged(const QString &min, const QString &max); + +private: + Q_DECLARE_PRIVATE(QBarCategoriesAxis) + Q_DISABLE_COPY(QBarCategoriesAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QCATEGORIESAXIS_H diff --git a/src/axis/qbarcategoriesaxis_p.h b/src/axis/qbarcategoriesaxis_p.h new file mode 100644 index 0000000..4af309d --- /dev/null +++ b/src/axis/qbarcategoriesaxis_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef QBARCATEGORIESAXIS_P_H +#define QBARCATEGORIESAXIS_P_H + +#include "qbarcategoriesaxis.h" +#include "qabstractaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate +{ + Q_OBJECT + +public: + QBarCategoriesAxisPrivate(QBarCategoriesAxis *q); + ~QBarCategoriesAxisPrivate(); + +public: + ChartAxis* createGraphics(ChartPresenter* presenter); + void emitRange(); + +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; + QString m_minCategory; + QString m_maxCategory; + +private: + Q_DECLARE_PUBLIC(QBarCategoriesAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QBARCATEGORIESAXIS_P_H diff --git a/src/axis/qcategoriesaxis.cpp b/src/axis/qcategoriesaxis.cpp index 952904b..8f9d84c 100644 --- a/src/axis/qcategoriesaxis.cpp +++ b/src/axis/qcategoriesaxis.cpp @@ -27,16 +27,16 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): - QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) +QCategoriesAxis::QCategoriesAxis(QObject *parent): + QValuesAxis(*new QCategoriesAxisPrivate(this),parent) { } -QBarCategoriesAxis::~QBarCategoriesAxis() +QCategoriesAxis::~QCategoriesAxis() { } -QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) +QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QValuesAxis(d,parent) { } @@ -44,253 +44,105 @@ QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *par /*! Appends \a categories to axis */ -void QBarCategoriesAxis::append(const QStringList &categories) -{ - Q_D(QBarCategoriesAxis); - if (d->m_categories.isEmpty()) { - d->m_categories.append(categories); - setRange(categories.first(),categories.last()); - }else{ - d->m_categories.append(categories); +void QCategoriesAxis::append(const QString& category, qreal x) +{ + Q_D(QCategoriesAxis); + if (!d->m_categories.contains(category)) + { + if(d->m_categories.isEmpty()){ + Range range(d->m_categoryMinimum,x); + d->m_categoriesMap.insert(category,range); + d->m_categories.append(category); + }else{ + Range range = d->m_categoriesMap.value(d->m_categories.last()); + d->m_categoriesMap.insert(category,Range(range.first,x)); + d->m_categories.append(category); + } + setRange(d->m_min,x); } - - emit categoriesChanged(); } -/*! - Appends \a category to axis -*/ -void QBarCategoriesAxis::append(const QString &category) +void QCategoriesAxis::setFisrtCategoryMinimum(qreal x) { - Q_D(QBarCategoriesAxis); - if (d->m_categories.isEmpty()) { - d->m_categories.append(category); - setRange(category,category); - }else{ - d->m_categories.append(category); - } - emit categoriesChanged(); + Q_D(QCategoriesAxis); + if(d->m_categories.isEmpty()){ + d->m_categoryMinimum=x; + }else{ + Range range = d->m_categoriesMap.value(d->m_categories.first()); + d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second)); + setRange(x,d->m_min); + } } /*! Removes \a category from axis */ -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()); - emit categoriesChanged(); - } -} - -/*! - Inserts \a category to axis at \a index -*/ -void QBarCategoriesAxis::insert(int index, const QString &category) -{ - Q_D(QBarCategoriesAxis); - if (d->m_categories.isEmpty()) { - d->m_categories.insert(index,category); - setRange(category,category); - }else{ - - } - emit categoriesChanged(); -} - -/*! - Removes all categories. - */ -void QBarCategoriesAxis::clear() +void QCategoriesAxis::remove(const QString &category) { - Q_D(QBarCategoriesAxis); - d->m_categories.clear(); - setRange(QString::null,QString::null); - emit categoriesChanged(); + Q_UNUSED(category); + //TODO } -void QBarCategoriesAxis::setCategories(const QStringList &categories) +QStringList QCategoriesAxis::categories() { - Q_D(QBarCategoriesAxis); - if(d->m_categories!=categories){ - d->m_categories = categories; - setRange(categories.first(),categories.last()); - emit categoriesChanged(); - } -} - -QStringList QBarCategoriesAxis::categories() -{ - Q_D(QBarCategoriesAxis); + Q_D(QCategoriesAxis); return d->m_categories; } /*! Returns number of categories. */ -int QBarCategoriesAxis::count() const +int QCategoriesAxis::count() const { - Q_D(const QBarCategoriesAxis); + Q_D(const QCategoriesAxis); return d->m_categories.count(); } /*! - Returns category at \a index. Index must be valid. -*/ -QString QBarCategoriesAxis::at(int index) const -{ - Q_D(const QBarCategoriesAxis); - return d->m_categories.at(index); -} - -/*! - Sets minimum category to \a min. -*/ -void QBarCategoriesAxis::setMin(const QString& min) -{ - Q_D(QBarCategoriesAxis); - setRange(min,d->m_maxCategory); -} - -/*! - Returns minimum category. -*/ -QString QBarCategoriesAxis::min() const -{ - Q_D(const QBarCategoriesAxis); - return d->m_minCategory; -} - -/*! - Sets maximum category to \a max. -*/ -void QBarCategoriesAxis::setMax(const QString& max) -{ - Q_D(QBarCategoriesAxis); - setRange(d->m_minCategory,max); -} - -/*! - Returns maximum category -*/ -QString QBarCategoriesAxis::max() const -{ - Q_D(const QBarCategoriesAxis); - return d->m_maxCategory; -} - -/*! - Sets range from \a minCategory to \a maxCategory -*/ -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_min = minIndex; - changed = true; - } - - if (!qFuzzyIsNull(d->m_max - (maxIndex))) { - d->m_max = maxIndex; - d->m_maxCategory = maxCategory; - changed = true; - } - - if ((changed)) { - d->emitRange(); - emit categoriesChanged(); - } -} - -/*! Returns the type of axis. */ -QAbstractAxis::AxisType QBarCategoriesAxis::type() const +QAbstractAxis::AxisType QCategoriesAxis::type() const { return AxisTypeCategories; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): - QAbstractAxisPrivate(q) +QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q): + QValuesAxisPrivate(q), + m_categoryMinimum(0) { } -QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() +QCategoriesAxisPrivate::~QCategoriesAxisPrivate() { } -void QBarCategoriesAxisPrivate::setMin(const QVariant &min) -{ - setRange(min,m_maxCategory); -} - -void QBarCategoriesAxisPrivate::setMax(const QVariant &max) -{ - setRange(m_minCategory,max); -} - -void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) -{ - Q_Q(QBarCategoriesAxis); - QString value1 = min.toString(); - QString value2 = max.toString(); - q->setRange(value1,value2); -} - -int QBarCategoriesAxisPrivate::ticksCount() const +int QCategoriesAxisPrivate::ticksCount() const { return m_categories.count()+1; } -void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) +void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) { m_min = min; m_max = max; m_ticksCount = count; } -ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) +ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) { - Q_Q( QBarCategoriesAxis); + Q_UNUSED(presenter); + // Q_Q( QCategoriesAxis); if(m_orientation == Qt::Vertical){ - return new ChartCategoriesAxisY(q,presenter); + return 0; }else{ - return new ChartCategoriesAxisX(q,presenter); + return 0; } } -void QBarCategoriesAxisPrivate::emitRange() -{ - Q_Q( QBarCategoriesAxis); - if(!q->signalsBlocked()) { - emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); - } -} - - #include "moc_qcategoriesaxis.cpp" #include "moc_qcategoriesaxis_p.cpp" diff --git a/src/axis/qcategoriesaxis.h b/src/axis/qcategoriesaxis.h index b5493ca..ef91f25 100644 --- a/src/axis/qcategoriesaxis.h +++ b/src/axis/qcategoriesaxis.h @@ -22,53 +22,41 @@ #define QCATEGORIESAXIS_H #include "qabstractaxis.h" +#include "qvaluesaxis.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QBarCategoriesAxisPrivate; +class QCategoriesAxisPrivate; -class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis +class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QValuesAxis { Q_OBJECT - Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged) - Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged) - Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) public: - explicit QBarCategoriesAxis(QObject *parent = 0); - ~QBarCategoriesAxis(); + explicit QCategoriesAxis(QObject *parent = 0); + ~QCategoriesAxis(); protected: - QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0); + QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0); public: AxisType type() const; - void append(const QStringList &categories); - void append(const QString &category); - void remove(const QString &category); - void insert(int index, const QString &category); - void clear(); - void setCategories(const QStringList &categories); + + void append(const QString& category, qreal interval = 1); + void remove(const QString& category); + + void setFisrtCategoryMinimum(qreal x); + + qreal categoryMin(const QString& category) const; + qreal categoryMax(const QString& category) const; + QStringList categories(); int count() const; - QString at(int index) const; - - //range handling - void setMin(const QString& minCategory); - QString min() const; - void setMax(const QString& maxCategory); - QString max() const; - void setRange(const QString& minCategory, const QString& maxCategory); -Q_SIGNALS: - void categoriesChanged(); - void minChanged(const QString &min); - void maxChanged(const QString &max); - void rangeChanged(const QString &min, const QString &max); private: - Q_DECLARE_PRIVATE(QBarCategoriesAxis) - Q_DISABLE_COPY(QBarCategoriesAxis) + Q_DECLARE_PRIVATE(QCategoriesAxis) + Q_DISABLE_COPY(QCategoriesAxis) }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/qcategoriesaxis_p.h b/src/axis/qcategoriesaxis_p.h index bdbd3d6..c5ee93e 100644 --- a/src/axis/qcategoriesaxis_p.h +++ b/src/axis/qcategoriesaxis_p.h @@ -31,27 +31,24 @@ #define QCATEGORIESAXIS_P_H #include "qcategoriesaxis.h" -#include "qabstractaxis_p.h" +#include "qvaluesaxis_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate + +typedef QPair Range; + +class QCategoriesAxisPrivate : public QValuesAxisPrivate { Q_OBJECT public: - QBarCategoriesAxisPrivate(QBarCategoriesAxis *q); - ~QBarCategoriesAxisPrivate(); + QCategoriesAxisPrivate(QCategoriesAxis *q); + ~QCategoriesAxisPrivate(); + public: ChartAxis* createGraphics(ChartPresenter* presenter); - void emitRange(); - -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: @@ -61,12 +58,12 @@ public Q_SLOTS: void handleAxisRangeChanged(qreal min, qreal max,int count); private: + QMap m_categoriesMap; QStringList m_categories; - QString m_minCategory; - QString m_maxCategory; + qreal m_categoryMinimum; private: - Q_DECLARE_PUBLIC(QBarCategoriesAxis) + Q_DECLARE_PUBLIC(QCategoriesAxis) }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 7698c0b..2a63fda 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -28,7 +28,7 @@ #include "charttheme_p.h" #include "chartanimator_p.h" #include "qvaluesaxis.h" -#include "qcategoriesaxis.h" +#include "qbarcategoriesaxis.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 7b7cd47..88c31c8 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -21,7 +21,7 @@ #include "chartdataset_p.h" #include "qchart.h" #include "qvaluesaxis.h" -#include "qcategoriesaxis.h" +#include "qbarcategoriesaxis.h" #include "qvaluesaxis_p.h" #include "qabstractseries_p.h" #include "qabstractbarseries.h" diff --git a/tests/auto/chartdataset/tst_chartdataset.cpp b/tests/auto/chartdataset/tst_chartdataset.cpp index 31259d6..e0ca443 100644 --- a/tests/auto/chartdataset/tst_chartdataset.cpp +++ b/tests/auto/chartdataset/tst_chartdataset.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/chartwidgettest/mainwidget.cpp b/tests/chartwidgettest/mainwidget.cpp index da28d7a..7e43fb5 100644 --- a/tests/chartwidgettest/mainwidget.cpp +++ b/tests/chartwidgettest/mainwidget.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE