| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 |  | 
| 4 | #include <private/horizontalbarchartitem_p.h> | 
| 5 | #include <private/qabstractbarseries_p.h> | 
| 6 | #include <private/qbarset_p.h> | 
| 7 | #include <private/bar_p.h> | 
| 8 |  | 
| 9 | QT_BEGIN_NAMESPACE | 
| 10 |  | 
| 11 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | 
| 12 |     : AbstractBarChartItem(series, item) | 
| 13 | { | 
| 14 | } | 
| 15 |  | 
| 16 | void HorizontalBarChartItem::initializeLayout(int set, int category, | 
| 17 |                                               int layoutIndex, bool resetAnimation) | 
| 18 | { | 
| 19 |     QRectF rect; | 
| 20 |  | 
| 21 |     if (set > 0) { | 
| 22 |         QBarSet *barSet = m_series->barSets().at(i: set - 1); | 
| 23 |         Bar *bar = m_indexForBarMap.value(key: barSet).value(key: category); | 
| 24 |         rect = m_layout.at(i: bar->layoutIndex()); | 
| 25 |         qreal oldTop = rect.top(); | 
| 26 |         if (resetAnimation) | 
| 27 |             rect.setTop(oldTop - rect.height()); | 
| 28 |         rect.setBottom(oldTop); | 
| 29 |         rect.setRight(rect.left()); | 
| 30 |     } else { | 
| 31 |         QPointF topLeft; | 
| 32 |         QPointF bottomRight; | 
| 33 |         const qreal barWidth = m_series->d_func()->barWidth() * m_seriesWidth; | 
| 34 |         const int setCount = m_series->count(); | 
| 35 |         if (domain()->type() == AbstractDomain::LogXYDomain | 
| 36 |                 || domain()->type() == AbstractDomain::LogXLogYDomain) { | 
| 37 |             topLeft = topLeftPoint(set, setCount, category, barWidth, value: domain()->minX()); | 
| 38 |             bottomRight = bottomRightPoint(set, setCount, category, barWidth, value: domain()->minX()); | 
| 39 |         } else { | 
| 40 |             topLeft = topLeftPoint(set, setCount, category, barWidth, value: 0.0); | 
| 41 |             bottomRight = bottomRightPoint(set, setCount, category, barWidth, value: 0.0); | 
| 42 |         } | 
| 43 |  | 
| 44 |         if (m_validData) { | 
| 45 |             rect.setTopLeft(topLeft); | 
| 46 |             rect.setBottomRight(bottomRight); | 
| 47 |         } | 
| 48 |     } | 
| 49 |     m_layout[layoutIndex] = rect.normalized(); | 
| 50 | } | 
| 51 |  | 
| 52 | QPointF HorizontalBarChartItem::topLeftPoint(int set, int setCount, int category, | 
| 53 |                                              qreal barWidth, qreal value) | 
| 54 | { | 
| 55 |     return domain()->calculateGeometryPoint( | 
| 56 |                 point: QPointF(value, m_seriesPosAdjustment + category - (barWidth / 2.0) | 
| 57 |                         + (qreal(set)/setCount) * barWidth), | 
| 58 |                 ok&: m_validData); | 
| 59 | } | 
| 60 |  | 
| 61 | QPointF HorizontalBarChartItem::bottomRightPoint(int set, int setCount, int category, | 
| 62 |                                                  qreal barWidth, qreal value) | 
| 63 | { | 
| 64 |     return domain()->calculateGeometryPoint( | 
| 65 |                 point: QPointF(value, m_seriesPosAdjustment + category - (barWidth / 2.0) | 
| 66 |                         + (qreal(set + 1)/setCount) * barWidth), | 
| 67 |                 ok&: m_validData); | 
| 68 | } | 
| 69 |  | 
| 70 | QList<QRectF> HorizontalBarChartItem::calculateLayout() | 
| 71 | { | 
| 72 |     QList<QRectF> layout; | 
| 73 |     layout.resize(size: m_layout.size()); | 
| 74 |  | 
| 75 |     const int setCount = m_series->count(); | 
| 76 |     const qreal barWidth = m_series->d_func()->barWidth() * m_seriesWidth; | 
| 77 |  | 
| 78 |     for (int set = 0; set < setCount; set++) { | 
| 79 |         QBarSet *barSet = m_series->barSets().at(i: set); | 
| 80 |         const QList<Bar *> bars = m_barMap.value(key: barSet); | 
| 81 |         for (int i = 0; i < m_categoryCount; i++) { | 
| 82 |             Bar *bar = bars.at(i); | 
| 83 |             const int category = bar->index(); | 
| 84 |             qreal value = barSet->at(index: category); | 
| 85 |             QRectF rect; | 
| 86 |             QPointF topLeft; | 
| 87 |             if (domain()->type() == AbstractDomain::LogXYDomain | 
| 88 |                     || domain()->type() == AbstractDomain::LogXLogYDomain) { | 
| 89 |                 topLeft = topLeftPoint(set, setCount, category, barWidth, value: domain()->minX()); | 
| 90 |             } else { | 
| 91 |                 topLeft = topLeftPoint(set, setCount, category, barWidth, value: 0.0); | 
| 92 |             } | 
| 93 |  | 
| 94 |             QPointF bottomRight = bottomRightPoint(set, setCount, category, barWidth, value); | 
| 95 |             rect.setTopLeft(topLeft); | 
| 96 |             rect.setBottomRight(bottomRight); | 
| 97 |             layout[bar->layoutIndex()] = rect.normalized(); | 
| 98 |         } | 
| 99 |     } | 
| 100 |     return layout; | 
| 101 | } | 
| 102 |  | 
| 103 | QT_END_NAMESPACE | 
| 104 |  | 
| 105 | #include "moc_horizontalbarchartitem_p.cpp" | 
| 106 |  |