barchartitem.cpp
97 lines
| 3.8 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r794 | /**************************************************************************** | ||
** | ||||
Miikka Heikkinen
|
r2432 | ** Copyright (C) 2013 Digia Plc | ||
Jani Honkonen
|
r794 | ** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
sauimone
|
r666 | #include "barchartitem_p.h" | ||
sauimone
|
r126 | #include "bar_p.h" | ||
sauimone
|
r1586 | #include "qabstractbarseries_p.h" | ||
sauimone
|
r1674 | #include "qbarset.h" | ||
#include "qbarset_p.h" | ||||
sauimone
|
r126 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Michal Klocek
|
r2273 | BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | ||
AbstractBarChartItem(series, item) | ||||
sauimone
|
r126 | { | ||
} | ||||
sauimone
|
r165 | |||
Marek Rosa
|
r2316 | void BarChartItem::initializeLayout() | ||
{ | ||||
qreal categoryCount = m_series->d_func()->categoryCount(); | ||||
qreal setCount = m_series->count(); | ||||
qreal barWidth = m_series->d_func()->barWidth(); | ||||
m_layout.clear(); | ||||
for(int category = 0; category < categoryCount; category++) { | ||||
for (int set = 0; set < setCount; set++) { | ||||
QRectF rect; | ||||
QPointF topLeft; | ||||
QPointF bottomRight; | ||||
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { | ||||
Marek Rosa
|
r2356 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()), m_validData); | ||
Marek Rosa
|
r2387 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY()), m_validData); | ||
Marek Rosa
|
r2316 | } else { | ||
Marek Rosa
|
r2356 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0), m_validData); | ||
bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0), m_validData); | ||||
Marek Rosa
|
r2316 | } | ||
Marek Rosa
|
r2356 | if (!m_validData) | ||
return; | ||||
Marek Rosa
|
r2316 | rect.setTopLeft(topLeft); | ||
rect.setBottomRight(bottomRight); | ||||
m_layout.append(rect.normalized()); | ||||
} | ||||
} | ||||
} | ||||
sauimone
|
r681 | QVector<QRectF> BarChartItem::calculateLayout() | ||
sauimone
|
r671 | { | ||
sauimone
|
r681 | QVector<QRectF> layout; | ||
sauimone
|
r1321 | // Use temporary qreals for accuracy | ||
qreal categoryCount = m_series->d_func()->categoryCount(); | ||||
Tero Ahola
|
r1462 | qreal setCount = m_series->count(); | ||
Marek Rosa
|
r2303 | qreal barWidth = m_series->d_func()->barWidth(); | ||
sauimone
|
r681 | |||
Marek Rosa
|
r2303 | for(int category = 0; category < categoryCount; category++) { | ||
sauimone
|
r681 | for (int set = 0; set < setCount; set++) { | ||
Marek Rosa
|
r2303 | qreal value = m_series->barSets().at(set)->at(category); | ||
QRectF rect; | ||||
Marek Rosa
|
r2356 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value), m_validData); | ||
Marek Rosa
|
r2303 | QPointF bottomRight; | ||
Marek Rosa
|
r2305 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | ||
Marek Rosa
|
r2356 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()), m_validData); | ||
Jani Honkonen
|
r2097 | else | ||
Marek Rosa
|
r2356 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData); | ||
if (!m_validData) | ||||
return QVector<QRectF>(); | ||||
Marek Rosa
|
r2303 | rect.setTopLeft(topLeft); | ||
rect.setBottomRight(bottomRight); | ||||
Marek Rosa
|
r2316 | layout.append(rect.normalized()); | ||
sauimone
|
r681 | } | ||
} | ||||
sauimone
|
r671 | return layout; | ||
} | ||||
sauimone
|
r666 | #include "moc_barchartitem_p.cpp" | ||
Michal Klocek
|
r139 | |||
sauimone
|
r126 | QTCOMMERCIALCHART_END_NAMESPACE | ||