| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 | #include <QtCharts/QHorizontalStackedBarSeries> | 
| 4 | #include <private/qhorizontalstackedbarseries_p.h> | 
| 5 | #include <private/horizontalstackedbarchartitem_p.h> | 
| 6 |  | 
| 7 | #include <private/chartdataset_p.h> | 
| 8 | #include <private/charttheme_p.h> | 
| 9 |  | 
| 10 | QT_BEGIN_NAMESPACE | 
| 11 | /*! | 
| 12 |     \class QHorizontalStackedBarSeries | 
| 13 |     \inmodule QtCharts | 
| 14 |     \brief The QHorizontalStackedBarSeries class presents a series of data as horizontally | 
| 15 |     stacked bars, with one bar per category. | 
| 16 |  | 
| 17 |     Each bar set added to the series contributes a single segment to each stacked bar. | 
| 18 |  | 
| 19 |     See the \l {Charts with Widgets Gallery} to learn how to create a horizontal stacked bar chart. | 
| 20 |     \image examples_horizontalstackedbarchart.png | 
| 21 |  | 
| 22 |     \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries | 
| 23 | */ | 
| 24 | /*! | 
| 25 |     \qmltype HorizontalStackedBarSeries | 
| 26 |     \nativetype QHorizontalStackedBarSeries | 
| 27 |     \inqmlmodule QtCharts | 
| 28 |  | 
| 29 |     \inherits AbstractBarSeries | 
| 30 |  | 
| 31 |     \brief Presents a series of data as stacked horizontal bars, with one bar per category. | 
| 32 |  | 
| 33 |     Each bar set added to the series contributes a single segment to each stacked bar. | 
| 34 |  | 
| 35 |     The following QML code snippet shows how to create a simple horizontal stacked bar chart: | 
| 36 |     \snippet qmlchartsgallery/qml/BarSeriesStackedHorizontal.qml 1 | 
| 37 |     \beginfloatleft | 
| 38 |     \image examples_qmlchart10.png | 
| 39 |     \endfloat | 
| 40 |     \clearfloat | 
| 41 | */ | 
| 42 |  | 
| 43 | /*! | 
| 44 |     Constructs an empty horizontal stacked bar series that is a QObject and a child of \a parent. | 
| 45 | */ | 
| 46 | QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) | 
| 47 |     : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent) | 
| 48 | { | 
| 49 | } | 
| 50 |  | 
| 51 | /*! | 
| 52 |     Removes the bar series from the chart. | 
| 53 | */ | 
| 54 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() | 
| 55 | { | 
| 56 |     Q_D(QHorizontalStackedBarSeries); | 
| 57 |     if (d->m_chart) | 
| 58 |         d->m_chart->removeSeries(series: this); | 
| 59 | } | 
| 60 |  | 
| 61 | /*! | 
| 62 |     Returns the horizontal stacked bar series. | 
| 63 | */ | 
| 64 | QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const | 
| 65 | { | 
| 66 |     return QAbstractSeries::SeriesTypeHorizontalStackedBar; | 
| 67 | } | 
| 68 |  | 
| 69 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 70 |  | 
| 71 | QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) | 
| 72 | { | 
| 73 |  | 
| 74 | } | 
| 75 |  | 
| 76 | void QHorizontalStackedBarSeriesPrivate::initializeDomain() | 
| 77 | { | 
| 78 |     qreal minX(domain()->minX()); | 
| 79 |     qreal minY(domain()->minY()); | 
| 80 |     qreal maxX(domain()->maxX()); | 
| 81 |     qreal maxY(domain()->maxY()); | 
| 82 |  | 
| 83 |     qreal y = categoryCount(); | 
| 84 |     minX = qMin(a: minX, b: bottom()); | 
| 85 |     minY = qMin(a: minY, b: - (qreal)0.5); | 
| 86 |     maxX = qMax(a: maxX, b: top()); | 
| 87 |     maxY = qMax(a: maxY, b: y - (qreal)0.5); | 
| 88 |  | 
| 89 |     domain()->setRange(minX, maxX, minY, maxY); | 
| 90 | } | 
| 91 |  | 
| 92 | void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | 
| 93 | { | 
| 94 |     Q_Q(QHorizontalStackedBarSeries); | 
| 95 |     HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent); | 
| 96 |     m_item.reset(p: bar); | 
| 97 |     QAbstractSeriesPrivate::initializeGraphics(parent); | 
| 98 | } | 
| 99 |  | 
| 100 | QT_END_NAMESPACE | 
| 101 |  | 
| 102 | #include "moc_qhorizontalstackedbarseries.cpp" | 
| 103 |  |