summaryrefslogtreecommitdiffstats
path: root/src/axis/logvalueaxis
diff options
context:
space:
mode:
Diffstat (limited to 'src/axis/logvalueaxis')
-rw-r--r--src/axis/logvalueaxis/chartlogvalueaxisx.cpp14
-rw-r--r--src/axis/logvalueaxis/chartlogvalueaxisx_p.h4
-rw-r--r--src/axis/logvalueaxis/chartlogvalueaxisy.cpp14
-rw-r--r--src/axis/logvalueaxis/chartlogvalueaxisy_p.h4
-rw-r--r--src/axis/logvalueaxis/polarchartlogvalueaxisangular.cpp90
-rw-r--r--src/axis/logvalueaxis/polarchartlogvalueaxisangular_p.h57
-rw-r--r--src/axis/logvalueaxis/polarchartlogvalueaxisradial.cpp95
-rw-r--r--src/axis/logvalueaxis/polarchartlogvalueaxisradial_p.h57
-rw-r--r--src/axis/logvalueaxis/qlogvalueaxis.cpp28
9 files changed, 335 insertions, 28 deletions
diff --git a/src/axis/logvalueaxis/chartlogvalueaxisx.cpp b/src/axis/logvalueaxis/chartlogvalueaxisx.cpp
index 3edc6d95..ac8f1f08 100644
--- a/src/axis/logvalueaxis/chartlogvalueaxisx.cpp
+++ b/src/axis/logvalueaxis/chartlogvalueaxisx.cpp
@@ -21,7 +21,7 @@
#include "chartlogvalueaxisx_p.h"
#include "chartpresenter_p.h"
#include "qlogvalueaxis.h"
-#include "chartlayout_p.h"
+#include "abstractchartlayout_p.h"
#include <QGraphicsLayout>
#include <QFontMetrics>
#include <qmath.h>
@@ -29,12 +29,12 @@
QTCOMMERCIALCHART_BEGIN_NAMESPACE
-ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item)
+ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem *item)
: HorizontalAxis(axis, item),
m_axis(axis)
{
- QObject::connect(m_axis,SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal)));
- QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
+ QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
+ QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
}
ChartLogValueAxisX::~ChartLogValueAxisX()
@@ -55,14 +55,14 @@ QVector<qreal> ChartLogValueAxisX::calculateLayout() const
const QRectF &gridRect = gridGeometry();
const qreal deltaX = gridRect.width() / qAbs(logMax - logMin);
for (int i = 0; i < tickCount; ++i)
- points[i] = (ceilEdge + i) * deltaX - leftEdge * deltaX + gridRect.left();
+ points[i] = (ceilEdge + qreal(i)) * deltaX - leftEdge * deltaX + gridRect.left();
return points;
}
void ChartLogValueAxisX::updateGeometry()
{
- const QVector<qreal>& layout = ChartAxis::layout();
+ const QVector<qreal>& layout = ChartAxisElement::layout();
if (layout.isEmpty())
return;
setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
@@ -87,7 +87,7 @@ QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
{
Q_UNUSED(constraint)
- QFontMetrics fn(font());
+ QFontMetrics fn(axis()->labelsFont());
QSizeF sh;
QSizeF base = HorizontalAxis::sizeHint(which, constraint);
diff --git a/src/axis/logvalueaxis/chartlogvalueaxisx_p.h b/src/axis/logvalueaxis/chartlogvalueaxisx_p.h
index c0b24a58..3017e260 100644
--- a/src/axis/logvalueaxis/chartlogvalueaxisx_p.h
+++ b/src/axis/logvalueaxis/chartlogvalueaxisx_p.h
@@ -35,20 +35,18 @@
QTCOMMERCIALCHART_BEGIN_NAMESPACE
class QLogValueAxis;
-class ChartPresenter;
class ChartLogValueAxisX : public HorizontalAxis
{
Q_OBJECT
public:
- ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item);
+ ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem *item);
~ChartLogValueAxisX();
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
protected:
- void handleAxisUpdated();
QVector<qreal> calculateLayout() const;
void updateGeometry();
diff --git a/src/axis/logvalueaxis/chartlogvalueaxisy.cpp b/src/axis/logvalueaxis/chartlogvalueaxisy.cpp
index ec474e2f..42ae875c 100644
--- a/src/axis/logvalueaxis/chartlogvalueaxisy.cpp
+++ b/src/axis/logvalueaxis/chartlogvalueaxisy.cpp
@@ -21,7 +21,7 @@
#include "chartlogvalueaxisy_p.h"
#include "chartpresenter_p.h"
#include "qlogvalueaxis.h"
-#include "chartlayout_p.h"
+#include "abstractchartlayout_p.h"
#include <QGraphicsLayout>
#include <QFontMetrics>
#include <qmath.h>
@@ -29,12 +29,12 @@
QTCOMMERCIALCHART_BEGIN_NAMESPACE
-ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item)
+ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem *item)
: VerticalAxis(axis, item),
m_axis(axis)
{
- QObject::connect(m_axis, SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal)));
- QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
+ QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
+ QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
}
ChartLogValueAxisY::~ChartLogValueAxisY()
@@ -54,7 +54,7 @@ QVector<qreal> ChartLogValueAxisY::calculateLayout() const
const QRectF &gridRect = gridGeometry();
const qreal deltaY = gridRect.height() / qAbs(logMax - logMin);
for (int i = 0; i < tickCount; ++i)
- points[i] = (ceilEdge + i) * -deltaY - leftEdge * -deltaY + gridRect.bottom();
+ points[i] = (ceilEdge + qreal(i)) * -deltaY - leftEdge * -deltaY + gridRect.bottom();
return points;
}
@@ -62,7 +62,7 @@ QVector<qreal> ChartLogValueAxisY::calculateLayout() const
void ChartLogValueAxisY::updateGeometry()
{
- const QVector<qreal> &layout = ChartAxis::layout();
+ const QVector<qreal> &layout = ChartAxisElement::layout();
if (layout.isEmpty())
return;
setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
@@ -87,7 +87,7 @@ QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
{
Q_UNUSED(constraint)
- QFontMetrics fn(font());
+ QFontMetrics fn(axis()->labelsFont());
QSizeF sh;
QSizeF base = VerticalAxis::sizeHint(which, constraint);
diff --git a/src/axis/logvalueaxis/chartlogvalueaxisy_p.h b/src/axis/logvalueaxis/chartlogvalueaxisy_p.h
index 8506cc29..39750976 100644
--- a/src/axis/logvalueaxis/chartlogvalueaxisy_p.h
+++ b/src/axis/logvalueaxis/chartlogvalueaxisy_p.h
@@ -35,20 +35,18 @@
QTCOMMERCIALCHART_BEGIN_NAMESPACE
class QLogValueAxis;
-class ChartPresenter;
class ChartLogValueAxisY : public VerticalAxis
{
Q_OBJECT
public:
- ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item);
+ ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem *item);
~ChartLogValueAxisY();
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
protected:
- void handleAxisUpdated();
QVector<qreal> calculateLayout() const;
void updateGeometry();
diff --git a/src/axis/logvalueaxis/polarchartlogvalueaxisangular.cpp b/src/axis/logvalueaxis/polarchartlogvalueaxisangular.cpp
new file mode 100644
index 00000000..ddbd9fe6
--- /dev/null
+++ b/src/axis/logvalueaxis/polarchartlogvalueaxisangular.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 "polarchartlogvalueaxisangular_p.h"
+#include "abstractchartlayout_p.h"
+#include "chartpresenter_p.h"
+#include "qlogvalueaxis.h"
+#include <qmath.h>
+#include <QDebug>
+
+QTCOMMERCIALCHART_BEGIN_NAMESPACE
+
+PolarChartLogValueAxisAngular::PolarChartLogValueAxisAngular(QLogValueAxis *axis, QGraphicsItem *item)
+ : PolarChartAxisAngular(axis, item)
+{
+ QObject::connect(axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
+ QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
+}
+
+PolarChartLogValueAxisAngular::~PolarChartLogValueAxisAngular()
+{
+}
+
+QVector<qreal> PolarChartLogValueAxisAngular::calculateLayout() const
+{
+ QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
+ const qreal logMax = log10(logValueAxis->max()) / log10(logValueAxis->base());
+ const qreal logMin = log10(logValueAxis->min()) / log10(logValueAxis->base());
+ const qreal startEdge = logMin < logMax ? logMin : logMax;
+ const qreal delta = 360.0 / qAbs(logMax - logMin);
+ const qreal initialSpan = (ceil(startEdge) - startEdge) * delta;
+ int tickCount = qAbs(ceil(logMax) - ceil(logMin));
+
+ QVector<qreal> points;
+ points.resize(tickCount);
+
+ for (int i = 0; i < tickCount; ++i) {
+ qreal angularCoordinate = initialSpan + (delta * qreal(i));
+ points[i] = angularCoordinate;
+ }
+
+ return points;
+}
+
+void PolarChartLogValueAxisAngular::createAxisLabels(const QVector<qreal> &layout)
+{
+ QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
+ setLabels(createLogValueLabels(logValueAxis->min(),
+ logValueAxis->max(),
+ logValueAxis->base(),
+ layout.size(),
+ logValueAxis->labelFormat()));
+}
+
+void PolarChartLogValueAxisAngular::handleBaseChanged(qreal base)
+{
+ Q_UNUSED(base);
+ QGraphicsLayoutItem::updateGeometry();
+ if (presenter())
+ presenter()->layout()->invalidate();
+}
+
+void PolarChartLogValueAxisAngular::handleLabelFormatChanged(const QString &format)
+{
+ Q_UNUSED(format);
+ QGraphicsLayoutItem::updateGeometry();
+ if (presenter())
+ presenter()->layout()->invalidate();
+}
+
+#include "moc_polarchartlogvalueaxisangular_p.cpp"
+
+QTCOMMERCIALCHART_END_NAMESPACE
diff --git a/src/axis/logvalueaxis/polarchartlogvalueaxisangular_p.h b/src/axis/logvalueaxis/polarchartlogvalueaxisangular_p.h
new file mode 100644
index 00000000..231172aa
--- /dev/null
+++ b/src/axis/logvalueaxis/polarchartlogvalueaxisangular_p.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 POLARCHARTLOGVALUEAXISANGULAR_P_H
+#define POLARCHARTLOGVALUEAXISANGULAR_P_H
+
+#include "polarchartaxisangular_p.h"
+
+QTCOMMERCIALCHART_BEGIN_NAMESPACE
+
+class QLogValueAxis;
+
+class PolarChartLogValueAxisAngular : public PolarChartAxisAngular
+{
+ Q_OBJECT
+public:
+ PolarChartLogValueAxisAngular(QLogValueAxis *axis, QGraphicsItem *item);
+ ~PolarChartLogValueAxisAngular();
+
+protected:
+ virtual QVector<qreal> calculateLayout() const;
+ virtual void createAxisLabels(const QVector<qreal> &layout);
+
+private Q_SLOTS:
+ void handleBaseChanged(qreal base);
+ void handleLabelFormatChanged(const QString &format);
+};
+
+QTCOMMERCIALCHART_END_NAMESPACE
+
+#endif // POLARCHARTLOGVALUEAXISANGULAR_P_H
diff --git a/src/axis/logvalueaxis/polarchartlogvalueaxisradial.cpp b/src/axis/logvalueaxis/polarchartlogvalueaxisradial.cpp
new file mode 100644
index 00000000..d0719dbc
--- /dev/null
+++ b/src/axis/logvalueaxis/polarchartlogvalueaxisradial.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 "polarchartlogvalueaxisradial_p.h"
+#include "abstractchartlayout_p.h"
+#include "chartpresenter_p.h"
+#include "qlogvalueaxis.h"
+#include <qmath.h>
+#include <QDebug>
+
+QTCOMMERCIALCHART_BEGIN_NAMESPACE
+
+PolarChartLogValueAxisRadial::PolarChartLogValueAxisRadial(QLogValueAxis *axis, QGraphicsItem *item)
+ : PolarChartAxisRadial(axis, item)
+{
+ QObject::connect(axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
+ QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
+}
+
+PolarChartLogValueAxisRadial::~PolarChartLogValueAxisRadial()
+{
+}
+
+QVector<qreal> PolarChartLogValueAxisRadial::calculateLayout() const
+{
+ QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
+ const qreal logMax = log10(logValueAxis->max()) / log10(logValueAxis->base());
+ const qreal logMin = log10(logValueAxis->min()) / log10(logValueAxis->base());
+ const qreal innerEdge = logMin < logMax ? logMin : logMax;
+ const qreal outerEdge = logMin > logMax ? logMin : logMax;
+ const qreal delta = (axisGeometry().width() / 2.0) / qAbs(logMax - logMin);
+ const qreal initialSpan = (ceil(innerEdge) - innerEdge) * delta;
+ int tickCount = qAbs(ceil(logMax) - ceil(logMin));
+
+ // Extra tick if outer edge is exactly at the tick
+ if (outerEdge == ceil(outerEdge))
+ tickCount++;
+
+ QVector<qreal> points;
+ points.resize(tickCount);
+
+ for (int i = 0; i < tickCount; ++i) {
+ qreal radialCoordinate = initialSpan + (delta * qreal(i));
+ points[i] = radialCoordinate;
+ }
+
+ return points;
+}
+
+void PolarChartLogValueAxisRadial::createAxisLabels(const QVector<qreal> &layout)
+{
+ QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
+ setLabels(createLogValueLabels(logValueAxis->min(),
+ logValueAxis->max(),
+ logValueAxis->base(),
+ layout.size(),
+ logValueAxis->labelFormat()));
+}
+
+void PolarChartLogValueAxisRadial::handleBaseChanged(qreal base)
+{
+ Q_UNUSED(base);
+ QGraphicsLayoutItem::updateGeometry();
+ if (presenter())
+ presenter()->layout()->invalidate();
+}
+
+void PolarChartLogValueAxisRadial::handleLabelFormatChanged(const QString &format)
+{
+ Q_UNUSED(format);
+ QGraphicsLayoutItem::updateGeometry();
+ if (presenter())
+ presenter()->layout()->invalidate();
+}
+
+#include "moc_polarchartlogvalueaxisradial_p.cpp"
+
+QTCOMMERCIALCHART_END_NAMESPACE
diff --git a/src/axis/logvalueaxis/polarchartlogvalueaxisradial_p.h b/src/axis/logvalueaxis/polarchartlogvalueaxisradial_p.h
new file mode 100644
index 00000000..bc7e8982
--- /dev/null
+++ b/src/axis/logvalueaxis/polarchartlogvalueaxisradial_p.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 POLARCHARTLOGVALUEAXISRADIAL_P_H
+#define POLARCHARTLOGVALUEAXISRADIAL_P_H
+
+#include "polarchartaxisradial_p.h"
+
+QTCOMMERCIALCHART_BEGIN_NAMESPACE
+
+class QLogValueAxis;
+
+class PolarChartLogValueAxisRadial : public PolarChartAxisRadial
+{
+ Q_OBJECT
+public:
+ PolarChartLogValueAxisRadial(QLogValueAxis *axis, QGraphicsItem *item);
+ ~PolarChartLogValueAxisRadial();
+
+protected:
+ virtual QVector<qreal> calculateLayout() const;
+ virtual void createAxisLabels(const QVector<qreal> &layout);
+
+private Q_SLOTS:
+ void handleBaseChanged(qreal base);
+ void handleLabelFormatChanged(const QString &format);
+};
+
+QTCOMMERCIALCHART_END_NAMESPACE
+
+#endif // POLARCHARTLOGVALUEAXISRADIAL_P_H
diff --git a/src/axis/logvalueaxis/qlogvalueaxis.cpp b/src/axis/logvalueaxis/qlogvalueaxis.cpp
index 12170b8b..27896b51 100644
--- a/src/axis/logvalueaxis/qlogvalueaxis.cpp
+++ b/src/axis/logvalueaxis/qlogvalueaxis.cpp
@@ -22,6 +22,8 @@
#include "qlogvalueaxis_p.h"
#include "chartlogvalueaxisx_p.h"
#include "chartlogvalueaxisy_p.h"
+#include "polarchartlogvalueaxisangular_p.h"
+#include "polarchartlogvalueaxisradial_p.h"
#include "abstractdomain_p.h"
#include <float.h>
#include <cmath>
@@ -287,14 +289,24 @@ void QLogValueAxisPrivate::setRange(qreal min, qreal max)
}
}
-void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
+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);
+ ChartAxisElement *axis(0);
+
+ if (m_chart->chartType() == QChart::ChartTypeCartesian) {
+ if (orientation() == Qt::Vertical)
+ axis = new ChartLogValueAxisY(q,parent);
+ if (orientation() == Qt::Horizontal)
+ axis = new ChartLogValueAxisX(q,parent);
+ }
+
+ if (m_chart->chartType() == QChart::ChartTypePolar) {
+ if (orientation() == Qt::Vertical)
+ axis = new PolarChartLogValueAxisRadial(q, parent);
+ if (orientation() == Qt::Horizontal)
+ axis = new PolarChartLogValueAxisAngular(q, parent);
+ }
m_item.reset(axis);
QAbstractAxisPrivate::initializeGraphics(parent);
@@ -304,7 +316,7 @@ void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
{
if (orientation() == Qt::Vertical) {
- if(!qFuzzyCompare(m_max, m_min)) {
+ if (!qFuzzyCompare(m_max, m_min)) {
domain->setRangeY(m_min, m_max);
} else if ( domain->minY() > 0) {
setRange(domain->minY(), domain->maxY());
@@ -315,7 +327,7 @@ void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
}
}
if (orientation() == Qt::Horizontal) {
- if(!qFuzzyCompare(m_max, m_min)) {
+ if (!qFuzzyCompare(m_max, m_min)) {
domain->setRangeX(m_min, m_max);
} else if (domain->minX() > 0){
setRange(domain->minX(), domain->maxX());