##// END OF EJS Templates
Remove createAxis from subclassess, if it is not nessery
Michal Klocek -
r1560:e99e16c1c580
parent child
Show More
@@ -1,130 +1,119
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 #include "qcategoriesaxis.h"
27 #include "qcategoriesaxis.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QGroupedBarSeries
33 \class QGroupedBarSeries
34 \brief Series for creating grouped bar chart
34 \brief Series for creating grouped bar chart
35 \mainclass
35 \mainclass
36
36
37 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
38 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
39 from sets to categories, which are defined by a QStringList.
39 from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
41 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
42 \image examples_groupedbarchart.png
42 \image examples_groupedbarchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
44 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass GroupedBarSeries QGroupedBarSeries
47 \qmlclass GroupedBarSeries QGroupedBarSeries
48 \inherits BarSeries
48 \inherits BarSeries
49
49
50 The following QML shows how to create a simple grouped bar chart:
50 The following QML shows how to create a simple grouped bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart7.png
53 \image demos_qmlchart7.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QGroupedBarSeries.
59 Constructs empty QGroupedBarSeries.
60 QGroupedBarSeries is QObject which is a child of a \a parent.
60 QGroupedBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
62 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
63 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
63 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypeGroupedBar.
68 Returns QChartSeries::SeriesTypeGroupedBar.
69 */
69 */
70 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
70 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypeGroupedBar;
72 return QAbstractSeries::SeriesTypeGroupedBar;
73 }
73 }
74
74
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
76
77 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q)
77 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q)
78 {
78 {
79
79
80 }
80 }
81
81
82 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
82 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
83 {
83 {
84 qreal minX(domain.minX());
84 qreal minX(domain.minX());
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
89 int tickYCount(domain.tickYCount());
90
90
91 qreal x = categoryCount();
91 qreal x = categoryCount();
92 qreal y = max();
92 qreal y = max();
93 minX = qMin(minX, -0.5);
93 minX = qMin(minX, -0.5);
94 minY = qMin(minY, y);
94 minY = qMin(minY, y);
95 maxX = qMax(maxX, x - 0.5);
95 maxX = qMax(maxX, x - 0.5);
96 maxY = qMax(maxY, y);
96 maxY = qMax(maxY, y);
97 tickXCount = x+1;
97 tickXCount = x+1;
98
98
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 }
100 }
101
101
102
102
103 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 {
104 {
105 Q_Q(QGroupedBarSeries);
105 Q_Q(QGroupedBarSeries);
106
106
107 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
107 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 presenter->animator()->addAnimation(bar);
109 presenter->animator()->addAnimation(bar);
110 }
110 }
111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 return bar;
112 return bar;
113 }
113 }
114
114
115 QAbstractAxis* QGroupedBarSeriesPrivate::createAxisX()
116 {
117 // TODO: parent?
118 return new QCategoriesAxis(this);
119 }
120
121 QAbstractAxis* QGroupedBarSeriesPrivate::createAxisY()
122 {
123 // TODO: parent?
124 return new QValuesAxis(this);
125 }
126
115
127 #include "moc_qgroupedbarseries.cpp"
116 #include "moc_qgroupedbarseries.cpp"
128
117
129 QTCOMMERCIALCHART_END_NAMESPACE
118 QTCOMMERCIALCHART_END_NAMESPACE
130
119
@@ -1,54 +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 QGROUPEDBARSERIES_P_H
30 #ifndef QGROUPEDBARSERIES_P_H
31 #define QGROUPEDBARSERIES_P_H
31 #define QGROUPEDBARSERIES_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 QGroupedBarSeriesPrivate: public QBarSeriesPrivate
39 class QGroupedBarSeriesPrivate: public QBarSeriesPrivate
40 {
40 {
41 public:
41 public:
42 QGroupedBarSeriesPrivate(QGroupedBarSeries* q);
42 QGroupedBarSeriesPrivate(QGroupedBarSeries* q);
43 Chart* createGraphics(ChartPresenter* presenter);
43 Chart* createGraphics(ChartPresenter* presenter);
44 void scaleDomain(Domain& domain);
44 void scaleDomain(Domain& domain);
45 QAbstractAxis* createAxisX();
46 QAbstractAxis* createAxisY();
47
45
48 private:
46 private:
49 Q_DECLARE_PUBLIC(QGroupedBarSeries)
47 Q_DECLARE_PUBLIC(QGroupedBarSeries)
50 };
48 };
51
49
52 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
53
51
54 #endif // QGROUPEDBARSERIES_P_H
52 #endif // QGROUPEDBARSERIES_P_H
@@ -1,129 +1,117
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 "qpercentbarseries.h"
21 #include "qpercentbarseries.h"
22 #include "qpercentbarseries_p.h"
22 #include "qpercentbarseries_p.h"
23 #include "percentbarchartitem_p.h"
23 #include "percentbarchartitem_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 #include "qcategoriesaxis.h"
27 #include "qcategoriesaxis.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QPercentBarSeries
33 \class QPercentBarSeries
34 \brief Series for creating percent bar chart
34 \brief Series for creating percent bar chart
35 \mainclass
35 \mainclass
36
36
37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as stacks, where each bar is shown as percentage of all bars in that category.
38 as stacks, where each bar is shown as percentage of all bars in that category.
39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
42 \image examples_percentbarchart.png
42 \image examples_percentbarchart.png
43
43
44 \sa QBarSet, QStackedBarSeries, QBarSeries
44 \sa QBarSet, QStackedBarSeries, QBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass PercentBarSeries QPercentBarSeries
47 \qmlclass PercentBarSeries QPercentBarSeries
48 \inherits BarSeries
48 \inherits BarSeries
49
49
50 The following QML shows how to create a simple percent bar chart:
50 The following QML shows how to create a simple percent bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart9.png
53 \image demos_qmlchart9.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QPercentBarSeries.
59 Constructs empty QPercentBarSeries.
60 QPercentBarSeries is QObject which is a child of a \a parent.
60 QPercentBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
63 : QBarSeries(*new QPercentBarSeriesPrivate(this), parent)
63 : QBarSeries(*new QPercentBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypePercentBar.
68 Returns QChartSeries::SeriesTypePercentBar.
69 */
69 */
70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypePercentBar;
72 return QAbstractSeries::SeriesTypePercentBar;
73 }
73 }
74
74
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
76
77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q)
77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q)
78 {
78 {
79
79
80 }
80 }
81
81
82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
83 {
83 {
84 qreal minX(domain.minX());
84 qreal minX(domain.minX());
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
89 int tickYCount(domain.tickYCount());
90
90
91 qreal x = categoryCount();
91 qreal x = categoryCount();
92 minX = qMin(minX, -0.5);
92 minX = qMin(minX, -0.5);
93 maxX = qMax(maxX, x - 0.5);
93 maxX = qMax(maxX, x - 0.5);
94 minY = 0;
94 minY = 0;
95 maxY = 100;
95 maxY = 100;
96 tickXCount = x+1;
96 tickXCount = x+1;
97
97
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 }
99 }
100
100
101
101
102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 {
103 {
104 Q_Q(QPercentBarSeries);
104 Q_Q(QPercentBarSeries);
105
105
106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 presenter->animator()->addAnimation(bar);
108 presenter->animator()->addAnimation(bar);
109 }
109 }
110 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
110 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
111 return bar;
111 return bar;
112 }
112 }
113
113
114 QAbstractAxis* QPercentBarSeriesPrivate::createAxisX()
115 {
116 // TODO: parent?
117 return new QCategoriesAxis(this);
118 }
119
120 QAbstractAxis* QPercentBarSeriesPrivate::createAxisY()
121 {
122 // TODO: parent?
123 return new QValuesAxis(this);
124 }
125
126 #include "moc_qpercentbarseries.cpp"
114 #include "moc_qpercentbarseries.cpp"
127
115
128 QTCOMMERCIALCHART_END_NAMESPACE
116 QTCOMMERCIALCHART_END_NAMESPACE
129
117
@@ -1,54 +1,51
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(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 QAbstractAxis* createAxisX();
46 QAbstractAxis* createAxisY();
47
48 private:
45 private:
49 Q_DECLARE_PUBLIC(QPercentBarSeries)
46 Q_DECLARE_PUBLIC(QPercentBarSeries)
50 };
47 };
51
48
52 QTCOMMERCIALCHART_END_NAMESPACE
49 QTCOMMERCIALCHART_END_NAMESPACE
53
50
54 #endif
51 #endif
@@ -1,132 +1,120
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 #include "qcategoriesaxis.h"
27 #include "qcategoriesaxis.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QStackedBarSeries
33 \class QStackedBarSeries
34 \brief Series for creating stacked bar chart
34 \brief Series for creating stacked bar chart
35 \mainclass
35 \mainclass
36
36
37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as stacks, where bars in same category are stacked on top of each other.
38 as stacks, where bars in same category are stacked on top of each other.
39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
40
40
41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
42 \image examples_stackedbarchart.png
42 \image examples_stackedbarchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QBarSeries
44 \sa QBarSet, QPercentBarSeries, QBarSeries
45 */
45 */
46
46
47 /*!
47 /*!
48 \qmlclass StackedBarSeries QStackedBarSeries
48 \qmlclass StackedBarSeries QStackedBarSeries
49 \inherits BarSeries
49 \inherits BarSeries
50
50
51 The following QML shows how to create a simple stacked bar chart:
51 The following QML shows how to create a simple stacked bar chart:
52 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
52 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
53 \beginfloatleft
53 \beginfloatleft
54 \image demos_qmlchart8.png
54 \image demos_qmlchart8.png
55 \endfloat
55 \endfloat
56 \clearfloat
56 \clearfloat
57 */
57 */
58
58
59 /*!
59 /*!
60 Constructs empty QStackedBarSeries.
60 Constructs empty QStackedBarSeries.
61 QStackedBarSeries is QObject which is a child of a \a parent.
61 QStackedBarSeries is QObject which is a child of a \a parent.
62 */
62 */
63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
64 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
64 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
65 {
65 {
66 }
66 }
67
67
68 /*!
68 /*!
69 Returns QChartSeries::SeriesTypeStackedBar.
69 Returns QChartSeries::SeriesTypeStackedBar.
70 */
70 */
71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
72 {
72 {
73 return QAbstractSeries::SeriesTypeStackedBar;
73 return QAbstractSeries::SeriesTypeStackedBar;
74 }
74 }
75
75
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
79 {
79 {
80
80
81 }
81 }
82
82
83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
84 {
84 {
85 qreal minX(domain.minX());
85 qreal minX(domain.minX());
86 qreal minY(domain.minY());
86 qreal minY(domain.minY());
87 qreal maxX(domain.maxX());
87 qreal maxX(domain.maxX());
88 qreal maxY(domain.maxY());
88 qreal maxY(domain.maxY());
89 int tickXCount(domain.tickXCount());
89 int tickXCount(domain.tickXCount());
90 int tickYCount(domain.tickYCount());
90 int tickYCount(domain.tickYCount());
91
91
92 qreal x = categoryCount();
92 qreal x = categoryCount();
93 qreal y = maxCategorySum();
93 qreal y = maxCategorySum();
94 minX = qMin(minX, -0.5);
94 minX = qMin(minX, -0.5);
95 minY = qMin(minY, y);
95 minY = qMin(minY, y);
96 maxX = qMax(maxX, x - 0.5);
96 maxX = qMax(maxX, x - 0.5);
97 maxY = qMax(maxY, y);
97 maxY = qMax(maxY, y);
98 tickXCount = x+1;
98 tickXCount = x+1;
99
99
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
101 }
101 }
102
102
103
103
104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
105 {
105 {
106 Q_Q(QStackedBarSeries);
106 Q_Q(QStackedBarSeries);
107
107
108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 presenter->animator()->addAnimation(bar);
110 presenter->animator()->addAnimation(bar);
111 }
111 }
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 return bar;
113 return bar;
114 }
114 }
115
115
116 QAbstractAxis* QStackedBarSeriesPrivate::createAxisX()
117 {
118 // TODO: parent?
119 return new QCategoriesAxis(this);
120 }
121
122 QAbstractAxis* QStackedBarSeriesPrivate::createAxisY()
123 {
124 // TODO: parent?
125 return new QValuesAxis(this);
126 }
127
128
116
129 #include "moc_qstackedbarseries.cpp"
117 #include "moc_qstackedbarseries.cpp"
130
118
131 QTCOMMERCIALCHART_END_NAMESPACE
119 QTCOMMERCIALCHART_END_NAMESPACE
132
120
@@ -1,54 +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(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 QAbstractAxis* createAxisX();
46 QAbstractAxis* createAxisY();
47
45
48 private:
46 private:
49 Q_DECLARE_PUBLIC(QStackedBarSeries)
47 Q_DECLARE_PUBLIC(QStackedBarSeries)
50 };
48 };
51
49
52 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
53
51
54 #endif
52 #endif
General Comments 0
You need to be logged in to leave comments. Login now