qintervalaxis.cpp
178 lines
| 4.0 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r1540 | /**************************************************************************** | ||
** | ||||
** 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
|
r1615 | #include "qintervalaxis.h" | ||
#include "qintervalaxis_p.h" | ||||
Marek Rosa
|
r1561 | #include "chartcategoriesaxisx_p.h" | ||
#include "chartcategoriesaxisy_p.h" | ||||
sauimone
|
r1572 | #include <qmath.h> | ||
Michal Klocek
|
r1611 | #include <QDebug> | ||
Michal Klocek
|
r1540 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
sauimone
|
r1624 | /*! | ||
Marek Rosa
|
r1653 | \internal | ||
sauimone
|
r1624 | \class QIntervalAxis | ||
\brief The QIntervalAxis class is used for manipulating chart's axis. | ||||
\mainclass | ||||
Axis can be setup to show axis line with tick marks, grid lines and shades. | ||||
*/ | ||||
/*! | ||||
\qmlclass Axis QIntervalAxis | ||||
\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 | ||||
*/ | ||||
Marek Rosa
|
r1636 | /*! | ||
Constructs an axis object which is a child of \a parent. | ||||
*/ | ||||
Michal Klocek
|
r1614 | QIntervalAxis::QIntervalAxis(QObject *parent): | ||
QValuesAxis(*new QIntervalAxisPrivate(this),parent) | ||||
Michal Klocek
|
r1540 | { | ||
} | ||||
Marek Rosa
|
r1638 | /*! | ||
Destroys the object | ||||
*/ | ||||
Michal Klocek
|
r1614 | QIntervalAxis::~QIntervalAxis() | ||
Michal Klocek
|
r1540 | { | ||
} | ||||
Marek Rosa
|
r1638 | /*! | ||
\internal | ||||
*/ | ||||
Michal Klocek
|
r1614 | QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent) | ||
Michal Klocek
|
r1540 | { | ||
} | ||||
/*! | ||||
sauimone
|
r1654 | Appends \a category to axis | ||
Michal Klocek
|
r1540 | */ | ||
Michal Klocek
|
r1614 | void QIntervalAxis::append(const QString& category, qreal x) | ||
Michal Klocek
|
r1613 | { | ||
Michal Klocek
|
r1614 | Q_D(QIntervalAxis); | ||
Michal Klocek
|
r1613 | 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); | ||||
sauimone
|
r1605 | } | ||
Michal Klocek
|
r1540 | } | ||
Michal Klocek
|
r1614 | void QIntervalAxis::setFisrtCategoryMinimum(qreal x) | ||
Michal Klocek
|
r1540 | { | ||
Michal Klocek
|
r1614 | Q_D(QIntervalAxis); | ||
Michal Klocek
|
r1613 | 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); | ||||
} | ||||
Michal Klocek
|
r1540 | } | ||
/*! | ||||
Removes \a category from axis | ||||
*/ | ||||
Michal Klocek
|
r1614 | void QIntervalAxis::remove(const QString &category) | ||
Michal Klocek
|
r1540 | { | ||
Michal Klocek
|
r1613 | Q_UNUSED(category); | ||
//TODO | ||||
Michal Klocek
|
r1540 | } | ||
Michal Klocek
|
r1614 | QStringList QIntervalAxis::categories() | ||
Tero Ahola
|
r1550 | { | ||
Michal Klocek
|
r1614 | Q_D(QIntervalAxis); | ||
Tero Ahola
|
r1550 | return d->m_categories; | ||
} | ||||
Michal Klocek
|
r1540 | /*! | ||
Returns number of categories. | ||||
*/ | ||||
Michal Klocek
|
r1614 | int QIntervalAxis::count() const | ||
Michal Klocek
|
r1540 | { | ||
Michal Klocek
|
r1614 | Q_D(const QIntervalAxis); | ||
Michal Klocek
|
r1540 | return d->m_categories.count(); | ||
} | ||||
/*! | ||||
Marek Rosa
|
r1637 | Returns the type of the axis | ||
Michal Klocek
|
r1540 | */ | ||
Michal Klocek
|
r1614 | QAbstractAxis::AxisType QIntervalAxis::type() const | ||
Michal Klocek
|
r1540 | { | ||
return AxisTypeCategories; | ||||
} | ||||
Michal Klocek
|
r1544 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
Michal Klocek
|
r1614 | QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q): | ||
Michal Klocek
|
r1613 | QValuesAxisPrivate(q), | ||
m_categoryMinimum(0) | ||||
Michal Klocek
|
r1541 | { | ||
Michal Klocek
|
r1544 | |||
Michal Klocek
|
r1541 | } | ||
Michal Klocek
|
r1614 | QIntervalAxisPrivate::~QIntervalAxisPrivate() | ||
Michal Klocek
|
r1541 | { | ||
Michal Klocek
|
r1544 | |||
Michal Klocek
|
r1541 | } | ||
Michal Klocek
|
r1614 | int QIntervalAxisPrivate::ticksCount() const | ||
Michal Klocek
|
r1540 | { | ||
Michal Klocek
|
r1544 | return m_categories.count()+1; | ||
Michal Klocek
|
r1540 | } | ||
Michal Klocek
|
r1614 | void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | ||
sauimone
|
r1566 | { | ||
m_min = min; | ||||
m_max = max; | ||||
m_ticksCount = count; | ||||
} | ||||
Michal Klocek
|
r1614 | ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter) | ||
Michal Klocek
|
r1556 | { | ||
Michal Klocek
|
r1613 | Q_UNUSED(presenter); | ||
// Q_Q( QCategoriesAxis); | ||||
Michal Klocek
|
r1556 | if(m_orientation == Qt::Vertical){ | ||
Michal Klocek
|
r1613 | return 0; | ||
Michal Klocek
|
r1556 | }else{ | ||
Michal Klocek
|
r1613 | return 0; | ||
Michal Klocek
|
r1556 | } | ||
} | ||||
Michal Klocek
|
r1615 | #include "moc_qintervalaxis.cpp" | ||
#include "moc_qintervalaxis_p.cpp" | ||||
Michal Klocek
|
r1540 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||