qchartaxis.cpp
421 lines
| 8.3 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r794 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
Michal Klocek
|
r72 | #include "qchartaxis.h" | ||
Michal Klocek
|
r85 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Michal Klocek
|
r331 | /*! | ||
\class QChartAxis | ||||
\brief The QChartAxis class is used for manipulating chart's axis | ||||
and for adding optional axes to the chart. | ||||
\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 share common X axis. | ||||
Axis can be setup to show axis line with ticks, gird lines and shades. | ||||
*/ | ||||
Michal Klocek
|
r333 | /*! | ||
\fn bool QChartAxis::isAxisVisible() const | ||||
\brief Returns if axis is visible | ||||
\sa setAxisVisible() | ||||
*/ | ||||
Michal Klocek
|
r331 | /*! | ||
\fn QPen QChartAxis::axisPen() const | ||||
\brief Returns pen used to draw axis and ticks. | ||||
\sa setAxisPen() | ||||
*/ | ||||
Michal Klocek
|
r333 | |||
/*! | ||||
Michal Klocek
|
r535 | \fn bool QChartAxis::isGridLineVisible() const | ||
Michal Klocek
|
r333 | \brief Returns if grid is visible | ||
Michal Klocek
|
r535 | \sa setGridLineVisible() | ||
Michal Klocek
|
r333 | */ | ||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r551 | \fn QPen QChartAxis::gridLinePen() const | ||
Michal Klocek
|
r331 | \brief Returns pen used to draw grid. | ||
Michal Klocek
|
r551 | \sa setGridLinePen() | ||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r333 | /*! | ||
Michal Klocek
|
r365 | \fn bool QChartAxis::labelsVisible() const | ||
Michal Klocek
|
r333 | \brief Returns if grid is visible | ||
\sa setLabelsVisible() | ||||
*/ | ||||
Michal Klocek
|
r331 | /*! | ||
\fn QPen QChartAxis::labelsPen() const | ||||
Michal Klocek
|
r333 | \brief Returns the pen used to labels. | ||
Michal Klocek
|
r331 | \sa setLabelsPen() | ||
*/ | ||||
/*! | ||||
\fn QBrush QChartAxis::labelsBrush() const | ||||
Michal Klocek
|
r333 | \brief Returns brush used to draw labels. | ||
Michal Klocek
|
r331 | \sa setLabelsBrush() | ||
*/ | ||||
/*! | ||||
\fn QFont QChartAxis::labelsFont() const | ||||
Michal Klocek
|
r333 | \brief Returns font used to draw labels. | ||
Michal Klocek
|
r331 | \sa setLabelsFont() | ||
*/ | ||||
/*! | ||||
\fn QFont QChartAxis::labelsAngle() const | ||||
Michal Klocek
|
r333 | \brief Returns angle used to draw labels. | ||
Michal Klocek
|
r331 | \sa setLabelsAngle() | ||
*/ | ||||
Michal Klocek
|
r333 | /*! | ||
Michal Klocek
|
r365 | \fn bool QChartAxis::shadesVisible() const | ||
Michal Klocek
|
r333 | \brief Returns if shades are visible. | ||
\sa setShadesVisible() | ||||
*/ | ||||
/*! | ||||
\fn qreal QChartAxis::shadesOpacity() const | ||||
\brief Returns opacity of shades. | ||||
*/ | ||||
Michal Klocek
|
r331 | /*! | ||
\fn QPen QChartAxis::shadesPen() const | ||||
Michal Klocek
|
r333 | \brief Returns pen used to draw shades. | ||
Michal Klocek
|
r331 | \sa setShadesPen() | ||
*/ | ||||
/*! | ||||
\fn QBrush QChartAxis::shadesBrush() const | ||||
Michal Klocek
|
r333 | \brief Returns brush used to draw shades. | ||
Michal Klocek
|
r331 | \sa setShadesBrush() | ||
*/ | ||||
Michal Klocek
|
r333 | /*! | ||
\fn qreal QChartAxis::min() const | ||||
\brief Returns minimum value on the axis. | ||||
\sa setMin() | ||||
*/ | ||||
/*! | ||||
\fn qreal QChartAxis::max() const | ||||
\brief Returns maximim value on the axis. | ||||
\sa setMax() | ||||
*/ | ||||
/*! | ||||
\fn void QChartAxis::minChanged(qreal min) | ||||
\brief Axis emits signal when \a min of axis has changed. | ||||
*/ | ||||
/*! | ||||
\fn void QChartAxis::maxChanged(qreal max) | ||||
\brief Axis emits signal when \a max of axis has changed. | ||||
*/ | ||||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r439 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) | ||
\brief Axis emits signal when \a min or \a max of axis has changed. | ||||
Michal Klocek
|
r331 | */ | ||
/*! | ||||
Michal Klocek
|
r439 | \fn int QChartAxis::ticksCount() const | ||
\brief Return number of ticks on the axis | ||||
\sa setTicksCount() | ||||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r400 | /*! | ||
Michal Klocek
|
r441 | \fn void QChartAxis::updated() | ||
Michal Klocek
|
r400 | \brief \internal | ||
*/ | ||||
/*! | ||||
Michal Klocek
|
r439 | \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) | ||
Michal Klocek
|
r400 | \brief \internal \a min \a max | ||
*/ | ||||
Michal Klocek
|
r331 | /*! | ||
Constructs new axis object which is a child of \a parent. Ownership is taken by | ||||
QChatView or QChart when axis added. | ||||
*/ | ||||
sauimone
|
r759 | QChartAxis::QChartAxis(QObject *parent) : QObject(parent), | ||
m_axisVisible(true), | ||||
m_gridLineVisible(true), | ||||
m_labelsVisible(true), | ||||
m_labelsAngle(0), | ||||
m_shadesVisible(false), | ||||
m_shadesOpacity(1.0), | ||||
m_min(0), | ||||
m_max(0), | ||||
m_ticksCount(5), | ||||
m_niceNumbers(false) | ||||
Michal Klocek
|
r72 | { | ||
} | ||||
Michal Klocek
|
r331 | /*! | ||
Destructor of the axis object. When axis is added to chart, chart object takes ownership. | ||||
*/ | ||||
Michal Klocek
|
r72 | QChartAxis::~QChartAxis() | ||
{ | ||||
} | ||||
Michal Klocek
|
r331 | /*! | ||
Sets \a pen used to draw axis line and ticks. | ||||
*/ | ||||
sauimone
|
r759 | void QChartAxis::setAxisPen(const QPen &pen) | ||
Michal Klocek
|
r140 | { | ||
Michal Klocek
|
r439 | if (pen != m_axisPen) { | ||
sauimone
|
r759 | m_axisPen = pen; | ||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r140 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets if axis and ticks are \a visible. | ||||
*/ | ||||
Michal Klocek
|
r85 | void QChartAxis::setAxisVisible(bool visible) | ||
{ | ||||
sauimone
|
r759 | if (m_axisVisible != visible) { | ||
m_axisVisible = visible; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r535 | Sets if grid line is \a visible. | ||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r535 | void QChartAxis::setGridLineVisible(bool visible) | ||
Michal Klocek
|
r85 | { | ||
sauimone
|
r759 | if (m_gridLineVisible != visible) { | ||
m_gridLineVisible = visible; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r535 | Sets \a pen used to draw grid line. | ||
Michal Klocek
|
r331 | */ | ||
sauimone
|
r759 | void QChartAxis::setGridLinePen(const QPen &pen) | ||
Michal Klocek
|
r176 | { | ||
sauimone
|
r759 | if (m_gridLinePen != pen) { | ||
m_gridLinePen = pen; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets if axis' labels are \a visible. | ||||
*/ | ||||
Michal Klocek
|
r85 | void QChartAxis::setLabelsVisible(bool visible) | ||
{ | ||||
sauimone
|
r759 | if (m_labelsVisible != visible) { | ||
m_labelsVisible = visible; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a pen used to draw labels. | ||||
*/ | ||||
sauimone
|
r759 | void QChartAxis::setLabelsPen(const QPen &pen) | ||
Michal Klocek
|
r176 | { | ||
sauimone
|
r759 | if (m_labelsPen != pen) { | ||
m_labelsPen = pen; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a brush used to draw labels. | ||||
*/ | ||||
sauimone
|
r759 | void QChartAxis::setLabelsBrush(const QBrush &brush) | ||
Michal Klocek
|
r176 | { | ||
sauimone
|
r759 | if (m_labelsBrush != brush) { | ||
m_labelsBrush = brush; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a font used to draw labels. | ||||
*/ | ||||
sauimone
|
r759 | void QChartAxis::setLabelsFont(const QFont &font) | ||
Michal Klocek
|
r176 | { | ||
sauimone
|
r759 | if (m_labelsFont != font) { | ||
m_labelsFont = font; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a angle for all the labels on given axis. | ||||
*/ | ||||
Michal Klocek
|
r223 | void QChartAxis::setLabelsAngle(int angle) | ||
Michal Klocek
|
r176 | { | ||
sauimone
|
r759 | if (m_labelsAngle != angle) { | ||
m_labelsAngle = angle; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets if shades are \a visible. | ||||
*/ | ||||
Michal Klocek
|
r176 | void QChartAxis::setShadesVisible(bool visible) | ||
{ | ||||
sauimone
|
r759 | if (m_shadesVisible != visible) { | ||
m_shadesVisible = visible; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a pen used to draw shades. | ||||
*/ | ||||
sauimone
|
r759 | void QChartAxis::setShadesPen(const QPen &pen) | ||
Michal Klocek
|
r176 | { | ||
sauimone
|
r759 | if (m_shadesPen != pen) { | ||
m_shadesPen = pen; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r176 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a brush used to draw shades. | ||||
*/ | ||||
sauimone
|
r759 | void QChartAxis::setShadesBrush(const QBrush &brush) | ||
Michal Klocek
|
r85 | { | ||
sauimone
|
r759 | if (m_shadesBrush != brush) { | ||
m_shadesBrush = brush; | ||||
emit updated(); | ||||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets \a opacity of the shades. | ||||
*/ | ||||
Michal Klocek
|
r188 | void QChartAxis::setShadesOpacity(qreal opacity) | ||
{ | ||||
sauimone
|
r759 | if (m_shadesOpacity != opacity) { | ||
Michal Klocek
|
r188 | m_shadesOpacity=opacity; | ||
Michal Klocek
|
r439 | emit updated(); | ||
} | ||||
Michal Klocek
|
r188 | } | ||
Michal Klocek
|
r85 | |||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r400 | Sets \a min value on the axis. | ||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r223 | void QChartAxis::setMin(qreal min) | ||
{ | ||||
Michal Klocek
|
r439 | setRange(min,m_max); | ||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r400 | Sets \a max value on the axis. | ||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r223 | void QChartAxis::setMax(qreal max) | ||
{ | ||||
Michal Klocek
|
r439 | setRange(m_min,max); | ||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets range from \a min to \a max on the axis. | ||||
*/ | ||||
Michal Klocek
|
r223 | void QChartAxis::setRange(qreal min, qreal max) | ||
{ | ||||
Michal Klocek
|
r439 | bool changed = false; | ||
Jani Honkonen
|
r768 | if (!qFuzzyIsNull(m_min - min)) { | ||
sauimone
|
r759 | m_min = min; | ||
changed = true; | ||||
Michal Klocek
|
r439 | emit minChanged(min); | ||
} | ||||
Michal Klocek
|
r400 | |||
Jani Honkonen
|
r768 | if (!qFuzzyIsNull(m_max - max)) { | ||
sauimone
|
r759 | m_max = max; | ||
changed = true; | ||||
Michal Klocek
|
r400 | emit maxChanged(max); | ||
} | ||||
sauimone
|
r759 | if (changed) { | ||
Michal Klocek
|
r554 | emit rangeChanged(m_min,m_max); | ||
Michal Klocek
|
r687 | emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers); | ||
Michal Klocek
|
r442 | } | ||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r400 | |||
Michal Klocek
|
r331 | /*! | ||
Sets \a count for ticks on the axis. | ||||
*/ | ||||
Michal Klocek
|
r223 | void QChartAxis::setTicksCount(int count) | ||
{ | ||||
sauimone
|
r759 | if (m_ticksCount != count) { | ||
m_ticksCount = count; | ||||
Michal Klocek
|
r554 | emit ticksCountChanged(count); | ||
Michal Klocek
|
r687 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); | ||
Michal Klocek
|
r439 | } | ||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r534 | /*! | ||
Sets axis, shades, labels and grid lines to be visible. | ||||
*/ | ||||
void QChartAxis::show() | ||||
{ | ||||
m_axisVisible=true; | ||||
Michal Klocek
|
r535 | m_gridLineVisible=true; | ||
Michal Klocek
|
r534 | m_labelsVisible=true; | ||
m_shadesVisible=true; | ||||
emit updated(); | ||||
} | ||||
/*! | ||||
Sets axis, shades, labels and grid lines to not be visible. | ||||
*/ | ||||
void QChartAxis::hide() | ||||
{ | ||||
sauimone
|
r759 | m_axisVisible = false; | ||
m_gridLineVisible = false; | ||||
m_labelsVisible = false; | ||||
m_shadesVisible = false; | ||||
Michal Klocek
|
r534 | emit updated(); | ||
} | ||||
Michal Klocek
|
r678 | void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count) | ||
Michal Klocek
|
r554 | { | ||
setRange(min,max); | ||||
Michal Klocek
|
r678 | setTicksCount(count); | ||
Michal Klocek
|
r554 | } | ||
Michal Klocek
|
r687 | void QChartAxis::setNiceNumbers(bool enabled) | ||
Michal Klocek
|
r554 | { | ||
sauimone
|
r759 | if (m_niceNumbers != enabled){ | ||
m_niceNumbers = enabled; | ||||
Michal Klocek
|
r687 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); | ||
Michal Klocek
|
r678 | } | ||
Michal Klocek
|
r554 | } | ||
Michal Klocek
|
r223 | #include "moc_qchartaxis.cpp" | ||
Michal Klocek
|
r85 | QTCOMMERCIALCHART_END_NAMESPACE | ||