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