From 8267a30e4282dae059e71ba22bf76c3a62386894 2012-06-28 06:45:27 From: Marek Rosa Date: 2012-06-28 06:45:27 Subject: [PATCH] Removed generic chartaxis --- diff --git a/src/axis/axis.pri b/src/axis/axis.pri index 6f6b4fa..9f3a6c0 100644 --- a/src/axis/axis.pri +++ b/src/axis/axis.pri @@ -3,8 +3,8 @@ DEPENDPATH += $$PWD SOURCES += \ $$PWD/chartaxis.cpp \ - $$PWD/chartaxisx.cpp \ - $$PWD/chartaxisy.cpp \ +# $$PWD/chartaxisx.cpp \ +# $$PWD/chartaxisy.cpp \ $$PWD/chartvaluesaxisx.cpp \ $$PWD/chartvaluesaxisy.cpp \ $$PWD/chartcategoriesaxisx.cpp \ @@ -15,8 +15,8 @@ SOURCES += \ PRIVATE_HEADERS += \ $$PWD/chartaxis_p.h \ - $$PWD/chartaxisx_p.h \ - $$PWD/chartaxisy_p.h \ +# $$PWD/chartaxisx_p.h \ +# $$PWD/chartaxisy_p.h \ $$PWD/chartvaluesaxisx_p.h \ $$PWD/chartvaluesaxisy_p.h \ $$PWD/chartcategoriesaxisx_p.h \ diff --git a/src/axis/chartaxisx.cpp b/src/axis/chartaxisx.cpp deleted file mode 100644 index f374324..0000000 --- a/src/axis/chartaxisx.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** 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 "chartaxisx_p.h" -#include "qabstractaxis.h" -#include "chartpresenter_p.h" -#include "chartanimator_p.h" -#include -#include -#include - -static int label_padding = 5; - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -ChartAxisX::ChartAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) -{ -} - -ChartAxisX::~ChartAxisX() -{ -} - -QVector ChartAxisX::calculateLayout() const -{ - Q_ASSERT(m_ticksCount>=2); - - QVector points; - points.resize(m_ticksCount); - - const qreal deltaX = m_rect.width()/(m_ticksCount-1); - for (int i = 0; i < m_ticksCount; ++i) { - int x = i * deltaX + m_rect.left(); - points[i] = x; - } - return points; -} - -void ChartAxisX::updateGeometry() -{ - const QVector& layout = ChartAxis::layout(); - - m_minWidth = 0; - m_minHeight = 0; - - if(layout.isEmpty()) return; - - QStringList ticksList; - - bool categories = createLabels(ticksList,m_min,m_max,layout.size()); - - QList lines = m_grid->childItems(); - QList labels = m_labels->childItems(); - QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); - - Q_ASSERT(labels.size() == ticksList.size()); - Q_ASSERT(layout.size() == ticksList.size()); - - QGraphicsLineItem *lineItem = static_cast(axis.at(0)); - lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); - - qreal width = 0; - for (int i = 0; i < layout.size(); ++i) { - QGraphicsLineItem *lineItem = static_cast(lines.at(i)); - lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); - QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); - if (!categories || i<1) { - labelItem->setText(ticksList.at(i)); - const QRectF& rect = labelItem->boundingRect(); - QPointF center = rect.center(); - labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); - - if(labelItem->pos().x()<=width){ - labelItem->setVisible(false); - lineItem->setVisible(false); - }else{ - labelItem->setVisible(true); - lineItem->setVisible(true); - width=rect.width()+labelItem->pos().x(); - } - m_minWidth+=rect.width(); - m_minHeight=qMax(rect.height(),m_minHeight); - } - else { - labelItem->setText(ticksList.at(i)); - const QRectF& rect = labelItem->boundingRect(); - QPointF center = rect.center(); - labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); - m_minWidth+=rect.width(); - m_minHeight=qMax(rect.height()+label_padding,m_minHeight); - } - - if ((i+1)%2 && i>1) { - QGraphicsRectItem *rectItem = static_cast(shades.at(i/2-1)); - rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); - } - lineItem = static_cast(axis.at(i+1)); - lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); - } -} - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartaxisx_p.h b/src/axis/chartaxisx_p.h deleted file mode 100644 index 5e23ce4..0000000 --- a/src/axis/chartaxisx_p.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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 CHARTAXISX_H -#define CHARTAXISX_H - -#include "chartaxis_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QAbstractAxis; -class ChartPresenter; - -class ChartAxisX : public ChartAxis -{ -public: - ChartAxisX(QAbstractAxis *axis, ChartPresenter *presenter); - ~ChartAxisX(); - - AxisType axisType() const { return X_AXIS;} - -protected: - QVector calculateLayout() const; - void updateGeometry(); -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif /* AXISITEM_H_ */ diff --git a/src/axis/chartaxisy.cpp b/src/axis/chartaxisy.cpp deleted file mode 100644 index d98c996..0000000 --- a/src/axis/chartaxisy.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** 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 "chartaxisy_p.h" -#include "qabstractaxis.h" -#include "chartpresenter_p.h" -#include "chartanimator_p.h" -#include -#include -#include - -static int label_padding = 5; - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -ChartAxisY::ChartAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) -{ -} - -ChartAxisY::~ChartAxisY() -{ -} - -QVector ChartAxisY::calculateLayout() const -{ - Q_ASSERT(m_ticksCount>=2); - - QVector points; - points.resize(m_ticksCount); - - const qreal deltaY = m_rect.height()/(m_ticksCount-1); - for (int i = 0; i < m_ticksCount; ++i) { - int y = i * -deltaY + m_rect.bottom(); - points[i] = y; - } - - return points; -} - -void ChartAxisY::updateGeometry() -{ - const QVector &layout = ChartAxis::layout(); - m_minWidth = 0; - m_minHeight = 0; - - if(layout.isEmpty()) return; - - QStringList ticksList; - - bool categories = createLabels(ticksList,m_min,m_max,layout.size()); - - QList lines = m_grid->childItems(); - QList labels = m_labels->childItems(); - QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); - - Q_ASSERT(labels.size() == ticksList.size()); - Q_ASSERT(layout.size() == ticksList.size()); - - qreal height = 2*m_rect.bottom(); - - QGraphicsLineItem *lineItem = static_cast(axis.at(0)); - lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); - - for (int i = 0; i < layout.size(); ++i) { - QGraphicsLineItem *lineItem = static_cast(lines.at(i)); - lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); - QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); - - if (!categories || i<1) { - labelItem->setText(ticksList.at(i)); - const QRectF& rect = labelItem->boundingRect(); - - QPointF center = rect.center(); - labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); - - if(labelItem->pos().y()+rect.height()>height) { - labelItem->setVisible(false); - lineItem->setVisible(false); - } - else { - labelItem->setVisible(true); - lineItem->setVisible(true); - height=labelItem->pos().y(); - } - - m_minWidth=qMax(rect.width()+label_padding,m_minWidth); - m_minHeight+=rect.height(); - } - else { - labelItem->setText(ticksList.at(i)); - const QRectF& rect = labelItem->boundingRect(); - m_minWidth=qMax(rect.width(),m_minWidth); - m_minHeight+=rect.height(); - QPointF center = rect.center(); - labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); - } - - if ((i+1)%2 && i>1) { - QGraphicsRectItem *rectItem = static_cast(shades.at(i/2-1)); - rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); - } - lineItem = static_cast(axis.at(i+1)); - lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); - } -} - - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartaxisy_p.h b/src/axis/chartaxisy_p.h deleted file mode 100644 index 342ede1..0000000 --- a/src/axis/chartaxisy_p.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** 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 CHARTAXISY_H -#define CHARTAXISY_H - -#include "chartaxis_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QAbstractAxis; -class ChartPresenter; - -class ChartAxisY : public ChartAxis -{ -public: - ChartAxisY(QAbstractAxis *axis, ChartPresenter *presenter); - ~ChartAxisY(); - - AxisType axisType() const { return Y_AXIS;} - -protected: - QVector calculateLayout() const; - void updateGeometry(); - -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif /* AXISITEM_H_ */ diff --git a/src/axis/chartcategoriesaxisy.cpp b/src/axis/chartcategoriesaxisy.cpp index d04f8a2..22881e1 100644 --- a/src/axis/chartcategoriesaxisy.cpp +++ b/src/axis/chartcategoriesaxisy.cpp @@ -45,11 +45,12 @@ QVector ChartCategoriesAxisY::calculateLayout() const QVector points; points.resize(m_ticksCount); - const qreal deltaX = m_rect.width()/(m_ticksCount-1); + const qreal deltaY = m_rect.height()/(m_ticksCount-1); for (int i = 0; i < m_ticksCount; ++i) { - int x = i * deltaX + m_rect.left(); - points[i] = x; + int y = i * -deltaY + m_rect.bottom(); + points[i] = y; } + return points; } diff --git a/src/axis/chartvaluesaxisx.cpp b/src/axis/chartvaluesaxisx.cpp index f722376..4e7f5d6 100644 --- a/src/axis/chartvaluesaxisx.cpp +++ b/src/axis/chartvaluesaxisx.cpp @@ -25,6 +25,7 @@ #include #include #include +#include static int label_padding = 5; @@ -64,7 +65,16 @@ void ChartValuesAxisX::updateGeometry() QStringList ticksList; - bool categories = createLabels(ticksList,m_min,m_max,layout.size()); + int ticks = layout.size(); + int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0); + n++; + for (int i=0; i< ticks; i++) { + qreal value = m_min + (i * (m_max - m_min)/ (ticks-1)); + Q_UNUSED(value); + ticksList << QString::number(value,'f',n); + } + + bool categories = false; //createLabels(ticksList,m_min,m_max,layout.size()); QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); @@ -100,15 +110,15 @@ void ChartValuesAxisX::updateGeometry() m_minWidth+=rect.width(); m_minHeight=qMax(rect.height(),m_minHeight); } - else { - labelItem->setText(ticksList.at(i)); - const QRectF& rect = labelItem->boundingRect(); - QPointF center = rect.center(); - labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); - m_minWidth+=rect.width(); - m_minHeight=qMax(rect.height()+label_padding,m_minHeight); - } +// else { +// labelItem->setText(ticksList.at(i)); +// const QRectF& rect = labelItem->boundingRect(); +// QPointF center = rect.center(); +// labelItem->setTransformOriginPoint(center.x(), center.y()); +// labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); +// m_minWidth+=rect.width(); +// m_minHeight=qMax(rect.height()+label_padding,m_minHeight); +// } if ((i+1)%2 && i>1) { QGraphicsRectItem *rectItem = static_cast(shades.at(i/2-1)); diff --git a/src/axis/chartvaluesaxisy.cpp b/src/axis/chartvaluesaxisy.cpp index 9a1aace..0dfb82b 100644 --- a/src/axis/chartvaluesaxisy.cpp +++ b/src/axis/chartvaluesaxisy.cpp @@ -25,6 +25,7 @@ #include #include #include +#include static int label_padding = 5; @@ -45,18 +46,18 @@ QVector ChartValuesAxisY::calculateLayout() const QVector points; points.resize(m_ticksCount); - const qreal deltaX = m_rect.width()/(m_ticksCount-1); + const qreal deltaY = m_rect.height()/(m_ticksCount-1); for (int i = 0; i < m_ticksCount; ++i) { - int x = i * deltaX + m_rect.left(); - points[i] = x; + int y = i * -deltaY + m_rect.bottom(); + points[i] = y; } + return points; } void ChartValuesAxisY::updateGeometry() { - const QVector& layout = ChartAxis::layout(); - + const QVector &layout = ChartAxis::layout(); m_minWidth = 0; m_minHeight = 0; @@ -64,7 +65,18 @@ void ChartValuesAxisY::updateGeometry() QStringList ticksList; - bool categories = createLabels(ticksList,m_min,m_max,layout.size()); + int ticks = layout.size(); + int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0); + n++; + for (int i=0; i< ticks; i++) { + qreal value = m_min + (i * (m_max - m_min)/ (ticks-1)); + Q_UNUSED(value); + ticksList << QString::number(value,'f',n); + } + + bool categories = false; + +// bool categories = createLabels(ticksList,m_min,m_max,layout.size()); QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); @@ -74,48 +86,53 @@ void ChartValuesAxisY::updateGeometry() Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); + qreal height = 2*m_rect.bottom(); + QGraphicsLineItem *lineItem = static_cast(axis.at(0)); - lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); + lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); - qreal width = 0; for (int i = 0; i < layout.size(); ++i) { QGraphicsLineItem *lineItem = static_cast(lines.at(i)); - lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); + lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); + if (!categories || i<1) { labelItem->setText(ticksList.at(i)); const QRectF& rect = labelItem->boundingRect(); + QPointF center = rect.center(); labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); + labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); - if(labelItem->pos().x()<=width){ + if(labelItem->pos().y()+rect.height()>height) { labelItem->setVisible(false); lineItem->setVisible(false); - }else{ + } + else { labelItem->setVisible(true); lineItem->setVisible(true); - width=rect.width()+labelItem->pos().x(); + height=labelItem->pos().y(); } - m_minWidth+=rect.width(); - m_minHeight=qMax(rect.height(),m_minHeight); + + m_minWidth=qMax(rect.width()+label_padding,m_minWidth); + m_minHeight+=rect.height(); } else { labelItem->setText(ticksList.at(i)); const QRectF& rect = labelItem->boundingRect(); + m_minWidth=qMax(rect.width(),m_minWidth); + m_minHeight+=rect.height(); QPointF center = rect.center(); labelItem->setTransformOriginPoint(center.x(), center.y()); - labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); - m_minWidth+=rect.width(); - m_minHeight=qMax(rect.height()+label_padding,m_minHeight); + labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); } if ((i+1)%2 && i>1) { QGraphicsRectItem *rectItem = static_cast(shades.at(i/2-1)); - rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); + rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); } lineItem = static_cast(axis.at(i+1)); - lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); + lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); } } diff --git a/src/axis/qcategoriesaxis.cpp b/src/axis/qcategoriesaxis.cpp index a8e0f77..7562a0e 100644 --- a/src/axis/qcategoriesaxis.cpp +++ b/src/axis/qcategoriesaxis.cpp @@ -20,8 +20,8 @@ #include "qcategoriesaxis.h" #include "qcategoriesaxis_p.h" -#include "chartaxisx_p.h" -#include "chartaxisy_p.h" +#include "chartcategoriesaxisx_p.h" +#include "chartcategoriesaxisy_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -209,9 +209,9 @@ ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) { Q_Q( QCategoriesAxis); if(m_orientation == Qt::Vertical){ - return new ChartAxisY(q,presenter); + return new ChartCategoriesAxisY(q,presenter); }else{ - return new ChartAxisX(q,presenter); + return new ChartCategoriesAxisX(q,presenter); } } diff --git a/src/axis/qvaluesaxis.cpp b/src/axis/qvaluesaxis.cpp index 04f70eb..2c06431 100644 --- a/src/axis/qvaluesaxis.cpp +++ b/src/axis/qvaluesaxis.cpp @@ -20,8 +20,8 @@ #include "qvaluesaxis.h" #include "qvaluesaxis_p.h" -#include "chartaxisx_p.h" -#include "chartaxisy_p.h" +#include "chartvaluesaxisx_p.h" +#include "chartvaluesaxisy_p.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -252,9 +252,9 @@ ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) { Q_Q(QValuesAxis); if(m_orientation == Qt::Vertical){ - return new ChartAxisY(q,presenter); + return new ChartValuesAxisY(q,presenter); }else{ - return new ChartAxisX(q,presenter); + return new ChartValuesAxisX(q,presenter); } } diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 4015cab..af8b35b 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -29,8 +29,8 @@ #include "qabstractseries_p.h" #include "qareaseries.h" #include "chartaxis_p.h" -#include "chartaxisx_p.h" -#include "chartaxisy_p.h" +//#include "chartaxisx_p.h" +//#include "chartaxisy_p.h" #include "areachartitem_p.h" #include "chartbackground_p.h" #include "chartlayout_p.h"