qchartaxis.cpp
535 lines
| 10.8 KiB
| text/x-c
|
CppLexer
|
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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r72 | #include "qchartaxis.h" | ||
|
r963 | #include "qchartaxis_p.h" | ||
|
r72 | |||
|
r85 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
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. | ||||
*/ | ||||
|
r333 | /*! | ||
\fn bool QChartAxis::isAxisVisible() const | ||||
\brief Returns if axis is visible | ||||
\sa setAxisVisible() | ||||
*/ | ||||
|
r331 | /*! | ||
\fn QPen QChartAxis::axisPen() const | ||||
\brief Returns pen used to draw axis and ticks. | ||||
\sa setAxisPen() | ||||
*/ | ||||
|
r333 | |||
/*! | ||||
|
r535 | \fn bool QChartAxis::isGridLineVisible() const | ||
|
r333 | \brief Returns if grid is visible | ||
|
r535 | \sa setGridLineVisible() | ||
|
r333 | */ | ||
|
r331 | /*! | ||
|
r551 | \fn QPen QChartAxis::gridLinePen() const | ||
|
r331 | \brief Returns pen used to draw grid. | ||
|
r551 | \sa setGridLinePen() | ||
|
r331 | */ | ||
|
r333 | /*! | ||
|
r365 | \fn bool QChartAxis::labelsVisible() const | ||
|
r333 | \brief Returns if grid is visible | ||
\sa setLabelsVisible() | ||||
*/ | ||||
|
r331 | /*! | ||
\fn QPen QChartAxis::labelsPen() const | ||||
|
r333 | \brief Returns the pen used to labels. | ||
|
r331 | \sa setLabelsPen() | ||
*/ | ||||
/*! | ||||
\fn QBrush QChartAxis::labelsBrush() const | ||||
|
r333 | \brief Returns brush used to draw labels. | ||
|
r331 | \sa setLabelsBrush() | ||
*/ | ||||
/*! | ||||
\fn QFont QChartAxis::labelsFont() const | ||||
|
r333 | \brief Returns font used to draw labels. | ||
|
r331 | \sa setLabelsFont() | ||
*/ | ||||
/*! | ||||
\fn QFont QChartAxis::labelsAngle() const | ||||
|
r333 | \brief Returns angle used to draw labels. | ||
|
r331 | \sa setLabelsAngle() | ||
*/ | ||||
|
r333 | /*! | ||
|
r365 | \fn bool QChartAxis::shadesVisible() const | ||
|
r333 | \brief Returns if shades are visible. | ||
\sa setShadesVisible() | ||||
*/ | ||||
/*! | ||||
\fn qreal QChartAxis::shadesOpacity() const | ||||
\brief Returns opacity of shades. | ||||
*/ | ||||
|
r331 | /*! | ||
\fn QPen QChartAxis::shadesPen() const | ||||
|
r333 | \brief Returns pen used to draw shades. | ||
|
r331 | \sa setShadesPen() | ||
*/ | ||||
/*! | ||||
\fn QBrush QChartAxis::shadesBrush() const | ||||
|
r333 | \brief Returns brush used to draw shades. | ||
|
r331 | \sa setShadesBrush() | ||
*/ | ||||
|
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. | ||||
*/ | ||||
|
r331 | /*! | ||
|
r439 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) | ||
\brief Axis emits signal when \a min or \a max of axis has changed. | ||||
|
r331 | */ | ||
/*! | ||||
|
r439 | \fn int QChartAxis::ticksCount() const | ||
\brief Return number of ticks on the axis | ||||
\sa setTicksCount() | ||||
|
r331 | */ | ||
|
r936 | /*! | ||
\fn bool QChartAxis::niceNumbers() const | ||||
\brief Returns whether nice numbers are enabled or not. | ||||
*/ | ||||
/*! | ||||
|
r937 | \fn QChartAxisCategories* QChartAxis::categories() | ||
|
r936 | \brief Returns pointer to the list of categories which correspond to the values on the axis. | ||
*/ | ||||
/*! | ||||
|
r937 | \fn void QChartAxis::ticksCountChanged(int count) | ||
|
r936 | \brief Emits the new \a count of ticks on the axis | ||
Signal is emitted when the number of the ticks on the axis has been changed to a different value. | ||||
Parementer count\a count is the new number of ticks on the axis. | ||||
*/ | ||||
|
r331 | /*! | ||
Constructs new axis object which is a child of \a parent. Ownership is taken by | ||||
QChatView or QChart when axis added. | ||||
*/ | ||||
|
r759 | QChartAxis::QChartAxis(QObject *parent) : QObject(parent), | ||
|
r963 | d_ptr(new QChartAxisPrivate(this)) | ||
|
r72 | { | ||
} | ||||
|
r331 | /*! | ||
Destructor of the axis object. When axis is added to chart, chart object takes ownership. | ||||
*/ | ||||
|
r72 | QChartAxis::~QChartAxis() | ||
{ | ||||
} | ||||
|
r331 | /*! | ||
Sets \a pen used to draw axis line and ticks. | ||||
*/ | ||||
|
r759 | void QChartAxis::setAxisPen(const QPen &pen) | ||
|
r140 | { | ||
|
r963 | if (d_ptr->m_axisPen!=pen) { | ||
d_ptr->m_axisPen = pen; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r140 | } | ||
|
r963 | QPen QChartAxis::axisPen() const | ||
{ | ||||
return d_ptr->m_axisPen; | ||||
} | ||||
|
r331 | /*! | ||
Sets if axis and ticks are \a visible. | ||||
*/ | ||||
|
r85 | void QChartAxis::setAxisVisible(bool visible) | ||
{ | ||||
|
r963 | if (d_ptr->m_axisVisible != visible) { | ||
d_ptr->m_axisVisible = visible; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r85 | } | ||
|
r963 | bool QChartAxis::isAxisVisible() const | ||
{ | ||||
return d_ptr->m_axisVisible; | ||||
} | ||||
|
r331 | /*! | ||
|
r535 | Sets if grid line is \a visible. | ||
|
r331 | */ | ||
|
r535 | void QChartAxis::setGridLineVisible(bool visible) | ||
|
r85 | { | ||
|
r963 | if (d_ptr->m_gridLineVisible != visible) { | ||
d_ptr->m_gridLineVisible = visible; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | bool QChartAxis::isGridLineVisible() const | ||
{ | ||||
return d_ptr->m_gridLineVisible; | ||||
} | ||||
|
r331 | /*! | ||
|
r535 | Sets \a pen used to draw grid line. | ||
|
r331 | */ | ||
|
r759 | void QChartAxis::setGridLinePen(const QPen &pen) | ||
|
r176 | { | ||
|
r963 | if (d_ptr->m_gridLinePen != pen) { | ||
d_ptr->m_gridLinePen = pen; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r85 | } | ||
|
r963 | QPen QChartAxis::gridLinePen() const | ||
{ | ||||
return d_ptr->m_gridLinePen; | ||||
} | ||||
|
r331 | /*! | ||
Sets if axis' labels are \a visible. | ||||
*/ | ||||
|
r85 | void QChartAxis::setLabelsVisible(bool visible) | ||
{ | ||||
|
r963 | if (d_ptr->m_labelsVisible != visible) { | ||
d_ptr->m_labelsVisible = visible; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r85 | } | ||
|
r963 | bool QChartAxis::labelsVisible() const | ||
{ | ||||
return d_ptr->m_labelsVisible; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a pen used to draw labels. | ||||
*/ | ||||
|
r759 | void QChartAxis::setLabelsPen(const QPen &pen) | ||
|
r176 | { | ||
|
r963 | if (d_ptr->m_labelsPen != pen) { | ||
d_ptr->m_labelsPen = pen; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | QPen QChartAxis::labelsPen() const | ||
{ | ||||
return d_ptr->m_labelsPen; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a brush used to draw labels. | ||||
*/ | ||||
|
r759 | void QChartAxis::setLabelsBrush(const QBrush &brush) | ||
|
r176 | { | ||
|
r963 | if (d_ptr->m_labelsBrush != brush) { | ||
d_ptr->m_labelsBrush = brush; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | QBrush QChartAxis::labelsBrush() const | ||
{ | ||||
return d_ptr->m_labelsBrush; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a font used to draw labels. | ||||
*/ | ||||
|
r759 | void QChartAxis::setLabelsFont(const QFont &font) | ||
|
r176 | { | ||
|
r963 | if (d_ptr->m_labelsFont != font) { | ||
d_ptr->m_labelsFont = font; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | QFont QChartAxis::labelsFont() const | ||
{ | ||||
return d_ptr->m_labelsFont; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a angle for all the labels on given axis. | ||||
*/ | ||||
|
r223 | void QChartAxis::setLabelsAngle(int angle) | ||
|
r176 | { | ||
|
r963 | if (d_ptr->m_labelsAngle != angle) { | ||
d_ptr->m_labelsAngle = angle; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | int QChartAxis::labelsAngle() const | ||
{ | ||||
return d_ptr->m_labelsAngle; | ||||
} | ||||
|
r331 | /*! | ||
Sets if shades are \a visible. | ||||
*/ | ||||
|
r176 | void QChartAxis::setShadesVisible(bool visible) | ||
{ | ||||
|
r963 | if (d_ptr->m_shadesVisible != visible) { | ||
d_ptr->m_shadesVisible = visible; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | bool QChartAxis::shadesVisible() const | ||
{ | ||||
return d_ptr->m_shadesVisible; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a pen used to draw shades. | ||||
*/ | ||||
|
r759 | void QChartAxis::setShadesPen(const QPen &pen) | ||
|
r176 | { | ||
|
r963 | if (d_ptr->m_shadesPen != pen) { | ||
d_ptr->m_shadesPen = pen; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r176 | } | ||
|
r963 | QPen QChartAxis::shadesPen() const | ||
{ | ||||
return d_ptr->m_shadesPen; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a brush used to draw shades. | ||||
*/ | ||||
|
r759 | void QChartAxis::setShadesBrush(const QBrush &brush) | ||
|
r85 | { | ||
|
r963 | if (d_ptr->m_shadesBrush != brush) { | ||
d_ptr->m_shadesBrush = brush; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r85 | } | ||
|
r963 | QBrush QChartAxis::shadesBrush() const | ||
{ | ||||
return d_ptr->m_shadesBrush; | ||||
} | ||||
|
r331 | /*! | ||
Sets \a opacity of the shades. | ||||
*/ | ||||
|
r188 | void QChartAxis::setShadesOpacity(qreal opacity) | ||
{ | ||||
|
r963 | if (d_ptr->m_shadesOpacity != opacity) { | ||
d_ptr->m_shadesOpacity=opacity; | ||||
emit d_ptr->updated(); | ||||
|
r439 | } | ||
|
r188 | } | ||
|
r85 | |||
|
r963 | qreal QChartAxis::shadesOpacity() const | ||
{ | ||||
return d_ptr->m_shadesOpacity; | ||||
} | ||||
|
r331 | /*! | ||
|
r400 | Sets \a min value on the axis. | ||
|
r331 | */ | ||
|
r223 | void QChartAxis::setMin(qreal min) | ||
{ | ||||
|
r963 | setRange(min,d_ptr->m_max); | ||
} | ||||
qreal QChartAxis::min() const | ||||
{ | ||||
return d_ptr->m_min; | ||||
|
r223 | } | ||
|
r331 | /*! | ||
|
r400 | Sets \a max value on the axis. | ||
|
r331 | */ | ||
|
r223 | void QChartAxis::setMax(qreal max) | ||
{ | ||||
|
r963 | setRange(d_ptr->m_min,max); | ||
} | ||||
qreal QChartAxis::max() const | ||||
{ | ||||
return d_ptr->m_max; | ||||
|
r223 | } | ||
|
r331 | /*! | ||
Sets range from \a min to \a max on the axis. | ||||
*/ | ||||
|
r223 | void QChartAxis::setRange(qreal min, qreal max) | ||
{ | ||||
|
r439 | bool changed = false; | ||
|
r963 | if (!qFuzzyIsNull(d_ptr->m_min - min)) { | ||
d_ptr->m_min = min; | ||||
|
r759 | changed = true; | ||
|
r439 | emit minChanged(min); | ||
} | ||||
|
r400 | |||
|
r963 | if (!qFuzzyIsNull(d_ptr->m_max - max)) { | ||
d_ptr->m_max = max; | ||||
|
r759 | changed = true; | ||
|
r400 | emit maxChanged(max); | ||
} | ||||
|
r759 | if (changed) { | ||
|
r963 | emit rangeChanged(d_ptr->m_min,d_ptr->m_max); | ||
emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | ||||
|
r442 | } | ||
|
r439 | } | ||
|
r400 | |||
|
r331 | /*! | ||
Sets \a count for ticks on the axis. | ||||
*/ | ||||
|
r223 | void QChartAxis::setTicksCount(int count) | ||
{ | ||||
|
r963 | if (d_ptr->m_ticksCount != count) { | ||
d_ptr->m_ticksCount = count; | ||||
|
r554 | emit ticksCountChanged(count); | ||
|
r963 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | ||
|
r439 | } | ||
|
r223 | } | ||
|
r963 | int QChartAxis::ticksCount() const | ||
{ | ||||
return d_ptr->m_ticksCount; | ||||
} | ||||
|
r534 | /*! | ||
Sets axis, shades, labels and grid lines to be visible. | ||||
*/ | ||||
void QChartAxis::show() | ||||
{ | ||||
|
r963 | d_ptr->m_axisVisible=true; | ||
d_ptr->m_gridLineVisible=true; | ||||
d_ptr->m_labelsVisible=true; | ||||
d_ptr->m_shadesVisible=true; | ||||
emit d_ptr->updated(); | ||||
|
r534 | } | ||
/*! | ||||
Sets axis, shades, labels and grid lines to not be visible. | ||||
*/ | ||||
void QChartAxis::hide() | ||||
{ | ||||
|
r963 | d_ptr->m_axisVisible = false; | ||
d_ptr->m_gridLineVisible = false; | ||||
d_ptr->m_labelsVisible = false; | ||||
d_ptr->m_shadesVisible = false; | ||||
emit d_ptr->updated(); | ||||
|
r554 | } | ||
|
r936 | /*! | ||
Sets the nice numbers state to \a enable | ||||
*/ | ||||
void QChartAxis::setNiceNumbers(bool enable) | ||||
|
r554 | { | ||
|
r963 | if (d_ptr->m_niceNumbers != enable){ | ||
d_ptr->m_niceNumbers = enable; | ||||
emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | ||||
|
r678 | } | ||
|
r554 | } | ||
|
r963 | bool QChartAxis::niceNumbers() const | ||
{ | ||||
return d_ptr->m_niceNumbers; | ||||
} | ||||
QChartAxisCategories* QChartAxis::categories() | ||||
{ | ||||
return &d_ptr->m_category; | ||||
} | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
QChartAxisPrivate::QChartAxisPrivate(QChartAxis* q): | ||||
q_ptr(q), | ||||
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) | ||||
{ | ||||
} | ||||
QChartAxisPrivate::~QChartAxisPrivate() | ||||
{ | ||||
} | ||||
void QChartAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | ||||
{ | ||||
q_ptr->setRange(min,max); | ||||
q_ptr->setTicksCount(count); | ||||
} | ||||
|
r223 | #include "moc_qchartaxis.cpp" | ||
|
r963 | #include "moc_qchartaxis_p.cpp" | ||
|
r223 | |||
|
r85 | QTCOMMERCIALCHART_END_NAMESPACE | ||