##// END OF EJS Templates
category fix to grouped, percent and stacked bar series
sauimone -
r1209:dcfa23e56a97
parent child
Show More
@@ -1,108 +1,109
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qgroupedbarseries.h"
21 #include "qgroupedbarseries.h"
22 #include "qgroupedbarseries_p.h"
22 #include "qgroupedbarseries_p.h"
23 #include "groupedbarchartitem_p.h"
23 #include "groupedbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QGroupedBarSeries
31 \class QGroupedBarSeries
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
36 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
37 from sets to categories, which are defined by a QStringList.
37 from sets to categories, which are defined by a QStringList.
38
38
39 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
39 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
40 \image examples_groupedbarchart.png
40 \image examples_groupedbarchart.png
41
41
42 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
42 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
43 */
43 */
44
44
45 /*!
45 /*!
46 \fn virtual QSeriesType QGroupedBarSeries::type() const
46 \fn virtual QSeriesType QGroupedBarSeries::type() const
47 \brief Returns type of series.
47 \brief Returns type of series.
48 \sa QAbstractSeries, QSeriesType
48 \sa QAbstractSeries, QSeriesType
49 */
49 */
50
50
51 /*!
51 /*!
52 Constructs empty QGroupedBarSeries.
52 Constructs empty QGroupedBarSeries.
53 QGroupedBarSeries is QObject which is a child of a \a parent.
53 QGroupedBarSeries is QObject which is a child of a \a parent.
54 */
54 */
55 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
55 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
56 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
56 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
57 {
57 {
58 }
58 }
59
59
60 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
60 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
61 {
61 {
62 return QAbstractSeries::SeriesTypeGroupedBar;
62 return QAbstractSeries::SeriesTypeGroupedBar;
63 }
63 }
64
64
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66
66
67 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(/*QBarCategories categories,*/ QGroupedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q)
67 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q)
68 {
68 {
69
69
70 }
70 }
71
71
72 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
72 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
73 {
73 {
74 Q_Q(QGroupedBarSeries);
74 qreal minX(domain.minX());
75 qreal minX(domain.minX());
75 qreal minY(domain.minY());
76 qreal minY(domain.minY());
76 qreal maxX(domain.maxX());
77 qreal maxX(domain.maxX());
77 qreal maxY(domain.maxY());
78 qreal maxY(domain.maxY());
78 int tickXCount(domain.tickXCount());
79 int tickXCount(domain.tickXCount());
79 int tickYCount(domain.tickYCount());
80 int tickYCount(domain.tickYCount());
80
81
81 qreal x = m_categories.count();
82 qreal x = q->categoryCount();
82 qreal y = maxCategorySum();
83 qreal y = maxCategorySum();
83 minX = qMin(minX, x);
84 minX = qMin(minX, x);
84 minY = qMin(minY, y);
85 minY = qMin(minY, y);
85 maxX = qMax(maxX, x);
86 maxX = qMax(maxX, x);
86 maxY = qMax(maxY, y);
87 maxY = qMax(maxY, y);
87 tickXCount = x+1;
88 tickXCount = x+1;
88
89
89 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
90 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
90 }
91 }
91
92
92
93
93 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
94 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
94 {
95 {
95 Q_Q(QGroupedBarSeries);
96 Q_Q(QGroupedBarSeries);
96
97
97 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
98 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
98 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
99 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
99 presenter->animator()->addAnimation(bar);
100 presenter->animator()->addAnimation(bar);
100 }
101 }
101 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
102 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
102 return bar;
103 return bar;
103 }
104 }
104
105
105 #include "moc_qgroupedbarseries.cpp"
106 #include "moc_qgroupedbarseries.cpp"
106
107
107 QTCOMMERCIALCHART_END_NAMESPACE
108 QTCOMMERCIALCHART_END_NAMESPACE
108
109
@@ -1,52 +1,52
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
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
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPERCENTBARSERIES_P_H
30 #ifndef QPERCENTBARSERIES_P_H
31 #define QPERCENTBARSERIES_P_H
31 #define QPERCENTBARSERIES_P_H
32
32
33 #include "qbarseries_p.h"
33 #include "qbarseries_p.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
38
39 class QPercentBarSeriesPrivate: public QBarSeriesPrivate
39 class QPercentBarSeriesPrivate: public QBarSeriesPrivate
40 {
40 {
41 public:
41 public:
42 QPercentBarSeriesPrivate(/*QBarCategories categories,*/QPercentBarSeries* q);
42 QPercentBarSeriesPrivate(QPercentBarSeries* q);
43 void scaleDomain(Domain& domain);
43 void scaleDomain(Domain& domain);
44 Chart* createGraphics(ChartPresenter* presenter);
44 Chart* createGraphics(ChartPresenter* presenter);
45
45
46 private:
46 private:
47 Q_DECLARE_PUBLIC(QPercentBarSeries)
47 Q_DECLARE_PUBLIC(QPercentBarSeries)
48 };
48 };
49
49
50 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
51
51
52 #endif
52 #endif
@@ -1,108 +1,109
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qstackedbarseries.h"
21 #include "qstackedbarseries.h"
22 #include "qstackedbarseries_p.h"
22 #include "qstackedbarseries_p.h"
23 #include "stackedbarchartitem_p.h"
23 #include "stackedbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QStackedBarSeries
31 \class QStackedBarSeries
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as stacks, where bars in same category are stacked on top of each other.
36 as stacks, where bars in same category are stacked on top of each other.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
38
38
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
40 \image examples_stackedbarchart.png
40 \image examples_stackedbarchart.png
41
41
42 \sa QBarSet, QPercentBarSeries, QBarSeries
42 \sa QBarSet, QPercentBarSeries, QBarSeries
43 */
43 */
44
44
45 /*!
45 /*!
46 \fn virtual QSeriesType QStackedBarSeries::type() const
46 \fn virtual QSeriesType QStackedBarSeries::type() const
47 \brief Returns type of series.
47 \brief Returns type of series.
48 \sa QAbstractSeries, QSeriesType
48 \sa QAbstractSeries, QSeriesType
49 */
49 */
50
50
51 /*!
51 /*!
52 Constructs empty QStackedBarSeries.
52 Constructs empty QStackedBarSeries.
53 QStackedBarSeries is QObject which is a child of a \a parent.
53 QStackedBarSeries is QObject which is a child of a \a parent.
54 */
54 */
55 QStackedBarSeries::QStackedBarSeries(QObject *parent)
55 QStackedBarSeries::QStackedBarSeries(QObject *parent)
56 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
56 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
57 {
57 {
58 }
58 }
59
59
60 QAbstractSeries::SeriesType QStackedBarSeries::type() const
60 QAbstractSeries::SeriesType QStackedBarSeries::type() const
61 {
61 {
62 return QAbstractSeries::SeriesTypeStackedBar;
62 return QAbstractSeries::SeriesTypeStackedBar;
63 }
63 }
64
64
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66
66
67 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
67 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
68 {
68 {
69
69
70 }
70 }
71
71
72 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
72 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
73 {
73 {
74 Q_Q(QStackedBarSeries);
74 qreal minX(domain.minX());
75 qreal minX(domain.minX());
75 qreal minY(domain.minY());
76 qreal minY(domain.minY());
76 qreal maxX(domain.maxX());
77 qreal maxX(domain.maxX());
77 qreal maxY(domain.maxY());
78 qreal maxY(domain.maxY());
78 int tickXCount(domain.tickXCount());
79 int tickXCount(domain.tickXCount());
79 int tickYCount(domain.tickYCount());
80 int tickYCount(domain.tickYCount());
80
81
81 qreal x = m_categories.count();
82 qreal x = q->categoryCount();
82 qreal y = maxCategorySum();
83 qreal y = maxCategorySum();
83 minX = qMin(minX, x);
84 minX = qMin(minX, x);
84 minY = qMin(minY, y);
85 minY = qMin(minY, y);
85 maxX = qMax(maxX, x);
86 maxX = qMax(maxX, x);
86 maxY = qMax(maxY, y);
87 maxY = qMax(maxY, y);
87 tickXCount = x+1;
88 tickXCount = x+1;
88
89
89 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
90 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
90 }
91 }
91
92
92
93
93 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
94 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
94 {
95 {
95 Q_Q(QStackedBarSeries);
96 Q_Q(QStackedBarSeries);
96
97
97 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
98 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
98 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
99 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
99 presenter->animator()->addAnimation(bar);
100 presenter->animator()->addAnimation(bar);
100 }
101 }
101 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
102 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
102 return bar;
103 return bar;
103 }
104 }
104
105
105 #include "moc_qstackedbarseries.cpp"
106 #include "moc_qstackedbarseries.cpp"
106
107
107 QTCOMMERCIALCHART_END_NAMESPACE
108 QTCOMMERCIALCHART_END_NAMESPACE
108
109
@@ -1,52 +1,52
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
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
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QSTACKEDBARSERIES_P_H
30 #ifndef QSTACKEDBARSERIES_P_H
31 #define QSTACKEDBARSERIES_P_H
31 #define QSTACKEDBARSERIES_P_H
32
32
33 #include "qbarseries_p.h"
33 #include "qbarseries_p.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
38
39 class QStackedBarSeriesPrivate: public QBarSeriesPrivate
39 class QStackedBarSeriesPrivate: public QBarSeriesPrivate
40 {
40 {
41 public:
41 public:
42 QStackedBarSeriesPrivate(/*QBarCategories categories,*/QStackedBarSeries* q);
42 QStackedBarSeriesPrivate(QStackedBarSeries* q);
43 Chart* createGraphics(ChartPresenter* presenter);
43 Chart* createGraphics(ChartPresenter* presenter);
44 void scaleDomain(Domain& domain);
44 void scaleDomain(Domain& domain);
45
45
46 private:
46 private:
47 Q_DECLARE_PUBLIC(QStackedBarSeries)
47 Q_DECLARE_PUBLIC(QStackedBarSeries)
48 };
48 };
49
49
50 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
51
51
52 #endif
52 #endif
General Comments 0
You need to be logged in to leave comments. Login now