##// END OF EJS Templates
Fix some spelling errors
Fix some spelling errors

File last commit:

r1918:a404d0b7b27f
r1932:642d1d1d06a9
Show More
chartbarcategoryaxisy.cpp
163 lines | 5.2 KiB | text/x-c | CppLexer
/ src / axis / barcategoryaxis / chartbarcategoryaxisy.cpp
Marek Rosa
Added Chart classes for value and categories axis
r1555 /****************************************************************************
Michal Klocek
Adds scroll support for categories axis
r1716 **
** 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$
**
****************************************************************************/
Marek Rosa
Added Chart classes for value and categories axis
r1555
Marek Rosa
renamed QBarCategoryAxis related files
r1810 #include "chartbarcategoryaxisy_p.h"
Marek Rosa
Added Chart classes for value and categories axis
r1555 #include "chartpresenter_p.h"
Marek Rosa
renamed QBarCategoryAxis related files
r1810 #include "qbarcategoryaxis_p.h"
Michal Klocek
Fixes rounding issue with labels numbering
r1720 #include <qmath.h>
Michal Klocek
Bugfixes for layout...
r1837 #include <QDebug>
Marek Rosa
Added Chart classes for value and categories axis
r1555
static int label_padding = 5;
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
Michal Klocek
Adds scroll support for categories axis
r1716 m_categoriesAxis(axis)
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 ChartBarCategoryAxisY::~ChartBarCategoryAxisY()
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 int count = m_categoriesAxis->d_ptr->count();
Q_ASSERT(count>=1);
Marek Rosa
Added Chart classes for value and categories axis
r1555
QVector<qreal> points;
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 points.resize(count+2);
Marek Rosa
Added Chart classes for value and categories axis
r1555
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 const qreal delta = m_rect.height()/(count);
Michal Klocek
Fixes rounding issue with labels numbering
r1720 qreal offset = - m_min - 0.5;
Michal Klocek
Adds scroll support for categories axis
r1716
Michal Klocek
Bugfixes for layout...
r1837 if(delta<1) return points;
Michal Klocek
Fixes rounding issue with labels numbering
r1720 if(offset<=0) {
offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta) + delta;
Michal Klocek
Adds scroll support for categories axis
r1716 }
else {
Michal Klocek
Fixes rounding issue with labels numbering
r1720 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta);
Michal Klocek
Adds scroll support for categories axis
r1716 }
Michal Klocek
Fixes rounding issue with labels numbering
r1720 points[0] = m_rect.bottom();
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 points[count+1] = m_rect.top();
Michal Klocek
Adds scroll support for categories axis
r1716
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 for (int i = 0; i < count; ++i) {
Michal Klocek
Fixes rounding issue with labels numbering
r1720 int y = m_rect.bottom() - i * delta - offset;
points[i+1] = y;
Marek Rosa
Added Chart classes for value and categories axis
r1555 }
return points;
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const
Michal Klocek
Fixes rounding issue with labels numbering
r1720 {
QStringList result;
qreal d = (m_max - m_min)/m_rect.height();
for (int i = 0;i < layout.count()-1; ++i) {
qreal x = qFloor(((m_rect.height()- (layout[i+1] + layout[i])/2 + m_rect.top())*d + m_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;
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 void ChartBarCategoryAxisY::updateGeometry()
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
const QVector<qreal>& layout = ChartAxis::layout();
m_minWidth = 0;
m_minHeight = 0;
if(layout.isEmpty()) return;
Michal Klocek
Fixes rounding issue with labels numbering
r1720 QStringList ticksList = createCategoryLabels(layout);
Marek Rosa
Added Chart classes for value and categories axis
r1555
QList<QGraphicsItem *> lines = m_grid->childItems();
QList<QGraphicsItem *> labels = m_labels->childItems();
QList<QGraphicsItem *> shades = m_shades->childItems();
Michal Klocek
Refactor Visibly methods of axis...
r1729 QList<QGraphicsItem *> axis = m_arrow->childItems();
Marek Rosa
Added Chart classes for value and categories axis
r1555
Michal Klocek
Adds scroll support for categories axis
r1716 Q_ASSERT(labels.size() == ticksList.size());
Q_ASSERT(layout.size() == ticksList.size());
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 const qreal delta = m_rect.height()/(m_categoriesAxis->d_ptr->count());
Marek Rosa
Added Chart classes for value and categories axis
r1555
QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
Michal Klocek
Fixes customchart, barcategoryaxisy
r1655 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
Marek Rosa
Added Chart classes for value and categories axis
r1555
Michal Klocek
Adds scroll support for categories axis
r1716 qreal height = m_rect.bottom();
Michal Klocek
Bugfixes to barcategoryaxis
r1640 for (int i = 0; i < layout.size(); ++i) {
Marek Rosa
Added Chart classes for value and categories axis
r1555 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
sauimone
fixed bug in category y axis
r1682 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
Marek Rosa
Added Chart classes for value and categories axis
r1555 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
Michal Klocek
Adds scroll support for categories axis
r1716 labelItem->setText(ticksList.at(i));
Michal Klocek
Refactor QChart API...
r1577 const QRectF& rect = labelItem->boundingRect();
QPointF center = rect.center();
labelItem->setTransformOriginPoint(center.x(), center.y());
Michal Klocek
Adds scroll support for categories axis
r1716
Michal Klocek
Fixes rounding issue with labels numbering
r1720 if(i==0) {
labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i+1] + (delta)/2 - center.y());
Michal Klocek
Adds scroll support for categories axis
r1716 }
else {
Michal Klocek
Fixes rounding issue with labels numbering
r1720 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i] - (delta)/2 - center.y());
Michal Klocek
Bugfixes to barcategoryaxis
r1640 }
Michal Klocek
Adds scroll support for categories axis
r1716 if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < m_rect.top()) {
labelItem->setVisible(false);
}
else {
labelItem->setVisible(true);
height=labelItem->pos().y();
}
Michal Klocek
Bugfixes for layout...
r1837 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
m_minHeight+=rect.height();
Marek Rosa
Added Chart classes for value and categories axis
r1555
if ((i+1)%2 && i>1) {
QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
Michal Klocek
Fixes customchart, barcategoryaxisy
r1655 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
Marek Rosa
Added Chart classes for value and categories axis
r1555 }
lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
Michal Klocek
Fixes customchart, barcategoryaxisy
r1655 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
Marek Rosa
Added Chart classes for value and categories axis
r1555 }
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 void ChartBarCategoryAxisY::handleAxisUpdated()
Michal Klocek
Fixes missing update barcategory...
r1643 {
if(m_categoriesAxis->categories()!=m_categories)
{
m_categories=m_categoriesAxis->categories();
Michal Klocek
Implements qbarcategoriesaxis logic...
r1725 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) {
Michal Klocek
Fixes rounding issue with labels numbering
r1720 updateGeometry();
}
Michal Klocek
Fixes missing update barcategory...
r1643 }
ChartAxis::handleAxisUpdated();
}
Marek Rosa
Added Chart classes for value and categories axis
r1555 QTCOMMERCIALCHART_END_NAMESPACE