qbarseries.cpp
125 lines
| 3.4 KiB
| text/x-c
|
CppLexer
|
r2845 | /****************************************************************************** | ||
|
r1167 | ** | ||
|
r2845 | ** Copyright (C) 2015 The Qt Company Ltd. | ||
** Contact: http://www.qt.io/licensing/ | ||||
|
r1167 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r1167 | ** | ||
|
r2845 | ** $QT_BEGIN_LICENSE:COMM$ | ||
|
r1167 | ** | ||
|
r2845 | ** Commercial License Usage | ||
** Licensees holding valid commercial Qt licenses may use this file in | ||||
** accordance with the commercial license agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and The Qt Company. For licensing terms | ||||
** and conditions see http://www.qt.io/terms-conditions. For further | ||||
** information use the contact form at http://www.qt.io/contact-us. | ||||
|
r1167 | ** | ||
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
******************************************************************************/ | ||||
|
r1167 | |||
|
r2714 | #include <QtCharts/QBarSeries> | ||
#include <private/qbarseries_p.h> | ||||
#include <private/barchartitem_p.h> | ||||
#include <private/chartdataset_p.h> | ||||
#include <private/charttheme_p.h> | ||||
#include <QtCharts/QValueAxis> | ||||
#include <QtCharts/QBarCategoryAxis> | ||||
|
r1167 | |||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r1167 | |||
/*! | ||||
|
r1594 | \class QBarSeries | ||
|
r2639 | \inmodule Qt Charts | ||
|
r2520 | \brief Series for creating bar chart. | ||
|
r1167 | |||
|
r1594 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | ||
as groups, where bars in same category are grouped next to each other. QBarSeries groups the data | ||||
|
r1208 | from sets to categories, which are defined by a QStringList. | ||
|
r1167 | |||
|
r1618 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. | ||
\image examples_barchart.png | ||||
|
r1167 | |||
|
r1586 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | ||
|
r1167 | */ | ||
|
r2639 | /*! | ||
\qmltype BarSeries | ||||
\instantiates QBarSeries | ||||
|
r2712 | \inqmlmodule QtCharts | ||
|
r2639 | |||
|
r2712 | \inherits AbstractBarSeries | ||
\brief Series for creating bar chart. | ||||
|
r1489 | |||
|
r2712 | The following QML shows how to create a simple grouped bar chart: | ||
\snippet qmlchart/qml/qmlchart/View6.qml 1 | ||||
\beginfloatleft | ||||
\image examples_qmlchart6.png | ||||
\endfloat | ||||
\clearfloat | ||||
|
r1489 | */ | ||
|
r1167 | |||
/*! | ||||
|
r1594 | Constructs empty QBarSeries. | ||
QBarSeries is QObject which is a child of a \a parent. | ||||
|
r1167 | */ | ||
|
r1594 | QBarSeries::QBarSeries(QObject *parent) | ||
: QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) | ||||
|
r1167 | { | ||
|
r2085 | |||
|
r1167 | } | ||
|
r1345 | /*! | ||
|
r2520 | Returns QAbstractSeries::SeriesTypeBar. | ||
|
r1345 | */ | ||
|
r1594 | QAbstractSeries::SeriesType QBarSeries::type() const | ||
|
r1167 | { | ||
|
r1594 | return QAbstractSeries::SeriesTypeBar; | ||
|
r1167 | } | ||
|
r1850 | /*! | ||
Destructor. Removes series from chart. | ||||
*/ | ||||
|
r1727 | QBarSeries::~QBarSeries() | ||
{ | ||||
|
r1725 | Q_D(QBarSeries); | ||
|
r2273 | if (d->m_chart) | ||
d->m_chart->removeSeries(this); | ||||
|
r1725 | } | ||
|
r1167 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r1594 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | ||
|
r1167 | { | ||
} | ||||
|
r2273 | void QBarSeriesPrivate::initializeDomain() | ||
|
r1167 | { | ||
|
r2273 | qreal minX(domain()->minX()); | ||
qreal minY(domain()->minY()); | ||||
qreal maxX(domain()->maxX()); | ||||
qreal maxY(domain()->maxY()); | ||||
|
r1167 | |||
|
r1321 | qreal x = categoryCount(); | ||
|
r1679 | minX = qMin(minX, - (qreal)0.5); | ||
|
r1781 | minY = qMin(minY, min()); | ||
|
r1679 | maxX = qMax(maxX, x - (qreal)0.5); | ||
|
r1781 | maxY = qMax(maxY, max()); | ||
|
r1167 | |||
|
r2273 | domain()->setRange(minX, maxX, minY, maxY); | ||
|
r1167 | } | ||
|
r2273 | void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | ||
|
r1167 | { | ||
|
r1594 | Q_Q(QBarSeries); | ||
|
r2273 | BarChartItem *bar = new BarChartItem(q,parent); | ||
m_item.reset(bar); | ||||
QAbstractSeriesPrivate::initializeGraphics(parent); | ||||
} | ||||
|
r1167 | |||
|
r1594 | #include "moc_qbarseries.cpp" | ||
|
r1167 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||
|
r1167 | |||