qbarseries.cpp
124 lines
| 3.4 KiB
| text/x-c
|
CppLexer
|
r1167 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r1594 | #include "qbarseries.h" | ||
#include "qbarseries_p.h" | ||||
|
r1674 | #include "barchartitem_p.h" | ||
|
r1167 | #include "chartdataset_p.h" | ||
#include "charttheme_p.h" | ||||
|
r1673 | #include "baranimation_p.h" | ||
|
r1805 | #include "qvalueaxis.h" | ||
|
r1810 | #include "qbarcategoryaxis.h" | ||
|
r1167 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
/*! | ||||
|
r1594 | \class QBarSeries | ||
\brief Series for creating bar chart | ||||
|
r1167 | \mainclass | ||
|
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 | */ | ||
|
r1489 | /*! | ||
|
r1594 | \qmlclass BarSeries QBarSeries | ||
|
r1590 | \inherits AbstractBarSeries | ||
|
r1489 | |||
The following QML shows how to create a simple grouped bar chart: | ||||
|
r1618 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | ||
|
r1489 | \beginfloatleft | ||
|
r1618 | \image demos_qmlchart6.png | ||
|
r1489 | \endfloat | ||
\clearfloat | ||||
*/ | ||||
|
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 | { | ||
} | ||||
|
r1345 | /*! | ||
|
r1674 | Returns QChartSeries::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); | ||
if(d->m_dataset) { | ||||
d->m_dataset->removeSeries(this); | ||||
} | ||||
} | ||||
|
r1167 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r1594 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | ||
|
r1167 | { | ||
} | ||||
|
r1594 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | ||
|
r1167 | { | ||
qreal minX(domain.minX()); | ||||
qreal minY(domain.minY()); | ||||
qreal maxX(domain.maxX()); | ||||
qreal maxY(domain.maxY()); | ||||
|
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 | |||
|
r1698 | domain.setRange(minX,maxX,minY,maxY); | ||
|
r1167 | } | ||
|
r1736 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | ||
|
r1167 | { | ||
|
r1594 | Q_Q(QBarSeries); | ||
|
r1167 | |||
|
r1674 | BarChartItem* bar = new BarChartItem(q,presenter); | ||
|
r1167 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | ||
|
r1673 | bar->setAnimation(new BarAnimation(bar)); | ||
|
r1167 | } | ||
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | ||||
return bar; | ||||
} | ||||
|
r1594 | #include "moc_qbarseries.cpp" | ||
|
r1167 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||