qhorizontalbarseries.cpp
90 lines
| 2.5 KiB
| text/x-c
|
CppLexer
|
r1672 | #include "qhorizontalbarseries.h" | ||
#include "qhorizontalbarseries_p.h" | ||||
|
r1681 | #include "horizontalbarchartitem_p.h" | ||
#include "horizontalbaranimation_p.h" | ||||
|
r1695 | #include "qbarcategoriesaxis.h" | ||
|
r1681 | |||
#include "chartdataset_p.h" | ||||
#include "charttheme_p.h" | ||||
|
r1672 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : | ||||
|
r1681 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) | ||
|
r1672 | { | ||
} | ||||
QAbstractSeries::SeriesType QHorizontalBarSeries::type() const | ||||
{ | ||||
return QAbstractSeries::SeriesTypeHorizontalBar; | ||||
} | ||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) | ||||
{ | ||||
} | ||||
void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) | ||||
{ | ||||
qreal minX(domain.minX()); | ||||
qreal minY(domain.minY()); | ||||
qreal maxX(domain.maxX()); | ||||
qreal maxY(domain.maxY()); | ||||
int tickXCount(domain.tickXCount()); | ||||
int tickYCount(domain.tickYCount()); | ||||
|
r1681 | qreal y = categoryCount(); | ||
qreal x = max(); | ||||
minX = qMin(minX, x); | ||||
|
r1688 | minY = qMin(minY, - (qreal)0.5); | ||
|
r1681 | maxX = qMax(maxX, x); | ||
|
r1688 | maxY = qMax(maxY, y - (qreal)0.5); | ||
|
r1681 | tickYCount = y+1; | ||
|
r1672 | |||
domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | ||||
} | ||||
Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | ||||
{ | ||||
Q_Q(QHorizontalBarSeries); | ||||
|
r1681 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); | ||
|
r1672 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | ||
|
r1681 | bar->setAnimator(presenter->animator()); | ||
bar->setAnimation(new HorizontalBarAnimation(bar)); | ||||
|
r1672 | } | ||
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | ||||
return bar; | ||||
|
r1681 | } | ||
|
r1695 | void QHorizontalBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | ||
|
r1681 | { | ||
|
r1695 | |||
if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Vertical) | ||||
{ | ||||
QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis); | ||||
Q_ASSERT(cataxis); | ||||
QStringList categories; | ||||
for (int i(1); i < categoryCount()+1; i++) | ||||
categories << QString::number(i); | ||||
cataxis->append(categories); | ||||
} | ||||
|
r1681 | } | ||
|
r1695 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | ||
|
r1681 | { | ||
|
r1695 | if(orientation==Qt::Vertical) | ||
return QAbstractAxis::AxisTypeCategories; | ||||
else | ||||
return QAbstractAxis::AxisTypeValues; | ||||
|
r1672 | } | ||
#include "moc_qhorizontalbarseries.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||