From 2d2a1c8b0f36b2757fd0afdae340e98303023d3d 2012-11-26 12:58:47 From: Marek Rosa Date: 2012-11-26 12:58:47 Subject: [PATCH] QLogValueAxis added. Log domain missing --- diff --git a/src/axis/axis.pri b/src/axis/axis.pri index e8e8625..264ed89 100644 --- a/src/axis/axis.pri +++ b/src/axis/axis.pri @@ -3,12 +3,14 @@ INCLUDEPATH += $$PWD \ $$PWD/valueaxis \ $$PWD/barcategoryaxis \ - $$PWD/categoryaxis + $$PWD/categoryaxis \ + $$PWD/logvalueaxis DEPENDPATH += $$PWD \ $$PWD/valueaxis \ $$PWD/barcategoryaxis \ - $$PWD/categoryaxis + $$PWD/categoryaxis \ + $$PWD/logvalueaxis SOURCES += \ $$PWD/chartaxis.cpp \ @@ -23,7 +25,10 @@ SOURCES += \ $$PWD/barcategoryaxis/qbarcategoryaxis.cpp \ $$PWD/categoryaxis/chartcategoryaxisx.cpp \ $$PWD/categoryaxis/chartcategoryaxisy.cpp \ - $$PWD/categoryaxis/qcategoryaxis.cpp + $$PWD/categoryaxis/qcategoryaxis.cpp \ + $$PWD/logvalueaxis/chartlogvalueaxisx.cpp \ + $$PWD/logvalueaxis/chartlogvalueaxisy.cpp \ + $$PWD/logvalueaxis/qlogvalueaxis.cpp PRIVATE_HEADERS += \ $$PWD/chartaxis_p.h \ @@ -38,13 +43,17 @@ PRIVATE_HEADERS += \ $$PWD/barcategoryaxis/qbarcategoryaxis_p.h \ $$PWD/categoryaxis/chartcategoryaxisx_p.h \ $$PWD/categoryaxis/chartcategoryaxisy_p.h \ - $$PWD/categoryaxis/qcategoryaxis_p.h + $$PWD/categoryaxis/qcategoryaxis_p.h \ + $$PWD/logvalueaxis/chartlogvalueaxisx_p.h \ + $$PWD/logvalueaxis/chartlogvalueaxisy_p.h \ + $$PWD/logvalueaxis/qlogvalueaxis_p.h PUBLIC_HEADERS += \ $$PWD/qabstractaxis.h \ $$PWD/valueaxis/qvalueaxis.h \ $$PWD/barcategoryaxis/qbarcategoryaxis.h \ - $$PWD/categoryaxis/qcategoryaxis.h + $$PWD/categoryaxis/qcategoryaxis.h \ + $$PWD/logvalueaxis/qlogvalueaxis.h \ !linux-arm*: { INCLUDEPATH += \ @@ -66,3 +75,4 @@ PRIVATE_HEADERS += \ PUBLIC_HEADERS += \ $$PWD/datetimeaxis/qdatetimeaxis.h } + diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index cd3c020..3fa8395 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -438,6 +439,44 @@ QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const Q return labels; } +QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) +{ +// Q_ASSERT(m_max > m_min); + // Q_ASSERT(ticks > 1); + + QStringList labels; + + int n = 0; + if (ticks > 1) + n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); + n++; + +// QLogValueAxis *axis = qobject_cast(m_chartAxis); + +// QString format = axis->labelFormat(); + + int firstTick; + if (base > 1) + firstTick = (int)(log10(min) / log10(base)); + else + firstTick = (int)(log10(max) / log10(base)); + + if (format.isNull()) { + for (int i = firstTick; i < ticks + firstTick; i++) { + qreal value = qPow(base, i); + labels << QString::number(value, 'f', n); + } + } else { + QByteArray array = format.toAscii(); + for (int i = firstTick; i < ticks + firstTick; i++) { + qreal value = qPow(base, i); + labels << QString().sprintf(array, value); + } + } + + return labels; +} + QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) { //TODO: Q_ASSERT(m_max > m_min); diff --git a/src/axis/chartaxis_p.h b/src/axis/chartaxis_p.h index cda88cb..ee54d85 100644 --- a/src/axis/chartaxis_p.h +++ b/src/axis/chartaxis_p.h @@ -92,6 +92,7 @@ public: //helpers static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); + static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format); static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); protected: diff --git a/src/axis/logvalueaxis/chartlogvalueaxisx.cpp b/src/axis/logvalueaxis/chartlogvalueaxisx.cpp new file mode 100644 index 0000000..e3bbcc1 --- /dev/null +++ b/src/axis/logvalueaxis/chartlogvalueaxisx.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 "chartlogvalueaxisx_p.h" +#include "chartpresenter_p.h" +#include "qlogvalueaxis.h" +#include "chartlayout_p.h" +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item) + : HorizontalAxis(axis, item), + m_axis(axis) +{ +} + +ChartLogValueAxisX::~ChartLogValueAxisX() +{ +} + +QVector ChartLogValueAxisX::calculateLayout() const +{ + QVector points; + + qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); + qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); + int tickCount = qAbs(qRound(logMax - logMin)); + + points.resize(tickCount); + const QRectF &gridRect = gridGeometry(); + const qreal deltaX = gridRect.width() / qAbs(logMax - logMin); + for (int i = 0; i < tickCount; ++i) + if (logMax > logMin) + points[i] = ((int)logMin + i) * deltaX - logMin * deltaX + gridRect.left(); + else + points[i] = ((int)logMax + i) * deltaX - logMax * deltaX + gridRect.left(); + + return points; +} + +void ChartLogValueAxisX::updateGeometry() +{ + const QVector& layout = ChartAxis::layout(); + if (layout.isEmpty()) + return; + setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); + HorizontalAxis::updateGeometry(); +} + +//void ChartLogValueAxisX::handleAxisUpdated() +//{ +// ChartAxis::handleAxisUpdated(); +//} + +QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + Q_UNUSED(constraint) + + QFontMetrics fn(font()); + QSizeF sh; + + QSizeF base = HorizontalAxis::sizeHint(which, constraint); + QStringList ticksList; + qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); + qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); + int tickCount = qAbs(qRound(logMax - logMin)); + + if (m_axis->max() > m_axis->min() && tickCount > 1) + ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); + else + ticksList.append(QString(" ")); + qreal width = 0; + qreal height = 0; + + + switch (which) { + case Qt::MinimumSize:{ + int count = qMax(ticksList.last().count(),ticksList.first().count()); + width = fn.averageCharWidth() * count; + height = fn.height() + labelPadding(); + width = qMax(width,base.width()); + height += base.height(); + sh = QSizeF(width,height); + break; + } + case Qt::PreferredSize: { + int count = qMax(ticksList.last().count(),ticksList.first().count()); + width=fn.averageCharWidth() * count; + height=fn.height()+labelPadding(); + width=qMax(width,base.width()); + height+=base.height(); + sh = QSizeF(width,height); + break; + } + default: + break; + } + + return sh; +} + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/logvalueaxis/chartlogvalueaxisx_p.h b/src/axis/logvalueaxis/chartlogvalueaxisx_p.h new file mode 100644 index 0000000..f156dbe --- /dev/null +++ b/src/axis/logvalueaxis/chartlogvalueaxisx_p.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial 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 CHARTLOGVALUEAXISX_H +#define CHARTLOGVALUEAXISX_H + +#include "horizontalaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QLogValueAxis; +class ChartPresenter; + +class ChartLogValueAxisX : public HorizontalAxis +{ +public: + ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item); + ~ChartLogValueAxisX(); + + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; + +protected: + void handleAxisUpdated(); + QVector calculateLayout() const; + void updateGeometry(); + +private: + QLogValueAxis *m_axis; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif /* CHARTLOGVALUEAXISX_H */ diff --git a/src/axis/logvalueaxis/chartlogvalueaxisy.cpp b/src/axis/logvalueaxis/chartlogvalueaxisy.cpp new file mode 100644 index 0000000..d4bafac --- /dev/null +++ b/src/axis/logvalueaxis/chartlogvalueaxisy.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** 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 "chartlogvalueaxisy_p.h" +#include "chartpresenter_p.h" +#include "qlogvalueaxis.h" +#include "chartlayout_p.h" +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item) + : VerticalAxis(axis, item), + m_axis(axis) +{ +} + +ChartLogValueAxisY::~ChartLogValueAxisY() +{ +} + +QVector ChartLogValueAxisY::calculateLayout() const +{ + QVector points; + qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); + qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); + int tickCount = qAbs(qRound(logMax - logMin)); + + points.resize(tickCount); + const QRectF &gridRect = gridGeometry(); + const qreal deltaY = gridRect.height() / qAbs(logMax - logMin); + for (int i = 0; i < tickCount; ++i) + if (logMax > logMin) + points[i] = ((int)logMin + i) * -deltaY - logMin * -deltaY + gridRect.bottom(); + else + points[i] = ((int)logMax + i) * -deltaY - logMax * -deltaY + gridRect.bottom(); + + return points; +} + + +void ChartLogValueAxisY::updateGeometry() +{ + const QVector &layout = ChartAxis::layout(); + if (layout.isEmpty()) + return; + setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); + VerticalAxis::updateGeometry(); +} + +//void ChartLogValueAxisY::handleAxisUpdated() +//{ +// ChartAxis::handleAxisUpdated(); +//} + +QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + Q_UNUSED(constraint) + + QFontMetrics fn(font()); + QSizeF sh; + + QSizeF base = VerticalAxis::sizeHint(which, constraint); + QStringList ticksList; + qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); + qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); + int tickCount = qAbs(qRound(logMax - logMin)); + if (m_axis->max() > m_axis->min() && tickCount > 1) + ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); + else + ticksList.append(QString(" ")); + qreal width = 0; + qreal height = 0; + + switch (which) { + case Qt::MinimumSize: { + width = fn.boundingRect("...").width() + labelPadding(); + width += base.width(); + height = fn.height(); + height = qMax(height,base.height()); + sh = QSizeF(width,height); + break; + } + case Qt::PreferredSize: { + int count = qMax(ticksList.first().count() , ticksList.last().count()); + width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance + width += base.width(); + height = fn.height() * ticksList.count(); + height = qMax(height,base.height()); + sh = QSizeF(width,height); + break; + } + default: + break; + } + + return sh; +} + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/logvalueaxis/chartlogvalueaxisy_p.h b/src/axis/logvalueaxis/chartlogvalueaxisy_p.h new file mode 100644 index 0000000..d835083 --- /dev/null +++ b/src/axis/logvalueaxis/chartlogvalueaxisy_p.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial 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 CHARTLOGVALUEAXISY_H +#define CHARTLOGVALUEAXISY_H + +#include "verticalaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QLogValueAxis; +class ChartPresenter; + +class ChartLogValueAxisY : public VerticalAxis +{ +public: + ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item); + ~ChartLogValueAxisY(); + + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; + +protected: + void handleAxisUpdated(); + QVector calculateLayout() const; + void updateGeometry(); + +private: + QLogValueAxis *m_axis; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif /* CHARTLOGVALUEAXISY_H */ diff --git a/src/axis/logvalueaxis/qlogvalueaxis.cpp b/src/axis/logvalueaxis/qlogvalueaxis.cpp new file mode 100644 index 0000000..369f8a3 --- /dev/null +++ b/src/axis/logvalueaxis/qlogvalueaxis.cpp @@ -0,0 +1,315 @@ +/**************************************************************************** +** +** 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 "qlogvalueaxis.h" +#include "qlogvalueaxis_p.h" +#include "chartlogvalueaxisx_p.h" +#include "chartlogvalueaxisy_p.h" +#include "domain_p.h" +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE +/*! + \class QLogValueAxis + \brief The QLogValueAxis class is used for manipulating chart's axis. + \mainclass +*/ + +/*! + \qmlclass DateTimeAxis QLogValueAxis + \brief The DateTimeAxis element is used for manipulating chart's axes + \inherits AbstractAxis +*/ + +/*! + \property QLogValueAxis::min + Defines the minimum value on the axis. + When setting this property the max is adjusted if necessary, to ensure that the range remains valid. +*/ +/*! + \qmlproperty real ValuesAxis::min + Defines the minimum value on the axis. + When setting this property the max is adjusted if necessary, to ensure that the range remains valid. +*/ + +/*! + \property QLogValueAxis::max + Defines the maximum value on the axis. + When setting this property the min is adjusted if necessary, to ensure that the range remains valid. +*/ +/*! + \qmlproperty real ValuesAxis::max + Defines the maximum value on the axis. + When setting this property the min is adjusted if necessary, to ensure that the range remains valid. +*/ + +/*! + \fn void QLogValueAxis::minChanged(qreal min) + Axis emits signal when \a min of axis has changed. +*/ +/*! + \qmlsignal ValuesAxis::onMinChanged(qreal min) + Axis emits signal when \a min of axis has changed. +*/ + +/*! + \fn void QLogValueAxis::maxChanged(qreal max) + Axis emits signal when \a max of axis has changed. +*/ +/*! + \qmlsignal ValuesAxis::onMaxChanged(qreal max) + Axis emits signal when \a max of axis has changed. +*/ + +/*! + \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) + Axis emits signal when \a min or \a max of axis has changed. +*/ + +/*! + Constructs an axis object which is a child of \a parent. +*/ +QLogValueAxis::QLogValueAxis(QObject *parent) : + QAbstractAxis(*new QLogValueAxisPrivate(this), parent) +{ + +} + +/*! + \internal +*/ +QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) +{ + +} + +/*! + Destroys the object +*/ +QLogValueAxis::~QLogValueAxis() +{ + +} + +void QLogValueAxis::setMin(qreal min) +{ + Q_D(QLogValueAxis); + setRange(min, qMax(d->m_max, min)); +} + +qreal QLogValueAxis::min() const +{ + Q_D(const QLogValueAxis); + return d->m_min; +} + +void QLogValueAxis::setMax(qreal max) +{ + Q_D(QLogValueAxis); + setRange(qMin(d->m_min, max), max); +} + +qreal QLogValueAxis::max() const +{ + Q_D(const QLogValueAxis); + return d->m_max; +} + +/*! + Sets range from \a min to \a max on the axis. + If min is greater than max then this function returns without making any changes. +*/ +void QLogValueAxis::setRange(qreal min, qreal max) +{ + Q_D(QLogValueAxis); + bool changed = false; + + if (min > max) + return; + + if (min > 0) { + if (!qFuzzyCompare(d->m_min, min)) { + d->m_min = min; + changed = true; + emit minChanged(min); + } + + if (!qFuzzyCompare(d->m_max, max)) { + d->m_max = max; + changed = true; + emit maxChanged(max); + } + + if (changed) { + emit rangeChanged(min, max); + emit d->rangeChanged(min,max); + } + } +} + +void QLogValueAxis::setLabelFormat(const QString &format) +{ + Q_D(QLogValueAxis); + d->m_format = format; +} + +QString QLogValueAxis::labelFormat() const +{ + Q_D(const QLogValueAxis); + return d->m_format; +} + +void QLogValueAxis::setBase(qreal base) +{ + // check if base is correct + if (base <= 0 || qFuzzyCompare(base, 1)) + return; + + Q_D(QLogValueAxis); + d->m_base = base; +} + +qreal QLogValueAxis::base() const +{ + Q_D(const QLogValueAxis); + return d->m_base; +} + +/*! + Returns the type of the axis +*/ +QAbstractAxis::AxisType QLogValueAxis::type() const +{ + return AxisTypeLogValue; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) + : QAbstractAxisPrivate(q), + m_min(1), + m_max(10), + m_base(10), + m_format(QString::null) +{ +} + +QLogValueAxisPrivate::~QLogValueAxisPrivate() +{ + +} + +void QLogValueAxisPrivate::setMin(const QVariant &min) +{ + Q_Q(QLogValueAxis); + bool ok; + qreal value = min.toReal(&ok); + if (ok) + q->setMin(value); +} + +void QLogValueAxisPrivate::setMax(const QVariant &max) +{ + + Q_Q(QLogValueAxis); + bool ok; + qreal value = max.toReal(&ok); + if (ok) + q->setMax(value); +} + +void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) +{ + Q_Q(QLogValueAxis); + bool ok1; + bool ok2; + qreal value1 = min.toReal(&ok1); + qreal value2 = max.toReal(&ok2); + if (ok1 && ok2) + q->setRange(value1, value2); +} + +void QLogValueAxisPrivate::setRange(qreal min, qreal max) +{ + Q_Q(QLogValueAxis); + bool changed = false; + + if (min > max) + return; + + if (min > 0) { + if (!qFuzzyCompare(m_min, min)) { + m_min = min; + changed = true; + emit q->minChanged(min); + } + + if (!qFuzzyCompare(m_max, max)) { + m_max = max; + changed = true; + emit q->maxChanged(max); + } + + if (changed) { + emit q->rangeChanged(min, max); + emit rangeChanged(min,max); + } + } +} + +void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) +{ + Q_Q(QLogValueAxis); + ChartAxis* axis(0); + if (orientation() == Qt::Vertical) + axis = new ChartLogValueAxisY(q,parent); + if (orientation() == Qt::Horizontal) + axis = new ChartLogValueAxisX(q,parent); + + m_item.reset(axis); + QAbstractAxisPrivate::initializeGraphics(parent); +} + + +void QLogValueAxisPrivate::initializeDomain(Domain *domain) +{ + if (orientation() == Qt::Vertical) { + if(!qFuzzyCompare(m_max, m_min)) { + domain->setRangeY(m_min, m_max); + } + else { + setRange(domain->minY() + 1, domain->maxY()); + } + } + if (orientation() == Qt::Horizontal) { + if(!qFuzzyCompare(m_max, m_min)) { + domain->setRangeX(m_min, m_max); + } + else { + setRange(domain->minX() + 1, domain->maxX()); + } + } +} + +#include "moc_qlogvalueaxis.cpp" +#include "moc_qlogvalueaxis_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/logvalueaxis/qlogvalueaxis.h b/src/axis/logvalueaxis/qlogvalueaxis.h new file mode 100644 index 0000000..1aa84f0 --- /dev/null +++ b/src/axis/logvalueaxis/qlogvalueaxis.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QLOGVALUEAXIS_H +#define QLOGVALUEAXIS_H + +#include "qabstractaxis.h" + +class QDateTime; + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QLogValueAxisPrivate; + +class QTCOMMERCIALCHART_EXPORT QLogValueAxis : public QAbstractAxis +{ + Q_OBJECT + Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) + Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) + Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat) + +public: + explicit QLogValueAxis(QObject *parent = 0); + ~QLogValueAxis(); + +protected: + QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = 0); + +public: + AxisType type() const; + + //range handling + void setMin(qreal min); + qreal min() const; + void setMax(qreal max); + qreal max() const; + void setRange(qreal min, qreal max); + + void setLabelFormat(const QString &format); + QString labelFormat() const; + + void setBase(qreal base); + qreal base() const; + +Q_SIGNALS: + void minChanged(qreal min); + void maxChanged(qreal max); + void rangeChanged(qreal min, qreal max); + +private: + Q_DECLARE_PRIVATE(QLogValueAxis) + Q_DISABLE_COPY(QLogValueAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QLOGVALUEAXIS_H diff --git a/src/axis/logvalueaxis/qlogvalueaxis_p.h b/src/axis/logvalueaxis/qlogvalueaxis_p.h new file mode 100644 index 0000000..f4bb7fb --- /dev/null +++ b/src/axis/logvalueaxis/qlogvalueaxis_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial 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 QLOGVALUEAXIS_P_H +#define QLOGVALUEAXIS_P_H + +#include "qlogvalueaxis.h" +#include "qabstractaxis_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QLogValueAxisPrivate : public QAbstractAxisPrivate +{ + Q_OBJECT + public: + QLogValueAxisPrivate(QLogValueAxis *q); + ~QLogValueAxisPrivate(); + + public: + void initializeGraphics(QGraphicsItem* parent); + void initializeDomain(Domain *domain); + + qreal min() { return m_min; } + qreal max() { return m_max; } + void setRange(qreal min,qreal max); + + protected: + void setMin(const QVariant &min); + void setMax(const QVariant &max); + void setRange(const QVariant &min, const QVariant &max); + int tickCount() const; + + protected: + qreal m_min; + qreal m_max; + qreal m_base; + QString m_format; + Q_DECLARE_PUBLIC(QLogValueAxis) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QLOGVALUEAXIS_P_H diff --git a/src/axis/qabstractaxis.h b/src/axis/qabstractaxis.h index 8127407..066ca39 100644 --- a/src/axis/qabstractaxis.h +++ b/src/axis/qabstractaxis.h @@ -74,7 +74,8 @@ public: AxisTypeValue = 0x1, AxisTypeBarCategory = 0x2, AxisTypeCategory = 0x3, - AxisTypeDateTime = 0x4 + AxisTypeDateTime = 0x4, + AxisTypeLogValue = 0x5 }; Q_DECLARE_FLAGS(AxisTypes, AxisType)