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