diff options
Diffstat (limited to 'src/axis/barcategoryaxis')
-rw-r--r-- | src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp | 138 | ||||
-rw-r--r-- | src/axis/barcategoryaxis/chartbarcategoryaxisx_p.h | 62 | ||||
-rw-r--r-- | src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp | 140 | ||||
-rw-r--r-- | src/axis/barcategoryaxis/chartbarcategoryaxisy_p.h | 61 | ||||
-rw-r--r-- | src/axis/barcategoryaxis/qbarcategoryaxis.cpp | 612 | ||||
-rw-r--r-- | src/axis/barcategoryaxis/qbarcategoryaxis.h | 81 | ||||
-rw-r--r-- | src/axis/barcategoryaxis/qbarcategoryaxis_p.h | 81 |
7 files changed, 0 insertions, 1175 deletions
diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp deleted file mode 100644 index af9932b3..00000000 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2014 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 Enterprise Charts Add-on. - ** - ** $QT_BEGIN_LICENSE$ - ** Licensees holding valid Qt Enterprise licenses may use this file in - ** accordance with the Qt Enterprise 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 "chartbarcategoryaxisx_p.h" -#include "chartpresenter_p.h" -#include "qbarcategoryaxis_p.h" -#include "abstractchartlayout_p.h" -#include <QDebug> -#include <qmath.h> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item) - : HorizontalAxis(axis, item, true), - m_categoriesAxis(axis) -{ - QObject::connect(m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged())); - handleCategoriesChanged(); -} - -ChartBarCategoryAxisX::~ChartBarCategoryAxisX() -{ -} - -QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const -{ - QVector<qreal> points; - const QRectF& gridRect = gridGeometry(); - qreal range = max() - min(); - const qreal delta = gridRect.width() / range; - - if (delta < 2) - return points; - - qreal adjustedMin = min() + 0.5; - qreal offset = (ceil(adjustedMin) - adjustedMin) * delta; - - int count = qFloor(range); - if (count < 1) - return points; - - points.resize(count + 2); - - for (int i = 0; i < count + 2; ++i) - points[i] = offset + (qreal(i) * delta) + gridRect.left(); - - return points; -} - -QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const -{ - QStringList result ; - const QRectF &gridRect = gridGeometry(); - qreal d = (max() - min()) / gridRect.width(); - - for (int i = 0; i < layout.count() - 1; ++i) { - qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5)); - if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { - result << m_categoriesAxis->categories().at(x); - } else { - // No label for x coordinate - result << ""; - } - } - result << ""; - return result; -} - - -void ChartBarCategoryAxisX::updateGeometry() -{ - const QVector<qreal>& layout = ChartAxisElement::layout(); - if (layout.isEmpty()) - return; - setLabels(createCategoryLabels(layout)); - HorizontalAxis::updateGeometry(); -} - -void ChartBarCategoryAxisX::handleCategoriesChanged() -{ - QGraphicsLayoutItem::updateGeometry(); - if(presenter()) presenter()->layout()->invalidate(); -} - -QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -{ - Q_UNUSED(constraint) - - QSizeF sh; - QSizeF base = HorizontalAxis::sizeHint(which, constraint); - QStringList ticksList = m_categoriesAxis->categories(); - - qreal width = 0; // Width is irrelevant for X axes with interval labels - qreal height = 0; - - switch (which) { - case Qt::MinimumSize: { - QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); - height = boundingRect.height() + labelPadding() + base.height() + 1.0; - sh = QSizeF(width, height); - break; - } - case Qt::PreferredSize:{ - qreal labelHeight = 0.0; - foreach (const QString& s, ticksList) { - QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); - labelHeight = qMax(rect.height(), labelHeight); - } - height = labelHeight + labelPadding() + base.height() + 1.0; - sh = QSizeF(width, height); - break; - } - default: - break; - } - return sh; -} - -#include "moc_chartbarcategoryaxisx_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisx_p.h b/src/axis/barcategoryaxis/chartbarcategoryaxisx_p.h deleted file mode 100644 index 24dd024c..00000000 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisx_p.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 Qt Enterprise 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 CHARTBARCATEGORYAXISX_H -#define CHARTBARCATEGORYAXISX_H - -#include "horizontalaxis_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class ChartPresenter; -class QBarCategoryAxis; - -class ChartBarCategoryAxisX : public HorizontalAxis -{ - Q_OBJECT -public: - ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item = 0); - ~ChartBarCategoryAxisX(); - - QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; -protected: - QVector<qreal> calculateLayout() const; - void updateGeometry(); -private: - QStringList createCategoryLabels(const QVector<qreal>& layout) const; -public Q_SLOTS: - void handleCategoriesChanged(); - -private: - QBarCategoryAxis *m_categoriesAxis; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif /* CHARTBARCATEGORYAXISX_H */ diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp deleted file mode 100644 index 48f9f2f6..00000000 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2014 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 Enterprise Charts Add-on. - ** - ** $QT_BEGIN_LICENSE$ - ** Licensees holding valid Qt Enterprise licenses may use this file in - ** accordance with the Qt Enterprise 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 "chartbarcategoryaxisy_p.h" -#include "chartpresenter_p.h" -#include "qbarcategoryaxis_p.h" -#include "abstractchartlayout_p.h" -#include <qmath.h> -#include <QDebug> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis, QGraphicsItem* item) - : VerticalAxis(axis, item, true), - m_categoriesAxis(axis) -{ - QObject::connect( m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged())); - handleCategoriesChanged(); -} - -ChartBarCategoryAxisY::~ChartBarCategoryAxisY() -{ -} - -QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const -{ - QVector<qreal> points; - const QRectF& gridRect = gridGeometry(); - qreal range = max() - min(); - const qreal delta = gridRect.height() / range; - - if (delta < 2) - return points; - - qreal adjustedMin = min() + 0.5; - qreal offset = (ceil(adjustedMin) - adjustedMin) * delta; - - int count = qFloor(range); - if (count < 1) - return points; - - points.resize(count + 2); - - for (int i = 0; i < count + 2; ++i) - points[i] = gridRect.bottom() - (qreal(i) * delta) - offset; - - return points; -} - -QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const -{ - QStringList result; - const QRectF &gridRect = gridGeometry(); - qreal d = (max() - min()) / gridRect.height(); - - for (int i = 0; i < layout.count() - 1; ++i) { - qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5)); - if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { - result << m_categoriesAxis->categories().at(x); - } else { - // No label for x coordinate - result << ""; - } - } - result << ""; - return result; -} - -void ChartBarCategoryAxisY::updateGeometry() -{ - const QVector<qreal>& layout = ChartAxisElement::layout(); - if (layout.isEmpty()) - return; - setLabels(createCategoryLabels(layout)); - VerticalAxis::updateGeometry(); -} - -void ChartBarCategoryAxisY::handleCategoriesChanged() -{ - QGraphicsLayoutItem::updateGeometry(); - if(presenter()) presenter()->layout()->invalidate(); -} - -QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -{ - Q_UNUSED(constraint) - - QSizeF sh; - QSizeF base = VerticalAxis::sizeHint(which, constraint); - QStringList ticksList = m_categoriesAxis->categories(); - qreal width = 0; - qreal height = 0; // Height is irrelevant for Y axes with interval labels - - switch (which) { - case Qt::MinimumSize: { - QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); - width = boundingRect.width() + labelPadding() + base.width() + 1.0; - if (base.width() > 0.0) - width += labelPadding(); - sh = QSizeF(width, height); - break; - } - case Qt::PreferredSize:{ - qreal labelWidth = 0.0; - foreach (const QString& s, ticksList) { - QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); - labelWidth = qMax(rect.width(), labelWidth); - } - width = labelWidth + labelPadding() + base.width() + 1.0; - if (base.width() > 0.0) - width += labelPadding(); - sh = QSizeF(width, height); - break; - } - default: - break; - } - return sh; -} - -#include "moc_chartbarcategoryaxisy_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisy_p.h b/src/axis/barcategoryaxis/chartbarcategoryaxisy_p.h deleted file mode 100644 index 76eddfff..00000000 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisy_p.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 Qt Enterprise 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 CHARTBARCATEGORYAXISY_H -#define CHARTBARCATEGORYAXISY_H - -#include "verticalaxis_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QBarCategoryAxis; -class ChartPresenter; - -class ChartBarCategoryAxisY : public VerticalAxis -{ - Q_OBJECT -public: - ChartBarCategoryAxisY(QBarCategoryAxis *axis, QGraphicsItem* item = 0); - ~ChartBarCategoryAxisY(); - - QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; -protected: - QVector<qreal> calculateLayout() const; - void updateGeometry(); -private: - QStringList createCategoryLabels(const QVector<qreal>& layout) const; -public Q_SLOTS: - void handleCategoriesChanged(); -private: - QBarCategoryAxis *m_categoriesAxis; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif /* CHARTBARCATEGORYAXISY_H */ diff --git a/src/axis/barcategoryaxis/qbarcategoryaxis.cpp b/src/axis/barcategoryaxis/qbarcategoryaxis.cpp deleted file mode 100644 index fa90de64..00000000 --- a/src/axis/barcategoryaxis/qbarcategoryaxis.cpp +++ /dev/null @@ -1,612 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "qbarcategoryaxis.h" -#include "qbarcategoryaxis_p.h" -#include "chartbarcategoryaxisx_p.h" -#include "chartbarcategoryaxisy_p.h" -#include "abstractdomain_p.h" -#include "qchart.h" -#include <qmath.h> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE -/*! - \class QBarCategoryAxis - \inmodule Qt Charts - \brief The QBarCategoryAxis class is used for manipulating chart's axis. - \mainclass - - QBarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. - Categories are drawn between ticks. Note that you can use this also with lineseries too. - See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. - - Example code on how to use QBarCategoryAxis. - \code - QChartView *chartView = new QChartView; - QBarSeries *series = new QBarSeries; - // ... - chartView->chart()->addSeries(series); - chartView->chart()->createDefaultAxes(); - - QBarCategoryAxis *axisX = new QBarCategoryAxis; - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - axisX->append(categories); - axisX->setRange("Feb", "May"); - chartView->chart()->setAxisX(axisX, series); - \endcode -*/ - -#ifdef QDOC_QT5 -/*! - \qmltype BarCategoryAxis - \instantiates QBarCategoryAxis - \inqmlmodule QtCommercial.Chart - - \include doc/src/barcategoryaxis.qdocinc -*/ -#else -/*! - \qmlclass BarCategoryAxis QBarCategoryAxis - - \include ../doc/src/barcategoryaxis.qdocinc -*/ -#endif - -/*! - \property QBarCategoryAxis::categories - Defines the categories of axis -*/ -/*! - \qmlproperty QStringList BarCategoryAxis::categories - Defines the categories of axis -*/ - -/*! - \property QBarCategoryAxis::min - Defines the minimum value on the axis. -*/ -/*! - \qmlproperty string BarCategoryAxis::min - Defines the minimum value on the axis. -*/ - -/*! - \property QBarCategoryAxis::max - Defines the maximum value on the axis. -*/ -/*! - \qmlproperty string BarCategoryAxis::max - Defines the maximum value on the axis. -*/ - -/*! - \property QBarCategoryAxis::count - The count of categories. -*/ -/*! - \qmlproperty int BarCategoryAxis::count - The count of categories. -*/ - -/*! - \fn void QBarCategoryAxis::categoriesChanged() - Axis emits signal when the categories of the axis have changed. -*/ - -/*! - \fn void QBarCategoryAxis::minChanged(const QString &min) - Axis emits signal when \a min of axis has changed. -*/ -/*! - \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) - Axis emits signal when \a min of axis has changed. -*/ - -/*! - \fn void QBarCategoryAxis::maxChanged(const QString &max) - Axis emits signal when \a max of axis has changed. -*/ -/*! - \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) - Axis emits signal when \a max of axis has changed. -*/ - -/*! - \fn void QBarCategoryAxis::countChanged() - Axis emits signal when the count of categories has changed. -*/ -/*! - \qmlsignal BarCategoryAxis::onCountChanged() - Axis emits signal when the count of categories has changed. -*/ - -/*! - \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) - Axis emits signal when \a min or \a max of axis has changed. -*/ - -/*! - \qmlmethod void BarCategoryAxis::clear() - Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. -*/ - -/*! - Constructs an axis object which is a child of \a parent. -*/ -QBarCategoryAxis::QBarCategoryAxis(QObject *parent): - QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) -{ -} - -/*! - Destroys the object -*/ -QBarCategoryAxis::~QBarCategoryAxis() -{ - Q_D(QBarCategoryAxis); - if (d->m_chart) - d->m_chart->removeAxis(this); -} - -/*! - \internal -*/ -QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) - : QAbstractAxis(d, parent) -{ - -} - -/*! - Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. - If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. - A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. -*/ -void QBarCategoryAxis::append(const QStringList &categories) -{ - if (categories.isEmpty()) - return; - - Q_D(QBarCategoryAxis); - - int count = d->m_categories.count(); - - foreach(QString category, categories) { - if (!d->m_categories.contains(category) && !category.isNull()) { - d->m_categories.append(category); - } - } - - if (d->m_categories.count() == count) - return; - - if (count == 0) - setRange(d->m_categories.first(), d->m_categories.last()); - else - setRange(d->m_minCategory, d->m_categories.last()); - - emit categoriesChanged(); - emit countChanged(); -} - -/*! - Appends \a category to axis. A maximum of the axis will be changed to last \a category. - If there were no categories previously defined, minimum of axis will be also changed to \a category. - A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. -*/ -void QBarCategoryAxis::append(const QString &category) -{ - Q_D(QBarCategoryAxis); - - int count = d->m_categories.count(); - - if (!d->m_categories.contains(category) && !category.isNull()) - d->m_categories.append(category); - - if (d->m_categories.count() == count) - return; - - if (count == 0) - setRange(d->m_categories.last(), d->m_categories.last()); - else - setRange(d->m_minCategory, d->m_categories.last()); - - emit categoriesChanged(); - emit countChanged(); -} - -/*! - Removes \a category from axis. Removing category which is currently maximum or minimum - will affect the axis range. -*/ -void QBarCategoryAxis::remove(const QString &category) -{ - Q_D(QBarCategoryAxis); - - if (d->m_categories.contains(category)) { - d->m_categories.removeAt(d->m_categories.indexOf(category)); - if (!d->m_categories.isEmpty()) { - if (d->m_minCategory == category) { - setRange(d->m_categories.first(), d->m_maxCategory); - } else if (d->m_maxCategory == category) { - setRange(d->m_minCategory, d->m_categories.last()); - } else { - d->updateCategoryDomain(); - } - } else { - setRange(QString::null, QString::null); - } - emit categoriesChanged(); - emit countChanged(); - } -} - -/*! - Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. - If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. -*/ -void QBarCategoryAxis::insert(int index, const QString &category) -{ - Q_D(QBarCategoryAxis); - - int count = d->m_categories.count(); - - if (!d->m_categories.contains(category) && !category.isNull()) - d->m_categories.insert(index, category); - - if (d->m_categories.count() == count) - return; - - if (count == 0) { - setRange(d->m_categories.first(), d->m_categories.first()); - } else if (index == 0) { - setRange(d->m_categories.first(), d->m_maxCategory); - } else if (index == count) { - setRange(d->m_minCategory, d->m_categories.last()); - } else { - d->updateCategoryDomain(); - } - - emit categoriesChanged(); - emit countChanged(); -} - -/*! - Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exist on the axis nothing is done. - A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, - minimum and maximum of axis is updated accordingly. -*/ -void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) -{ - Q_D(QBarCategoryAxis); - - int pos = d->m_categories.indexOf(oldCategory); - - if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { - d->m_categories.replace(pos, newCategory); - if (d->m_minCategory == oldCategory) - setRange(newCategory, d->m_maxCategory); - else if (d->m_maxCategory == oldCategory) - setRange(d->m_minCategory, newCategory); - - emit categoriesChanged(); - emit countChanged(); - } -} - -/*! - Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. - */ -void QBarCategoryAxis::clear() -{ - Q_D(QBarCategoryAxis); - d->m_categories.clear(); - setRange(QString::null, QString::null); - emit categoriesChanged(); - emit countChanged(); -} - -/*! - Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. - A category has to be valid QStrings and can not be duplicated. -*/ -void QBarCategoryAxis::setCategories(const QStringList &categories) -{ - Q_D(QBarCategoryAxis); - d->m_categories.clear(); - d->m_minCategory = QString::null; - d->m_maxCategory = QString::null; - d->m_min = 0; - d->m_max = 0; - d->m_count = 0; - append(categories); -} - -/*! - Returns categories -*/ -QStringList QBarCategoryAxis::categories() -{ - Q_D(QBarCategoryAxis); - return d->m_categories; -} - -/*! - Returns number of categories. - */ -int QBarCategoryAxis::count() const -{ - Q_D(const QBarCategoryAxis); - return d->m_categories.count(); -} - -/*! - Returns category at \a index. Index must be valid. -*/ -QString QBarCategoryAxis::at(int index) const -{ - Q_D(const QBarCategoryAxis); - return d->m_categories.at(index); -} - -/*! - Sets minimum category to \a min. -*/ -void QBarCategoryAxis::setMin(const QString &min) -{ - Q_D(QBarCategoryAxis); - d->setRange(min, d->m_maxCategory); -} - -/*! - Returns minimum category. -*/ -QString QBarCategoryAxis::min() const -{ - Q_D(const QBarCategoryAxis); - return d->m_minCategory; -} - -/*! - Sets maximum category to \a max. -*/ -void QBarCategoryAxis::setMax(const QString &max) -{ - Q_D(QBarCategoryAxis); - d->setRange(d->m_minCategory, max); -} - -/*! - Returns maximum category -*/ -QString QBarCategoryAxis::max() const -{ - Q_D(const QBarCategoryAxis); - return d->m_maxCategory; -} - -/*! - Sets range from \a minCategory to \a maxCategory -*/ -void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) -{ - Q_D(QBarCategoryAxis); - d->setRange(minCategory,maxCategory); -} - -/*! - Returns the type of the axis -*/ -QAbstractAxis::AxisType QBarCategoryAxis::type() const -{ - return AxisTypeBarCategory; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) - : QAbstractAxisPrivate(q), - m_min(0.0), - m_max(0.0), - m_count(0) -{ - -} - -QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() -{ - -} - -void QBarCategoryAxisPrivate::setMin(const QVariant &min) -{ - setRange(min, m_maxCategory); -} - -void QBarCategoryAxisPrivate::setMax(const QVariant &max) -{ - setRange(m_minCategory, max); -} - -void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) -{ - QString value1 = min.toString(); - QString value2 = max.toString(); - setRange(value1, value2); -} - -void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) -{ - Q_Q(QBarCategoryAxis); - - bool categoryChanged = false; - bool changed = false; - - if (min > max) - return; - - if (!qFuzzyIsNull(m_min - min)) { - m_min = min; - changed = true; - - int imin = m_min + 0.5; - if (imin >= 0 && imin < m_categories.count()) { - QString minCategory = m_categories.at(imin); - if (m_minCategory != minCategory && !minCategory.isEmpty()) { - m_minCategory = minCategory; - categoryChanged = true; - emit q->minChanged(minCategory); - } - } - - } - - if (!qFuzzyIsNull(m_max - max)) { - m_max = max; - changed = true; - - int imax = m_max - 0.5; - if (imax >= 0 && imax < m_categories.count()) { - QString maxCategory = m_categories.at(imax); - if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { - m_maxCategory = maxCategory; - categoryChanged = true; - emit q->maxChanged(maxCategory); - } - } - } - - if (categoryChanged){ - emit q->rangeChanged(m_minCategory, m_maxCategory); - } - - if (changed) { - emit rangeChanged(m_min,m_max); - } -} - -void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) -{ - Q_Q(QBarCategoryAxis); - bool changed = false; - - //special case in case or clearing all categories - if (minCategory.isNull() && maxCategory.isNull()) { - m_minCategory = minCategory; - m_maxCategory = maxCategory; - m_min = 0; - m_max = 0; - m_count = 0; - emit q->minChanged(minCategory); - emit q->maxChanged(maxCategory); - emit q->rangeChanged(m_minCategory, m_maxCategory); - emit rangeChanged(m_min,m_max); - return; - } - - if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) - return; - - if (!minCategory.isNull() && (m_minCategory != minCategory || m_minCategory.isNull()) - && m_categories.contains(minCategory)) { - m_minCategory = minCategory; - m_min = m_categories.indexOf(m_minCategory) - 0.5; - changed = true; - emit q->minChanged(minCategory); - } - - if (!maxCategory.isNull() && (m_maxCategory != maxCategory || m_maxCategory.isNull()) - && m_categories.contains(maxCategory)) { - m_maxCategory = maxCategory; - m_max = m_categories.indexOf(m_maxCategory) + 0.5; - changed = true; - emit q->maxChanged(maxCategory); - } - - if (changed) { - m_count = m_max - m_min; - emit q->rangeChanged(m_minCategory, m_maxCategory); - emit rangeChanged(m_min,m_max); - } -} - -void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) -{ - Q_Q(QBarCategoryAxis); - ChartAxisElement* axis(0); - if (orientation() == Qt::Vertical) - axis = new ChartBarCategoryAxisY(q,parent); - if (orientation() == Qt::Horizontal) - axis = new ChartBarCategoryAxisX(q,parent); - - m_item.reset(axis); - QAbstractAxisPrivate::initializeGraphics(parent); -} - -void QBarCategoryAxisPrivate::updateCategoryDomain() -{ - bool changed = false; - - qreal tmpMin = m_categories.indexOf(m_minCategory) - 0.5; - if (!qFuzzyIsNull(m_min - tmpMin)) { - m_min = tmpMin; - changed = true; - } - qreal tmpMax = m_categories.indexOf(m_maxCategory) + 0.5; - if (!qFuzzyIsNull(m_max - tmpMax)) { - m_max = tmpMax; - changed = true; - } - m_count = m_max - m_min; - - if (changed) - emit rangeChanged(m_min,m_max); -} - - -void QBarCategoryAxisPrivate::initializeDomain(AbstractDomain *domain) -{ - Q_Q(QBarCategoryAxis); - if (m_max == m_min) { - int min; - int max; - if (orientation() == Qt::Vertical) { - min = domain->minY() + 0.5; - max = domain->maxY() - 0.5; - } else { - min = domain->minX() + 0.5; - max = domain->maxX() - 0.5; - } - - if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) - q->setRange(m_categories.at(min), m_categories.at(max)); - } else { - if (orientation() == Qt::Vertical) - domain->setRangeY(m_min, m_max); - else - domain->setRangeX(m_min, m_max); - } -} - -#include "moc_qbarcategoryaxis.cpp" -#include "moc_qbarcategoryaxis_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/barcategoryaxis/qbarcategoryaxis.h b/src/axis/barcategoryaxis/qbarcategoryaxis.h deleted file mode 100644 index 8f40b5c2..00000000 --- a/src/axis/barcategoryaxis/qbarcategoryaxis.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 QBARCATEGORYAXIS_H -#define QBARCATEGORYAXIS_H - -#include "qabstractaxis.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QBarCategoryAxisPrivate; - -class QTCOMMERCIALCHART_EXPORT QBarCategoryAxis : public QAbstractAxis -{ - Q_OBJECT - Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged) - Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged) - Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - -public: - explicit QBarCategoryAxis(QObject *parent = 0); - ~QBarCategoryAxis(); - -protected: - QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent = 0); - -public: - AxisType type() const; - void append(const QStringList &categories); - void append(const QString &category); - void remove(const QString &category); - void insert(int index, const QString &category); - void replace(const QString &oldCategory, const QString &newCategory); - Q_INVOKABLE void clear(); - void setCategories(const QStringList &categories); - QStringList categories(); - int count() const; - QString at(int index) const; - - //range handling - void setMin(const QString &minCategory); - QString min() const; - void setMax(const QString &maxCategory); - QString max() const; - void setRange(const QString &minCategory, const QString &maxCategory); - -Q_SIGNALS: - void categoriesChanged(); - void minChanged(const QString &min); - void maxChanged(const QString &max); - void rangeChanged(const QString &min, const QString &max); - void countChanged(); - -private: - Q_DECLARE_PRIVATE(QBarCategoryAxis) - Q_DISABLE_COPY(QBarCategoryAxis) - friend class ChartBarCategoryAxisX; - friend class ChartBarCategoryAxisY; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QBARCATEGORYAXIS_H diff --git a/src/axis/barcategoryaxis/qbarcategoryaxis_p.h b/src/axis/barcategoryaxis/qbarcategoryaxis_p.h deleted file mode 100644 index 85fab82d..00000000 --- a/src/axis/barcategoryaxis/qbarcategoryaxis_p.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 Qt Enterprise 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 QBARCATEGORYAXIS_P_H -#define QBARCATEGORYAXIS_P_H - -#include "qbarcategoryaxis.h" -#include "qabstractaxis_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class AbstractDomain; - -class QBarCategoryAxisPrivate : public QAbstractAxisPrivate -{ - Q_OBJECT - -public: - QBarCategoryAxisPrivate(QBarCategoryAxis *q); - ~QBarCategoryAxisPrivate(); - -public: - void initializeGraphics(QGraphicsItem* parent); - void initializeDomain(AbstractDomain *domain); - void updateCategoryDomain(); - - //interface for manipulating range form base class - void setRange(const QVariant &min, const QVariant &max); - void setMin(const QVariant &min); - void setMax(const QVariant &max); - - //interface manipulating range form domain - qreal min() { return m_min; } - qreal max() { return m_max; } - void setRange(qreal min,qreal max); - -private: - //range handling - void setRange(const QString &minCategory, const QString &maxCategory); - -private: - QStringList m_categories; - QString m_minCategory; - QString m_maxCategory; - qreal m_min; - qreal m_max; - int m_count; - -private: - Q_DECLARE_PUBLIC(QBarCategoryAxis); -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QBARCATEGORYAXIS_P_H |