| 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 | #include <QtCharts/QHorizontalStackedBarSeries> |
| 30 | #include <private/qhorizontalstackedbarseries_p.h> |
| 31 | #include <private/horizontalstackedbarchartitem_p.h> |
| 32 | |
| 33 | #include <private/chartdataset_p.h> |
| 34 | #include <private/charttheme_p.h> |
| 35 | |
| 36 | QT_CHARTS_BEGIN_NAMESPACE |
| 37 | /*! |
| 38 | \class QHorizontalStackedBarSeries |
| 39 | \inmodule QtCharts |
| 40 | \brief The QHorizontalStackedBarSeries class presents a series of data as horizontally |
| 41 | stacked bars, with one bar per category. |
| 42 | |
| 43 | Each bar set added to the series contributes a single segment to each stacked bar. |
| 44 | |
| 45 | See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart. |
| 46 | \image examples_horizontalstackedbarchart.png |
| 47 | |
| 48 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries |
| 49 | */ |
| 50 | /*! |
| 51 | \qmltype HorizontalStackedBarSeries |
| 52 | \instantiates QHorizontalStackedBarSeries |
| 53 | \inqmlmodule QtCharts |
| 54 | |
| 55 | \inherits AbstractBarSeries |
| 56 | |
| 57 | \brief Presents a series of data as stacked horizontal bars, with one bar per category. |
| 58 | |
| 59 | Each bar set added to the series contributes a single segment to each stacked bar. |
| 60 | |
| 61 | The following QML code snippet shows how to create a simple horizontal stacked bar chart: |
| 62 | \snippet qmlchart/qml/qmlchart/View10.qml 1 |
| 63 | \beginfloatleft |
| 64 | \image examples_qmlchart10.png |
| 65 | \endfloat |
| 66 | \clearfloat |
| 67 | */ |
| 68 | |
| 69 | /*! |
| 70 | Constructs an empty horizontal stacked bar series that is a QObject and a child of \a parent. |
| 71 | */ |
| 72 | QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) |
| 73 | : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | Removes the bar series from the chart. |
| 79 | */ |
| 80 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() |
| 81 | { |
| 82 | Q_D(QHorizontalStackedBarSeries); |
| 83 | if (d->m_chart) |
| 84 | d->m_chart->removeSeries(series: this); |
| 85 | } |
| 86 | |
| 87 | /*! |
| 88 | Returns the horizontal stacked bar series. |
| 89 | */ |
| 90 | QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const |
| 91 | { |
| 92 | return QAbstractSeries::SeriesTypeHorizontalStackedBar; |
| 93 | } |
| 94 | |
| 95 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 96 | |
| 97 | QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
| 98 | { |
| 99 | |
| 100 | } |
| 101 | |
| 102 | void QHorizontalStackedBarSeriesPrivate::initializeDomain() |
| 103 | { |
| 104 | qreal minX(domain()->minX()); |
| 105 | qreal minY(domain()->minY()); |
| 106 | qreal maxX(domain()->maxX()); |
| 107 | qreal maxY(domain()->maxY()); |
| 108 | |
| 109 | qreal y = categoryCount(); |
| 110 | minX = qMin(a: minX, b: bottom()); |
| 111 | minY = qMin(a: minY, b: - (qreal)0.5); |
| 112 | maxX = qMax(a: maxX, b: top()); |
| 113 | maxY = qMax(a: maxY, b: y - (qreal)0.5); |
| 114 | |
| 115 | domain()->setRange(minX, maxX, minY, maxY); |
| 116 | } |
| 117 | |
| 118 | void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent) |
| 119 | { |
| 120 | Q_Q(QHorizontalStackedBarSeries); |
| 121 | HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent); |
| 122 | m_item.reset(other: bar); |
| 123 | QAbstractSeriesPrivate::initializeGraphics(parent); |
| 124 | } |
| 125 | |
| 126 | QT_CHARTS_END_NAMESPACE |
| 127 | |
| 128 | #include "moc_qhorizontalstackedbarseries.cpp" |
| 129 | |