| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #include <QtCharts/QStackedBarSeries> |
| 31 | #include <private/qstackedbarseries_p.h> |
| 32 | #include <private/stackedbarchartitem_p.h> |
| 33 | #include <private/chartdataset_p.h> |
| 34 | #include <private/charttheme_p.h> |
| 35 | #include <QtCharts/QValueAxis> |
| 36 | |
| 37 | QT_CHARTS_BEGIN_NAMESPACE |
| 38 | |
| 39 | /*! |
| 40 | \class QStackedBarSeries |
| 41 | \inmodule QtCharts |
| 42 | \brief The QStackedBarSeries class presents a series of data as vertically stacked bars, |
| 43 | with one bar per category. |
| 44 | |
| 45 | Each bar set added to the series contributes a single segment to each stacked bar. |
| 46 | |
| 47 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
| 48 | \image examples_stackedbarchart.png |
| 49 | |
| 50 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
| 51 | */ |
| 52 | |
| 53 | /*! |
| 54 | \qmltype StackedBarSeries |
| 55 | \instantiates QStackedBarSeries |
| 56 | \inqmlmodule QtCharts |
| 57 | |
| 58 | \inherits AbstractBarSeries |
| 59 | |
| 60 | \brief Presents a series of data as vertically stacked bars, with one bar per category. |
| 61 | |
| 62 | Each bar set added to the series contributes a single segment to each stacked bar. |
| 63 | |
| 64 | The following QML shows how to create a simple stacked bar chart: |
| 65 | \snippet qmlchart/qml/qmlchart/View7.qml 1 |
| 66 | \beginfloatleft |
| 67 | \image examples_qmlchart7.png |
| 68 | \endfloat |
| 69 | \clearfloat |
| 70 | */ |
| 71 | |
| 72 | /*! |
| 73 | Constructs an empty bar series that is a QObject and a child of \a parent. |
| 74 | */ |
| 75 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
| 76 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | /*! |
| 81 | Removes the bar series from the chart. |
| 82 | */ |
| 83 | QStackedBarSeries::~QStackedBarSeries() |
| 84 | { |
| 85 | Q_D(QStackedBarSeries); |
| 86 | if (d->m_chart) |
| 87 | d->m_chart->removeSeries(series: this); |
| 88 | } |
| 89 | /*! |
| 90 | Returns the stacked bar series. |
| 91 | */ |
| 92 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
| 93 | { |
| 94 | return QAbstractSeries::SeriesTypeStackedBar; |
| 95 | } |
| 96 | |
| 97 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
| 100 | { |
| 101 | |
| 102 | } |
| 103 | |
| 104 | void QStackedBarSeriesPrivate::initializeDomain() |
| 105 | { |
| 106 | qreal minX(domain()->minX()); |
| 107 | qreal minY(domain()->minY()); |
| 108 | qreal maxX(domain()->maxX()); |
| 109 | qreal maxY(domain()->maxY()); |
| 110 | |
| 111 | qreal x = categoryCount(); |
| 112 | minX = qMin(a: minX, b: - (qreal)0.5); |
| 113 | minY = qMin(a: minY, b: bottom()); |
| 114 | maxX = qMax(a: maxX, b: x - (qreal)0.5); |
| 115 | maxY = qMax(a: maxY, b: top()); |
| 116 | |
| 117 | domain()->setRange(minX, maxX, minY, maxY); |
| 118 | } |
| 119 | |
| 120 | void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
| 121 | { |
| 122 | Q_Q(QStackedBarSeries); |
| 123 | StackedBarChartItem *bar = new StackedBarChartItem(q,parent); |
| 124 | m_item.reset(other: bar); |
| 125 | QAbstractSeriesPrivate::initializeGraphics(parent); |
| 126 | } |
| 127 | |
| 128 | QT_CHARTS_END_NAMESPACE |
| 129 | |
| 130 | #include "moc_qstackedbarseries.cpp" |
| 131 | |