##// END OF EJS Templates
Refactored QML axis handling
Refactored QML axis handling

File last commit:

r1804:82dd686825b5
r1813:c3705e59ed40
Show More
qintervalsaxis.cpp
249 lines | 6.7 KiB | text/x-c | CppLexer
Marek Rosa
QIntervalsAxis working somewhat
r1701 /****************************************************************************
**
** 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 "qintervalsaxis.h"
#include "qintervalsaxis_p.h"
#include "chartintervalsaxisx_p.h"
#include "chartintervalsaxisy_p.h"
#include <qmath.h>
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
/*!
\class QIntervalsAxis
\brief The QIntervalsAxis class is used for manipulating chart's axis.
\mainclass
*/
/*!
\qmlclass Axis QIntervalsAxis
\brief The Axis element is used for manipulating chart's axes.
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
// TODO :)
\endcode
*/
/*!
Constructs an axis object which is a child of \a parent.
*/
QIntervalsAxis::QIntervalsAxis(QObject *parent):
Marek Rosa
class QValuesAxis renamed to QValueAxis
r1804 QValueAxis(*new QIntervalsAxisPrivate(this),parent)
Marek Rosa
QIntervalsAxis working somewhat
r1701 {
}
/*!
Destroys the object
*/
QIntervalsAxis::~QIntervalsAxis()
{
Marek Rosa
class QValuesAxis renamed to QValueAxis
r1804 // Q_D(QValueAxis);
Marek Rosa
Added posibility to replace interval's label in QIntervalsAxis
r1777 // if(d->m_dataset) {
// d->m_dataset->removeAxis(this);
// }
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
/*!
\internal
*/
Marek Rosa
class QValuesAxis renamed to QValueAxis
r1804 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
Marek Rosa
QIntervalsAxis working somewhat
r1701 {
}
/*!
Marek Rosa
Docs update
r1731 Appends new interval to the axis with an \a intervalLabel.
Marek Rosa
QIntervalsAxis some names updates
r1799 Interval label has to be unique.
Marek Rosa
Some interval axis docs updates
r1800 Parameter \a intervalEnd specifies the high end limit of the interval.
Marek Rosa
QIntervalsAxis some names updates
r1799 It has to be greater than the high end limit of the previous interval.
Otherwise the method returns without adding a new interval.
Marek Rosa
QIntervalsAxis working somewhat
r1701 */
Marek Rosa
QIntervalsAxis some names updates
r1799 void QIntervalsAxis::append(const QString& intervalLabel, qreal intervalEnd)
Marek Rosa
QIntervalsAxis working somewhat
r1701 {
Q_D(QIntervalsAxis);
Marek Rosa
Fixes and tests to Interval axis
r1708
Marek Rosa
QIntervalsAxis working somewhat
r1701 if (!d->m_intervals.contains(intervalLabel))
{
if(d->m_intervals.isEmpty()){
Marek Rosa
QIntervalsAxis some names updates
r1799 Range range(d->m_categoryMinimum, intervalEnd);
Marek Rosa
QIntervalsAxis working somewhat
r1701 d->m_intervalsMap.insert(intervalLabel, range);
d->m_intervals.append(intervalLabel);
Marek Rosa
QIntervalsAxis some names updates
r1799 }else if (intervalEnd > intervalMax(d->m_intervals.last())){
Marek Rosa
QIntervalsAxis working somewhat
r1701 Range range = d->m_intervalsMap.value(d->m_intervals.last());
Marek Rosa
QIntervalsAxis some names updates
r1799 d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd));
Marek Rosa
QIntervalsAxis working somewhat
r1701 d->m_intervals.append(intervalLabel);
Marek Rosa
Fixes and tests to Interval axis
r1708 }
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
}
Marek Rosa
Docs update
r1731 /*!
Sets to \a min the low end limit of the first interval on the axis.
*/
Marek Rosa
QIntervalsAxis working somewhat
r1701 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
{
Marek Rosa
Fixes and tests to Interval axis
r1708 Q_D(QIntervalsAxis);
if(d->m_intervals.isEmpty()){
d->m_categoryMinimum = min;
}else{
Range range = d->m_intervalsMap.value(d->m_intervals.first());
d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
}
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
Marek Rosa
Docs update
r1731 /*!
Returns the low end limit of the interval specified by an \a intervalLabel
*/
Marek Rosa
QIntervalsAxis working somewhat
r1701 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
{
Q_D(const QIntervalsAxis);
return d->m_intervalsMap.value(intervalLabel).first;
}
Marek Rosa
Docs update
r1731 /*!
Returns the high end limit of the interval specified by an \a intervalLabel
*/
Marek Rosa
QIntervalsAxis working somewhat
r1701 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
{
Q_D(const QIntervalsAxis);
return d->m_intervalsMap.value(intervalLabel).second;
}
/*!
Marek Rosa
Some interval axis docs updates
r1800 Removes an interval specified by the \a intervalLabel from the axis
Marek Rosa
QIntervalsAxis working somewhat
r1701 */
void QIntervalsAxis::remove(const QString &intervalLabel)
{
Marek Rosa
Fixes and tests to Interval axis
r1708 Q_D(QIntervalsAxis);
int labelIndex = d->m_intervals.indexOf(intervalLabel);
// check if such label exists
if (labelIndex != -1) {
d->m_intervals.removeAt(labelIndex);
d->m_intervalsMap.remove(intervalLabel);
// the range of the interval that follows (if exists) needs to be updated
if (labelIndex < d->m_intervals.count()) {
QString label = d->m_intervals.at(labelIndex);
Range range = d->m_intervalsMap.value(label);
// set the range
if (labelIndex == 0) {
range.first = d->m_categoryMinimum;
d->m_intervalsMap.insert(label, range);
} else {
range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
d->m_intervalsMap.insert(label, range);
}
}
Marek Rosa
Added posibility to replace interval's label in QIntervalsAxis
r1777 d->emitUpdated();
Marek Rosa
Fixes and tests to Interval axis
r1708 }
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
Marek Rosa
Some interval axis docs updates
r1800 /*!
Replaces \a oldLabel of an existing interval with a \a newLabel
If the old label does not exist the method returns without making any changes.
*/
Marek Rosa
QIntervalsAxis some names updates
r1799 void QIntervalsAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
Marek Rosa
Added posibility to replace interval's label in QIntervalsAxis
r1777 {
Q_D(QIntervalsAxis);
int labelIndex = d->m_intervals.indexOf(oldLabel);
// check if such label exists
if (labelIndex != -1) {
d->m_intervals.replace(labelIndex, newLabel);
Range range = d->m_intervalsMap.value(oldLabel);
d->m_intervalsMap.remove(oldLabel);
d->m_intervalsMap.insert(newLabel, range);
d->emitUpdated();
}
}
Marek Rosa
Some interval axis docs updates
r1800 /*!
Returns the list of the intervals labels
*/
Marek Rosa
QIntervalsAxis working somewhat
r1701 QStringList QIntervalsAxis::intervalsLabels()
{
Q_D(QIntervalsAxis);
return d->m_intervals;
}
/*!
Marek Rosa
QIntervalsAxis some names updates
r1799 Returns number of intervals.
Marek Rosa
QIntervalsAxis working somewhat
r1701 */
int QIntervalsAxis::count() const
{
Q_D(const QIntervalsAxis);
return d->m_intervals.count();
}
/*!
Returns the type of the axis
*/
QAbstractAxis::AxisType QIntervalsAxis::type() const
{
Marek Rosa
Fixes and tests to Interval axis
r1708 return QAbstractAxis::AxisTypeIntervals;
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
Marek Rosa
class QValuesAxis renamed to QValueAxis
r1804 QValueAxisPrivate(q),
Marek Rosa
QIntervalsAxis working somewhat
r1701 m_categoryMinimum(0)
{
}
QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
{
}
int QIntervalsAxisPrivate::ticksCount() const
{
return m_intervals.count() + 1;
}
void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
{
Q_UNUSED(count);
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 Q_UNUSED(min);
Q_UNUSED(max);
//m_min = min;
//m_max = max;
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
{
Q_Q(QIntervalsAxis);
if(m_orientation == Qt::Vertical){
return new ChartIntervalAxisY(q,presenter);
}else{
return new ChartIntervalAxisX(q,presenter);
}
}
#include "moc_qintervalsaxis.cpp"
#include "moc_qintervalsaxis_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE