##// END OF EJS Templates
horizontal barchart & example
sauimone -
r1681:77439ba76361
parent child
Show More
@@ -0,0 +1,6
1 !include( ../examples.pri ) {
2 error( "Couldn't find the examples.pri file!" )
3 }
4
5 TARGET = horizontalbarchart
6 SOURCES += main.cpp
@@ -0,0 +1,94
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QApplication>
22 #include <QMainWindow>
23 #include <QChartView>
24 #include <QBarSeries>
25 #include <QBarSet>
26 #include <QLegend>
27 #include <QBarCategoriesAxis>
28 #include <QHorizontalBarSeries>
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
32 int main(int argc, char *argv[])
33 {
34 QApplication a(argc, argv);
35
36 //![1]
37 QBarSet *set0 = new QBarSet("Jane");
38 QBarSet *set1 = new QBarSet("John");
39 QBarSet *set2 = new QBarSet("Axel");
40 QBarSet *set3 = new QBarSet("Mary");
41 QBarSet *set4 = new QBarSet("Samantha");
42
43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
48 //![1]
49
50 //![2]
51 QHorizontalBarSeries *series = new QHorizontalBarSeries();
52 series->append(set0);
53 series->append(set1);
54 series->append(set2);
55 series->append(set3);
56 series->append(set4);
57
58 //![2]
59
60 //![3]
61 QChart* chart = new QChart();
62 chart->addSeries(series);
63 chart->setTitle("Simple horizontal barchart example");
64 chart->createDefaultAxes();
65 //![3]
66
67 //![4]
68 QStringList categories;
69 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
70 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
71 axis->append(categories);
72 chart->createDefaultAxes();
73 chart->setAxisY(axis,series);
74 //![4]
75
76 //![5]
77 chart->legend()->setVisible(true);
78 chart->legend()->setAlignment(Qt::AlignBottom);
79 //![5]
80
81 //![6]
82 QChartView* chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
84 //![6]
85
86 //![7]
87 QMainWindow window;
88 window.setCentralWidget(chartView);
89 window.resize(400, 300);
90 window.show();
91 //![7]
92
93 return a.exec();
94 }
@@ -0,0 +1,51
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "horizontalbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) :
30 AbstractBarAnimation(item)
31 {
32 }
33
34 HorizontalBarAnimation::~HorizontalBarAnimation()
35 {
36
37 }
38
39
40 QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
42 // TODO:
43 Q_UNUSED(from);
44 Q_UNUSED(to);
45 Q_UNUSED(progress);
46 return to;
47 }
48
49 #include "moc_horizontalbaranimation_p.cpp"
50
51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,52
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef HORIZONTALBARANIMATION_P_H
31 #define HORIZONTALBARANIMATION_P_H
32
33 #include "abstractbaranimation_p.h"
34 #include "chartanimation_p.h"
35 #include "abstractbarchartitem_p.h"
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
39 class HorizontalBarAnimation : public AbstractBarAnimation
40 {
41 Q_OBJECT
42 public:
43 explicit HorizontalBarAnimation(AbstractBarChartItem *item);
44 ~HorizontalBarAnimation();
45
46 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
47
48 };
49
50 QTCOMMERCIALCHART_END_NAMESPACE
51
52 #endif // HORIZONTALBARANIMATION_P_H
@@ -23,4 +23,5 SUBDIRS += \
23 23 legend \
24 24 barmodelmapper \
25 25 qmlpiechart \
26 lineandbar
26 lineandbar \
27 horizontalbarchart
@@ -11,7 +11,8 SOURCES += \
11 11 $$PWD/baranimation.cpp \
12 12 $$PWD/stackedbaranimation.cpp \
13 13 $$PWD/percentbaranimation.cpp \
14 $$PWD/abstractbaranimation.cpp
14 $$PWD/abstractbaranimation.cpp \
15 $$PWD/horizontalbaranimation.cpp
15 16
16 17
17 18 PRIVATE_HEADERS += \
@@ -25,4 +26,5 PRIVATE_HEADERS += \
25 26 $$PWD/baranimation_p.h \
26 27 $$PWD/stackedbaranimation_p.h \
27 28 $$PWD/percentbaranimation_p.h \
28 $$PWD/abstractbaranimation_p.h
29 $$PWD/abstractbaranimation_p.h \
30 $$PWD/horizontalbaranimation_p.h
@@ -56,10 +56,10 QVector<QRectF> BarChartItem::calculateLayout()
56 56 for (int set = 0; set < setCount; set++) {
57 57 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58 58
59 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left();
59 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left();
60 60 xPos -= setCount*barWidth/2;
61 61 xPos += set*barWidth;
62 qreal barHeight = barSet->at(category).y() * scaleY;
62 qreal barHeight = barSet->value(category) * scaleY;
63 63 Bar* bar = m_bars.at(itemIndex);
64 64
65 65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
@@ -74,8 +74,8 QVector<QRectF> BarChartItem::calculateLayout()
74 74
75 75 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
76 76
77 if (!qFuzzyIsNull(barSet->at(category).y())) {
78 label->setText(QString::number(barSet->at(category).y()));
77 if (!qFuzzyIsNull(barSet->value(category))) {
78 label->setText(QString::number(barSet->value(category)));
79 79 } else {
80 80 label->setText(QString(""));
81 81 }
@@ -1,16 +1,93
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 21 #include "horizontalbarchartitem_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset_p.h"
24 #include "bar_p.h"
25 #include <QDebug>
2 26
3 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 28
5 HorizontalBarChartitem::HorizontalBarChartitem(QAbstractBarSeries *series, ChartPresenter *presenter) :
29 HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
6 30 AbstractBarChartItem(series, presenter)
7 31 {
8 32 }
9 33
10 QVector<QRectF> HorizontalBarChartitem::calculateLayout()
34 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
11 35 {
12 // TODO:
13 36 QVector<QRectF> layout;
37
38 // Use temporary qreals for accuracy
39 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal setCount = m_series->count();
41 bool barsVisible = m_series->isVisible();
42
43 // Domain:
44 qreal width = geometry().width();
45 qreal height = geometry().height();
46 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
50 qreal barHeight = (scaleY / setCount) * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
51
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
54 qreal xPos = scaleX * m_domainMinX + geometry().left();
55 for (int set = 0; set < setCount; set++) {
56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
58 qreal yPos = m_rect.bottom() -(barSet->pos(category) + m_domainMinY + 1) * scaleY;
59 yPos += setCount*barHeight/2;
60 yPos -= set*barHeight;
61
62 qreal barWidth = barSet->value(category) * scaleX;
63 Bar* bar = m_bars.at(itemIndex);
64
65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
66 layout.append(rect);
67 bar->setPen(barSet->m_pen);
68 bar->setBrush(barSet->m_brush);
69 if (qFuzzyIsNull(barHeight)) {
70 bar->setVisible(false);
71 } else {
72 bar->setVisible(barsVisible);
73 }
74
75 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
76
77 if (!qFuzzyIsNull(barSet->value(category))) {
78 label->setText(QString::number(barSet->value(category)));
79 } else {
80 label->setText(QString(""));
81 }
82
83 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
84 ,yPos - barHeight/2 - label->boundingRect().height()/2);
85 label->setFont(barSet->m_labelFont);
86 label->setBrush(barSet->m_labelBrush);
87
88 itemIndex++;
89 }
90 }
14 91 return layout;
15 92 }
16 93
@@ -1,3 +1,32
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
1 30 #ifndef HORIZONTALBARCHARTITEM_H
2 31 #define HORIZONTALBARCHARTITEM_H
3 32
@@ -7,12 +36,11
7 36
8 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 38
10
11 class HorizontalBarChartitem : public AbstractBarChartItem
39 class HorizontalBarChartItem : public AbstractBarChartItem
12 40 {
13 41 Q_OBJECT
14 42 public:
15 HorizontalBarChartitem(QAbstractBarSeries *series, ChartPresenter *presenter);
43 HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
16 44
17 45 private:
18 46 virtual QVector<QRectF> calculateLayout();
@@ -58,9 +58,9 QVector<QRectF> PercentBarChartItem::calculateLayout()
58 58 for (int set=0; set < setCount; set++) {
59 59 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
60 60
61 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
61 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
62 62
63 qreal barHeight = barSet->at(category).y() * percentage * scaleY;
63 qreal barHeight = barSet->value(category) * percentage * scaleY;
64 64 Bar* bar = m_bars.at(itemIndex);
65 65 bar->setPen(barSet->m_pen);
66 66 bar->setBrush(barSet->m_brush);
@@ -722,12 +722,12 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
722 722
723 723 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
724 724 {
725 return QAbstractAxis::AxisTypeCategories;
725 return QAbstractAxis::AxisTypeNoAxis;
726 726 }
727 727
728 728 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
729 729 {
730 return QAbstractAxis::AxisTypeValues;
730 return QAbstractAxis::AxisTypeNoAxis;
731 731 }
732 732
733 733 #include "moc_qabstractbarseries.cpp"
@@ -75,6 +75,7 protected:
75 75 friend class PercentBarChartItem;
76 76 friend class StackedBarChartItem;
77 77 friend class BarChartItem;
78 friend class HorizontalBarChartItem;
78 79 };
79 80
80 81 QTCOMMERCIALCHART_END_NAMESPACE
@@ -113,6 +113,16 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
113 113 return bar;
114 114 }
115 115
116 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisXType() const
117 {
118 return QAbstractAxis::AxisTypeCategories;
119 }
120
121 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisYType() const
122 {
123 return QAbstractAxis::AxisTypeValues;
124 }
125
116 126 #include "moc_qbarseries.cpp"
117 127
118 128 QTCOMMERCIALCHART_END_NAMESPACE
@@ -21,7 +21,6
21 21 #ifndef QBARSERIES_H
22 22 #define QBARSERIES_H
23 23
24 #include <QStringList>
25 24 #include <qabstractbarseries.h>
26 25
27 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -43,6 +43,9 public:
43 43 Chart* createGraphics(ChartPresenter* presenter);
44 44 void scaleDomain(Domain& domain);
45 45
46 QAbstractAxis::AxisType defaultAxisXType() const;
47 QAbstractAxis::AxisType defaultAxisYType() const;
48
46 49 private:
47 50 Q_DECLARE_PUBLIC(QBarSeries)
48 51 };
@@ -611,15 +611,23 void QBarSetPrivate::replace(const int index, const QPointF value)
611 611 emit updatedBars();
612 612 }
613 613
614 QPointF QBarSetPrivate::at(const int index)
614 qreal QBarSetPrivate::pos(const int index)
615 615 {
616 if (index < 0 || index >= m_values.count()) {
617 return QPointF(0,0);
618 }
616 if (index < 0 || index >= m_values.count()) {
617 return 0;
618 }
619 619
620 return m_values.at(index);
620 return m_values.at(index).x();
621 621 }
622 622
623 qreal QBarSetPrivate::value(const int index)
624 {
625 if (index < 0 || index >= m_values.count()) {
626 return 0;
627 }
628
629 return m_values.at(index).y();
630 }
623 631
624 632 #include "moc_qbarset.cpp"
625 633 #include "moc_qbarset_p.cpp"
@@ -108,6 +108,7 private:
108 108 friend class StackedBarChartItem;
109 109 friend class PercentBarChartItem;
110 110 friend class BarChartItem;
111 friend class HorizontalBarChartItem;
111 112 };
112 113
113 114 QTCOMMERCIALCHART_END_NAMESPACE
@@ -57,7 +57,8 public:
57 57 void replace(const int index, const qreal value);
58 58 void replace(const int index, const QPointF value);
59 59
60 QPointF at(const int index);
60 qreal pos(const int index);
61 qreal value(const int index);
61 62
62 63 Q_SIGNALS:
63 64 void restructuredBars();
@@ -1,9 +1,16
1 1 #include "qhorizontalbarseries.h"
2 2 #include "qhorizontalbarseries_p.h"
3 #include "horizontalbarchartitem_p.h"
4 #include "horizontalbaranimation_p.h"
5
6 #include "chartdataset_p.h"
7 #include "charttheme_p.h"
8
9
3 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 11
5 12 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
6 QAbstractBarSeries(parent)
13 QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
7 14 {
8 15 }
9 16
@@ -24,8 +31,6 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q
24 31 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
25 32 {
26 33 // TODO:
27 Q_UNUSED(domain);
28 /*
29 34 qreal minX(domain.minX());
30 35 qreal minY(domain.minY());
31 36 qreal maxX(domain.maxX());
@@ -33,34 +38,39 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
33 38 int tickXCount(domain.tickXCount());
34 39 int tickYCount(domain.tickYCount());
35 40
36 qreal x = categoryCount();
37 qreal y = max();
38 minX = qMin(minX, -0.5);
39 minY = qMin(minY, y);
40 maxX = qMax(maxX, x - 0.5);
41 maxY = qMax(maxY, y);
42 tickXCount = x+1;
41 qreal y = categoryCount();
42 qreal x = max();
43 minX = qMin(minX, x);
44 minY = qMin(minY, -0.5);
45 maxX = qMax(maxX, x);
46 maxY = qMax(maxY, y -0.5);
47 tickYCount = y+1;
43 48
44 49 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
45 */
46 50 }
47 51
48 52
49 53 Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
50 54 {
51 // TODO:
52 Q_UNUSED(presenter);
53 return 0;
54 /*
55 55 Q_Q(QHorizontalBarSeries);
56 56
57 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
57 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
58 58 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
59 presenter->animator()->addAnimation(bar);
59 bar->setAnimator(presenter->animator());
60 bar->setAnimation(new HorizontalBarAnimation(bar));
60 61 }
61 62 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
62 63 return bar;
63 */
64 }
65
66 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisXType() const
67 {
68 return QAbstractAxis::AxisTypeValues;
69 }
70
71 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisYType() const
72 {
73 return QAbstractAxis::AxisTypeValues;
64 74 }
65 75
66 76
@@ -1,3 +1,23
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 21 #ifndef QHORIZONTALBARSERIES_H
2 22 #define QHORIZONTALBARSERIES_H
3 23
@@ -41,6 +41,8 public:
41 41 QHorizontalBarSeriesPrivate(QHorizontalBarSeries* q);
42 42 Chart* createGraphics(ChartPresenter* presenter);
43 43 void scaleDomain(Domain& domain);
44 QAbstractAxis::AxisType defaultAxisXType() const;
45 QAbstractAxis::AxisType defaultAxisYType() const;
44 46
45 47 private:
46 48 Q_DECLARE_PUBLIC(QHorizontalBarSeries)
@@ -112,6 +112,16 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
112 112 return bar;
113 113 }
114 114
115 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisXType() const
116 {
117 return QAbstractAxis::AxisTypeCategories;
118 }
119
120 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisYType() const
121 {
122 return QAbstractAxis::AxisTypeValues;
123 }
124
115 125 #include "moc_qpercentbarseries.cpp"
116 126
117 127 QTCOMMERCIALCHART_END_NAMESPACE
@@ -42,6 +42,9 public:
42 42 QPercentBarSeriesPrivate(QPercentBarSeries* q);
43 43 void scaleDomain(Domain& domain);
44 44 Chart* createGraphics(ChartPresenter* presenter);
45 QAbstractAxis::AxisType defaultAxisXType() const;
46 QAbstractAxis::AxisType defaultAxisYType() const;
47
45 48 private:
46 49 Q_DECLARE_PUBLIC(QPercentBarSeries)
47 50 };
@@ -114,6 +114,16 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
114 114 return bar;
115 115 }
116 116
117 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisXType() const
118 {
119 return QAbstractAxis::AxisTypeCategories;
120 }
121
122 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisYType() const
123 {
124 return QAbstractAxis::AxisTypeValues;
125 }
126
117 127
118 128 #include "moc_qstackedbarseries.cpp"
119 129
@@ -42,6 +42,8 public:
42 42 QStackedBarSeriesPrivate(QStackedBarSeries* q);
43 43 Chart* createGraphics(ChartPresenter* presenter);
44 44 void scaleDomain(Domain& domain);
45 QAbstractAxis::AxisType defaultAxisXType() const;
46 QAbstractAxis::AxisType defaultAxisYType() const;
45 47
46 48 private:
47 49 Q_DECLARE_PUBLIC(QStackedBarSeries)
@@ -55,9 +55,9 QVector<QRectF> StackedBarChartItem::calculateLayout()
55 55 for (int set=0; set < setCount; set++) {
56 56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57 57
58 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
58 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
59 59
60 qreal barHeight = barSet->at(category).y() * scaleY;
60 qreal barHeight = barSet->value(category) * scaleY;
61 61 Bar* bar = m_bars.at(itemIndex);
62 62 bar->setPen(barSet->m_pen);
63 63 bar->setBrush(barSet->m_brush);
@@ -72,8 +72,8 QVector<QRectF> StackedBarChartItem::calculateLayout()
72 72
73 73 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
74 74
75 if (!qFuzzyIsNull(barSet->at(category).y())) {
76 label->setText(QString::number(barSet->at(category).y()));
75 if (!qFuzzyIsNull(barSet->value(category))) {
76 label->setText(QString::number(barSet->value(category)));
77 77 } else {
78 78 label->setText(QString(""));
79 79 }
General Comments 0
You need to be logged in to leave comments. Login now