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