From daa1eadf0e06d1635e2bd8dfb1ebb8faa83c7702 2012-07-12 09:58:03 From: sauimone Date: 2012-07-12 09:58:03 Subject: [PATCH] horizontal percent barchart & example --- diff --git a/examples/examples.pro b/examples/examples.pro index b26ca7e..0a1e17a 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -25,4 +25,5 @@ SUBDIRS += \ qmlpiechart \ lineandbar \ horizontalbarchart \ - horizontalstackedbarchart + horizontalstackedbarchart \ + horizontalpercentbarchart diff --git a/examples/horizontalpercentbarchart/horizontalpercentbarchart.pro b/examples/horizontalpercentbarchart/horizontalpercentbarchart.pro new file mode 100644 index 0000000..d616869 --- /dev/null +++ b/examples/horizontalpercentbarchart/horizontalpercentbarchart.pro @@ -0,0 +1,6 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +TARGET = horizontalpercentbarchart +SOURCES += main.cpp diff --git a/examples/horizontalpercentbarchart/main.cpp b/examples/horizontalpercentbarchart/main.cpp new file mode 100644 index 0000000..a2e65d0 --- /dev/null +++ b/examples/horizontalpercentbarchart/main.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + +//![1] + QBarSet *set0 = new QBarSet("Jane"); + QBarSet *set1 = new QBarSet("John"); + QBarSet *set2 = new QBarSet("Axel"); + QBarSet *set3 = new QBarSet("Mary"); + QBarSet *set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; +//![1] + +//![2] + QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(); + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + +//![2] + +//![3] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple horizontal stacked barchart example"); + chart->createDefaultAxes(); + chart->setAnimationOptions(QChart::SeriesAnimations); +//![3] + +//![4] + QStringList categories; + categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; + QBarCategoriesAxis* axis = new QBarCategoriesAxis(); + axis->append(categories); + chart->createDefaultAxes(); + chart->setAxisY(axis,series); +//![4] + +//![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); +//![5] + +//![6] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![6] + +//![7] + QMainWindow window; + window.setCentralWidget(chartView); + window.resize(400, 300); + window.show(); +//![7] + + return a.exec(); +} diff --git a/src/animations/animations.pri b/src/animations/animations.pri index 7b7061a..263aa04 100644 --- a/src/animations/animations.pri +++ b/src/animations/animations.pri @@ -13,8 +13,8 @@ SOURCES += \ $$PWD/percentbaranimation.cpp \ $$PWD/abstractbaranimation.cpp \ $$PWD/horizontalbaranimation.cpp \ - $$PWD/horizontalstackedbaranimation.cpp - + $$PWD/horizontalstackedbaranimation.cpp \ + $$PWD/horizontalpercentbaranimation.cpp PRIVATE_HEADERS += \ $$PWD/axisanimation_p.h \ @@ -29,4 +29,5 @@ PRIVATE_HEADERS += \ $$PWD/percentbaranimation_p.h \ $$PWD/abstractbaranimation_p.h \ $$PWD/horizontalbaranimation_p.h \ - $$PWD/horizontalstackedbaranimation_p.h + $$PWD/horizontalstackedbaranimation_p.h \ + $$PWD/horizontalpercentbaranimation_p.h diff --git a/src/animations/horizontalpercentbaranimation.cpp b/src/animations/horizontalpercentbaranimation.cpp new file mode 100644 index 0000000..fffcc8c --- /dev/null +++ b/src/animations/horizontalpercentbaranimation.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "horizontalpercentbaranimation_p.h" +#include "abstractbarchartitem_p.h" +#include + +Q_DECLARE_METATYPE(QVector) + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +HorizontalPercentBarAnimation::HorizontalPercentBarAnimation(AbstractBarChartItem *item) : + AbstractBarAnimation(item) +{ +} + +HorizontalPercentBarAnimation::~HorizontalPercentBarAnimation() +{ + +} + + +QVariant HorizontalPercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const +{ + QVector startVector = qVariantValue >(from); + QVector endVector = qVariantValue >(to); + QVector result; + + Q_ASSERT(startVector.count() == endVector.count()); + + qreal xAxis = m_item->geometry().x(); + + for(int i = 0; i < startVector.count(); i++) { + qreal h = endVector[i].height(); + qreal w = endVector[i].width() * progress; + qreal x = xAxis + ((endVector[i].left() - xAxis) * progress); + qreal y = endVector[i].top(); + + QRectF value(x,y,w,h); + result << value; + } + return qVariantFromValue(result); +} + +#include "moc_horizontalpercentbaranimation_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/horizontalpercentbaranimation_p.h b/src/animations/horizontalpercentbaranimation_p.h new file mode 100644 index 0000000..82852e6 --- /dev/null +++ b/src/animations/horizontalpercentbaranimation_p.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef HORIZONTALPERCENTBARANIMATION_P_H +#define HORIZONTALPERCENTBARANIMATION_P_H + +#include "abstractbaranimation_p.h" +#include "chartanimation_p.h" +#include "abstractbarchartitem_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class HorizontalPercentBarAnimation : public AbstractBarAnimation +{ + Q_OBJECT +public: + explicit HorizontalPercentBarAnimation(AbstractBarChartItem *item); + ~HorizontalPercentBarAnimation(); + + virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // HORIZONTALPERCENTBARANIMATION_P_H diff --git a/src/animations/horizontalstackedbaranimation.cpp b/src/animations/horizontalstackedbaranimation.cpp index a3b5a13..66635ee 100644 --- a/src/animations/horizontalstackedbaranimation.cpp +++ b/src/animations/horizontalstackedbaranimation.cpp @@ -49,7 +49,7 @@ QVariant HorizontalStackedBarAnimation::interpolated(const QVariant &from, const for(int i = 0; i < startVector.count(); i++) { qreal h = endVector[i].height(); - qreal w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress); + qreal w = endVector[i].width() * progress; qreal x = xAxis + ((endVector[i].left() - xAxis) * progress); qreal y = endVector[i].top(); diff --git a/src/barchart/barchart.pri b/src/barchart/barchart.pri index 9c3e7d0..9f9ae39 100644 --- a/src/barchart/barchart.pri +++ b/src/barchart/barchart.pri @@ -18,7 +18,9 @@ SOURCES += \ $$PWD/qhorizontalbarseries.cpp \ $$PWD/horizontalbarchartitem.cpp \ $$PWD/qhorizontalstackedbarseries.cpp \ - $$PWD/horizontalstackedbarchartitem.cpp + $$PWD/horizontalstackedbarchartitem.cpp \ + $$PWD/qhorizontalpercentbarseries.cpp \ + $$PWD/horizontalpercentbarchartitem.cpp PRIVATE_HEADERS += \ $$PWD/bar_p.h \ @@ -35,7 +37,9 @@ PRIVATE_HEADERS += \ $$PWD/qhorizontalbarseries_p.h \ $$PWD/horizontalbarchartitem_p.h \ $$PWD/qhorizontalstackedbarseries_p.h \ - $$PWD/horizontalstackedbarchartitem_p.h + $$PWD/horizontalstackedbarchartitem_p.h \ + $$PWD/qhorizontalpercentbarseries_p.h \ + $$PWD/horizontalpercentbarchartitem_p.h PUBLIC_HEADERS += \ $$PWD/qabstractbarseries.h \ @@ -47,4 +51,5 @@ PUBLIC_HEADERS += \ $$PWD/qvbarmodelmapper.h \ $$PWD/qhbarmodelmapper.h \ $$PWD/qhorizontalbarseries.h \ - $$PWD/qhorizontalstackedbarseries.h + $$PWD/qhorizontalstackedbarseries.h \ + $$PWD/qhorizontalpercentbarseries.h diff --git a/src/barchart/horizontalpercentbarchartitem.cpp b/src/barchart/horizontalpercentbarchartitem.cpp new file mode 100644 index 0000000..96863a0 --- /dev/null +++ b/src/barchart/horizontalpercentbarchartitem.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "horizontalpercentbarchartitem_p.h" +#include "qabstractbarseries_p.h" +#include "qbarset_p.h" +#include "bar_p.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : + AbstractBarChartItem(series, presenter) +{ +} + +QVector HorizontalPercentBarChartItem::calculateLayout() +{ + QVector layout; + + // Use temporary qreals for accuracy + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + bool barsVisible = m_series->isVisible(); + + // Domain: + qreal width = geometry().width(); + qreal height = geometry().height(); + qreal rangeY = m_domainMaxY - m_domainMinY; + qreal rangeX = m_domainMaxX - m_domainMinX; + qreal scaleY = (height / rangeY); + qreal scaleX = (width / rangeX); + qreal barHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect. + + int itemIndex(0); + for (int category = 0; category < categoryCount; category++) { + qreal colSum = m_series->d_func()->categorySum(category); + qreal percentage = (100 / colSum); + qreal xPos = rangeX * m_domainMinX + geometry().left(); + for (int set = 0; set < setCount; set++) { + QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); + + qreal yPos = -(barSet->pos(category) - m_domainMinY -0.5) * scaleY + m_rect.bottom() - barHeight/2; + + qreal barWidth = barSet->value(category) * percentage * scaleX; + Bar* bar = m_bars.at(itemIndex); + + QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); + layout.append(rect); + bar->setPen(barSet->m_pen); + bar->setBrush(barSet->m_brush); + if (qFuzzyIsNull(barHeight)) { + bar->setVisible(false); + } else { + bar->setVisible(barsVisible); + } + + QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); + + if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { + int p = m_series->d_func()->percentageAt(set,category) * 100; + QString vString(QString::number(p)); + vString.truncate(3); + vString.append("%"); + label->setText(vString); + } else { + label->setText(QString("")); + } + + label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) + ,yPos - barHeight/2 - label->boundingRect().height()/2); + label->setFont(barSet->m_labelFont); + label->setBrush(barSet->m_labelBrush); + + itemIndex++; + xPos += barWidth; + } + } + return layout; +} + +#include "moc_horizontalpercentbarchartitem_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE + diff --git a/src/barchart/horizontalpercentbarchartitem_p.h b/src/barchart/horizontalpercentbarchartitem_p.h new file mode 100644 index 0000000..aa7fc29 --- /dev/null +++ b/src/barchart/horizontalpercentbarchartitem_p.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef HORIZONTALPERCENTBARCHARTITEM_P_H +#define HORIZONTALPERCENTBARCHARTITEM_P_H + +#include "abstractbarchartitem_p.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class HorizontalPercentBarChartItem : public AbstractBarChartItem +{ + Q_OBJECT +public: + HorizontalPercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); + +private: + virtual QVector calculateLayout(); +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // HORIZONTALPERCENTBARCHARTITEM_P_H diff --git a/src/barchart/qabstractbarseries.h b/src/barchart/qabstractbarseries.h index 622ba40..2cabe49 100644 --- a/src/barchart/qabstractbarseries.h +++ b/src/barchart/qabstractbarseries.h @@ -77,6 +77,7 @@ protected: friend class BarChartItem; friend class HorizontalBarChartItem; friend class HorizontalStackedBarChartItem; + friend class HorizontalPercentBarChartItem; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 22df927..1ef6032 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -110,6 +110,7 @@ private: friend class BarChartItem; friend class HorizontalBarChartItem; friend class HorizontalStackedBarChartItem; + friend class HorizontalPercentBarChartItem; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qhorizontalbarseries.cpp b/src/barchart/qhorizontalbarseries.cpp index 48de46d..b69d2f7 100644 --- a/src/barchart/qhorizontalbarseries.cpp +++ b/src/barchart/qhorizontalbarseries.cpp @@ -40,9 +40,9 @@ void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) qreal y = categoryCount(); qreal x = max(); minX = qMin(minX, x); - minY = qMin(minY, -0.5); + minY = qMin(minY, - (qreal)0.5); maxX = qMax(maxX, x); - maxY = qMax(maxY, y -0.5); + maxY = qMax(maxY, y - (qreal)0.5); tickYCount = y+1; domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); diff --git a/src/barchart/qhorizontalpercentbarseries.cpp b/src/barchart/qhorizontalpercentbarseries.cpp new file mode 100644 index 0000000..244ce02 --- /dev/null +++ b/src/barchart/qhorizontalpercentbarseries.cpp @@ -0,0 +1,75 @@ +#include "qhorizontalpercentbarseries.h" +#include "qhorizontalpercentbarseries_p.h" +#include "horizontalpercentbarchartitem_p.h" +#include "horizontalpercentbaranimation_p.h" + +#include "chartdataset_p.h" +#include "charttheme_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) : + QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent) +{ +} + +QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const +{ + return QAbstractSeries::SeriesTypeHorizontalPercentBar; +} + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) +{ + +} + +void QHorizontalPercentBarSeriesPrivate::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()); + + qreal y = categoryCount(); + minX = 0; + maxX = 100; + minY = qMin(minY, - (qreal)0.5); + maxY = qMax(maxY, y - (qreal)0.5); + tickYCount = y+1; + + domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); +} + +Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) +{ + Q_Q(QHorizontalPercentBarSeries); + + HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter); + if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { + bar->setAnimator(presenter->animator()); + bar->setAnimation(new HorizontalPercentBarAnimation(bar)); + } + presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); + return bar; +} + +QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisXType() const +{ + return QAbstractAxis::AxisTypeValues; +} + +QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisYType() const +{ + return QAbstractAxis::AxisTypeCategories; +} + + +#include "moc_qhorizontalpercentbarseries.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qhorizontalpercentbarseries.h b/src/barchart/qhorizontalpercentbarseries.h new file mode 100644 index 0000000..eaa1ebd --- /dev/null +++ b/src/barchart/qhorizontalpercentbarseries.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QHORIZONTALPERCENTBARSERIES_H +#define QHORIZONTALPERCENTBARSERIES_H + +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QHorizontalPercentBarSeriesPrivate; + +class QTCOMMERCIALCHART_EXPORT QHorizontalPercentBarSeries : public QAbstractBarSeries +{ + Q_OBJECT +public: + explicit QHorizontalPercentBarSeries(QObject *parent = 0); + QAbstractSeries::SeriesType type() const; + +private: + Q_DECLARE_PRIVATE(QHorizontalPercentBarSeries) + Q_DISABLE_COPY(QHorizontalPercentBarSeries) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QHORIZONTALPERCENTBARSERIES_H diff --git a/src/barchart/qhorizontalpercentbarseries_p.h b/src/barchart/qhorizontalpercentbarseries_p.h new file mode 100644 index 0000000..b52dc4a --- /dev/null +++ b/src/barchart/qhorizontalpercentbarseries_p.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef QHORIZONTALPERCENTBARSERIES_P_H +#define QHORIZONTALPERCENTBARSERIES_P_H + +#include "qabstractbarseries_p.h" +#include "domain_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate +{ +public: + QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries* q); + Chart* createGraphics(ChartPresenter* presenter); + void scaleDomain(Domain& domain); + QAbstractAxis::AxisType defaultAxisXType() const; + QAbstractAxis::AxisType defaultAxisYType() const; + +private: + Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QHORIZONTALPERCENTBARSERIES_P_H diff --git a/src/barchart/qhorizontalstackedbarseries.cpp b/src/barchart/qhorizontalstackedbarseries.cpp index f0a7205..aa2521c 100644 --- a/src/barchart/qhorizontalstackedbarseries.cpp +++ b/src/barchart/qhorizontalstackedbarseries.cpp @@ -39,9 +39,9 @@ void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain& domain) qreal y = categoryCount(); qreal x = maxCategorySum(); minX = qMin(minX, x); - minY = qMin(minY, -0.5); + minY = qMin(minY, - (qreal)0.5); maxX = qMax(maxX, x); - maxY = qMax(maxY, y -0.5); + maxY = qMax(maxY, y - (qreal)0.5); tickYCount = y+1; domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);