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

source code of qtcharts/src/charts/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp