@@ -1,118 +1,117 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qhorizontalbarseries.h" |
|
22 | 22 | #include "qhorizontalbarseries_p.h" |
|
23 | 23 | #include "horizontalbarchartitem_p.h" |
|
24 | 24 | #include "horizontalbaranimation_p.h" |
|
25 | 25 | #include "qbarcategoriesaxis.h" |
|
26 | 26 | |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \class QHorizontalBarSeries |
|
35 | 35 | \brief Series for creating horizontal bar chart |
|
36 | 36 | \mainclass |
|
37 | 37 | |
|
38 | 38 | QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
39 | 39 | as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data |
|
40 | 40 | from sets to categories, which are defined by a QStringList. |
|
41 | 41 | |
|
42 | 42 | See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart. |
|
43 | 43 | \image examples_horizontalbarchart.png |
|
44 | 44 | |
|
45 | 45 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries |
|
46 | 46 | */ |
|
47 | 47 | /* |
|
48 | 48 | // TODO: |
|
49 | 49 | \qmlclass Horizontal QHorizontalBarSeries |
|
50 | 50 | \inherits AbstractBarSeries |
|
51 | 51 | |
|
52 | 52 | The following QML shows how to create a simple grouped bar chart: |
|
53 | 53 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | 54 | \beginfloatleft |
|
55 | 55 | \image demos_qmlchart6.png |
|
56 | 56 | \endfloat |
|
57 | 57 | \clearfloat |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : |
|
63 | 63 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | QHorizontalBarSeries::~QHorizontalBarSeries() |
|
68 | 68 | { |
|
69 | 69 | Q_D(QHorizontalBarSeries); |
|
70 | 70 | if(d->m_dataset) { |
|
71 | 71 | d->m_dataset->removeSeries(this); |
|
72 | 72 | } |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const |
|
76 | 76 | { |
|
77 | 77 | return QAbstractSeries::SeriesTypeHorizontalBar; |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 | 81 | |
|
82 | 82 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
83 | 83 | { |
|
84 | 84 | |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) |
|
88 | 88 | { |
|
89 | 89 | qreal minX(domain.minX()); |
|
90 | 90 | qreal minY(domain.minY()); |
|
91 | 91 | qreal maxX(domain.maxX()); |
|
92 | 92 | qreal maxY(domain.maxY()); |
|
93 | 93 | |
|
94 | 94 | qreal y = categoryCount(); |
|
95 | qreal x = max(); | |
|
96 | minX = qMin(minX, x); | |
|
95 | minX = qMin(minX, min()); | |
|
97 | 96 | minY = qMin(minY, - (qreal)0.5); |
|
98 | maxX = qMax(maxX, x); | |
|
97 | maxX = qMax(maxX, max()); | |
|
99 | 98 | maxY = qMax(maxY, y - (qreal)0.5); |
|
100 | 99 | |
|
101 | 100 | domain.setRange(minX,maxX,minY,maxY); |
|
102 | 101 | } |
|
103 | 102 | |
|
104 | 103 | ChartElement* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
105 | 104 | { |
|
106 | 105 | Q_Q(QHorizontalBarSeries); |
|
107 | 106 | |
|
108 | 107 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); |
|
109 | 108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
110 | 109 | bar->setAnimation(new HorizontalBarAnimation(bar)); |
|
111 | 110 | } |
|
112 | 111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
113 | 112 | return bar; |
|
114 | 113 | } |
|
115 | 114 | |
|
116 | 115 | #include "moc_qhorizontalbarseries.cpp" |
|
117 | 116 | |
|
118 | 117 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,122 +1,121 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "barchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "baranimation_p.h" |
|
27 | 27 | #include "qvaluesaxis.h" |
|
28 | 28 | #include "qbarcategoriesaxis.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QBarSeries |
|
34 | 34 | \brief Series for creating bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data |
|
39 | 39 | from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. |
|
42 | 42 | \image examples_barchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass BarSeries QBarSeries |
|
48 | 48 | \inherits AbstractBarSeries |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple grouped bar chart: |
|
51 | 51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
52 | 52 | \beginfloatleft |
|
53 | 53 | \image demos_qmlchart6.png |
|
54 | 54 | \endfloat |
|
55 | 55 | \clearfloat |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | Constructs empty QBarSeries. |
|
60 | 60 | QBarSeries is QObject which is a child of a \a parent. |
|
61 | 61 | */ |
|
62 | 62 | QBarSeries::QBarSeries(QObject *parent) |
|
63 | 63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | Returns QChartSeries::SeriesTypeBar. |
|
69 | 69 | */ |
|
70 | 70 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
71 | 71 | { |
|
72 | 72 | return QAbstractSeries::SeriesTypeBar; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | QBarSeries::~QBarSeries() |
|
76 | 76 | { |
|
77 | 77 | Q_D(QBarSeries); |
|
78 | 78 | if(d->m_dataset) { |
|
79 | 79 | d->m_dataset->removeSeries(this); |
|
80 | 80 | } |
|
81 | 81 | } |
|
82 | 82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 | 83 | |
|
84 | 84 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
85 | 85 | { |
|
86 | 86 | |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
90 | 90 | { |
|
91 | 91 | qreal minX(domain.minX()); |
|
92 | 92 | qreal minY(domain.minY()); |
|
93 | 93 | qreal maxX(domain.maxX()); |
|
94 | 94 | qreal maxY(domain.maxY()); |
|
95 | 95 | |
|
96 | 96 | qreal x = categoryCount(); |
|
97 | qreal y = max(); | |
|
98 | 97 | minX = qMin(minX, - (qreal)0.5); |
|
99 |
minY = qMin(minY, |
|
|
98 | minY = qMin(minY, min()); | |
|
100 | 99 | maxX = qMax(maxX, x - (qreal)0.5); |
|
101 |
maxY = qMax(maxY, |
|
|
100 | maxY = qMax(maxY, max()); | |
|
102 | 101 | |
|
103 | 102 | domain.setRange(minX,maxX,minY,maxY); |
|
104 | 103 | } |
|
105 | 104 | |
|
106 | 105 | |
|
107 | 106 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
108 | 107 | { |
|
109 | 108 | Q_Q(QBarSeries); |
|
110 | 109 | |
|
111 | 110 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
112 | 111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
113 | 112 | bar->setAnimation(new BarAnimation(bar)); |
|
114 | 113 | } |
|
115 | 114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
116 | 115 | return bar; |
|
117 | 116 | } |
|
118 | 117 | |
|
119 | 118 | #include "moc_qbarseries.cpp" |
|
120 | 119 | |
|
121 | 120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
122 | 121 |
General Comments 0
You need to be logged in to leave comments.
Login now