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