From 83291e82d98370b3086e85bbc7bcca97667f15a4 2012-06-26 15:40:06 From: Michal Klocek Date: 2012-06-26 15:40:06 Subject: [PATCH] Adds new API classes * qabstractaxis * avaluesaxis * qcategoriesaxis --- diff --git a/src/axis/axis.pri b/src/axis/axis.pri index 96b8afe..a9bd496 100644 --- a/src/axis/axis.pri +++ b/src/axis/axis.pri @@ -6,15 +6,24 @@ SOURCES += \ $$PWD/chartaxisx.cpp \ $$PWD/chartaxisy.cpp \ $$PWD/qaxis.cpp \ - $$PWD/qaxiscategories.cpp + $$PWD/qaxiscategories.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/qaxis_p.h \ - $$PWD/qaxiscategories_p.h + $$PWD/qaxiscategories_p.h \ + $$PWD/qcategoriesaxis_p.h \ + $$PWD/qvaluesaxis_p.h \ + $$PWD/qabstractaxis_p.h PUBLIC_HEADERS += \ $$PWD/qaxis.h \ - $$PWD/qaxiscategories.h \ No newline at end of file + $$PWD/qaxiscategories.h \ + $$PWD/qcategoriesaxis.h \ + $$PWD/qvaluesaxis.h \ + $$PWD/qabstractaxis.h \ No newline at end of file diff --git a/src/axis/qabstractaxis.cpp b/src/axis/qabstractaxis.cpp new file mode 100644 index 0000000..daed62f --- /dev/null +++ b/src/axis/qabstractaxis.cpp @@ -0,0 +1,573 @@ +/**************************************************************************** +** +** 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.h" +#include "qabstractaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +/*! + \class QAbstractAxis + \brief The QAbstractAxis class is used for manipulating chart's axis. + \mainclass + + There is only one x Axis, however there can be multiple y axes. + Each chart series can be bound to exactly one Y axis and the shared common X axis. + Axis can be setup to show axis line with tick marks, grid lines and shades. +*/ + +/*! + \qmlclass Axis QAbstractAxis + \brief The Axis element is used for manipulating chart's axes + + There is only one x Axis, however there can be multiple y axes on a ChartView. + Each chart series can be bound to exactly one Y axis and the shared common X axis. + Axis can be setup to show axis line with tick marks, grid lines and shades. + + To access Axes you can use ChartView API. For example: + \code + ChartView { + axisX.min: 0 + axisX.max: 3 + axisX.ticksCount: 4 + axisY.min: 0 + axisY.max: 4 + // Add a few series... + } + \endcode +*/ + +/*! + \property QAbstractAxis::labelsVisible + Defines if axis labels are visible. +*/ +/*! + \qmlproperty bool Axis::labelsVisible + Defines if axis labels are visible. +*/ + +/*! + \property QAbstractAxis::min + Defines the minimum value on the axis. +*/ +/*! + \qmlproperty real Axis::min + Defines the minimum value on the axis. +*/ + +/*! + \property QAbstractAxis::max + Defines the maximum value on the axis. +*/ +/*! + \qmlproperty real Axis::max + Defines the maximum value on the axis. +*/ + +/*! + \property QAbstractAxis::visible + The visibility of the axis. +*/ +/*! + \qmlproperty bool Axis::visible + The visibility of the axis. +*/ + +/*! + \property QAbstractAxis::gridVisible + The visibility of the grid lines. +*/ +/*! + \qmlproperty bool Axis::gridVisible + The visibility of the grid lines. +*/ + +/*! + \property QAbstractAxis::color + The color of the axis and ticks. +*/ +/*! + \qmlproperty color Axis::color + The color of the axis and ticks. +*/ + +/*! + \property QAxis::labelsFont + The font of the axis labels. +*/ +/*! + \qmlproperty Font Axis::labelsFont + The font of the axis labels. + + See the \l {Font} {QML Font Element} for detailed documentation. +*/ + +/*! + \property QAbstractAxis::labelsColor + The color of the axis labels. +*/ +/*! + \qmlproperty color Axis::labelsColor + The color of the axis labels. +*/ + +/*! + \property QAbstractAxis::labelsAngle + The angle of the axis labels in degrees. +*/ +/*! + \qmlproperty int Axis::labelsAngle + The angle of the axis labels in degrees. +*/ + +/*! + \property QAbstractAxis::shadesVisible + The visibility of the axis shades. +*/ +/*! + \qmlproperty bool Axis::shadesVisible + The visibility of the axis shades. +*/ + +/*! + \property QAbstractAxis::shadesColor + The fill (brush) color of the axis shades. +*/ +/*! + \qmlproperty color Axis::shadesColor + The fill (brush) color of the axis shades. +*/ + +/*! + \property QAbstractAxis::shadesBorderColor + The border (pen) color of the axis shades. +*/ +/*! + \qmlproperty color Axis::shadesBorderColor + The border (pen) color of the axis shades. +*/ + +/*! + \property QAbstractAxis::ticksCount + The number of tick marks for the axis. +*/ +/*! + \qmlproperty int Axis::ticksCount + The number of tick marks for the axis. +*/ + +/*! + \property QAbstractAxis::niceNumbersEnabled + Whether the nice numbers algorithm is enabled or not for the axis. +*/ +/*! + \qmlproperty bool Axis::niceNumbersEnabled + Whether the nice numbers algorithm is enabled or not for the axis. +*/ + +/*! + \fn void QAbstractAxis::visibleChanged(bool) + Visiblity of the axis has changed to \a visible. +*/ + +/*! + \fn void QAbstractAxis::labelsVisibleChanged(bool) + Visiblity of the labels of the axis has changed to \a visible. +*/ + +/*! + \fn void QAbstractAxis::gridVisibleChanged(bool) + Visiblity of the grid lines of the axis has changed to \a visible. +*/ + +/*! + \fn void QAbstractAxis::minChanged(qreal min) + Axis emits signal when \a min of axis has changed. +*/ + +/*! + \fn void QAbstractAxis::maxChanged(qreal max) + Axis emits signal when \a max of axis has changed. +*/ + +/*! + \fn void QAbstractAxis::rangeChanged(qreal min, qreal max) + Axis emits signal when \a min or \a max of axis has changed. +*/ + +/*! + \fn QChartAxisCategories* QAbstractAxis::categories() + Returns pointer to the list of categories which correspond to the values on the axis. +*/ + +/*! + \fn void QAbstractAxis::colorChanged(QColor) + Emitted if the \a color of the axis is changed. +*/ + +/*! + \fn void QAbstractAxis::labelsColorChanged(QColor) + Emitted if the \a color of the axis labels is changed. +*/ + +/*! + \fn void QAbstractAxis::shadesVisibleChanged(bool) + Emitted if the visibility of the axis shades is changed to \a visible. +*/ + +/*! + \fn void QAbstractAxis::shadesColorChanged(QColor) + Emitted if the \a color of the axis shades is changed. +*/ + +/*! + \fn void QAbstractAxis::shadesBorderColorChanged(QColor) + Emitted if the border \a color of the axis shades is changed. +*/ + +/*! + Constructs new axis object which is a child of \a parent. Ownership is taken by + QChart when axis added. +*/ + +QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : +QObject(parent), +d_ptr(&d) +{ +} + +/*! + Destructor of the axis object. When axis is added to chart, chart object takes ownership. +*/ + +QAbstractAxis::~QAbstractAxis() +{ +} + +/*! + Sets \a pen used to draw axis line and ticks. + */ +void QAbstractAxis::setAxisPen(const QPen &pen) +{ + if (d_ptr->m_axisPen!=pen) { + d_ptr->m_axisPen = pen; + emit d_ptr->updated(); + } +} + +/*! + Returns pen used to draw axis and ticks. +*/ +QPen QAbstractAxis::axisPen() const +{ + return d_ptr->m_axisPen; +} + +void QAbstractAxis::setAxisPenColor(QColor color) +{ + QPen p = d_ptr->m_axisPen; + if (p.color() != color) { + p.setColor(color); + setAxisPen(p); + emit colorChanged(color); + } +} + +QColor QAbstractAxis::axisPenColor() const +{ + return d_ptr->m_axisPen.color(); +} + +/*! + Sets if axis and ticks are \a visible. + */ +void QAbstractAxis::setAxisVisible(bool visible) +{ + if (d_ptr->m_axisVisible != visible) { + d_ptr->m_axisVisible = visible; + emit d_ptr->updated(); + emit visibleChanged(visible); + } +} + +bool QAbstractAxis::isAxisVisible() const +{ + return d_ptr->m_axisVisible; +} + +void QAbstractAxis::setGridLineVisible(bool visible) +{ + if (d_ptr->m_gridLineVisible != visible) { + d_ptr->m_gridLineVisible = visible; + emit d_ptr->updated(); + emit gridVisibleChanged(visible); + } +} + +bool QAbstractAxis::isGridLineVisible() const +{ + return d_ptr->m_gridLineVisible; +} + +/*! + Sets \a pen used to draw grid line. +*/ +void QAbstractAxis::setGridLinePen(const QPen &pen) +{ + if (d_ptr->m_gridLinePen != pen) { + d_ptr->m_gridLinePen = pen; + emit d_ptr->updated(); + } +} + +/*! + Returns pen used to draw grid. +*/ +QPen QAbstractAxis::gridLinePen() const +{ + return d_ptr->m_gridLinePen; +} + +void QAbstractAxis::setLabelsVisible(bool visible) +{ + if (d_ptr->m_labelsVisible != visible) { + d_ptr->m_labelsVisible = visible; + emit d_ptr->updated(); + emit labelsVisibleChanged(visible); + } +} + +bool QAbstractAxis::labelsVisible() const +{ + return d_ptr->m_labelsVisible; +} + +/*! + Sets \a pen used to draw labels. +*/ +void QAbstractAxis::setLabelsPen(const QPen &pen) +{ + if (d_ptr->m_labelsPen != pen) { + d_ptr->m_labelsPen = pen; + emit d_ptr->updated(); + } +} + +/*! + Returns the pen used to labels. +*/ +QPen QAbstractAxis::labelsPen() const +{ + return d_ptr->m_labelsPen; +} + +/*! + Sets \a brush used to draw labels. + */ +void QAbstractAxis::setLabelsBrush(const QBrush &brush) +{ + if (d_ptr->m_labelsBrush != brush) { + d_ptr->m_labelsBrush = brush; + emit d_ptr->updated(); + } +} + +/*! + Returns brush used to draw labels. +*/ +QBrush QAbstractAxis::labelsBrush() const +{ + return d_ptr->m_labelsBrush; +} + +/*! + Sets \a font used to draw labels. +*/ +void QAbstractAxis::setLabelsFont(const QFont &font) +{ + if (d_ptr->m_labelsFont != font) { + d_ptr->m_labelsFont = font; + emit d_ptr->updated(); + } +} + +/*! + Returns font used to draw labels. +*/ +QFont QAbstractAxis::labelsFont() const +{ + return d_ptr->m_labelsFont; +} + +void QAbstractAxis::setLabelsAngle(int angle) +{ + if (d_ptr->m_labelsAngle != angle) { + d_ptr->m_labelsAngle = angle; + emit d_ptr->updated(); + } +} + +int QAbstractAxis::labelsAngle() const +{ + return d_ptr->m_labelsAngle; +} + +void QAbstractAxis::setLabelsColor(QColor color) +{ + QBrush b = d_ptr->m_labelsBrush; + if (b.color() != color) { + b.setColor(color); + setLabelsBrush(b); + emit labelsColorChanged(color); + } +} + +QColor QAbstractAxis::labelsColor() const +{ + return d_ptr->m_labelsBrush.color(); +} + +void QAbstractAxis::setShadesVisible(bool visible) +{ + if (d_ptr->m_shadesVisible != visible) { + d_ptr->m_shadesVisible = visible; + emit d_ptr->updated(); + emit shadesVisibleChanged(visible); + } +} + +bool QAbstractAxis::shadesVisible() const +{ + return d_ptr->m_shadesVisible; +} + +/*! + Sets \a pen used to draw shades. +*/ +void QAbstractAxis::setShadesPen(const QPen &pen) +{ + if (d_ptr->m_shadesPen != pen) { + d_ptr->m_shadesPen = pen; + emit d_ptr->updated(); + } +} + +/*! + Returns pen used to draw shades. +*/ +QPen QAbstractAxis::shadesPen() const +{ + return d_ptr->m_shadesPen; +} + +/*! + Sets \a brush used to draw shades. +*/ +void QAbstractAxis::setShadesBrush(const QBrush &brush) +{ + if (d_ptr->m_shadesBrush != brush) { + d_ptr->m_shadesBrush = brush; + emit d_ptr->updated(); + emit shadesColorChanged(brush.color()); + } +} + +/*! + Returns brush used to draw shades. +*/ +QBrush QAbstractAxis::shadesBrush() const +{ + return d_ptr->m_shadesBrush; +} + +void QAbstractAxis::setShadesColor(QColor color) +{ + QBrush b = d_ptr->m_shadesBrush; + b.setColor(color); + setShadesBrush(b); +} + +QColor QAbstractAxis::shadesColor() const +{ + return d_ptr->m_shadesBrush.color(); +} + +void QAbstractAxis::setShadesBorderColor(QColor color) +{ + QPen p = d_ptr->m_shadesPen; + p.setColor(color); + setShadesPen(p); +} + +QColor QAbstractAxis::shadesBorderColor() const +{ + return d_ptr->m_shadesPen.color(); +} + + +/*! + Sets axis, shades, labels and grid lines to be visible. +*/ +void QAbstractAxis::show() +{ + d_ptr->m_axisVisible=true; + d_ptr->m_gridLineVisible=true; + d_ptr->m_labelsVisible=true; + d_ptr->m_shadesVisible=true; + emit d_ptr->updated(); +} + +/*! + Sets axis, shades, labels and grid lines to not be visible. +*/ +void QAbstractAxis::hide() +{ + d_ptr->m_axisVisible = false; + d_ptr->m_gridLineVisible = false; + d_ptr->m_labelsVisible = false; + d_ptr->m_shadesVisible = false; + emit d_ptr->updated(); +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): + q_ptr(q), + m_axisVisible(true), + m_gridLineVisible(true), + m_labelsVisible(true), + m_labelsAngle(0), + m_shadesVisible(false), + m_shadesBrush(Qt::SolidPattern), + m_shadesOpacity(1.0) +{ + +} + +QAbstractAxisPrivate::~QAbstractAxisPrivate() +{ + +} + +#include "moc_qabstractaxis.cpp" +#include "moc_qabstractaxis_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/qabstractaxis.h b/src/axis/qabstractaxis.h new file mode 100644 index 0000000..0d7dcbc --- /dev/null +++ b/src/axis/qabstractaxis.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** 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 QABSTRACTAXIS_H +#define QABSTRACTAXIS_H + +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QAbstractAxisPrivate; + +class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) + Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) + Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) + Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) + Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) + Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) + Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) + Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) + Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) + Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) + //Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) + //Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) + +public: + + enum AxisType { + AxisTypeValues, + AxisTypeCategories + }; + +protected: + explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); + +public: + ~QAbstractAxis(); + + virtual AxisType type() const = 0; + + //axis handling + bool isAxisVisible() const; + void setAxisVisible(bool visible = true); + void setAxisPen(const QPen &pen); + QPen axisPen() const; + void setAxisPenColor(QColor color); + QColor axisPenColor() const; + + //grid handling + bool isGridLineVisible() const; + void setGridLineVisible(bool visible = true); + void setGridLinePen(const QPen &pen); + QPen gridLinePen() const; + + //labels handling + bool labelsVisible() const; + void setLabelsVisible(bool visible = true); + void setLabelsPen(const QPen &pen); + QPen labelsPen() const; + void setLabelsBrush(const QBrush &brush); + QBrush labelsBrush() const; + void setLabelsFont(const QFont &font); + QFont labelsFont() const; + void setLabelsAngle(int angle); + int labelsAngle() const; + void setLabelsColor(QColor color); + QColor labelsColor() const; + + //shades handling + bool shadesVisible() const; + void setShadesVisible(bool visible = true); + void setShadesPen(const QPen &pen); + QPen shadesPen() const; + void setShadesBrush(const QBrush &brush); + QBrush shadesBrush() const; + void setShadesColor(QColor color); + QColor shadesColor() const; + void setShadesBorderColor(QColor color); + QColor shadesBorderColor() const; + + int ticksCount() const; + + void show(); + void hide(); + +Q_SIGNALS: + void visibleChanged(bool visible); + void labelsVisibleChanged(bool visible); + void gridVisibleChanged(bool visible); + void rangeChanged(); + void colorChanged(QColor color); + void labelsColorChanged(QColor color); + void shadesVisibleChanged(bool visible); + void shadesColorChanged(QColor color); + void shadesBorderColorChanged(QColor color); + void minChanged(); + void maxChanged(); + +protected: + QScopedPointer d_ptr; + Q_DISABLE_COPY(QAbstractAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE +#endif diff --git a/src/axis/qabstractaxis_p.h b/src/axis/qabstractaxis_p.h new file mode 100644 index 0000000..9ad29b1 --- /dev/null +++ b/src/axis/qabstractaxis_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 QABSTRACTAXIS_P_H +#define QABSTRACTAXIS_P_H + +#include "qabstractaxis.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QAbstractAxisPrivate : public QObject +{ + Q_OBJECT +public: + QAbstractAxisPrivate(QAbstractAxis *q); + ~QAbstractAxisPrivate(); + +Q_SIGNALS: + void updated(); + +protected: + QAbstractAxis *q_ptr; + + bool m_axisVisible; + QPen m_axisPen; + QBrush m_axisBrush; + + bool m_gridLineVisible; + QPen m_gridLinePen; + + bool m_labelsVisible; + QPen m_labelsPen; + QBrush m_labelsBrush; + QFont m_labelsFont; + int m_labelsAngle; + + bool m_shadesVisible; + QPen m_shadesPen; + QBrush m_shadesBrush; + qreal m_shadesOpacity; + + friend class QAbstractAxis; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif diff --git a/src/axis/qcategoriesaxis.cpp b/src/axis/qcategoriesaxis.cpp new file mode 100644 index 0000000..12f3c30 --- /dev/null +++ b/src/axis/qcategoriesaxis.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** 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 "qcategoriesaxis.h" +#include "qcategoriesaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QCategoriesAxis::QCategoriesAxis(QObject *parent): + QAbstractAxis(*new QCategoriesAxisPrivate(this),parent) +{ + +} + +QCategoriesAxis::~QCategoriesAxis() +{ + +} + +QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) +{ + +} + +/*! + Appends \a categories to axis +*/ +void QCategoriesAxis::append(QStringList &categories) +{ + Q_D(QCategoriesAxis); + d->m_categories.append(categories); + emit categoriesChanged(); +} + +/*! + Appends \a category to axis +*/ +void QCategoriesAxis::append(const QString &category) +{ + Q_D(QCategoriesAxis); + d->m_categories.append(category); + emit categoriesChanged(); +} + +/*! + Removes \a category from axis +*/ +void QCategoriesAxis::remove(const QString &category) +{ + Q_D(QCategoriesAxis); + if (d->m_categories.contains(category)) { + d->m_categories.removeAt(d->m_categories.indexOf(category)); + emit categoriesChanged(); + } +} + +/*! + Inserts \a category to axis at \a index +*/ +void QCategoriesAxis::insert(int index, const QString &category) +{ + Q_D(QCategoriesAxis); + d->m_categories.insert(index,category); + emit categoriesChanged(); +} + +/*! + Removes all categories. + */ +void QCategoriesAxis::clear() +{ + Q_D(QCategoriesAxis); + d->m_categories.clear(); + emit categoriesChanged(); +} + +/*! + Returns number of categories. + */ +int QCategoriesAxis::count() +{ + Q_D(QCategoriesAxis); + return d->m_categories.count(); +} + +/*! + Returns category at \a index. Index must be valid. +*/ +QString QCategoriesAxis::at(int index) const +{ + Q_D(const QCategoriesAxis); + return d->m_categories.at(index); +} + +/*! + Sets minimum category to \a minCategory. +*/ +void QCategoriesAxis::setMin(QString minCategory) +{ + Q_D(QCategoriesAxis); + int minIndex = d->m_categories.indexOf(minCategory); + if (minIndex == -1) + return; +// else +// QAbstractAxis::setMin(minIndex); +} + +/*! + Sets maximum category to \a maxCategory. +*/ +void QCategoriesAxis::setMax(QString maxCategory) +{ + Q_D(QCategoriesAxis); + int maxIndex = d->m_categories.indexOf(maxCategory); + if (maxIndex == -1) + return; +// else +// QAbstractAxis::setMax(maxIndex); +} + +/*! + Sets range from \a minCategory to \a maxCategory +*/ +void QCategoriesAxis::setRange(QString minCategory, QString maxCategory) +{ + // TODO: what if maxCategory < minCategory? + setMin(minCategory); + setMax(maxCategory); +} + +/*! + Returns the type of axis. +*/ +QAbstractAxis::AxisType QCategoriesAxis::type() const +{ + return AxisTypeCategories; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q): + QAbstractAxisPrivate(q) +{ + +} + +QCategoriesAxisPrivate::~QCategoriesAxisPrivate() +{ + +} + +#include "moc_qcategoriesaxis.cpp" +#include "moc_qcategoriesaxis_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/qcategoriesaxis.h b/src/axis/qcategoriesaxis.h new file mode 100644 index 0000000..9457597 --- /dev/null +++ b/src/axis/qcategoriesaxis.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 QCATEGORIESAXIS_H +#define QCATEGORIESAXIS_H + +#include "qabstractaxis.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QCategoriesAxisPrivate; + +class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis +{ + Q_OBJECT + +public: + explicit QCategoriesAxis(QObject *parent = 0); + ~QCategoriesAxis(); + +protected: + QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0); + +public: + AxisType type() const; + void append(QStringList &categories); + void append(const QString &category); + void remove(const QString &category); + void insert(int index, const QString &category); + void clear(); + int count(); + + QString at(int index) const; + + //range handling convenience functions + void setMin(QString minCategory); + void setMax(QString maxCategory); + void setRange(QString minCategory, QString maxCategory); + +Q_SIGNALS: + void categoriesChanged(); + +private: + Q_DECLARE_PRIVATE(QCategoriesAxis) + Q_DISABLE_COPY(QCategoriesAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QCATEGORIESAXIS_H diff --git a/src/axis/qcategoriesaxis_p.h b/src/axis/qcategoriesaxis_p.h new file mode 100644 index 0000000..d1e8cd5 --- /dev/null +++ b/src/axis/qcategoriesaxis_p.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 QCATEGORIESAXIS_P_H +#define QCATEGORIESAXIS_P_H + +#include "qcategoriesaxis.h" +#include "qabstractaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QCategoriesAxisPrivate : public QAbstractAxisPrivate +{ + Q_OBJECT + +public: + QCategoriesAxisPrivate(QCategoriesAxis *q); + ~QCategoriesAxisPrivate(); + +private: + QStringList m_categories; + QString m_minCategory; + QString m_maxCategory; + +Q_SIGNALS: + void updated(); + +private: + Q_DECLARE_PUBLIC(QCategoriesAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QCATEGORIESAXIS_P_H diff --git a/src/axis/qvaluesaxis.cpp b/src/axis/qvaluesaxis.cpp new file mode 100644 index 0000000..17d233a --- /dev/null +++ b/src/axis/qvaluesaxis.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** 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 "qvaluesaxis.h" +#include "qvaluesaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QValuesAxis::QValuesAxis(QObject *parent) : + QAbstractAxis(*new QValuesAxisPrivate(this),parent) +{ + +} + +QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) +{ + +} + +QValuesAxis::~QValuesAxis() +{ + +} + +void QValuesAxis::setMin(qreal min) +{ + Q_D(QValuesAxis); + setRange(min,d->m_max); +} + +qreal QValuesAxis::min() const +{ + Q_D(const QValuesAxis); + return d->m_min; +} + +void QValuesAxis::setMax(qreal max) +{ + Q_D(QValuesAxis); + setRange(d->m_min,max); +} + +qreal QValuesAxis::max() const +{ + Q_D(const QValuesAxis); + return d->m_max; +} + +/*! + Sets range from \a min to \a max on the axis. +*/ +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; + emit minChanged(min); + } + + if (!qFuzzyIsNull(d->m_max - max)) { + d->m_max = max; + changed = true; + emit maxChanged(max); + } + + if (changed) { + emit rangeChanged(d->m_min,d->m_max); + emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); + } +} + +/*! + Sets \a count for ticks on the axis. +*/ +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); + } +} + +/*! + \fn int QAbstractAxis::ticksCount() const + Return number of ticks on the axis +*/ +int QValuesAxis::ticksCount() const +{ + Q_D(const QValuesAxis); + return d->m_ticksCount; +} + +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); + } +} + +bool QValuesAxis::niceNumbersEnabled() const +{ + Q_D(const QValuesAxis); + return d->m_niceNumbers; +} + +QAbstractAxis::AxisType QValuesAxis::type() const +{ + return AxisTypeValues; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): + QAbstractAxisPrivate(q), + m_min(0), + m_max(0), + m_niceNumbers(false), + m_ticksCount(5) +{ + +} + +QValuesAxisPrivate::~QValuesAxisPrivate() +{ + +} + +void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) +{ + Q_Q(QValuesAxis); + q->setRange(min,max); + q->setTicksCount(count); +} + +#include "moc_qvaluesaxis.cpp" +#include "moc_qvaluesaxis_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/qvaluesaxis.h b/src/axis/qvaluesaxis.h new file mode 100644 index 0000000..a1d1b64 --- /dev/null +++ b/src/axis/qvaluesaxis.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$ +** +****************************************************************************/ + +#ifndef QVALUESAXIS_H +#define QVALUESAXIS_H + +#include "qabstractaxis.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QValuesAxisPrivate; + +class QTCOMMERCIALCHART_EXPORT QValuesAxis : public QAbstractAxis +{ + Q_OBJECT + Q_PROPERTY(int ticksCount READ ticksCount WRITE setTicksCount) + Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) + Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) + Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) + +public: + explicit QValuesAxis(QObject *parent = 0); + ~QValuesAxis(); + +protected: + QValuesAxis(QValuesAxisPrivate &d,QObject *parent = 0); + +public: + AxisType type() const; + + //range handling + void setMin(qreal min); + qreal min() const; + void setMax(qreal max); + qreal max() const; + void setRange(qreal min, qreal max); + + //ticks handling + void setTicksCount(int count); + int ticksCount() const; + + void setNiceNumbersEnabled(bool enable = true); + bool niceNumbersEnabled() const; + +Q_SIGNALS: + void minChanged(qreal min); + void maxChanged(qreal max); + void rangeChanged(qreal min, qreal max); + +private: + Q_DECLARE_PRIVATE(QValuesAxis) + Q_DISABLE_COPY(QValuesAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QVALUESAXIS_H diff --git a/src/axis/qvaluesaxis_p.h b/src/axis/qvaluesaxis_p.h new file mode 100644 index 0000000..9419638 --- /dev/null +++ b/src/axis/qvaluesaxis_p.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 QVALUESAXIS_P_H +#define QVALUESAXIS_P_H + +#include "qvaluesaxis.h" +#include "qabstractaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QValuesAxisPrivate : public QAbstractAxisPrivate +{ + Q_OBJECT +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); + +private: + qreal m_min; + qreal m_max; + bool m_niceNumbers; + int m_ticksCount; + Q_DECLARE_PUBLIC(QValuesAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QVALUESAXIS_P_H