@@ -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 "charttitle_p.h" | |||
|
22 | #include <QFont> | |||
|
23 | #include <QFontMetrics> | |||
|
24 | #include <QDebug> | |||
|
25 | ||||
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
27 | ||||
|
28 | ChartTitle::ChartTitle(QGraphicsItem* parent):QGraphicsSimpleTextItem(parent) | |||
|
29 | { | |||
|
30 | ||||
|
31 | } | |||
|
32 | ||||
|
33 | ChartTitle::~ChartTitle() | |||
|
34 | { | |||
|
35 | ||||
|
36 | } | |||
|
37 | ||||
|
38 | void ChartTitle::setText(const QString &text) | |||
|
39 | { | |||
|
40 | m_text=text; | |||
|
41 | } | |||
|
42 | ||||
|
43 | QString ChartTitle::text() const | |||
|
44 | { | |||
|
45 | return m_text; | |||
|
46 | } | |||
|
47 | ||||
|
48 | void ChartTitle::setGeometry(const QRectF &rect) | |||
|
49 | { | |||
|
50 | QFontMetrics fn(font()); | |||
|
51 | ||||
|
52 | int width = rect.width(); | |||
|
53 | ||||
|
54 | if (fn.boundingRect(m_text).width() > width) | |||
|
55 | { | |||
|
56 | QString string = m_text + "..."; | |||
|
57 | while (fn.boundingRect(string).width() > width && string.length() > 3) | |||
|
58 | string.remove(string.length() - 4, 1); | |||
|
59 | QGraphicsSimpleTextItem::setText(string); | |||
|
60 | } | |||
|
61 | else | |||
|
62 | QGraphicsSimpleTextItem::setText(m_text); | |||
|
63 | ||||
|
64 | setPos(rect.topLeft()); | |||
|
65 | } | |||
|
66 | ||||
|
67 | ||||
|
68 | QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |||
|
69 | { | |||
|
70 | Q_UNUSED(constraint); | |||
|
71 | QFontMetrics fn (font ()); | |||
|
72 | QSizeF sh; | |||
|
73 | ||||
|
74 | switch(which) { | |||
|
75 | case Qt::MinimumSize: | |||
|
76 | sh = QSizeF(fn.boundingRect ("...").width(),fn.height()); | |||
|
77 | break; | |||
|
78 | case Qt::PreferredSize: | |||
|
79 | sh = QSizeF(fn.boundingRect(m_text).width(),fn.height()); | |||
|
80 | break; | |||
|
81 | case Qt::MaximumSize: | |||
|
82 | sh = QSizeF(fn.boundingRect(m_text).width(),fn.height()); | |||
|
83 | break; | |||
|
84 | case Qt::MinimumDescent: | |||
|
85 | sh = QSizeF(0, fn.descent ()); | |||
|
86 | break; | |||
|
87 | default: | |||
|
88 | break; | |||
|
89 | } | |||
|
90 | ||||
|
91 | return sh; | |||
|
92 | } | |||
|
93 | ||||
|
94 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,53 | |||||
|
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 CHARTTITLE_P_H_ | |||
|
31 | #define CHARTTITLE_P_H_ | |||
|
32 | ||||
|
33 | #include "qchartglobal.h" | |||
|
34 | #include <QGraphicsSimpleTextItem> | |||
|
35 | ||||
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
37 | ||||
|
38 | class ChartTitle : public QGraphicsSimpleTextItem | |||
|
39 | { | |||
|
40 | public: | |||
|
41 | ChartTitle(QGraphicsItem* parent = 0); | |||
|
42 | ~ChartTitle(); | |||
|
43 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |||
|
44 | void setText(const QString &text); | |||
|
45 | QString text() const; | |||
|
46 | void setGeometry(const QRectF &rect); | |||
|
47 | private: | |||
|
48 | QString m_text; | |||
|
49 | }; | |||
|
50 | ||||
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
52 | ||||
|
53 | #endif /* CHARTTITLE_P_H_ */ |
@@ -1,704 +1,705 | |||||
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 "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QDeclarativeEngine> |
|
23 | #include <QDeclarativeEngine> | |
24 | #include "declarativelineseries.h" |
|
24 | #include "declarativelineseries.h" | |
25 | #include "declarativeareaseries.h" |
|
25 | #include "declarativeareaseries.h" | |
26 | #include "declarativebarseries.h" |
|
26 | #include "declarativebarseries.h" | |
27 | #include "declarativepieseries.h" |
|
27 | #include "declarativepieseries.h" | |
28 | #include "declarativesplineseries.h" |
|
28 | #include "declarativesplineseries.h" | |
29 | #include "declarativescatterseries.h" |
|
29 | #include "declarativescatterseries.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 | #include "qvalueaxis.h" |
|
31 | #include "qvalueaxis.h" | |
32 | #include "qcategoryaxis.h" |
|
32 | #include "qcategoryaxis.h" | |
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 | #include "declarativemargins.h" |
|
34 | #include "declarativemargins.h" | |
35 |
|
35 | |||
36 | #ifndef QT_ON_ARM |
|
36 | #ifndef QT_ON_ARM | |
37 | #include "qdatetimeaxis.h" |
|
37 | #include "qdatetimeaxis.h" | |
38 | #endif |
|
38 | #endif | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \qmlclass ChartView DeclarativeChart |
|
43 | \qmlclass ChartView DeclarativeChart | |
44 |
|
44 | |||
45 | ChartView element is the parent that is responsible for showing different chart series types. |
|
45 | ChartView element is the parent that is responsible for showing different chart series types. | |
46 |
|
46 | |||
47 | The following QML shows how to create a simple chart with one pie series: |
|
47 | The following QML shows how to create a simple chart with one pie series: | |
48 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
48 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
51 |
|
51 | |||
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image examples_qmlpiechart.png |
|
53 | \image examples_qmlpiechart.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \qmlproperty Theme ChartView::theme |
|
59 | \qmlproperty Theme ChartView::theme | |
60 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
60 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
61 | widths and chart background. |
|
61 | widths and chart background. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty Animation ChartView::animation |
|
65 | \qmlproperty Animation ChartView::animation | |
66 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
66 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
67 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
67 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty Font ChartView::titleFont |
|
71 | \qmlproperty Font ChartView::titleFont | |
72 | The title font of the chart |
|
72 | The title font of the chart | |
73 |
|
73 | |||
74 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
74 | See the \l {Font} {QML Font Element} for detailed documentation. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \qmlproperty string ChartView::title |
|
78 | \qmlproperty string ChartView::title | |
79 | The title of the chart, shown on top of the chart. |
|
79 | The title of the chart, shown on top of the chart. | |
80 | \sa ChartView::titleColor |
|
80 | \sa ChartView::titleColor | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty string ChartView::titleColor |
|
84 | \qmlproperty string ChartView::titleColor | |
85 | The color of the title text. |
|
85 | The color of the title text. | |
86 | */ |
|
86 | */ | |
87 |
|
87 | |||
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty Axis ChartView::axisX |
|
89 | \qmlproperty Axis ChartView::axisX | |
90 | The x-axis of the chart. |
|
90 | The x-axis of the chart. | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \qmlproperty Axis ChartView::axisY |
|
94 | \qmlproperty Axis ChartView::axisY | |
95 | The default y-axis of the chart. |
|
95 | The default y-axis of the chart. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty Legend ChartView::legend |
|
99 | \qmlproperty Legend ChartView::legend | |
100 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
100 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty int ChartView::count |
|
104 | \qmlproperty int ChartView::count | |
105 | The count of series added to the chart. |
|
105 | The count of series added to the chart. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \qmlproperty color ChartView::backgroundColor |
|
109 | \qmlproperty color ChartView::backgroundColor | |
110 | The color of the chart's background. By default background color is defined by chart theme. |
|
110 | The color of the chart's background. By default background color is defined by chart theme. | |
111 | \sa ChartView::theme |
|
111 | \sa ChartView::theme | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty bool ChartView::dropShadowEnabled |
|
115 | \qmlproperty bool ChartView::dropShadowEnabled | |
116 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
116 | The chart's border drop shadow. Set to true to enable drop shadow. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \qmlproperty real ChartView::topMargin |
|
120 | \qmlproperty real ChartView::topMargin | |
121 | Deprecated. Use minimumMargins and plotArea instead. |
|
121 | Deprecated. Use minimumMargins and plotArea instead. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \qmlproperty real ChartView::bottomMargin |
|
125 | \qmlproperty real ChartView::bottomMargin | |
126 | Deprecated. Use minimumMargins and plotArea instead. |
|
126 | Deprecated. Use minimumMargins and plotArea instead. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \qmlproperty real ChartView::leftMargin |
|
130 | \qmlproperty real ChartView::leftMargin | |
131 | Deprecated. Use minimumMargins and plotArea instead. |
|
131 | Deprecated. Use minimumMargins and plotArea instead. | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlproperty real ChartView::rightMargin |
|
135 | \qmlproperty real ChartView::rightMargin | |
136 | Deprecated. Use minimumMargins and plotArea instead. |
|
136 | Deprecated. Use minimumMargins and plotArea instead. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \qmlproperty Margins ChartView::minimumMargins |
|
140 | \qmlproperty Margins ChartView::minimumMargins | |
141 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
141 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
142 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
142 | area of ChartView is used for drawing title, axes and legend. Please note that setting the | |
143 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
143 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView | |
144 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
144 | properties that affect it's layout. If you need to know the actual plotting area used at any | |
145 | given time, you can check ChartView::plotArea instead. |
|
145 | given time, you can check ChartView::plotArea instead. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \qmlproperty rect ChartView::plotArea |
|
149 | \qmlproperty rect ChartView::plotArea | |
150 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
150 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the | |
151 | margins. |
|
151 | margins. | |
152 | \sa ChartView::minimumMargins |
|
152 | \sa ChartView::minimumMargins | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
156 | \qmlmethod AbstractSeries ChartView::series(int index) | |
157 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
157 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
158 | the count property of the chart. |
|
158 | the count property of the chart. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
162 | \qmlmethod AbstractSeries ChartView::series(string name) | |
163 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
163 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
167 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) | |
168 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
168 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and | |
169 | optional axis \a axisY. For example: |
|
169 | optional axis \a axisY. For example: | |
170 | \code |
|
170 | \code | |
171 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
171 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes | |
172 | var myAxisX = chartView.axisX(lineSeries); |
|
172 | var myAxisX = chartView.axisX(lineSeries); | |
173 | var myAxisY = chartView.axisY(lineSeries); |
|
173 | var myAxisY = chartView.axisY(lineSeries); | |
174 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
174 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); | |
175 | \endcode |
|
175 | \endcode | |
176 | */ |
|
176 | */ | |
177 |
|
177 | |||
178 | /*! |
|
178 | /*! | |
179 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
179 | \qmlmethod ChartView::removeSeries(AbstractSeries series) | |
180 | Removes the \a series from the chart. The series object is also destroyed. |
|
180 | Removes the \a series from the chart. The series object is also destroyed. | |
181 | */ |
|
181 | */ | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | \qmlmethod ChartView::removeAllSeries() |
|
184 | \qmlmethod ChartView::removeAllSeries() | |
185 | Removes all series from the chart. All the series objects are also destroyed. |
|
185 | Removes all series from the chart. All the series objects are also destroyed. | |
186 | */ |
|
186 | */ | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \qmlmethod Axis ChartView::axisX(QAbstractSeries *series) |
|
189 | \qmlmethod Axis ChartView::axisX(QAbstractSeries *series) | |
190 | The x-axis of the series. |
|
190 | The x-axis of the series. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
194 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) | |
195 | The y-axis of the series. |
|
195 | The y-axis of the series. | |
196 | */ |
|
196 | */ | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \qmlmethod ChartView::zoomY(real factor) |
|
199 | \qmlmethod ChartView::zoomY(real factor) | |
200 | Zooms in by \a factor on the center of the chart. |
|
200 | Zooms in by \a factor on the center of the chart. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
204 | \qmlmethod ChartView::scrollLeft(real pixels) | |
205 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
205 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
206 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
206 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \qmlmethod ChartView::scrollRight(real pixels) |
|
210 | \qmlmethod ChartView::scrollRight(real pixels) | |
211 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
211 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
212 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
212 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
213 | */ |
|
213 | */ | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | \qmlmethod ChartView::scrollUp(real pixels) |
|
216 | \qmlmethod ChartView::scrollUp(real pixels) | |
217 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
217 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
218 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
218 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \qmlmethod ChartView::scrollDown(real pixels) |
|
222 | \qmlmethod ChartView::scrollDown(real pixels) | |
223 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
223 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
224 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
224 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
228 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) | |
229 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
229 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins | |
230 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
230 | or if you resize the chart, or if you modify font size related properties of the legend or chart | |
231 | title. |
|
231 | title. | |
232 | */ |
|
232 | */ | |
233 |
|
233 | |||
234 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
234 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
235 | : QDeclarativeItem(parent), |
|
235 | : QDeclarativeItem(parent), | |
236 | m_chart(new QChart(this)) |
|
236 | m_chart(new QChart(this)) | |
237 | { |
|
237 | { | |
238 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
238 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
239 | m_minMargins = new DeclarativeMargins(this); |
|
239 | m_minMargins = new DeclarativeMargins(this); | |
240 | connect(m_minMargins, SIGNAL(topChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); |
|
240 | connect(m_minMargins, SIGNAL(topChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); | |
241 | connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); |
|
241 | connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); | |
242 | connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); |
|
242 | connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); | |
243 | connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); |
|
243 | connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
246 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) | |
247 | { |
|
247 | { | |
248 |
m_chart->setM |
|
248 | m_chart->setMargins(QMargins(left, top, right, bottom)); | |
249 | emit minimumMarginsChanged(); |
|
249 | emit minimumMarginsChanged(); | |
250 | emit plotAreaChanged(m_chart->plotArea()); |
|
250 | emit plotAreaChanged(m_chart->plotArea()); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | DeclarativeChart::~DeclarativeChart() |
|
253 | DeclarativeChart::~DeclarativeChart() | |
254 | { |
|
254 | { | |
255 | delete m_chart; |
|
255 | delete m_chart; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
258 | void DeclarativeChart::childEvent(QChildEvent *event) | |
259 | { |
|
259 | { | |
260 | if (event->type() == QEvent::ChildAdded) { |
|
260 | if (event->type() == QEvent::ChildAdded) { | |
261 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
261 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
262 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
262 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
263 | } |
|
263 | } | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void DeclarativeChart::componentComplete() |
|
267 | void DeclarativeChart::componentComplete() | |
268 | { |
|
268 | { | |
269 | foreach(QObject *child, children()) { |
|
269 | foreach(QObject *child, children()) { | |
270 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
270 | if (qobject_cast<QAbstractSeries *>(child)) { | |
271 | // Add series to the chart |
|
271 | // Add series to the chart | |
272 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
272 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); | |
273 | m_chart->addSeries(series); |
|
273 | m_chart->addSeries(series); | |
274 |
|
274 | |||
275 | // Set optional user defined axes for the series and connect axis related signals |
|
275 | // Set optional user defined axes for the series and connect axis related signals | |
276 | if (qobject_cast<DeclarativeLineSeries *>(child)) { |
|
276 | if (qobject_cast<DeclarativeLineSeries *>(child)) { | |
277 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); |
|
277 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); | |
278 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
278 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
279 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
279 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
280 | setAxisX(s->axisX(), s); |
|
280 | setAxisX(s->axisX(), s); | |
281 | setAxisY(s->axisY(), s); |
|
281 | setAxisY(s->axisY(), s); | |
282 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { |
|
282 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { | |
283 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); |
|
283 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); | |
284 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
284 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
285 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
285 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
286 | setAxisX(s->axisX(), s); |
|
286 | setAxisX(s->axisX(), s); | |
287 | setAxisY(s->axisY(), s); |
|
287 | setAxisY(s->axisY(), s); | |
288 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { |
|
288 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { | |
289 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); |
|
289 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); | |
290 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
290 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
291 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
291 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
292 | setAxisX(s->axisX(), s); |
|
292 | setAxisX(s->axisX(), s); | |
293 | setAxisY(s->axisY(), s); |
|
293 | setAxisY(s->axisY(), s); | |
294 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { |
|
294 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { | |
295 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); |
|
295 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); | |
296 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
296 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
297 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
297 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
298 | setAxisX(s->axisX(), s); |
|
298 | setAxisX(s->axisX(), s); | |
299 | setAxisY(s->axisY(), s); |
|
299 | setAxisY(s->axisY(), s); | |
300 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { |
|
300 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { | |
301 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); |
|
301 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); | |
302 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
302 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
303 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
303 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
304 | setAxisX(s->axisX(), s); |
|
304 | setAxisX(s->axisX(), s); | |
305 | setAxisY(s->axisY(), s); |
|
305 | setAxisY(s->axisY(), s); | |
306 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { |
|
306 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { | |
307 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); |
|
307 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); | |
308 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
308 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
309 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
309 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
310 | setAxisX(s->axisX(), s); |
|
310 | setAxisX(s->axisX(), s); | |
311 | setAxisY(s->axisY(), s); |
|
311 | setAxisY(s->axisY(), s); | |
312 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { |
|
312 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { | |
313 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); |
|
313 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); | |
314 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
314 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
315 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
315 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
316 | setAxisX(s->axisX(), s); |
|
316 | setAxisX(s->axisX(), s); | |
317 | setAxisY(s->axisY(), s); |
|
317 | setAxisY(s->axisY(), s); | |
318 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { |
|
318 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { | |
319 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); |
|
319 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); | |
320 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
320 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
321 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
321 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
322 | setAxisX(s->axisX(), s); |
|
322 | setAxisX(s->axisX(), s); | |
323 | setAxisY(s->axisY(), s); |
|
323 | setAxisY(s->axisY(), s); | |
324 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { |
|
324 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { | |
325 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); |
|
325 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); | |
326 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
326 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
327 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
327 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
328 | setAxisX(s->axisX(), s); |
|
328 | setAxisX(s->axisX(), s); | |
329 | setAxisY(s->axisY(), s); |
|
329 | setAxisY(s->axisY(), s); | |
330 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { |
|
330 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { | |
331 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); |
|
331 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); | |
332 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
332 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
333 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
333 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
334 | setAxisX(s->axisX(), s); |
|
334 | setAxisX(s->axisX(), s); | |
335 | setAxisY(s->axisY(), s); |
|
335 | setAxisY(s->axisY(), s); | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | // Create the missing axes for the series that cannot be painted without axes |
|
340 | // Create the missing axes for the series that cannot be painted without axes | |
341 | foreach (QAbstractSeries *chartSeries, m_chart->series()) |
|
341 | foreach (QAbstractSeries *chartSeries, m_chart->series()) | |
342 | createDefaultAxes(chartSeries); |
|
342 | createDefaultAxes(chartSeries); | |
343 |
|
343 | |||
344 | QDeclarativeItem::componentComplete(); |
|
344 | QDeclarativeItem::componentComplete(); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) |
|
347 | void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) | |
348 | { |
|
348 | { | |
349 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; |
|
349 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; | |
350 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
350 | if (axis && qobject_cast<QAbstractSeries *>(sender())) | |
351 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
351 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); | |
352 | else |
|
352 | else | |
353 | qWarning() << "Trying to set axisX to null."; |
|
353 | qWarning() << "Trying to set axisX to null."; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) |
|
356 | void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) | |
357 | { |
|
357 | { | |
358 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; |
|
358 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; | |
359 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
359 | if (axis && qobject_cast<QAbstractSeries *>(sender())) | |
360 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
360 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); | |
361 | else |
|
361 | else | |
362 | qWarning() << "Trying to set axisY to null."; |
|
362 | qWarning() << "Trying to set axisY to null."; | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
365 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
366 | { |
|
366 | { | |
367 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
367 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
368 | if (newGeometry.isValid()) { |
|
368 | if (newGeometry.isValid()) { | |
369 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
369 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
370 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
370 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
371 | } |
|
371 | } | |
372 | } |
|
372 | } | |
373 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
373 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
374 |
|
374 | |||
375 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
375 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or | |
376 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
376 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is | |
377 | // to implement it here for the QML API purposes. |
|
377 | // to implement it here for the QML API purposes. | |
378 | emit plotAreaChanged(m_chart->plotArea()); |
|
378 | emit plotAreaChanged(m_chart->plotArea()); | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
381 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
382 | { |
|
382 | { | |
383 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
383 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
384 | if (chartTheme != m_chart->theme()) |
|
384 | if (chartTheme != m_chart->theme()) | |
385 | m_chart->setTheme(chartTheme); |
|
385 | m_chart->setTheme(chartTheme); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
388 | DeclarativeChart::Theme DeclarativeChart::theme() | |
389 | { |
|
389 | { | |
390 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
390 | return (DeclarativeChart::Theme) m_chart->theme(); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
393 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
394 | { |
|
394 | { | |
395 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
395 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
396 | if (animationOptions != m_chart->animationOptions()) |
|
396 | if (animationOptions != m_chart->animationOptions()) | |
397 | m_chart->setAnimationOptions(animationOptions); |
|
397 | m_chart->setAnimationOptions(animationOptions); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
400 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
401 | { |
|
401 | { | |
402 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
402 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
403 | return DeclarativeChart::AllAnimations; |
|
403 | return DeclarativeChart::AllAnimations; | |
404 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
404 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
405 | return DeclarativeChart::GridAxisAnimations; |
|
405 | return DeclarativeChart::GridAxisAnimations; | |
406 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
406 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
407 | return DeclarativeChart::SeriesAnimations; |
|
407 | return DeclarativeChart::SeriesAnimations; | |
408 | else |
|
408 | else | |
409 | return DeclarativeChart::NoAnimation; |
|
409 | return DeclarativeChart::NoAnimation; | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | void DeclarativeChart::setTitle(QString title) |
|
412 | void DeclarativeChart::setTitle(QString title) | |
413 | { |
|
413 | { | |
414 | if (title != m_chart->title()) |
|
414 | if (title != m_chart->title()) | |
415 | m_chart->setTitle(title); |
|
415 | m_chart->setTitle(title); | |
416 | } |
|
416 | } | |
417 | QString DeclarativeChart::title() |
|
417 | QString DeclarativeChart::title() | |
418 | { |
|
418 | { | |
419 | return m_chart->title(); |
|
419 | return m_chart->title(); | |
420 | } |
|
420 | } | |
421 |
|
421 | |||
422 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
422 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
423 | { |
|
423 | { | |
424 | return m_chart->axisX(series); |
|
424 | return m_chart->axisX(series); | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
427 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
428 | { |
|
428 | { | |
429 | return m_chart->axisY(series); |
|
429 | return m_chart->axisY(series); | |
430 | } |
|
430 | } | |
431 |
|
431 | |||
432 | QLegend *DeclarativeChart::legend() |
|
432 | QLegend *DeclarativeChart::legend() | |
433 | { |
|
433 | { | |
434 | return m_chart->legend(); |
|
434 | return m_chart->legend(); | |
435 | } |
|
435 | } | |
436 |
|
436 | |||
437 | void DeclarativeChart::setTitleColor(QColor color) |
|
437 | void DeclarativeChart::setTitleColor(QColor color) | |
438 | { |
|
438 | { | |
439 | QBrush b = m_chart->titleBrush(); |
|
439 | QBrush b = m_chart->titleBrush(); | |
440 | if (color != b.color()) { |
|
440 | if (color != b.color()) { | |
441 | b.setColor(color); |
|
441 | b.setColor(color); | |
442 | m_chart->setTitleBrush(b); |
|
442 | m_chart->setTitleBrush(b); | |
443 | emit titleColorChanged(color); |
|
443 | emit titleColorChanged(color); | |
444 | } |
|
444 | } | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | QFont DeclarativeChart::titleFont() const |
|
447 | QFont DeclarativeChart::titleFont() const | |
448 | { |
|
448 | { | |
449 | return m_chart->titleFont(); |
|
449 | return m_chart->titleFont(); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
452 | void DeclarativeChart::setTitleFont(const QFont& font) | |
453 | { |
|
453 | { | |
454 | m_chart->setTitleFont(font); |
|
454 | m_chart->setTitleFont(font); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QColor DeclarativeChart::titleColor() |
|
457 | QColor DeclarativeChart::titleColor() | |
458 | { |
|
458 | { | |
459 | return m_chart->titleBrush().color(); |
|
459 | return m_chart->titleBrush().color(); | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
462 | void DeclarativeChart::setBackgroundColor(QColor color) | |
463 | { |
|
463 | { | |
464 | QBrush b = m_chart->backgroundBrush(); |
|
464 | QBrush b = m_chart->backgroundBrush(); | |
465 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
465 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
466 | b.setStyle(Qt::SolidPattern); |
|
466 | b.setStyle(Qt::SolidPattern); | |
467 | b.setColor(color); |
|
467 | b.setColor(color); | |
468 | m_chart->setBackgroundBrush(b); |
|
468 | m_chart->setBackgroundBrush(b); | |
469 | emit backgroundColorChanged(); |
|
469 | emit backgroundColorChanged(); | |
470 | } |
|
470 | } | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | QColor DeclarativeChart::backgroundColor() |
|
473 | QColor DeclarativeChart::backgroundColor() | |
474 | { |
|
474 | { | |
475 | return m_chart->backgroundBrush().color(); |
|
475 | return m_chart->backgroundBrush().color(); | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | int DeclarativeChart::count() |
|
478 | int DeclarativeChart::count() | |
479 | { |
|
479 | { | |
480 | return m_chart->series().count(); |
|
480 | return m_chart->series().count(); | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
483 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
484 | { |
|
484 | { | |
485 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
485 | if (enabled != m_chart->isDropShadowEnabled()) { | |
486 | m_chart->setDropShadowEnabled(enabled); |
|
486 | m_chart->setDropShadowEnabled(enabled); | |
487 | dropShadowEnabledChanged(enabled); |
|
487 | dropShadowEnabledChanged(enabled); | |
488 | } |
|
488 | } | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | bool DeclarativeChart::dropShadowEnabled() |
|
491 | bool DeclarativeChart::dropShadowEnabled() | |
492 | { |
|
492 | { | |
493 | return m_chart->isDropShadowEnabled(); |
|
493 | return m_chart->isDropShadowEnabled(); | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 | qreal DeclarativeChart::topMargin() |
|
496 | qreal DeclarativeChart::topMargin() | |
497 | { |
|
497 | { | |
498 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
498 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; | |
499 | return m_chart->plotArea().top(); |
|
499 | return m_chart->plotArea().top(); | |
500 | } |
|
500 | } | |
501 |
|
501 | |||
502 | qreal DeclarativeChart::bottomMargin() |
|
502 | qreal DeclarativeChart::bottomMargin() | |
503 | { |
|
503 | { | |
|
504 | ||||
504 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
505 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; | |
505 | return m_chart->plotArea().bottom(); |
|
506 | return m_chart->plotArea().bottom(); | |
506 | } |
|
507 | } | |
507 |
|
508 | |||
508 | qreal DeclarativeChart::leftMargin() |
|
509 | qreal DeclarativeChart::leftMargin() | |
509 | { |
|
510 | { | |
510 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
511 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; | |
511 | return m_chart->plotArea().left(); |
|
512 | return m_chart->plotArea().left(); | |
512 | } |
|
513 | } | |
513 |
|
514 | |||
514 | qreal DeclarativeChart::rightMargin() |
|
515 | qreal DeclarativeChart::rightMargin() | |
515 | { |
|
516 | { | |
516 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
517 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; | |
517 | return m_chart->plotArea().right(); |
|
518 | return m_chart->plotArea().right(); | |
518 | } |
|
519 | } | |
519 |
|
520 | |||
520 | void DeclarativeChart::zoom(qreal factor) |
|
521 | void DeclarativeChart::zoom(qreal factor) | |
521 | { |
|
522 | { | |
522 | m_chart->zoom(factor); |
|
523 | m_chart->zoom(factor); | |
523 | } |
|
524 | } | |
524 |
|
525 | |||
525 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
526 | void DeclarativeChart::scrollLeft(qreal pixels) | |
526 | { |
|
527 | { | |
527 | m_chart->scroll(-pixels, 0); |
|
528 | m_chart->scroll(-pixels, 0); | |
528 | } |
|
529 | } | |
529 |
|
530 | |||
530 | void DeclarativeChart::scrollRight(qreal pixels) |
|
531 | void DeclarativeChart::scrollRight(qreal pixels) | |
531 | { |
|
532 | { | |
532 | m_chart->scroll(pixels, 0); |
|
533 | m_chart->scroll(pixels, 0); | |
533 | } |
|
534 | } | |
534 |
|
535 | |||
535 | void DeclarativeChart::scrollUp(qreal pixels) |
|
536 | void DeclarativeChart::scrollUp(qreal pixels) | |
536 | { |
|
537 | { | |
537 | m_chart->scroll(0, pixels); |
|
538 | m_chart->scroll(0, pixels); | |
538 | } |
|
539 | } | |
539 |
|
540 | |||
540 | void DeclarativeChart::scrollDown(qreal pixels) |
|
541 | void DeclarativeChart::scrollDown(qreal pixels) | |
541 | { |
|
542 | { | |
542 | m_chart->scroll(0, -pixels); |
|
543 | m_chart->scroll(0, -pixels); | |
543 | } |
|
544 | } | |
544 |
|
545 | |||
545 | QAbstractSeries *DeclarativeChart::series(int index) |
|
546 | QAbstractSeries *DeclarativeChart::series(int index) | |
546 | { |
|
547 | { | |
547 | if (index < m_chart->series().count()) { |
|
548 | if (index < m_chart->series().count()) { | |
548 | return m_chart->series().at(index); |
|
549 | return m_chart->series().at(index); | |
549 | } |
|
550 | } | |
550 | return 0; |
|
551 | return 0; | |
551 | } |
|
552 | } | |
552 |
|
553 | |||
553 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
554 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
554 | { |
|
555 | { | |
555 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
556 | foreach(QAbstractSeries *series, m_chart->series()) { | |
556 | if (series->name() == seriesName) |
|
557 | if (series->name() == seriesName) | |
557 | return series; |
|
558 | return series; | |
558 | } |
|
559 | } | |
559 | return 0; |
|
560 | return 0; | |
560 | } |
|
561 | } | |
561 |
|
562 | |||
562 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
563 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
563 | { |
|
564 | { | |
564 | return createSeries(type, name, 0, 0); |
|
565 | return createSeries(type, name, 0, 0); | |
565 | } |
|
566 | } | |
566 |
|
567 | |||
567 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
568 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) | |
568 | { |
|
569 | { | |
569 | QAbstractSeries *series = 0; |
|
570 | QAbstractSeries *series = 0; | |
570 |
|
571 | |||
571 | switch (type) { |
|
572 | switch (type) { | |
572 | case DeclarativeChart::SeriesTypeLine: |
|
573 | case DeclarativeChart::SeriesTypeLine: | |
573 | series = new DeclarativeLineSeries(); |
|
574 | series = new DeclarativeLineSeries(); | |
574 | break; |
|
575 | break; | |
575 | case DeclarativeChart::SeriesTypeArea: |
|
576 | case DeclarativeChart::SeriesTypeArea: | |
576 | series = new DeclarativeAreaSeries(); |
|
577 | series = new DeclarativeAreaSeries(); | |
577 | break; |
|
578 | break; | |
578 | case DeclarativeChart::SeriesTypeStackedBar: |
|
579 | case DeclarativeChart::SeriesTypeStackedBar: | |
579 | series = new DeclarativeStackedBarSeries(); |
|
580 | series = new DeclarativeStackedBarSeries(); | |
580 | break; |
|
581 | break; | |
581 | case DeclarativeChart::SeriesTypePercentBar: |
|
582 | case DeclarativeChart::SeriesTypePercentBar: | |
582 | series = new DeclarativePercentBarSeries(); |
|
583 | series = new DeclarativePercentBarSeries(); | |
583 | break; |
|
584 | break; | |
584 | case DeclarativeChart::SeriesTypeBar: |
|
585 | case DeclarativeChart::SeriesTypeBar: | |
585 | series = new DeclarativeBarSeries(); |
|
586 | series = new DeclarativeBarSeries(); | |
586 | break; |
|
587 | break; | |
587 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
588 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
588 | series = new DeclarativeHorizontalBarSeries(); |
|
589 | series = new DeclarativeHorizontalBarSeries(); | |
589 | break; |
|
590 | break; | |
590 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
591 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
591 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
592 | series = new DeclarativeHorizontalPercentBarSeries(); | |
592 | break; |
|
593 | break; | |
593 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
594 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
594 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
595 | series = new DeclarativeHorizontalStackedBarSeries(); | |
595 | break; |
|
596 | break; | |
596 | case DeclarativeChart::SeriesTypePie: |
|
597 | case DeclarativeChart::SeriesTypePie: | |
597 | series = new DeclarativePieSeries(); |
|
598 | series = new DeclarativePieSeries(); | |
598 | break; |
|
599 | break; | |
599 | case DeclarativeChart::SeriesTypeScatter: |
|
600 | case DeclarativeChart::SeriesTypeScatter: | |
600 | series = new DeclarativeScatterSeries(); |
|
601 | series = new DeclarativeScatterSeries(); | |
601 | break; |
|
602 | break; | |
602 | case DeclarativeChart::SeriesTypeSpline: |
|
603 | case DeclarativeChart::SeriesTypeSpline: | |
603 | series = new DeclarativeSplineSeries(); |
|
604 | series = new DeclarativeSplineSeries(); | |
604 | break; |
|
605 | break; | |
605 | default: |
|
606 | default: | |
606 | qWarning() << "Illegal series type"; |
|
607 | qWarning() << "Illegal series type"; | |
607 | } |
|
608 | } | |
608 |
|
609 | |||
609 | if (series) { |
|
610 | if (series) { | |
610 | series->setName(name); |
|
611 | series->setName(name); | |
611 | m_chart->addSeries(series); |
|
612 | m_chart->addSeries(series); | |
612 | // Set possible user defined axes |
|
613 | // Set possible user defined axes | |
613 | setAxisX(axisX, series); |
|
614 | setAxisX(axisX, series); | |
614 | setAxisY(axisY, series); |
|
615 | setAxisY(axisY, series); | |
615 | // Then create the missing axes |
|
616 | // Then create the missing axes | |
616 | createDefaultAxes(series); |
|
617 | createDefaultAxes(series); | |
617 | } |
|
618 | } | |
618 |
|
619 | |||
619 | return series; |
|
620 | return series; | |
620 | } |
|
621 | } | |
621 |
|
622 | |||
622 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
623 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
623 | { |
|
624 | { | |
624 | if (axis) |
|
625 | if (axis) | |
625 | m_chart->setAxisX(axis, series); |
|
626 | m_chart->setAxisX(axis, series); | |
626 | } |
|
627 | } | |
627 |
|
628 | |||
628 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
629 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
629 | { |
|
630 | { | |
630 | if (axis) |
|
631 | if (axis) | |
631 | m_chart->setAxisY(axis, series); |
|
632 | m_chart->setAxisY(axis, series); | |
632 | } |
|
633 | } | |
633 |
|
634 | |||
634 | void DeclarativeChart::createDefaultAxes() |
|
635 | void DeclarativeChart::createDefaultAxes() | |
635 | { |
|
636 | { | |
636 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
637 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; | |
637 | } |
|
638 | } | |
638 |
|
639 | |||
639 | void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) |
|
640 | void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) | |
640 | { |
|
641 | { | |
641 | foreach (QAbstractSeries *s, m_chart->series()) { |
|
642 | foreach (QAbstractSeries *s, m_chart->series()) { | |
642 | // If there is already an x axis of the correct type, re-use it |
|
643 | // If there is already an x axis of the correct type, re-use it | |
643 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) |
|
644 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) | |
644 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
645 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) | |
645 | m_chart->setAxisX(m_chart->axisX(s), series); |
|
646 | m_chart->setAxisX(m_chart->axisX(s), series); | |
646 |
|
647 | |||
647 | // If there is already a y axis of the correct type, re-use it |
|
648 | // If there is already a y axis of the correct type, re-use it | |
648 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) |
|
649 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) | |
649 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) |
|
650 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) | |
650 | m_chart->setAxisY(m_chart->axisY(s), series); |
|
651 | m_chart->setAxisY(m_chart->axisY(s), series); | |
651 | } |
|
652 | } | |
652 |
|
653 | |||
653 | // If no x axis of correct type was found, create a new x axis based of default axis type |
|
654 | // If no x axis of correct type was found, create a new x axis based of default axis type | |
654 | if (!m_chart->axisX(series)) { |
|
655 | if (!m_chart->axisX(series)) { | |
655 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { |
|
656 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { | |
656 | case QAbstractAxis::AxisTypeValue: |
|
657 | case QAbstractAxis::AxisTypeValue: | |
657 | m_chart->setAxisX(new QValueAxis(this), series); |
|
658 | m_chart->setAxisX(new QValueAxis(this), series); | |
658 | break; |
|
659 | break; | |
659 | case QAbstractAxis::AxisTypeBarCategory: |
|
660 | case QAbstractAxis::AxisTypeBarCategory: | |
660 | m_chart->setAxisX(new QBarCategoryAxis(this), series); |
|
661 | m_chart->setAxisX(new QBarCategoryAxis(this), series); | |
661 | break; |
|
662 | break; | |
662 | case QAbstractAxis::AxisTypeCategory: |
|
663 | case QAbstractAxis::AxisTypeCategory: | |
663 | m_chart->setAxisX(new QCategoryAxis(this), series); |
|
664 | m_chart->setAxisX(new QCategoryAxis(this), series); | |
664 | break; |
|
665 | break; | |
665 | #ifndef QT_ON_ARM |
|
666 | #ifndef QT_ON_ARM | |
666 | case QAbstractAxis::AxisTypeDateTime: |
|
667 | case QAbstractAxis::AxisTypeDateTime: | |
667 | m_chart->setAxisX(new QDateTimeAxis(this), series); |
|
668 | m_chart->setAxisX(new QDateTimeAxis(this), series); | |
668 | break; |
|
669 | break; | |
669 | #endif |
|
670 | #endif | |
670 | default: |
|
671 | default: | |
671 | // Do nothing, assume AxisTypeNoAxis |
|
672 | // Do nothing, assume AxisTypeNoAxis | |
672 | break; |
|
673 | break; | |
673 | } |
|
674 | } | |
674 | } |
|
675 | } | |
675 |
|
676 | |||
676 | // If no y axis of correct type was found, create a new y axis based of default axis type |
|
677 | // If no y axis of correct type was found, create a new y axis based of default axis type | |
677 | if (!m_chart->axisY(series)) { |
|
678 | if (!m_chart->axisY(series)) { | |
678 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { |
|
679 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { | |
679 | case QAbstractAxis::AxisTypeValue: |
|
680 | case QAbstractAxis::AxisTypeValue: | |
680 | m_chart->setAxisY(new QValueAxis(this), series); |
|
681 | m_chart->setAxisY(new QValueAxis(this), series); | |
681 | break; |
|
682 | break; | |
682 | case QAbstractAxis::AxisTypeBarCategory: |
|
683 | case QAbstractAxis::AxisTypeBarCategory: | |
683 | m_chart->setAxisY(new QBarCategoryAxis(this), series); |
|
684 | m_chart->setAxisY(new QBarCategoryAxis(this), series); | |
684 | break; |
|
685 | break; | |
685 | case QAbstractAxis::AxisTypeCategory: |
|
686 | case QAbstractAxis::AxisTypeCategory: | |
686 | m_chart->setAxisY(new QCategoryAxis(this), series); |
|
687 | m_chart->setAxisY(new QCategoryAxis(this), series); | |
687 | break; |
|
688 | break; | |
688 | #ifndef QT_ON_ARM |
|
689 | #ifndef QT_ON_ARM | |
689 | case QAbstractAxis::AxisTypeDateTime: |
|
690 | case QAbstractAxis::AxisTypeDateTime: | |
690 | m_chart->setAxisY(new QDateTimeAxis(this), series); |
|
691 | m_chart->setAxisY(new QDateTimeAxis(this), series); | |
691 | break; |
|
692 | break; | |
692 | #endif |
|
693 | #endif | |
693 | default: |
|
694 | default: | |
694 | // Do nothing, assume AxisTypeNoAxis |
|
695 | // Do nothing, assume AxisTypeNoAxis | |
695 | break; |
|
696 | break; | |
696 | } |
|
697 | } | |
697 | } |
|
698 | } | |
698 |
|
699 | |||
699 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); |
|
700 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); | |
700 | } |
|
701 | } | |
701 |
|
702 | |||
702 | #include "moc_declarativechart.cpp" |
|
703 | #include "moc_declarativechart.cpp" | |
703 |
|
704 | |||
704 | QTCOMMERCIALCHART_END_NAMESPACE |
|
705 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,139 +1,139 | |||||
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 "axisanimation_p.h" |
|
21 | #include "axisanimation_p.h" | |
22 | #include "chartaxis_p.h" |
|
22 | #include "chartaxis_p.h" | |
|
23 | #include "chartpresenter_p.h" | |||
23 | #include <QTimer> |
|
24 | #include <QTimer> | |
24 | #include <QDebug> |
|
25 | #include <QDebug> | |
25 |
|
26 | |||
26 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
27 | Q_DECLARE_METATYPE(QVector<qreal>) | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 |
|
31 | |||
31 | AxisAnimation::AxisAnimation(ChartAxis *axis): ChartAnimation(axis), |
|
32 | AxisAnimation::AxisAnimation(ChartAxis *axis): ChartAnimation(axis), | |
32 | m_axis(axis), |
|
33 | m_axis(axis), | |
33 | m_type(DefaultAnimation) |
|
34 | m_type(DefaultAnimation) | |
34 | { |
|
35 | { | |
35 | setDuration(ChartAnimationDuration); |
|
36 | setDuration(ChartAnimationDuration); | |
36 | setEasingCurve(QEasingCurve::OutQuart); |
|
37 | setEasingCurve(QEasingCurve::OutQuart); | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | AxisAnimation::~AxisAnimation() |
|
40 | AxisAnimation::~AxisAnimation() | |
40 | { |
|
41 | { | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | void AxisAnimation::setAnimationType(Animation type) |
|
44 | void AxisAnimation::setAnimationType(Animation type) | |
44 | { |
|
45 | { | |
45 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
46 | if (state() != QAbstractAnimation::Stopped) stop(); | |
46 | m_type=type; |
|
47 | m_type=type; | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | void AxisAnimation::setAnimationPoint(const QPointF& point) |
|
50 | void AxisAnimation::setAnimationPoint(const QPointF& point) | |
50 | { |
|
51 | { | |
51 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
52 | if (state() != QAbstractAnimation::Stopped) stop(); | |
52 | m_point=point; |
|
53 | m_point=point; | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 | void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout) |
|
56 | void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout) | |
56 | { |
|
57 | { | |
57 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
58 | if (state() != QAbstractAnimation::Stopped) stop(); | |
58 |
|
59 | |||
59 | if (newLayout.count() == 0) |
|
60 | if (newLayout.count() == 0) | |
60 | return; |
|
61 | return; | |
61 |
|
62 | |||
62 | switch (m_type) { |
|
63 | switch (m_type) { | |
63 | case ZoomOutAnimation: { |
|
64 | case ZoomOutAnimation: { | |
64 |
QRectF rect = m_axis-> |
|
65 | QRectF rect = m_axis->presenter()->chartsGeometry(); | |
65 | oldLayout.resize(newLayout.count()); |
|
66 | oldLayout.resize(newLayout.count()); | |
66 |
|
67 | |||
67 | for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { |
|
68 | for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { | |
68 | oldLayout[i] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.bottom(); |
|
69 | oldLayout[i] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.bottom(); | |
69 | oldLayout[j] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.right() : rect.top(); |
|
70 | oldLayout[j] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.right() : rect.top(); | |
70 | } |
|
71 | } | |
71 | } |
|
72 | } | |
72 | break; |
|
73 | break; | |
73 | case ZoomInAnimation: { |
|
74 | case ZoomInAnimation: { | |
74 | int index = qMin(oldLayout.count() * (m_axis->axisType() == ChartAxis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); |
|
75 | int index = qMin(oldLayout.count() * (m_axis->axisType() == ChartAxis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); | |
75 | oldLayout.resize(newLayout.count()); |
|
76 | oldLayout.resize(newLayout.count()); | |
76 |
|
77 | |||
77 | for(int i = 0; i < oldLayout.count(); i++) |
|
78 | for(int i = 0; i < oldLayout.count(); i++) | |
78 | oldLayout[i]= oldLayout[index]; |
|
79 | oldLayout[i]= oldLayout[index]; | |
79 | } |
|
80 | } | |
80 | break; |
|
81 | break; | |
81 | case MoveForwardAnimation: { |
|
82 | case MoveForwardAnimation: { | |
82 | oldLayout.resize(newLayout.count()); |
|
83 | oldLayout.resize(newLayout.count()); | |
83 |
|
84 | |||
84 | for(int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) |
|
85 | for(int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) | |
85 | oldLayout[i]= oldLayout[j]; |
|
86 | oldLayout[i]= oldLayout[j]; | |
86 | } |
|
87 | } | |
87 | break; |
|
88 | break; | |
88 | case MoveBackwordAnimation: { |
|
89 | case MoveBackwordAnimation: { | |
89 | oldLayout.resize(newLayout.count()); |
|
90 | oldLayout.resize(newLayout.count()); | |
90 |
|
91 | |||
91 | for(int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) |
|
92 | for(int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) | |
92 | oldLayout[i]= oldLayout[j]; |
|
93 | oldLayout[i]= oldLayout[j]; | |
93 | } |
|
94 | } | |
94 | break; |
|
95 | break; | |
95 | default: { |
|
96 | default: { | |
96 | oldLayout.resize(newLayout.count()); |
|
97 | oldLayout.resize(newLayout.count()); | |
97 |
QRectF rect = m_axis-> |
|
98 | QRectF rect = m_axis->presenter()->chartsGeometry(); | |
98 | for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) |
|
99 | for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) | |
99 | oldLayout[i] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.top(); |
|
100 | oldLayout[i] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.top(); | |
100 | } |
|
101 | } | |
101 | break; |
|
102 | break; | |
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 | QVariantAnimation::KeyValues value; |
|
105 | QVariantAnimation::KeyValues value; | |
105 | setKeyValues(value); //workaround for wrong interpolation call |
|
106 | setKeyValues(value); //workaround for wrong interpolation call | |
106 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
107 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
107 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
108 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
108 | } |
|
109 | } | |
109 |
|
110 | |||
110 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const |
|
111 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const | |
111 | { |
|
112 | { | |
112 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); |
|
113 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); | |
113 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); |
|
114 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); | |
114 | QVector<qreal> result; |
|
115 | QVector<qreal> result; | |
115 |
|
116 | |||
116 | Q_ASSERT(startVector.count() == endVecotr.count()) ; |
|
117 | Q_ASSERT(startVector.count() == endVecotr.count()) ; | |
117 |
|
118 | |||
118 | for(int i = 0; i < startVector.count(); i++){ |
|
119 | for(int i = 0; i < startVector.count(); i++){ | |
119 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); |
|
120 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); | |
120 | result << value; |
|
121 | result << value; | |
121 | } |
|
122 | } | |
122 | return qVariantFromValue(result); |
|
123 | return qVariantFromValue(result); | |
123 | } |
|
124 | } | |
124 |
|
125 | |||
125 |
|
126 | |||
126 | void AxisAnimation::updateCurrentValue (const QVariant &value ) |
|
127 | void AxisAnimation::updateCurrentValue (const QVariant &value ) | |
127 | { |
|
128 | { | |
128 | if (state() != QAbstractAnimation::Stopped)//workaround |
|
129 | if (state() != QAbstractAnimation::Stopped)//workaround | |
129 | { |
|
130 | { | |
130 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); |
|
131 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); | |
131 | Q_ASSERT(vector.count() != 0); |
|
132 | Q_ASSERT(vector.count() != 0); | |
132 | m_axis->setLayout(vector); |
|
133 | m_axis->setLayout(vector); | |
133 | m_axis->updateGeometry(); |
|
134 | m_axis->updateGeometry(); | |
134 | m_axis->checkLayout(); |
|
|||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | QTCOMMERCIALCHART_END_NAMESPACE |
|
139 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,161 +1,200 | |||||
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 "chartbarcategoryaxisx_p.h" |
|
21 | #include "chartbarcategoryaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qbarcategoryaxis_p.h" |
|
23 | #include "qbarcategoryaxis_p.h" | |
|
24 | #include <QFontMetrics> | |||
24 | #include <QDebug> |
|
25 | #include <QDebug> | |
25 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
26 |
|
27 | |||
27 | static int label_padding = 5; |
|
28 | static int label_padding = 5; | |
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
32 | ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
32 | m_categoriesAxis(axis) |
|
33 | m_categoriesAxis(axis) | |
33 | { |
|
34 | { | |
34 |
|
35 | |||
35 | } |
|
36 | } | |
36 |
|
37 | |||
37 | ChartBarCategoryAxisX::~ChartBarCategoryAxisX() |
|
38 | ChartBarCategoryAxisX::~ChartBarCategoryAxisX() | |
38 | { |
|
39 | { | |
39 | } |
|
40 | } | |
40 |
|
41 | |||
41 | QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const |
|
42 | QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const | |
42 | { |
|
43 | { | |
43 | int count = m_categoriesAxis->d_ptr->count(); |
|
44 | int count = m_categoriesAxis->d_ptr->count(); | |
44 |
|
45 | |||
45 | Q_ASSERT(count>=1); |
|
46 | Q_ASSERT(count>=1); | |
46 |
|
47 | |||
47 | QVector<qreal> points; |
|
48 | QVector<qreal> points; | |
48 | points.resize(count+2); |
|
49 | points.resize(count+2); | |
49 |
|
50 | |||
50 | const qreal delta = m_rect.width()/(count); |
|
51 | QRectF rect = presenter()->chartsGeometry(); | |
|
52 | ||||
|
53 | const qreal delta = rect.width()/(count); | |||
51 | qreal offset =-m_min-0.5; |
|
54 | qreal offset =-m_min-0.5; | |
52 |
|
55 | |||
53 | if(delta<1) return points; |
|
56 | if(delta<1) return points; | |
54 |
|
57 | |||
55 | if(offset<=0) { |
|
58 | if(offset<=0) { | |
56 |
offset = int(offset * |
|
59 | offset = int(offset * rect.width()/(m_max - m_min))%int(delta) + delta; | |
57 | } |
|
60 | } | |
58 | else { |
|
61 | else { | |
59 |
offset = int(offset * |
|
62 | offset = int(offset * rect.width()/(m_max - m_min))%int(delta); | |
60 | } |
|
63 | } | |
61 |
|
64 | |||
62 |
points[0] = |
|
65 | points[0] = rect.left(); | |
63 |
points[count+1] = |
|
66 | points[count+1] = rect.right(); | |
64 |
|
67 | |||
65 | for (int i = 0; i < count; ++i) { |
|
68 | for (int i = 0; i < count; ++i) { | |
66 |
qreal x = offset + i * delta + |
|
69 | qreal x = offset + i * delta + rect.left(); | |
67 | points[i+1] = x; |
|
70 | points[i+1] = x; | |
68 | } |
|
71 | } | |
69 | return points; |
|
72 | return points; | |
70 | } |
|
73 | } | |
71 |
|
74 | |||
72 | QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const |
|
75 | QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const | |
73 | { |
|
76 | { | |
74 | QStringList result; |
|
77 | QStringList result; | |
75 | qreal d = (m_max - m_min)/m_rect.width(); |
|
78 | QRectF rect = presenter()->chartsGeometry(); | |
|
79 | qreal d = (m_max - m_min)/rect.width(); | |||
76 | for (int i = 0;i < layout.count()-1; ++i) { |
|
80 | for (int i = 0;i < layout.count()-1; ++i) { | |
77 |
qreal x = qFloor((((layout[i+1] + layout[i])/2- |
|
81 | qreal x = qFloor((((layout[i+1] + layout[i])/2-rect.left())*d + m_min+0.5)); | |
78 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { |
|
82 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { | |
79 | result << m_categoriesAxis->categories().at(x); |
|
83 | result << m_categoriesAxis->categories().at(x); | |
80 | } |
|
84 | } | |
81 | else { |
|
85 | else { | |
82 | // No label for x coordinate |
|
86 | // No label for x coordinate | |
83 | result << ""; |
|
87 | result << ""; | |
84 | } |
|
88 | } | |
85 | } |
|
89 | } | |
86 | result << ""; |
|
90 | result << ""; | |
87 | return result; |
|
91 | return result; | |
88 | } |
|
92 | } | |
89 |
|
93 | |||
90 |
|
94 | |||
91 | void ChartBarCategoryAxisX::updateGeometry() |
|
95 | void ChartBarCategoryAxisX::updateGeometry() | |
92 | { |
|
96 | { | |
93 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
97 | const QVector<qreal>& layout = ChartAxis::layout(); | |
94 |
|
98 | |||
95 | m_minWidth = 0; |
|
|||
96 | m_minHeight = 0; |
|
|||
97 |
|
||||
98 | if(layout.isEmpty()) return; |
|
99 | if(layout.isEmpty()) return; | |
99 |
|
100 | |||
100 | QStringList ticksList = createCategoryLabels(layout); |
|
101 | QStringList ticksList = createCategoryLabels(layout); | |
101 |
|
102 | |||
102 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
103 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
103 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
104 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
104 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
105 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
105 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
106 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
106 |
|
107 | |||
107 | Q_ASSERT(labels.size() == ticksList.size()); |
|
108 | Q_ASSERT(labels.size() == ticksList.size()); | |
108 | Q_ASSERT(layout.size() == ticksList.size()); |
|
109 | Q_ASSERT(layout.size() == ticksList.size()); | |
109 |
|
110 | |||
110 | const qreal delta = m_rect.width()/(m_categoriesAxis->d_ptr->count()); |
|
111 | QRectF chartRect = presenter()->chartsGeometry(); | |
|
112 | ||||
|
113 | const qreal delta = chartRect.width()/(m_categoriesAxis->d_ptr->count()); | |||
111 |
|
114 | |||
112 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
115 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
113 |
lineItem->setLine( |
|
116 | lineItem->setLine( chartRect.left(), chartRect.bottom(), chartRect.right(), chartRect.bottom()); | |
114 |
|
117 | |||
115 |
qreal width = |
|
118 | qreal width = chartRect.left(); | |
116 | for (int i = 0; i < layout.size(); ++i) { |
|
119 | for (int i = 0; i < layout.size(); ++i) { | |
117 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
120 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
118 |
lineItem->setLine(layout[i], |
|
121 | lineItem->setLine(layout[i], chartRect.top(), layout[i], chartRect.bottom()); | |
119 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
122 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
120 | labelItem->setText(ticksList.at(i)); |
|
123 | labelItem->setText(ticksList.at(i)); | |
121 | const QRectF& rect = labelItem->boundingRect(); |
|
124 | const QRectF& rect = labelItem->boundingRect(); | |
122 | QPointF center = rect.center(); |
|
125 | QPointF center = rect.center(); | |
123 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
126 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
124 |
|
127 | |||
125 | if(i==0){ |
|
128 | if(i==0){ | |
126 |
labelItem->setPos(layout[i+1] - (delta)/2 - center.x(), |
|
129 | labelItem->setPos(layout[i+1] - (delta)/2 - center.x(), chartRect.bottom() + label_padding); | |
127 | }else{ |
|
130 | }else{ | |
128 |
labelItem->setPos(layout[i] + (delta)/2 - center.x(), |
|
131 | labelItem->setPos(layout[i] + (delta)/2 - center.x(), chartRect.bottom() + label_padding); | |
129 | } |
|
132 | } | |
130 |
|
133 | |||
131 |
if(labelItem->pos().x()<=width || labelItem->pos().x()+ rect.width()> |
|
134 | if(labelItem->pos().x()<=width || labelItem->pos().x()+ rect.width()> chartRect.right()) { | |
132 | labelItem->setVisible(false); |
|
135 | labelItem->setVisible(false); | |
133 | } |
|
136 | } | |
134 | else { |
|
137 | else { | |
135 | labelItem->setVisible(true); |
|
138 | labelItem->setVisible(true); | |
136 | width=rect.width()+labelItem->pos().x(); |
|
139 | width=rect.width()+labelItem->pos().x(); | |
137 | } |
|
140 | } | |
138 |
|
141 | |||
139 | m_minWidth+=rect.width(); |
|
|||
140 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); |
|
|||
141 |
|
||||
142 | if ((i+1)%2 && i>1) { |
|
142 | if ((i+1)%2 && i>1) { | |
143 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
143 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
144 |
rectItem->setRect(layout[i-1], |
|
144 | rectItem->setRect(layout[i-1], chartRect.top(),layout[i]-layout[i-1], chartRect.height()); | |
145 | } |
|
145 | } | |
146 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
146 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
147 |
lineItem->setLine(layout[i], |
|
147 | lineItem->setLine(layout[i], chartRect.bottom(),layout[i], chartRect.bottom()+5); | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void ChartBarCategoryAxisX::handleAxisUpdated() |
|
151 | void ChartBarCategoryAxisX::handleAxisUpdated() | |
152 | { |
|
152 | { | |
153 | if(m_categoriesAxis->categories()!=m_categories) |
|
153 | if(m_categoriesAxis->categories()!=m_categories) | |
154 | { |
|
154 | { | |
155 | m_categories=m_categoriesAxis->categories(); |
|
155 | m_categories=m_categoriesAxis->categories(); | |
156 | if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry(); |
|
156 | if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry(); | |
157 | } |
|
157 | } | |
158 | ChartAxis::handleAxisUpdated(); |
|
158 | ChartAxis::handleAxisUpdated(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
|
161 | QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
162 | { | |||
|
163 | Q_UNUSED(constraint) | |||
|
164 | ||||
|
165 | QFontMetrics fn(m_font); | |||
|
166 | QSizeF sh; | |||
|
167 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |||
|
168 | QStringList ticksList = createCategoryLabels(ChartAxis::layout()); | |||
|
169 | qreal width=0; | |||
|
170 | qreal height=0; | |||
|
171 | ||||
|
172 | switch (which) { | |||
|
173 | case Qt::MinimumSize: | |||
|
174 | width = fn.boundingRect("...").width(); | |||
|
175 | height = fn.height()+label_padding; | |||
|
176 | width=qMax(width,base.width()); | |||
|
177 | height+=base.height(); | |||
|
178 | sh = QSizeF(width,height); | |||
|
179 | break; | |||
|
180 | case Qt::PreferredSize:{ | |||
|
181 | ||||
|
182 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
183 | { | |||
|
184 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |||
|
185 | width+=rect.width(); | |||
|
186 | height=qMax(rect.height()+label_padding,height); | |||
|
187 | } | |||
|
188 | width=qMax(width,base.width()); | |||
|
189 | height+=base.height(); | |||
|
190 | sh = QSizeF(width,height); | |||
|
191 | break; | |||
|
192 | } | |||
|
193 | default: | |||
|
194 | break; | |||
|
195 | } | |||
|
196 | ||||
|
197 | return sh; | |||
|
198 | } | |||
|
199 | ||||
161 | QTCOMMERCIALCHART_END_NAMESPACE |
|
200 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,64 +1,64 | |||||
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 CHARTBARCATEGORYAXISX_H |
|
30 | #ifndef CHARTBARCATEGORYAXISX_H | |
31 | #define CHARTBARCATEGORYAXISX_H |
|
31 | #define CHARTBARCATEGORYAXISX_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class QBarCategoryAxis; |
|
39 | class QBarCategoryAxis; | |
40 |
|
40 | |||
41 | class ChartBarCategoryAxisX : public ChartAxis |
|
41 | class ChartBarCategoryAxisX : public ChartAxis | |
42 | { |
|
42 | { | |
43 | public: |
|
43 | public: | |
44 | ChartBarCategoryAxisX(QBarCategoryAxis *axis, ChartPresenter *presenter); |
|
44 | ChartBarCategoryAxisX(QBarCategoryAxis *axis, ChartPresenter *presenter); | |
45 | ~ChartBarCategoryAxisX(); |
|
45 | ~ChartBarCategoryAxisX(); | |
46 |
|
46 | |||
47 | AxisType axisType() const { return X_AXIS;} |
|
47 | AxisType axisType() const { return X_AXIS;} | |
48 |
|
48 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
49 | protected: |
|
49 | protected: | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
52 | private: |
|
52 | private: | |
53 | QStringList createCategoryLabels(const QVector<qreal>& layout) const; |
|
53 | QStringList createCategoryLabels(const QVector<qreal>& layout) const; | |
54 | Q_SLOTS |
|
54 | Q_SLOTS | |
55 | void handleAxisUpdated(); |
|
55 | void handleAxisUpdated(); | |
56 |
|
56 | |||
57 | private: |
|
57 | private: | |
58 | QStringList m_categories; |
|
58 | QStringList m_categories; | |
59 | QBarCategoryAxis *m_categoriesAxis; |
|
59 | QBarCategoryAxis *m_categoriesAxis; | |
60 | }; |
|
60 | }; | |
61 |
|
61 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
62 | QTCOMMERCIALCHART_END_NAMESPACE | |
63 |
|
63 | |||
64 | #endif /* CHARTBARCATEGORYAXISX_H */ |
|
64 | #endif /* CHARTBARCATEGORYAXISX_H */ |
@@ -1,163 +1,202 | |||||
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 "chartbarcategoryaxisy_p.h" |
|
21 | #include "chartbarcategoryaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qbarcategoryaxis_p.h" |
|
23 | #include "qbarcategoryaxis_p.h" | |
24 | #include <qmath.h> |
|
24 | #include <qmath.h> | |
|
25 | #include <QFontMetrics> | |||
25 | #include <QDebug> |
|
26 | #include <QDebug> | |
26 |
|
27 | |||
27 | static int label_padding = 5; |
|
28 | static int label_padding = 5; | |
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
32 | ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
32 | m_categoriesAxis(axis) |
|
33 | m_categoriesAxis(axis) | |
33 | { |
|
34 | { | |
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 | ChartBarCategoryAxisY::~ChartBarCategoryAxisY() |
|
37 | ChartBarCategoryAxisY::~ChartBarCategoryAxisY() | |
37 | { |
|
38 | { | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const |
|
41 | QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const | |
41 | { |
|
42 | { | |
42 | int count = m_categoriesAxis->d_ptr->count(); |
|
43 | int count = m_categoriesAxis->d_ptr->count(); | |
43 |
|
44 | |||
44 | Q_ASSERT(count>=1); |
|
45 | Q_ASSERT(count>=1); | |
45 |
|
46 | |||
46 | QVector<qreal> points; |
|
47 | QVector<qreal> points; | |
47 | points.resize(count+2); |
|
48 | points.resize(count+2); | |
48 |
|
49 | |||
49 | const qreal delta = m_rect.height()/(count); |
|
50 | QRectF rect = presenter()->chartsGeometry(); | |
|
51 | ||||
|
52 | const qreal delta = rect.height()/(count); | |||
50 | qreal offset = - m_min - 0.5; |
|
53 | qreal offset = - m_min - 0.5; | |
51 |
|
54 | |||
52 | if(delta<1) return points; |
|
55 | if(delta<1) return points; | |
53 |
|
56 | |||
54 | if(offset<=0) { |
|
57 | if(offset<=0) { | |
55 |
offset = int(offset * |
|
58 | offset = int(offset * rect.height()/(m_max - m_min))%int(delta) + delta; | |
56 | } |
|
59 | } | |
57 | else { |
|
60 | else { | |
58 |
offset = int(offset * |
|
61 | offset = int(offset * rect.height()/(m_max - m_min))%int(delta); | |
59 | } |
|
62 | } | |
60 |
|
63 | |||
61 |
points[0] = |
|
64 | points[0] = rect.bottom(); | |
62 |
points[count+1] = |
|
65 | points[count+1] = rect.top(); | |
63 |
|
66 | |||
64 | for (int i = 0; i < count; ++i) { |
|
67 | for (int i = 0; i < count; ++i) { | |
65 |
int y = |
|
68 | int y = rect.bottom() - i * delta - offset; | |
66 | points[i+1] = y; |
|
69 | points[i+1] = y; | |
67 | } |
|
70 | } | |
68 | return points; |
|
71 | return points; | |
69 | } |
|
72 | } | |
70 |
|
73 | |||
71 | QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const |
|
74 | QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const | |
72 | { |
|
75 | { | |
73 | QStringList result; |
|
76 | QStringList result; | |
74 | qreal d = (m_max - m_min)/m_rect.height(); |
|
77 | QRectF rect = presenter()->chartsGeometry(); | |
|
78 | qreal d = (m_max - m_min)/rect.height(); | |||
75 | for (int i = 0;i < layout.count()-1; ++i) { |
|
79 | for (int i = 0;i < layout.count()-1; ++i) { | |
76 |
qreal x = qFloor((( |
|
80 | qreal x = qFloor(((rect.height()- (layout[i+1] + layout[i])/2 + rect.top())*d + m_min+0.5)); | |
77 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { |
|
81 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { | |
78 | result << m_categoriesAxis->categories().at(x); |
|
82 | result << m_categoriesAxis->categories().at(x); | |
79 | } |
|
83 | } | |
80 | else { |
|
84 | else { | |
81 | // No label for x coordinate |
|
85 | // No label for x coordinate | |
82 | result << ""; |
|
86 | result << ""; | |
83 | } |
|
87 | } | |
84 | } |
|
88 | } | |
85 | result << ""; |
|
89 | result << ""; | |
86 | return result; |
|
90 | return result; | |
87 | } |
|
91 | } | |
88 |
|
92 | |||
89 | void ChartBarCategoryAxisY::updateGeometry() |
|
93 | void ChartBarCategoryAxisY::updateGeometry() | |
90 | { |
|
94 | { | |
91 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
95 | const QVector<qreal>& layout = ChartAxis::layout(); | |
92 |
|
96 | |||
93 | m_minWidth = 0; |
|
|||
94 | m_minHeight = 0; |
|
|||
95 |
|
||||
96 | if(layout.isEmpty()) return; |
|
97 | if(layout.isEmpty()) return; | |
97 |
|
98 | |||
98 | QStringList ticksList = createCategoryLabels(layout); |
|
99 | QStringList ticksList = createCategoryLabels(layout); | |
99 |
|
100 | |||
100 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
101 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
101 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
102 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
102 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
103 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
103 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
104 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
104 |
|
105 | |||
105 | Q_ASSERT(labels.size() == ticksList.size()); |
|
106 | Q_ASSERT(labels.size() == ticksList.size()); | |
106 | Q_ASSERT(layout.size() == ticksList.size()); |
|
107 | Q_ASSERT(layout.size() == ticksList.size()); | |
107 |
|
108 | |||
108 | const qreal delta = m_rect.height()/(m_categoriesAxis->d_ptr->count()); |
|
109 | QRectF chartRect = presenter()->chartsGeometry(); | |
|
110 | ||||
|
111 | const qreal delta = chartRect.height()/(m_categoriesAxis->d_ptr->count()); | |||
109 |
|
112 | |||
110 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
113 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
111 |
lineItem->setLine( |
|
114 | lineItem->setLine(chartRect.left() , chartRect.top(), chartRect.left(), chartRect.bottom()); | |
112 |
|
115 | |||
113 |
qreal height = |
|
116 | qreal height = chartRect.bottom(); | |
114 | for (int i = 0; i < layout.size(); ++i) { |
|
117 | for (int i = 0; i < layout.size(); ++i) { | |
115 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
118 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
116 |
lineItem->setLine( |
|
119 | lineItem->setLine(chartRect.left() , layout[i], chartRect.right(), layout[i]); | |
117 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
120 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
118 | labelItem->setText(ticksList.at(i)); |
|
121 | labelItem->setText(ticksList.at(i)); | |
119 | const QRectF& rect = labelItem->boundingRect(); |
|
122 | const QRectF& rect = labelItem->boundingRect(); | |
120 | QPointF center = rect.center(); |
|
123 | QPointF center = rect.center(); | |
121 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
124 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
122 |
|
125 | |||
123 | if(i==0) { |
|
126 | if(i==0) { | |
124 |
labelItem->setPos( |
|
127 | labelItem->setPos(chartRect.left() - rect.width() - label_padding ,layout[i+1] + (delta)/2 - center.y()); | |
125 | } |
|
128 | } | |
126 | else { |
|
129 | else { | |
127 |
labelItem->setPos( |
|
130 | labelItem->setPos(chartRect.left() - rect.width() - label_padding ,layout[i] - (delta)/2 - center.y()); | |
128 | } |
|
131 | } | |
129 |
|
132 | |||
130 |
if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < |
|
133 | if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < chartRect.top()) { | |
131 | labelItem->setVisible(false); |
|
134 | labelItem->setVisible(false); | |
132 | } |
|
135 | } | |
133 | else { |
|
136 | else { | |
134 | labelItem->setVisible(true); |
|
137 | labelItem->setVisible(true); | |
135 | height=labelItem->pos().y(); |
|
138 | height=labelItem->pos().y(); | |
136 | } |
|
139 | } | |
137 |
|
140 | |||
138 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
|||
139 | m_minHeight+=rect.height(); |
|
|||
140 |
|
||||
141 | if ((i+1)%2 && i>1) { |
|
141 | if ((i+1)%2 && i>1) { | |
142 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
142 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
143 |
rectItem->setRect( |
|
143 | rectItem->setRect(chartRect.left(),layout[i],chartRect.width(),layout[i-1]-layout[i]); | |
144 | } |
|
144 | } | |
145 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
145 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
146 |
lineItem->setLine( |
|
146 | lineItem->setLine(chartRect.left()-5,layout[i],chartRect.left(),layout[i]); | |
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void ChartBarCategoryAxisY::handleAxisUpdated() |
|
150 | void ChartBarCategoryAxisY::handleAxisUpdated() | |
151 | { |
|
151 | { | |
152 |
|
152 | |||
153 | if(m_categoriesAxis->categories()!=m_categories) |
|
153 | if(m_categoriesAxis->categories()!=m_categories) | |
154 | { |
|
154 | { | |
155 | m_categories=m_categoriesAxis->categories(); |
|
155 | m_categories=m_categoriesAxis->categories(); | |
156 | if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) { |
|
156 | if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) { | |
157 | updateGeometry(); |
|
157 | updateGeometry(); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 | ChartAxis::handleAxisUpdated(); |
|
160 | ChartAxis::handleAxisUpdated(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
|
163 | QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
164 | { | |||
|
165 | Q_UNUSED(constraint) | |||
|
166 | ||||
|
167 | QFontMetrics fn(m_font); | |||
|
168 | QSizeF sh; | |||
|
169 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |||
|
170 | QStringList ticksList = createCategoryLabels(ChartAxis::layout()); | |||
|
171 | qreal width=0; | |||
|
172 | qreal height=0; | |||
|
173 | ||||
|
174 | switch (which) { | |||
|
175 | case Qt::MinimumSize: | |||
|
176 | width = fn.boundingRect("...").width() + label_padding; | |||
|
177 | height = fn.height(); | |||
|
178 | width+=base.width(); | |||
|
179 | height=qMax(height,base.height()); | |||
|
180 | sh = QSizeF(width,height); | |||
|
181 | break; | |||
|
182 | case Qt::PreferredSize:{ | |||
|
183 | ||||
|
184 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
185 | { | |||
|
186 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |||
|
187 | height+=rect.height(); | |||
|
188 | width=qMax(rect.width()+label_padding,width); | |||
|
189 | } | |||
|
190 | height=qMax(height,base.height()); | |||
|
191 | width+=base.width(); | |||
|
192 | sh = QSizeF(width,height); | |||
|
193 | break; | |||
|
194 | } | |||
|
195 | default: | |||
|
196 | break; | |||
|
197 | } | |||
|
198 | ||||
|
199 | return sh; | |||
|
200 | } | |||
|
201 | ||||
163 | QTCOMMERCIALCHART_END_NAMESPACE |
|
202 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,63 +1,63 | |||||
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 CHARTBARCATEGORYAXISY_H |
|
30 | #ifndef CHARTBARCATEGORYAXISY_H | |
31 | #define CHARTBARCATEGORYAXISY_H |
|
31 | #define CHARTBARCATEGORYAXISY_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class QBarCategoryAxis; |
|
38 | class QBarCategoryAxis; | |
39 | class ChartPresenter; |
|
39 | class ChartPresenter; | |
40 |
|
40 | |||
41 | class ChartBarCategoryAxisY : public ChartAxis |
|
41 | class ChartBarCategoryAxisY : public ChartAxis | |
42 | { |
|
42 | { | |
43 | public: |
|
43 | public: | |
44 | ChartBarCategoryAxisY(QBarCategoryAxis *axis, ChartPresenter *presenter); |
|
44 | ChartBarCategoryAxisY(QBarCategoryAxis *axis, ChartPresenter *presenter); | |
45 | ~ChartBarCategoryAxisY(); |
|
45 | ~ChartBarCategoryAxisY(); | |
46 |
|
46 | |||
47 | AxisType axisType() const { return Y_AXIS;} |
|
47 | AxisType axisType() const { return Y_AXIS;} | |
48 |
|
48 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
49 | protected: |
|
49 | protected: | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
52 | private: |
|
52 | private: | |
53 | QStringList createCategoryLabels(const QVector<qreal>& layout) const; |
|
53 | QStringList createCategoryLabels(const QVector<qreal>& layout) const; | |
54 | Q_SLOTS |
|
54 | Q_SLOTS | |
55 | void handleAxisUpdated(); |
|
55 | void handleAxisUpdated(); | |
56 | private: |
|
56 | private: | |
57 | QStringList m_categories; |
|
57 | QStringList m_categories; | |
58 | QBarCategoryAxis *m_categoriesAxis; |
|
58 | QBarCategoryAxis *m_categoriesAxis; | |
59 | }; |
|
59 | }; | |
60 |
|
60 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
62 | |||
63 | #endif /* CHARTBARCATEGORYAXISY_H */ |
|
63 | #endif /* CHARTBARCATEGORYAXISY_H */ |
@@ -1,149 +1,187 | |||||
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 "chartcategoryaxisx_p.h" |
|
21 | #include "chartcategoryaxisx_p.h" | |
22 | #include "qcategoryaxis.h" |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartCategoryAxisX::ChartCategoryAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
33 | ChartCategoryAxisX::ChartCategoryAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
34 | { |
|
34 | { | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | ChartCategoryAxisX::~ChartCategoryAxisX() |
|
37 | ChartCategoryAxisX::~ChartCategoryAxisX() | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const |
|
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |
42 | { |
|
42 | { | |
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
44 | int tickCount = axis->categoriesLabels().count() + 1; |
|
44 | int tickCount = axis->categoriesLabels().count() + 1; | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 |
|
46 | |||
47 | if (tickCount < 2) |
|
47 | if (tickCount < 2) | |
48 | return points; |
|
48 | return points; | |
49 |
|
49 | |||
|
50 | QRectF rect = presenter()->chartsGeometry(); | |||
|
51 | ||||
50 | qreal range = axis->max() - axis->min(); |
|
52 | qreal range = axis->max() - axis->min(); | |
51 | if (range > 0) { |
|
53 | if (range > 0) { | |
52 | points.resize(tickCount); |
|
54 | points.resize(tickCount); | |
53 |
qreal scale = |
|
55 | qreal scale = rect.width() / range; | |
54 | for (int i = 0; i < tickCount; ++i) |
|
56 | for (int i = 0; i < tickCount; ++i) | |
55 | if (i < tickCount - 1) { |
|
57 | if (i < tickCount - 1) { | |
56 |
int x = (axis->startValue(axis->categoriesLabels().at(i)) - axis->min()) * scale + |
|
58 | int x = (axis->startValue(axis->categoriesLabels().at(i)) - axis->min()) * scale + rect.left(); | |
57 | points[i] = x; |
|
59 | points[i] = x; | |
58 | } else { |
|
60 | } else { | |
59 |
int x = (axis->endValue(axis->categoriesLabels().at(i - 1)) - axis->min()) * scale + |
|
61 | int x = (axis->endValue(axis->categoriesLabels().at(i - 1)) - axis->min()) * scale + rect.left(); | |
60 | points[i] = x; |
|
62 | points[i] = x; | |
61 | } |
|
63 | } | |
62 | } |
|
64 | } | |
63 | return points; |
|
65 | return points; | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | void ChartCategoryAxisX::updateGeometry() |
|
68 | void ChartCategoryAxisX::updateGeometry() | |
67 | { |
|
69 | { | |
68 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
70 | const QVector<qreal>& layout = ChartAxis::layout(); | |
69 |
|
71 | |||
70 | m_minWidth = 0; |
|
|||
71 | m_minHeight = 0; |
|
|||
72 |
|
||||
73 | if(layout.isEmpty()) return; |
|
72 | if(layout.isEmpty()) return; | |
74 |
|
73 | |||
75 | QCategoryAxis *categoryAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
74 | QCategoryAxis *categoryAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
76 | QStringList ticksList = categoryAxis->categoriesLabels(); |
|
75 | QStringList ticksList = categoryAxis->categoriesLabels(); | |
77 |
|
76 | |||
78 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
77 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
79 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
78 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
80 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
79 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
81 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
80 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
82 |
|
81 | |||
83 |
|
82 | |||
84 | for (int i = 0; i < labels.count(); i++) { |
|
83 | for (int i = 0; i < labels.count(); i++) { | |
85 | labels.at(i)->setVisible(false); |
|
84 | labels.at(i)->setVisible(false); | |
86 | } |
|
85 | } | |
87 |
|
86 | |||
|
87 | QRectF chartRect = presenter()->chartsGeometry(); | |||
88 | // axis base line |
|
88 | // axis base line | |
|
89 | ||||
89 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
90 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
90 |
lineItem->setLine( |
|
91 | lineItem->setLine(chartRect.left(), chartRect.bottom(), chartRect.right(), chartRect.bottom()); | |
91 |
|
92 | |||
92 | for (int i = 0; i < layout.size(); ++i) { |
|
93 | for (int i = 0; i < layout.size(); ++i) { | |
93 |
|
94 | |||
94 | // label items |
|
|||
95 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
95 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
96 | if (i < ticksList.count()) { |
|
96 | if (i < ticksList.count()) { | |
97 | labelItem->setText(ticksList.at(i)); |
|
97 | labelItem->setText(ticksList.at(i)); | |
98 | } |
|
98 | } | |
99 | const QRectF& rect = labelItem->boundingRect(); |
|
99 | const QRectF& rect = labelItem->boundingRect(); | |
100 | QPointF center = rect.center(); |
|
100 | QPointF center = rect.center(); | |
101 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
101 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
102 | ||||
102 | if (i < layout.size() - 1) { |
|
103 | if (i < layout.size() - 1) { | |
103 |
labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), |
|
104 | labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), chartRect.bottom() + label_padding); | |
104 | } else { |
|
105 | } else { | |
105 |
labelItem->setPos(layout[i] - center.x(), |
|
106 | labelItem->setPos(layout[i] - center.x(), chartRect.bottom() + label_padding); | |
106 | } |
|
107 | } | |
107 |
|
108 | |||
108 | // check if the label should be shown |
|
109 | // check if the label should be shown | |
109 |
if (labelItem->pos().x() + center.x() < |
|
110 | if (labelItem->pos().x() + center.x() < chartRect.left() || labelItem->pos().x() + center.x() > chartRect.right()) | |
110 | labelItem->setVisible(false); |
|
111 | labelItem->setVisible(false); | |
111 | else |
|
112 | else | |
112 | labelItem->setVisible(true); |
|
113 | labelItem->setVisible(true); | |
113 |
|
114 | |||
114 | m_minWidth += rect.width(); |
|
|||
115 | m_minHeight = qMax(rect.height()+ label_padding, m_minHeight); |
|
|||
116 |
|
||||
117 | if ((i + 1) % 2 && i > 1) { |
|
115 | if ((i + 1) % 2 && i > 1) { | |
118 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); |
|
116 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); | |
119 |
rectItem->setRect(layout[i - 1], |
|
117 | rectItem->setRect(layout[i - 1],chartRect.top(),layout[i]-layout[i - 1],chartRect.height()); | |
120 | } |
|
118 | } | |
121 |
|
119 | |||
122 | // grid lines and axis line ticks |
|
120 | // grid lines and axis line ticks | |
123 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
121 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
124 |
lineItem->setPos(layout[i], |
|
122 | lineItem->setPos(layout[i], chartRect.top()); | |
125 |
lineItem->setLine(0, 0, 0, |
|
123 | lineItem->setLine(0, 0, 0, chartRect.height()); | |
126 |
|
124 | |||
127 | QGraphicsLineItem *tickLineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
125 | QGraphicsLineItem *tickLineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
128 |
tickLineItem->setPos(layout[i], |
|
126 | tickLineItem->setPos(layout[i], chartRect.bottom()); | |
129 | tickLineItem->setLine(0, 0, 0, 5); |
|
127 | tickLineItem->setLine(0, 0, 0, 5); | |
130 |
|
128 | |||
131 | // check if the grid line and the axis tick should be shown |
|
129 | // check if the grid line and the axis tick should be shown | |
132 |
if (lineItem->pos().x() < |
|
130 | if (lineItem->pos().x() < chartRect.left() || lineItem->pos().x() > chartRect.right()) { | |
133 | lineItem->setVisible(false); |
|
131 | lineItem->setVisible(false); | |
134 | tickLineItem->setVisible(false); |
|
132 | tickLineItem->setVisible(false); | |
135 | } else { |
|
133 | } else { | |
136 | lineItem->setVisible(true); |
|
134 | lineItem->setVisible(true); | |
137 | tickLineItem->setVisible(true); |
|
135 | tickLineItem->setVisible(true); | |
138 | } |
|
136 | } | |
|
137 | ||||
139 | } |
|
138 | } | |
140 |
|
139 | |||
141 | } |
|
140 | } | |
142 |
|
141 | |||
143 | void ChartCategoryAxisX::handleAxisUpdated() |
|
142 | void ChartCategoryAxisX::handleAxisUpdated() | |
144 | { |
|
143 | { | |
145 | updateGeometry(); |
|
144 | updateGeometry(); | |
146 | ChartAxis::handleAxisUpdated(); |
|
145 | ChartAxis::handleAxisUpdated(); | |
147 | } |
|
146 | } | |
148 |
|
147 | |||
|
148 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
149 | { | |||
|
150 | Q_UNUSED(constraint) | |||
|
151 | ||||
|
152 | QFontMetrics fn(m_font); | |||
|
153 | QSizeF sh; | |||
|
154 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |||
|
155 | QStringList ticksList ; //TODO: | |||
|
156 | qreal width=0; | |||
|
157 | qreal height=0; | |||
|
158 | ||||
|
159 | switch (which) { | |||
|
160 | case Qt::MinimumSize: | |||
|
161 | width = fn.boundingRect("...").width(); | |||
|
162 | height = fn.height() + label_padding; | |||
|
163 | width=qMax(width,base.width()); | |||
|
164 | height+=base.height(); | |||
|
165 | sh = QSizeF(width,height); | |||
|
166 | break; | |||
|
167 | case Qt::PreferredSize: { | |||
|
168 | ||||
|
169 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
170 | { | |||
|
171 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |||
|
172 | width+=rect.width(); | |||
|
173 | height=qMax(rect.height()+label_padding,height); | |||
|
174 | } | |||
|
175 | width=qMax(width,base.width()); | |||
|
176 | height+=base.height(); | |||
|
177 | sh = QSizeF(width,height); | |||
|
178 | break; | |||
|
179 | } | |||
|
180 | default: | |||
|
181 | break; | |||
|
182 | } | |||
|
183 | ||||
|
184 | return sh; | |||
|
185 | } | |||
|
186 | ||||
149 | QTCOMMERCIALCHART_END_NAMESPACE |
|
187 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
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 CHARTCATEGORYAXISX_H |
|
30 | #ifndef CHARTCATEGORYAXISX_H | |
31 | #define CHARTCATEGORYAXISX_H |
|
31 | #define CHARTCATEGORYAXISX_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 | class ChartCategoryAxisX : public ChartAxis |
|
40 | class ChartCategoryAxisX : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 | ChartCategoryAxisX(QAbstractAxis *axis, ChartPresenter *presenter); |
|
43 | ChartCategoryAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 | ~ChartCategoryAxisX(); |
|
44 | ~ChartCategoryAxisX(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return X_AXIS;} |
|
46 | AxisType axisType() const { return X_AXIS;} | |
47 |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
48 | protected: |
|
48 | protected: | |
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
51 |
|
51 | |||
52 | Q_SLOTS |
|
52 | Q_SLOTS | |
53 | void handleAxisUpdated(); |
|
53 | void handleAxisUpdated(); | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif /* CHARTCATEGORYAXISX_H */ |
|
58 | #endif /* CHARTCATEGORYAXISX_H */ |
@@ -1,161 +1,201 | |||||
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 "chartcategoryaxisy_p.h" |
|
21 | #include "chartcategoryaxisy_p.h" | |
22 | #include "qcategoryaxis.h" |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartCategoryAxisY::ChartCategoryAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
33 | ChartCategoryAxisY::ChartCategoryAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
34 | { |
|
34 | { | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | ChartCategoryAxisY::~ChartCategoryAxisY() |
|
37 | ChartCategoryAxisY::~ChartCategoryAxisY() | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const |
|
41 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |
42 | { |
|
42 | { | |
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
44 | int tickCount = axis->categoriesLabels().count() + 1; |
|
44 | int tickCount = axis->categoriesLabels().count() + 1; | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 |
|
46 | |||
47 | if (tickCount < 2) |
|
47 | if (tickCount < 2) | |
48 | return points; |
|
48 | return points; | |
49 |
|
49 | |||
|
50 | QRectF rect = presenter()->chartsGeometry(); | |||
|
51 | ||||
50 | qreal range = axis->max() - axis->min(); |
|
52 | qreal range = axis->max() - axis->min(); | |
51 | if (range > 0) { |
|
53 | if (range > 0) { | |
52 | points.resize(tickCount); |
|
54 | points.resize(tickCount); | |
53 |
qreal scale = |
|
55 | qreal scale = rect.height() / range; | |
54 | for (int i = 0; i < tickCount; ++i) |
|
56 | for (int i = 0; i < tickCount; ++i) | |
55 | if (i < tickCount - 1) { |
|
57 | if (i < tickCount - 1) { | |
56 |
int y = -(axis->startValue(axis->categoriesLabels().at(i)) - axis->min()) * scale + |
|
58 | int y = -(axis->startValue(axis->categoriesLabels().at(i)) - axis->min()) * scale + rect.bottom(); | |
57 | points[i] = y; |
|
59 | points[i] = y; | |
58 | } else { |
|
60 | } else { | |
59 |
int y = -(axis->endValue(axis->categoriesLabels().at(i - 1)) - axis->min()) * scale + |
|
61 | int y = -(axis->endValue(axis->categoriesLabels().at(i - 1)) - axis->min()) * scale + rect.bottom(); | |
60 | points[i] = y; |
|
62 | points[i] = y; | |
61 | } |
|
63 | } | |
62 | } |
|
64 | } | |
63 |
|
65 | |||
64 | return points; |
|
66 | return points; | |
65 | } |
|
67 | } | |
66 |
|
68 | |||
67 | void ChartCategoryAxisY::updateGeometry() |
|
69 | void ChartCategoryAxisY::updateGeometry() | |
68 | { |
|
70 | { | |
69 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
71 | const QVector<qreal> &layout = ChartAxis::layout(); | |
70 | m_minWidth = 0; |
|
|||
71 | m_minHeight = 0; |
|
|||
72 |
|
72 | |||
73 | if(layout.isEmpty()) { |
|
73 | if(layout.isEmpty()) { | |
74 | return; |
|
74 | return; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | QCategoryAxis *categoryAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
77 | QCategoryAxis *categoryAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
78 | QStringList ticksList = categoryAxis->categoriesLabels(); |
|
78 | QStringList ticksList = categoryAxis->categoriesLabels(); | |
79 |
|
79 | |||
80 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
80 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
81 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
81 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
82 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
82 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
83 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
83 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
84 |
|
84 | |||
85 | // qreal height = 2*m_rect.bottom(); |
|
85 | // qreal height = 2*m_rect.bottom(); | |
86 |
|
86 | |||
87 | for (int i = 0; i < labels.count(); i++) { |
|
87 | for (int i = 0; i < labels.count(); i++) { | |
88 | labels.at(i)->setVisible(false); |
|
88 | labels.at(i)->setVisible(false); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
|
91 | QRectF chartRect = presenter()->chartsGeometry(); | |||
|
92 | ||||
91 | // axis base line |
|
93 | // axis base line | |
92 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
94 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
93 |
lineItem->setLine( |
|
95 | lineItem->setLine(chartRect.left() , chartRect.top(), chartRect.left(), chartRect.bottom()); | |
94 |
|
96 | |||
95 | for (int i = 0; i < layout.size(); ++i) { |
|
97 | for (int i = 0; i < layout.size(); ++i) { | |
96 |
|
98 | |||
97 | // label items |
|
99 | // label items | |
98 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
100 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
99 | if (i < ticksList.count()) { |
|
101 | if (i < ticksList.count()) { | |
100 | labelItem->setText(ticksList.at(i)); |
|
102 | labelItem->setText(ticksList.at(i)); | |
101 | } |
|
103 | } | |
102 | const QRectF& rect = labelItem->boundingRect(); |
|
104 | const QRectF& rect = labelItem->boundingRect(); | |
103 |
|
105 | |||
104 | QPointF center = rect.center(); |
|
106 | QPointF center = rect.center(); | |
105 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
107 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
106 |
|
108 | |||
|
109 | ||||
107 | if (i < layout.size() - 1) |
|
110 | if (i < layout.size() - 1) | |
108 |
labelItem->setPos( |
|
111 | labelItem->setPos(chartRect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y()); | |
109 | else |
|
112 | else | |
110 |
labelItem->setPos( |
|
113 | labelItem->setPos(chartRect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
111 |
|
114 | |||
112 | // check if the label should be shown |
|
115 | // check if the label should be shown | |
113 |
if (labelItem->pos().y() + center.y() < |
|
116 | if (labelItem->pos().y() + center.y() < chartRect.top() || labelItem->pos().y() + center.y() > chartRect.bottom()) | |
114 | labelItem->setVisible(false); |
|
117 | labelItem->setVisible(false); | |
115 | else |
|
118 | else | |
116 | labelItem->setVisible(true); |
|
119 | labelItem->setVisible(true); | |
117 |
|
120 | |||
118 | // if(labelItem->pos().y()+rect.height()>height) { |
|
121 | // if(labelItem->pos().y()+rect.height()>height) { | |
119 | // labelItem->setVisible(false); |
|
122 | // labelItem->setVisible(false); | |
120 | // } |
|
123 | // } | |
121 | // else { |
|
124 | // else { | |
122 | // labelItem->setVisible(true); |
|
125 | // labelItem->setVisible(true); | |
123 | // height=labelItem->pos().y(); |
|
126 | // height=labelItem->pos().y(); | |
124 | // } |
|
127 | // } | |
125 |
|
128 | |||
126 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
|||
127 | m_minHeight+=rect.height(); |
|
|||
128 |
|
||||
129 | if ((i+1)%2 && i>1) { |
|
129 | if ((i+1)%2 && i>1) { | |
130 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
130 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
131 |
rectItem->setRect( |
|
131 | rectItem->setRect(chartRect.left(),layout[i],chartRect.width(),layout[i-1]-layout[i]); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | // grid lines and axis line ticks |
|
134 | // grid lines and axis line ticks | |
135 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
135 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
136 |
lineItem->setPos( |
|
136 | lineItem->setPos(chartRect.left(), layout[i]); | |
137 |
lineItem->setLine(0, 0, |
|
137 | lineItem->setLine(0, 0, chartRect.width(), 0); | |
138 |
|
138 | |||
139 | QGraphicsLineItem *tickLineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
139 | QGraphicsLineItem *tickLineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
140 |
tickLineItem->setPos( |
|
140 | tickLineItem->setPos(chartRect.left(), layout[i]); | |
141 | tickLineItem->setLine(-5, 0, 0, 0); |
|
141 | tickLineItem->setLine(-5, 0, 0, 0); | |
142 |
|
142 | |||
143 | // check if the grid line and the axis tick should be shown |
|
143 | // check if the grid line and the axis tick should be shown | |
144 |
if (lineItem->pos().y() < |
|
144 | if (lineItem->pos().y() < chartRect.top() || lineItem->pos().y() > chartRect.bottom()) { | |
145 | lineItem->setVisible(false); |
|
145 | lineItem->setVisible(false); | |
146 | tickLineItem->setVisible(false); |
|
146 | tickLineItem->setVisible(false); | |
147 | } else { |
|
147 | } else { | |
148 | lineItem->setVisible(true); |
|
148 | lineItem->setVisible(true); | |
149 | tickLineItem->setVisible(true); |
|
149 | tickLineItem->setVisible(true); | |
150 | } |
|
150 | } | |
|
151 | ||||
151 | } |
|
152 | } | |
152 |
|
153 | |||
153 | } |
|
154 | } | |
154 |
|
155 | |||
155 | void ChartCategoryAxisY::handleAxisUpdated() |
|
156 | void ChartCategoryAxisY::handleAxisUpdated() | |
156 | { |
|
157 | { | |
157 | updateGeometry(); |
|
158 | updateGeometry(); | |
158 | ChartAxis::handleAxisUpdated(); |
|
159 | ChartAxis::handleAxisUpdated(); | |
159 | } |
|
160 | } | |
160 |
|
161 | |||
|
162 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
163 | { | |||
|
164 | Q_UNUSED(constraint) | |||
|
165 | ||||
|
166 | QFontMetrics fn(m_font); | |||
|
167 | QSizeF sh; | |||
|
168 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |||
|
169 | QStringList ticksList; //TODO:: | |||
|
170 | qreal width=0; | |||
|
171 | qreal height=0; | |||
|
172 | ||||
|
173 | switch (which) { | |||
|
174 | case Qt::MinimumSize: | |||
|
175 | width = fn.boundingRect("...").width()+label_padding; | |||
|
176 | height = fn.height(); | |||
|
177 | width=qMax(width,base.width()); | |||
|
178 | height+=base.height(); | |||
|
179 | sh = QSizeF(width,height); | |||
|
180 | break; | |||
|
181 | case Qt::PreferredSize:{ | |||
|
182 | ||||
|
183 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
184 | { | |||
|
185 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |||
|
186 | height+=rect.height(); | |||
|
187 | width=qMax(rect.width()+label_padding,width); | |||
|
188 | } | |||
|
189 | height=qMax(height,base.height()); | |||
|
190 | width+=base.width(); | |||
|
191 | sh = QSizeF(width,height); | |||
|
192 | break; | |||
|
193 | } | |||
|
194 | default: | |||
|
195 | break; | |||
|
196 | } | |||
|
197 | ||||
|
198 | return sh; | |||
|
199 | } | |||
|
200 | ||||
161 | QTCOMMERCIALCHART_END_NAMESPACE |
|
201 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
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 CHARTCATEGORYAXISY_H |
|
30 | #ifndef CHARTCATEGORYAXISY_H | |
31 | #define CHARTCATEGORYAXISY_H |
|
31 | #define CHARTCATEGORYAXISY_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 | class ChartCategoryAxisY : public ChartAxis |
|
40 | class ChartCategoryAxisY : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 | ChartCategoryAxisY(QAbstractAxis *axis, ChartPresenter *presenter); |
|
43 | ChartCategoryAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 | ~ChartCategoryAxisY(); |
|
44 | ~ChartCategoryAxisY(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return Y_AXIS;} |
|
46 | AxisType axisType() const { return Y_AXIS;} | |
47 |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
48 | protected: |
|
48 | protected: | |
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
51 |
|
51 | |||
52 | Q_SLOTS |
|
52 | Q_SLOTS | |
53 | void handleAxisUpdated(); |
|
53 | void handleAxisUpdated(); | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif /* CHARTCATEGORYAXISY_H */ |
|
58 | #endif /* CHARTCATEGORYAXISY_H */ |
@@ -1,399 +1,487 | |||||
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 "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 | #include <QDateTime> |
|
27 | #include <QDateTime> | |
28 | #include <QValueAxis> |
|
28 | #include <QValueAxis> | |
29 | #include <QGraphicsLayout> |
|
29 | #include <QGraphicsLayout> | |
|
30 | #include <QFontMetrics> | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartElement(presenter), |
|
34 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartElement(presenter), | |
34 | m_chartAxis(axis), |
|
35 | m_chartAxis(axis), | |
35 | m_labelsAngle(0), |
|
36 | m_labelsAngle(0), | |
36 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
37 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
37 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
38 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
38 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
39 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
39 | m_arrow(new QGraphicsItemGroup(presenter->rootItem())), |
|
40 | m_arrow(new QGraphicsItemGroup(presenter->rootItem())), | |
|
41 | m_title(new QGraphicsSimpleTextItem(presenter->rootItem())), | |||
40 | m_min(0), |
|
42 | m_min(0), | |
41 | m_max(0), |
|
43 | m_max(0), | |
42 |
m_animation(0) |
|
44 | m_animation(0) | |
43 | m_minWidth(0), |
|
|||
44 | m_minHeight(0) |
|
|||
45 | { |
|
45 | { | |
46 | //initial initialization |
|
46 | //initial initialization | |
47 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
47 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
48 | m_arrow->setHandlesChildEvents(false); |
|
48 | m_arrow->setHandlesChildEvents(false); | |
49 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
49 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
51 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
51 | m_grid->setZValue(ChartPresenter::GridZValue); | |
52 |
|
52 | |||
53 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
53 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
54 |
|
54 | |||
55 | QGraphicsSimpleTextItem item; |
|
55 | QGraphicsSimpleTextItem item; | |
56 | m_font = item.font(); |
|
56 | m_font = item.font(); | |
57 |
|
57 | |||
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | ChartAxis::~ChartAxis() |
|
60 | ChartAxis::~ChartAxis() | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void ChartAxis::setAnimation(AxisAnimation* animation) |
|
64 | void ChartAxis::setAnimation(AxisAnimation* animation) | |
65 | { |
|
65 | { | |
66 | m_animation=animation; |
|
66 | m_animation=animation; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
69 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
70 | { |
|
70 | { | |
71 | m_layoutVector=layout; |
|
71 | m_layoutVector=layout; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void ChartAxis::createItems(int count) |
|
74 | void ChartAxis::createItems(int count) | |
75 | { |
|
75 | { | |
76 | if (m_arrow->children().size() == 0) |
|
76 | if (m_arrow->children().size() == 0) | |
77 | m_arrow->addToGroup(new AxisItem(this,presenter()->rootItem())); |
|
77 | m_arrow->addToGroup(new AxisItem(this,presenter()->rootItem())); | |
78 | for (int i = 0; i < count; ++i) { |
|
78 | for (int i = 0; i < count; ++i) { | |
79 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
79 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
80 | m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem())); |
|
80 | m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem())); | |
81 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
81 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
82 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); |
|
82 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void ChartAxis::deleteItems(int count) |
|
86 | void ChartAxis::deleteItems(int count) | |
87 | { |
|
87 | { | |
88 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
88 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
89 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
89 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
90 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
90 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
91 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
91 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
92 |
|
92 | |||
93 | for (int i = 0; i < count; ++i) { |
|
93 | for (int i = 0; i < count; ++i) { | |
94 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
94 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
95 | delete(lines.takeLast()); |
|
95 | delete(lines.takeLast()); | |
96 | delete(labels.takeLast()); |
|
96 | delete(labels.takeLast()); | |
97 | delete(axis.takeLast()); |
|
97 | delete(axis.takeLast()); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
101 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
102 | { |
|
102 | { | |
103 | int diff = m_layoutVector.size() - layout.size(); |
|
103 | int diff = m_layoutVector.size() - layout.size(); | |
104 |
|
104 | |||
105 | if (diff>0) { |
|
105 | if (diff>0) { | |
106 | deleteItems(diff); |
|
106 | deleteItems(diff); | |
107 | } |
|
107 | } | |
108 | else if (diff<0) { |
|
108 | else if (diff<0) { | |
109 | createItems(-diff); |
|
109 | createItems(-diff); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | if(diff<0) handleAxisUpdated(); |
|
112 | if(diff<0) handleAxisUpdated(); | |
113 |
|
113 | |||
114 | if (m_animation) { |
|
114 | if (m_animation) { | |
115 | switch(presenter()->state()){ |
|
115 | switch(presenter()->state()){ | |
116 | case ChartPresenter::ZoomInState: |
|
116 | case ChartPresenter::ZoomInState: | |
117 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
117 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
118 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
118 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
119 | break; |
|
119 | break; | |
120 | case ChartPresenter::ZoomOutState: |
|
120 | case ChartPresenter::ZoomOutState: | |
121 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
121 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
122 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
122 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
123 | break; |
|
123 | break; | |
124 | case ChartPresenter::ScrollUpState: |
|
124 | case ChartPresenter::ScrollUpState: | |
125 | case ChartPresenter::ScrollLeftState: |
|
125 | case ChartPresenter::ScrollLeftState: | |
126 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
126 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
127 | break; |
|
127 | break; | |
128 | case ChartPresenter::ScrollDownState: |
|
128 | case ChartPresenter::ScrollDownState: | |
129 | case ChartPresenter::ScrollRightState: |
|
129 | case ChartPresenter::ScrollRightState: | |
130 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
130 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
131 | break; |
|
131 | break; | |
132 | case ChartPresenter::ShowState: |
|
132 | case ChartPresenter::ShowState: | |
133 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
133 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
134 | break; |
|
134 | break; | |
135 | } |
|
135 | } | |
136 | m_animation->setValues(m_layoutVector,layout); |
|
136 | m_animation->setValues(m_layoutVector,layout); | |
137 | presenter()->startAnimation(m_animation); |
|
137 | presenter()->startAnimation(m_animation); | |
138 | } |
|
138 | } | |
139 | else { |
|
139 | else { | |
140 | setLayout(layout); |
|
140 | setLayout(layout); | |
141 | updateGeometry(); |
|
141 | updateGeometry(); | |
142 | checkLayout(); |
|
|||
143 | } |
|
142 | } | |
144 | } |
|
143 | } | |
145 |
|
144 | |||
146 | void ChartAxis::setArrowOpacity(qreal opacity) |
|
145 | void ChartAxis::setArrowOpacity(qreal opacity) | |
147 | { |
|
146 | { | |
148 | m_arrow->setOpacity(opacity); |
|
147 | m_arrow->setOpacity(opacity); | |
149 | } |
|
148 | } | |
150 |
|
149 | |||
151 | qreal ChartAxis::arrowOpacity() const |
|
150 | qreal ChartAxis::arrowOpacity() const | |
152 | { |
|
151 | { | |
153 | return m_arrow->opacity(); |
|
152 | return m_arrow->opacity(); | |
154 | } |
|
153 | } | |
155 |
|
154 | |||
156 | void ChartAxis::setArrowVisibility(bool visible) |
|
155 | void ChartAxis::setArrowVisibility(bool visible) | |
157 | { |
|
156 | { | |
158 | m_arrow->setOpacity(visible); |
|
157 | m_arrow->setOpacity(visible); | |
159 | } |
|
158 | } | |
160 |
|
159 | |||
161 | void ChartAxis::setGridOpacity(qreal opacity) |
|
160 | void ChartAxis::setGridOpacity(qreal opacity) | |
162 | { |
|
161 | { | |
163 | m_grid->setOpacity(opacity); |
|
162 | m_grid->setOpacity(opacity); | |
164 | } |
|
163 | } | |
165 |
|
164 | |||
166 | qreal ChartAxis::gridOpacity() const |
|
165 | qreal ChartAxis::gridOpacity() const | |
167 | { |
|
166 | { | |
168 | return m_grid->opacity(); |
|
167 | return m_grid->opacity(); | |
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 | void ChartAxis::setGridVisibility(bool visible) |
|
170 | void ChartAxis::setGridVisibility(bool visible) | |
172 | { |
|
171 | { | |
173 | m_grid->setOpacity(visible); |
|
172 | m_grid->setOpacity(visible); | |
174 | } |
|
173 | } | |
175 |
|
174 | |||
176 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
175 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
177 | { |
|
176 | { | |
178 | m_labels->setOpacity(opacity); |
|
177 | m_labels->setOpacity(opacity); | |
179 | } |
|
178 | } | |
180 |
|
179 | |||
181 | qreal ChartAxis::labelsOpacity() const |
|
180 | qreal ChartAxis::labelsOpacity() const | |
182 | { |
|
181 | { | |
183 | return m_labels->opacity(); |
|
182 | return m_labels->opacity(); | |
184 | } |
|
183 | } | |
185 |
|
184 | |||
186 | void ChartAxis::setLabelsVisibility(bool visible) |
|
185 | void ChartAxis::setLabelsVisibility(bool visible) | |
187 | { |
|
186 | { | |
188 | m_labels->setOpacity(visible); |
|
187 | m_labels->setOpacity(visible); | |
189 | } |
|
188 | } | |
190 |
|
189 | |||
191 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
190 | void ChartAxis::setShadesOpacity(qreal opacity) | |
192 | { |
|
191 | { | |
193 | m_shades->setOpacity(opacity); |
|
192 | m_shades->setOpacity(opacity); | |
194 | } |
|
193 | } | |
195 |
|
194 | |||
196 | qreal ChartAxis::shadesOpacity() const |
|
195 | qreal ChartAxis::shadesOpacity() const | |
197 | { |
|
196 | { | |
198 | return m_shades->opacity(); |
|
197 | return m_shades->opacity(); | |
199 | } |
|
198 | } | |
200 |
|
199 | |||
201 | void ChartAxis::setShadesVisibility(bool visible) |
|
200 | void ChartAxis::setShadesVisibility(bool visible) | |
202 | { |
|
201 | { | |
203 | m_shades->setVisible(visible); |
|
202 | m_shades->setVisible(visible); | |
204 | } |
|
203 | } | |
205 |
|
204 | |||
206 | void ChartAxis::setLabelsAngle(int angle) |
|
205 | void ChartAxis::setLabelsAngle(int angle) | |
207 | { |
|
206 | { | |
208 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
207 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
209 | item->setRotation(angle); |
|
208 | item->setRotation(angle); | |
210 | } |
|
209 | } | |
211 |
|
210 | |||
212 | m_labelsAngle=angle; |
|
211 | m_labelsAngle=angle; | |
213 | } |
|
212 | } | |
214 |
|
213 | |||
215 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
214 | void ChartAxis::setLabelsPen(const QPen &pen) | |
216 | { |
|
215 | { | |
217 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
216 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
218 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
217 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
219 | } |
|
218 | } | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
221 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
223 | { |
|
222 | { | |
224 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
223 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
225 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
224 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
226 | } |
|
225 | } | |
227 | } |
|
226 | } | |
228 |
|
227 | |||
229 | void ChartAxis::setLabelsFont(const QFont &font) |
|
228 | void ChartAxis::setLabelsFont(const QFont &font) | |
230 | { |
|
229 | { | |
231 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
230 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
232 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
231 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
233 | } |
|
232 | } | |
234 |
m_font |
|
233 | if(m_font!=font) { | |
|
234 | m_font = font; | |||
|
235 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |||
|
236 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |||
|
237 | } | |||
|
238 | QGraphicsLayoutItem::updateGeometry(); | |||
|
239 | presenter()->layout()->invalidate(); | |||
|
240 | ||||
|
241 | } | |||
235 | } |
|
242 | } | |
236 |
|
243 | |||
237 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
244 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
238 | { |
|
245 | { | |
239 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
246 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
240 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
247 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
241 | } |
|
248 | } | |
242 | } |
|
249 | } | |
243 |
|
250 | |||
244 | void ChartAxis::setShadesPen(const QPen &pen) |
|
251 | void ChartAxis::setShadesPen(const QPen &pen) | |
245 | { |
|
252 | { | |
246 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
253 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
247 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
254 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
248 | } |
|
255 | } | |
249 | } |
|
256 | } | |
250 |
|
257 | |||
251 | void ChartAxis::setArrowPen(const QPen &pen) |
|
258 | void ChartAxis::setArrowPen(const QPen &pen) | |
252 | { |
|
259 | { | |
253 | foreach(QGraphicsItem* item , m_arrow->childItems()) { |
|
260 | foreach(QGraphicsItem* item , m_arrow->childItems()) { | |
254 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
261 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
255 | } |
|
262 | } | |
256 | } |
|
263 | } | |
257 |
|
264 | |||
258 | void ChartAxis::setGridPen(const QPen &pen) |
|
265 | void ChartAxis::setGridPen(const QPen &pen) | |
259 | { |
|
266 | { | |
260 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
267 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
261 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
268 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
262 | } |
|
269 | } | |
263 | } |
|
270 | } | |
264 |
|
271 | |||
265 | bool ChartAxis::isEmpty() |
|
272 | bool ChartAxis::isEmpty() | |
266 | { |
|
273 | { | |
267 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max); |
|
274 | return !m_rect.isValid() || presenter()->chartsGeometry().isEmpty() || qFuzzyIsNull(m_min - m_max); | |
268 | } |
|
275 | } | |
269 |
|
276 | |||
270 | void ChartAxis::handleDomainUpdated() |
|
277 | void ChartAxis::handleDomainUpdated() | |
271 | { |
|
278 | { | |
272 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
279 | Domain* domain = qobject_cast<Domain*>(sender()); | |
273 | qreal min(0); |
|
280 | qreal min(0); | |
274 | qreal max(0); |
|
281 | qreal max(0); | |
275 |
|
282 | |||
276 | if(m_chartAxis->orientation()==Qt::Horizontal) { |
|
283 | if(m_chartAxis->orientation()==Qt::Horizontal) { | |
277 | min = domain->minX(); |
|
284 | min = domain->minX(); | |
278 | max = domain->maxX(); |
|
285 | max = domain->maxX(); | |
279 | } |
|
286 | } | |
280 | else if (m_chartAxis->orientation()==Qt::Vertical) |
|
287 | else if (m_chartAxis->orientation()==Qt::Vertical) | |
281 | { |
|
288 | { | |
282 | min = domain->minY(); |
|
289 | min = domain->minY(); | |
283 | max = domain->maxY(); |
|
290 | max = domain->maxY(); | |
284 | } |
|
291 | } | |
285 |
|
292 | |||
286 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) |
|
293 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) | |
287 | { |
|
294 | { | |
288 | m_min = min; |
|
295 | m_min = min; | |
289 | m_max = max; |
|
296 | m_max = max; | |
290 |
|
297 | |||
291 | if (!isEmpty()) { |
|
298 | if (!isEmpty()) { | |
|
299 | ||||
292 | QVector<qreal> layout = calculateLayout(); |
|
300 | QVector<qreal> layout = calculateLayout(); | |
293 | updateLayout(layout); |
|
301 | updateLayout(layout); | |
|
302 | QSizeF before = effectiveSizeHint(Qt::MinimumSize); | |||
|
303 | ||||
|
304 | QSizeF after= sizeHint(Qt::MinimumSize); | |||
|
305 | ||||
|
306 | if(before!=after) { | |||
|
307 | QGraphicsLayoutItem::updateGeometry(); | |||
|
308 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |||
|
309 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |||
|
310 | //instead recalculate layout and use plotArea for extra space. | |||
|
311 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |||
|
312 | } | |||
294 | } |
|
313 | } | |
295 | } |
|
314 | } | |
296 | } |
|
315 | } | |
297 |
|
316 | |||
298 | void ChartAxis::handleAxisUpdated() |
|
317 | void ChartAxis::handleAxisUpdated() | |
299 | { |
|
318 | { | |
300 | if(isEmpty()) return; |
|
319 | if(isEmpty()) return; | |
301 |
|
320 | |||
302 |
|
321 | |||
303 | bool visible = m_chartAxis->isVisible(); |
|
322 | bool visible = m_chartAxis->isVisible(); | |
304 |
|
323 | |||
305 | setArrowVisibility(visible && m_chartAxis->isLineVisible()); |
|
324 | setArrowVisibility(visible && m_chartAxis->isLineVisible()); | |
306 | setGridVisibility(visible && m_chartAxis->isGridLineVisible()); |
|
325 | setGridVisibility(visible && m_chartAxis->isGridLineVisible()); | |
307 | setLabelsVisibility(visible && m_chartAxis->labelsVisible()); |
|
326 | setLabelsVisibility(visible && m_chartAxis->labelsVisible()); | |
308 | setShadesVisibility(visible && m_chartAxis->shadesVisible()); |
|
327 | setShadesVisibility(visible && m_chartAxis->shadesVisible()); | |
309 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
328 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
310 | setArrowPen(m_chartAxis->linePen()); |
|
329 | setArrowPen(m_chartAxis->linePen()); | |
311 | setLabelsPen(m_chartAxis->labelsPen()); |
|
330 | setLabelsPen(m_chartAxis->labelsPen()); | |
312 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
331 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
313 | setLabelsFont(m_chartAxis->labelsFont()); |
|
332 | setLabelsFont(m_chartAxis->labelsFont()); | |
314 | setGridPen(m_chartAxis->gridLinePen()); |
|
333 | setGridPen(m_chartAxis->gridLinePen()); | |
315 | setShadesPen(m_chartAxis->shadesPen()); |
|
334 | setShadesPen(m_chartAxis->shadesPen()); | |
316 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
335 | setShadesBrush(m_chartAxis->shadesBrush()); | |
|
336 | setTitleText(m_chartAxis->title()); | |||
|
337 | } | |||
317 |
|
338 | |||
|
339 | void ChartAxis::setTitleText(const QString& title) | |||
|
340 | { | |||
|
341 | if(m_titleText!=title) { | |||
|
342 | m_titleText = title; | |||
|
343 | m_rect = QRect(); | |||
|
344 | QGraphicsLayoutItem::updateGeometry(); | |||
|
345 | presenter()->layout()->invalidate(); | |||
|
346 | } | |||
318 | } |
|
347 | } | |
319 |
|
348 | |||
320 | void ChartAxis::hide() |
|
349 | void ChartAxis::hide() | |
321 | { |
|
350 | { | |
322 | setArrowVisibility(false); |
|
351 | setArrowVisibility(false); | |
323 | setGridVisibility(false); |
|
352 | setGridVisibility(false); | |
324 | setLabelsVisibility(false); |
|
353 | setLabelsVisibility(false); | |
325 | setShadesVisibility(false); |
|
354 | setShadesVisibility(false); | |
326 | } |
|
355 | } | |
327 |
|
356 | |||
328 |
void ChartAxis:: |
|
357 | void ChartAxis::setGeometry(const QRectF &rect) | |
329 | { |
|
358 | { | |
330 | if(m_rect != rect) |
|
359 | ||
331 | { |
|
|||
332 | m_rect = rect; |
|
360 | m_rect = rect; | |
|
361 | ||||
333 | if (isEmpty()) return; |
|
362 | if (isEmpty()) return; | |
|
363 | ||||
|
364 | if(!m_titleText.isNull()) { | |||
|
365 | QFontMetrics fn(m_title->font()); | |||
|
366 | ||||
|
367 | int size(0); | |||
|
368 | ||||
|
369 | QRectF chartRect = presenter()->chartsGeometry(); | |||
|
370 | ||||
|
371 | if(orientation()==Qt::Horizontal) | |||
|
372 | size = chartRect.width(); | |||
|
373 | else if(orientation()==Qt::Vertical) | |||
|
374 | size = chartRect.height(); | |||
|
375 | ||||
|
376 | if (fn.boundingRect(m_titleText).width() > size) | |||
|
377 | { | |||
|
378 | QString string = m_titleText + "..."; | |||
|
379 | while (fn.boundingRect(string).width() > size && string.length() > 3) | |||
|
380 | string.remove(string.length() - 4, 1); | |||
|
381 | m_title->setText(string); | |||
|
382 | } | |||
|
383 | else | |||
|
384 | m_title->setText(m_titleText); | |||
|
385 | ||||
|
386 | QPointF center = chartRect.center() - m_title->boundingRect().center(); | |||
|
387 | if(orientation()==Qt::Horizontal) { | |||
|
388 | m_title->setPos(center.x(),m_rect.bottom()-m_title->boundingRect().height()); | |||
|
389 | } | |||
|
390 | else if(orientation()==Qt::Vertical) { | |||
|
391 | m_title->setTransformOriginPoint(m_title->boundingRect().center()); | |||
|
392 | m_title->setRotation(270); | |||
|
393 | m_title->setPos(m_rect.left()- m_title->boundingRect().width()/2+m_title->boundingRect().height()/2,center.y()); | |||
|
394 | } | |||
|
395 | } | |||
|
396 | ||||
334 | QVector<qreal> layout = calculateLayout(); |
|
397 | QVector<qreal> layout = calculateLayout(); | |
335 | updateLayout(layout); |
|
398 | updateLayout(layout); | |
336 | } |
|
|||
337 | } |
|
|||
338 |
|
||||
339 |
|
399 | |||
340 | qreal ChartAxis::minimumWidth() |
|
|||
341 | { |
|
|||
342 | if(m_minWidth == 0) updateGeometry(); |
|
|||
343 | return m_minWidth; |
|
|||
344 | } |
|
400 | } | |
345 |
|
401 | |||
346 | qreal ChartAxis::minimumHeight() |
|
|||
347 | { |
|
|||
348 | if(m_minHeight == 0) updateGeometry(); |
|
|||
349 | return m_minHeight; |
|
|||
350 | } |
|
|||
351 |
|
||||
352 |
|
||||
353 | void ChartAxis::axisSelected() |
|
402 | void ChartAxis::axisSelected() | |
354 | { |
|
403 | { | |
355 |
|
|
404 | //TODO: axis clicked; | |
356 | } |
|
405 | } | |
357 |
|
406 | |||
358 |
|
407 | |||
359 |
|
|
408 | QStringList ChartAxis::createNumberLabels(qreal min, qreal max, int ticks) const | |
360 | { |
|
409 | { | |
361 | Q_ASSERT(max>min); |
|
410 | Q_ASSERT(max>min); | |
362 | Q_ASSERT(ticks>1); |
|
411 | Q_ASSERT(ticks>1); | |
363 |
|
412 | |||
|
413 | QStringList labels; | |||
|
414 | ||||
364 | int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0); |
|
415 | int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0); | |
365 | n++; |
|
416 | n++; | |
366 |
|
417 | |||
367 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); |
|
418 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); | |
368 |
|
419 | |||
369 | QString format = axis->labelFormat(); |
|
420 | QString format = axis->labelFormat(); | |
370 |
|
421 | |||
371 | if(format.isNull()) { |
|
422 | if(format.isNull()) { | |
372 | for (int i=0; i< ticks; i++) { |
|
423 | for (int i=0; i< ticks; i++) { | |
373 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
424 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
374 | labels << QString::number(value,'f',n); |
|
425 | labels << QString::number(value,'f',n); | |
375 | } |
|
426 | } | |
376 | } |
|
427 | } | |
377 | else { |
|
428 | else { | |
378 | QByteArray array = format.toAscii(); |
|
429 | QByteArray array = format.toAscii(); | |
379 | for (int i=0; i< ticks; i++) { |
|
430 | for (int i=0; i< ticks; i++) { | |
380 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
431 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
381 | labels << QString().sprintf(array, value); |
|
432 | labels << QString().sprintf(array, value); | |
382 | } |
|
433 | } | |
383 | } |
|
434 | } | |
|
435 | ||||
|
436 | return labels; | |||
384 | } |
|
437 | } | |
385 |
|
438 | |||
386 | void ChartAxis::checkLayout() |
|
439 | Qt::Orientation ChartAxis::orientation() const | |
387 | { |
|
440 | { | |
388 | if(m_minWidth > m_rect.width()) { |
|
441 | return m_chartAxis->orientation(); | |
389 | presenter()->layout()->invalidate(); |
|
442 | } | |
390 | } |
|
|||
391 |
|
443 | |||
392 | if(m_minHeight > m_rect.height()) { |
|
444 | bool ChartAxis::isVisible() | |
393 | presenter()->layout()->invalidate(); |
|
445 | { | |
|
446 | return m_chartAxis->isVisible(); | |||
|
447 | } | |||
|
448 | ||||
|
449 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
450 | { | |||
|
451 | ||||
|
452 | Q_UNUSED(constraint); | |||
|
453 | QFontMetrics fn(m_title->font()); | |||
|
454 | QSizeF sh; | |||
|
455 | ||||
|
456 | if(m_titleText.isNull()) return sh; | |||
|
457 | ||||
|
458 | switch(which) { | |||
|
459 | case Qt::MinimumSize: | |||
|
460 | if(orientation()==Qt::Horizontal) { | |||
|
461 | sh = QSizeF(fn.boundingRect ("...").width(),fn.height()); | |||
|
462 | } | |||
|
463 | else if(orientation()==Qt::Vertical) { | |||
|
464 | sh = QSizeF(fn.height(),fn.boundingRect ("...").width()); | |||
|
465 | } | |||
|
466 | ||||
|
467 | break; | |||
|
468 | case Qt::MaximumSize: | |||
|
469 | case Qt::PreferredSize: | |||
|
470 | if(orientation()==Qt::Horizontal) { | |||
|
471 | sh = QSizeF(fn.boundingRect(m_chartAxis->title()).width(),fn.height()); | |||
|
472 | } | |||
|
473 | else if(orientation()==Qt::Vertical) { | |||
|
474 | sh = QSizeF(fn.height(),fn.boundingRect(m_chartAxis->title()).width()); | |||
|
475 | } | |||
|
476 | ||||
|
477 | break; | |||
|
478 | default: | |||
|
479 | break; | |||
394 | } |
|
480 | } | |
|
481 | ||||
|
482 | return sh; | |||
395 | } |
|
483 | } | |
396 |
|
484 | |||
397 | #include "moc_chartaxis_p.cpp" |
|
485 | #include "moc_chartaxis_p.cpp" | |
398 |
|
486 | |||
399 | QTCOMMERCIALCHART_END_NAMESPACE |
|
487 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,169 +1,181 | |||||
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 CHARTAXIS_H |
|
30 | #ifndef CHARTAXIS_H | |
31 | #define CHARTAXIS_H |
|
31 | #define CHARTAXIS_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartelement_p.h" |
|
34 | #include "chartelement_p.h" | |
35 | #include "axisanimation_p.h" |
|
35 | #include "axisanimation_p.h" | |
36 | #include <QGraphicsItem> |
|
36 | #include <QGraphicsItem> | |
|
37 | #include <QGraphicsLayoutItem> | |||
37 | #include <QFont> |
|
38 | #include <QFont> | |
38 |
|
39 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
41 | |||
41 | class QAbstractAxis; |
|
42 | class QAbstractAxis; | |
42 | class ChartPresenter; |
|
43 | class ChartPresenter; | |
43 |
|
44 | |||
44 | class ChartAxis : public ChartElement |
|
45 | class ChartAxis : public ChartElement, public QGraphicsLayoutItem | |
45 | { |
|
46 | { | |
46 | Q_OBJECT |
|
47 | Q_OBJECT | |
|
48 | Q_INTERFACES(QGraphicsLayoutItem) | |||
47 | public: |
|
49 | public: | |
48 | enum AxisType{ X_AXIS,Y_AXIS }; |
|
50 | enum AxisType{ X_AXIS,Y_AXIS }; | |
49 |
|
51 | |||
50 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter); |
|
52 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter); | |
51 | ~ChartAxis(); |
|
53 | ~ChartAxis(); | |
52 |
|
54 | |||
53 | virtual AxisType axisType() const = 0; |
|
55 | virtual AxisType axisType() const = 0; | |
54 |
|
56 | |||
55 | void setArrowOpacity(qreal opacity); |
|
57 | void setArrowOpacity(qreal opacity); | |
56 | qreal arrowOpacity() const; |
|
58 | qreal arrowOpacity() const; | |
57 | void setArrowVisibility(bool visible); |
|
59 | void setArrowVisibility(bool visible); | |
58 |
|
60 | |||
59 | void setGridOpacity(qreal opacity); |
|
61 | void setGridOpacity(qreal opacity); | |
60 | qreal gridOpacity() const; |
|
62 | qreal gridOpacity() const; | |
61 | void setGridVisibility(bool visible); |
|
63 | void setGridVisibility(bool visible); | |
62 |
|
64 | |||
63 | void setLabelsOpacity(qreal opacity); |
|
65 | void setLabelsOpacity(qreal opacity); | |
64 | qreal labelsOpacity() const; |
|
66 | qreal labelsOpacity() const; | |
65 | void setLabelsVisibility(bool visible); |
|
67 | void setLabelsVisibility(bool visible); | |
66 |
|
68 | |||
67 | void setShadesOpacity(qreal opacity); |
|
69 | void setShadesOpacity(qreal opacity); | |
68 | qreal shadesOpacity() const; |
|
70 | qreal shadesOpacity() const; | |
69 | void setShadesVisibility(bool visible); |
|
71 | void setShadesVisibility(bool visible); | |
70 |
|
72 | |||
71 | void setLabelsAngle(int angle); |
|
73 | void setLabelsAngle(int angle); | |
72 | int labelsAngle()const { return m_labelsAngle; } |
|
74 | int labelsAngle()const { return m_labelsAngle; } | |
73 |
|
75 | |||
74 | void setShadesBrush(const QBrush &brush); |
|
76 | void setShadesBrush(const QBrush &brush); | |
75 | void setShadesPen(const QPen &pen); |
|
77 | void setShadesPen(const QPen &pen); | |
76 |
|
78 | |||
77 | void setArrowPen(const QPen &pen); |
|
79 | void setArrowPen(const QPen &pen); | |
78 | void setGridPen(const QPen &pen); |
|
80 | void setGridPen(const QPen &pen); | |
79 |
|
81 | |||
80 | void setLabelsPen(const QPen &pen); |
|
82 | void setLabelsPen(const QPen &pen); | |
81 | void setLabelsBrush(const QBrush &brush); |
|
83 | void setLabelsBrush(const QBrush &brush); | |
82 | void setLabelsFont(const QFont &font); |
|
84 | void setLabelsFont(const QFont &font); | |
83 |
|
85 | |||
|
86 | void setTitlePen(const QPen &pen); | |||
|
87 | void setTitleBrush(const QBrush &brush); | |||
|
88 | void setTitleFont(const QFont &font); | |||
|
89 | void setTitleText(const QString& title); | |||
|
90 | ||||
|
91 | ||||
84 | void setLayout(QVector<qreal> &layout); |
|
92 | void setLayout(QVector<qreal> &layout); | |
85 | QVector<qreal> layout() const { return m_layoutVector; } |
|
93 | QVector<qreal> layout() const { return m_layoutVector; } | |
86 |
|
94 | |||
87 | void setAnimation(AxisAnimation* animation); |
|
95 | void setAnimation(AxisAnimation* animation); | |
88 | ChartAnimation* animation() const { return m_animation; }; |
|
96 | ChartAnimation* animation() const { return m_animation; }; | |
89 |
|
97 | |||
90 | QRectF geometry() const { return m_rect; } |
|
98 | Qt::Orientation orientation() const; | |
91 |
|
||||
92 | qreal minimumWidth(); |
|
|||
93 | qreal minimumHeight(); |
|
|||
94 |
|
99 | |||
|
100 | bool isVisible(); | |||
95 | void hide(); |
|
101 | void hide(); | |
96 |
|
102 | |||
|
103 | void setGeometry(const QRectF &size); | |||
|
104 | QRectF geometry() const { return m_rect; } | |||
|
105 | ||||
|
106 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const; | |||
|
107 | ||||
97 | protected: |
|
108 | protected: | |
98 | virtual void updateGeometry() = 0; |
|
109 | virtual void updateGeometry() = 0; | |
99 | virtual QVector<qreal> calculateLayout() const = 0; |
|
110 | virtual QVector<qreal> calculateLayout() const = 0; | |
100 |
|
|
111 | QStringList createNumberLabels(qreal min, qreal max,int ticks) const; | |
101 | void checkLayout(); |
|
112 | ||
102 |
|
113 | |||
103 | public Q_SLOTS: |
|
114 | public Q_SLOTS: | |
104 | virtual void handleAxisUpdated(); |
|
115 | virtual void handleAxisUpdated(); | |
105 | virtual void handleDomainUpdated(); |
|
116 | virtual void handleDomainUpdated(); | |
106 | void handleGeometryChanged(const QRectF &size); |
|
117 | ||
107 |
|
118 | |||
108 | private: |
|
119 | private: | |
109 | inline bool isEmpty(); |
|
120 | inline bool isEmpty(); | |
110 | void createItems(int count); |
|
121 | void createItems(int count); | |
111 | void deleteItems(int count); |
|
122 | void deleteItems(int count); | |
112 | void updateLayout(QVector<qreal> &layout); |
|
123 | void updateLayout(QVector<qreal> &layout); | |
113 | void axisSelected(); |
|
124 | void axisSelected(); | |
114 |
|
125 | |||
115 | protected: |
|
126 | protected: | |
116 | QAbstractAxis* m_chartAxis; |
|
127 | QAbstractAxis* m_chartAxis; | |
117 | QRectF m_rect; |
|
|||
118 | int m_labelsAngle; |
|
128 | int m_labelsAngle; | |
|
129 | //TODO: to be removed | |||
|
130 | QRectF m_rect; | |||
119 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
131 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
120 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
132 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
121 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
133 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
122 | QScopedPointer<QGraphicsItemGroup> m_arrow; |
|
134 | QScopedPointer<QGraphicsItemGroup> m_arrow; | |
|
135 | QGraphicsSimpleTextItem* m_title; | |||
123 | QVector<qreal> m_layoutVector; |
|
136 | QVector<qreal> m_layoutVector; | |
124 | qreal m_min; |
|
137 | qreal m_min; | |
125 | qreal m_max; |
|
138 | qreal m_max; | |
126 | AxisAnimation *m_animation; |
|
139 | AxisAnimation *m_animation; | |
127 | qreal m_minWidth; |
|
|||
128 | qreal m_minHeight; |
|
|||
129 | QFont m_font; |
|
140 | QFont m_font; | |
|
141 | QString m_titleText; | |||
130 |
|
142 | |||
131 | friend class AxisAnimation; |
|
143 | friend class AxisAnimation; | |
132 | friend class AxisItem; |
|
144 | friend class AxisItem; | |
133 |
|
145 | |||
134 | }; |
|
146 | }; | |
135 |
|
147 | |||
136 | class AxisItem: public QGraphicsLineItem |
|
148 | class AxisItem: public QGraphicsLineItem | |
137 | { |
|
149 | { | |
138 |
|
150 | |||
139 | public: |
|
151 | public: | |
140 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} |
|
152 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | |
141 |
|
153 | |||
142 | protected: |
|
154 | protected: | |
143 | void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
155 | void mousePressEvent(QGraphicsSceneMouseEvent *event) | |
144 | { |
|
156 | { | |
145 | Q_UNUSED(event) |
|
157 | Q_UNUSED(event) | |
146 | m_axis->axisSelected(); |
|
158 | m_axis->axisSelected(); | |
147 | } |
|
159 | } | |
148 |
|
160 | |||
149 | QRectF boundingRect() const |
|
161 | QRectF boundingRect() const | |
150 | { |
|
162 | { | |
151 | return shape().boundingRect(); |
|
163 | return shape().boundingRect(); | |
152 | } |
|
164 | } | |
153 |
|
165 | |||
154 | QPainterPath shape() const |
|
166 | QPainterPath shape() const | |
155 | { |
|
167 | { | |
156 | QPainterPath path = QGraphicsLineItem::shape(); |
|
168 | QPainterPath path = QGraphicsLineItem::shape(); | |
157 | QRectF rect = path.boundingRect(); |
|
169 | QRectF rect = path.boundingRect(); | |
158 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=ChartAxis::X_AXIS?8:0,m_axis->axisType()!=ChartAxis::Y_AXIS?8:0)); |
|
170 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=ChartAxis::X_AXIS?8:0,m_axis->axisType()!=ChartAxis::Y_AXIS?8:0)); | |
159 | return path; |
|
171 | return path; | |
160 | } |
|
172 | } | |
161 |
|
173 | |||
162 | private: |
|
174 | private: | |
163 | ChartAxis* m_axis; |
|
175 | ChartAxis* m_axis; | |
164 |
|
176 | |||
165 | }; |
|
177 | }; | |
166 |
|
178 | |||
167 | QTCOMMERCIALCHART_END_NAMESPACE |
|
179 | QTCOMMERCIALCHART_END_NAMESPACE | |
168 |
|
180 | |||
169 | #endif /* CHARTAXI_H */ |
|
181 | #endif /* CHARTAXI_H */ |
@@ -1,136 +1,170 | |||||
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 "chartdatetimeaxisx_p.h" |
|
21 | #include "chartdatetimeaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qdatetimeaxis.h" |
|
23 | #include "qdatetimeaxis.h" | |
24 | #include <QGraphicsLayout> |
|
24 | #include <QGraphicsLayout> | |
25 | #include <QDateTime> |
|
25 | #include <QDateTime> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | static int label_padding = 5; |
|
30 | static int label_padding = 5; | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | ChartDateTimeAxisX::ChartDateTimeAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
34 | ChartDateTimeAxisX::ChartDateTimeAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
35 | m_tickCount(0) |
|
35 | m_tickCount(0) | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() |
|
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartDateTimeAxisX::createLabels(QStringList &labels,qreal min, qreal max, int ticks) |
|
43 | void ChartDateTimeAxisX::createLabels(QStringList &labels,qreal min, qreal max, int ticks) | |
44 | { |
|
44 | { | |
45 | Q_ASSERT(max>min); |
|
45 | Q_ASSERT(max>min); | |
46 | Q_ASSERT(ticks>1); |
|
46 | Q_ASSERT(ticks>1); | |
47 |
|
47 | |||
48 | QDateTimeAxis *axis = qobject_cast<QDateTimeAxis *>(m_chartAxis); |
|
48 | QDateTimeAxis *axis = qobject_cast<QDateTimeAxis *>(m_chartAxis); | |
49 |
|
49 | |||
50 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
50 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
51 | n++; |
|
51 | n++; | |
52 | for (int i=0; i< ticks; i++) { |
|
52 | for (int i=0; i< ticks; i++) { | |
53 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
53 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
54 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(axis->format()); |
|
54 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(axis->format()); | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const |
|
58 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |
59 | { |
|
59 | { | |
60 | Q_ASSERT(m_tickCount>=2); |
|
60 | Q_ASSERT(m_tickCount>=2); | |
61 |
|
61 | |||
62 | QVector<qreal> points; |
|
62 | QVector<qreal> points; | |
63 | points.resize(m_tickCount); |
|
63 | points.resize(m_tickCount); | |
64 |
|
64 | QRectF rect = presenter()->chartsGeometry(); | ||
65 |
const qreal deltaX = |
|
65 | const qreal deltaX = rect.width()/(m_tickCount-1); | |
66 | for (int i = 0; i < m_tickCount; ++i) { |
|
66 | for (int i = 0; i < m_tickCount; ++i) { | |
67 |
int x = i * deltaX + |
|
67 | int x = i * deltaX + rect.left(); | |
68 | points[i] = x; |
|
68 | points[i] = x; | |
69 | } |
|
69 | } | |
70 | return points; |
|
70 | return points; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartDateTimeAxisX::updateGeometry() |
|
73 | void ChartDateTimeAxisX::updateGeometry() | |
74 | { |
|
74 | { | |
75 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
75 | const QVector<qreal>& layout = ChartAxis::layout(); | |
76 |
|
76 | |||
77 | m_minWidth = 0; |
|
|||
78 | m_minHeight = 0; |
|
|||
79 |
|
||||
80 | if(layout.isEmpty()) return; |
|
77 | if(layout.isEmpty()) return; | |
81 |
|
78 | |||
82 | QStringList ticksList; |
|
79 | QStringList ticksList; | |
83 |
|
80 | |||
84 | createLabels(ticksList,m_min,m_max,layout.size()); |
|
81 | createLabels(ticksList,m_min,m_max,layout.size()); | |
85 |
|
82 | |||
86 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
83 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
87 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
84 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
88 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
85 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
89 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
86 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
90 |
|
87 | |||
91 | Q_ASSERT(labels.size() == ticksList.size()); |
|
88 | Q_ASSERT(labels.size() == ticksList.size()); | |
92 | Q_ASSERT(layout.size() == ticksList.size()); |
|
89 | Q_ASSERT(layout.size() == ticksList.size()); | |
93 |
|
90 | |||
|
91 | QRectF chartRect = presenter()->chartsGeometry(); | |||
|
92 | ||||
94 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
93 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
95 |
lineItem->setLine( |
|
94 | lineItem->setLine(chartRect.left(), chartRect.bottom(), chartRect.right(), chartRect.bottom()); | |
96 |
|
95 | |||
97 | qreal width = 0; |
|
96 | qreal width = 0; | |
98 | for (int i = 0; i < layout.size(); ++i) { |
|
97 | for (int i = 0; i < layout.size(); ++i) { | |
99 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
98 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
100 |
lineItem->setLine(layout[i], |
|
99 | lineItem->setLine(layout[i], chartRect.top(), layout[i], chartRect.bottom()); | |
101 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
100 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
102 | labelItem->setText(ticksList.at(i)); |
|
101 | labelItem->setText(ticksList.at(i)); | |
103 | const QRectF& rect = labelItem->boundingRect(); |
|
102 | const QRectF& rect = labelItem->boundingRect(); | |
104 | QPointF center = rect.center(); |
|
103 | QPointF center = rect.center(); | |
105 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
104 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
106 |
labelItem->setPos(layout[i] - center.x(), |
|
105 | labelItem->setPos(layout[i] - center.x(), chartRect.bottom() + label_padding); | |
107 |
|
106 | |||
108 | if(labelItem->pos().x()<=width){ |
|
107 | if(labelItem->pos().x()<=width){ | |
109 | labelItem->setVisible(false); |
|
108 | labelItem->setVisible(false); | |
110 | lineItem->setVisible(false); |
|
109 | lineItem->setVisible(false); | |
111 | }else{ |
|
110 | }else{ | |
112 | labelItem->setVisible(true); |
|
111 | labelItem->setVisible(true); | |
113 | lineItem->setVisible(true); |
|
112 | lineItem->setVisible(true); | |
114 | width=rect.width()+labelItem->pos().x(); |
|
113 | width=rect.width()+labelItem->pos().x(); | |
115 | } |
|
114 | } | |
116 | m_minWidth+=rect.width(); |
|
|||
117 | m_minHeight=qMax(rect.height(),m_minHeight); |
|
|||
118 |
|
115 | |||
119 | if ((i+1)%2 && i>1) { |
|
116 | if ((i+1)%2 && i>1) { | |
120 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
117 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
121 |
rectItem->setRect(layout[i-1], |
|
118 | rectItem->setRect(layout[i-1],chartRect.top(),layout[i]-layout[i-1],chartRect.height()); | |
122 | } |
|
119 | } | |
123 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
120 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
124 |
lineItem->setLine(layout[i], |
|
121 | lineItem->setLine(layout[i],chartRect.bottom(),layout[i],chartRect.bottom()+5); | |
125 | } |
|
122 | } | |
126 | } |
|
123 | } | |
127 |
|
124 | |||
128 | void ChartDateTimeAxisX::handleAxisUpdated() |
|
125 | void ChartDateTimeAxisX::handleAxisUpdated() | |
129 | { |
|
126 | { | |
130 | //TODO:: fix this |
|
127 | //TODO:: fix this | |
131 | QDateTimeAxis* axis = qobject_cast<QDateTimeAxis*>(m_chartAxis); |
|
128 | QDateTimeAxis* axis = qobject_cast<QDateTimeAxis*>(m_chartAxis); | |
132 | m_tickCount = axis->tickCount(); |
|
129 | m_tickCount = axis->tickCount(); | |
133 | ChartAxis::handleAxisUpdated(); |
|
130 | ChartAxis::handleAxisUpdated(); | |
134 | } |
|
131 | } | |
135 |
|
132 | |||
|
133 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
134 | { | |||
|
135 | Q_UNUSED(constraint) | |||
|
136 | ||||
|
137 | QFontMetrics fn(m_font); | |||
|
138 | QSizeF sh; | |||
|
139 | ||||
|
140 | switch (which) { | |||
|
141 | case Qt::MinimumSize: | |||
|
142 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); | |||
|
143 | break; | |||
|
144 | case Qt::PreferredSize:{ | |||
|
145 | ||||
|
146 | const QVector<qreal>& layout = ChartAxis::layout(); | |||
|
147 | if(layout.isEmpty()) break; | |||
|
148 | QStringList ticksList; | |||
|
149 | ||||
|
150 | ||||
|
151 | qreal width=0; | |||
|
152 | qreal height=0; | |||
|
153 | ||||
|
154 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
155 | { | |||
|
156 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |||
|
157 | width+=rect.width(); | |||
|
158 | height+=qMax(rect.height()+label_padding,height); | |||
|
159 | } | |||
|
160 | sh = QSizeF(width,height); | |||
|
161 | break; | |||
|
162 | } | |||
|
163 | default: | |||
|
164 | break; | |||
|
165 | } | |||
|
166 | ||||
|
167 | return sh; | |||
|
168 | } | |||
|
169 | ||||
136 | QTCOMMERCIALCHART_END_NAMESPACE |
|
170 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,61 +1,61 | |||||
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 CHARTDATETIMEAXISX_H |
|
30 | #ifndef CHARTDATETIMEAXISX_H | |
31 | #define CHARTDATETIMEAXISX_H |
|
31 | #define CHARTDATETIMEAXISX_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 | class ChartDateTimeAxisX : public ChartAxis |
|
40 | class ChartDateTimeAxisX : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 | ChartDateTimeAxisX(QAbstractAxis *axis, ChartPresenter *presenter); |
|
43 | ChartDateTimeAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 | ~ChartDateTimeAxisX(); |
|
44 | ~ChartDateTimeAxisX(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return X_AXIS;} |
|
46 | AxisType axisType() const { return X_AXIS;} | |
47 |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
48 | protected: |
|
48 | protected: | |
49 | void createLabels(QStringList &labels,qreal min, qreal max, int ticks); |
|
49 | void createLabels(QStringList &labels,qreal min, qreal max, int ticks); | |
50 | void handleAxisUpdated(); |
|
50 | void handleAxisUpdated(); | |
51 | QVector<qreal> calculateLayout() const; |
|
51 | QVector<qreal> calculateLayout() const; | |
52 | void updateGeometry(); |
|
52 | void updateGeometry(); | |
53 |
|
53 | |||
54 | private: |
|
54 | private: | |
55 | int m_tickCount; |
|
55 | int m_tickCount; | |
56 |
|
56 | |||
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
60 |
|
60 | |||
61 | #endif /* CHARTDATETIMEAXISX_H */ |
|
61 | #endif /* CHARTDATETIMEAXISX_H */ |
@@ -1,142 +1,175 | |||||
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 "chartdatetimeaxisy_p.h" |
|
21 | #include "chartdatetimeaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qdatetimeaxis.h" |
|
23 | #include "qdatetimeaxis.h" | |
24 | #include <QGraphicsLayout> |
|
24 | #include <QGraphicsLayout> | |
25 | #include <QFontMetrics> |
|
25 | #include <QFontMetrics> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | static int label_padding = 5; |
|
30 | static int label_padding = 5; | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | ChartDateTimeAxisY::ChartDateTimeAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
34 | ChartDateTimeAxisY::ChartDateTimeAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
35 | m_tickCount(0) |
|
35 | m_tickCount(0) | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() |
|
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartDateTimeAxisY::createLabels(QStringList &labels,qreal min, qreal max, int ticks) |
|
43 | void ChartDateTimeAxisY::createLabels(QStringList &labels,qreal min, qreal max, int ticks) | |
44 | { |
|
44 | { | |
45 | Q_ASSERT(max>min); |
|
45 | Q_ASSERT(max>min); | |
46 | Q_ASSERT(ticks>1); |
|
46 | Q_ASSERT(ticks>1); | |
47 |
|
47 | |||
48 | QDateTimeAxis *axis = qobject_cast<QDateTimeAxis *>(m_chartAxis); |
|
48 | QDateTimeAxis *axis = qobject_cast<QDateTimeAxis *>(m_chartAxis); | |
49 |
|
49 | |||
50 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
50 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
51 | n++; |
|
51 | n++; | |
52 | for (int i=0; i< ticks; i++) { |
|
52 | for (int i=0; i< ticks; i++) { | |
53 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
53 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
54 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(axis->format()); |
|
54 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(axis->format()); | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const |
|
58 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |
59 | { |
|
59 | { | |
60 | Q_ASSERT(m_tickCount>=2); |
|
60 | Q_ASSERT(m_tickCount>=2); | |
61 |
|
61 | |||
62 | QVector<qreal> points; |
|
62 | QVector<qreal> points; | |
63 | points.resize(m_tickCount); |
|
63 | points.resize(m_tickCount); | |
64 |
|
64 | QRectF rect = presenter()->chartsGeometry(); | ||
65 |
const qreal deltaY = |
|
65 | const qreal deltaY = rect.height()/(m_tickCount-1); | |
66 | for (int i = 0; i < m_tickCount; ++i) { |
|
66 | for (int i = 0; i < m_tickCount; ++i) { | |
67 |
int y = i * -deltaY + |
|
67 | int y = i * -deltaY + rect.bottom(); | |
68 | points[i] = y; |
|
68 | points[i] = y; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | return points; |
|
71 | return points; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void ChartDateTimeAxisY::updateGeometry() |
|
74 | void ChartDateTimeAxisY::updateGeometry() | |
75 | { |
|
75 | { | |
76 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
76 | const QVector<qreal> &layout = ChartAxis::layout(); | |
77 | m_minWidth = 0; |
|
|||
78 | m_minHeight = 0; |
|
|||
79 |
|
77 | |||
80 | if(layout.isEmpty()) return; |
|
78 | if(layout.isEmpty()) return; | |
81 |
|
79 | |||
82 | QStringList ticksList; |
|
80 | QStringList ticksList; | |
83 |
|
81 | |||
84 | createLabels(ticksList,m_min,m_max,layout.size()); |
|
82 | createLabels(ticksList,m_min,m_max,layout.size()); | |
85 |
|
83 | |||
86 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
84 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
87 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
85 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
88 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
86 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
89 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
87 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
90 |
|
88 | |||
91 | Q_ASSERT(labels.size() == ticksList.size()); |
|
89 | Q_ASSERT(labels.size() == ticksList.size()); | |
92 | Q_ASSERT(layout.size() == ticksList.size()); |
|
90 | Q_ASSERT(layout.size() == ticksList.size()); | |
93 |
|
91 | |||
94 | qreal height = 2*m_rect.bottom(); |
|
92 | QRectF chartRect = presenter()->chartsGeometry(); | |
|
93 | ||||
|
94 | qreal height = chartRect.bottom(); | |||
95 |
|
95 | |||
96 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
96 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
97 |
lineItem->setLine( |
|
97 | lineItem->setLine(chartRect.left() , chartRect.top(), chartRect.left(), chartRect.bottom()); | |
98 |
|
98 | |||
99 | for (int i = 0; i < layout.size(); ++i) { |
|
99 | for (int i = 0; i < layout.size(); ++i) { | |
100 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
100 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
101 |
lineItem->setLine( |
|
101 | lineItem->setLine(chartRect.left() , layout[i], chartRect.right(), layout[i]); | |
102 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
102 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
103 |
|
103 | |||
104 | labelItem->setText(ticksList.at(i)); |
|
104 | labelItem->setText(ticksList.at(i)); | |
105 | const QRectF& rect = labelItem->boundingRect(); |
|
105 | const QRectF& rect = labelItem->boundingRect(); | |
106 |
|
106 | |||
107 | QPointF center = rect.center(); |
|
107 | QPointF center = rect.center(); | |
108 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
108 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
109 |
labelItem->setPos( |
|
109 | labelItem->setPos(chartRect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
110 |
|
110 | |||
111 | if(labelItem->pos().y()+rect.height()>height) { |
|
111 | if(labelItem->pos().y()+rect.height()>height) { | |
112 | labelItem->setVisible(false); |
|
112 | labelItem->setVisible(false); | |
113 | lineItem->setVisible(false); |
|
113 | lineItem->setVisible(false); | |
114 | } |
|
114 | } | |
115 | else { |
|
115 | else { | |
116 | labelItem->setVisible(true); |
|
116 | labelItem->setVisible(true); | |
117 | lineItem->setVisible(true); |
|
117 | lineItem->setVisible(true); | |
118 | height=labelItem->pos().y(); |
|
118 | height=labelItem->pos().y(); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
|||
122 | m_minHeight+=rect.height(); |
|
|||
123 |
|
||||
124 | if ((i+1)%2 && i>1) { |
|
121 | if ((i+1)%2 && i>1) { | |
125 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
122 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
126 |
rectItem->setRect( |
|
123 | rectItem->setRect(chartRect.left(),layout[i],chartRect.width(),layout[i-1]-layout[i]); | |
127 | } |
|
124 | } | |
128 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
125 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
129 |
lineItem->setLine( |
|
126 | lineItem->setLine(chartRect.left()-5,layout[i],chartRect.left(),layout[i]); | |
130 | } |
|
127 | } | |
131 | } |
|
128 | } | |
132 |
|
129 | |||
133 | void ChartDateTimeAxisY::handleAxisUpdated() |
|
130 | void ChartDateTimeAxisY::handleAxisUpdated() | |
134 | { |
|
131 | { | |
135 | //TODO:: fix this |
|
132 | //TODO:: fix this | |
136 | QDateTimeAxis* axis = qobject_cast<QDateTimeAxis*>(m_chartAxis); |
|
133 | QDateTimeAxis* axis = qobject_cast<QDateTimeAxis*>(m_chartAxis); | |
137 | m_tickCount = axis->tickCount(); |
|
134 | m_tickCount = axis->tickCount(); | |
138 | ChartAxis::handleAxisUpdated(); |
|
135 | ChartAxis::handleAxisUpdated(); | |
139 | } |
|
136 | } | |
140 |
|
137 | |||
|
138 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
139 | { | |||
|
140 | Q_UNUSED(constraint) | |||
|
141 | ||||
|
142 | QFontMetrics fn(m_font); | |||
|
143 | QSizeF sh; | |||
|
144 | ||||
|
145 | switch (which) { | |||
|
146 | case Qt::MinimumSize: | |||
|
147 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); | |||
|
148 | break; | |||
|
149 | case Qt::PreferredSize:{ | |||
|
150 | ||||
|
151 | const QVector<qreal>& layout = ChartAxis::layout(); | |||
|
152 | if(layout.isEmpty()) break; | |||
|
153 | QStringList ticksList; | |||
|
154 | ||||
|
155 | ||||
|
156 | qreal width=0; | |||
|
157 | qreal height=0; | |||
|
158 | ||||
|
159 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
160 | { | |||
|
161 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |||
|
162 | width+=rect.width(); | |||
|
163 | height+=qMax(rect.height()+label_padding,height); | |||
|
164 | } | |||
|
165 | sh = QSizeF(width,height); | |||
|
166 | break; | |||
|
167 | } | |||
|
168 | default: | |||
|
169 | break; | |||
|
170 | } | |||
|
171 | ||||
|
172 | return sh; | |||
|
173 | } | |||
141 |
|
174 | |||
142 | QTCOMMERCIALCHART_END_NAMESPACE |
|
175 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,59 | |||||
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 CHARTDATETIMEAXISY_H |
|
30 | #ifndef CHARTDATETIMEAXISY_H | |
31 | #define CHARTDATETIMEAXISY_H |
|
31 | #define CHARTDATETIMEAXISY_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 | class ChartDateTimeAxisY : public ChartAxis |
|
40 | class ChartDateTimeAxisY : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 | ChartDateTimeAxisY(QAbstractAxis *axis, ChartPresenter *presenter); |
|
43 | ChartDateTimeAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 | ~ChartDateTimeAxisY(); |
|
44 | ~ChartDateTimeAxisY(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return Y_AXIS;} |
|
46 | AxisType axisType() const { return Y_AXIS;} | |
47 |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
48 | protected: |
|
48 | protected: | |
49 | void createLabels(QStringList &labels,qreal min, qreal max, int ticks); |
|
49 | void createLabels(QStringList &labels,qreal min, qreal max, int ticks); | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
52 | void handleAxisUpdated(); |
|
52 | void handleAxisUpdated(); | |
53 | private: |
|
53 | private: | |
54 | int m_tickCount; |
|
54 | int m_tickCount; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
58 | |||
59 | #endif /* CHARTDATETIMEAXISY_H */ |
|
59 | #endif /* CHARTDATETIMEAXISY_H */ |
@@ -1,658 +1,742 | |||||
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 "qabstractaxis.h" |
|
21 | #include "qabstractaxis.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QAbstractAxis |
|
27 | \class QAbstractAxis | |
28 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
28 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
29 | \mainclass |
|
29 | \mainclass | |
30 |
|
30 | |||
31 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
31 | There is only one x Axis visible at the time, however there can be multiple y axes. | |
32 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
32 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
33 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
33 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \qmlclass AbstractAxis QAbstractAxis |
|
37 | \qmlclass AbstractAxis QAbstractAxis | |
38 | \brief The Axis element is used for manipulating chart's axes |
|
38 | \brief The Axis element is used for manipulating chart's axes | |
39 |
|
39 | |||
40 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
40 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. | |
41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
43 |
|
43 | |||
44 | To access Axes you can use ChartView API. For example: |
|
44 | To access Axes you can use ChartView API. For example: | |
45 | \code |
|
45 | \code | |
46 | ChartView { |
|
46 | ChartView { | |
47 | axisX.min: 0 |
|
47 | axisX.min: 0 | |
48 | axisX.max: 3 |
|
48 | axisX.max: 3 | |
49 | axisX.ticksCount: 4 |
|
49 | axisX.ticksCount: 4 | |
50 | axisY.min: 0 |
|
50 | axisY.min: 0 | |
51 | axisY.max: 4 |
|
51 | axisY.max: 4 | |
52 | // Add a few series... |
|
52 | // Add a few series... | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \enum QAbstractAxis::AxisType |
|
58 | \enum QAbstractAxis::AxisType | |
59 |
|
59 | |||
60 | The type of the series object. |
|
60 | The type of the series object. | |
61 |
|
61 | |||
62 | \value AxisTypeNoAxis |
|
62 | \value AxisTypeNoAxis | |
63 | \value AxisTypeValue |
|
63 | \value AxisTypeValue | |
64 | \value AxisTypeBarCategory |
|
64 | \value AxisTypeBarCategory | |
65 | \value AxisTypeCategory |
|
65 | \value AxisTypeCategory | |
66 | \value AxisTypeDateTime |
|
66 | \value AxisTypeDateTime | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | *\fn void QAbstractAxis::type() const |
|
70 | *\fn void QAbstractAxis::type() const | |
71 | Returns the type of the axis |
|
71 | Returns the type of the axis | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \property QAbstractAxis::lineVisible |
|
75 | \property QAbstractAxis::lineVisible | |
76 | The visibility of the axis line |
|
76 | The visibility of the axis line | |
77 | */ |
|
77 | */ | |
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty bool AbstractAxis::lineVisible |
|
79 | \qmlproperty bool AbstractAxis::lineVisible | |
80 | The visibility of the axis line |
|
80 | The visibility of the axis line | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QAbstractAxis::labelsVisible |
|
84 | \property QAbstractAxis::labelsVisible | |
85 | Defines if axis labels are visible. |
|
85 | Defines if axis labels are visible. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty bool AbstractAxis::labelsVisible |
|
88 | \qmlproperty bool AbstractAxis::labelsVisible | |
89 | Defines if axis labels are visible. |
|
89 | Defines if axis labels are visible. | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \property QAbstractAxis::visible |
|
93 | \property QAbstractAxis::visible | |
94 | The visibility of the axis. |
|
94 | The visibility of the axis. | |
95 | */ |
|
95 | */ | |
96 | /*! |
|
96 | /*! | |
97 | \qmlproperty bool AbstractAxis::visible |
|
97 | \qmlproperty bool AbstractAxis::visible | |
98 | The visibility of the axis. |
|
98 | The visibility of the axis. | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \property QAbstractAxis::gridVisible |
|
102 | \property QAbstractAxis::gridVisible | |
103 | The visibility of the grid lines. |
|
103 | The visibility of the grid lines. | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlproperty bool AbstractAxis::gridVisible |
|
106 | \qmlproperty bool AbstractAxis::gridVisible | |
107 | The visibility of the grid lines. |
|
107 | The visibility of the grid lines. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \property QAbstractAxis::color |
|
111 | \property QAbstractAxis::color | |
112 | The color of the axis and ticks. |
|
112 | The color of the axis and ticks. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty color AbstractAxis::color |
|
115 | \qmlproperty color AbstractAxis::color | |
116 | The color of the axis and ticks. |
|
116 | The color of the axis and ticks. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \property QAbstractAxis::labelsFont |
|
120 | \property QAbstractAxis::labelsFont | |
121 | The font of the axis labels. |
|
121 | The font of the axis labels. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \qmlproperty Font AbstractAxis::labelsFont |
|
125 | \qmlproperty Font AbstractAxis::labelsFont | |
126 | The font of the axis labels. |
|
126 | The font of the axis labels. | |
127 |
|
127 | |||
128 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
128 | See the \l {Font} {QML Font Element} for detailed documentation. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \property QAbstractAxis::labelsColor |
|
132 | \property QAbstractAxis::labelsColor | |
133 | The color of the axis labels. |
|
133 | The color of the axis labels. | |
134 | */ |
|
134 | */ | |
135 | /*! |
|
135 | /*! | |
136 | \qmlproperty color AbstractAxis::labelsColor |
|
136 | \qmlproperty color AbstractAxis::labelsColor | |
137 | The color of the axis labels. |
|
137 | The color of the axis labels. | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \property QAbstractAxis::labelsAngle |
|
141 | \property QAbstractAxis::labelsAngle | |
142 | The angle of the axis labels in degrees. |
|
142 | The angle of the axis labels in degrees. | |
143 | */ |
|
143 | */ | |
144 | /*! |
|
144 | /*! | |
145 | \qmlproperty int AbstractAxis::labelsAngle |
|
145 | \qmlproperty int AbstractAxis::labelsAngle | |
146 | The angle of the axis labels in degrees. |
|
146 | The angle of the axis labels in degrees. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \property QAbstractAxis::shadesVisible |
|
150 | \property QAbstractAxis::shadesVisible | |
151 | The visibility of the axis shades. |
|
151 | The visibility of the axis shades. | |
152 | */ |
|
152 | */ | |
153 | /*! |
|
153 | /*! | |
154 | \qmlproperty bool AbstractAxis::shadesVisible |
|
154 | \qmlproperty bool AbstractAxis::shadesVisible | |
155 | The visibility of the axis shades. |
|
155 | The visibility of the axis shades. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \property QAbstractAxis::shadesColor |
|
159 | \property QAbstractAxis::shadesColor | |
160 | The fill (brush) color of the axis shades. |
|
160 | The fill (brush) color of the axis shades. | |
161 | */ |
|
161 | */ | |
162 | /*! |
|
162 | /*! | |
163 | \qmlproperty color AbstractAxis::shadesColor |
|
163 | \qmlproperty color AbstractAxis::shadesColor | |
164 | The fill (brush) color of the axis shades. |
|
164 | The fill (brush) color of the axis shades. | |
165 | */ |
|
165 | */ | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | \property QAbstractAxis::shadesBorderColor |
|
168 | \property QAbstractAxis::shadesBorderColor | |
169 | The border (pen) color of the axis shades. |
|
169 | The border (pen) color of the axis shades. | |
170 | */ |
|
170 | */ | |
171 | /*! |
|
171 | /*! | |
172 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
172 | \qmlproperty color AbstractAxis::shadesBorderColor | |
173 | The border (pen) color of the axis shades. |
|
173 | The border (pen) color of the axis shades. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
177 | \fn void QAbstractAxis::visibleChanged(bool visible) | |
178 | Visibility of the axis has changed to \a visible. |
|
178 | Visibility of the axis has changed to \a visible. | |
179 | */ |
|
179 | */ | |
180 | /*! |
|
180 | /*! | |
181 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
181 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) | |
182 | Visibility of the axis has changed to \a visible. |
|
182 | Visibility of the axis has changed to \a visible. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
186 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) | |
187 | Visibility of the axis line has changed to \a visible. |
|
187 | Visibility of the axis line has changed to \a visible. | |
188 | */ |
|
188 | */ | |
189 | /*! |
|
189 | /*! | |
190 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
190 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) | |
191 | Visibility of the axis line has changed to \a visible. |
|
191 | Visibility of the axis line has changed to \a visible. | |
192 | */ |
|
192 | */ | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
195 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) | |
196 | Visibility of the labels of the axis has changed to \a visible. |
|
196 | Visibility of the labels of the axis has changed to \a visible. | |
197 | */ |
|
197 | */ | |
198 | /*! |
|
198 | /*! | |
199 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
199 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) | |
200 | Visibility of the labels of the axis has changed to \a visible. |
|
200 | Visibility of the labels of the axis has changed to \a visible. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
204 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) | |
205 | Visibility of the grid lines of the axis has changed to \a visible. |
|
205 | Visibility of the grid lines of the axis has changed to \a visible. | |
206 | */ |
|
206 | */ | |
207 | /*! |
|
207 | /*! | |
208 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
208 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) | |
209 | Visibility of the grid lines of the axis has changed to \a visible. |
|
209 | Visibility of the grid lines of the axis has changed to \a visible. | |
210 | */ |
|
210 | */ | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
213 | \fn void QAbstractAxis::colorChanged(QColor color) | |
214 | Emitted if the \a color of the axis is changed. |
|
214 | Emitted if the \a color of the axis is changed. | |
215 | */ |
|
215 | */ | |
216 | /*! |
|
216 | /*! | |
217 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
217 | \qmlsignal AbstractAxis::onColorChanged(QColor color) | |
218 | Emitted if the \a color of the axis is changed. |
|
218 | Emitted if the \a color of the axis is changed. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
222 | \fn void QAbstractAxis::labelsColorChanged(QColor color) | |
223 | Emitted if the \a color of the axis labels is changed. |
|
223 | Emitted if the \a color of the axis labels is changed. | |
224 | */ |
|
224 | */ | |
225 | /*! |
|
225 | /*! | |
226 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
226 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) | |
227 | Emitted if the \a color of the axis labels is changed. |
|
227 | Emitted if the \a color of the axis labels is changed. | |
228 | */ |
|
228 | */ | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
231 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
232 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
232 | Emitted if the visibility of the axis shades is changed to \a visible. | |
233 | */ |
|
233 | */ | |
234 | /*! |
|
234 | /*! | |
235 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
235 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) | |
236 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
236 | Emitted if the visibility of the axis shades is changed to \a visible. | |
237 | */ |
|
237 | */ | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
240 | \fn void QAbstractAxis::shadesColorChanged(QColor color) | |
241 | Emitted if the \a color of the axis shades is changed. |
|
241 | Emitted if the \a color of the axis shades is changed. | |
242 | */ |
|
242 | */ | |
243 | /*! |
|
243 | /*! | |
244 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
244 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) | |
245 | Emitted if the \a color of the axis shades is changed. |
|
245 | Emitted if the \a color of the axis shades is changed. | |
246 | */ |
|
246 | */ | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
249 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
250 | Emitted if the border \a color of the axis shades is changed. |
|
250 | Emitted if the border \a color of the axis shades is changed. | |
251 | */ |
|
251 | */ | |
252 | /*! |
|
252 | /*! | |
253 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
253 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) | |
254 | Emitted if the border \a color of the axis shades is changed. |
|
254 | Emitted if the border \a color of the axis shades is changed. | |
255 | */ |
|
255 | */ | |
256 |
|
256 | |||
257 | /*! |
|
257 | /*! | |
258 | \internal |
|
258 | \internal | |
259 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
259 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
260 | QChart when axis added. |
|
260 | QChart when axis added. | |
261 | */ |
|
261 | */ | |
262 |
|
262 | |||
263 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : |
|
263 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : | |
264 | QObject(parent), |
|
264 | QObject(parent), | |
265 | d_ptr(&d) |
|
265 | d_ptr(&d) | |
266 | { |
|
266 | { | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
270 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
271 | */ |
|
271 | */ | |
272 |
|
272 | |||
273 | QAbstractAxis::~QAbstractAxis() |
|
273 | QAbstractAxis::~QAbstractAxis() | |
274 | { |
|
274 | { | |
275 | if(d_ptr->m_dataset) qFatal("Still binded axis detected !"); |
|
275 | if(d_ptr->m_dataset) qFatal("Still binded axis detected !"); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Sets \a pen used to draw axis line and ticks. |
|
279 | Sets \a pen used to draw axis line and ticks. | |
280 | */ |
|
280 | */ | |
281 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
281 | void QAbstractAxis::setLinePen(const QPen &pen) | |
282 | { |
|
282 | { | |
283 | if (d_ptr->m_axisPen!=pen) { |
|
283 | if (d_ptr->m_axisPen!=pen) { | |
284 | d_ptr->m_axisPen = pen; |
|
284 | d_ptr->m_axisPen = pen; | |
285 | d_ptr->emitUpdated(); |
|
285 | d_ptr->emitUpdated(); | |
286 | } |
|
286 | } | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | Returns pen used to draw axis and ticks. |
|
290 | Returns pen used to draw axis and ticks. | |
291 | */ |
|
291 | */ | |
292 | QPen QAbstractAxis::linePen() const |
|
292 | QPen QAbstractAxis::linePen() const | |
293 | { |
|
293 | { | |
294 | return d_ptr->m_axisPen; |
|
294 | return d_ptr->m_axisPen; | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void QAbstractAxis::setLinePenColor(QColor color) |
|
297 | void QAbstractAxis::setLinePenColor(QColor color) | |
298 | { |
|
298 | { | |
299 | QPen p = d_ptr->m_axisPen; |
|
299 | QPen p = d_ptr->m_axisPen; | |
300 | if (p.color() != color) { |
|
300 | if (p.color() != color) { | |
301 | p.setColor(color); |
|
301 | p.setColor(color); | |
302 | setLinePen(p); |
|
302 | setLinePen(p); | |
303 | emit colorChanged(color); |
|
303 | emit colorChanged(color); | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | QColor QAbstractAxis::linePenColor() const |
|
307 | QColor QAbstractAxis::linePenColor() const | |
308 | { |
|
308 | { | |
309 | return d_ptr->m_axisPen.color(); |
|
309 | return d_ptr->m_axisPen.color(); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | /*! |
|
312 | /*! | |
313 | Sets if axis and ticks are \a visible. |
|
313 | Sets if axis and ticks are \a visible. | |
314 | */ |
|
314 | */ | |
315 | void QAbstractAxis::setLineVisible(bool visible) |
|
315 | void QAbstractAxis::setLineVisible(bool visible) | |
316 | { |
|
316 | { | |
317 | if (d_ptr->m_arrowVisible != visible) { |
|
317 | if (d_ptr->m_arrowVisible != visible) { | |
318 | d_ptr->m_arrowVisible = visible; |
|
318 | d_ptr->m_arrowVisible = visible; | |
319 | d_ptr->emitUpdated(); |
|
319 | d_ptr->emitUpdated(); | |
320 | emit lineVisibleChanged(visible); |
|
320 | emit lineVisibleChanged(visible); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | bool QAbstractAxis::isLineVisible() const |
|
324 | bool QAbstractAxis::isLineVisible() const | |
325 | { |
|
325 | { | |
326 | return d_ptr->m_arrowVisible; |
|
326 | return d_ptr->m_arrowVisible; | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
329 | void QAbstractAxis::setGridLineVisible(bool visible) | |
330 | { |
|
330 | { | |
331 | if (d_ptr->m_gridLineVisible != visible) { |
|
331 | if (d_ptr->m_gridLineVisible != visible) { | |
332 | d_ptr->m_gridLineVisible = visible; |
|
332 | d_ptr->m_gridLineVisible = visible; | |
333 | d_ptr->emitUpdated(); |
|
333 | d_ptr->emitUpdated(); | |
334 | emit gridVisibleChanged(visible); |
|
334 | emit gridVisibleChanged(visible); | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | bool QAbstractAxis::isGridLineVisible() const |
|
338 | bool QAbstractAxis::isGridLineVisible() const | |
339 | { |
|
339 | { | |
340 | return d_ptr->m_gridLineVisible; |
|
340 | return d_ptr->m_gridLineVisible; | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | /*! |
|
343 | /*! | |
344 | Sets \a pen used to draw grid line. |
|
344 | Sets \a pen used to draw grid line. | |
345 | */ |
|
345 | */ | |
346 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
346 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
347 | { |
|
347 | { | |
348 | if (d_ptr->m_gridLinePen != pen) { |
|
348 | if (d_ptr->m_gridLinePen != pen) { | |
349 | d_ptr->m_gridLinePen = pen; |
|
349 | d_ptr->m_gridLinePen = pen; | |
350 | d_ptr->emitUpdated(); |
|
350 | d_ptr->emitUpdated(); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns pen used to draw grid. |
|
355 | Returns pen used to draw grid. | |
356 | */ |
|
356 | */ | |
357 | QPen QAbstractAxis::gridLinePen() const |
|
357 | QPen QAbstractAxis::gridLinePen() const | |
358 | { |
|
358 | { | |
359 | return d_ptr->m_gridLinePen; |
|
359 | return d_ptr->m_gridLinePen; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
362 | void QAbstractAxis::setLabelsVisible(bool visible) | |
363 | { |
|
363 | { | |
364 | if (d_ptr->m_labelsVisible != visible) { |
|
364 | if (d_ptr->m_labelsVisible != visible) { | |
365 | d_ptr->m_labelsVisible = visible; |
|
365 | d_ptr->m_labelsVisible = visible; | |
366 | d_ptr->emitUpdated(); |
|
366 | d_ptr->emitUpdated(); | |
367 | emit labelsVisibleChanged(visible); |
|
367 | emit labelsVisibleChanged(visible); | |
368 | } |
|
368 | } | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | bool QAbstractAxis::labelsVisible() const |
|
371 | bool QAbstractAxis::labelsVisible() const | |
372 | { |
|
372 | { | |
373 | return d_ptr->m_labelsVisible; |
|
373 | return d_ptr->m_labelsVisible; | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | /*! |
|
376 | /*! | |
377 | Sets \a pen used to draw labels. |
|
377 | Sets \a pen used to draw labels. | |
378 | */ |
|
378 | */ | |
379 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
379 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
380 | { |
|
380 | { | |
381 | if (d_ptr->m_labelsPen != pen) { |
|
381 | if (d_ptr->m_labelsPen != pen) { | |
382 | d_ptr->m_labelsPen = pen; |
|
382 | d_ptr->m_labelsPen = pen; | |
383 | d_ptr->emitUpdated(); |
|
383 | d_ptr->emitUpdated(); | |
384 | } |
|
384 | } | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | /*! |
|
387 | /*! | |
388 | Returns the pen used to labels. |
|
388 | Returns the pen used to labels. | |
389 | */ |
|
389 | */ | |
390 | QPen QAbstractAxis::labelsPen() const |
|
390 | QPen QAbstractAxis::labelsPen() const | |
391 | { |
|
391 | { | |
392 | return d_ptr->m_labelsPen; |
|
392 | return d_ptr->m_labelsPen; | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | /*! |
|
395 | /*! | |
396 | Sets \a brush used to draw labels. |
|
396 | Sets \a brush used to draw labels. | |
397 | */ |
|
397 | */ | |
398 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
398 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
399 | { |
|
399 | { | |
400 | if (d_ptr->m_labelsBrush != brush) { |
|
400 | if (d_ptr->m_labelsBrush != brush) { | |
401 | d_ptr->m_labelsBrush = brush; |
|
401 | d_ptr->m_labelsBrush = brush; | |
402 | d_ptr->emitUpdated(); |
|
402 | d_ptr->emitUpdated(); | |
403 | } |
|
403 | } | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | /*! |
|
406 | /*! | |
407 | Returns brush used to draw labels. |
|
407 | Returns brush used to draw labels. | |
408 | */ |
|
408 | */ | |
409 | QBrush QAbstractAxis::labelsBrush() const |
|
409 | QBrush QAbstractAxis::labelsBrush() const | |
410 | { |
|
410 | { | |
411 | return d_ptr->m_labelsBrush; |
|
411 | return d_ptr->m_labelsBrush; | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | /*! |
|
414 | /*! | |
415 | Sets \a font used to draw labels. |
|
415 | Sets \a font used to draw labels. | |
416 | */ |
|
416 | */ | |
417 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
417 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
418 | { |
|
418 | { | |
419 | if (d_ptr->m_labelsFont != font) { |
|
419 | if (d_ptr->m_labelsFont != font) { | |
420 | d_ptr->m_labelsFont = font; |
|
420 | d_ptr->m_labelsFont = font; | |
421 | d_ptr->emitUpdated(); |
|
421 | d_ptr->emitUpdated(); | |
422 | } |
|
422 | } | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | Returns font used to draw labels. |
|
426 | Returns font used to draw labels. | |
427 | */ |
|
427 | */ | |
428 | QFont QAbstractAxis::labelsFont() const |
|
428 | QFont QAbstractAxis::labelsFont() const | |
429 | { |
|
429 | { | |
430 | return d_ptr->m_labelsFont; |
|
430 | return d_ptr->m_labelsFont; | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | void QAbstractAxis::setLabelsAngle(int angle) |
|
433 | void QAbstractAxis::setLabelsAngle(int angle) | |
434 | { |
|
434 | { | |
435 | if (d_ptr->m_labelsAngle != angle) { |
|
435 | if (d_ptr->m_labelsAngle != angle) { | |
436 | d_ptr->m_labelsAngle = angle; |
|
436 | d_ptr->m_labelsAngle = angle; | |
437 | d_ptr->emitUpdated(); |
|
437 | d_ptr->emitUpdated(); | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | int QAbstractAxis::labelsAngle() const |
|
441 | int QAbstractAxis::labelsAngle() const | |
442 | { |
|
442 | { | |
443 | return d_ptr->m_labelsAngle; |
|
443 | return d_ptr->m_labelsAngle; | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | void QAbstractAxis::setLabelsColor(QColor color) |
|
446 | void QAbstractAxis::setLabelsColor(QColor color) | |
447 | { |
|
447 | { | |
448 | QBrush b = d_ptr->m_labelsBrush; |
|
448 | QBrush b = d_ptr->m_labelsBrush; | |
449 | if (b.color() != color) { |
|
449 | if (b.color() != color) { | |
450 | b.setColor(color); |
|
450 | b.setColor(color); | |
451 | setLabelsBrush(b); |
|
451 | setLabelsBrush(b); | |
452 | emit labelsColorChanged(color); |
|
452 | emit labelsColorChanged(color); | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | QColor QAbstractAxis::labelsColor() const |
|
456 | QColor QAbstractAxis::labelsColor() const | |
457 | { |
|
457 | { | |
458 | return d_ptr->m_labelsBrush.color(); |
|
458 | return d_ptr->m_labelsBrush.color(); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
|
461 | void QAbstractAxis::setTitleVisible(bool visible) | |||
|
462 | { | |||
|
463 | if (d_ptr->m_titleVisible != visible) { | |||
|
464 | d_ptr->m_titleVisible = visible; | |||
|
465 | d_ptr->emitUpdated(); | |||
|
466 | } | |||
|
467 | } | |||
|
468 | ||||
|
469 | bool QAbstractAxis::titleVisible() const | |||
|
470 | { | |||
|
471 | return d_ptr->m_titleVisible; | |||
|
472 | } | |||
|
473 | ||||
|
474 | /*! | |||
|
475 | Sets \a pen used to draw title. | |||
|
476 | */ | |||
|
477 | void QAbstractAxis::setTitlePen(const QPen &pen) | |||
|
478 | { | |||
|
479 | if (d_ptr->m_titlePen != pen) { | |||
|
480 | d_ptr->m_titlePen = pen; | |||
|
481 | d_ptr->emitUpdated(); | |||
|
482 | } | |||
|
483 | } | |||
|
484 | ||||
|
485 | /*! | |||
|
486 | Returns the pen used to title. | |||
|
487 | */ | |||
|
488 | QPen QAbstractAxis::titlePen() const | |||
|
489 | { | |||
|
490 | return d_ptr->m_titlePen; | |||
|
491 | } | |||
|
492 | ||||
|
493 | /*! | |||
|
494 | Sets \a brush used to draw title. | |||
|
495 | */ | |||
|
496 | void QAbstractAxis::setTitleBrush(const QBrush &brush) | |||
|
497 | { | |||
|
498 | if (d_ptr->m_titleBrush != brush) { | |||
|
499 | d_ptr->m_titleBrush = brush; | |||
|
500 | d_ptr->emitUpdated(); | |||
|
501 | } | |||
|
502 | } | |||
|
503 | ||||
|
504 | /*! | |||
|
505 | Returns brush used to draw title. | |||
|
506 | */ | |||
|
507 | QBrush QAbstractAxis::titleBrush() const | |||
|
508 | { | |||
|
509 | return d_ptr->m_titleBrush; | |||
|
510 | } | |||
|
511 | ||||
|
512 | /*! | |||
|
513 | Sets \a font used to draw title. | |||
|
514 | */ | |||
|
515 | void QAbstractAxis::setTitleFont(const QFont &font) | |||
|
516 | { | |||
|
517 | if (d_ptr->m_titleFont != font) { | |||
|
518 | d_ptr->m_titleFont = font; | |||
|
519 | d_ptr->emitUpdated(); | |||
|
520 | } | |||
|
521 | } | |||
|
522 | ||||
|
523 | /*! | |||
|
524 | Returns font used to draw title. | |||
|
525 | */ | |||
|
526 | QFont QAbstractAxis::titleFont() const | |||
|
527 | { | |||
|
528 | return d_ptr->m_titleFont; | |||
|
529 | } | |||
|
530 | ||||
|
531 | void QAbstractAxis::setTitle(const QString& title) | |||
|
532 | { | |||
|
533 | if (d_ptr->m_title != title) { | |||
|
534 | d_ptr->m_title = title; | |||
|
535 | d_ptr->emitUpdated(); | |||
|
536 | } | |||
|
537 | } | |||
|
538 | ||||
|
539 | QString QAbstractAxis::title() const | |||
|
540 | { | |||
|
541 | return d_ptr->m_title; | |||
|
542 | } | |||
|
543 | ||||
|
544 | ||||
461 | void QAbstractAxis::setShadesVisible(bool visible) |
|
545 | void QAbstractAxis::setShadesVisible(bool visible) | |
462 | { |
|
546 | { | |
463 | if (d_ptr->m_shadesVisible != visible) { |
|
547 | if (d_ptr->m_shadesVisible != visible) { | |
464 | d_ptr->m_shadesVisible = visible; |
|
548 | d_ptr->m_shadesVisible = visible; | |
465 | d_ptr->emitUpdated(); |
|
549 | d_ptr->emitUpdated(); | |
466 | emit shadesVisibleChanged(visible); |
|
550 | emit shadesVisibleChanged(visible); | |
467 | } |
|
551 | } | |
468 | } |
|
552 | } | |
469 |
|
553 | |||
470 | bool QAbstractAxis::shadesVisible() const |
|
554 | bool QAbstractAxis::shadesVisible() const | |
471 | { |
|
555 | { | |
472 | return d_ptr->m_shadesVisible; |
|
556 | return d_ptr->m_shadesVisible; | |
473 | } |
|
557 | } | |
474 |
|
558 | |||
475 | /*! |
|
559 | /*! | |
476 | Sets \a pen used to draw shades. |
|
560 | Sets \a pen used to draw shades. | |
477 | */ |
|
561 | */ | |
478 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
562 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
479 | { |
|
563 | { | |
480 | if (d_ptr->m_shadesPen != pen) { |
|
564 | if (d_ptr->m_shadesPen != pen) { | |
481 | d_ptr->m_shadesPen = pen; |
|
565 | d_ptr->m_shadesPen = pen; | |
482 | d_ptr->emitUpdated(); |
|
566 | d_ptr->emitUpdated(); | |
483 | } |
|
567 | } | |
484 | } |
|
568 | } | |
485 |
|
569 | |||
486 | /*! |
|
570 | /*! | |
487 | Returns pen used to draw shades. |
|
571 | Returns pen used to draw shades. | |
488 | */ |
|
572 | */ | |
489 | QPen QAbstractAxis::shadesPen() const |
|
573 | QPen QAbstractAxis::shadesPen() const | |
490 | { |
|
574 | { | |
491 | return d_ptr->m_shadesPen; |
|
575 | return d_ptr->m_shadesPen; | |
492 | } |
|
576 | } | |
493 |
|
577 | |||
494 | /*! |
|
578 | /*! | |
495 | Sets \a brush used to draw shades. |
|
579 | Sets \a brush used to draw shades. | |
496 | */ |
|
580 | */ | |
497 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
581 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
498 | { |
|
582 | { | |
499 | if (d_ptr->m_shadesBrush != brush) { |
|
583 | if (d_ptr->m_shadesBrush != brush) { | |
500 | d_ptr->m_shadesBrush = brush; |
|
584 | d_ptr->m_shadesBrush = brush; | |
501 | d_ptr->emitUpdated(); |
|
585 | d_ptr->emitUpdated(); | |
502 | emit shadesColorChanged(brush.color()); |
|
586 | emit shadesColorChanged(brush.color()); | |
503 | } |
|
587 | } | |
504 | } |
|
588 | } | |
505 |
|
589 | |||
506 | /*! |
|
590 | /*! | |
507 | Returns brush used to draw shades. |
|
591 | Returns brush used to draw shades. | |
508 | */ |
|
592 | */ | |
509 | QBrush QAbstractAxis::shadesBrush() const |
|
593 | QBrush QAbstractAxis::shadesBrush() const | |
510 | { |
|
594 | { | |
511 | return d_ptr->m_shadesBrush; |
|
595 | return d_ptr->m_shadesBrush; | |
512 | } |
|
596 | } | |
513 |
|
597 | |||
514 | void QAbstractAxis::setShadesColor(QColor color) |
|
598 | void QAbstractAxis::setShadesColor(QColor color) | |
515 | { |
|
599 | { | |
516 | QBrush b = d_ptr->m_shadesBrush; |
|
600 | QBrush b = d_ptr->m_shadesBrush; | |
517 | b.setColor(color); |
|
601 | b.setColor(color); | |
518 | setShadesBrush(b); |
|
602 | setShadesBrush(b); | |
519 | } |
|
603 | } | |
520 |
|
604 | |||
521 | QColor QAbstractAxis::shadesColor() const |
|
605 | QColor QAbstractAxis::shadesColor() const | |
522 | { |
|
606 | { | |
523 | return d_ptr->m_shadesBrush.color(); |
|
607 | return d_ptr->m_shadesBrush.color(); | |
524 | } |
|
608 | } | |
525 |
|
609 | |||
526 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
610 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
527 | { |
|
611 | { | |
528 | QPen p = d_ptr->m_shadesPen; |
|
612 | QPen p = d_ptr->m_shadesPen; | |
529 | p.setColor(color); |
|
613 | p.setColor(color); | |
530 | setShadesPen(p); |
|
614 | setShadesPen(p); | |
531 | } |
|
615 | } | |
532 |
|
616 | |||
533 | QColor QAbstractAxis::shadesBorderColor() const |
|
617 | QColor QAbstractAxis::shadesBorderColor() const | |
534 | { |
|
618 | { | |
535 | return d_ptr->m_shadesPen.color(); |
|
619 | return d_ptr->m_shadesPen.color(); | |
536 | } |
|
620 | } | |
537 |
|
621 | |||
538 |
|
622 | |||
539 | bool QAbstractAxis::isVisible() const |
|
623 | bool QAbstractAxis::isVisible() const | |
540 | { |
|
624 | { | |
541 | return d_ptr->m_visible; |
|
625 | return d_ptr->m_visible; | |
542 | } |
|
626 | } | |
543 |
|
627 | |||
544 | /*! |
|
628 | /*! | |
545 | Sets axis, shades, labels and grid lines to be visible. |
|
629 | Sets axis, shades, labels and grid lines to be visible. | |
546 | */ |
|
630 | */ | |
547 | void QAbstractAxis::setVisible(bool visible) |
|
631 | void QAbstractAxis::setVisible(bool visible) | |
548 | { |
|
632 | { | |
549 | if(d_ptr->m_visible!=visible){ |
|
633 | if(d_ptr->m_visible!=visible){ | |
550 | d_ptr->m_visible=visible; |
|
634 | d_ptr->m_visible=visible; | |
551 | d_ptr->emitUpdated(); |
|
635 | d_ptr->emitUpdated(); | |
552 | emit visibleChanged(visible); |
|
636 | emit visibleChanged(visible); | |
553 | } |
|
637 | } | |
554 | } |
|
638 | } | |
555 |
|
639 | |||
556 |
|
640 | |||
557 | /*! |
|
641 | /*! | |
558 | Sets axis, shades, labels and grid lines to be visible. |
|
642 | Sets axis, shades, labels and grid lines to be visible. | |
559 | */ |
|
643 | */ | |
560 | void QAbstractAxis::show() |
|
644 | void QAbstractAxis::show() | |
561 | { |
|
645 | { | |
562 | setVisible(true); |
|
646 | setVisible(true); | |
563 | } |
|
647 | } | |
564 |
|
648 | |||
565 | /*! |
|
649 | /*! | |
566 | Sets axis, shades, labels and grid lines to not be visible. |
|
650 | Sets axis, shades, labels and grid lines to not be visible. | |
567 | */ |
|
651 | */ | |
568 | void QAbstractAxis::hide() |
|
652 | void QAbstractAxis::hide() | |
569 | { |
|
653 | { | |
570 | setVisible(false); |
|
654 | setVisible(false); | |
571 | } |
|
655 | } | |
572 |
|
656 | |||
573 | /*! |
|
657 | /*! | |
574 | Sets the minimum value shown on the axis. |
|
658 | Sets the minimum value shown on the axis. | |
575 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
659 | Depending on the actual axis type the \a min parameter is converted to appropriate type. | |
576 | If the conversion is impossible then the function call does nothing |
|
660 | If the conversion is impossible then the function call does nothing | |
577 | */ |
|
661 | */ | |
578 | void QAbstractAxis::setMin(const QVariant &min) |
|
662 | void QAbstractAxis::setMin(const QVariant &min) | |
579 | { |
|
663 | { | |
580 | d_ptr->setMin(min); |
|
664 | d_ptr->setMin(min); | |
581 | } |
|
665 | } | |
582 |
|
666 | |||
583 | /*! |
|
667 | /*! | |
584 | Sets the maximum value shown on the axis. |
|
668 | Sets the maximum value shown on the axis. | |
585 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
669 | Depending on the actual axis type the \a max parameter is converted to appropriate type. | |
586 | If the conversion is impossible then the function call does nothing |
|
670 | If the conversion is impossible then the function call does nothing | |
587 | */ |
|
671 | */ | |
588 | void QAbstractAxis::setMax(const QVariant &max) |
|
672 | void QAbstractAxis::setMax(const QVariant &max) | |
589 | { |
|
673 | { | |
590 | d_ptr->setMax(max); |
|
674 | d_ptr->setMax(max); | |
591 | } |
|
675 | } | |
592 |
|
676 | |||
593 | /*! |
|
677 | /*! | |
594 | Sets the range shown on the axis. |
|
678 | Sets the range shown on the axis. | |
595 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
679 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. | |
596 | If the conversion is impossible then the function call does nothing. |
|
680 | If the conversion is impossible then the function call does nothing. | |
597 | */ |
|
681 | */ | |
598 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
682 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
599 | { |
|
683 | { | |
600 | d_ptr->setRange(min,max); |
|
684 | d_ptr->setRange(min,max); | |
601 | } |
|
685 | } | |
602 |
|
686 | |||
603 |
|
687 | |||
604 | /*! |
|
688 | /*! | |
605 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
689 | Returns the orientation in which the axis is being used (Vertical or Horizontal) | |
606 | */ |
|
690 | */ | |
607 | Qt::Orientation QAbstractAxis::orientation() |
|
691 | Qt::Orientation QAbstractAxis::orientation() | |
608 | { |
|
692 | { | |
609 | return d_ptr->m_orientation; |
|
693 | return d_ptr->m_orientation; | |
610 | } |
|
694 | } | |
611 |
|
695 | |||
612 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
696 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
613 |
|
697 | |||
614 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
698 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): | |
615 | q_ptr(q), |
|
699 | q_ptr(q), | |
616 | m_orientation(Qt::Orientation(0)), |
|
700 | m_orientation(Qt::Orientation(0)), | |
617 | m_dataset(0), |
|
701 | m_dataset(0), | |
618 | m_visible(false), |
|
702 | m_visible(false), | |
619 | m_arrowVisible(true), |
|
703 | m_arrowVisible(true), | |
620 | m_gridLineVisible(true), |
|
704 | m_gridLineVisible(true), | |
621 | m_labelsVisible(true), |
|
705 | m_labelsVisible(true), | |
622 | m_labelsAngle(0), |
|
706 | m_labelsAngle(0), | |
623 | m_shadesVisible(false), |
|
707 | m_shadesVisible(false), | |
624 | m_shadesBrush(Qt::SolidPattern), |
|
708 | m_shadesBrush(Qt::SolidPattern), | |
625 | m_shadesOpacity(1.0), |
|
709 | m_shadesOpacity(1.0), | |
626 | m_dirty(false) |
|
710 | m_dirty(false) | |
627 | { |
|
711 | { | |
628 |
|
712 | |||
629 | } |
|
713 | } | |
630 |
|
714 | |||
631 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
715 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
632 | { |
|
716 | { | |
633 |
|
717 | |||
634 | } |
|
718 | } | |
635 |
|
719 | |||
636 | void QAbstractAxisPrivate::emitUpdated() |
|
720 | void QAbstractAxisPrivate::emitUpdated() | |
637 | { |
|
721 | { | |
638 | if(!m_dirty){ |
|
722 | if(!m_dirty){ | |
639 | m_dirty=true; |
|
723 | m_dirty=true; | |
640 | emit updated(); |
|
724 | emit updated(); | |
641 | } |
|
725 | } | |
642 | } |
|
726 | } | |
643 |
|
727 | |||
644 | void QAbstractAxisPrivate::setDirty(bool dirty) |
|
728 | void QAbstractAxisPrivate::setDirty(bool dirty) | |
645 | { |
|
729 | { | |
646 | m_dirty=dirty; |
|
730 | m_dirty=dirty; | |
647 | } |
|
731 | } | |
648 |
|
732 | |||
649 | void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) |
|
733 | void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) | |
650 | { |
|
734 | { | |
651 | m_orientation=orientation; |
|
735 | m_orientation=orientation; | |
652 | } |
|
736 | } | |
653 |
|
737 | |||
654 |
|
738 | |||
655 | #include "moc_qabstractaxis.cpp" |
|
739 | #include "moc_qabstractaxis.cpp" | |
656 | #include "moc_qabstractaxis_p.cpp" |
|
740 | #include "moc_qabstractaxis_p.cpp" | |
657 |
|
741 | |||
658 | QTCOMMERCIALCHART_END_NAMESPACE |
|
742 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,143 +1,156 | |||||
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 | #ifndef QABSTRACTAXIS_H |
|
21 | #ifndef QABSTRACTAXIS_H | |
22 | #define QABSTRACTAXIS_H |
|
22 | #define QABSTRACTAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QFont> |
|
26 | #include <QFont> | |
27 | #include <QVariant> |
|
27 | #include <QVariant> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractAxisPrivate; |
|
31 | class QAbstractAxisPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
37 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
37 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) | |
38 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
38 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) | |
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) | |
41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) | |
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) | |
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) | |
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) | |
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) | |
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 |
|
49 | |||
50 | enum AxisType { |
|
50 | enum AxisType { | |
51 | AxisTypeNoAxis = 0x0, |
|
51 | AxisTypeNoAxis = 0x0, | |
52 | AxisTypeValue = 0x1, |
|
52 | AxisTypeValue = 0x1, | |
53 | AxisTypeBarCategory = 0x2, |
|
53 | AxisTypeBarCategory = 0x2, | |
54 | AxisTypeCategory = 0x3, |
|
54 | AxisTypeCategory = 0x3, | |
55 | AxisTypeDateTime = 0x4 |
|
55 | AxisTypeDateTime = 0x4 | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
58 | Q_DECLARE_FLAGS(AxisTypes, AxisType) | |
59 |
|
59 | |||
60 | protected: |
|
60 | protected: | |
61 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); |
|
61 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); | |
62 |
|
62 | |||
63 | public: |
|
63 | public: | |
64 | ~QAbstractAxis(); |
|
64 | ~QAbstractAxis(); | |
65 |
|
65 | |||
66 | virtual AxisType type() const = 0; |
|
66 | virtual AxisType type() const = 0; | |
67 |
|
67 | |||
68 | //visibilty hadnling |
|
68 | //visibilty hadnling | |
69 | bool isVisible() const; |
|
69 | bool isVisible() const; | |
70 | void setVisible(bool visible = true); |
|
70 | void setVisible(bool visible = true); | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | //axis handling |
|
73 | //axis handling | |
74 | bool isLineVisible() const; |
|
74 | bool isLineVisible() const; | |
75 | void setLineVisible(bool visible = true); |
|
75 | void setLineVisible(bool visible = true); | |
76 | void setLinePen(const QPen &pen); |
|
76 | void setLinePen(const QPen &pen); | |
77 | QPen linePen() const; |
|
77 | QPen linePen() const; | |
78 | void setLinePenColor(QColor color); |
|
78 | void setLinePenColor(QColor color); | |
79 | QColor linePenColor() const; |
|
79 | QColor linePenColor() const; | |
80 |
|
80 | |||
81 | //grid handling |
|
81 | //grid handling | |
82 | bool isGridLineVisible() const; |
|
82 | bool isGridLineVisible() const; | |
83 | void setGridLineVisible(bool visible = true); |
|
83 | void setGridLineVisible(bool visible = true); | |
84 | void setGridLinePen(const QPen &pen); |
|
84 | void setGridLinePen(const QPen &pen); | |
85 | QPen gridLinePen() const; |
|
85 | QPen gridLinePen() const; | |
86 |
|
86 | |||
87 | //labels handling |
|
87 | //labels handling | |
88 | bool labelsVisible() const; |
|
88 | bool labelsVisible() const; | |
89 | void setLabelsVisible(bool visible = true); |
|
89 | void setLabelsVisible(bool visible = true); | |
90 | void setLabelsPen(const QPen &pen); |
|
90 | void setLabelsPen(const QPen &pen); | |
91 | QPen labelsPen() const; |
|
91 | QPen labelsPen() const; | |
92 | void setLabelsBrush(const QBrush &brush); |
|
92 | void setLabelsBrush(const QBrush &brush); | |
93 | QBrush labelsBrush() const; |
|
93 | QBrush labelsBrush() const; | |
94 | void setLabelsFont(const QFont &font); |
|
94 | void setLabelsFont(const QFont &font); | |
95 | QFont labelsFont() const; |
|
95 | QFont labelsFont() const; | |
96 | void setLabelsAngle(int angle); |
|
96 | void setLabelsAngle(int angle); | |
97 | int labelsAngle() const; |
|
97 | int labelsAngle() const; | |
98 | void setLabelsColor(QColor color); |
|
98 | void setLabelsColor(QColor color); | |
99 | QColor labelsColor() const; |
|
99 | QColor labelsColor() const; | |
100 |
|
100 | |||
|
101 | //title handling | |||
|
102 | bool titleVisible() const; | |||
|
103 | void setTitleVisible(bool visible = true); | |||
|
104 | void setTitlePen(const QPen &pen); | |||
|
105 | QPen titlePen() const; | |||
|
106 | void setTitleBrush(const QBrush &brush); | |||
|
107 | QBrush titleBrush() const; | |||
|
108 | void setTitleFont(const QFont &font); | |||
|
109 | QFont titleFont() const; | |||
|
110 | void setTitle(const QString& title); | |||
|
111 | QString title() const; | |||
|
112 | ||||
|
113 | ||||
101 | //shades handling |
|
114 | //shades handling | |
102 | bool shadesVisible() const; |
|
115 | bool shadesVisible() const; | |
103 | void setShadesVisible(bool visible = true); |
|
116 | void setShadesVisible(bool visible = true); | |
104 | void setShadesPen(const QPen &pen); |
|
117 | void setShadesPen(const QPen &pen); | |
105 | QPen shadesPen() const; |
|
118 | QPen shadesPen() const; | |
106 | void setShadesBrush(const QBrush &brush); |
|
119 | void setShadesBrush(const QBrush &brush); | |
107 | QBrush shadesBrush() const; |
|
120 | QBrush shadesBrush() const; | |
108 | void setShadesColor(QColor color); |
|
121 | void setShadesColor(QColor color); | |
109 | QColor shadesColor() const; |
|
122 | QColor shadesColor() const; | |
110 | void setShadesBorderColor(QColor color); |
|
123 | void setShadesBorderColor(QColor color); | |
111 | QColor shadesBorderColor() const; |
|
124 | QColor shadesBorderColor() const; | |
112 |
|
125 | |||
113 | Qt::Orientation orientation(); |
|
126 | Qt::Orientation orientation(); | |
114 |
|
127 | |||
115 | //range handling |
|
128 | //range handling | |
116 | void setMin(const QVariant &min); |
|
129 | void setMin(const QVariant &min); | |
117 | void setMax(const QVariant &max); |
|
130 | void setMax(const QVariant &max); | |
118 | void setRange(const QVariant &min, const QVariant &max); |
|
131 | void setRange(const QVariant &min, const QVariant &max); | |
119 |
|
132 | |||
120 | void show(); |
|
133 | void show(); | |
121 | void hide(); |
|
134 | void hide(); | |
122 |
|
135 | |||
123 | Q_SIGNALS: |
|
136 | Q_SIGNALS: | |
124 | void visibleChanged(bool visible); |
|
137 | void visibleChanged(bool visible); | |
125 | void lineVisibleChanged(bool visible); |
|
138 | void lineVisibleChanged(bool visible); | |
126 | void labelsVisibleChanged(bool visible); |
|
139 | void labelsVisibleChanged(bool visible); | |
127 | void gridVisibleChanged(bool visible); |
|
140 | void gridVisibleChanged(bool visible); | |
128 | void colorChanged(QColor color); |
|
141 | void colorChanged(QColor color); | |
129 | void labelsColorChanged(QColor color); |
|
142 | void labelsColorChanged(QColor color); | |
130 | void shadesVisibleChanged(bool visible); |
|
143 | void shadesVisibleChanged(bool visible); | |
131 | void shadesColorChanged(QColor color); |
|
144 | void shadesColorChanged(QColor color); | |
132 | void shadesBorderColorChanged(QColor color); |
|
145 | void shadesBorderColorChanged(QColor color); | |
133 |
|
146 | |||
134 | protected: |
|
147 | protected: | |
135 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
148 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
136 | Q_DISABLE_COPY(QAbstractAxis) |
|
149 | Q_DISABLE_COPY(QAbstractAxis) | |
137 | friend class ChartDataSet; |
|
150 | friend class ChartDataSet; | |
138 | friend class ChartAxis; |
|
151 | friend class ChartAxis; | |
139 | friend class ChartPresenter; |
|
152 | friend class ChartPresenter; | |
140 | }; |
|
153 | }; | |
141 |
|
154 | |||
142 | QTCOMMERCIALCHART_END_NAMESPACE |
|
155 | QTCOMMERCIALCHART_END_NAMESPACE | |
143 | #endif |
|
156 | #endif |
@@ -1,110 +1,116 | |||||
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 QABSTRACTAXIS_P_H |
|
30 | #ifndef QABSTRACTAXIS_P_H | |
31 | #define QABSTRACTAXIS_P_H |
|
31 | #define QABSTRACTAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qabstractaxis.h" |
|
33 | #include "qabstractaxis.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartPresenter; |
|
37 | class ChartPresenter; | |
38 | class ChartAxis; |
|
38 | class ChartAxis; | |
39 | class Domain; |
|
39 | class Domain; | |
40 | class ChartDataSet; |
|
40 | class ChartDataSet; | |
41 |
|
41 | |||
42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject |
|
42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | QAbstractAxisPrivate(QAbstractAxis *q); |
|
46 | QAbstractAxisPrivate(QAbstractAxis *q); | |
47 | ~QAbstractAxisPrivate(); |
|
47 | ~QAbstractAxisPrivate(); | |
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 |
|
50 | |||
51 | virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; |
|
51 | virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; | |
52 | virtual void intializeDomain(Domain* domain) = 0; |
|
52 | virtual void intializeDomain(Domain* domain) = 0; | |
53 |
|
53 | |||
54 | void emitUpdated(); |
|
54 | void emitUpdated(); | |
55 | void setDirty(bool dirty); |
|
55 | void setDirty(bool dirty); | |
56 | bool isDirty(){ return m_dirty; } |
|
56 | bool isDirty(){ return m_dirty; } | |
57 | void setOrientation(Qt::Orientation orientation); |
|
57 | void setOrientation(Qt::Orientation orientation); | |
58 | Qt::Orientation orientation() const { return m_orientation; } |
|
58 | Qt::Orientation orientation() const { return m_orientation; } | |
59 |
|
59 | |||
60 | virtual void setMin(const QVariant &min) = 0; |
|
60 | virtual void setMin(const QVariant &min) = 0; | |
61 | virtual qreal min() = 0; |
|
61 | virtual qreal min() = 0; | |
62 |
|
62 | |||
63 | virtual void setMax(const QVariant &max) = 0; |
|
63 | virtual void setMax(const QVariant &max) = 0; | |
64 | virtual qreal max() = 0; |
|
64 | virtual qreal max() = 0; | |
65 |
|
65 | |||
66 | virtual int count() const = 0; |
|
66 | virtual int count() const = 0; | |
67 |
|
67 | |||
68 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; |
|
68 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; | |
69 |
|
69 | |||
70 | public Q_SLOTS: |
|
70 | public Q_SLOTS: | |
71 | virtual void handleDomainUpdated() = 0; |
|
71 | virtual void handleDomainUpdated() = 0; | |
72 |
|
72 | |||
73 | Q_SIGNALS: |
|
73 | Q_SIGNALS: | |
74 | void updated(); |
|
74 | void updated(); | |
75 |
|
75 | |||
76 | protected: |
|
76 | protected: | |
77 | QAbstractAxis *q_ptr; |
|
77 | QAbstractAxis *q_ptr; | |
78 | Qt::Orientation m_orientation; |
|
78 | Qt::Orientation m_orientation; | |
79 | ChartDataSet *m_dataset; |
|
79 | ChartDataSet *m_dataset; | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | bool m_visible; |
|
82 | bool m_visible; | |
83 |
|
83 | |||
84 | bool m_arrowVisible; |
|
84 | bool m_arrowVisible; | |
85 | QPen m_axisPen; |
|
85 | QPen m_axisPen; | |
86 | QBrush m_axisBrush; |
|
86 | QBrush m_axisBrush; | |
87 |
|
87 | |||
88 | bool m_gridLineVisible; |
|
88 | bool m_gridLineVisible; | |
89 | QPen m_gridLinePen; |
|
89 | QPen m_gridLinePen; | |
90 |
|
90 | |||
91 | bool m_labelsVisible; |
|
91 | bool m_labelsVisible; | |
92 | QPen m_labelsPen; |
|
92 | QPen m_labelsPen; | |
93 | QBrush m_labelsBrush; |
|
93 | QBrush m_labelsBrush; | |
94 | QFont m_labelsFont; |
|
94 | QFont m_labelsFont; | |
95 | int m_labelsAngle; |
|
95 | int m_labelsAngle; | |
96 |
|
96 | |||
|
97 | bool m_titleVisible; | |||
|
98 | QPen m_titlePen; | |||
|
99 | QBrush m_titleBrush; | |||
|
100 | QFont m_titleFont; | |||
|
101 | QString m_title; | |||
|
102 | ||||
97 | bool m_shadesVisible; |
|
103 | bool m_shadesVisible; | |
98 | QPen m_shadesPen; |
|
104 | QPen m_shadesPen; | |
99 | QBrush m_shadesBrush; |
|
105 | QBrush m_shadesBrush; | |
100 | qreal m_shadesOpacity; |
|
106 | qreal m_shadesOpacity; | |
101 |
|
107 | |||
102 | bool m_dirty; |
|
108 | bool m_dirty; | |
103 |
|
109 | |||
104 | friend class QAbstractAxis; |
|
110 | friend class QAbstractAxis; | |
105 | friend class ChartDataSet; |
|
111 | friend class ChartDataSet; | |
106 | }; |
|
112 | }; | |
107 |
|
113 | |||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
109 |
|
115 | |||
110 | #endif |
|
116 | #endif |
@@ -1,121 +1,160 | |||||
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 "chartvalueaxisx_p.h" |
|
21 | #include "chartvalueaxisx_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
|
28 | #include <QDebug> | |||
28 |
|
29 | |||
29 | static int label_padding = 5; |
|
30 | static int label_padding = 5; | |
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
34 | ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
34 | m_tickCount(0) |
|
35 | m_tickCount(0) | |
35 | { |
|
36 | { | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 | ChartValueAxisX::~ChartValueAxisX() |
|
39 | ChartValueAxisX::~ChartValueAxisX() | |
39 | { |
|
40 | { | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | QVector<qreal> ChartValueAxisX::calculateLayout() const |
|
43 | QVector<qreal> ChartValueAxisX::calculateLayout() const | |
43 | { |
|
44 | { | |
44 | Q_ASSERT(m_tickCount>=2); |
|
45 | Q_ASSERT(m_tickCount>=2); | |
45 |
|
46 | |||
46 | QVector<qreal> points; |
|
47 | QVector<qreal> points; | |
47 | points.resize(m_tickCount); |
|
48 | points.resize(m_tickCount); | |
48 |
|
49 | |||
49 | const qreal deltaX = m_rect.width()/(m_tickCount-1); |
|
50 | QRectF rect = presenter()->chartsGeometry(); | |
|
51 | ||||
|
52 | const qreal deltaX = rect.width()/(m_tickCount-1); | |||
50 | for (int i = 0; i < m_tickCount; ++i) { |
|
53 | for (int i = 0; i < m_tickCount; ++i) { | |
51 |
int x = i * deltaX + |
|
54 | int x = i * deltaX + rect.left(); | |
52 | points[i] = x; |
|
55 | points[i] = x; | |
53 | } |
|
56 | } | |
54 | return points; |
|
57 | return points; | |
55 | } |
|
58 | } | |
56 |
|
59 | |||
57 | void ChartValueAxisX::updateGeometry() |
|
60 | void ChartValueAxisX::updateGeometry() | |
58 | { |
|
61 | { | |
59 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
62 | const QVector<qreal>& layout = ChartAxis::layout(); | |
60 |
|
63 | |||
61 | m_minWidth = 0; |
|
|||
62 | m_minHeight = 0; |
|
|||
63 |
|
||||
64 | if(layout.isEmpty()) return; |
|
64 | if(layout.isEmpty()) return; | |
65 |
|
65 | |||
66 | QStringList ticksList; |
|
66 | QStringList ticksList = createNumberLabels(m_min,m_max,layout.size()); | |
67 |
|
||||
68 | createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
|||
69 |
|
67 | |||
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
68 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
69 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
70 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
73 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
71 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
74 |
|
72 | |||
75 | Q_ASSERT(labels.size() == ticksList.size()); |
|
73 | Q_ASSERT(labels.size() == ticksList.size()); | |
76 | Q_ASSERT(layout.size() == ticksList.size()); |
|
74 | Q_ASSERT(layout.size() == ticksList.size()); | |
77 |
|
75 | |||
|
76 | QRectF chartRrect = presenter()->chartsGeometry(); | |||
|
77 | ||||
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
79 |
lineItem->setLine( |
|
79 | lineItem->setLine(chartRrect.left(), chartRrect.bottom(), chartRrect.right(), chartRrect.bottom()); | |
80 |
|
80 | |||
81 | qreal width = 0; |
|
81 | qreal width = 0; | |
82 | for (int i = 0; i < layout.size(); ++i) { |
|
82 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 |
lineItem->setLine(layout[i], |
|
84 | lineItem->setLine(layout[i], chartRrect.top(), layout[i], chartRrect.bottom()); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | labelItem->setText(ticksList.at(i)); |
|
86 | labelItem->setText(ticksList.at(i)); | |
87 | const QRectF& rect = labelItem->boundingRect(); |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
88 | QPointF center = rect.center(); |
|
88 | QPointF center = rect.center(); | |
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
90 |
labelItem->setPos(layout[i] - center.x(), |
|
90 | labelItem->setPos(layout[i] - center.x(), chartRrect.bottom() + label_padding); | |
91 |
|
91 | if(labelItem->pos().x() <= width || | ||
92 |
|
|
92 | labelItem->pos().x() < m_rect.left() || | |
|
93 | labelItem->pos().x() + rect.width() > m_rect.right()){ | |||
93 | labelItem->setVisible(false); |
|
94 | labelItem->setVisible(false); | |
94 | lineItem->setVisible(false); |
|
95 | lineItem->setVisible(false); | |
95 | }else{ |
|
96 | }else{ | |
96 | labelItem->setVisible(true); |
|
97 | labelItem->setVisible(true); | |
97 | lineItem->setVisible(true); |
|
98 | lineItem->setVisible(true); | |
98 | width=rect.width()+labelItem->pos().x(); |
|
99 | width=rect.width()+labelItem->pos().x(); | |
99 | } |
|
100 | } | |
100 | m_minWidth+=rect.width(); |
|
|||
101 | m_minHeight=qMax(rect.height(),m_minHeight); |
|
|||
102 |
|
101 | |||
103 | if ((i+1)%2 && i>1) { |
|
102 | if ((i+1)%2 && i>1) { | |
104 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
103 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
105 |
rectItem->setRect(layout[i-1], |
|
104 | rectItem->setRect(layout[i-1],chartRrect.top(),layout[i]-layout[i-1],chartRrect.height()); | |
106 | } |
|
105 | } | |
107 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
106 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
108 |
lineItem->setLine(layout[i], |
|
107 | lineItem->setLine(layout[i],chartRrect.bottom(),layout[i],chartRrect.bottom()+5); | |
109 | } |
|
108 | } | |
110 |
|
||||
111 | } |
|
109 | } | |
112 |
|
110 | |||
113 | void ChartValueAxisX::handleAxisUpdated() |
|
111 | void ChartValueAxisX::handleAxisUpdated() | |
114 | { |
|
112 | { | |
115 | //TODO:: fix this |
|
113 | //TODO:: fix this | |
116 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); |
|
114 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); | |
117 | m_tickCount = axis->tickCount(); |
|
115 | m_tickCount = axis->tickCount(); | |
118 | ChartAxis::handleAxisUpdated(); |
|
116 | ChartAxis::handleAxisUpdated(); | |
119 | } |
|
117 | } | |
120 |
|
118 | |||
|
119 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
120 | { | |||
|
121 | Q_UNUSED(constraint) | |||
|
122 | ||||
|
123 | QFontMetrics fn(m_font); | |||
|
124 | QSizeF sh; | |||
|
125 | ||||
|
126 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |||
|
127 | QStringList ticksList = createNumberLabels(m_min,m_max,m_tickCount); | |||
|
128 | qreal width=0; | |||
|
129 | qreal height=0; | |||
|
130 | ||||
|
131 | switch (which) { | |||
|
132 | case Qt::MinimumSize:{ | |||
|
133 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | |||
|
134 | width=fn.averageCharWidth()*count; | |||
|
135 | height=fn.height()+label_padding; | |||
|
136 | width=qMax(width,base.width()); | |||
|
137 | height+=base.height(); | |||
|
138 | sh = QSizeF(width,height); | |||
|
139 | break; | |||
|
140 | } | |||
|
141 | case Qt::PreferredSize:{ | |||
|
142 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
143 | { | |||
|
144 | width+=fn.averageCharWidth()*ticksList.at(i).count(); | |||
|
145 | ||||
|
146 | } | |||
|
147 | height=fn.height()+label_padding; | |||
|
148 | width=qMax(width,base.width()); | |||
|
149 | height+=base.height(); | |||
|
150 | sh = QSizeF(width,height); | |||
|
151 | break; | |||
|
152 | } | |||
|
153 | default: | |||
|
154 | break; | |||
|
155 | } | |||
|
156 | ||||
|
157 | return sh; | |||
|
158 | } | |||
|
159 | ||||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
160 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,60 | |||||
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 CHARTVALUEAXISX_H |
|
30 | #ifndef CHARTVALUEAXISX_H | |
31 | #define CHARTVALUEAXISX_H |
|
31 | #define CHARTVALUEAXISX_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 | class ChartValueAxisX : public ChartAxis |
|
40 | class ChartValueAxisX : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 | ChartValueAxisX(QAbstractAxis *axis, ChartPresenter *presenter); |
|
43 | ChartValueAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 | ~ChartValueAxisX(); |
|
44 | ~ChartValueAxisX(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return X_AXIS;} |
|
46 | AxisType axisType() const { return X_AXIS;} | |
47 |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
48 | protected: |
|
48 | protected: | |
49 | void handleAxisUpdated(); |
|
49 | void handleAxisUpdated(); | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
52 |
|
52 | |||
53 | private: |
|
53 | private: | |
54 | int m_tickCount; |
|
54 | int m_tickCount; | |
55 |
|
55 | |||
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 |
|
59 | |||
60 | #endif /* CHARTVALUEAXISX_H */ |
|
60 | #endif /* CHARTVALUEAXISX_H */ |
@@ -1,127 +1,175 | |||||
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 "chartvalueaxisy_p.h" |
|
21 | #include "chartvalueaxisy_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
|
28 | #include <QDebug> | |||
28 |
|
29 | |||
29 | static int label_padding = 5; |
|
30 | static int label_padding = 5; | |
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
34 | ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
34 | m_tickCount(0) |
|
35 | m_tickCount(0) | |
35 | { |
|
36 | { | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 | ChartValueAxisY::~ChartValueAxisY() |
|
39 | ChartValueAxisY::~ChartValueAxisY() | |
39 | { |
|
40 | { | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | QVector<qreal> ChartValueAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartValueAxisY::calculateLayout() const | |
43 | { |
|
44 | { | |
44 | Q_ASSERT(m_tickCount>=2); |
|
45 | Q_ASSERT(m_tickCount>=2); | |
45 |
|
46 | |||
46 | QVector<qreal> points; |
|
47 | QVector<qreal> points; | |
47 | points.resize(m_tickCount); |
|
48 | points.resize(m_tickCount); | |
48 |
|
49 | |||
49 | const qreal deltaY = m_rect.height()/(m_tickCount-1); |
|
50 | QRectF rect = presenter()->chartsGeometry(); | |
|
51 | ||||
|
52 | const qreal deltaY = rect.height()/(m_tickCount-1); | |||
50 | for (int i = 0; i < m_tickCount; ++i) { |
|
53 | for (int i = 0; i < m_tickCount; ++i) { | |
51 |
int y = i * -deltaY + |
|
54 | int y = i * -deltaY + rect.bottom(); | |
52 | points[i] = y; |
|
55 | points[i] = y; | |
53 | } |
|
56 | } | |
54 |
|
57 | |||
55 | return points; |
|
58 | return points; | |
56 | } |
|
59 | } | |
57 |
|
60 | |||
58 | void ChartValueAxisY::updateGeometry() |
|
61 | void ChartValueAxisY::updateGeometry() | |
59 | { |
|
62 | { | |
60 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
63 | const QVector<qreal> &layout = ChartAxis::layout(); | |
61 | m_minWidth = 0; |
|
|||
62 | m_minHeight = 0; |
|
|||
63 |
|
64 | |||
64 | if(layout.isEmpty()) return; |
|
65 | if(layout.isEmpty()) return; | |
65 |
|
66 | |||
66 | QStringList ticksList; |
|
67 | QStringList ticksList = createNumberLabels(m_min,m_max,layout.size()); | |
67 |
|
||||
68 | createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
|||
69 |
|
68 | |||
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
73 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
72 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
74 |
|
73 | |||
75 | Q_ASSERT(labels.size() == ticksList.size()); |
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
76 | Q_ASSERT(layout.size() == ticksList.size()); |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
77 |
|
76 | |||
78 | qreal height = 2*m_rect.bottom(); |
|
77 | QRectF chartRect = presenter()->chartsGeometry(); | |
|
78 | ||||
|
79 | qreal height = m_rect.bottom(); | |||
79 |
|
80 | |||
80 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
81 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
81 |
lineItem->setLine( |
|
82 | lineItem->setLine( chartRect.left() , chartRect.top(), chartRect.left(), chartRect.bottom()); | |
|
83 | ||||
|
84 | QFontMetrics fn(m_font); | |||
82 |
|
85 | |||
83 | for (int i = 0; i < layout.size(); ++i) { |
|
86 | for (int i = 0; i < layout.size(); ++i) { | |
84 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
87 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
85 |
lineItem->setLine( |
|
88 | lineItem->setLine( chartRect.left() , layout[i], chartRect.right(), layout[i]); | |
86 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
89 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
87 |
|
90 | |||
88 |
|
|
91 | QString text = ticksList.at(i); | |
|
92 | ||||
|
93 | if (fn.boundingRect(text).width() > chartRect.left() - m_rect.left() - label_padding ) | |||
|
94 | { | |||
|
95 | QString label = text + "..."; | |||
|
96 | while (fn.boundingRect(label).width() > chartRect.left() - m_rect.left() - label_padding && label.length() > 3) | |||
|
97 | label.remove(label.length() - 4, 1); | |||
|
98 | labelItem->setText(label); | |||
|
99 | }else{ | |||
|
100 | labelItem->setText(text); | |||
|
101 | } | |||
|
102 | ||||
89 | const QRectF& rect = labelItem->boundingRect(); |
|
103 | const QRectF& rect = labelItem->boundingRect(); | |
90 |
|
104 | |||
91 | QPointF center = rect.center(); |
|
105 | QPointF center = rect.center(); | |
92 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
106 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
93 |
labelItem->setPos( |
|
107 | labelItem->setPos( chartRect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
94 |
|
108 | |||
95 |
if(labelItem->pos().y()+rect.height()>height |
|
109 | if(labelItem->pos().y() + rect.height() > height || | |
|
110 | labelItem->pos().y() < m_rect.top()) { | |||
96 | labelItem->setVisible(false); |
|
111 | labelItem->setVisible(false); | |
97 | lineItem->setVisible(false); |
|
112 | lineItem->setVisible(false); | |
98 | } |
|
113 | }else{ | |
99 | else { |
|
|||
100 | labelItem->setVisible(true); |
|
114 | labelItem->setVisible(true); | |
101 | lineItem->setVisible(true); |
|
115 | lineItem->setVisible(true); | |
102 | height=labelItem->pos().y(); |
|
116 | height=labelItem->pos().y(); | |
103 | } |
|
117 | } | |
104 |
|
118 | |||
105 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
|||
106 | m_minHeight+=rect.height(); |
|
|||
107 |
|
||||
108 | if ((i+1)%2 && i>1) { |
|
119 | if ((i+1)%2 && i>1) { | |
109 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
120 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
110 |
rectItem->setRect( |
|
121 | rectItem->setRect( chartRect.left(),layout[i], chartRect.width(),layout[i-1]-layout[i]); | |
111 | } |
|
122 | } | |
112 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
123 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
113 |
lineItem->setLine( |
|
124 | lineItem->setLine( chartRect.left()-5,layout[i], chartRect.left(),layout[i]); | |
114 | } |
|
125 | } | |
115 |
|
||||
116 | } |
|
126 | } | |
117 |
|
127 | |||
118 | void ChartValueAxisY::handleAxisUpdated() |
|
128 | void ChartValueAxisY::handleAxisUpdated() | |
119 | { |
|
129 | { | |
120 | //TODO:: fix this |
|
130 | //TODO:: fix this | |
121 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); |
|
131 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); | |
122 | m_tickCount = axis->tickCount(); |
|
132 | m_tickCount = axis->tickCount(); | |
123 | ChartAxis::handleAxisUpdated(); |
|
133 | ChartAxis::handleAxisUpdated(); | |
124 | } |
|
134 | } | |
125 |
|
135 | |||
|
136 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
137 | { | |||
|
138 | Q_UNUSED(constraint) | |||
|
139 | ||||
|
140 | QFontMetrics fn(m_font); | |||
|
141 | QSizeF sh; | |||
|
142 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |||
|
143 | QStringList ticksList = createNumberLabels(m_min,m_max,m_tickCount); | |||
|
144 | qreal width=0; | |||
|
145 | qreal height=0; | |||
|
146 | ||||
|
147 | switch (which) { | |||
|
148 | case Qt::MinimumSize: { | |||
|
149 | int count = qMax(ticksList.first().count() , ticksList.last().count()); | |||
|
150 | width=fn.averageCharWidth()*count+label_padding; | |||
|
151 | height=fn.height(); | |||
|
152 | height=qMax(height,base.height()); | |||
|
153 | width+=base.width(); | |||
|
154 | sh = QSizeF(width,height); | |||
|
155 | break; | |||
|
156 | } | |||
|
157 | case Qt::PreferredSize: | |||
|
158 | { | |||
|
159 | for (int i = 0; i < ticksList.size(); ++i) | |||
|
160 | { | |||
|
161 | width=qMax(qreal(fn.averageCharWidth()*ticksList.at(i).count())+label_padding,width); | |||
|
162 | height+=fn.height(); | |||
|
163 | } | |||
|
164 | height=qMax(height,base.height()); | |||
|
165 | width+=base.width(); | |||
|
166 | sh = QSizeF(width,height); | |||
|
167 | break; | |||
|
168 | } | |||
|
169 | default: | |||
|
170 | break; | |||
|
171 | } | |||
|
172 | return sh; | |||
|
173 | } | |||
126 |
|
174 | |||
127 | QTCOMMERCIALCHART_END_NAMESPACE |
|
175 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
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 CHARTVALUEAXISY_H |
|
30 | #ifndef CHARTVALUEAXISY_H | |
31 | #define CHARTVALUEAXISY_H |
|
31 | #define CHARTVALUEAXISY_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 | class ChartValueAxisY : public ChartAxis |
|
40 | class ChartValueAxisY : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 | ChartValueAxisY(QAbstractAxis *axis, ChartPresenter *presenter); |
|
43 | ChartValueAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 | ~ChartValueAxisY(); |
|
44 | ~ChartValueAxisY(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return Y_AXIS;} |
|
46 | AxisType axisType() const { return Y_AXIS;} | |
47 |
|
47 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const; | ||
48 | protected: |
|
48 | protected: | |
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
51 | void handleAxisUpdated(); |
|
51 | void handleAxisUpdated(); | |
52 | private: |
|
52 | private: | |
53 | int m_tickCount; |
|
53 | int m_tickCount; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif /* CHARTVALUEAXISY_H */ |
|
58 | #endif /* CHARTVALUEAXISY_H */ |
@@ -1,66 +1,65 | |||||
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 CHARTBACKGROUND_H |
|
30 | #ifndef CHARTBACKGROUND_H | |
31 | #define CHARTBACKGROUND_H |
|
31 | #define CHARTBACKGROUND_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QGraphicsRectItem> |
|
34 | #include <QGraphicsRectItem> | |
35 |
|
35 | |||
36 | class QGraphicsDropShadowEffect; |
|
36 | class QGraphicsDropShadowEffect; | |
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class ChartBackground: public QGraphicsRectItem |
|
39 | class ChartBackground: public QGraphicsRectItem | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | ChartBackground(QGraphicsItem *parent =0); |
|
42 | ChartBackground(QGraphicsItem *parent =0); | |
43 | ~ChartBackground(); |
|
43 | ~ChartBackground(); | |
44 |
|
44 | |||
45 | void setDimeter(int dimater); |
|
45 | void setDimeter(int dimater); | |
46 | int diameter() const; |
|
46 | int diameter() const; | |
47 | void setDropShadowEnabled(bool enabled); |
|
47 | void setDropShadowEnabled(bool enabled); | |
48 | bool isDropShadowEnabled() {return m_dropShadow != 0;} |
|
48 | bool isDropShadowEnabled() {return m_dropShadow != 0;} | |
49 |
|
49 | |||
50 | protected: |
|
50 | protected: | |
51 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
51 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
52 |
|
52 | |||
53 |
|
||||
54 | private: |
|
53 | private: | |
55 | int roundness(qreal size) const; |
|
54 | int roundness(qreal size) const; | |
56 |
|
55 | |||
57 | private: |
|
56 | private: | |
58 | int m_diameter; |
|
57 | int m_diameter; | |
59 | QGraphicsDropShadowEffect *m_dropShadow; |
|
58 | QGraphicsDropShadowEffect *m_dropShadow; | |
60 | }; |
|
59 | }; | |
61 |
|
60 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE | |
63 |
|
62 | |||
64 | #endif /* CHARTBACKGROUND_H */ |
|
63 | #endif /* CHARTBACKGROUND_H */ | |
65 |
|
64 | |||
66 |
|
65 |
@@ -1,180 +1,259 | |||||
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 "chartlayout_p.h" |
|
21 | #include "chartlayout_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlegend_p.h" |
|
23 | #include "qlegend_p.h" | |
24 | #include "chartaxis_p.h" |
|
24 | #include "chartaxis_p.h" | |
|
25 | #include "charttitle_p.h" | |||
|
26 | #include "chartbackground_p.h" | |||
|
27 | #include "layoutdebuger_p.h" | |||
|
28 | #include "legendmarker_p.h" | |||
25 | #include <QDebug> |
|
29 | #include <QDebug> | |
26 |
|
30 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
32 | |||
|
33 | static const qreal golden_ratio = 0.25; | |||
|
34 | ||||
29 | ChartLayout::ChartLayout(ChartPresenter* presenter): |
|
35 | ChartLayout::ChartLayout(ChartPresenter* presenter): | |
30 | m_presenter(presenter), |
|
36 | m_presenter(presenter), | |
31 |
m_margin |
|
37 | m_margins(20,20,20,20), | |
32 | m_marginSmall(20), |
|
38 | m_minChartRect(0,0,200,200) | |
33 | m_marginTiny(10), |
|
|||
34 | m_chartMargins(m_marginBig,m_marginBig,m_marginBig,m_marginBig), |
|
|||
35 | m_intialized(false) |
|
|||
36 | { |
|
39 | { | |
37 |
|
40 | |||
38 | } |
|
41 | } | |
39 |
|
42 | |||
40 | ChartLayout::~ChartLayout() |
|
43 | ChartLayout::~ChartLayout() | |
41 | { |
|
44 | { | |
42 |
|
45 | |||
43 | } |
|
46 | } | |
44 |
|
47 | |||
45 | void ChartLayout::setGeometry(const QRectF& rect) |
|
48 | void ChartLayout::setGeometry(const QRectF& rect) | |
46 | { |
|
49 | { | |
|
50 | Q_ASSERT(rect.isValid()); | |||
47 |
|
51 | |||
48 | if (!rect.isValid()) return; |
|
52 | QList<ChartAxis*> axes = m_presenter->axisItems(); | |
|
53 | ChartTitle* title = m_presenter->titleElement(); | |||
|
54 | QLegend* legend = m_presenter->legend(); | |||
|
55 | ChartBackground* background = m_presenter->backgroundElement(); | |||
49 |
|
56 | |||
50 | QGraphicsLayout::setGeometry(rect); |
|
57 | QRectF contentGeometry = calculateBackgroundGeometry(rect,background); | |
51 |
|
58 | |||
52 | if(!m_intialized){ |
|
59 | contentGeometry = calculateContentGeometry(contentGeometry); | |
53 | m_presenter->setGeometry(rect); |
|
|||
54 | m_intialized=true; |
|
|||
55 | } |
|
|||
56 |
|
60 | |||
57 | // check title size |
|
61 | if (title && title->isVisible()) { | |
|
62 | contentGeometry = calculateTitleGeometry(contentGeometry,title); | |||
|
63 | } | |||
58 |
|
64 | |||
59 | QSize titleSize = QSize(0,0); |
|
65 | if (legend->isAttachedToChart() && legend->isVisible()) { | |
|
66 | contentGeometry = calculateLegendGeometry(contentGeometry,legend); | |||
|
67 | } | |||
60 |
|
68 | |||
61 | if (m_presenter->titleItem()) { |
|
69 | calculateChartGeometry(contentGeometry,axes); | |
62 | titleSize= m_presenter->titleItem()->boundingRect().size().toSize(); |
|
70 | ||
|
71 | //TODO remove me | |||
|
72 | #ifdef SHOW_LAYOUT | |||
|
73 | LayoutDebuger* debuger = LayoutDebuger::instance(); | |||
|
74 | debuger->reset(); | |||
|
75 | debuger->setPen(QPen(Qt::red)); | |||
|
76 | debuger->add(backgroundGeometry,m_presenter->rootItem()); | |||
|
77 | debuger->add(titleGeometry,m_presenter->rootItem()); | |||
|
78 | debuger->add(legendGeometry ,m_presenter->rootItem()); | |||
|
79 | debuger->add(axisGeometry ,m_presenter->rootItem()); | |||
|
80 | debuger->add(geometry,m_presenter->rootItem()); | |||
|
81 | foreach(LegendMarker* marker,legend->d_ptr->markers()){ | |||
|
82 | debuger->add(marker->mapRectToScene(marker->boundingRect()),m_presenter->rootItem()); | |||
63 | } |
|
83 | } | |
|
84 | #endif | |||
|
85 | ||||
|
86 | QGraphicsLayout::setGeometry(rect); | |||
|
87 | } | |||
|
88 | ||||
|
89 | QRectF ChartLayout::calculateContentGeometry(const QRectF& geometry) const | |||
|
90 | { | |||
|
91 | return geometry.adjusted(m_margins.left(),m_margins.top(),-m_margins.right(),-m_margins.bottom()); | |||
|
92 | } | |||
|
93 | ||||
|
94 | QRectF ChartLayout::calculateContentMinimum(const QRectF& minimum) const | |||
|
95 | { | |||
|
96 | return minimum.adjusted(0,0,m_margins.left()+m_margins.right(),m_margins.top() + m_margins.bottom()); | |||
|
97 | } | |||
64 |
|
98 | |||
65 | qreal axisHeight = 0; |
|
99 | ||
66 | qreal axisWidth = 0; |
|
100 | QRectF ChartLayout::calculateBackgroundGeometry(const QRectF& geometry,ChartBackground* background) const | |
|
101 | { | |||
|
102 | qreal left, top, right, bottom; | |||
|
103 | getContentsMargins(&left, &top, &right, &bottom); | |||
|
104 | QRectF backgroundGeometry = geometry.adjusted(left,top,-right,-bottom); | |||
|
105 | if(background) background->setRect(backgroundGeometry); | |||
|
106 | return backgroundGeometry; | |||
|
107 | } | |||
|
108 | ||||
|
109 | QRectF ChartLayout::calculateBackgroundMinimum(const QRectF& minimum) const | |||
|
110 | { | |||
|
111 | qreal left, top, right, bottom; | |||
|
112 | getContentsMargins(&left, &top, &right, &bottom); | |||
|
113 | return minimum.adjusted(0,0,left + right,top+bottom); | |||
|
114 | } | |||
|
115 | ||||
|
116 | QRectF ChartLayout::calculateChartGeometry(const QRectF& geometry, const QList<ChartAxis*>& axes) const | |||
|
117 | { | |||
|
118 | ||||
|
119 | QSizeF vertical(0,0); | |||
|
120 | QSizeF horizontal(0,0); | |||
67 |
|
121 | |||
68 | // check axis size |
|
122 | // check axis size | |
|
123 | foreach(ChartAxis* axis , axes) { | |||
|
124 | if(axis->orientation()==Qt::Vertical && axis->isVisible()) { | |||
|
125 | vertical = vertical.expandedTo(axis->effectiveSizeHint(Qt::MinimumSize)); | |||
|
126 | } | |||
|
127 | else if(axis->orientation()==Qt::Horizontal && axis->isVisible()) { | |||
|
128 | horizontal = horizontal.expandedTo(axis->effectiveSizeHint(Qt::MinimumSize)); | |||
|
129 | } | |||
69 |
|
130 | |||
70 | foreach (ChartAxis* axis,m_presenter->axisItems()){ |
|
|||
71 | if(axis->axisType() == ChartAxis::X_AXIS) |
|
|||
72 | axisHeight = qMax(axis->minimumHeight(),axisHeight); |
|
|||
73 | else |
|
|||
74 | axisWidth = qMax(axis->minimumWidth(),axisWidth); |
|
|||
75 | } |
|
131 | } | |
76 |
|
132 | |||
77 | QLegend* legend = m_presenter->legend(); |
|
133 | qreal width = qMin(vertical.width(),geometry.width() * golden_ratio); | |
78 | Q_ASSERT(legend); |
|
|||
79 |
|
134 | |||
80 | qreal titlePadding = m_chartMargins.top()/2; |
|
135 | QRectF rect = geometry.adjusted(width,vertical.height()/2,-horizontal.width()/2,-horizontal.height()); | |
81 |
|
136 | |||
82 | QMargins chartMargins = m_chartMargins; |
|
137 | m_presenter->setChartsGeometry(rect); | |
83 |
|
138 | |||
84 | //TODO multiple axis handling; |
|
139 | foreach(ChartAxis* axis , axes) { | |
85 | chartMargins.setLeft(qMax(m_chartMargins.left(),int(axisWidth + 2*m_marginTiny))); |
|
140 | axis->setGeometry(geometry); | |
86 | chartMargins.setBottom(qMax(m_chartMargins.bottom(),int(axisHeight + 2* m_marginTiny))); |
|
141 | } | |
87 |
|
142 | |||
|
143 | return rect; | |||
|
144 | } | |||
88 |
|
145 | |||
89 | // recalculate legend position |
|
146 | QRectF ChartLayout::calculateAxisMinimum(const QRectF& minimum, const QList<ChartAxis*>& axes) const | |
90 | if ((legend->isAttachedToChart() && legend->isVisible())) { |
|
147 | { | |
|
148 | QSizeF vertical(0,0); | |||
|
149 | QSizeF horizontal(0,0); | |||
91 |
|
150 | |||
92 | // Reserve some space for legend |
|
151 | // check axis size | |
93 | switch (legend->alignment()) { |
|
152 | foreach(ChartAxis* axis , axes) { | |
|
153 | if(axis->orientation()==Qt::Vertical && axis->isVisible()){ | |||
|
154 | vertical = vertical.expandedTo(axis->effectiveSizeHint(Qt::MinimumSize)); | |||
|
155 | }else if(axis->orientation()==Qt::Horizontal && axis->isVisible()) { | |||
|
156 | horizontal = horizontal.expandedTo(axis->effectiveSizeHint(Qt::MinimumSize)); | |||
|
157 | } | |||
|
158 | } | |||
|
159 | return minimum.adjusted(0,0,horizontal.width()+vertical.width(),horizontal.height() + vertical.height()); | |||
|
160 | } | |||
94 |
|
161 | |||
95 | case Qt::AlignTop: { |
|
162 | QRectF ChartLayout::calculateLegendGeometry(const QRectF& geometry,QLegend* legend) const | |
|
163 | { | |||
|
164 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,-1)); | |||
|
165 | QRectF legendRect; | |||
|
166 | QRectF result; | |||
96 |
|
167 | |||
97 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1)); |
|
168 | switch (legend->alignment()) { | |
98 | int topMargin = 2*m_marginTiny + titleSize.height() + legendSize.height() + m_marginTiny; |
|
169 | ||
99 | chartMargins = QMargins(chartMargins.left(),topMargin,chartMargins.right(),chartMargins.bottom()); |
|
170 | case Qt::AlignTop: { | |
100 | m_legendMargins = QMargins(chartMargins.left(),topMargin - (legendSize.height() + m_marginTiny),chartMargins.right(),rect.height()-topMargin + m_marginTiny); |
|
171 | legendRect = QRectF(geometry.topLeft(),QSizeF(geometry.width(),size.height())); | |
101 | titlePadding = m_marginTiny + m_marginTiny; |
|
172 | result = geometry.adjusted(0,legendRect.height(),0,0); | |
102 | break; |
|
173 | break; | |
103 | } |
|
174 | } | |
104 | case Qt::AlignBottom: { |
|
175 | case Qt::AlignBottom: { | |
105 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1)); |
|
176 | legendRect = QRectF(QPointF(geometry.left(),geometry.bottom()-size.height()),QSizeF(geometry.width(),size.height())); | |
106 | int bottomMargin = m_marginTiny + legendSize.height() + m_marginTiny + axisHeight; |
|
177 | result = geometry.adjusted(0,0,0,-legendRect.height()); | |
107 | chartMargins = QMargins(chartMargins.left(),chartMargins.top(),chartMargins.right(),bottomMargin); |
|
|||
108 | m_legendMargins = QMargins(chartMargins.left(),rect.height()-bottomMargin + m_marginTiny + axisHeight,chartMargins.right(),m_marginTiny + m_marginSmall); |
|
|||
109 | titlePadding = chartMargins.top()/2; |
|
|||
110 | break; |
|
178 | break; | |
111 | } |
|
179 | } | |
112 | case Qt::AlignLeft: { |
|
180 | case Qt::AlignLeft: { | |
113 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height())); |
|
181 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); | |
114 | int leftPadding = m_marginTiny + legendSize.width() + m_marginTiny + axisWidth; |
|
182 | legendRect = QRectF(geometry.topLeft(),QSizeF(width,geometry.height())); | |
115 | chartMargins = QMargins(leftPadding,chartMargins.top(),chartMargins.right(),chartMargins.bottom()); |
|
183 | result = geometry.adjusted(width,0,0,0); | |
116 | m_legendMargins = QMargins(m_marginTiny + m_marginSmall,chartMargins.top(),rect.width()-leftPadding + m_marginTiny + axisWidth,chartMargins.bottom()); |
|
|||
117 | titlePadding = chartMargins.top()/2; |
|
|||
118 | break; |
|
184 | break; | |
119 | } |
|
185 | } | |
120 | case Qt::AlignRight: { |
|
186 | case Qt::AlignRight: { | |
121 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height())); |
|
187 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); | |
122 | int rightPadding = m_marginTiny + legendSize.width() + m_marginTiny; |
|
188 | legendRect = QRectF(QPointF(geometry.right()-width,geometry.top()),QSizeF(width,geometry.height())); | |
123 | chartMargins = QMargins(chartMargins.left(),chartMargins.top(),rightPadding,chartMargins.bottom()); |
|
189 | result = geometry.adjusted(0,0,-width,0); | |
124 | m_legendMargins = QMargins(rect.width()- rightPadding+ m_marginTiny ,chartMargins.top(),m_marginTiny + m_marginSmall,chartMargins.bottom()); |
|
|||
125 | titlePadding = chartMargins.top()/2; |
|
|||
126 | break; |
|
190 | break; | |
127 | } |
|
191 | } | |
128 | default: { |
|
192 | default: { | |
129 | break; |
|
193 | break; | |
130 | } |
|
194 | } | |
131 | } |
|
|||
132 |
|
||||
133 | legend->setGeometry(rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); |
|
|||
134 | } |
|
195 | } | |
135 |
|
196 | |||
136 | // recalculate title position |
|
197 | legend->setGeometry(legendRect); | |
137 | if (m_presenter->titleItem()) { |
|
|||
138 | QPointF center = rect.center() - m_presenter->titleItem()->boundingRect().center(); |
|
|||
139 | m_presenter->titleItem()->setPos(center.x(),titlePadding); |
|
|||
140 | } |
|
|||
141 |
|
198 | |||
142 | //recalculate background gradient |
|
199 | return result; | |
143 | if (m_presenter->backgroundItem()) { |
|
200 | } | |
144 | m_presenter->backgroundItem()->setRect(rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); |
|
|||
145 | } |
|
|||
146 |
|
201 | |||
147 | QRectF chartRect = rect.adjusted(chartMargins.left(),chartMargins.top(),-chartMargins.right(),-chartMargins.bottom()); |
|
202 | QRectF ChartLayout::calculateLegendMinimum(const QRectF& geometry,QLegend* legend) const | |
|
203 | { | |||
|
204 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize,QSizeF(-1,-1)); | |||
|
205 | return geometry.adjusted(0,0,minSize.width(),minSize.height()); | |||
|
206 | } | |||
148 |
|
207 | |||
149 | if(m_presenter->geometry()!=chartRect && chartRect.isValid()){ |
|
208 | QRectF ChartLayout::calculateTitleGeometry(const QRectF& geometry,ChartTitle* title) const | |
150 | m_presenter->setGeometry(chartRect); |
|
209 | { | |
151 | }else if(chartRect.size().isEmpty()){ |
|
210 | title->setGeometry(geometry); | |
152 | m_presenter->setGeometry(QRect(rect.width()/2,rect.height()/2,1,1)); |
|
211 | QPointF center = geometry.center() - title->boundingRect().center(); | |
153 | } |
|
212 | title->setPos(center.x(),title->pos().y()); | |
|
213 | return geometry.adjusted(0,title->boundingRect().height(),0,0); | |||
154 | } |
|
214 | } | |
155 |
|
215 | |||
|
216 | QRectF ChartLayout::calculateTitleMinimum(const QRectF& minimum,ChartTitle* title) const | |||
|
217 | { | |||
|
218 | QSizeF min = title->sizeHint(Qt::MinimumSize); | |||
|
219 | return minimum.adjusted(0,0,min.width(),min.height()); | |||
|
220 | } | |||
156 |
|
221 | |||
157 | QSizeF ChartLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const |
|
222 | QSizeF ChartLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const | |
158 | { |
|
223 | { | |
159 | Q_UNUSED(constraint); |
|
224 | Q_UNUSED(constraint); | |
160 | if(which == Qt::MinimumSize) |
|
225 | if(which == Qt::MinimumSize){ | |
161 | return QSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom())); |
|
226 | QList<ChartAxis*> axes = m_presenter->axisItems(); | |
162 | else |
|
227 | ChartTitle* title = m_presenter->titleElement(); | |
|
228 | QLegend* legend = m_presenter->legend(); | |||
|
229 | QRectF minimumRect(0,0,0,0); | |||
|
230 | minimumRect = calculateBackgroundMinimum(minimumRect); | |||
|
231 | minimumRect = calculateContentMinimum(minimumRect); | |||
|
232 | minimumRect = calculateTitleMinimum(minimumRect,title); | |||
|
233 | minimumRect = calculateLegendMinimum(minimumRect,legend); | |||
|
234 | minimumRect = calculateAxisMinimum(minimumRect,axes); | |||
|
235 | return minimumRect.united(m_minChartRect).size().toSize(); | |||
|
236 | }else | |||
163 | return QSize(-1,-1); |
|
237 | return QSize(-1,-1); | |
164 | } |
|
238 | } | |
165 |
|
239 | |||
166 |
void ChartLayout::setM |
|
240 | void ChartLayout::setMargins(const QMargins& margins) | |
167 | { |
|
241 | { | |
168 |
|
242 | |||
169 |
if(m_ |
|
243 | if(m_margins != margins){ | |
170 |
m_ |
|
244 | m_margins = margins; | |
171 | updateGeometry(); |
|
245 | updateGeometry(); | |
172 | } |
|
246 | } | |
173 | } |
|
247 | } | |
174 |
|
248 | |||
175 |
QMargins ChartLayout::m |
|
249 | QMargins ChartLayout::margins() const | |
|
250 | { | |||
|
251 | return m_margins; | |||
|
252 | } | |||
|
253 | ||||
|
254 | void ChartLayout::adjustChartGeometry() | |||
176 | { |
|
255 | { | |
177 | return m_chartMargins; |
|
256 | setGeometry(geometry()); | |
178 | } |
|
257 | } | |
179 |
|
258 | |||
180 | QTCOMMERCIALCHART_END_NAMESPACE |
|
259 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,63 +1,75 | |||||
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 | #ifndef CHARTLAYOUT_H |
|
21 | #ifndef CHARTLAYOUT_H | |
22 | #define CHARTLAYOUT_H |
|
22 | #define CHARTLAYOUT_H | |
23 | #include <QGraphicsLayout> |
|
23 | #include <QGraphicsLayout> | |
24 | #include <QMargins> |
|
24 | #include <QMargins> | |
25 | #include "qchartglobal.h" |
|
25 | #include "qchartglobal.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class ChartPresenter; |
|
29 | class ChartPresenter; | |
|
30 | class ChartTitle; | |||
|
31 | class QLegend; | |||
|
32 | class ChartAxis; | |||
|
33 | class ChartBackground; | |||
30 |
|
34 | |||
31 | class ChartLayout : public QGraphicsLayout |
|
35 | class ChartLayout : public QGraphicsLayout | |
32 | { |
|
36 | { | |
33 | public: |
|
37 | public: | |
34 |
|
38 | |||
35 | ChartLayout(ChartPresenter* presenter); |
|
39 | ChartLayout(ChartPresenter* presenter); | |
36 | virtual ~ChartLayout(); |
|
40 | virtual ~ChartLayout(); | |
37 |
|
41 | |||
38 |
void setM |
|
42 | void setMargins(const QMargins& margins); | |
39 |
QMargins m |
|
43 | QMargins margins() const; | |
40 |
|
44 | |||
41 | void setGeometry(const QRectF& rect); |
|
45 | void setGeometry(const QRectF& rect); | |
|
46 | void adjustChartGeometry(); | |||
42 |
|
47 | |||
43 | protected: |
|
48 | protected: | |
44 | QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const; |
|
49 | QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const; | |
45 | int count() const { return 0; } |
|
50 | int count() const { return 0; } | |
46 | QGraphicsLayoutItem* itemAt(int) const { return 0; }; |
|
51 | QGraphicsLayoutItem* itemAt(int) const { return 0; }; | |
47 | void removeAt(int){}; |
|
52 | void removeAt(int){}; | |
48 |
|
53 | |||
49 | private: |
|
54 | private: | |
50 | ChartPresenter* m_presenter; |
|
55 | QRectF calculateBackgroundGeometry(const QRectF& geometry,ChartBackground* background) const; | |
51 | int m_marginBig; |
|
56 | QRectF calculateContentGeometry(const QRectF& geometry) const; | |
52 | int m_marginSmall; |
|
57 | QRectF calculateTitleGeometry(const QRectF& geometry, ChartTitle* title) const; | |
53 | int m_marginTiny; |
|
58 | QRectF calculateChartGeometry(const QRectF& geometry,const QList<ChartAxis*>& axes) const; | |
54 | QMargins m_chartMargins; |
|
59 | QRectF calculateLegendGeometry(const QRectF& geometry, QLegend* legend) const; | |
55 | QMargins m_legendMargins; |
|
60 | QRectF calculateBackgroundMinimum(const QRectF& minimum) const; | |
56 | bool m_intialized; |
|
61 | QRectF calculateContentMinimum(const QRectF& minimum) const; | |
57 |
|
62 | QRectF calculateTitleMinimum(const QRectF& minimum,ChartTitle* title) const; | ||
|
63 | QRectF calculateAxisMinimum(const QRectF& minimum,const QList<ChartAxis*>& axes) const; | |||
|
64 | QRectF calculateLegendMinimum(const QRectF& minimum,QLegend* legend) const; | |||
58 |
|
65 | |||
|
66 | private: | |||
|
67 | ChartPresenter* m_presenter; | |||
|
68 | QMargins m_margins; | |||
|
69 | QRectF m_minChartRect; | |||
|
70 | QRectF m_minAxisRect; | |||
59 | }; |
|
71 | }; | |
60 |
|
72 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
74 | |||
63 | #endif |
|
75 | #endif |
@@ -1,449 +1,456 | |||||
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 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "qabstractaxis_p.h" |
|
24 | #include "qabstractaxis_p.h" | |
25 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
27 | #include "chartanimation_p.h" |
|
27 | #include "chartanimation_p.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "chartaxis_p.h" |
|
30 | #include "chartaxis_p.h" | |
31 | //#include "chartaxisx_p.h" |
|
|||
32 | //#include "chartaxisy_p.h" |
|
|||
33 | #include "areachartitem_p.h" |
|
|||
34 | #include "chartbackground_p.h" |
|
31 | #include "chartbackground_p.h" | |
35 | #include "chartlayout_p.h" |
|
32 | #include "chartlayout_p.h" | |
|
33 | #include "charttitle_p.h" | |||
36 | #include <QTimer> |
|
34 | #include <QTimer> | |
37 |
|
35 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
37 | |||
40 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
38 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
41 | m_chart(chart), |
|
39 | m_chart(chart), | |
42 | m_dataset(dataset), |
|
40 | m_dataset(dataset), | |
43 | m_chartTheme(0), |
|
41 | m_chartTheme(0), | |
44 | m_options(QChart::NoAnimation), |
|
42 | m_options(QChart::NoAnimation), | |
45 | m_state(ShowState), |
|
43 | m_state(ShowState), | |
46 | m_layout(new ChartLayout(this)), |
|
44 | m_layout(new ChartLayout(this)), | |
47 |
m_background |
|
45 | m_background(0), | |
48 |
m_title |
|
46 | m_title(0) | |
49 | { |
|
47 | { | |
50 |
|
48 | |||
51 | } |
|
49 | } | |
52 |
|
50 | |||
53 | ChartPresenter::~ChartPresenter() |
|
51 | ChartPresenter::~ChartPresenter() | |
54 | { |
|
52 | { | |
55 | delete m_chartTheme; |
|
53 | delete m_chartTheme; | |
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 | void ChartPresenter::setGeometry(const QRectF& rect) |
|
56 | void ChartPresenter::setChartsGeometry(const QRectF& rect) | |
59 | { |
|
57 | { | |
60 |
|
||||
61 | Q_ASSERT(rect.isValid()); |
|
58 | Q_ASSERT(rect.isValid()); | |
62 |
|
59 | |||
63 | if(m_rect!=rect) { |
|
60 | if(m_chartsRect!=rect) { | |
64 |
|
|
61 | m_chartsRect=rect; | |
65 | emit geometryChanged(m_rect); |
|
62 | foreach(ChartElement* chart, m_chartItems) | |
|
63 | { | |||
|
64 | chart->handleGeometryChanged(rect); | |||
|
65 | } | |||
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
|
69 | QRectF ChartPresenter::chartsGeometry() const | |||
|
70 | { | |||
|
71 | return m_chartsRect; | |||
|
72 | } | |||
|
73 | ||||
69 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) |
|
74 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) | |
70 | { |
|
75 | { | |
71 | ChartAxis* item = axis->d_ptr->createGraphics(this); |
|
76 | ChartAxis* item = axis->d_ptr->createGraphics(this); | |
72 | item->setDomain(domain); |
|
77 | item->setDomain(domain); | |
73 |
|
78 | |||
74 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
79 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
75 | item->setAnimation(new AxisAnimation(item)); |
|
80 | item->setAnimation(new AxisAnimation(item)); | |
76 | } |
|
81 | } | |
77 |
|
82 | |||
78 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
83 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
79 | QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); |
|
84 | QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); | |
80 | QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); |
|
85 | QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); | |
81 |
|
86 | |||
82 | //initialize |
|
87 | //initialize | |
83 | domain->emitUpdated(); |
|
88 | domain->emitUpdated(); | |
84 | m_chartTheme->decorate(axis); |
|
89 | m_chartTheme->decorate(axis); | |
85 | axis->d_ptr->setDirty(false); |
|
90 | axis->d_ptr->setDirty(false); | |
86 | axis->d_ptr->emitUpdated(); |
|
91 | axis->d_ptr->emitUpdated(); | |
87 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
92 | if(m_chartsRect.isValid()) item->handleGeometryChanged(m_chartsRect); | |
88 |
|
93 | |||
89 | m_axisItems.insert(axis, item); |
|
94 | m_axisItems.insert(axis, item); | |
90 | selectVisibleAxis(); |
|
95 | selectVisibleAxis(); | |
91 | } |
|
96 | } | |
92 |
|
97 | |||
93 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) |
|
98 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) | |
94 | { |
|
99 | { | |
95 | ChartAxis* item = m_axisItems.take(axis); |
|
100 | ChartAxis* item = m_axisItems.take(axis); | |
96 | Q_ASSERT(item); |
|
101 | Q_ASSERT(item); | |
97 | selectVisibleAxis(); |
|
102 | selectVisibleAxis(); | |
98 | item->hide(); |
|
103 | item->hide(); | |
99 | item->disconnect(); |
|
104 | item->disconnect(); | |
100 | QObject::disconnect(this,0,item,0); |
|
105 | QObject::disconnect(this,0,item,0); | |
101 | item->deleteLater(); |
|
106 | item->deleteLater(); | |
102 | } |
|
107 | } | |
103 |
|
108 | |||
104 |
|
109 | |||
105 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) |
|
110 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) | |
106 | { |
|
111 | { | |
107 | ChartElement *item = series->d_ptr->createGraphics(this); |
|
112 | ChartElement *item = series->d_ptr->createGraphics(this); | |
108 | Q_ASSERT(item); |
|
113 | Q_ASSERT(item); | |
109 | item->setDomain(domain); |
|
114 | item->setDomain(domain); | |
110 |
|
115 | |||
111 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
112 | QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); |
|
117 | QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); | |
113 | //initialize |
|
118 | //initialize | |
114 | item->handleDomainUpdated(); |
|
119 | item->handleDomainUpdated(); | |
115 |
|
120 | |||
116 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
121 | if(m_chartsRect.isValid()) item->handleGeometryChanged(m_chartsRect); | |
117 | m_chartItems.insert(series,item); |
|
122 | m_chartItems.insert(series,item); | |
118 | } |
|
123 | } | |
119 |
|
124 | |||
120 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) |
|
125 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) | |
121 | { |
|
126 | { | |
122 | ChartElement* item = m_chartItems.take(series); |
|
127 | ChartElement* item = m_chartItems.take(series); | |
123 | Q_ASSERT(item); |
|
128 | Q_ASSERT(item); | |
124 | item->deleteLater(); |
|
129 | item->deleteLater(); | |
125 | } |
|
130 | } | |
126 |
|
131 | |||
127 | void ChartPresenter::selectVisibleAxis() |
|
132 | void ChartPresenter::selectVisibleAxis() | |
128 | { |
|
133 | { | |
129 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
134 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
130 |
|
135 | |||
131 | while (i.hasNext()) { |
|
136 | while (i.hasNext()) { | |
132 | i.next(); |
|
137 | i.next(); | |
133 | i.key()->hide(); |
|
138 | i.key()->hide(); | |
134 | } |
|
139 | } | |
135 |
|
140 | |||
136 | i.toFront(); |
|
141 | i.toFront(); | |
137 |
|
142 | |||
138 | bool axisX=false; |
|
143 | bool axisX=false; | |
139 | bool axisY=false; |
|
144 | bool axisY=false; | |
140 |
|
145 | |||
141 | while (i.hasNext()) { |
|
146 | while (i.hasNext()) { | |
142 | i.next(); |
|
147 | i.next(); | |
143 | if(i.key()->orientation()==Qt::Vertical && !axisY) { |
|
148 | if(i.key()->orientation()==Qt::Vertical && !axisY) { | |
144 | axisY=true; |
|
149 | axisY=true; | |
145 | i.key()->show(); |
|
150 | i.key()->show(); | |
146 | } |
|
151 | } | |
147 | if(i.key()->orientation()==Qt::Horizontal && !axisX) { |
|
152 | if(i.key()->orientation()==Qt::Horizontal && !axisX) { | |
148 | axisX=true; |
|
153 | axisX=true; | |
149 | i.key()->show(); |
|
154 | i.key()->show(); | |
150 | } |
|
155 | } | |
151 |
|
156 | |||
152 | } |
|
157 | } | |
153 | } |
|
158 | } | |
154 |
|
159 | |||
155 |
|
160 | |||
156 | void ChartPresenter::handleAxisVisibleChanged(bool visible) |
|
161 | void ChartPresenter::handleAxisVisibleChanged(bool visible) | |
157 | { |
|
162 | { | |
158 | QAbstractAxis* axis = static_cast<QAbstractAxis*> (sender()); |
|
163 | QAbstractAxis* axis = static_cast<QAbstractAxis*> (sender()); | |
159 | Q_ASSERT(axis); |
|
164 | Q_ASSERT(axis); | |
160 | if(visible){ |
|
165 | if(visible){ | |
161 |
|
166 | |||
162 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
167 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
163 |
|
168 | |||
164 | while (i.hasNext()) { |
|
169 | while (i.hasNext()) { | |
165 | i.next(); |
|
170 | i.next(); | |
166 | if(i.key()==axis) { |
|
171 | if(i.key()==axis) { | |
167 | continue; |
|
172 | continue; | |
168 | } |
|
173 | } | |
169 | if(i.key()->orientation()==axis->orientation()) { |
|
174 | if(i.key()->orientation()==axis->orientation()) { | |
170 | i.key()->setVisible(false); |
|
175 | i.key()->setVisible(false); | |
171 | } |
|
176 | } | |
172 | } |
|
177 | } | |
173 | } |
|
178 | } | |
174 | } |
|
179 | } | |
175 |
|
180 | |||
176 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
181 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
177 | { |
|
182 | { | |
178 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
183 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
179 | delete m_chartTheme; |
|
184 | delete m_chartTheme; | |
180 | m_chartTheme = ChartTheme::createTheme(theme); |
|
185 | m_chartTheme = ChartTheme::createTheme(theme); | |
181 | m_chartTheme->setForced(force); |
|
186 | m_chartTheme->setForced(force); | |
182 | m_chartTheme->decorate(m_chart); |
|
187 | m_chartTheme->decorate(m_chart); | |
183 | m_chartTheme->decorate(m_chart->legend()); |
|
188 | m_chartTheme->decorate(m_chart->legend()); | |
184 | resetAllElements(); |
|
189 | resetAllElements(); | |
185 |
|
190 | |||
186 | // We do not want "force" to stay on. |
|
191 | // We do not want "force" to stay on. | |
187 | // Bar/pie are calling decorate when adding/removing slices/bars which means |
|
192 | // Bar/pie are calling decorate when adding/removing slices/bars which means | |
188 | // that to preserve users colors "force" must not be on. |
|
193 | // that to preserve users colors "force" must not be on. | |
189 | m_chartTheme->setForced(false); |
|
194 | m_chartTheme->setForced(false); | |
190 | } |
|
195 | } | |
191 |
|
196 | |||
192 | QChart::ChartTheme ChartPresenter::theme() |
|
197 | QChart::ChartTheme ChartPresenter::theme() | |
193 | { |
|
198 | { | |
194 | return m_chartTheme->id(); |
|
199 | return m_chartTheme->id(); | |
195 | } |
|
200 | } | |
196 |
|
201 | |||
197 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
202 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
198 | { |
|
203 | { | |
199 | if(m_options!=options) { |
|
204 | if(m_options!=options) { | |
200 | m_options=options; |
|
205 | m_options=options; | |
201 | resetAllElements(); |
|
206 | resetAllElements(); | |
202 | } |
|
207 | } | |
203 |
|
208 | |||
204 | } |
|
209 | } | |
205 |
|
210 | |||
206 | void ChartPresenter::resetAllElements() |
|
211 | void ChartPresenter::resetAllElements() | |
207 | { |
|
212 | { | |
208 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
213 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
209 | while (i.hasNext()) { |
|
214 | while (i.hasNext()) { | |
210 | i.next(); |
|
215 | i.next(); | |
211 | Domain* domain = i.value()->domain(); |
|
216 | Domain* domain = i.value()->domain(); | |
212 | QAbstractAxis* axis = i.key(); |
|
217 | QAbstractAxis* axis = i.key(); | |
213 | handleAxisRemoved(axis); |
|
218 | handleAxisRemoved(axis); | |
214 | handleAxisAdded(axis,domain); |
|
219 | handleAxisAdded(axis,domain); | |
215 | } |
|
220 | } | |
216 |
|
221 | |||
217 | QMapIterator<QAbstractSeries*, ChartElement*> j(m_chartItems); |
|
222 | QMapIterator<QAbstractSeries*, ChartElement*> j(m_chartItems); | |
218 | while (j.hasNext()) { |
|
223 | while (j.hasNext()) { | |
219 | j.next(); |
|
224 | j.next(); | |
220 | Domain* domain = j.value()->domain(); |
|
225 | Domain* domain = j.value()->domain(); | |
221 | QAbstractSeries* series = j.key(); |
|
226 | QAbstractSeries* series = j.key(); | |
222 | handleSeriesRemoved(series); |
|
227 | handleSeriesRemoved(series); | |
223 | handleSeriesAdded(series,domain); |
|
228 | handleSeriesAdded(series,domain); | |
224 | } |
|
229 | } | |
|
230 | ||||
|
231 | layout()->invalidate(); | |||
225 | } |
|
232 | } | |
226 |
|
233 | |||
227 | void ChartPresenter::zoomIn(qreal factor) |
|
234 | void ChartPresenter::zoomIn(qreal factor) | |
228 | { |
|
235 | { | |
229 |
QRectF rect = |
|
236 | QRectF rect = chartsGeometry(); | |
230 | rect.setWidth(rect.width()/factor); |
|
237 | rect.setWidth(rect.width()/factor); | |
231 | rect.setHeight(rect.height()/factor); |
|
238 | rect.setHeight(rect.height()/factor); | |
232 |
rect.moveCenter( |
|
239 | rect.moveCenter(chartsGeometry().center()); | |
233 | zoomIn(rect); |
|
240 | zoomIn(rect); | |
234 | } |
|
241 | } | |
235 |
|
242 | |||
236 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
243 | void ChartPresenter::zoomIn(const QRectF& rect) | |
237 | { |
|
244 | { | |
238 | QRectF r = rect.normalized(); |
|
245 | QRectF r = rect.normalized(); | |
239 |
r.translate(- |
|
246 | r.translate(-chartsGeometry().topLeft()); | |
240 | if (!r.isValid()) |
|
247 | if (!r.isValid()) | |
241 | return; |
|
248 | return; | |
242 |
|
249 | |||
243 | m_state = ZoomInState; |
|
250 | m_state = ZoomInState; | |
244 |
m_statePoint = QPointF(r.center().x()/ |
|
251 | m_statePoint = QPointF(r.center().x()/chartsGeometry().width(),r.center().y()/chartsGeometry().height()); | |
245 |
m_dataset->zoomInDomain(r, |
|
252 | m_dataset->zoomInDomain(r,chartsGeometry().size()); | |
246 | m_state = ShowState; |
|
253 | m_state = ShowState; | |
247 | } |
|
254 | } | |
248 |
|
255 | |||
249 | void ChartPresenter::zoomOut(qreal factor) |
|
256 | void ChartPresenter::zoomOut(qreal factor) | |
250 | { |
|
257 | { | |
251 | m_state = ZoomOutState; |
|
258 | m_state = ZoomOutState; | |
252 |
|
259 | |||
253 | QRectF chartRect; |
|
260 | QRectF chartRect; | |
254 |
chartRect.setSize( |
|
261 | chartRect.setSize(chartsGeometry().size()); | |
255 |
|
262 | |||
256 | QRectF rect; |
|
263 | QRectF rect; | |
257 | rect.setSize(chartRect.size()/factor); |
|
264 | rect.setSize(chartRect.size()/factor); | |
258 | rect.moveCenter(chartRect.center()); |
|
265 | rect.moveCenter(chartRect.center()); | |
259 | if (!rect.isValid()) |
|
266 | if (!rect.isValid()) | |
260 | return; |
|
267 | return; | |
261 |
m_statePoint = QPointF(rect.center().x()/ |
|
268 | m_statePoint = QPointF(rect.center().x()/chartsGeometry().width(),rect.center().y()/chartsGeometry().height()); | |
262 | m_dataset->zoomOutDomain(rect, chartRect.size()); |
|
269 | m_dataset->zoomOutDomain(rect, chartRect.size()); | |
263 | m_state = ShowState; |
|
270 | m_state = ShowState; | |
264 | } |
|
271 | } | |
265 |
|
272 | |||
266 | void ChartPresenter::scroll(qreal dx,qreal dy) |
|
273 | void ChartPresenter::scroll(qreal dx,qreal dy) | |
267 | { |
|
274 | { | |
268 | if(dx<0) m_state=ScrollLeftState; |
|
275 | if(dx<0) m_state=ScrollLeftState; | |
269 | if(dx>0) m_state=ScrollRightState; |
|
276 | if(dx>0) m_state=ScrollRightState; | |
270 | if(dy<0) m_state=ScrollUpState; |
|
277 | if(dy<0) m_state=ScrollUpState; | |
271 | if(dy>0) m_state=ScrollDownState; |
|
278 | if(dy>0) m_state=ScrollDownState; | |
272 |
|
279 | |||
273 |
m_dataset->scrollDomain(dx,dy, |
|
280 | m_dataset->scrollDomain(dx,dy,chartsGeometry().size()); | |
274 | m_state = ShowState; |
|
281 | m_state = ShowState; | |
275 | } |
|
282 | } | |
276 |
|
283 | |||
277 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
284 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
278 | { |
|
285 | { | |
279 | return m_options; |
|
286 | return m_options; | |
280 | } |
|
287 | } | |
281 |
|
288 | |||
282 | void ChartPresenter::createBackgroundItem() |
|
289 | void ChartPresenter::createBackgroundItem() | |
283 | { |
|
290 | { | |
284 |
if (!m_background |
|
291 | if (!m_background) { | |
285 |
m_background |
|
292 | m_background = new ChartBackground(rootItem()); | |
286 |
m_background |
|
293 | m_background->setPen(Qt::NoPen); | |
287 |
m_background |
|
294 | m_background->setZValue(ChartPresenter::BackgroundZValue); | |
288 | } |
|
295 | } | |
289 | } |
|
296 | } | |
290 |
|
297 | |||
291 | void ChartPresenter::createTitleItem() |
|
298 | void ChartPresenter::createTitleItem() | |
292 | { |
|
299 | { | |
293 |
if (!m_title |
|
300 | if (!m_title) { | |
294 |
m_title |
|
301 | m_title = new ChartTitle(rootItem()); | |
295 |
m_title |
|
302 | m_title->setZValue(ChartPresenter::BackgroundZValue); | |
296 | } |
|
303 | } | |
297 | } |
|
304 | } | |
298 |
|
305 | |||
299 |
|
306 | |||
300 | void ChartPresenter::handleAnimationFinished() |
|
307 | void ChartPresenter::handleAnimationFinished() | |
301 | { |
|
308 | { | |
302 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); |
|
309 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); | |
303 | if(m_animations.empty()) emit animationsFinished(); |
|
310 | if(m_animations.empty()) emit animationsFinished(); | |
304 | } |
|
311 | } | |
305 |
|
312 | |||
306 | void ChartPresenter::startAnimation(ChartAnimation* animation) |
|
313 | void ChartPresenter::startAnimation(ChartAnimation* animation) | |
307 | { |
|
314 | { | |
308 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
315 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
309 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); |
|
316 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); | |
310 | if(!m_animations.isEmpty()){ |
|
317 | if(!m_animations.isEmpty()){ | |
311 | m_animations.append(animation); |
|
318 | m_animations.append(animation); | |
312 | } |
|
319 | } | |
313 | QTimer::singleShot(0, animation, SLOT(start())); |
|
320 | QTimer::singleShot(0, animation, SLOT(start())); | |
314 | } |
|
321 | } | |
315 |
|
322 | |||
316 | QGraphicsRectItem* ChartPresenter::backgroundItem() |
|
|||
317 | { |
|
|||
318 | return m_backgroundItem; |
|
|||
319 | } |
|
|||
320 |
|
||||
321 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) |
|
323 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) | |
322 | { |
|
324 | { | |
323 | createBackgroundItem(); |
|
325 | createBackgroundItem(); | |
324 |
m_background |
|
326 | m_background->setBrush(brush); | |
325 | m_layout->invalidate(); |
|
327 | m_layout->invalidate(); | |
326 | } |
|
328 | } | |
327 |
|
329 | |||
328 | QBrush ChartPresenter::backgroundBrush() const |
|
330 | QBrush ChartPresenter::backgroundBrush() const | |
329 | { |
|
331 | { | |
330 |
if (!m_background |
|
332 | if (!m_background) return QBrush(); | |
331 |
return m_background |
|
333 | return m_background->brush(); | |
332 | } |
|
334 | } | |
333 |
|
335 | |||
334 | void ChartPresenter::setBackgroundPen(const QPen& pen) |
|
336 | void ChartPresenter::setBackgroundPen(const QPen& pen) | |
335 | { |
|
337 | { | |
336 | createBackgroundItem(); |
|
338 | createBackgroundItem(); | |
337 |
m_background |
|
339 | m_background->setPen(pen); | |
338 | m_layout->invalidate(); |
|
340 | m_layout->invalidate(); | |
339 | } |
|
341 | } | |
340 |
|
342 | |||
341 | QPen ChartPresenter::backgroundPen() const |
|
343 | QPen ChartPresenter::backgroundPen() const | |
342 | { |
|
344 | { | |
343 |
if (!m_background |
|
345 | if (!m_background) return QPen(); | |
344 |
return m_background |
|
346 | return m_background->pen(); | |
345 | } |
|
|||
346 |
|
||||
347 | QGraphicsItem* ChartPresenter::titleItem() |
|
|||
348 | { |
|
|||
349 | return m_titleItem; |
|
|||
350 | } |
|
347 | } | |
351 |
|
348 | |||
352 | void ChartPresenter::setTitle(const QString& title) |
|
349 | void ChartPresenter::setTitle(const QString& title) | |
353 | { |
|
350 | { | |
354 | createTitleItem(); |
|
351 | createTitleItem(); | |
355 |
m_title |
|
352 | m_title->setText(title); | |
356 | m_layout->invalidate(); |
|
353 | m_layout->invalidate(); | |
357 | } |
|
354 | } | |
358 |
|
355 | |||
359 | QString ChartPresenter::title() const |
|
356 | QString ChartPresenter::title() const | |
360 | { |
|
357 | { | |
361 |
if (!m_title |
|
358 | if (!m_title) return QString(); | |
362 |
return m_title |
|
359 | return m_title->text(); | |
363 | } |
|
360 | } | |
364 |
|
361 | |||
365 | void ChartPresenter::setTitleFont(const QFont& font) |
|
362 | void ChartPresenter::setTitleFont(const QFont& font) | |
366 | { |
|
363 | { | |
367 | createTitleItem(); |
|
364 | createTitleItem(); | |
368 |
m_title |
|
365 | m_title->setFont(font); | |
369 | m_layout->invalidate(); |
|
366 | m_layout->invalidate(); | |
370 | } |
|
367 | } | |
371 |
|
368 | |||
372 | QFont ChartPresenter::titleFont() const |
|
369 | QFont ChartPresenter::titleFont() const | |
373 | { |
|
370 | { | |
374 |
if (!m_title |
|
371 | if (!m_title) return QFont(); | |
375 |
return m_title |
|
372 | return m_title->font(); | |
376 | } |
|
373 | } | |
377 |
|
374 | |||
378 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
375 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
379 | { |
|
376 | { | |
380 | createTitleItem(); |
|
377 | createTitleItem(); | |
381 |
m_title |
|
378 | m_title->setBrush(brush); | |
382 | m_layout->invalidate(); |
|
379 | m_layout->invalidate(); | |
383 | } |
|
380 | } | |
384 |
|
381 | |||
385 | QBrush ChartPresenter::titleBrush() const |
|
382 | QBrush ChartPresenter::titleBrush() const | |
386 | { |
|
383 | { | |
387 |
if (!m_title |
|
384 | if (!m_title) return QBrush(); | |
388 |
return m_title |
|
385 | return m_title->brush(); | |
389 | } |
|
386 | } | |
390 |
|
387 | |||
391 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
388 | void ChartPresenter::setBackgroundVisible(bool visible) | |
392 | { |
|
389 | { | |
393 | createBackgroundItem(); |
|
390 | createBackgroundItem(); | |
394 |
m_background |
|
391 | m_background->setVisible(visible); | |
395 | } |
|
392 | } | |
396 |
|
393 | |||
397 |
|
394 | |||
398 | bool ChartPresenter::isBackgroundVisible() const |
|
395 | bool ChartPresenter::isBackgroundVisible() const | |
399 | { |
|
396 | { | |
400 |
if (!m_background |
|
397 | if (!m_background) return false; | |
401 |
return m_background |
|
398 | return m_background->isVisible(); | |
402 | } |
|
399 | } | |
403 |
|
400 | |||
404 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
401 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
405 | { |
|
402 | { | |
406 | createBackgroundItem(); |
|
403 | createBackgroundItem(); | |
407 |
m_background |
|
404 | m_background->setDropShadowEnabled(enabled); | |
408 | } |
|
405 | } | |
409 |
|
406 | |||
410 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
407 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
411 | { |
|
408 | { | |
412 |
if (!m_background |
|
409 | if (!m_background) return false; | |
413 |
return m_background |
|
410 | return m_background->isDropShadowEnabled(); | |
414 | } |
|
411 | } | |
415 |
|
412 | |||
416 |
|
413 | |||
417 | QGraphicsLayout* ChartPresenter::layout() |
|
414 | QGraphicsLayout* ChartPresenter::layout() | |
418 | { |
|
415 | { | |
419 | return m_layout; |
|
416 | return m_layout; | |
420 | } |
|
417 | } | |
421 |
|
418 | |||
422 |
void ChartPresenter::setM |
|
419 | void ChartPresenter::setMargins(const QMargins& margins) | |
423 | { |
|
420 | { | |
424 |
m_layout->setM |
|
421 | m_layout->setMargins(margins); | |
425 | } |
|
422 | } | |
426 |
|
423 | |||
427 |
QMargins ChartPresenter::m |
|
424 | QMargins ChartPresenter::margins() const | |
428 | { |
|
425 | { | |
429 |
return m_layout->m |
|
426 | return m_layout->margins(); | |
430 | } |
|
427 | } | |
431 |
|
428 | |||
432 | QLegend* ChartPresenter::legend() |
|
429 | QLegend* ChartPresenter::legend() | |
433 | { |
|
430 | { | |
434 | return m_chart->legend(); |
|
431 | return m_chart->legend(); | |
435 | } |
|
432 | } | |
436 |
|
433 | |||
|
434 | void ChartPresenter::setVisible(bool visible) | |||
|
435 | { | |||
|
436 | m_chart->setVisible(visible); | |||
|
437 | } | |||
|
438 | ||||
|
439 | ChartBackground* ChartPresenter::backgroundElement() | |||
|
440 | { | |||
|
441 | return m_background; | |||
|
442 | } | |||
|
443 | ||||
437 | QList<ChartAxis*> ChartPresenter::axisItems() const |
|
444 | QList<ChartAxis*> ChartPresenter::axisItems() const | |
438 | { |
|
445 | { | |
439 | return m_axisItems.values(); |
|
446 | return m_axisItems.values(); | |
440 | } |
|
447 | } | |
441 |
|
448 | |||
442 | void ChartPresenter::setVisible(bool visible) |
|
449 | ChartTitle* ChartPresenter::titleElement() | |
443 | { |
|
450 | { | |
444 | m_chart->setVisible(visible); |
|
451 | return m_title; | |
445 | } |
|
452 | } | |
446 |
|
453 | |||
447 | #include "moc_chartpresenter_p.cpp" |
|
454 | #include "moc_chartpresenter_p.cpp" | |
448 |
|
455 | |||
449 | QTCOMMERCIALCHART_END_NAMESPACE |
|
456 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,177 +1,178 | |||||
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 CHARTPRESENTER_H |
|
30 | #ifndef CHARTPRESENTER_H | |
31 | #define CHARTPRESENTER_H |
|
31 | #define CHARTPRESENTER_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
34 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
35 | #include <QRectF> |
|
35 | #include <QRectF> | |
36 | #include <QMargins> |
|
36 | #include <QMargins> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class ChartElement; |
|
40 | class ChartElement; | |
41 | class QAbstractSeries; |
|
41 | class QAbstractSeries; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 | class Domain; |
|
43 | class Domain; | |
44 | class ChartAxis; |
|
44 | class ChartAxis; | |
45 | class ChartTheme; |
|
45 | class ChartTheme; | |
46 | class ChartAnimator; |
|
46 | class ChartAnimator; | |
47 | class ChartBackground; |
|
47 | class ChartBackground; | |
|
48 | class ChartTitle; | |||
48 | class ChartAnimation; |
|
49 | class ChartAnimation; | |
49 | class ChartLayout; |
|
50 | class ChartLayout; | |
50 |
|
51 | |||
51 | class ChartPresenter: public QObject |
|
52 | class ChartPresenter: public QObject | |
52 | { |
|
53 | { | |
53 | Q_OBJECT |
|
54 | Q_OBJECT | |
54 | public: |
|
55 | public: | |
55 | enum ZValues { |
|
56 | enum ZValues { | |
56 | BackgroundZValue = -1, |
|
57 | BackgroundZValue = -1, | |
57 | ShadesZValue , |
|
58 | ShadesZValue , | |
58 | GridZValue, |
|
59 | GridZValue, | |
59 | AxisZValue, |
|
60 | AxisZValue, | |
60 | SeriesZValue, |
|
61 | SeriesZValue, | |
61 | LineChartZValue = SeriesZValue, |
|
62 | LineChartZValue = SeriesZValue, | |
62 | SplineChartZValue = SeriesZValue, |
|
63 | SplineChartZValue = SeriesZValue, | |
63 | BarSeriesZValue = SeriesZValue, |
|
64 | BarSeriesZValue = SeriesZValue, | |
64 | ScatterSeriesZValue = SeriesZValue, |
|
65 | ScatterSeriesZValue = SeriesZValue, | |
65 | PieSeriesZValue = SeriesZValue, |
|
66 | PieSeriesZValue = SeriesZValue, | |
66 | LegendZValue, |
|
67 | LegendZValue, | |
67 | TopMostZValue |
|
68 | TopMostZValue | |
68 | }; |
|
69 | }; | |
69 |
|
70 | |||
70 | enum State { |
|
71 | enum State { | |
71 | ShowState, |
|
72 | ShowState, | |
72 | ScrollUpState, |
|
73 | ScrollUpState, | |
73 | ScrollDownState, |
|
74 | ScrollDownState, | |
74 | ScrollLeftState, |
|
75 | ScrollLeftState, | |
75 | ScrollRightState, |
|
76 | ScrollRightState, | |
76 | ZoomInState, |
|
77 | ZoomInState, | |
77 | ZoomOutState |
|
78 | ZoomOutState | |
78 | }; |
|
79 | }; | |
79 |
|
80 | |||
80 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
81 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
81 | virtual ~ChartPresenter(); |
|
82 | virtual ~ChartPresenter(); | |
82 |
|
83 | |||
83 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
84 | ChartTheme *chartTheme() const { return m_chartTheme; } | |
84 | ChartDataSet *dataSet() const { return m_dataset; } |
|
85 | ChartDataSet *dataSet() const { return m_dataset; } | |
85 | QGraphicsItem* rootItem() const { return m_chart; } |
|
86 | QGraphicsItem* rootItem() const { return m_chart; } | |
86 | QGraphicsRectItem* backgroundItem(); |
|
87 | ChartBackground* backgroundElement(); | |
87 |
|
|
88 | ChartTitle* titleElement(); | |
88 | QList<ChartAxis*> axisItems() const; |
|
89 | QList<ChartAxis*> axisItems() const; | |
89 |
|
90 | |||
90 | QLegend* legend(); |
|
91 | QLegend* legend(); | |
91 |
|
92 | |||
92 | void setBackgroundBrush(const QBrush& brush); |
|
93 | void setBackgroundBrush(const QBrush& brush); | |
93 | QBrush backgroundBrush() const; |
|
94 | QBrush backgroundBrush() const; | |
94 |
|
95 | |||
95 | void setBackgroundPen(const QPen& pen); |
|
96 | void setBackgroundPen(const QPen& pen); | |
96 | QPen backgroundPen() const; |
|
97 | QPen backgroundPen() const; | |
97 |
|
98 | |||
98 | void setTitle(const QString& title); |
|
99 | void setTitle(const QString& title); | |
99 | QString title() const; |
|
100 | QString title() const; | |
100 |
|
101 | |||
101 | void setTitleFont(const QFont& font); |
|
102 | void setTitleFont(const QFont& font); | |
102 | QFont titleFont() const; |
|
103 | QFont titleFont() const; | |
103 |
|
104 | |||
104 | void setTitleBrush(const QBrush &brush); |
|
105 | void setTitleBrush(const QBrush &brush); | |
105 | QBrush titleBrush() const; |
|
106 | QBrush titleBrush() const; | |
106 |
|
107 | |||
107 | void setBackgroundVisible(bool visible); |
|
108 | void setBackgroundVisible(bool visible); | |
108 | bool isBackgroundVisible() const; |
|
109 | bool isBackgroundVisible() const; | |
109 |
|
110 | |||
110 | void setBackgroundDropShadowEnabled(bool enabled); |
|
111 | void setBackgroundDropShadowEnabled(bool enabled); | |
111 | bool isBackgroundDropShadowEnabled() const; |
|
112 | bool isBackgroundDropShadowEnabled() const; | |
112 |
|
113 | |||
113 | void setVisible(bool visible); |
|
114 | void setVisible(bool visible); | |
114 |
|
115 | |||
115 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
116 | void setTheme(QChart::ChartTheme theme,bool force = true); | |
116 | QChart::ChartTheme theme(); |
|
117 | QChart::ChartTheme theme(); | |
117 |
|
118 | |||
118 | void setAnimationOptions(QChart::AnimationOptions options); |
|
119 | void setAnimationOptions(QChart::AnimationOptions options); | |
119 | QChart::AnimationOptions animationOptions() const; |
|
120 | QChart::AnimationOptions animationOptions() const; | |
120 |
|
121 | |||
121 | void zoomIn(qreal factor); |
|
122 | void zoomIn(qreal factor); | |
122 | void zoomIn(const QRectF& rect); |
|
123 | void zoomIn(const QRectF& rect); | |
123 | void zoomOut(qreal factor); |
|
124 | void zoomOut(qreal factor); | |
124 | void scroll(qreal dx,qreal dy); |
|
125 | void scroll(qreal dx,qreal dy); | |
125 |
|
126 | |||
126 | void setGeometry(const QRectF& rect); |
|
127 | void setChartsGeometry(const QRectF& rect); | |
127 |
QRectF |
|
128 | QRectF chartsGeometry() const; | |
128 |
|
129 | |||
129 | void startAnimation(ChartAnimation* animation); |
|
130 | void startAnimation(ChartAnimation* animation); | |
130 | State state() const { return m_state; } |
|
131 | State state() const { return m_state; } | |
131 | QPointF statePoint() const { return m_statePoint; } |
|
132 | QPointF statePoint() const { return m_statePoint; } | |
132 |
|
133 | |||
133 | void resetAllElements(); |
|
134 | void resetAllElements(); | |
134 |
|
135 | |||
135 |
void setM |
|
136 | void setMargins(const QMargins& margins); | |
136 |
QMargins m |
|
137 | QMargins margins() const; | |
137 | QGraphicsLayout* layout(); |
|
138 | QGraphicsLayout* layout(); | |
138 |
|
139 | |||
139 | private: |
|
140 | private: | |
140 | void createBackgroundItem(); |
|
141 | void createBackgroundItem(); | |
141 | void createTitleItem(); |
|
142 | void createTitleItem(); | |
142 | void selectVisibleAxis(); |
|
143 | void selectVisibleAxis(); | |
143 |
|
144 | |||
144 | public Q_SLOTS: |
|
145 | public Q_SLOTS: | |
145 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); |
|
146 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); | |
146 | void handleSeriesRemoved(QAbstractSeries* series); |
|
147 | void handleSeriesRemoved(QAbstractSeries* series); | |
147 | void handleAxisAdded(QAbstractAxis* axis,Domain* domain); |
|
148 | void handleAxisAdded(QAbstractAxis* axis,Domain* domain); | |
148 | void handleAxisRemoved(QAbstractAxis* axis); |
|
149 | void handleAxisRemoved(QAbstractAxis* axis); | |
149 | void handleAxisVisibleChanged(bool visible); |
|
150 | void handleAxisVisibleChanged(bool visible); | |
150 |
|
151 | |||
151 | private Q_SLOTS: |
|
152 | private Q_SLOTS: | |
152 | void handleAnimationFinished(); |
|
153 | void handleAnimationFinished(); | |
153 |
|
154 | |||
154 | Q_SIGNALS: |
|
155 | Q_SIGNALS: | |
155 | void geometryChanged(const QRectF& rect); |
|
156 | void geometryChanged(const QRectF& rect); | |
156 | void animationsFinished(); |
|
157 | void animationsFinished(); | |
157 | void marginsChanged(QRectF margins); |
|
158 | void marginsChanged(QRectF margins); | |
158 |
|
159 | |||
159 | private: |
|
160 | private: | |
160 | QChart* m_chart; |
|
161 | QChart* m_chart; | |
161 | ChartDataSet* m_dataset; |
|
162 | ChartDataSet* m_dataset; | |
162 | ChartTheme *m_chartTheme; |
|
163 | ChartTheme *m_chartTheme; | |
163 | QMap<QAbstractSeries*, ChartElement*> m_chartItems; |
|
164 | QMap<QAbstractSeries*, ChartElement*> m_chartItems; | |
164 | QMap<QAbstractAxis*, ChartAxis*> m_axisItems; |
|
165 | QMap<QAbstractAxis*, ChartAxis*> m_axisItems; | |
165 | QRectF m_rect; |
|
166 | QRectF m_chartsRect; | |
166 | QChart::AnimationOptions m_options; |
|
167 | QChart::AnimationOptions m_options; | |
167 | State m_state; |
|
168 | State m_state; | |
168 | QPointF m_statePoint; |
|
169 | QPointF m_statePoint; | |
169 | QList<ChartAnimation*> m_animations; |
|
170 | QList<ChartAnimation*> m_animations; | |
170 | ChartLayout* m_layout; |
|
171 | ChartLayout* m_layout; | |
171 |
ChartBackground* m_background |
|
172 | ChartBackground* m_background; | |
172 | QGraphicsSimpleTextItem* m_titleItem; |
|
173 | ChartTitle* m_title; | |
173 | }; |
|
174 | }; | |
174 |
|
175 | |||
175 | QTCOMMERCIALCHART_END_NAMESPACE |
|
176 | QTCOMMERCIALCHART_END_NAMESPACE | |
176 |
|
177 | |||
177 | #endif /* CHARTPRESENTER_H */ |
|
178 | #endif /* CHARTPRESENTER_H */ |
@@ -1,207 +1,206 | |||||
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 "domain_p.h" |
|
21 | #include "domain_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | Domain::Domain(QObject* parent) : QObject(parent), |
|
26 | Domain::Domain(QObject* parent) : QObject(parent), | |
27 | m_minX(0), |
|
27 | m_minX(0), | |
28 | m_maxX(0), |
|
28 | m_maxX(0), | |
29 | m_minY(0), |
|
29 | m_minY(0), | |
30 | m_maxY(0) |
|
30 | m_maxY(0) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | Domain::~Domain() |
|
34 | Domain::~Domain() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
38 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
39 | { |
|
39 | { | |
40 | bool axisXChanged = false; |
|
40 | bool axisXChanged = false; | |
41 | bool axisYChanged = false; |
|
41 | bool axisYChanged = false; | |
42 |
|
42 | |||
43 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { |
|
43 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { | |
44 | m_minX=minX; |
|
44 | m_minX=minX; | |
45 | m_maxX=maxX; |
|
45 | m_maxX=maxX; | |
46 | axisXChanged=true; |
|
46 | axisXChanged=true; | |
47 | emit rangeXChanged(m_minX,m_maxX); |
|
47 | emit rangeXChanged(m_minX,m_maxX); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
50 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { | |
51 | m_minY=minY; |
|
51 | m_minY=minY; | |
52 | m_maxY=maxY; |
|
52 | m_maxY=maxY; | |
53 | axisYChanged=true; |
|
53 | axisYChanged=true; | |
54 | emit rangeYChanged(m_minY,m_maxY); |
|
54 | emit rangeYChanged(m_minY,m_maxY); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | if(axisXChanged || axisYChanged) { |
|
57 | if(axisXChanged || axisYChanged) { | |
58 | emit updated(); |
|
58 | emit updated(); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void Domain::setRangeX(qreal min, qreal max) |
|
62 | void Domain::setRangeX(qreal min, qreal max) | |
63 | { |
|
63 | { | |
64 | setRange(min,max,m_minY, m_maxY); |
|
64 | setRange(min,max,m_minY, m_maxY); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void Domain::setRangeY(qreal min, qreal max) |
|
67 | void Domain::setRangeY(qreal min, qreal max) | |
68 | { |
|
68 | { | |
69 | setRange(m_minX, m_maxX, min, max); |
|
69 | setRange(m_minX, m_maxX, min, max); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void Domain::setMinX(qreal min) |
|
72 | void Domain::setMinX(qreal min) | |
73 | { |
|
73 | { | |
74 | setRange(min, m_maxX, m_minY, m_maxY); |
|
74 | setRange(min, m_maxX, m_minY, m_maxY); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void Domain::setMaxX(qreal max) |
|
77 | void Domain::setMaxX(qreal max) | |
78 | { |
|
78 | { | |
79 | setRange(m_minX, max, m_minY, m_maxY); |
|
79 | setRange(m_minX, max, m_minY, m_maxY); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void Domain::setMinY(qreal min) |
|
82 | void Domain::setMinY(qreal min) | |
83 | { |
|
83 | { | |
84 | setRange(m_minX, m_maxX, min, m_maxY); |
|
84 | setRange(m_minX, m_maxX, min, m_maxY); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void Domain::setMaxY(qreal max) |
|
87 | void Domain::setMaxY(qreal max) | |
88 | { |
|
88 | { | |
89 | setRange(m_minX, m_maxX, m_minY, max); |
|
89 | setRange(m_minX, m_maxX, m_minY, max); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | qreal Domain::spanX() const |
|
92 | qreal Domain::spanX() const | |
93 | { |
|
93 | { | |
94 | Q_ASSERT(m_maxX >= m_minX); |
|
94 | Q_ASSERT(m_maxX >= m_minX); | |
95 | return m_maxX - m_minX; |
|
95 | return m_maxX - m_minX; | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | qreal Domain::spanY() const |
|
98 | qreal Domain::spanY() const | |
99 | { |
|
99 | { | |
100 | Q_ASSERT(m_maxY >= m_minY); |
|
100 | Q_ASSERT(m_maxY >= m_minY); | |
101 | return m_maxY - m_minY; |
|
101 | return m_maxY - m_minY; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | bool Domain::isEmpty() const |
|
104 | bool Domain::isEmpty() const | |
105 | { |
|
105 | { | |
106 | return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY()); |
|
106 | return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY()); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void Domain::zoomIn(const QRectF& rect, const QSizeF& size) |
|
109 | void Domain::zoomIn(const QRectF& rect, const QSizeF& size) | |
110 | { |
|
110 | { | |
111 | qreal dx = spanX() / size.width(); |
|
111 | qreal dx = spanX() / size.width(); | |
112 | qreal dy = spanY() / size.height(); |
|
112 | qreal dy = spanY() / size.height(); | |
113 |
|
113 | |||
114 | qreal maxX = m_maxX; |
|
114 | qreal maxX = m_maxX; | |
115 | qreal minX = m_minX; |
|
115 | qreal minX = m_minX; | |
116 | qreal minY = m_minY; |
|
116 | qreal minY = m_minY; | |
117 | qreal maxY = m_maxY; |
|
117 | qreal maxY = m_maxY; | |
118 |
|
118 | |||
119 | maxX = minX + dx * rect.right(); |
|
119 | maxX = minX + dx * rect.right(); | |
120 | minX = minX + dx * rect.left(); |
|
120 | minX = minX + dx * rect.left(); | |
121 | minY = maxY - dy * rect.bottom(); |
|
121 | minY = maxY - dy * rect.bottom(); | |
122 | maxY = maxY - dy * rect.top(); |
|
122 | maxY = maxY - dy * rect.top(); | |
123 |
|
123 | |||
124 | setRange(minX,maxX,minY,maxY); |
|
124 | setRange(minX,maxX,minY,maxY); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void Domain::zoomOut(const QRectF& rect, const QSizeF& size) |
|
127 | void Domain::zoomOut(const QRectF& rect, const QSizeF& size) | |
128 | { |
|
128 | { | |
129 | qreal dx = spanX() / rect.width(); |
|
129 | qreal dx = spanX() / rect.width(); | |
130 | qreal dy = spanY() / rect.height(); |
|
130 | qreal dy = spanY() / rect.height(); | |
131 |
|
131 | |||
132 | qreal maxX = m_maxX; |
|
132 | qreal maxX = m_maxX; | |
133 | qreal minX = m_minX; |
|
133 | qreal minX = m_minX; | |
134 | qreal minY = m_minY; |
|
134 | qreal minY = m_minY; | |
135 | qreal maxY = m_maxY; |
|
135 | qreal maxY = m_maxY; | |
136 |
|
136 | |||
137 | minX = maxX - dx * rect.right(); |
|
137 | minX = maxX - dx * rect.right(); | |
138 | maxX = minX + dx * size.width(); |
|
138 | maxX = minX + dx * size.width(); | |
139 | maxY = minY + dy * rect.bottom(); |
|
139 | maxY = minY + dy * rect.bottom(); | |
140 | minY = maxY - dy * size.height(); |
|
140 | minY = maxY - dy * size.height(); | |
141 |
|
141 | |||
142 | setRange(minX,maxX,minY,maxY); |
|
142 | setRange(minX,maxX,minY,maxY); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void Domain::move(qreal dx,qreal dy,const QSizeF& size) |
|
145 | void Domain::move(qreal dx,qreal dy,const QSizeF& size) | |
146 | { |
|
146 | { | |
147 | qreal x = spanX() / size.width(); |
|
147 | qreal x = spanX() / size.width(); | |
148 | qreal y = spanY() / size.height(); |
|
148 | qreal y = spanY() / size.height(); | |
149 |
|
149 | |||
150 | qreal maxX = m_maxX; |
|
150 | qreal maxX = m_maxX; | |
151 | qreal minX = m_minX; |
|
151 | qreal minX = m_minX; | |
152 | qreal minY = m_minY; |
|
152 | qreal minY = m_minY; | |
153 | qreal maxY = m_maxY; |
|
153 | qreal maxY = m_maxY; | |
154 |
|
154 | |||
155 | if(dx!=0) { |
|
155 | if(dx!=0) { | |
156 | minX = minX + x * dx; |
|
156 | minX = minX + x * dx; | |
157 | maxX = maxX + x * dx; |
|
157 | maxX = maxX + x * dx; | |
158 | } |
|
158 | } | |
159 | if(dy!=0) { |
|
159 | if(dy!=0) { | |
160 | minY = minY + y * dy; |
|
160 | minY = minY + y * dy; | |
161 | maxY = maxY + y * dy; |
|
161 | maxY = maxY + y * dy; | |
162 | } |
|
162 | } | |
163 | setRange(minX,maxX,minY,maxY); |
|
163 | setRange(minX,maxX,minY,maxY); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void Domain::emitUpdated() |
|
166 | void Domain::emitUpdated() | |
167 | { |
|
167 | { | |
168 | emit updated(); |
|
168 | emit updated(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void Domain::handleAxisUpdated() |
|
171 | void Domain::handleAxisUpdated() | |
172 | { |
|
172 | { | |
173 | QAbstractAxisPrivate* axis = qobject_cast<QAbstractAxisPrivate*>(sender()); |
|
173 | QAbstractAxisPrivate* axis = qobject_cast<QAbstractAxisPrivate*>(sender()); | |
174 | Q_ASSERT(axis); |
|
174 | Q_ASSERT(axis); | |
175 | axis->setDirty(false); |
|
175 | axis->setDirty(false); | |
176 | if(axis->orientation()==Qt::Horizontal){ |
|
176 | if(axis->orientation()==Qt::Horizontal){ | |
177 | setRangeX(axis->min(),axis->max()); |
|
177 | setRangeX(axis->min(),axis->max()); | |
178 | }else if(axis->orientation()==Qt::Vertical){ |
|
178 | }else if(axis->orientation()==Qt::Vertical){ | |
179 | setRangeY(axis->min(),axis->max()); |
|
179 | setRangeY(axis->min(),axis->max()); | |
180 | } |
|
180 | } | |
181 |
|
||||
182 | } |
|
181 | } | |
183 |
|
182 | |||
184 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2) |
|
183 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2) | |
185 | { |
|
184 | { | |
186 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && |
|
185 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && | |
187 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && |
|
186 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && | |
188 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && |
|
187 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && | |
189 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
188 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); | |
190 | } |
|
189 | } | |
191 |
|
190 | |||
192 |
|
191 | |||
193 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2) |
|
192 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2) | |
194 | { |
|
193 | { | |
195 | return !(domain1 == domain2); |
|
194 | return !(domain1 == domain2); | |
196 | } |
|
195 | } | |
197 |
|
196 | |||
198 |
|
197 | |||
199 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain) |
|
198 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain) | |
200 | { |
|
199 | { | |
201 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')'; |
|
200 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')'; | |
202 | return dbg.maybeSpace(); |
|
201 | return dbg.maybeSpace(); | |
203 | } |
|
202 | } | |
204 |
|
203 | |||
205 | #include "moc_domain_p.cpp" |
|
204 | #include "moc_domain_p.cpp" | |
206 |
|
205 | |||
207 | QTCOMMERCIALCHART_END_NAMESPACE |
|
206 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,381 +1,389 | |||||
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 "legendlayout_p.h" |
|
21 | #include "legendlayout_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "legendmarker_p.h" |
|
23 | #include "legendmarker_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
|
25 | #include <QDebug> | |||
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
28 | LegendLayout::LegendLayout(QLegend* legend): |
|
29 | LegendLayout::LegendLayout(QLegend* legend): | |
29 | m_legend(legend) |
|
30 | m_legend(legend) | |
30 | { |
|
31 | { | |
31 |
|
32 | |||
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | LegendLayout::~LegendLayout() |
|
35 | LegendLayout::~LegendLayout() | |
35 | { |
|
36 | { | |
36 |
|
37 | |||
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | void LegendLayout::setOffset(qreal x, qreal y) |
|
40 | void LegendLayout::setOffset(qreal x, qreal y) | |
40 | { |
|
41 | { | |
41 | bool scrollHorizontal = true; |
|
42 | bool scrollHorizontal = true; | |
42 | switch(m_legend->alignment()) { |
|
43 | switch(m_legend->alignment()) { | |
43 | case Qt::AlignTop: |
|
44 | case Qt::AlignTop: | |
44 | case Qt::AlignBottom: { |
|
45 | case Qt::AlignBottom: { | |
45 | scrollHorizontal = true; |
|
46 | scrollHorizontal = true; | |
46 | break; |
|
47 | break; | |
47 | } |
|
48 | } | |
48 | case Qt::AlignLeft: |
|
49 | case Qt::AlignLeft: | |
49 | case Qt::AlignRight: { |
|
50 | case Qt::AlignRight: { | |
50 | scrollHorizontal = false; |
|
51 | scrollHorizontal = false; | |
51 | break; |
|
52 | break; | |
52 | } |
|
53 | } | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. |
|
56 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. | |
56 | if (!m_legend->isAttachedToChart()) { |
|
57 | if (!m_legend->isAttachedToChart()) { | |
57 | scrollHorizontal = !scrollHorizontal; |
|
58 | scrollHorizontal = !scrollHorizontal; | |
58 | } |
|
59 | } | |
59 |
|
60 | |||
60 | QRectF boundingRect = geometry(); |
|
61 | QRectF boundingRect = geometry(); | |
|
62 | qreal left, top, right, bottom; | |||
|
63 | getContentsMargins(&left, &top, &right, &bottom); | |||
|
64 | boundingRect.adjust(left,top,-right,-bottom); | |||
61 |
|
65 | |||
62 | // Limit offset between m_minOffset and m_maxOffset |
|
66 | // Limit offset between m_minOffset and m_maxOffset | |
63 | if (scrollHorizontal) { |
|
67 | if (scrollHorizontal) { | |
64 | if(m_width<=boundingRect.width()) return; |
|
68 | if(m_width<=boundingRect.width()) return; | |
65 |
|
69 | |||
66 | if (x != m_offsetX) { |
|
70 | if (x != m_offsetX) { | |
67 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); |
|
71 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); | |
68 | m_legend->d_ptr->items()->setPos(-m_offsetX,boundingRect.top()); |
|
72 | m_legend->d_ptr->items()->setPos(-m_offsetX,boundingRect.top()); | |
69 | } |
|
73 | } | |
70 | } |
|
74 | } | |
71 | else { |
|
75 | else { | |
72 | if(m_height<=boundingRect.height()) return; |
|
76 | if(m_height<=boundingRect.height()) return; | |
73 |
|
77 | |||
74 | if (y != m_offsetY) { |
|
78 | if (y != m_offsetY) { | |
75 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); |
|
79 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); | |
76 | m_legend->d_ptr->items()->setPos(boundingRect.left(),-m_offsetY); |
|
80 | m_legend->d_ptr->items()->setPos(boundingRect.left(),-m_offsetY); | |
77 | } |
|
81 | } | |
78 | } |
|
82 | } | |
79 | } |
|
83 | } | |
80 |
|
84 | |||
81 | QPointF LegendLayout::offset() const |
|
85 | QPointF LegendLayout::offset() const | |
82 | { |
|
86 | { | |
83 | return QPointF(m_offsetX,m_offsetY); |
|
87 | return QPointF(m_offsetX,m_offsetY); | |
84 | } |
|
88 | } | |
85 |
|
89 | |||
86 | void LegendLayout::setGeometry(const QRectF& rect) |
|
90 | void LegendLayout::setGeometry(const QRectF& rect) | |
87 | { |
|
91 | { | |
88 | m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); |
|
92 | m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); | |
89 |
|
93 | |||
90 | if(m_legend->isAttachedToChart()) { |
|
94 | if(m_legend->isAttachedToChart()) { | |
91 |
|
95 | |||
92 | setAttachedGeometry(rect); |
|
96 | setAttachedGeometry(rect); | |
93 | } |
|
97 | } | |
94 | else { |
|
98 | else { | |
95 | setDettachedGeometry(rect); |
|
99 | setDettachedGeometry(rect); | |
96 | } |
|
100 | } | |
97 |
|
101 | |||
98 | QGraphicsLayout::setGeometry(rect); |
|
102 | QGraphicsLayout::setGeometry(rect); | |
99 | } |
|
103 | } | |
100 |
|
104 | |||
101 | void LegendLayout::setAttachedGeometry(const QRectF& rect) |
|
105 | void LegendLayout::setAttachedGeometry(const QRectF& rect) | |
102 | { |
|
106 | { | |
103 | if (!rect.isValid()) return; |
|
107 | if (!rect.isValid()) return; | |
104 |
|
108 | |||
105 | m_offsetX=0; |
|
109 | m_offsetX=0; | |
106 | m_offsetY=0; |
|
110 | m_offsetY=0; | |
107 |
|
111 | |||
108 | QSizeF size(0,0); |
|
112 | QSizeF size(0,0); | |
109 |
|
113 | |||
110 | if( m_legend->d_ptr->markers().isEmpty()) return; |
|
114 | if( m_legend->d_ptr->markers().isEmpty()) return; | |
111 |
|
115 | |||
112 | m_width=0; |
|
116 | m_width=0; | |
113 | m_height=0; |
|
117 | m_height=0; | |
114 |
|
118 | |||
|
119 | qreal left, top, right, bottom; | |||
|
120 | getContentsMargins(&left, &top, &right, &bottom); | |||
|
121 | ||||
|
122 | QRectF geometry = rect.adjusted(left,top,-right,-bottom); | |||
|
123 | ||||
115 | switch(m_legend->alignment()) { |
|
124 | switch(m_legend->alignment()) { | |
116 |
|
125 | |||
117 | case Qt::AlignTop: |
|
126 | case Qt::AlignTop: | |
118 |
|
||||
119 | case Qt::AlignBottom: { |
|
127 | case Qt::AlignBottom: { | |
120 | QPointF point(0,0); |
|
128 | QPointF point(0,0); | |
121 | foreach (LegendMarker* marker, m_legend->d_ptr->markers()) { |
|
129 | foreach (LegendMarker* marker, m_legend->d_ptr->markers()) { | |
122 | if (marker->isVisible()) { |
|
130 | if (marker->isVisible()) { | |
123 | marker->setGeometry(QRectF(QPointF(0,0),marker->effectiveSizeHint(Qt::PreferredSize))); |
|
131 | marker->setGeometry(geometry); | |
124 |
marker->setPos(point.x(), |
|
132 | marker->setPos(point.x(),geometry.height()/2 - marker->boundingRect().height()/2); | |
125 | const QRectF& rect = marker->boundingRect(); |
|
133 | const QRectF& rect = marker->boundingRect(); | |
126 | size = size.expandedTo(rect.size()); |
|
134 | size = size.expandedTo(rect.size()); | |
127 | qreal w = rect.width(); |
|
135 | qreal w = rect.width(); | |
128 | m_width+=w; |
|
136 | m_width+=w; | |
129 | point.setX(point.x() + w); |
|
137 | point.setX(point.x() + w); | |
130 | } |
|
138 | } | |
131 | } |
|
139 | } | |
132 |
if(m_width< |
|
140 | if(m_width<geometry.width()) { | |
133 |
m_legend->d_ptr->items()->setPos( |
|
141 | m_legend->d_ptr->items()->setPos(geometry.width()/2-m_width/2,geometry.top()); | |
134 |
|
142 | |||
135 | } |
|
143 | } | |
136 | else { |
|
144 | else { | |
137 |
m_legend->d_ptr->items()->setPos( |
|
145 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
138 | } |
|
146 | } | |
139 | m_height=size.height(); |
|
147 | m_height=size.height(); | |
140 | } |
|
148 | } | |
141 | break; |
|
149 | break; | |
142 | case Qt::AlignLeft: |
|
150 | case Qt::AlignLeft: | |
143 | case Qt::AlignRight: { |
|
151 | case Qt::AlignRight: { | |
144 | QPointF point(0,0); |
|
152 | QPointF point(0,0); | |
145 | foreach (LegendMarker* marker, m_legend->d_ptr->markers()) { |
|
153 | foreach (LegendMarker* marker, m_legend->d_ptr->markers()) { | |
146 | if (marker->isVisible()) { |
|
154 | if (marker->isVisible()) { | |
147 | marker->setGeometry(QRectF(QPointF(0,0),marker->effectiveSizeHint(Qt::PreferredSize))); |
|
155 | marker->setGeometry(geometry); | |
148 | marker->setPos(point); |
|
156 | marker->setPos(point); | |
149 | const QRectF& rect = marker->boundingRect(); |
|
157 | const QRectF& rect = marker->boundingRect(); | |
150 | qreal h = rect.height(); |
|
158 | qreal h = rect.height(); | |
151 | size = size.expandedTo(rect.size()); |
|
159 | size = size.expandedTo(rect.size()); | |
152 | m_height+=h; |
|
160 | m_height+=h; | |
153 | point.setY(point.y() + h); |
|
161 | point.setY(point.y() + h); | |
154 | } |
|
162 | } | |
155 | } |
|
163 | } | |
156 |
if(m_height< |
|
164 | if(m_height<geometry.height()) { | |
157 |
m_legend->d_ptr->items()->setPos( |
|
165 | m_legend->d_ptr->items()->setPos(geometry.left(),geometry.height()/2-m_height/2); | |
158 | } |
|
166 | } | |
159 | else { |
|
167 | else { | |
160 |
m_legend->d_ptr->items()->setPos( |
|
168 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
161 | } |
|
169 | } | |
162 | m_width=size.width(); |
|
170 | m_width=size.width(); | |
163 | } |
|
171 | } | |
164 | break; |
|
172 | break; | |
165 | } |
|
173 | } | |
166 |
|
174 | |||
167 | m_minOffsetX = 0; |
|
175 | ||
168 |
m_minOffset |
|
176 | m_minOffsetX = -left; | |
169 | m_maxOffsetX = m_width - rect.width(); |
|
177 | m_minOffsetY = - top; | |
170 | m_maxOffsetY = m_height - rect.height(); |
|
178 | m_maxOffsetX = m_width - geometry.width() - right; | |
|
179 | m_maxOffsetY = m_height - geometry.height() - bottom; | |||
171 | } |
|
180 | } | |
172 |
|
181 | |||
173 | void LegendLayout::setDettachedGeometry(const QRectF& rect) |
|
182 | void LegendLayout::setDettachedGeometry(const QRectF& rect) | |
174 | { |
|
183 | { | |
175 | if (!rect.isValid()) return; |
|
184 | if (!rect.isValid()) return; | |
176 |
|
185 | |||
177 | // Detached layout is different. |
|
186 | // Detached layout is different. | |
178 | // In detached mode legend may have multiple rows and columns, so layout calculations |
|
187 | // In detached mode legend may have multiple rows and columns, so layout calculations | |
179 | // differ a log from attached mode. |
|
188 | // differ a log from attached mode. | |
180 | // Also the scrolling logic is bit different. |
|
189 | // Also the scrolling logic is bit different. | |
181 |
|
190 | |||
182 | m_offsetX=0; |
|
191 | m_offsetX=0; | |
183 | m_offsetY=0; |
|
192 | m_offsetY=0; | |
184 |
|
193 | |||
|
194 | qreal left, top, right, bottom; | |||
|
195 | getContentsMargins(&left, &top, &right, &bottom); | |||
|
196 | QRectF geometry = rect.adjusted(left,top,-right,-bottom); | |||
|
197 | ||||
185 | QSizeF size(0,0); |
|
198 | QSizeF size(0,0); | |
186 |
|
199 | |||
187 | QList<LegendMarker *> markers = m_legend->d_ptr->markers(); |
|
200 | QList<LegendMarker *> markers = m_legend->d_ptr->markers(); | |
188 |
|
201 | |||
189 | if(markers.isEmpty()) return; |
|
202 | if(markers.isEmpty()) return; | |
190 |
|
203 | |||
191 | switch (m_legend->alignment()) { |
|
204 | switch (m_legend->alignment()) { | |
192 | case Qt::AlignTop: { |
|
205 | case Qt::AlignTop: { | |
193 |
QPointF point |
|
206 | QPointF point(0,0); | |
194 | m_width = 0; |
|
207 | m_width = 0; | |
195 | m_height = 0; |
|
208 | m_height = 0; | |
196 | for (int i=0; i<markers.count(); i++) { |
|
209 | for (int i=0; i<markers.count(); i++) { | |
197 | LegendMarker *marker = markers.at(i); |
|
210 | LegendMarker *marker = markers.at(i); | |
198 | if (marker->isVisible()) { |
|
211 | if (marker->isVisible()) { | |
199 | marker->setGeometry(QRectF(QPointF(0,0),marker->effectiveSizeHint(Qt::PreferredSize))); |
|
212 | marker->setGeometry(geometry); | |
200 | marker->setPos(point.x(),point.y()); |
|
213 | marker->setPos(point.x(),point.y()); | |
201 | const QRectF& boundingRect = marker->boundingRect(); |
|
214 | const QRectF& boundingRect = marker->boundingRect(); | |
202 | qreal w = boundingRect.width(); |
|
215 | qreal w = boundingRect.width(); | |
203 | qreal h = boundingRect.height(); |
|
216 | qreal h = boundingRect.height(); | |
204 | m_width = qMax(m_width,w); |
|
217 | m_width = qMax(m_width,w); | |
205 | m_height = qMax(m_height,h); |
|
218 | m_height = qMax(m_height,h); | |
206 | point.setX(point.x() + w); |
|
219 | point.setX(point.x() + w); | |
207 |
if (point.x() + w > |
|
220 | if (point.x() + w > geometry.left() + geometry.width() - right) { | |
208 | // Next item would go off rect. |
|
221 | // Next item would go off rect. | |
209 |
point.setX( |
|
222 | point.setX(0); | |
210 | point.setY(point.y() + h); |
|
223 | point.setY(point.y() + h); | |
211 | if (i+1 < markers.count()) { |
|
224 | if (i+1 < markers.count()) { | |
212 | m_height += h; |
|
225 | m_height += h; | |
213 | } |
|
226 | } | |
214 | } |
|
227 | } | |
215 | } |
|
228 | } | |
216 | } |
|
229 | } | |
217 |
m_legend->d_ptr->items()->setPos( |
|
230 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
218 |
|
231 | |||
219 |
m_minOffsetX = |
|
232 | m_minOffsetX = -left; | |
220 |
m_minOffsetY = |
|
233 | m_minOffsetY = -top; | |
221 |
m_maxOffsetX = m_width - |
|
234 | m_maxOffsetX = m_width - geometry.width() - right; | |
222 |
m_maxOffsetY = m_height - |
|
235 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
223 | } |
|
236 | } | |
224 | break; |
|
237 | break; | |
225 | case Qt::AlignBottom: { |
|
238 | case Qt::AlignBottom: { | |
226 |
QPointF point |
|
239 | QPointF point(0,geometry.height()); | |
227 | m_width = 0; |
|
240 | m_width = 0; | |
228 | m_height = 0; |
|
241 | m_height = 0; | |
229 | for (int i=0; i<markers.count(); i++) { |
|
242 | for (int i=0; i<markers.count(); i++) { | |
230 | LegendMarker *marker = markers.at(i); |
|
243 | LegendMarker *marker = markers.at(i); | |
231 | if (marker->isVisible()) { |
|
244 | if (marker->isVisible()) { | |
232 | marker->setGeometry(QRectF(QPointF(0,0),marker->effectiveSizeHint(Qt::PreferredSize))); |
|
245 | marker->setGeometry(geometry); | |
233 | const QRectF& boundingRect = marker->boundingRect(); |
|
246 | const QRectF& boundingRect = marker->boundingRect(); | |
234 | qreal w = boundingRect.width(); |
|
247 | qreal w = boundingRect.width(); | |
235 | qreal h = boundingRect.height(); |
|
248 | qreal h = boundingRect.height(); | |
236 | m_width = qMax(m_width,w); |
|
249 | m_width = qMax(m_width,w); | |
237 | m_height = qMax(m_height,h); |
|
250 | m_height = qMax(m_height,h); | |
238 | marker->setPos(point.x(),point.y() - h); |
|
251 | marker->setPos(point.x(),point.y() - h); | |
239 | point.setX(point.x() + w); |
|
252 | point.setX(point.x() + w); | |
240 |
if (point.x() + w > |
|
253 | if (point.x() + w > geometry.left() + geometry.width() - right) { | |
241 | // Next item would go off rect. |
|
254 | // Next item would go off rect. | |
242 |
point.setX( |
|
255 | point.setX(0); | |
243 | point.setY(point.y() - h); |
|
256 | point.setY(point.y() - h); | |
244 | if (i+1 < markers.count()) { |
|
257 | if (i+1 < markers.count()) { | |
245 | m_height += h; |
|
258 | m_height += h; | |
246 | } |
|
259 | } | |
247 | } |
|
260 | } | |
248 | } |
|
261 | } | |
249 | } |
|
262 | } | |
250 |
m_legend->d_ptr->items()->setPos( |
|
263 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
251 |
|
264 | |||
252 |
m_minOffsetX = |
|
265 | m_minOffsetX = -left; | |
253 |
m_minOffsetY = |
|
266 | m_minOffsetY = -m_height + geometry.height() - top; | |
254 |
m_maxOffsetX = m_width - |
|
267 | m_maxOffsetX = m_width - geometry.width() - right; | |
255 |
m_maxOffsetY = |
|
268 | m_maxOffsetY = -bottom; | |
256 | } |
|
269 | } | |
257 | break; |
|
270 | break; | |
258 | case Qt::AlignLeft: { |
|
271 | case Qt::AlignLeft: { | |
259 |
QPointF point |
|
272 | QPointF point(0,0); | |
260 | m_width = 0; |
|
273 | m_width = 0; | |
261 | m_height = 0; |
|
274 | m_height = 0; | |
262 | qreal maxWidth = 0; |
|
275 | qreal maxWidth = 0; | |
263 | for (int i=0; i<markers.count(); i++) { |
|
276 | for (int i=0; i<markers.count(); i++) { | |
264 | LegendMarker *marker = markers.at(i); |
|
277 | LegendMarker *marker = markers.at(i); | |
265 | if (marker->isVisible()) { |
|
278 | if (marker->isVisible()) { | |
266 | marker->setGeometry(QRectF(QPointF(0,0),marker->effectiveSizeHint(Qt::PreferredSize))); |
|
279 | marker->setGeometry(geometry); | |
267 | const QRectF& boundingRect = marker->boundingRect(); |
|
280 | const QRectF& boundingRect = marker->boundingRect(); | |
268 | qreal w = boundingRect.width(); |
|
281 | qreal w = boundingRect.width(); | |
269 | qreal h = boundingRect.height(); |
|
282 | qreal h = boundingRect.height(); | |
270 | m_height = qMax(m_height,h); |
|
283 | m_height = qMax(m_height,h); | |
271 | maxWidth = qMax(maxWidth,w); |
|
284 | maxWidth = qMax(maxWidth,w); | |
272 | marker->setPos(point.x(),point.y()); |
|
285 | marker->setPos(point.x(),point.y()); | |
273 | point.setY(point.y() + h); |
|
286 | point.setY(point.y() + h); | |
274 |
if (point.y() + h > |
|
287 | if (point.y() + h > geometry.bottom() - bottom) { | |
275 | // Next item would go off rect. |
|
288 | // Next item would go off rect. | |
276 | point.setX(point.x() + maxWidth); |
|
289 | point.setX(point.x() + maxWidth); | |
277 |
point.setY( |
|
290 | point.setY(0); | |
278 | if (i+1 < markers.count()) { |
|
291 | if (i+1 < markers.count()) { | |
279 | m_width += maxWidth; |
|
292 | m_width += maxWidth; | |
280 | maxWidth = 0; |
|
293 | maxWidth = 0; | |
281 | } |
|
294 | } | |
282 | } |
|
295 | } | |
283 | } |
|
296 | } | |
284 | } |
|
297 | } | |
285 | m_width += maxWidth; |
|
298 | m_width += maxWidth; | |
286 |
m_legend->d_ptr->items()->setPos( |
|
299 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
287 |
|
300 | |||
288 |
m_minOffsetX = |
|
301 | m_minOffsetX = -left; | |
289 |
m_minOffsetY = |
|
302 | m_minOffsetY = -top; | |
290 |
m_maxOffsetX = m_width - |
|
303 | m_maxOffsetX = m_width - geometry.width() - right; | |
291 |
m_maxOffsetY = m_height - |
|
304 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
292 | } |
|
305 | } | |
293 | break; |
|
306 | break; | |
294 | case Qt::AlignRight: { |
|
307 | case Qt::AlignRight: { | |
295 |
QPointF point |
|
308 | QPointF point(geometry.width(),0); | |
296 | m_width = 0; |
|
309 | m_width = 0; | |
297 | m_height = 0; |
|
310 | m_height = 0; | |
298 | qreal maxWidth = 0; |
|
311 | qreal maxWidth = 0; | |
299 | for (int i=0; i<markers.count(); i++) { |
|
312 | for (int i=0; i<markers.count(); i++) { | |
300 | LegendMarker *marker = markers.at(i); |
|
313 | LegendMarker *marker = markers.at(i); | |
301 | if (marker->isVisible()) { |
|
314 | if (marker->isVisible()) { | |
302 | marker->setGeometry(QRectF(QPointF(0,0),marker->effectiveSizeHint(Qt::PreferredSize))); |
|
315 | marker->setGeometry(geometry); | |
303 | const QRectF& boundingRect = marker->boundingRect(); |
|
316 | const QRectF& boundingRect = marker->boundingRect(); | |
304 | qreal w = boundingRect.width(); |
|
317 | qreal w = boundingRect.width(); | |
305 | qreal h = boundingRect.height(); |
|
318 | qreal h = boundingRect.height(); | |
306 | m_height = qMax(m_height,h); |
|
319 | m_height = qMax(m_height,h); | |
307 | maxWidth = qMax(maxWidth,w); |
|
320 | maxWidth = qMax(maxWidth,w); | |
308 | marker->setPos(point.x() - w,point.y()); |
|
321 | marker->setPos(point.x() - w,point.y()); | |
309 | point.setY(point.y() + h); |
|
322 | point.setY(point.y() + h); | |
310 |
if (point.y() + h > |
|
323 | if (point.y() + h > geometry.bottom()-bottom) { | |
311 | // Next item would go off rect. |
|
324 | // Next item would go off rect. | |
312 | point.setX(point.x() - maxWidth); |
|
325 | point.setX(point.x() - maxWidth); | |
313 |
point.setY( |
|
326 | point.setY(0); | |
314 | if (i+1 < markers.count()) { |
|
327 | if (i+1 < markers.count()) { | |
315 | m_width += maxWidth; |
|
328 | m_width += maxWidth; | |
316 | maxWidth = 0; |
|
329 | maxWidth = 0; | |
317 | } |
|
330 | } | |
318 | } |
|
331 | } | |
319 | } |
|
332 | } | |
320 | } |
|
333 | } | |
321 | m_width += maxWidth; |
|
334 | m_width += maxWidth; | |
322 |
m_legend->d_ptr->items()->setPos( |
|
335 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
323 |
|
336 | |||
324 |
m_minOffsetX = |
|
337 | m_minOffsetX = - m_width + geometry.width() - left; | |
325 |
m_minOffsetY = |
|
338 | m_minOffsetY = -top; | |
326 |
m_maxOffsetX = |
|
339 | m_maxOffsetX = - right; | |
327 |
m_maxOffsetY = m_height - |
|
340 | m_maxOffsetY = m_height - geometry.height() - bottom; | |
328 | } |
|
341 | } | |
329 | break; |
|
342 | break; | |
330 | default: |
|
343 | default: | |
331 | break; |
|
344 | break; | |
332 | } |
|
345 | } | |
333 |
|
346 | |||
334 | } |
|
347 | } | |
335 |
|
348 | |||
336 | QSizeF LegendLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const |
|
349 | QSizeF LegendLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const | |
337 | { |
|
350 | { | |
338 | QSizeF size(0, 0); |
|
351 | QSizeF size(0, 0); | |
339 | qreal left, top, right, bottom; |
|
352 | qreal left, top, right, bottom; | |
340 | getContentsMargins(&left, &top, &right, &bottom); |
|
353 | getContentsMargins(&left, &top, &right, &bottom); | |
341 |
|
354 | |||
342 | if(which!=Qt::PreferredSize) return QSizeF(-1,-1); |
|
|||
343 |
|
||||
344 | if(constraint.isValid()) { |
|
355 | if(constraint.isValid()) { | |
345 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { |
|
356 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { | |
346 | size = size.expandedTo(marker->effectiveSizeHint(which)); |
|
357 | size = size.expandedTo(marker->effectiveSizeHint(which)); | |
347 | } |
|
358 | } | |
348 | size = size.boundedTo(constraint); |
|
359 | size = size.boundedTo(constraint); | |
349 | } |
|
360 | } | |
350 | else if (constraint.width() >= 0) { |
|
361 | else if (constraint.width() >= 0) { | |
351 | qreal width = 0; |
|
362 | qreal width = 0; | |
352 | qreal height = 0; |
|
363 | qreal height = 0; | |
353 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { |
|
364 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { | |
354 | width+=marker->effectiveSizeHint(which).width(); |
|
365 | width+=marker->effectiveSizeHint(which).width(); | |
355 | height=qMax(height,marker->effectiveSizeHint(which).height()); |
|
366 | height=qMax(height,marker->effectiveSizeHint(which).height()); | |
356 | } |
|
367 | } | |
357 |
|
368 | |||
358 | size = QSizeF(qMin(constraint.width(),width), height); |
|
369 | size = QSizeF(qMin(constraint.width(),width), height); | |
359 | } |
|
370 | } | |
360 | else if (constraint.height() >= 0) { |
|
371 | else if (constraint.height() >= 0) { | |
361 | qreal width = 0; |
|
372 | qreal width = 0; | |
362 | qreal height = 0; |
|
373 | qreal height = 0; | |
363 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { |
|
374 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { | |
364 | width=qMax(width,marker->effectiveSizeHint(which).width()); |
|
375 | width=qMax(width,marker->effectiveSizeHint(which).width()); | |
365 | height+=height,marker->effectiveSizeHint(which).height(); |
|
376 | height+=height,marker->effectiveSizeHint(which).height(); | |
366 | } |
|
377 | } | |
367 | size = QSizeF(width,qMin(constraint.height(),height)); |
|
378 | size = QSizeF(width,qMin(constraint.height(),height)); | |
368 | } |
|
379 | } | |
369 | else { |
|
380 | else { | |
370 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { |
|
381 | foreach(LegendMarker* marker, m_legend->d_ptr->markers()) { | |
371 | size = size.expandedTo(marker->effectiveSizeHint(which)); |
|
382 | size = size.expandedTo(marker->effectiveSizeHint(which)); | |
372 | } |
|
383 | } | |
373 | } |
|
384 | } | |
374 | size += QSize(left + right, top + bottom); |
|
385 | size += QSize(left + right, top + bottom); | |
375 |
|
||||
376 | return size; |
|
386 | return size; | |
377 |
|
||||
378 |
|
||||
379 | } |
|
387 | } | |
380 |
|
388 | |||
381 | QTCOMMERCIALCHART_END_NAMESPACE |
|
389 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,236 +1,253 | |||||
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 "legendmarker_p.h" |
|
21 | #include "legendmarker_p.h" | |
22 | #include "qxyseries.h" |
|
22 | #include "qxyseries.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include "qlegend.h" |
|
24 | #include "qlegend.h" | |
25 | #include "qabstractbarseries.h" |
|
25 | #include "qabstractbarseries.h" | |
26 | #include "qpieseries.h" |
|
26 | #include "qpieseries.h" | |
27 | #include "qpieslice.h" |
|
27 | #include "qpieslice.h" | |
28 | #include "qbarset.h" |
|
28 | #include "qbarset.h" | |
29 | #include "qbarset_p.h" |
|
29 | #include "qbarset_p.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qareaseries_p.h" |
|
31 | #include "qareaseries_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 | #include <QGraphicsSceneEvent> |
|
33 | #include <QGraphicsSceneEvent> | |
34 | #include <QGraphicsSimpleTextItem> |
|
34 | #include <QGraphicsSimpleTextItem> | |
35 | #include <QDebug> |
|
35 | #include <QDebug> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : |
|
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : | |
40 | QGraphicsObject(legend), |
|
40 | QGraphicsObject(legend), | |
41 | m_series(series), |
|
41 | m_series(series), | |
42 | m_markerRect(0,0,10.0,10.0), |
|
42 | m_markerRect(0,0,10.0,10.0), | |
43 | m_boundingRect(0,0,0,0), |
|
43 | m_boundingRect(0,0,0,0), | |
44 | m_legend(legend), |
|
44 | m_legend(legend), | |
45 | m_textItem(new QGraphicsSimpleTextItem(this)), |
|
45 | m_textItem(new QGraphicsSimpleTextItem(this)), | |
46 | m_rectItem(new QGraphicsRectItem(this)), |
|
46 | m_rectItem(new QGraphicsRectItem(this)), | |
47 |
m_margin( |
|
47 | m_margin(4), | |
48 | m_space(4) |
|
48 | m_space(4) | |
49 | { |
|
49 | { | |
50 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
50 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
51 | m_rectItem->setRect(m_markerRect); |
|
51 | m_rectItem->setRect(m_markerRect); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void LegendMarker::setPen(const QPen &pen) |
|
54 | void LegendMarker::setPen(const QPen &pen) | |
55 | { |
|
55 | { | |
56 | m_rectItem->setPen(pen); |
|
56 | m_rectItem->setPen(pen); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QPen LegendMarker::pen() const |
|
59 | QPen LegendMarker::pen() const | |
60 | { |
|
60 | { | |
61 | return m_rectItem->pen(); |
|
61 | return m_rectItem->pen(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void LegendMarker::setBrush(const QBrush &brush) |
|
64 | void LegendMarker::setBrush(const QBrush &brush) | |
65 | { |
|
65 | { | |
66 | m_rectItem->setBrush(brush); |
|
66 | m_rectItem->setBrush(brush); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | QBrush LegendMarker::brush() const |
|
69 | QBrush LegendMarker::brush() const | |
70 | { |
|
70 | { | |
71 | return m_rectItem->brush(); |
|
71 | return m_rectItem->brush(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void LegendMarker::setFont(const QFont &font) |
|
74 | void LegendMarker::setFont(const QFont &font) | |
75 | { |
|
75 | { | |
76 | m_textItem->setFont(font); |
|
76 | m_textItem->setFont(font); | |
77 | QFontMetrics fn(font); |
|
77 | QFontMetrics fn(font); | |
78 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); |
|
78 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); | |
79 | updateGeometry(); |
|
79 | updateGeometry(); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | QFont LegendMarker::font() const |
|
82 | QFont LegendMarker::font() const | |
83 | { |
|
83 | { | |
84 | return m_textItem->font(); |
|
84 | return m_textItem->font(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void LegendMarker::setLabel(const QString label) |
|
87 | void LegendMarker::setLabel(const QString label) | |
88 | { |
|
88 | { | |
89 |
m_text |
|
89 | m_text = label; | |
|
90 | updateGeometry(); | |||
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | QString LegendMarker::label() const |
|
93 | QString LegendMarker::label() const | |
93 | { |
|
94 | { | |
94 |
return m_text |
|
95 | return m_text; | |
95 | } |
|
96 | } | |
96 |
|
97 | |||
97 | QRectF LegendMarker::boundingRect() const |
|
98 | QRectF LegendMarker::boundingRect() const | |
98 | { |
|
99 | { | |
99 | return m_boundingRect; |
|
100 | return m_boundingRect; | |
100 | } |
|
101 | } | |
101 |
|
102 | |||
102 | void LegendMarker::setLabelBrush(const QBrush &brush) |
|
103 | void LegendMarker::setLabelBrush(const QBrush &brush) | |
103 | { |
|
104 | { | |
104 | m_textItem->setBrush(brush); |
|
105 | m_textItem->setBrush(brush); | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | QBrush LegendMarker::labelBrush() const |
|
108 | QBrush LegendMarker::labelBrush() const | |
108 | { |
|
109 | { | |
109 | return m_textItem->brush(); |
|
110 | return m_textItem->brush(); | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 |
|
113 | |||
113 | void LegendMarker::setGeometry(const QRectF& rect) |
|
114 | void LegendMarker::setGeometry(const QRectF& rect) | |
114 | { |
|
115 | { | |
|
116 | QFontMetrics fn (font()); | |||
|
117 | ||||
|
118 | int width = rect.width(); | |||
|
119 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; | |||
|
120 | qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin); | |||
|
121 | ||||
|
122 | if (fn.boundingRect(m_text).width() + x > width) | |||
|
123 | { | |||
|
124 | QString string = m_text + "..."; | |||
|
125 | while(fn.boundingRect(string).width() + x > width && string.length() > 3) | |||
|
126 | string.remove(string.length() - 4, 1); | |||
|
127 | m_textItem->setText(string); | |||
|
128 | } | |||
|
129 | else | |||
|
130 | m_textItem->setText(m_text); | |||
|
131 | ||||
115 | const QRectF& textRect = m_textItem->boundingRect(); |
|
132 | const QRectF& textRect = m_textItem->boundingRect(); | |
116 |
|
133 | |||
117 | m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2); |
|
134 | ||
|
135 | m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); | |||
118 | m_rectItem->setRect(m_markerRect); |
|
136 | m_rectItem->setRect(m_markerRect); | |
119 |
m_rectItem->setPos(m_margin, |
|
137 | m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2); | |
120 |
|
138 | |||
121 | prepareGeometryChange(); |
|
139 | prepareGeometryChange(); | |
122 | m_boundingRect = rect; |
|
140 | m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y); | |
123 | } |
|
141 | } | |
124 |
|
142 | |||
125 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
143 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
126 | { |
|
144 | { | |
127 | Q_UNUSED(option) |
|
145 | Q_UNUSED(option) | |
128 | Q_UNUSED(widget) |
|
146 | Q_UNUSED(widget) | |
129 | Q_UNUSED(painter) |
|
147 | Q_UNUSED(painter) | |
130 | } |
|
148 | } | |
131 |
|
149 | |||
132 |
|
||||
133 | QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
150 | QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
134 | { |
|
151 | { | |
135 | Q_UNUSED(constraint) |
|
152 | Q_UNUSED(constraint) | |
136 |
|
153 | |||
137 | QFontMetrics fn(m_textItem->font()); |
|
154 | QFontMetrics fn(m_textItem->font()); | |
138 | QSizeF sh; |
|
155 | QSizeF sh; | |
139 |
|
156 | |||
140 | switch (which) { |
|
157 | switch (which) { | |
141 | case Qt::MinimumSize: |
|
158 | case Qt::MinimumSize: | |
142 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); |
|
159 | sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |
143 | break; |
|
160 | break; | |
144 | case Qt::PreferredSize: |
|
161 | case Qt::PreferredSize: | |
145 |
sh = QSizeF(fn.boundingRect(m_text |
|
162 | sh = QSizeF(fn.boundingRect(m_text).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |
146 | break; |
|
163 | break; | |
147 | default: |
|
164 | default: | |
148 | break; |
|
165 | break; | |
149 | } |
|
166 | } | |
150 |
|
167 | |||
151 | return sh; |
|
168 | return sh; | |
152 | } |
|
169 | } | |
153 |
|
170 | |||
154 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
171 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
155 | { |
|
172 | { | |
156 | QGraphicsObject::mousePressEvent(event); |
|
173 | QGraphicsObject::mousePressEvent(event); | |
157 |
|
|
174 | //TODO: selected signal removed for now | |
158 | } |
|
175 | } | |
159 |
|
176 | |||
160 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
161 |
|
178 | |||
162 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), |
|
179 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), | |
163 | m_series(series) |
|
180 | m_series(series) | |
164 | { |
|
181 | { | |
165 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
182 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
166 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
183 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
167 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
184 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
168 | updated(); |
|
185 | updated(); | |
169 | } |
|
186 | } | |
170 |
|
187 | |||
171 | void AreaLegendMarker::updated() |
|
188 | void AreaLegendMarker::updated() | |
172 | { |
|
189 | { | |
173 | setBrush(m_series->brush()); |
|
190 | setBrush(m_series->brush()); | |
174 | setLabel(m_series->name()); |
|
191 | setLabel(m_series->name()); | |
175 | } |
|
192 | } | |
176 |
|
193 | |||
177 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
178 |
|
195 | |||
179 | BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), |
|
196 | BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), | |
180 | m_barset(barset) |
|
197 | m_barset(barset) | |
181 | { |
|
198 | { | |
182 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); |
|
199 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); | |
183 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); |
|
200 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); | |
184 | updated(); |
|
201 | updated(); | |
185 | } |
|
202 | } | |
186 |
|
203 | |||
187 | void BarLegendMarker::updated() |
|
204 | void BarLegendMarker::updated() | |
188 | { |
|
205 | { | |
189 | setBrush(m_barset->brush()); |
|
206 | setBrush(m_barset->brush()); | |
190 | setLabel(m_barset->label()); |
|
207 | setLabel(m_barset->label()); | |
191 | } |
|
208 | } | |
192 |
|
209 | |||
193 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
210 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
194 |
|
211 | |||
195 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), |
|
212 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), | |
196 | m_pieslice(pieslice) |
|
213 | m_pieslice(pieslice) | |
197 | { |
|
214 | { | |
198 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
215 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
199 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
216 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
200 | updated(); |
|
217 | updated(); | |
201 | } |
|
218 | } | |
202 |
|
219 | |||
203 | void PieLegendMarker::updated() |
|
220 | void PieLegendMarker::updated() | |
204 | { |
|
221 | { | |
205 | setBrush(m_pieslice->brush()); |
|
222 | setBrush(m_pieslice->brush()); | |
206 | setLabel(m_pieslice->label()); |
|
223 | setLabel(m_pieslice->label()); | |
207 | } |
|
224 | } | |
208 |
|
225 | |||
209 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
226 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
210 |
|
227 | |||
211 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), |
|
228 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), | |
212 | m_series(series) |
|
229 | m_series(series) | |
213 | { |
|
230 | { | |
214 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
231 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
215 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
232 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
216 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
233 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
217 | updated(); |
|
234 | updated(); | |
218 | } |
|
235 | } | |
219 |
|
236 | |||
220 | void XYLegendMarker::updated() |
|
237 | void XYLegendMarker::updated() | |
221 | { |
|
238 | { | |
222 | setLabel(m_series->name()); |
|
239 | setLabel(m_series->name()); | |
223 |
|
240 | |||
224 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) |
|
241 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) | |
225 | { |
|
242 | { | |
226 | setBrush(m_series->brush()); |
|
243 | setBrush(m_series->brush()); | |
227 |
|
244 | |||
228 | } |
|
245 | } | |
229 | else { |
|
246 | else { | |
230 | setBrush(QBrush(m_series->pen().color())); |
|
247 | setBrush(QBrush(m_series->pen().color())); | |
231 | } |
|
248 | } | |
232 | } |
|
249 | } | |
233 |
|
250 | |||
234 | #include "moc_legendmarker_p.cpp" |
|
251 | #include "moc_legendmarker_p.cpp" | |
235 |
|
252 | |||
236 | QTCOMMERCIALCHART_END_NAMESPACE |
|
253 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,144 +1,145 | |||||
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 LEGENDMARKER_P_H |
|
30 | #ifndef LEGENDMARKER_P_H | |
31 | #define LEGENDMARKER_P_H |
|
31 | #define LEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QGraphicsObject> |
|
34 | #include <QGraphicsObject> | |
35 | #include <QBrush> |
|
35 | #include <QBrush> | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QGraphicsSimpleTextItem> |
|
37 | #include <QGraphicsSimpleTextItem> | |
38 | #include <QGraphicsLayoutItem> |
|
38 | #include <QGraphicsLayoutItem> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class QAbstractSeries; |
|
42 | class QAbstractSeries; | |
43 | class QAreaSeries; |
|
43 | class QAreaSeries; | |
44 | class QXYSeries; |
|
44 | class QXYSeries; | |
45 | class QBarSet; |
|
45 | class QBarSet; | |
46 | class QAbstractBarSeries; |
|
46 | class QAbstractBarSeries; | |
47 | class QPieSlice; |
|
47 | class QPieSlice; | |
48 | class QLegend; |
|
48 | class QLegend; | |
49 | class QPieSeries; |
|
49 | class QPieSeries; | |
50 |
|
50 | |||
51 | class LegendMarker : public QGraphicsObject, public QGraphicsLayoutItem |
|
51 | class LegendMarker : public QGraphicsObject, public QGraphicsLayoutItem | |
52 | { |
|
52 | { | |
53 | Q_OBJECT |
|
53 | Q_OBJECT | |
54 | Q_INTERFACES(QGraphicsLayoutItem) |
|
54 | Q_INTERFACES(QGraphicsLayoutItem) | |
55 | public: |
|
55 | public: | |
56 | explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent); |
|
56 | explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent); | |
57 |
|
57 | |||
58 | void setPen(const QPen &pen); |
|
58 | void setPen(const QPen &pen); | |
59 | QPen pen() const; |
|
59 | QPen pen() const; | |
60 |
|
60 | |||
61 | void setBrush(const QBrush &brush); |
|
61 | void setBrush(const QBrush &brush); | |
62 | QBrush brush() const; |
|
62 | QBrush brush() const; | |
63 |
|
63 | |||
64 | void setFont(const QFont &font); |
|
64 | void setFont(const QFont &font); | |
65 | QFont font() const; |
|
65 | QFont font() const; | |
66 |
|
66 | |||
67 | void setLabel(const QString label); |
|
67 | void setLabel(const QString label); | |
68 | QString label() const; |
|
68 | QString label() const; | |
69 |
|
69 | |||
70 | void setLabelBrush(const QBrush &brush); |
|
70 | void setLabelBrush(const QBrush &brush); | |
71 | QBrush labelBrush() const; |
|
71 | QBrush labelBrush() const; | |
72 |
|
72 | |||
73 | QAbstractSeries *series() const { return m_series;} |
|
73 | QAbstractSeries *series() const { return m_series;} | |
74 |
|
74 | |||
75 | void setGeometry(const QRectF& rect); |
|
75 | void setGeometry(const QRectF& rect); | |
76 |
|
76 | |||
77 | QRectF boundingRect() const; |
|
77 | QRectF boundingRect() const; | |
78 |
|
78 | |||
79 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
79 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
80 |
|
80 | |||
81 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; |
|
81 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; | |
82 |
|
82 | |||
83 | protected: |
|
83 | protected: | |
84 | // From QGraphicsObject |
|
84 | // From QGraphicsObject | |
85 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
85 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
86 |
|
86 | |||
87 | public Q_SLOTS: |
|
87 | public Q_SLOTS: | |
88 | virtual void updated() = 0; |
|
88 | virtual void updated() = 0; | |
89 |
|
89 | |||
90 | protected: |
|
90 | protected: | |
91 | QAbstractSeries *m_series; |
|
91 | QAbstractSeries *m_series; | |
92 | QRectF m_markerRect; |
|
92 | QRectF m_markerRect; | |
93 | QRectF m_boundingRect; |
|
93 | QRectF m_boundingRect; | |
94 | QLegend* m_legend; |
|
94 | QLegend* m_legend; | |
95 | QGraphicsSimpleTextItem *m_textItem; |
|
95 | QGraphicsSimpleTextItem *m_textItem; | |
96 | QGraphicsRectItem *m_rectItem; |
|
96 | QGraphicsRectItem *m_rectItem; | |
97 | qreal m_margin; |
|
97 | qreal m_margin; | |
98 | qreal m_space; |
|
98 | qreal m_space; | |
|
99 | QString m_text; | |||
99 |
|
100 | |||
100 | }; |
|
101 | }; | |
101 |
|
102 | |||
102 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
103 | class XYLegendMarker : public LegendMarker |
|
104 | class XYLegendMarker : public LegendMarker | |
104 | { |
|
105 | { | |
105 | public: |
|
106 | public: | |
106 | XYLegendMarker(QXYSeries *series, QLegend *legend); |
|
107 | XYLegendMarker(QXYSeries *series, QLegend *legend); | |
107 | protected: |
|
108 | protected: | |
108 | void updated(); |
|
109 | void updated(); | |
109 | private: |
|
110 | private: | |
110 | QXYSeries *m_series; |
|
111 | QXYSeries *m_series; | |
111 | }; |
|
112 | }; | |
112 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
113 | class AreaLegendMarker : public LegendMarker |
|
114 | class AreaLegendMarker : public LegendMarker | |
114 | { |
|
115 | { | |
115 | public: |
|
116 | public: | |
116 | AreaLegendMarker(QAreaSeries *series, QLegend *legend); |
|
117 | AreaLegendMarker(QAreaSeries *series, QLegend *legend); | |
117 | protected: |
|
118 | protected: | |
118 | void updated(); |
|
119 | void updated(); | |
119 | private: |
|
120 | private: | |
120 | QAreaSeries *m_series; |
|
121 | QAreaSeries *m_series; | |
121 | }; |
|
122 | }; | |
122 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
123 | class BarLegendMarker : public LegendMarker |
|
124 | class BarLegendMarker : public LegendMarker | |
124 | { |
|
125 | { | |
125 | public: |
|
126 | public: | |
126 | BarLegendMarker(QAbstractBarSeries *barseries, QBarSet *barset,QLegend *legend); |
|
127 | BarLegendMarker(QAbstractBarSeries *barseries, QBarSet *barset,QLegend *legend); | |
127 | protected: |
|
128 | protected: | |
128 | void updated(); |
|
129 | void updated(); | |
129 | private: |
|
130 | private: | |
130 | QBarSet *m_barset; |
|
131 | QBarSet *m_barset; | |
131 | }; |
|
132 | }; | |
132 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
133 | class PieLegendMarker : public LegendMarker |
|
134 | class PieLegendMarker : public LegendMarker | |
134 | { |
|
135 | { | |
135 | public: |
|
136 | public: | |
136 | PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend); |
|
137 | PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend); | |
137 | protected: |
|
138 | protected: | |
138 | void updated(); |
|
139 | void updated(); | |
139 | private: |
|
140 | private: | |
140 | QPieSlice *m_pieslice; |
|
141 | QPieSlice *m_pieslice; | |
141 | }; |
|
142 | }; | |
142 |
|
143 | |||
143 | QTCOMMERCIALCHART_END_NAMESPACE |
|
144 | QTCOMMERCIALCHART_END_NAMESPACE | |
144 | #endif // LEGENDMARKER_P_H |
|
145 | #endif // LEGENDMARKER_P_H |
@@ -1,505 +1,505 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
28 | #include <QGraphicsSceneResizeEvent> |
|
28 | #include <QGraphicsSceneResizeEvent> | |
29 | #include <QGraphicsLayout> |
|
29 | #include <QGraphicsLayout> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \enum QChart::ChartTheme |
|
34 | \enum QChart::ChartTheme | |
35 |
|
35 | |||
36 | This enum describes the theme used by the chart. |
|
36 | This enum describes the theme used by the chart. | |
37 |
|
37 | |||
38 | \value ChartThemeLight The default theme |
|
38 | \value ChartThemeLight The default theme | |
39 | \value ChartThemeBlueCerulean |
|
39 | \value ChartThemeBlueCerulean | |
40 | \value ChartThemeDark |
|
40 | \value ChartThemeDark | |
41 | \value ChartThemeBrownSand |
|
41 | \value ChartThemeBrownSand | |
42 | \value ChartThemeBlueNcs |
|
42 | \value ChartThemeBlueNcs | |
43 | \value ChartThemeHighContrast |
|
43 | \value ChartThemeHighContrast | |
44 | \value ChartThemeBlueIcy |
|
44 | \value ChartThemeBlueIcy | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \enum QChart::AnimationOption |
|
48 | \enum QChart::AnimationOption | |
49 |
|
49 | |||
50 | For enabling/disabling animations. Defaults to NoAnimation. |
|
50 | For enabling/disabling animations. Defaults to NoAnimation. | |
51 |
|
51 | |||
52 | \value NoAnimation |
|
52 | \value NoAnimation | |
53 | \value GridAxisAnimations |
|
53 | \value GridAxisAnimations | |
54 | \value SeriesAnimations |
|
54 | \value SeriesAnimations | |
55 | \value AllAnimations |
|
55 | \value AllAnimations | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \class QChart |
|
59 | \class QChart | |
60 | \brief QtCommercial chart API. |
|
60 | \brief QtCommercial chart API. | |
61 |
|
61 | |||
62 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
62 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
63 | representation of different types of series and other chart related objects like |
|
63 | representation of different types of series and other chart related objects like | |
64 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
64 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
65 | convenience class QChartView instead of QChart. |
|
65 | convenience class QChartView instead of QChart. | |
66 | \sa QChartView |
|
66 | \sa QChartView | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QChart::animationOptions |
|
70 | \property QChart::animationOptions | |
71 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
71 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \property QChart::backgroundVisible |
|
75 | \property QChart::backgroundVisible | |
76 | Whether the chart background is visible or not. |
|
76 | Whether the chart background is visible or not. | |
77 | \sa setBackgroundBrush(), setBackgroundPen() |
|
77 | \sa setBackgroundBrush(), setBackgroundPen() | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QChart::dropShadowEnabled |
|
81 | \property QChart::dropShadowEnabled | |
82 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
82 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
83 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
83 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \property QChart::margins |
|
87 | \property QChart::margins | |
88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. |
|
88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \property QChart::theme |
|
92 | \property QChart::theme | |
93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | |
95 | different themes. |
|
95 | different themes. | |
96 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
96 | Note: changing the theme will overwrite all customizations previously applied to the series. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::title |
|
100 | \property QChart::title | |
101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \fn void QChart::marginsChanged(QRectF newMargins) |
|
105 | \fn void QChart::marginsChanged(QRectF newMargins) | |
106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, |
|
106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, | |
107 | modify axes or hide/show legend. |
|
107 | modify axes or hide/show legend. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
112 | */ |
|
112 | */ | |
113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
114 | d_ptr(new QChartPrivate()) |
|
114 | d_ptr(new QChartPrivate()) | |
115 | { |
|
115 | { | |
116 | d_ptr->m_dataset = new ChartDataSet(this); |
|
116 | d_ptr->m_dataset = new ChartDataSet(this); | |
117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
118 | d_ptr->createConnections(); |
|
118 | d_ptr->createConnections(); | |
119 | d_ptr->m_legend = new LegendScroller(this); |
|
119 | d_ptr->m_legend = new LegendScroller(this); | |
120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); | |
122 | setLayout(d_ptr->m_presenter->layout()); |
|
122 | setLayout(d_ptr->m_presenter->layout()); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | Destroys the object and it's children, like series and axis objects added to it. |
|
126 | Destroys the object and it's children, like series and axis objects added to it. | |
127 | */ |
|
127 | */ | |
128 | QChart::~QChart() |
|
128 | QChart::~QChart() | |
129 | { |
|
129 | { | |
130 | //delete first presenter , since this is a root of all the graphical items |
|
130 | //delete first presenter , since this is a root of all the graphical items | |
131 | setLayout(0); |
|
131 | setLayout(0); | |
132 | delete d_ptr->m_presenter; |
|
132 | delete d_ptr->m_presenter; | |
133 | d_ptr->m_presenter=0; |
|
133 | d_ptr->m_presenter=0; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Adds the \a series onto the chart and takes the ownership of the object. |
|
137 | Adds the \a series onto the chart and takes the ownership of the object. | |
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
139 | the y axis). |
|
139 | the y axis). | |
140 |
|
140 | |||
141 | \sa removeSeries(), removeAllSeries() |
|
141 | \sa removeSeries(), removeAllSeries() | |
142 | */ |
|
142 | */ | |
143 | void QChart::addSeries(QAbstractSeries *series) |
|
143 | void QChart::addSeries(QAbstractSeries *series) | |
144 | { |
|
144 | { | |
145 | Q_ASSERT(series); |
|
145 | Q_ASSERT(series); | |
146 | d_ptr->m_dataset->addSeries(series); |
|
146 | d_ptr->m_dataset->addSeries(series); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Removes the \a series specified in a perameter from the QChartView. |
|
150 | Removes the \a series specified in a perameter from the QChartView. | |
151 | It releses its ownership of the specified QChartSeries object. |
|
151 | It releses its ownership of the specified QChartSeries object. | |
152 | It does not delete the pointed QChartSeries data object |
|
152 | It does not delete the pointed QChartSeries data object | |
153 | \sa addSeries(), removeAllSeries() |
|
153 | \sa addSeries(), removeAllSeries() | |
154 | */ |
|
154 | */ | |
155 | void QChart::removeSeries(QAbstractSeries *series) |
|
155 | void QChart::removeSeries(QAbstractSeries *series) | |
156 | { |
|
156 | { | |
157 | Q_ASSERT(series); |
|
157 | Q_ASSERT(series); | |
158 | d_ptr->m_dataset->removeSeries(series); |
|
158 | d_ptr->m_dataset->removeSeries(series); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Removes all the QChartSeries that have been added to the QChartView |
|
162 | Removes all the QChartSeries that have been added to the QChartView | |
163 | It also deletes the pointed QChartSeries data objects |
|
163 | It also deletes the pointed QChartSeries data objects | |
164 | \sa addSeries(), removeSeries() |
|
164 | \sa addSeries(), removeSeries() | |
165 | */ |
|
165 | */ | |
166 | void QChart::removeAllSeries() |
|
166 | void QChart::removeAllSeries() | |
167 | { |
|
167 | { | |
168 | d_ptr->m_dataset->removeAllSeries(); |
|
168 | d_ptr->m_dataset->removeAllSeries(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Sets the \a brush that is used for painting the background of the chart area. |
|
172 | Sets the \a brush that is used for painting the background of the chart area. | |
173 | */ |
|
173 | */ | |
174 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
174 | void QChart::setBackgroundBrush(const QBrush& brush) | |
175 | { |
|
175 | { | |
176 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
176 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Gets the brush that is used for painting the background of the chart area. |
|
180 | Gets the brush that is used for painting the background of the chart area. | |
181 | */ |
|
181 | */ | |
182 | QBrush QChart::backgroundBrush() const |
|
182 | QBrush QChart::backgroundBrush() const | |
183 | { |
|
183 | { | |
184 | return d_ptr->m_presenter->backgroundBrush(); |
|
184 | return d_ptr->m_presenter->backgroundBrush(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Sets the \a pen that is used for painting the background of the chart area. |
|
188 | Sets the \a pen that is used for painting the background of the chart area. | |
189 | */ |
|
189 | */ | |
190 | void QChart::setBackgroundPen(const QPen& pen) |
|
190 | void QChart::setBackgroundPen(const QPen& pen) | |
191 | { |
|
191 | { | |
192 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
192 | d_ptr->m_presenter->setBackgroundPen(pen); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Gets the pen that is used for painting the background of the chart area. |
|
196 | Gets the pen that is used for painting the background of the chart area. | |
197 | */ |
|
197 | */ | |
198 | QPen QChart::backgroundPen() const |
|
198 | QPen QChart::backgroundPen() const | |
199 | { |
|
199 | { | |
200 | return d_ptr->m_presenter->backgroundPen(); |
|
200 | return d_ptr->m_presenter->backgroundPen(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets the chart \a title. The description text that is drawn above the chart. |
|
204 | Sets the chart \a title. The description text that is drawn above the chart. | |
205 | */ |
|
205 | */ | |
206 | void QChart::setTitle(const QString& title) |
|
206 | void QChart::setTitle(const QString& title) | |
207 | { |
|
207 | { | |
208 | d_ptr->m_presenter->setTitle(title); |
|
208 | d_ptr->m_presenter->setTitle(title); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | Returns the chart title. The description text that is drawn above the chart. |
|
212 | Returns the chart title. The description text that is drawn above the chart. | |
213 | */ |
|
213 | */ | |
214 | QString QChart::title() const |
|
214 | QString QChart::title() const | |
215 | { |
|
215 | { | |
216 | return d_ptr->m_presenter->title(); |
|
216 | return d_ptr->m_presenter->title(); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
221 | */ |
|
221 | */ | |
222 | void QChart::setTitleFont(const QFont& font) |
|
222 | void QChart::setTitleFont(const QFont& font) | |
223 | { |
|
223 | { | |
224 | d_ptr->m_presenter->setTitleFont(font); |
|
224 | d_ptr->m_presenter->setTitleFont(font); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
229 | */ |
|
229 | */ | |
230 | QFont QChart::titleFont() const |
|
230 | QFont QChart::titleFont() const | |
231 | { |
|
231 | { | |
232 | return d_ptr->m_presenter->titleFont(); |
|
232 | return d_ptr->m_presenter->titleFont(); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | /*! |
|
235 | /*! | |
236 | Sets the \a brush used for rendering the title text. |
|
236 | Sets the \a brush used for rendering the title text. | |
237 | */ |
|
237 | */ | |
238 | void QChart::setTitleBrush(const QBrush &brush) |
|
238 | void QChart::setTitleBrush(const QBrush &brush) | |
239 | { |
|
239 | { | |
240 | d_ptr->m_presenter->setTitleBrush(brush); |
|
240 | d_ptr->m_presenter->setTitleBrush(brush); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns the brush used for rendering the title text. |
|
244 | Returns the brush used for rendering the title text. | |
245 | */ |
|
245 | */ | |
246 | QBrush QChart::titleBrush() const |
|
246 | QBrush QChart::titleBrush() const | |
247 | { |
|
247 | { | |
248 | return d_ptr->m_presenter->titleBrush(); |
|
248 | return d_ptr->m_presenter->titleBrush(); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void QChart::setTheme(QChart::ChartTheme theme) |
|
251 | void QChart::setTheme(QChart::ChartTheme theme) | |
252 | { |
|
252 | { | |
253 | d_ptr->m_presenter->setTheme(theme); |
|
253 | d_ptr->m_presenter->setTheme(theme); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | QChart::ChartTheme QChart::theme() const |
|
256 | QChart::ChartTheme QChart::theme() const | |
257 | { |
|
257 | { | |
258 | return d_ptr->m_presenter->theme(); |
|
258 | return d_ptr->m_presenter->theme(); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Zooms in the view by a factor of 2 |
|
262 | Zooms in the view by a factor of 2 | |
263 | */ |
|
263 | */ | |
264 | void QChart::zoomIn() |
|
264 | void QChart::zoomIn() | |
265 | { |
|
265 | { | |
266 | d_ptr->m_presenter->zoomIn(2.0); |
|
266 | d_ptr->m_presenter->zoomIn(2.0); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
270 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
271 | */ |
|
271 | */ | |
272 | void QChart::zoomIn(const QRectF& rect) |
|
272 | void QChart::zoomIn(const QRectF& rect) | |
273 | { |
|
273 | { | |
274 | if (!rect.isValid()) return; |
|
274 | if (!rect.isValid()) return; | |
275 | d_ptr->m_presenter->zoomIn(rect); |
|
275 | d_ptr->m_presenter->zoomIn(rect); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Restores the view zoom level to the previous one. |
|
279 | Restores the view zoom level to the previous one. | |
280 | */ |
|
280 | */ | |
281 | void QChart::zoomOut() |
|
281 | void QChart::zoomOut() | |
282 | { |
|
282 | { | |
283 | d_ptr->m_presenter->zoomOut(2.0); |
|
283 | d_ptr->m_presenter->zoomOut(2.0); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | /*! |
|
286 | /*! | |
287 | Zooms in the view by a \a factor. |
|
287 | Zooms in the view by a \a factor. | |
288 |
|
288 | |||
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
290 | */ |
|
290 | */ | |
291 | void QChart::zoom(qreal factor) |
|
291 | void QChart::zoom(qreal factor) | |
292 | { |
|
292 | { | |
293 | if (qFuzzyIsNull(factor)) |
|
293 | if (qFuzzyIsNull(factor)) | |
294 | return; |
|
294 | return; | |
295 |
|
295 | |||
296 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
296 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
297 | return; |
|
297 | return; | |
298 |
|
298 | |||
299 | if (factor < 0) |
|
299 | if (factor < 0) | |
300 | return; |
|
300 | return; | |
301 |
|
301 | |||
302 | if (factor > 1.0) |
|
302 | if (factor > 1.0) | |
303 | d_ptr->m_presenter->zoomIn(factor); |
|
303 | d_ptr->m_presenter->zoomIn(factor); | |
304 | else |
|
304 | else | |
305 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
305 | d_ptr->m_presenter->zoomOut(1.0 / factor); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
310 | If no series is provided then pointer to currently visible axis is provided |
|
310 | If no series is provided then pointer to currently visible axis is provided | |
311 | */ |
|
311 | */ | |
312 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const |
|
312 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const | |
313 | { |
|
313 | { | |
314 | return d_ptr->m_dataset->axisX(series); |
|
314 | return d_ptr->m_dataset->axisX(series); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
318 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
319 | If no series is provided then pointer to currently visible axis is provided |
|
319 | If no series is provided then pointer to currently visible axis is provided | |
320 | */ |
|
320 | */ | |
321 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const |
|
321 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const | |
322 | { |
|
322 | { | |
323 | return d_ptr->m_dataset->axisY(series); |
|
323 | return d_ptr->m_dataset->axisY(series); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
327 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. | |
328 |
|
328 | |||
329 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
329 | Creates the axes for the chart based on the series that has already been added to the chart. | |
330 |
|
330 | |||
331 | \table |
|
331 | \table | |
332 | \header |
|
332 | \header | |
333 | \o Series type |
|
333 | \o Series type | |
334 | \o X-axis |
|
334 | \o X-axis | |
335 | \o Y-axis |
|
335 | \o Y-axis | |
336 | \row |
|
336 | \row | |
337 | \o QXYSeries |
|
337 | \o QXYSeries | |
338 | \o QValueAxis |
|
338 | \o QValueAxis | |
339 | \o QValueAxis |
|
339 | \o QValueAxis | |
340 | \row |
|
340 | \row | |
341 | \o QBarSeries |
|
341 | \o QBarSeries | |
342 | \o QBarCategoryAxis |
|
342 | \o QBarCategoryAxis | |
343 | \o QValueAxis |
|
343 | \o QValueAxis | |
344 | \row |
|
344 | \row | |
345 | \o QPieSeries |
|
345 | \o QPieSeries | |
346 | \o None |
|
346 | \o None | |
347 | \o None |
|
347 | \o None | |
348 | \endtable |
|
348 | \endtable | |
349 |
|
349 | |||
350 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
350 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. | |
351 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
351 | If there are sevaral series added of different types then each series gets its own axes pair. | |
352 |
|
352 | |||
353 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
353 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. | |
354 |
|
354 | |||
355 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
355 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | |
356 | QPieSeries does not create any axes. |
|
356 | QPieSeries does not create any axes. | |
357 |
|
357 | |||
358 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
358 | \sa axisX(), axisY(), setAxisX(), setAxisY() | |
359 | */ |
|
359 | */ | |
360 | void QChart::createDefaultAxes() |
|
360 | void QChart::createDefaultAxes() | |
361 | { |
|
361 | { | |
362 | d_ptr->m_dataset->createDefaultAxes(); |
|
362 | d_ptr->m_dataset->createDefaultAxes(); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | Returns the legend object of the chart. Ownership stays in chart. |
|
366 | Returns the legend object of the chart. Ownership stays in chart. | |
367 | */ |
|
367 | */ | |
368 | QLegend* QChart::legend() const |
|
368 | QLegend* QChart::legend() const | |
369 | { |
|
369 | { | |
370 | return d_ptr->m_legend; |
|
370 | return d_ptr->m_legend; | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | /*! |
|
373 | /*! | |
374 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
374 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
375 | */ |
|
375 | */ | |
376 |
void QChart::setM |
|
376 | void QChart::setMargins(const QMargins& margins) | |
377 | { |
|
377 | { | |
378 |
d_ptr->m_presenter->setM |
|
378 | d_ptr->m_presenter->setMargins(margins); | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | /*! |
|
381 | /*! | |
382 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
382 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
383 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
383 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
384 | */ |
|
384 | */ | |
385 |
QMargins QChart::m |
|
385 | QMargins QChart::margins() const | |
386 | { |
|
386 | { | |
387 |
return d_ptr->m_presenter->m |
|
387 | return d_ptr->m_presenter->margins(); | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | /*! |
|
390 | /*! | |
391 | Returns the the rect within which the drawing of the chart is done. |
|
391 | Returns the the rect within which the drawing of the chart is done. | |
392 | It does not include the area defines by margins. |
|
392 | It does not include the area defines by margins. | |
393 | */ |
|
393 | */ | |
394 | QRectF QChart::plotArea() const |
|
394 | QRectF QChart::plotArea() const | |
395 | { |
|
395 | { | |
396 |
return d_ptr->m_presenter-> |
|
396 | return d_ptr->m_presenter->chartsGeometry(); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | ///*! |
|
399 | ///*! | |
400 | // TODO: Dummy. |
|
400 | // TODO: Dummy. | |
401 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
401 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible | |
402 | // */ |
|
402 | // */ | |
403 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
403 | //void QChart::adjustViewToSeries(QAbstractSeries* series) | |
404 | //{ |
|
404 | //{ | |
405 | // // |
|
405 | // // | |
406 | //} |
|
406 | //} | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Sets animation \a options for the chart |
|
409 | Sets animation \a options for the chart | |
410 | */ |
|
410 | */ | |
411 | void QChart::setAnimationOptions(AnimationOptions options) |
|
411 | void QChart::setAnimationOptions(AnimationOptions options) | |
412 | { |
|
412 | { | |
413 | d_ptr->m_presenter->setAnimationOptions(options); |
|
413 | d_ptr->m_presenter->setAnimationOptions(options); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | QChart::AnimationOptions QChart::animationOptions() const |
|
416 | QChart::AnimationOptions QChart::animationOptions() const | |
417 | { |
|
417 | { | |
418 | return d_ptr->m_presenter->animationOptions(); |
|
418 | return d_ptr->m_presenter->animationOptions(); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | /*! |
|
421 | /*! | |
422 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
422 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
423 | */ |
|
423 | */ | |
424 | void QChart::scroll(qreal dx, qreal dy) |
|
424 | void QChart::scroll(qreal dx, qreal dy) | |
425 | { |
|
425 | { | |
426 | d_ptr->m_presenter->scroll(dx, dy); |
|
426 | d_ptr->m_presenter->scroll(dx, dy); | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | void QChart::setBackgroundVisible(bool visible) |
|
429 | void QChart::setBackgroundVisible(bool visible) | |
430 | { |
|
430 | { | |
431 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
431 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
432 | } |
|
432 | } | |
433 |
|
433 | |||
434 | bool QChart::isBackgroundVisible() const |
|
434 | bool QChart::isBackgroundVisible() const | |
435 | { |
|
435 | { | |
436 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
436 | return d_ptr->m_presenter->isBackgroundVisible(); | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | void QChart::setDropShadowEnabled(bool enabled) |
|
439 | void QChart::setDropShadowEnabled(bool enabled) | |
440 | { |
|
440 | { | |
441 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
441 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | bool QChart::isDropShadowEnabled() const |
|
444 | bool QChart::isDropShadowEnabled() const | |
445 | { |
|
445 | { | |
446 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
446 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | /*! |
|
449 | /*! | |
450 | Returns all the series that are added to the chart. |
|
450 | Returns all the series that are added to the chart. | |
451 |
|
451 | |||
452 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
452 | \sa addSeries(), removeSeries(), removeAllSeries() | |
453 | */ |
|
453 | */ | |
454 | QList<QAbstractSeries*> QChart::series() const |
|
454 | QList<QAbstractSeries*> QChart::series() const | |
455 | { |
|
455 | { | |
456 | return d_ptr->m_dataset->series(); |
|
456 | return d_ptr->m_dataset->series(); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | /*! |
|
459 | /*! | |
460 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
460 | Sets \a axis to the chart, which will control the presentation of the \a series | |
461 |
|
461 | |||
462 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
462 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
463 | */ |
|
463 | */ | |
464 | void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) |
|
464 | void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) | |
465 | { |
|
465 | { | |
466 | d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal); |
|
466 | d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal); | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | /*! |
|
469 | /*! | |
470 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
470 | Sets \a axis to the chart, which will control the presentation of the \a series | |
471 |
|
471 | |||
472 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
472 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
473 | */ |
|
473 | */ | |
474 | void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series) |
|
474 | void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series) | |
475 | { |
|
475 | { | |
476 | d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical); |
|
476 | d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical); | |
477 | } |
|
477 | } | |
478 |
|
478 | |||
479 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
479 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
480 |
|
480 | |||
481 | QChartPrivate::QChartPrivate(): |
|
481 | QChartPrivate::QChartPrivate(): | |
482 | m_legend(0), |
|
482 | m_legend(0), | |
483 | m_dataset(0), |
|
483 | m_dataset(0), | |
484 | m_presenter(0) |
|
484 | m_presenter(0) | |
485 | { |
|
485 | { | |
486 |
|
486 | |||
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | QChartPrivate::~QChartPrivate() |
|
489 | QChartPrivate::~QChartPrivate() | |
490 | { |
|
490 | { | |
491 |
|
491 | |||
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | void QChartPrivate::createConnections() |
|
494 | void QChartPrivate::createConnections() | |
495 | { |
|
495 | { | |
496 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
496 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
497 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
497 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
498 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
498 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); | |
499 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
499 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); | |
500 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
500 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | #include "moc_qchart.cpp" |
|
503 | #include "moc_qchart.cpp" | |
504 |
|
504 | |||
505 | QTCOMMERCIALCHART_END_NAMESPACE |
|
505 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,133 +1,133 | |||||
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 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QAbstractSeries> |
|
24 | #include <QAbstractSeries> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include <QGraphicsWidget> |
|
26 | #include <QGraphicsWidget> | |
27 | #include <QMargins> |
|
27 | #include <QMargins> | |
28 |
|
28 | |||
29 | class QGraphicsSceneResizeEvent; |
|
29 | class QGraphicsSceneResizeEvent; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 | class QAbstractAxis; |
|
34 | class QAbstractAxis; | |
35 | class QLegend; |
|
35 | class QLegend; | |
36 | struct QChartPrivate; |
|
36 | struct QChartPrivate; | |
37 |
|
37 | |||
38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) | |
42 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
42 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) | |
44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) | |
45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) | |
46 |
Q_PROPERTY(QMargins m |
|
46 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) | |
47 | Q_ENUMS(ChartTheme) |
|
47 | Q_ENUMS(ChartTheme) | |
48 | Q_ENUMS(AnimationOption) |
|
48 | Q_ENUMS(AnimationOption) | |
49 |
|
49 | |||
50 | public: |
|
50 | public: | |
51 | enum ChartTheme { |
|
51 | enum ChartTheme { | |
52 | ChartThemeLight = 0, |
|
52 | ChartThemeLight = 0, | |
53 | ChartThemeBlueCerulean, |
|
53 | ChartThemeBlueCerulean, | |
54 | ChartThemeDark, |
|
54 | ChartThemeDark, | |
55 | ChartThemeBrownSand, |
|
55 | ChartThemeBrownSand, | |
56 | ChartThemeBlueNcs, |
|
56 | ChartThemeBlueNcs, | |
57 | ChartThemeHighContrast, |
|
57 | ChartThemeHighContrast, | |
58 | ChartThemeBlueIcy |
|
58 | ChartThemeBlueIcy | |
59 | }; |
|
59 | }; | |
60 |
|
60 | |||
61 | enum AnimationOption { |
|
61 | enum AnimationOption { | |
62 | NoAnimation = 0x0, |
|
62 | NoAnimation = 0x0, | |
63 | GridAxisAnimations = 0x1, |
|
63 | GridAxisAnimations = 0x1, | |
64 | SeriesAnimations =0x2, |
|
64 | SeriesAnimations =0x2, | |
65 | AllAnimations = 0x3 |
|
65 | AllAnimations = 0x3 | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
69 |
|
69 | |||
70 | public: |
|
70 | public: | |
71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
72 | ~QChart(); |
|
72 | ~QChart(); | |
73 |
|
73 | |||
74 | void addSeries(QAbstractSeries *series); |
|
74 | void addSeries(QAbstractSeries *series); | |
75 | void removeSeries(QAbstractSeries *series); |
|
75 | void removeSeries(QAbstractSeries *series); | |
76 | void removeAllSeries(); |
|
76 | void removeAllSeries(); | |
77 | QList<QAbstractSeries*> series() const; |
|
77 | QList<QAbstractSeries*> series() const; | |
78 |
|
78 | |||
79 | void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
79 | void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); | |
80 | void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
80 | void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); | |
81 |
|
81 | |||
82 | QAbstractAxis* axisX(QAbstractSeries* series = 0) const; |
|
82 | QAbstractAxis* axisX(QAbstractSeries* series = 0) const; | |
83 | QAbstractAxis* axisY(QAbstractSeries* series = 0) const; |
|
83 | QAbstractAxis* axisY(QAbstractSeries* series = 0) const; | |
84 |
|
84 | |||
85 | void createDefaultAxes(); |
|
85 | void createDefaultAxes(); | |
86 |
|
86 | |||
87 | void setTheme(QChart::ChartTheme theme); |
|
87 | void setTheme(QChart::ChartTheme theme); | |
88 | QChart::ChartTheme theme() const; |
|
88 | QChart::ChartTheme theme() const; | |
89 |
|
89 | |||
90 | void setTitle(const QString& title); |
|
90 | void setTitle(const QString& title); | |
91 | QString title() const; |
|
91 | QString title() const; | |
92 | void setTitleFont(const QFont& font); |
|
92 | void setTitleFont(const QFont& font); | |
93 | QFont titleFont() const; |
|
93 | QFont titleFont() const; | |
94 | void setTitleBrush(const QBrush &brush); |
|
94 | void setTitleBrush(const QBrush &brush); | |
95 | QBrush titleBrush() const; |
|
95 | QBrush titleBrush() const; | |
96 |
|
96 | |||
97 | void setBackgroundBrush(const QBrush &brush); |
|
97 | void setBackgroundBrush(const QBrush &brush); | |
98 | QBrush backgroundBrush() const; |
|
98 | QBrush backgroundBrush() const; | |
99 | void setBackgroundPen(const QPen &pen); |
|
99 | void setBackgroundPen(const QPen &pen); | |
100 | QPen backgroundPen() const; |
|
100 | QPen backgroundPen() const; | |
101 | void setBackgroundVisible(bool visible = true); |
|
101 | void setBackgroundVisible(bool visible = true); | |
102 | bool isBackgroundVisible() const; |
|
102 | bool isBackgroundVisible() const; | |
103 |
|
103 | |||
104 | void setDropShadowEnabled(bool enabled = true); |
|
104 | void setDropShadowEnabled(bool enabled = true); | |
105 | bool isDropShadowEnabled() const; |
|
105 | bool isDropShadowEnabled() const; | |
106 | void setAnimationOptions(AnimationOptions options); |
|
106 | void setAnimationOptions(AnimationOptions options); | |
107 | AnimationOptions animationOptions() const; |
|
107 | AnimationOptions animationOptions() const; | |
108 |
|
108 | |||
109 | void zoomIn(); |
|
109 | void zoomIn(); | |
110 | void zoomIn(const QRectF &rect); |
|
110 | void zoomIn(const QRectF &rect); | |
111 | void zoomOut(); |
|
111 | void zoomOut(); | |
112 | void zoom(qreal factor); |
|
112 | void zoom(qreal factor); | |
113 | void scroll(qreal dx, qreal dy); |
|
113 | void scroll(qreal dx, qreal dy); | |
114 |
|
114 | |||
115 | QLegend* legend() const; |
|
115 | QLegend* legend() const; | |
116 |
|
116 | |||
117 |
void setM |
|
117 | void setMargins(const QMargins& margins); | |
118 |
QMargins m |
|
118 | QMargins margins() const; | |
119 |
|
119 | |||
120 | QRectF plotArea() const; |
|
120 | QRectF plotArea() const; | |
121 |
|
121 | |||
122 | protected: |
|
122 | protected: | |
123 | QScopedPointer<QChartPrivate> d_ptr; |
|
123 | QScopedPointer<QChartPrivate> d_ptr; | |
124 | friend class QLegend; |
|
124 | friend class QLegend; | |
125 | friend class ChartPresenter; |
|
125 | friend class ChartPresenter; | |
126 | Q_DISABLE_COPY(QChart) |
|
126 | Q_DISABLE_COPY(QChart) | |
127 | }; |
|
127 | }; | |
128 |
|
128 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE | |
130 |
|
130 | |||
131 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
131 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
132 |
|
132 | |||
133 | #endif |
|
133 | #endif |
@@ -1,252 +1,253 | |||||
1 | !include( ../config.pri ):error( "Couldn't find the config.pri file!" ) |
|
1 | !include( ../config.pri ):error( "Couldn't find the config.pri file!" ) | |
2 |
|
2 | |||
3 | ############################# BUILD CONFIG ###################################### |
|
3 | ############################# BUILD CONFIG ###################################### | |
4 |
|
4 | |||
5 | TARGET = $$LIBRARY_NAME |
|
5 | TARGET = $$LIBRARY_NAME | |
6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
7 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
8 | QT = core gui |
|
8 | QT = core gui | |
9 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
9 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
10 | win32:CONFIG += create_prl |
|
10 | win32:CONFIG += create_prl | |
11 | # treat warnings as errors |
|
11 | # treat warnings as errors | |
12 | win32-msvc*: { |
|
12 | win32-msvc*: { | |
13 | QMAKE_CXXFLAGS += /WX |
|
13 | QMAKE_CXXFLAGS += /WX | |
14 | } else { |
|
14 | } else { | |
15 | QMAKE_CXXFLAGS += -Werror |
|
15 | QMAKE_CXXFLAGS += -Werror | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | unix:{ |
|
18 | unix:{ | |
19 | QMAKE_CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden |
|
19 | QMAKE_CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | ############################# DEPEDENCES ######################################## |
|
22 | ############################# DEPEDENCES ######################################## | |
23 |
|
23 | |||
24 | win32-msvc*: LIBS += User32.lib |
|
24 | win32-msvc*: LIBS += User32.lib | |
25 | LIBS -= -l$$LIBRARY_NAME |
|
25 | LIBS -= -l$$LIBRARY_NAME | |
26 | INCLUDEPATH += ../include . |
|
26 | INCLUDEPATH += ../include . | |
27 |
|
27 | |||
28 | ############################# SOURCES ########################################## |
|
28 | ############################# SOURCES ########################################## | |
29 |
|
29 | |||
30 | SOURCES += \ |
|
30 | SOURCES += \ | |
31 | $$PWD/chartdataset.cpp \ |
|
31 | $$PWD/chartdataset.cpp \ | |
32 | $$PWD/chartpresenter.cpp \ |
|
32 | $$PWD/chartpresenter.cpp \ | |
33 | $$PWD/charttheme.cpp \ |
|
33 | $$PWD/charttheme.cpp \ | |
34 | $$PWD/domain.cpp \ |
|
34 | $$PWD/domain.cpp \ | |
35 | $$PWD/qchart.cpp \ |
|
35 | $$PWD/qchart.cpp \ | |
36 | $$PWD/qchartview.cpp \ |
|
36 | $$PWD/qchartview.cpp \ | |
37 | $$PWD/qabstractseries.cpp \ |
|
37 | $$PWD/qabstractseries.cpp \ | |
38 | $$PWD/chartbackground.cpp \ |
|
38 | $$PWD/chartbackground.cpp \ | |
39 | $$PWD/chartelement.cpp \ |
|
39 | $$PWD/chartelement.cpp \ | |
40 | $$PWD/scroller.cpp \ |
|
40 | $$PWD/scroller.cpp \ | |
41 | $$PWD/chartlayout.cpp |
|
41 | $$PWD/chartlayout.cpp \ | |
|
42 | $$PWD/charttitle.cpp | |||
42 | PRIVATE_HEADERS += \ |
|
43 | PRIVATE_HEADERS += \ | |
43 | $$PWD/chartdataset_p.h \ |
|
44 | $$PWD/chartdataset_p.h \ | |
44 | $$PWD/chartitem_p.h \ |
|
45 | $$PWD/chartitem_p.h \ | |
45 | $$PWD/chartpresenter_p.h \ |
|
46 | $$PWD/chartpresenter_p.h \ | |
46 | $$PWD/charttheme_p.h \ |
|
47 | $$PWD/charttheme_p.h \ | |
47 | $$PWD/domain_p.h \ |
|
48 | $$PWD/domain_p.h \ | |
48 | $$PWD/chartbackground_p.h \ |
|
49 | $$PWD/chartbackground_p.h \ | |
49 | $$PWD/chartelement_p.h \ |
|
50 | $$PWD/chartelement_p.h \ | |
50 | $$PWD/chartconfig_p.h \ |
|
51 | $$PWD/chartconfig_p.h \ | |
51 | $$PWD/qchart_p.h \ |
|
52 | $$PWD/qchart_p.h \ | |
52 | $$PWD/qchartview_p.h \ |
|
53 | $$PWD/qchartview_p.h \ | |
53 | $$PWD/scroller_p.h \ |
|
54 | $$PWD/scroller_p.h \ | |
54 | $$PWD/qabstractseries_p.h \ |
|
55 | $$PWD/qabstractseries_p.h \ | |
55 | $$PWD/chartlayout_p.h |
|
56 | $$PWD/chartlayout_p.h \ | |
56 |
|
57 | $$PWD/charttitle_p.h | ||
57 | PUBLIC_HEADERS += \ |
|
58 | PUBLIC_HEADERS += \ | |
58 | $$PWD/qchart.h \ |
|
59 | $$PWD/qchart.h \ | |
59 | $$PWD/qchartglobal.h \ |
|
60 | $$PWD/qchartglobal.h \ | |
60 | $$PWD/qabstractseries.h \ |
|
61 | $$PWD/qabstractseries.h \ | |
61 | $$PWD/qchartview.h \ |
|
62 | $$PWD/qchartview.h \ | |
62 | $$PWD/chartsnamespace.h |
|
63 | $$PWD/chartsnamespace.h | |
63 |
|
64 | |||
64 | include(animations/animations.pri) |
|
65 | include(animations/animations.pri) | |
65 | include(areachart/areachart.pri) |
|
66 | include(areachart/areachart.pri) | |
66 | include(axis/axis.pri) |
|
67 | include(axis/axis.pri) | |
67 | include(barchart/barchart.pri) |
|
68 | include(barchart/barchart.pri) | |
68 | include(legend/legend.pri) |
|
69 | include(legend/legend.pri) | |
69 | include(linechart/linechart.pri) |
|
70 | include(linechart/linechart.pri) | |
70 | include(piechart/piechart.pri) |
|
71 | include(piechart/piechart.pri) | |
71 | include(scatterchart/scatter.pri) |
|
72 | include(scatterchart/scatter.pri) | |
72 | include(splinechart/splinechart.pri) |
|
73 | include(splinechart/splinechart.pri) | |
73 | include(themes/themes.pri) |
|
74 | include(themes/themes.pri) | |
74 | include(xychart/xychart.pri) |
|
75 | include(xychart/xychart.pri) | |
75 |
|
76 | |||
76 | HEADERS += $$PUBLIC_HEADERS |
|
77 | HEADERS += $$PUBLIC_HEADERS | |
77 | HEADERS += $$PRIVATE_HEADERS |
|
78 | HEADERS += $$PRIVATE_HEADERS | |
78 | HEADERS += $$THEMES |
|
79 | HEADERS += $$THEMES | |
79 |
|
80 | |||
80 | ############################# BUILD PATH ########################################## |
|
81 | ############################# BUILD PATH ########################################## | |
81 |
|
82 | |||
82 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
83 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
83 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
84 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
84 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
85 | UI_DIR = $$CHART_BUILD_DIR/lib | |
85 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
86 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
86 |
|
87 | |||
87 | ############################# PUBLIC HEADERS GENERATOR ########################################## |
|
88 | ############################# PUBLIC HEADERS GENERATOR ########################################## | |
88 |
|
89 | |||
89 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal) |
|
90 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal) | |
90 | { |
|
91 | { | |
91 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
92 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) | |
92 | win32:{ |
|
93 | win32:{ | |
93 | command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" |
|
94 | command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" | |
94 | }else{ |
|
95 | }else{ | |
95 | command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" |
|
96 | command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" | |
96 | } |
|
97 | } | |
97 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal |
|
98 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal | |
98 | system($$command) |
|
99 | system($$command) | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | for(file, PUBLIC_HEADERS) { |
|
102 | for(file, PUBLIC_HEADERS) { | |
102 | name = $$split(file,'/') |
|
103 | name = $$split(file,'/') | |
103 | name = $$last(name) |
|
104 | name = $$last(name) | |
104 | class = "$$cat($$file)" |
|
105 | class = "$$cat($$file)" | |
105 | class = $$find(class,class) |
|
106 | class = $$find(class,class) | |
106 | !isEmpty(class){ |
|
107 | !isEmpty(class){ | |
107 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) |
|
108 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) | |
108 | class = $$member(class,1) |
|
109 | class = $$member(class,1) | |
109 | class = $$split(class,' ') |
|
110 | class = $$split(class,' ') | |
110 | class = $$replace(class,' ','') |
|
111 | class = $$replace(class,' ','') | |
111 | class = $$member(class,0) |
|
112 | class = $$member(class,0) | |
112 | win32:{ |
|
113 | win32:{ | |
113 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
114 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
114 | }else{ |
|
115 | }else{ | |
115 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
116 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
116 | } |
|
117 | } | |
117 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class |
|
118 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class | |
118 | system($$command) |
|
119 | system($$command) | |
119 | } |
|
120 | } | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | ############################# INSTALLERS ########################################## |
|
123 | ############################# INSTALLERS ########################################## | |
123 |
|
124 | |||
124 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
125 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
125 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS |
|
126 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS | |
126 | INSTALLS += public_headers |
|
127 | INSTALLS += public_headers | |
127 |
|
128 | |||
128 | install_build_public_headers.name = build_public_headers |
|
129 | install_build_public_headers.name = build_public_headers | |
129 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
130 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
130 | install_build_public_headers.input = PUBLIC_HEADERS |
|
131 | install_build_public_headers.input = PUBLIC_HEADERS | |
131 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
132 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
132 | ${QMAKE_FILE_NAME} \ |
|
133 | ${QMAKE_FILE_NAME} \ | |
133 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
134 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
134 | install_build_public_headers.CONFIG += target_predeps \ |
|
135 | install_build_public_headers.CONFIG += target_predeps \ | |
135 | no_link |
|
136 | no_link | |
136 |
|
137 | |||
137 | install_build_private_headers.name = build_private_headers |
|
138 | install_build_private_headers.name = build_private_headers | |
138 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
139 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
139 | install_build_private_headers.input = PRIVATE_HEADERS |
|
140 | install_build_private_headers.input = PRIVATE_HEADERS | |
140 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
141 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
141 | ${QMAKE_FILE_NAME} \ |
|
142 | ${QMAKE_FILE_NAME} \ | |
142 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
143 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
143 | install_build_private_headers.CONFIG += target_predeps \ |
|
144 | install_build_private_headers.CONFIG += target_predeps \ | |
144 | no_link |
|
145 | no_link | |
145 |
|
146 | |||
146 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
147 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
147 | install_build_private_headers \ |
|
148 | install_build_private_headers \ | |
148 |
|
149 | |||
149 | win32:{ |
|
150 | win32:{ | |
150 | bintarget.CONFIG += no_check_exist |
|
151 | bintarget.CONFIG += no_check_exist | |
151 | !staticlib: { |
|
152 | !staticlib: { | |
152 | bintarget.files += $$CHART_BUILD_LIB_DIR\\$${TARGET}.dll |
|
153 | bintarget.files += $$CHART_BUILD_LIB_DIR\\$${TARGET}.dll | |
153 | } |
|
154 | } | |
154 | win32-msvc*:CONFIG(debug, debug|release): { |
|
155 | win32-msvc*:CONFIG(debug, debug|release): { | |
155 | bintarget.files += $$CHART_BUILD_LIB_DIR\\$${TARGET}.pdb |
|
156 | bintarget.files += $$CHART_BUILD_LIB_DIR\\$${TARGET}.pdb | |
156 | } |
|
157 | } | |
157 | bintarget.path = $$[QT_INSTALL_BINS] |
|
158 | bintarget.path = $$[QT_INSTALL_BINS] | |
158 |
|
159 | |||
159 | libtarget.CONFIG += no_check_exist |
|
160 | libtarget.CONFIG += no_check_exist | |
160 | libtarget.files = $$CHART_BUILD_LIB_DIR\\$${TARGET}.prl |
|
161 | libtarget.files = $$CHART_BUILD_LIB_DIR\\$${TARGET}.prl | |
161 | win32-msvc*: { |
|
162 | win32-msvc*: { | |
162 | libtarget.files += $$CHART_BUILD_LIB_DIR\\$${TARGET}.lib |
|
163 | libtarget.files += $$CHART_BUILD_LIB_DIR\\$${TARGET}.lib | |
163 | } else { |
|
164 | } else { | |
164 | libtarget.files += $$CHART_BUILD_LIB_DIR\\lib$${TARGET}.a |
|
165 | libtarget.files += $$CHART_BUILD_LIB_DIR\\lib$${TARGET}.a | |
165 | } |
|
166 | } | |
166 | libtarget.path = $$[QT_INSTALL_LIBS] |
|
167 | libtarget.path = $$[QT_INSTALL_LIBS] | |
167 |
|
168 | |||
168 | DLLDESTDIR = $$CHART_BUILD_BIN_DIR |
|
169 | DLLDESTDIR = $$CHART_BUILD_BIN_DIR | |
169 | INSTALLS += bintarget libtarget |
|
170 | INSTALLS += bintarget libtarget | |
170 | }else{ |
|
171 | }else{ | |
171 | target.path=$$[QT_INSTALL_LIBS] |
|
172 | target.path=$$[QT_INSTALL_LIBS] | |
172 | INSTALLS += target |
|
173 | INSTALLS += target | |
173 | } |
|
174 | } | |
174 |
|
175 | |||
175 | mac: !staticlib: { |
|
176 | mac: !staticlib: { | |
176 | # Update the name (id) of the library on OSX to point to the lib path |
|
177 | # Update the name (id) of the library on OSX to point to the lib path | |
177 | MAC_CHARTS_LIB_NAME = "lib"$$LIBRARY_NAME".1.dylib" |
|
178 | MAC_CHARTS_LIB_NAME = "lib"$$LIBRARY_NAME".1.dylib" | |
178 | QMAKE_POST_LINK += "install_name_tool -id $$CHART_BUILD_LIB_DIR"/"$$MAC_CHARTS_LIB_NAME $$CHART_BUILD_LIB_DIR"/"$$MAC_CHARTS_LIB_NAME" |
|
179 | QMAKE_POST_LINK += "install_name_tool -id $$CHART_BUILD_LIB_DIR"/"$$MAC_CHARTS_LIB_NAME $$CHART_BUILD_LIB_DIR"/"$$MAC_CHARTS_LIB_NAME" | |
179 |
|
180 | |||
180 | # Update the name (id) of the installed library on OSX to point to the installation path |
|
181 | # Update the name (id) of the installed library on OSX to point to the installation path | |
181 | postinstall.path = $$[QT_INSTALL_LIBS] |
|
182 | postinstall.path = $$[QT_INSTALL_LIBS] | |
182 | postinstall.extra = "install_name_tool -id $$[QT_INSTALL_LIBS]"/"$$MAC_CHARTS_LIB_NAME $$[QT_INSTALL_LIBS]"/"$$MAC_CHARTS_LIB_NAME" |
|
183 | postinstall.extra = "install_name_tool -id $$[QT_INSTALL_LIBS]"/"$$MAC_CHARTS_LIB_NAME $$[QT_INSTALL_LIBS]"/"$$MAC_CHARTS_LIB_NAME" | |
183 | INSTALLS += postinstall |
|
184 | INSTALLS += postinstall | |
184 | } |
|
185 | } | |
185 |
|
186 | |||
186 | ################################ DEVELOPMENT BUILD ########################################## |
|
187 | ################################ DEVELOPMENT BUILD ########################################## | |
187 | # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly. |
|
188 | # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly. | |
188 | # This is the case at least with shadow builds. |
|
189 | # This is the case at least with shadow builds. | |
189 | # http://qt-project.org/wiki/jom |
|
190 | # http://qt-project.org/wiki/jom | |
190 |
|
191 | |||
191 | development_build:!win32-msvc*:{ |
|
192 | development_build:!win32-msvc*:{ | |
192 | chartversion.target = $$PWD/qchartversion_p.h |
|
193 | chartversion.target = $$PWD/qchartversion_p.h | |
193 |
|
194 | |||
194 | unix:{ |
|
195 | unix:{ | |
195 | chartversion.commands = @echo \ |
|
196 | chartversion.commands = @echo \ | |
196 | \" $${LITERAL_HASH}ifndef QCHARTVERSION_P_H\\n\ |
|
197 | \" $${LITERAL_HASH}ifndef QCHARTVERSION_P_H\\n\ | |
197 | $${LITERAL_HASH}define QCHARTVERSION_P_H\\n\ |
|
198 | $${LITERAL_HASH}define QCHARTVERSION_P_H\\n\ | |
198 | const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" ; \\n\ |
|
199 | const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" ; \\n\ | |
199 | const char *gitHead = \\\"`git rev-parse HEAD`\\\" ; \\n \ |
|
200 | const char *gitHead = \\\"`git rev-parse HEAD`\\\" ; \\n \ | |
200 | $${LITERAL_HASH}endif \" \ |
|
201 | $${LITERAL_HASH}endif \" \ | |
201 | > \ |
|
202 | > \ | |
202 | $$chartversion.target; |
|
203 | $$chartversion.target; | |
203 | }else{ |
|
204 | }else{ | |
204 | chartversion.commands = @echo \ |
|
205 | chartversion.commands = @echo \ | |
205 | "const char *buildTime = \"%date%_%time%\" ; \ |
|
206 | "const char *buildTime = \"%date%_%time%\" ; \ | |
206 | const char *gitHead = \"unknown\" ; " \ |
|
207 | const char *gitHead = \"unknown\" ; " \ | |
207 | > \ |
|
208 | > \ | |
208 | $$chartversion.target |
|
209 | $$chartversion.target | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 | chartversion.depends = $$HEADERS \ |
|
212 | chartversion.depends = $$HEADERS \ | |
212 | $$SOURCES |
|
213 | $$SOURCES | |
213 |
|
214 | |||
214 | PRE_TARGETDEPS += $$chartversion.target |
|
215 | PRE_TARGETDEPS += $$chartversion.target | |
215 | QMAKE_CLEAN += $$PWD/qchartversion_p.h |
|
216 | QMAKE_CLEAN += $$PWD/qchartversion_p.h | |
216 | QMAKE_EXTRA_TARGETS += chartversion |
|
217 | QMAKE_EXTRA_TARGETS += chartversion | |
217 | } |
|
218 | } | |
218 |
|
219 | |||
219 | ############################### CLEAN ########################################### |
|
220 | ############################### CLEAN ########################################### | |
220 |
|
221 | |||
221 | unix:QMAKE_DISTCLEAN += -r \ |
|
222 | unix:QMAKE_DISTCLEAN += -r \ | |
222 | $$CHART_BUILD_HEADER_DIR \ |
|
223 | $$CHART_BUILD_HEADER_DIR \ | |
223 | $$CHART_BUILD_LIB_DIR |
|
224 | $$CHART_BUILD_LIB_DIR | |
224 | win32:QMAKE_DISTCLEAN += /Q \ |
|
225 | win32:QMAKE_DISTCLEAN += /Q \ | |
225 | $$CHART_BUILD_HEADER_DIR \ |
|
226 | $$CHART_BUILD_HEADER_DIR \ | |
226 | $$CHART_BUILD_LIB_DIR |
|
227 | $$CHART_BUILD_LIB_DIR | |
227 |
|
228 | |||
228 | ############################## COVERAGE ######################################### |
|
229 | ############################## COVERAGE ######################################### | |
229 |
|
230 | |||
230 | unix:coverage:{ |
|
231 | unix:coverage:{ | |
231 |
|
232 | |||
232 | QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage |
|
233 | QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage | |
233 | QMAKE_LDFLAGS += -fprofile-arcs -ftest-coverage |
|
234 | QMAKE_LDFLAGS += -fprofile-arcs -ftest-coverage | |
234 |
|
235 | |||
235 | LIBS += -lgcov |
|
236 | LIBS += -lgcov | |
236 |
|
237 | |||
237 | QMAKE_CLEAN += $$OBJECTS_DIR/*.gcda $$OBJECTS_DIR/*.gcno $$PWD/*.gcov ../coverage/*.info |
|
238 | QMAKE_CLEAN += $$OBJECTS_DIR/*.gcda $$OBJECTS_DIR/*.gcno $$PWD/*.gcov ../coverage/*.info | |
238 | QMAKE_EXTRA_TARGETS += preparecoverage gencoverage |
|
239 | QMAKE_EXTRA_TARGETS += preparecoverage gencoverage | |
239 |
|
240 | |||
240 | preparecoverage.target = prepare_coverage |
|
241 | preparecoverage.target = prepare_coverage | |
241 | preparecoverage.depends = all |
|
242 | preparecoverage.depends = all | |
242 | preparecoverage.commands = lcov --directory $$OBJECTS_DIR --zerocounters ;\ |
|
243 | preparecoverage.commands = lcov --directory $$OBJECTS_DIR --zerocounters ;\ | |
243 | lcov -i -d $$OBJECTS_DIR -c -o ../coverage/base.info -b $$PWD; |
|
244 | lcov -i -d $$OBJECTS_DIR -c -o ../coverage/base.info -b $$PWD; | |
244 |
|
245 | |||
245 | gencoverage.target = gen_coverage |
|
246 | gencoverage.target = gen_coverage | |
246 | gencoverage.depends = all |
|
247 | gencoverage.depends = all | |
247 | gencoverage.commands = lcov -d $$OBJECTS_DIR -c -o ../coverage/src.info -b $$PWD;\ |
|
248 | gencoverage.commands = lcov -d $$OBJECTS_DIR -c -o ../coverage/src.info -b $$PWD;\ | |
248 | lcov -e ../coverage/base.info $$PWD/* $$PWD/animations/* $$PWD/areachart/* $$PWD/axis/* $$PWD/barchart/* $$PWD/legend/* $$PWD/linechart/* $$PWD/piechart/* $$PWD/scatterchart/* $$PWD/splinechart/* $$PWD/themes/* $$PWD/xychart/* -o ../coverage/base.info;\ |
|
249 | lcov -e ../coverage/base.info $$PWD/* $$PWD/animations/* $$PWD/areachart/* $$PWD/axis/* $$PWD/barchart/* $$PWD/legend/* $$PWD/linechart/* $$PWD/piechart/* $$PWD/scatterchart/* $$PWD/splinechart/* $$PWD/themes/* $$PWD/xychart/* -o ../coverage/base.info;\ | |
249 | lcov -e ../coverage/src.info $$PWD/* $$PWD/animations/* $$PWD/areachart/* $$PWD/axis/* $$PWD/barchart/* $$PWD/legend/* $$PWD/linechart/* $$PWD/piechart/* $$PWD/scatterchart/* $$PWD/splinechart/* $$PWD/themes/* $$PWD/xychart/* -o ../coverage/src.info;\ |
|
250 | lcov -e ../coverage/src.info $$PWD/* $$PWD/animations/* $$PWD/areachart/* $$PWD/axis/* $$PWD/barchart/* $$PWD/legend/* $$PWD/linechart/* $$PWD/piechart/* $$PWD/scatterchart/* $$PWD/splinechart/* $$PWD/themes/* $$PWD/xychart/* -o ../coverage/src.info;\ | |
250 | lcov -a ../coverage/base.info -a ../coverage/src.info -o ../coverage/coverage.info; |
|
251 | lcov -a ../coverage/base.info -a ../coverage/src.info -o ../coverage/coverage.info; | |
251 | } |
|
252 | } | |
252 |
|
253 |
General Comments 0
You need to be logged in to leave comments.
Login now