@@ -1,118 +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 "qhorizontalbarseries.h" |
|
21 | #include "qhorizontalbarseries.h" | |
22 | #include "qhorizontalbarseries_p.h" |
|
22 | #include "qhorizontalbarseries_p.h" | |
23 | #include "horizontalbarchartitem_p.h" |
|
23 | #include "horizontalbarchartitem_p.h" | |
24 | #include "horizontalbaranimation_p.h" |
|
24 | #include "horizontalbaranimation_p.h" | |
25 | #include "qbarcategoriesaxis.h" |
|
25 | #include "qbarcategoriesaxis.h" | |
26 |
|
26 | |||
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QHorizontalBarSeries |
|
34 | \class QHorizontalBarSeries | |
35 | \brief Series for creating horizontal bar chart |
|
35 | \brief Series for creating horizontal bar chart | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
39 | as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data |
|
39 | as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data | |
40 | from sets to categories, which are defined by a QStringList. |
|
40 | from sets to categories, which are defined by a QStringList. | |
41 |
|
41 | |||
42 | See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart. |
|
42 | See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart. | |
43 | \image examples_horizontalbarchart.png |
|
43 | \image examples_horizontalbarchart.png | |
44 |
|
44 | |||
45 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries |
|
45 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries | |
46 | */ |
|
46 | */ | |
47 | /* |
|
47 | /* | |
48 | // TODO: |
|
48 | // TODO: | |
49 | \qmlclass Horizontal QHorizontalBarSeries |
|
49 | \qmlclass Horizontal QHorizontalBarSeries | |
50 | \inherits AbstractBarSeries |
|
50 | \inherits AbstractBarSeries | |
51 |
|
51 | |||
52 | The following QML shows how to create a simple grouped bar chart: |
|
52 | The following QML shows how to create a simple grouped bar chart: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
53 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
54 | \beginfloatleft |
|
54 | \beginfloatleft | |
55 | \image demos_qmlchart6.png |
|
55 | \image demos_qmlchart6.png | |
56 | \endfloat |
|
56 | \endfloat | |
57 | \clearfloat |
|
57 | \clearfloat | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 |
|
60 | |||
61 |
|
61 | |||
62 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : |
|
62 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : | |
63 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) |
|
63 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | QHorizontalBarSeries::~QHorizontalBarSeries() |
|
67 | QHorizontalBarSeries::~QHorizontalBarSeries() | |
68 | { |
|
68 | { | |
69 | Q_D(QHorizontalBarSeries); |
|
69 | Q_D(QHorizontalBarSeries); | |
70 | if(d->m_dataset) { |
|
70 | if(d->m_dataset) { | |
71 | d->m_dataset->removeSeries(this); |
|
71 | d->m_dataset->removeSeries(this); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const |
|
75 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const | |
76 | { |
|
76 | { | |
77 | return QAbstractSeries::SeriesTypeHorizontalBar; |
|
77 | return QAbstractSeries::SeriesTypeHorizontalBar; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
81 |
|
81 | |||
82 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
82 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
83 | { |
|
83 | { | |
84 |
|
84 | |||
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) |
|
87 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) | |
88 | { |
|
88 | { | |
89 | qreal minX(domain.minX()); |
|
89 | qreal minX(domain.minX()); | |
90 | qreal minY(domain.minY()); |
|
90 | qreal minY(domain.minY()); | |
91 | qreal maxX(domain.maxX()); |
|
91 | qreal maxX(domain.maxX()); | |
92 | qreal maxY(domain.maxY()); |
|
92 | qreal maxY(domain.maxY()); | |
93 |
|
93 | |||
94 | qreal y = categoryCount(); |
|
94 | qreal y = categoryCount(); | |
95 | qreal x = max(); |
|
95 | minX = qMin(minX, min()); | |
96 | minX = qMin(minX, x); |
|
|||
97 | minY = qMin(minY, - (qreal)0.5); |
|
96 | minY = qMin(minY, - (qreal)0.5); | |
98 | maxX = qMax(maxX, x); |
|
97 | maxX = qMax(maxX, max()); | |
99 | maxY = qMax(maxY, y - (qreal)0.5); |
|
98 | maxY = qMax(maxY, y - (qreal)0.5); | |
100 |
|
99 | |||
101 | domain.setRange(minX,maxX,minY,maxY); |
|
100 | domain.setRange(minX,maxX,minY,maxY); | |
102 | } |
|
101 | } | |
103 |
|
102 | |||
104 | ChartElement* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
103 | ChartElement* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
105 | { |
|
104 | { | |
106 | Q_Q(QHorizontalBarSeries); |
|
105 | Q_Q(QHorizontalBarSeries); | |
107 |
|
106 | |||
108 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); |
|
107 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); | |
109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
110 | bar->setAnimation(new HorizontalBarAnimation(bar)); |
|
109 | bar->setAnimation(new HorizontalBarAnimation(bar)); | |
111 | } |
|
110 | } | |
112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
113 | return bar; |
|
112 | return bar; | |
114 | } |
|
113 | } | |
115 |
|
114 | |||
116 | #include "moc_qhorizontalbarseries.cpp" |
|
115 | #include "moc_qhorizontalbarseries.cpp" | |
117 |
|
116 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
117 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,122 +1,121 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "barchartitem_p.h" |
|
23 | #include "barchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "baranimation_p.h" |
|
26 | #include "baranimation_p.h" | |
27 | #include "qvaluesaxis.h" |
|
27 | #include "qvaluesaxis.h" | |
28 | #include "qbarcategoriesaxis.h" |
|
28 | #include "qbarcategoriesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QBarSeries |
|
33 | \class QBarSeries | |
34 | \brief Series for creating bar chart |
|
34 | \brief Series for creating bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QBarSeries 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. QBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QBarSeries 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 {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. | |
42 | \image examples_barchart.png |
|
42 | \image examples_barchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass BarSeries QBarSeries |
|
47 | \qmlclass BarSeries QBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
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/View6.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart6.png |
|
53 | \image demos_qmlchart6.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QBarSeries. |
|
59 | Constructs empty QBarSeries. | |
60 | QBarSeries is QObject which is a child of a \a parent. |
|
60 | QBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QBarSeries::QBarSeries(QObject *parent) |
|
62 | QBarSeries::QBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypeBar. |
|
68 | Returns QChartSeries::SeriesTypeBar. | |
69 | */ |
|
69 | */ | |
70 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QBarSeries::type() const | |
71 | { |
|
71 | { | |
72 | return QAbstractSeries::SeriesTypeBar; |
|
72 | return QAbstractSeries::SeriesTypeBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QBarSeries::~QBarSeries() |
|
75 | QBarSeries::~QBarSeries() | |
76 | { |
|
76 | { | |
77 | Q_D(QBarSeries); |
|
77 | Q_D(QBarSeries); | |
78 | if(d->m_dataset) { |
|
78 | if(d->m_dataset) { | |
79 | d->m_dataset->removeSeries(this); |
|
79 | d->m_dataset->removeSeries(this); | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
83 | |||
84 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
84 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
89 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
90 | { | |
91 | qreal minX(domain.minX()); |
|
91 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
92 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
93 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
94 | qreal maxY(domain.maxY()); | |
95 |
|
95 | |||
96 | qreal x = categoryCount(); |
|
96 | qreal x = categoryCount(); | |
97 | qreal y = max(); |
|
|||
98 | minX = qMin(minX, - (qreal)0.5); |
|
97 | minX = qMin(minX, - (qreal)0.5); | |
99 |
minY = qMin(minY, |
|
98 | minY = qMin(minY, min()); | |
100 | maxX = qMax(maxX, x - (qreal)0.5); |
|
99 | maxX = qMax(maxX, x - (qreal)0.5); | |
101 |
maxY = qMax(maxY, |
|
100 | maxY = qMax(maxY, max()); | |
102 |
|
101 | |||
103 | domain.setRange(minX,maxX,minY,maxY); |
|
102 | domain.setRange(minX,maxX,minY,maxY); | |
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 |
|
105 | |||
107 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
106 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
108 | { |
|
107 | { | |
109 | Q_Q(QBarSeries); |
|
108 | Q_Q(QBarSeries); | |
110 |
|
109 | |||
111 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
110 | BarChartItem* bar = new BarChartItem(q,presenter); | |
112 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
113 | bar->setAnimation(new BarAnimation(bar)); |
|
112 | bar->setAnimation(new BarAnimation(bar)); | |
114 | } |
|
113 | } | |
115 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
116 | return bar; |
|
115 | return bar; | |
117 | } |
|
116 | } | |
118 |
|
117 | |||
119 | #include "moc_qbarseries.cpp" |
|
118 | #include "moc_qbarseries.cpp" | |
120 |
|
119 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE | |
122 |
|
121 |
General Comments 0
You need to be logged in to leave comments.
Login now