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