##// END OF EJS Templates
Increses margins prescision
Michal Klocek -
r874:fcf207f30c3f
parent child
Show More
@@ -1,126 +1,126
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 CHARTPRESENTER_H_
21 #ifndef CHARTPRESENTER_H_
22 #define CHARTPRESENTER_H_
22 #define CHARTPRESENTER_H_
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "chartbackground_p.h" //TODO fix me
25 #include "chartbackground_p.h" //TODO fix me
26 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
26 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
27 #include "qchartaxis.h"
27 #include "qchartaxis.h"
28 #include <QRectF>
28 #include <QRectF>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class Chart;
32 class Chart;
33 class QSeries;
33 class QSeries;
34 class ChartDataSet;
34 class ChartDataSet;
35 class Domain;
35 class Domain;
36 class Axis;
36 class Axis;
37 class ChartTheme;
37 class ChartTheme;
38 class ChartAnimator;
38 class ChartAnimator;
39
39
40 class ChartPresenter: public QObject
40 class ChartPresenter: public QObject
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 enum ZValues {
44 enum ZValues {
45 BackgroundZValue = -1,
45 BackgroundZValue = -1,
46 ShadesZValue,
46 ShadesZValue,
47 GridZValue,
47 GridZValue,
48 LineChartZValue,
48 LineChartZValue,
49 BarSeriesZValue,
49 BarSeriesZValue,
50 ScatterSeriesZValue,
50 ScatterSeriesZValue,
51 PieSeriesZValue,
51 PieSeriesZValue,
52 AxisZValue,
52 AxisZValue,
53 LegendZValue
53 LegendZValue
54 };
54 };
55
55
56 ChartPresenter(QChart* chart,ChartDataSet *dataset);
56 ChartPresenter(QChart* chart,ChartDataSet *dataset);
57 virtual ~ChartPresenter();
57 virtual ~ChartPresenter();
58
58
59 ChartAnimator* animator() const { return m_animator; }
59 ChartAnimator* animator() const { return m_animator; }
60 ChartTheme *chartTheme() const { return m_chartTheme; }
60 ChartTheme *chartTheme() const { return m_chartTheme; }
61 ChartDataSet *dataSet() const { return m_dataset; }
61 ChartDataSet *dataSet() const { return m_dataset; }
62 QGraphicsItem* rootItem() const { return m_chart; }
62 QGraphicsItem* rootItem() const { return m_chart; }
63
63
64 void setTheme(QChart::ChartTheme theme,bool force = true);
64 void setTheme(QChart::ChartTheme theme,bool force = true);
65 QChart::ChartTheme theme();
65 QChart::ChartTheme theme();
66
66
67 void setAnimationOptions(QChart::AnimationOptions options);
67 void setAnimationOptions(QChart::AnimationOptions options);
68 QChart::AnimationOptions animationOptions() const;
68 QChart::AnimationOptions animationOptions() const;
69
69
70 void zoomIn();
70 void zoomIn();
71 void zoomIn(const QRectF& rect);
71 void zoomIn(const QRectF& rect);
72 void zoomOut();
72 void zoomOut();
73 void scroll(int dx,int dy);
73 void scroll(int dx,int dy);
74
74
75 void setGeometry(const QRectF& rect);
75 void setGeometry(const QRectF& rect);
76 QRectF chartGeometry() const { return m_chartRect; }
76 QRectF chartGeometry() const { return m_chartRect; }
77
77
78 void setMinimumMarginHeight(Axis* axis, qreal height);
78 void setMinimumMarginHeight(Axis* axis, qreal height);
79 void setMinimumMarginWidth(Axis* axis, qreal width);
79 void setMinimumMarginWidth(Axis* axis, qreal width);
80 qreal minimumLeftMargin() const { return m_minLeftMargin; }
80 qreal minimumLeftMargin() const { return m_minLeftMargin; }
81 qreal minimumBottomMargin() const { return m_minBottomMargin; }
81 qreal minimumBottomMargin() const { return m_minBottomMargin; }
82
82
83 public: //TODO: fix me
83 public: //TODO: fix me
84 void resetAllElements();
84 void resetAllElements();
85 void createChartBackgroundItem();
85 void createChartBackgroundItem();
86 void createChartTitleItem();
86 void createChartTitleItem();
87 QRect margins() const { return m_chartMargins;}
87 QRectF margins() const { return m_chartMargins;}
88
88
89 public Q_SLOTS:
89 public Q_SLOTS:
90 void handleSeriesAdded(QSeries* series,Domain* domain);
90 void handleSeriesAdded(QSeries* series,Domain* domain);
91 void handleSeriesRemoved(QSeries* series);
91 void handleSeriesRemoved(QSeries* series);
92 void handleAxisAdded(QChartAxis* axis,Domain* domain);
92 void handleAxisAdded(QChartAxis* axis,Domain* domain);
93 void handleAxisRemoved(QChartAxis* axis);
93 void handleAxisRemoved(QChartAxis* axis);
94 void updateLayout();
94 void updateLayout();
95
95
96 Q_SIGNALS:
96 Q_SIGNALS:
97 void geometryChanged(const QRectF& rect);
97 void geometryChanged(const QRectF& rect);
98
98
99
99
100 private:
100 private:
101 QChart* m_chart;
101 QChart* m_chart;
102 ChartAnimator* m_animator;
102 ChartAnimator* m_animator;
103 ChartDataSet* m_dataset;
103 ChartDataSet* m_dataset;
104 ChartTheme *m_chartTheme;
104 ChartTheme *m_chartTheme;
105 QMap<QSeries*,Chart*> m_chartItems;
105 QMap<QSeries*,Chart*> m_chartItems;
106 QMap<QChartAxis*,Axis*> m_axisItems;
106 QMap<QChartAxis*,Axis*> m_axisItems;
107 QRectF m_rect;
107 QRectF m_rect;
108 QRectF m_chartRect;
108 QRectF m_chartRect;
109 QChart::AnimationOptions m_options;
109 QChart::AnimationOptions m_options;
110 bool m_themeForce;
110 bool m_themeForce;
111 qreal m_minLeftMargin;
111 qreal m_minLeftMargin;
112 qreal m_minBottomMargin;
112 qreal m_minBottomMargin;
113 public: //TODO: fixme
113 public: //TODO: fixme
114 ChartBackground* m_backgroundItem;
114 ChartBackground* m_backgroundItem;
115 QGraphicsSimpleTextItem* m_titleItem;
115 QGraphicsSimpleTextItem* m_titleItem;
116 int m_marginBig;
116 int m_marginBig;
117 int m_marginSmall;
117 int m_marginSmall;
118 int m_marginTiny;
118 int m_marginTiny;
119 QRect m_chartMargins;
119 QRectF m_chartMargins;
120 QRect m_legendMargins;
120 QRectF m_legendMargins;
121
121
122 };
122 };
123
123
124 QTCOMMERCIALCHART_END_NAMESPACE
124 QTCOMMERCIALCHART_END_NAMESPACE
125
125
126 #endif /* CHARTPRESENTER_H_ */
126 #endif /* CHARTPRESENTER_H_ */
@@ -1,371 +1,371
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 <QGraphicsScene>
23 #include <QGraphicsScene>
24 #include <QGraphicsSceneResizeEvent>
24 #include <QGraphicsSceneResizeEvent>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \enum QChart::ChartTheme
29 \enum QChart::ChartTheme
30
30
31 This enum describes the theme used by the chart.
31 This enum describes the theme used by the chart.
32
32
33 \value ChartThemeLight The default theme
33 \value ChartThemeLight The default theme
34 \value ChartThemeBlueCerulean
34 \value ChartThemeBlueCerulean
35 \value ChartThemeDark
35 \value ChartThemeDark
36 \value ChartThemeBrownSand
36 \value ChartThemeBrownSand
37 \value ChartThemeBlueNcs
37 \value ChartThemeBlueNcs
38 \value ChartThemeHighContrast
38 \value ChartThemeHighContrast
39 \value ChartThemeBlueIcy
39 \value ChartThemeBlueIcy
40 \value ChartThemeCount Not really a theme; the total count of themes.
40 \value ChartThemeCount Not really a theme; the total count of themes.
41 */
41 */
42
42
43 /*!
43 /*!
44 \enum QChart::AnimationOption
44 \enum QChart::AnimationOption
45
45
46 For enabling/disabling animations. Defaults to NoAnimation.
46 For enabling/disabling animations. Defaults to NoAnimation.
47
47
48 \value NoAnimation
48 \value NoAnimation
49 \value GridAxisAnimations
49 \value GridAxisAnimations
50 \value SeriesAnimations
50 \value SeriesAnimations
51 \value AllAnimations
51 \value AllAnimations
52 */
52 */
53
53
54 /*!
54 /*!
55 \class QChart
55 \class QChart
56 \brief QtCommercial chart API.
56 \brief QtCommercial chart API.
57
57
58 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
58 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
59 representation of different types of QChartSeries and other chart related objects like
59 representation of different types of QChartSeries and other chart related objects like
60 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
60 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
61 convenience class QChartView instead of QChart.
61 convenience class QChartView instead of QChart.
62 \sa QChartView
62 \sa QChartView
63 */
63 */
64
64
65 /*!
65 /*!
66 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
66 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
67 */
67 */
68 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
68 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
69 d_ptr(new QChartPrivate())
69 d_ptr(new QChartPrivate())
70 {
70 {
71 d_ptr->m_legend = new ScrolledQLegend(this);
71 d_ptr->m_legend = new ScrolledQLegend(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
75 d_ptr->createConnections();
75 d_ptr->createConnections();
76 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
76 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
77 }
77 }
78
78
79 /*!
79 /*!
80 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
80 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
81 */
81 */
82 QChart::~QChart()
82 QChart::~QChart()
83 {
83 {
84 //delete first presenter , since this is a root of all the graphical items
84 //delete first presenter , since this is a root of all the graphical items
85 delete d_ptr->m_presenter;
85 delete d_ptr->m_presenter;
86 d_ptr->m_presenter=0;
86 d_ptr->m_presenter=0;
87 }
87 }
88
88
89 /*!
89 /*!
90 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
90 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
91 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
91 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
92 the y axis).
92 the y axis).
93 */
93 */
94 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
94 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
95 {
95 {
96 d_ptr->m_dataset->addSeries(series, axisY);
96 d_ptr->m_dataset->addSeries(series, axisY);
97 }
97 }
98
98
99 /*!
99 /*!
100 Removes the \a series specified in a perameter from the QChartView.
100 Removes the \a series specified in a perameter from the QChartView.
101 It releses its ownership of the specified QChartSeries object.
101 It releses its ownership of the specified QChartSeries object.
102 It does not delete the pointed QChartSeries data object
102 It does not delete the pointed QChartSeries data object
103 \sa addSeries(), removeAllSeries()
103 \sa addSeries(), removeAllSeries()
104 */
104 */
105 void QChart::removeSeries(QSeries* series)
105 void QChart::removeSeries(QSeries* series)
106 {
106 {
107 d_ptr->m_dataset->removeSeries(series);
107 d_ptr->m_dataset->removeSeries(series);
108 }
108 }
109
109
110 /*!
110 /*!
111 Removes all the QChartSeries that have been added to the QChartView
111 Removes all the QChartSeries that have been added to the QChartView
112 It also deletes the pointed QChartSeries data objects
112 It also deletes the pointed QChartSeries data objects
113 \sa addSeries(), removeSeries()
113 \sa addSeries(), removeSeries()
114 */
114 */
115 void QChart::removeAllSeries()
115 void QChart::removeAllSeries()
116 {
116 {
117 d_ptr->m_dataset->removeAllSeries();
117 d_ptr->m_dataset->removeAllSeries();
118 }
118 }
119
119
120 /*!
120 /*!
121 Sets the \a brush that is used for painting the background of the chart area.
121 Sets the \a brush that is used for painting the background of the chart area.
122 */
122 */
123 void QChart::setBackgroundBrush(const QBrush& brush)
123 void QChart::setBackgroundBrush(const QBrush& brush)
124 {
124 {
125 //TODO: refactor me
125 //TODO: refactor me
126 d_ptr->m_presenter->createChartBackgroundItem();
126 d_ptr->m_presenter->createChartBackgroundItem();
127 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
127 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
128 d_ptr->m_presenter->m_backgroundItem->update();
128 d_ptr->m_presenter->m_backgroundItem->update();
129 }
129 }
130
130
131 QBrush QChart::backgroundBrush() const
131 QBrush QChart::backgroundBrush() const
132 {
132 {
133 //TODO: refactor me
133 //TODO: refactor me
134 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
134 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
135 return (d_ptr->m_presenter->m_backgroundItem)->brush();
135 return (d_ptr->m_presenter->m_backgroundItem)->brush();
136 }
136 }
137
137
138 /*!
138 /*!
139 Sets the \a pen that is used for painting the background of the chart area.
139 Sets the \a pen that is used for painting the background of the chart area.
140 */
140 */
141 void QChart::setBackgroundPen(const QPen& pen)
141 void QChart::setBackgroundPen(const QPen& pen)
142 {
142 {
143 //TODO: refactor me
143 //TODO: refactor me
144 d_ptr->m_presenter->createChartBackgroundItem();
144 d_ptr->m_presenter->createChartBackgroundItem();
145 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
145 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
146 d_ptr->m_presenter->m_backgroundItem->update();
146 d_ptr->m_presenter->m_backgroundItem->update();
147 }
147 }
148
148
149 QPen QChart::backgroundPen() const
149 QPen QChart::backgroundPen() const
150 {
150 {
151 //TODO: refactor me
151 //TODO: refactor me
152 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
152 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
153 return d_ptr->m_presenter->m_backgroundItem->pen();
153 return d_ptr->m_presenter->m_backgroundItem->pen();
154 }
154 }
155
155
156 /*!
156 /*!
157 Sets the chart \a title. The description text that is drawn above the chart.
157 Sets the chart \a title. The description text that is drawn above the chart.
158 */
158 */
159 void QChart::setTitle(const QString& title)
159 void QChart::setTitle(const QString& title)
160 {
160 {
161 //TODO: refactor me
161 //TODO: refactor me
162 d_ptr->m_presenter->createChartTitleItem();
162 d_ptr->m_presenter->createChartTitleItem();
163 d_ptr->m_presenter->m_titleItem->setText(title);
163 d_ptr->m_presenter->m_titleItem->setText(title);
164 d_ptr->m_presenter->updateLayout();
164 d_ptr->m_presenter->updateLayout();
165 }
165 }
166
166
167 /*!
167 /*!
168 Returns the chart title. The description text that is drawn above the chart.
168 Returns the chart title. The description text that is drawn above the chart.
169 */
169 */
170 QString QChart::title() const
170 QString QChart::title() const
171 {
171 {
172 //TODO: refactor me
172 //TODO: refactor me
173 if (d_ptr->m_presenter->m_titleItem)
173 if (d_ptr->m_presenter->m_titleItem)
174 return d_ptr->m_presenter->m_titleItem->text();
174 return d_ptr->m_presenter->m_titleItem->text();
175 else
175 else
176 return QString();
176 return QString();
177 }
177 }
178
178
179 /*!
179 /*!
180 Sets the \a font that is used for rendering the description text that is rendered above the chart.
180 Sets the \a font that is used for rendering the description text that is rendered above the chart.
181 */
181 */
182 void QChart::setTitleFont(const QFont& font)
182 void QChart::setTitleFont(const QFont& font)
183 {
183 {
184 //TODO: refactor me
184 //TODO: refactor me
185 d_ptr->m_presenter->createChartTitleItem();
185 d_ptr->m_presenter->createChartTitleItem();
186 d_ptr->m_presenter->m_titleItem->setFont(font);
186 d_ptr->m_presenter->m_titleItem->setFont(font);
187 d_ptr->m_presenter->updateLayout();
187 d_ptr->m_presenter->updateLayout();
188 }
188 }
189
189
190 /*!
190 /*!
191 Sets the \a brush used for rendering the title text.
191 Sets the \a brush used for rendering the title text.
192 */
192 */
193 void QChart::setTitleBrush(const QBrush &brush)
193 void QChart::setTitleBrush(const QBrush &brush)
194 {
194 {
195 //TODO: refactor me
195 //TODO: refactor me
196 d_ptr->m_presenter->createChartTitleItem();
196 d_ptr->m_presenter->createChartTitleItem();
197 d_ptr->m_presenter->m_titleItem->setBrush(brush);
197 d_ptr->m_presenter->m_titleItem->setBrush(brush);
198 d_ptr->m_presenter->updateLayout();
198 d_ptr->m_presenter->updateLayout();
199 }
199 }
200
200
201 /*!
201 /*!
202 Returns the brush used for rendering the title text.
202 Returns the brush used for rendering the title text.
203 */
203 */
204 QBrush QChart::titleBrush() const
204 QBrush QChart::titleBrush() const
205 {
205 {
206 //TODO: refactor me
206 //TODO: refactor me
207 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
207 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
208 return d_ptr->m_presenter->m_titleItem->brush();
208 return d_ptr->m_presenter->m_titleItem->brush();
209 }
209 }
210
210
211 /*!
211 /*!
212 Sets the \a theme used by the chart for rendering the graphical representation of the data
212 Sets the \a theme used by the chart for rendering the graphical representation of the data
213 \sa ChartTheme, chartTheme()
213 \sa ChartTheme, chartTheme()
214 */
214 */
215 void QChart::setTheme(QChart::ChartTheme theme)
215 void QChart::setTheme(QChart::ChartTheme theme)
216 {
216 {
217 d_ptr->m_presenter->setTheme(theme);
217 d_ptr->m_presenter->setTheme(theme);
218 }
218 }
219
219
220 /*!
220 /*!
221 Returns the theme enum used by the chart.
221 Returns the theme enum used by the chart.
222 \sa ChartTheme, setChartTheme()
222 \sa ChartTheme, setChartTheme()
223 */
223 */
224 QChart::ChartTheme QChart::theme() const
224 QChart::ChartTheme QChart::theme() const
225 {
225 {
226 return d_ptr->m_presenter->theme();
226 return d_ptr->m_presenter->theme();
227 }
227 }
228
228
229 /*!
229 /*!
230 Zooms in the view by a factor of 2
230 Zooms in the view by a factor of 2
231 */
231 */
232 void QChart::zoomIn()
232 void QChart::zoomIn()
233 {
233 {
234 d_ptr->m_presenter->zoomIn();
234 d_ptr->m_presenter->zoomIn();
235 }
235 }
236
236
237 /*!
237 /*!
238 Zooms in the view to a maximum level at which \a rect is still fully visible.
238 Zooms in the view to a maximum level at which \a rect is still fully visible.
239 */
239 */
240 void QChart::zoomIn(const QRectF& rect)
240 void QChart::zoomIn(const QRectF& rect)
241 {
241 {
242 if (!rect.isValid()) return;
242 if (!rect.isValid()) return;
243 d_ptr->m_presenter->zoomIn(rect);
243 d_ptr->m_presenter->zoomIn(rect);
244 }
244 }
245
245
246 /*!
246 /*!
247 Restores the view zoom level to the previous one.
247 Restores the view zoom level to the previous one.
248 */
248 */
249 void QChart::zoomOut()
249 void QChart::zoomOut()
250 {
250 {
251 d_ptr->m_presenter->zoomOut();
251 d_ptr->m_presenter->zoomOut();
252 }
252 }
253
253
254 /*!
254 /*!
255 Returns the pointer to the x axis object of the chart
255 Returns the pointer to the x axis object of the chart
256 */
256 */
257 QChartAxis* QChart::axisX() const
257 QChartAxis* QChart::axisX() const
258 {
258 {
259 return d_ptr->m_dataset->axisX();
259 return d_ptr->m_dataset->axisX();
260 }
260 }
261
261
262 /*!
262 /*!
263 Returns the pointer to the y axis object of the chart
263 Returns the pointer to the y axis object of the chart
264 */
264 */
265 QChartAxis* QChart::axisY() const
265 QChartAxis* QChart::axisY() const
266 {
266 {
267 return d_ptr->m_dataset->axisY();
267 return d_ptr->m_dataset->axisY();
268 }
268 }
269
269
270 /*!
270 /*!
271 Returns the legend object of the chart. Ownership stays in chart.
271 Returns the legend object of the chart. Ownership stays in chart.
272 */
272 */
273 QLegend* QChart::legend() const
273 QLegend* QChart::legend() const
274 {
274 {
275 return d_ptr->m_legend;
275 return d_ptr->m_legend;
276 }
276 }
277
277
278 QRect QChart::margins() const
278 QRectF QChart::margins() const
279 {
279 {
280 return d_ptr->m_presenter->margins();
280 return d_ptr->m_presenter->margins();
281 }
281 }
282
282
283
283
284 /*!
284 /*!
285 Resizes and updates the chart area using the \a event data
285 Resizes and updates the chart area using the \a event data
286 */
286 */
287 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
287 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
288 {
288 {
289 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
289 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
290 QGraphicsWidget::resizeEvent(event);
290 QGraphicsWidget::resizeEvent(event);
291 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
291 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
292 }
292 }
293
293
294 /*!
294 /*!
295 Sets animation \a options for the chart
295 Sets animation \a options for the chart
296 */
296 */
297 void QChart::setAnimationOptions(AnimationOptions options)
297 void QChart::setAnimationOptions(AnimationOptions options)
298 {
298 {
299 d_ptr->m_presenter->setAnimationOptions(options);
299 d_ptr->m_presenter->setAnimationOptions(options);
300 }
300 }
301
301
302 /*!
302 /*!
303 Returns animation options for the chart
303 Returns animation options for the chart
304 */
304 */
305 QChart::AnimationOptions QChart::animationOptions() const
305 QChart::AnimationOptions QChart::animationOptions() const
306 {
306 {
307 return d_ptr->m_presenter->animationOptions();
307 return d_ptr->m_presenter->animationOptions();
308 }
308 }
309
309
310 void QChart::scrollLeft()
310 void QChart::scrollLeft()
311 {
311 {
312 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
312 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
313 }
313 }
314
314
315 void QChart::scrollRight()
315 void QChart::scrollRight()
316 {
316 {
317 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
317 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
318 }
318 }
319
319
320 void QChart::scrollUp()
320 void QChart::scrollUp()
321 {
321 {
322 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
322 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
323 }
323 }
324
324
325 void QChart::scrollDown()
325 void QChart::scrollDown()
326 {
326 {
327 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
327 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
328 }
328 }
329
329
330 void QChart::setBackgroundVisible(bool visible)
330 void QChart::setBackgroundVisible(bool visible)
331 {
331 {
332 //TODO: refactor me
332 //TODO: refactor me
333 d_ptr->m_presenter->createChartBackgroundItem();
333 d_ptr->m_presenter->createChartBackgroundItem();
334 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
334 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
335 }
335 }
336
336
337 bool QChart::isBackgroundVisible() const
337 bool QChart::isBackgroundVisible() const
338 {
338 {
339 //TODO: refactor me
339 //TODO: refactor me
340 if (!d_ptr->m_presenter->m_backgroundItem) return false;
340 if (!d_ptr->m_presenter->m_backgroundItem) return false;
341 return d_ptr->m_presenter->m_backgroundItem->isVisible();
341 return d_ptr->m_presenter->m_backgroundItem->isVisible();
342 }
342 }
343
343
344 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
344 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
345
345
346 QChartPrivate::QChartPrivate():
346 QChartPrivate::QChartPrivate():
347 m_legend(0),
347 m_legend(0),
348 m_dataset(0),
348 m_dataset(0),
349 m_presenter(0)
349 m_presenter(0)
350 {
350 {
351
351
352 }
352 }
353
353
354 QChartPrivate::~QChartPrivate()
354 QChartPrivate::~QChartPrivate()
355 {
355 {
356
356
357 }
357 }
358
358
359 void QChartPrivate::createConnections()
359 void QChartPrivate::createConnections()
360 {
360 {
361 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
361 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
362 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
362 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
363 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*)));
363 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*)));
364 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*)));
364 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*)));
365 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
365 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
366 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*)));
366 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*)));
367 }
367 }
368
368
369 #include "moc_qchart.cpp"
369 #include "moc_qchart.cpp"
370
370
371 QTCOMMERCIALCHART_END_NAMESPACE
371 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,118 +1,119
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCHART_H
21 #ifndef QCHART_H
22 #define QCHART_H
22 #define QCHART_H
23
23
24 #include <QSeries>
24 #include <QSeries>
25 #include <QGraphicsWidget>
25 #include <QGraphicsWidget>
26
26
27 class QGraphicsSceneResizeEvent;
27 class QGraphicsSceneResizeEvent;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QSeries;
31 class QSeries;
32 class QChartAxis;
32 class QChartAxis;
33 class QLegend;
33 class QLegend;
34 struct QChartPrivate;
34 struct QChartPrivate;
35
35
36 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
36 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_ENUMS(ChartTheme)
39 Q_ENUMS(ChartTheme)
40
40
41 public:
41 public:
42 enum ChartTheme {
42 enum ChartTheme {
43 ChartThemeLight = 0,
43 ChartThemeLight = 0,
44 ChartThemeBlueCerulean,
44 ChartThemeBlueCerulean,
45 ChartThemeDark,
45 ChartThemeDark,
46 ChartThemeBrownSand,
46 ChartThemeBrownSand,
47 ChartThemeBlueNcs,
47 ChartThemeBlueNcs,
48 ChartThemeHighContrast,
48 ChartThemeHighContrast,
49 ChartThemeBlueIcy,
49 ChartThemeBlueIcy,
50 ChartThemeCount
50 ChartThemeCount
51 };
51 };
52
52
53 enum AnimationOption {
53 enum AnimationOption {
54 NoAnimation = 0x0,
54 NoAnimation = 0x0,
55 GridAxisAnimations = 0x1,
55 GridAxisAnimations = 0x1,
56 SeriesAnimations =0x2,
56 SeriesAnimations =0x2,
57 AllAnimations = 0x3
57 AllAnimations = 0x3
58 };
58 };
59
59
60 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
60 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
61
61
62 public:
62 public:
63 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
63 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
64 ~QChart();
64 ~QChart();
65
65
66 void addSeries(QSeries *series, QChartAxis *axisY = 0);
66 void addSeries(QSeries *series, QChartAxis *axisY = 0);
67 void removeSeries(QSeries *series);
67 void removeSeries(QSeries *series);
68 void removeAllSeries();
68 void removeAllSeries();
69
69
70 void setTheme(QChart::ChartTheme theme);
70 void setTheme(QChart::ChartTheme theme);
71 QChart::ChartTheme theme() const;
71 QChart::ChartTheme theme() const;
72
72
73 void setTitle(const QString& title);
73 void setTitle(const QString& title);
74 QString title() const;
74 QString title() const;
75 void setTitleFont(const QFont& font);
75 void setTitleFont(const QFont& font);
76 QFont titleFont() const;
76 QFont titleFont() const;
77 void setTitleBrush(const QBrush &brush);
77 void setTitleBrush(const QBrush &brush);
78 QBrush titleBrush() const;
78 QBrush titleBrush() const;
79
79 void setBackgroundBrush(const QBrush &brush);
80 void setBackgroundBrush(const QBrush &brush);
80 QBrush backgroundBrush() const;
81 QBrush backgroundBrush() const;
81 void setBackgroundPen(const QPen &pen);
82 void setBackgroundPen(const QPen &pen);
82 QPen backgroundPen() const;
83 QPen backgroundPen() const;
83
84
84 void setBackgroundVisible(bool visible);
85 void setBackgroundVisible(bool visible);
85 bool isBackgroundVisible() const;
86 bool isBackgroundVisible() const;
86
87
87 void setAnimationOptions(AnimationOptions options);
88 void setAnimationOptions(AnimationOptions options);
88 AnimationOptions animationOptions() const;
89 AnimationOptions animationOptions() const;
89
90
90 void zoomIn();
91 void zoomIn();
91 void zoomIn(const QRectF &rect);
92 void zoomIn(const QRectF &rect);
92 void zoomOut();
93 void zoomOut();
93 void scrollLeft();
94 void scrollLeft();
94 void scrollRight();
95 void scrollRight();
95 void scrollUp();
96 void scrollUp();
96 void scrollDown();
97 void scrollDown();
97
98
98 QChartAxis* axisX() const;
99 QChartAxis* axisX() const;
99 QChartAxis* axisY() const;
100 QChartAxis* axisY() const;
100
101
101 QLegend* legend() const;
102 QLegend* legend() const;
102 QRect margins() const;
103 QRectF margins() const;
103
104
104 protected:
105 protected:
105 void resizeEvent(QGraphicsSceneResizeEvent *event);
106 void resizeEvent(QGraphicsSceneResizeEvent *event);
106
107
107 protected:
108 protected:
108 QScopedPointer<QChartPrivate> d_ptr;
109 QScopedPointer<QChartPrivate> d_ptr;
109 friend class QLegend;
110 friend class QLegend;
110 friend class ChartPresenter;
111 friend class ChartPresenter;
111 Q_DISABLE_COPY(QChart)
112 Q_DISABLE_COPY(QChart)
112 };
113 };
113
114
114 QTCOMMERCIALCHART_END_NAMESPACE
115 QTCOMMERCIALCHART_END_NAMESPACE
115
116
116 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
117 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
117
118
118 #endif
119 #endif
@@ -1,244 +1,245
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 "qchartview.h"
21 #include "qchartview.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qchartview_p.h"
23 #include "qchartview_p.h"
24 #include <QGraphicsScene>
24 #include <QGraphicsScene>
25 #include <QRubberBand>
25 #include <QRubberBand>
26
26
27
27
28 /*!
28 /*!
29 \enum QChartView::RubberBandPolicy
29 \enum QChartView::RubberBandPolicy
30
30
31 This enum describes the different types of rubber bands that can be used for zoom rect selection
31 This enum describes the different types of rubber bands that can be used for zoom rect selection
32
32
33 \value NoRubberBand
33 \value NoRubberBand
34 \value VerticalRubberBand
34 \value VerticalRubberBand
35 \value HorizonalRubberBand
35 \value HorizonalRubberBand
36 \value RectangleRubberBand
36 \value RectangleRubberBand
37 */
37 */
38
38
39 /*!
39 /*!
40 \class QChartView
40 \class QChartView
41 \brief Standalone charting widget.
41 \brief Standalone charting widget.
42
42
43 QChartView is a standalone widget that can display charts. It does not require separate
43 QChartView is a standalone widget that can display charts. It does not require separate
44 QGraphicsScene to work. It manages the graphical representation of different types of
44 QGraphicsScene to work. It manages the graphical representation of different types of
45 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
45 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
46 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
46 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
47
47
48 \sa QChart
48 \sa QChart
49 */
49 */
50
50
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52
52
53 /*!
53 /*!
54 Constructs a chartView object which is a child of a\a parent.
54 Constructs a chartView object which is a child of a\a parent.
55 */
55 */
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
57 QGraphicsView(parent),
57 QGraphicsView(parent),
58 d_ptr(new QChartViewPrivate())
58 d_ptr(new QChartViewPrivate())
59 {
59 {
60 d_ptr->m_scene = new QGraphicsScene(this);
60 d_ptr->m_scene = new QGraphicsScene(this);
61 d_ptr->m_chart = chart;
61 d_ptr->m_chart = chart;
62 setFrameShape(QFrame::NoFrame);
62 setFrameShape(QFrame::NoFrame);
63 setBackgroundRole(QPalette::Window);
63 setBackgroundRole(QPalette::Window);
64 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
64 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setScene(d_ptr->m_scene);
66 setScene(d_ptr->m_scene);
67 d_ptr->m_scene->addItem(chart);
67 d_ptr->m_scene->addItem(chart);
68 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
68 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69 }
69 }
70
70
71
71
72 /*!
72 /*!
73 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
73 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
74 */
74 */
75 QChartView::~QChartView()
75 QChartView::~QChartView()
76 {
76 {
77 }
77 }
78
78
79 QChart* QChartView::chart() const
79 QChart* QChartView::chart() const
80 {
80 {
81 return d_ptr->m_chart;
81 return d_ptr->m_chart;
82 }
82 }
83
83
84 /*!
84 /*!
85 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
85 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
86 */
86 */
87 void QChartView::setRubberBand(const RubberBands& rubberBand)
87 void QChartView::setRubberBand(const RubberBands& rubberBand)
88 {
88 {
89 d_ptr->m_rubberBandFlags=rubberBand;
89 d_ptr->m_rubberBandFlags=rubberBand;
90
90
91 if (!d_ptr->m_rubberBandFlags) {
91 if (!d_ptr->m_rubberBandFlags) {
92 delete d_ptr->m_rubberBand;
92 delete d_ptr->m_rubberBand;
93 d_ptr->m_rubberBand=0;
93 d_ptr->m_rubberBand=0;
94 return;
94 return;
95 }
95 }
96
96
97 if (!d_ptr->m_rubberBand) {
97 if (!d_ptr->m_rubberBand) {
98 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
98 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
99 d_ptr->m_rubberBand->setEnabled(true);
99 d_ptr->m_rubberBand->setEnabled(true);
100 }
100 }
101 }
101 }
102
102
103 /*!
103 /*!
104 Returns the RubberBandPolicy that is currently being used by the widget.
104 Returns the RubberBandPolicy that is currently being used by the widget.
105 */
105 */
106 QChartView::RubberBands QChartView::rubberBand() const
106 QChartView::RubberBands QChartView::rubberBand() const
107 {
107 {
108 return d_ptr->m_rubberBandFlags;
108 return d_ptr->m_rubberBandFlags;
109 }
109 }
110
110
111 /*!
111 /*!
112 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
112 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
113 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
113 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
114 */
114 */
115 void QChartView::mousePressEvent(QMouseEvent *event)
115 void QChartView::mousePressEvent(QMouseEvent *event)
116 {
116 {
117 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
117 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
118
118
119 int padding = d_ptr->m_chart->margins().top();
119 int padding = d_ptr->m_chart->margins().top();
120 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
120 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
121
121
122 if (rect.contains(event->pos())) {
122 if (rect.contains(event->pos())) {
123 d_ptr->m_rubberBandOrigin = event->pos();
123 d_ptr->m_rubberBandOrigin = event->pos();
124 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
124 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
125 d_ptr->m_rubberBand->show();
125 d_ptr->m_rubberBand->show();
126 event->accept();
126 event->accept();
127 }
127 }
128 }
128 }
129 else {
129 else {
130 QGraphicsView::mousePressEvent(event);
130 QGraphicsView::mousePressEvent(event);
131 }
131 }
132 }
132 }
133
133
134 /*!
134 /*!
135 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
135 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
136 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
136 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
137 */
137 */
138 void QChartView::mouseMoveEvent(QMouseEvent *event)
138 void QChartView::mouseMoveEvent(QMouseEvent *event)
139 {
139 {
140 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
140 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
141 int padding = d_ptr->m_chart->margins().top();
141 QRectF margins = d_ptr->m_chart->margins();
142 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
142 QRectF geometry = d_ptr->m_chart->geometry();
143 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
143 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
144 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
144 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
145 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
145 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
146 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
146 d_ptr->m_rubberBandOrigin.setY(rect.top());
147 d_ptr->m_rubberBandOrigin.setY(rect.top());
147 height = rect.height();
148 height = rect.height();
148 }
149 }
149 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
150 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
150 d_ptr->m_rubberBandOrigin.setX(rect.left());
151 d_ptr->m_rubberBandOrigin.setX(rect.left());
151 width= rect.width();
152 width= rect.width();
152 }
153 }
153 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
154 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
154 }
155 }
155 else {
156 else {
156 QGraphicsView::mouseMoveEvent(event);
157 QGraphicsView::mouseMoveEvent(event);
157 }
158 }
158 }
159 }
159
160
160 /*!
161 /*!
161 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
162 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
162 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
163 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
163 */
164 */
164 void QChartView::mouseReleaseEvent(QMouseEvent *event)
165 void QChartView::mouseReleaseEvent(QMouseEvent *event)
165 {
166 {
166 if(d_ptr->m_rubberBand) {
167 if(d_ptr->m_rubberBand) {
167 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
168 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
168 d_ptr->m_rubberBand->hide();
169 d_ptr->m_rubberBand->hide();
169 QRect rect = d_ptr->m_rubberBand->geometry();
170 QRect rect = d_ptr->m_rubberBand->geometry();
170 d_ptr->m_chart->zoomIn(rect);
171 d_ptr->m_chart->zoomIn(rect);
171 event->accept();
172 event->accept();
172 }
173 }
173
174
174 if(event->button()==Qt::RightButton){
175 if(event->button()==Qt::RightButton){
175 d_ptr->m_chart->zoomOut();
176 d_ptr->m_chart->zoomOut();
176 event->accept();
177 event->accept();
177 }
178 }
178 }
179 }
179 else {
180 else {
180 QGraphicsView::mouseReleaseEvent(event);
181 QGraphicsView::mouseReleaseEvent(event);
181 }
182 }
182 }
183 }
183
184
184 /*!
185 /*!
185 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
186 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
186 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
187 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
187 */
188 */
188 void QChartView::keyPressEvent(QKeyEvent *event)
189 void QChartView::keyPressEvent(QKeyEvent *event)
189 {
190 {
190 switch (event->key()) {
191 switch (event->key()) {
191 case Qt::Key_Plus:
192 case Qt::Key_Plus:
192 d_ptr->m_chart->zoomIn();
193 d_ptr->m_chart->zoomIn();
193 break;
194 break;
194 case Qt::Key_Minus:
195 case Qt::Key_Minus:
195 d_ptr->m_chart->zoomOut();
196 d_ptr->m_chart->zoomOut();
196 break;
197 break;
197 case Qt::Key_Left:
198 case Qt::Key_Left:
198 d_ptr->m_chart->scrollLeft();
199 d_ptr->m_chart->scrollLeft();
199 break;
200 break;
200 case Qt::Key_Right:
201 case Qt::Key_Right:
201 d_ptr->m_chart->scrollRight();
202 d_ptr->m_chart->scrollRight();
202 break;
203 break;
203 case Qt::Key_Up:
204 case Qt::Key_Up:
204 d_ptr->m_chart->scrollUp();
205 d_ptr->m_chart->scrollUp();
205 break;
206 break;
206 case Qt::Key_Down:
207 case Qt::Key_Down:
207 d_ptr->m_chart->scrollDown();
208 d_ptr->m_chart->scrollDown();
208 break;
209 break;
209 default:
210 default:
210 QGraphicsView::keyPressEvent(event);
211 QGraphicsView::keyPressEvent(event);
211 break;
212 break;
212 }
213 }
213 }
214 }
214
215
215 /*!
216 /*!
216 Resizes and updates the chart area using the \a event data
217 Resizes and updates the chart area using the \a event data
217 */
218 */
218 void QChartView::resizeEvent(QResizeEvent *event)
219 void QChartView::resizeEvent(QResizeEvent *event)
219 {
220 {
220 QGraphicsView::resizeEvent(event);
221 QGraphicsView::resizeEvent(event);
221 d_ptr->m_chart->resize(size());
222 d_ptr->m_chart->resize(size());
222 setSceneRect(d_ptr->m_chart->geometry());
223 setSceneRect(d_ptr->m_chart->geometry());
223 }
224 }
224
225
225 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
226 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
226
227
227 QChartViewPrivate::QChartViewPrivate():
228 QChartViewPrivate::QChartViewPrivate():
228 m_scene(0),
229 m_scene(0),
229 m_chart(0),
230 m_chart(0),
230 m_presenter(0),
231 m_presenter(0),
231 m_rubberBand(0),
232 m_rubberBand(0),
232 m_rubberBandFlags(QChartView::NoRubberBand)
233 m_rubberBandFlags(QChartView::NoRubberBand)
233 {
234 {
234
235
235 }
236 }
236
237
237 QChartViewPrivate::~QChartViewPrivate()
238 QChartViewPrivate::~QChartViewPrivate()
238 {
239 {
239
240
240 }
241 }
241
242
242 #include "moc_qchartview.cpp"
243 #include "moc_qchartview.cpp"
243
244
244 QTCOMMERCIALCHART_END_NAMESPACE
245 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,213 +1,216
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
21
22 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
23 #include <qchartview.h>
23 #include <qchartview.h>
24 #include <qlineseries.h>
24 #include <qlineseries.h>
25 #include <qlegend.h>
25 #include <cmath>
26 #include <cmath>
26
27
27 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
28
29
29
30
30 Q_DECLARE_METATYPE(QChart*)
31 Q_DECLARE_METATYPE(QChart*)
31 Q_DECLARE_METATYPE(QChartView::RubberBands)
32 Q_DECLARE_METATYPE(QChartView::RubberBands)
32 Q_DECLARE_METATYPE(Qt::Key)
33 Q_DECLARE_METATYPE(Qt::Key)
33
34
34 class tst_QChartView : public QObject
35 class tst_QChartView : public QObject
35 {
36 {
36 Q_OBJECT
37 Q_OBJECT
37
38
38 public Q_SLOTS:
39 public Q_SLOTS:
39 void initTestCase();
40 void initTestCase();
40 void cleanupTestCase();
41 void cleanupTestCase();
41 void init();
42 void init();
42 void cleanup();
43 void cleanup();
43
44
44 private Q_SLOTS:
45 private Q_SLOTS:
45 void qchartview_data();
46 void qchartview_data();
46 void qchartview();
47 void qchartview();
47 void chart_data();
48 void chart_data();
48 void chart();
49 void chart();
49 void rubberBand_data();
50 void rubberBand_data();
50 void rubberBand();
51 void rubberBand();
51 void keys_data();
52 void keys_data();
52 void keys();
53 void keys();
53
54
54 private:
55 private:
55 QChartView* m_view;
56 QChartView* m_view;
56 };
57 };
57
58
58 void tst_QChartView::initTestCase()
59 void tst_QChartView::initTestCase()
59 {
60 {
60 //test tracks mouse, give a while to user to relese it
61 //test tracks mouse, give a while to user to relese it
61 QTest::qWait(1000);
62 QTest::qWait(1000);
62 }
63 }
63
64
64 void tst_QChartView::cleanupTestCase()
65 void tst_QChartView::cleanupTestCase()
65 {
66 {
66 }
67 }
67
68
68 void tst_QChartView::init()
69 void tst_QChartView::init()
69 {
70 {
70 m_view = new QChartView(new QChart());
71 m_view = new QChartView(new QChart());
72 m_view->chart()->legend()->setVisible(false);
71 }
73 }
72
74
73 void tst_QChartView::cleanup()
75 void tst_QChartView::cleanup()
74 {
76 {
75 delete m_view;
77 delete m_view;
76 m_view =0;
78 m_view =0;
77 }
79 }
78
80
79 void tst_QChartView::qchartview_data()
81 void tst_QChartView::qchartview_data()
80 {
82 {
81
83
82 }
84 }
83
85
84 void tst_QChartView::qchartview()
86 void tst_QChartView::qchartview()
85 {
87 {
86 QVERIFY(m_view->chart());
88 QVERIFY(m_view->chart());
87 QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand);
89 QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand);
88 m_view->show();
90 m_view->show();
89 QTest::qWaitForWindowShown(m_view);
91 QTest::qWaitForWindowShown(m_view);
90 }
92 }
91
93
92 void tst_QChartView::chart_data()
94 void tst_QChartView::chart_data()
93 {
95 {
94
96
95 QTest::addColumn<QChart*>("chart");
97 QTest::addColumn<QChart*>("chart");
96 QTest::newRow("qchart") << new QChart();
98 QTest::newRow("qchart") << new QChart();
97 }
99 }
98
100
99 void tst_QChartView::chart()
101 void tst_QChartView::chart()
100 {
102 {
101 QFETCH(QChart*, chart);
103 QFETCH(QChart*, chart);
102 QChartView* view = new QChartView(chart);
104 QChartView* view = new QChartView(chart);
103 QCOMPARE(view->chart(), chart);
105 QCOMPARE(view->chart(), chart);
104 delete view;
106 delete view;
105 }
107 }
106
108
107 void tst_QChartView::rubberBand_data()
109 void tst_QChartView::rubberBand_data()
108 {
110 {
109 QTest::addColumn<QChartView::RubberBands>("rubberBand");
111 QTest::addColumn<QChartView::RubberBands>("rubberBand");
110 QTest::addColumn<int>("Xcount");
112 QTest::addColumn<int>("Xcount");
111 QTest::addColumn<int>("Ycount");
113 QTest::addColumn<int>("Ycount");
112
114
113 QTest::addColumn<int>("minX");
115 QTest::addColumn<int>("minX");
114 QTest::addColumn<int>("maxX");
116 QTest::addColumn<int>("maxX");
115 QTest::addColumn<int>("minY");
117 QTest::addColumn<int>("minY");
116 QTest::addColumn<int>("maxY");
118 QTest::addColumn<int>("maxY");
117
119
118 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100;
120 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100;
119 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90;
121 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90;
120 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90;
122 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90;
121 }
123 }
122
124
123 void tst_QChartView::rubberBand()
125 void tst_QChartView::rubberBand()
124 {
126 {
125 QFETCH(QChartView::RubberBands, rubberBand);
127 QFETCH(QChartView::RubberBands, rubberBand);
126 QFETCH(int, Xcount);
128 QFETCH(int, Xcount);
127 QFETCH(int, Ycount);
129 QFETCH(int, Ycount);
128 QFETCH(int, minX);
130 QFETCH(int, minX);
129 QFETCH(int, maxX);
131 QFETCH(int, maxX);
130 QFETCH(int, minY);
132 QFETCH(int, minY);
131 QFETCH(int, maxY);
133 QFETCH(int, maxY);
132
134
133 m_view->setRubberBand(rubberBand);
135 m_view->setRubberBand(rubberBand);
134 QRect padding = m_view->chart()->margins();
136 QRectF padding = m_view->chart()->margins();
135 QCOMPARE(m_view->rubberBand(), rubberBand);
137 QCOMPARE(m_view->rubberBand(), rubberBand);
136
138
137 QLineSeries* line = new QLineSeries();
139 QLineSeries* line = new QLineSeries();
138 *line << QPointF(0, 0) << QPointF(100, 100);
140 *line << QPointF(0, 0) << QPointF(100, 100);
139
141
140 m_view->chart()->addSeries(line);
142 m_view->chart()->addSeries(line);
141 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
143 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
142 m_view->show();
144 m_view->show();
143
145
144 //this is hack since view does not get events otherwise
146 //this is hack since view does not get events otherwise
145 m_view->setMouseTracking(true);
147 m_view->setMouseTracking(true);
146
148
147 QChartAxis* axisY = m_view->chart()->axisY();
149 QChartAxis* axisY = m_view->chart()->axisY();
148 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
150 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
149 QChartAxis* axisX = m_view->chart()->axisX();
151 QChartAxis* axisX = m_view->chart()->axisX();
150 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
152 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
151
153
152 QTest::qWaitForWindowShown(m_view);
154 QTest::qWaitForWindowShown(m_view);
153 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft());
155 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
154 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft());
156 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
155 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft());
157 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
156 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft());
158 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
159
157
160
158 QCOMPARE(spy0.count(), Xcount);
161 QCOMPARE(spy0.count(), Xcount);
159 QCOMPARE(spy1.count(), Ycount);
162 QCOMPARE(spy1.count(), Ycount);
160
163
161 //this is hack since view does not get events otherwise
164 //this is hack since view does not get events otherwise
162 m_view->setMouseTracking(false);
165 m_view->setMouseTracking(false);
163
166
164 QVERIFY(axisX->min() - minX < 1);
167 QVERIFY(axisX->min() - minX < 1);
165 QVERIFY(axisX->max() - maxX < 1);
168 QVERIFY(axisX->max() - maxX < 1);
166 QVERIFY(axisY->min() - minY < 1);
169 QVERIFY(axisY->min() - minY < 1);
167 QVERIFY(axisY->max() - maxY < 1);
170 QVERIFY(axisY->max() - maxY < 1);
168 }
171 }
169
172
170 void tst_QChartView::keys_data()
173 void tst_QChartView::keys_data()
171 {
174 {
172 QTest::addColumn<Qt::Key>("key");
175 QTest::addColumn<Qt::Key>("key");
173 QTest::addColumn<int>("Xcount");
176 QTest::addColumn<int>("Xcount");
174 QTest::addColumn<int>("Ycount");
177 QTest::addColumn<int>("Ycount");
175 QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1;
178 QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1;
176 QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1;
179 QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1;
177 QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1;
180 QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1;
178 QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1;
181 QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1;
179 QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0;
182 QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0;
180 QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0;
183 QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0;
181 }
184 }
182
185
183 void tst_QChartView::keys()
186 void tst_QChartView::keys()
184 {
187 {
185 QFETCH(Qt::Key,key);
188 QFETCH(Qt::Key,key);
186 QFETCH(int, Xcount);
189 QFETCH(int, Xcount);
187 QFETCH(int, Ycount);
190 QFETCH(int, Ycount);
188
191
189 QRect padding = m_view->chart()->margins();
192 QRectF padding = m_view->chart()->margins();
190
193
191 QLineSeries* line = new QLineSeries();
194 QLineSeries* line = new QLineSeries();
192 *line << QPointF(0, 0) << QPointF(100, 100);
195 *line << QPointF(0, 0) << QPointF(100, 100);
193
196
194 m_view->chart()->addSeries(line);
197 m_view->chart()->addSeries(line);
195 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
198 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
196 m_view->show();
199 m_view->show();
197
200
198 QChartAxis* axisY = m_view->chart()->axisY();
201 QChartAxis* axisY = m_view->chart()->axisY();
199 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
202 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
200 QChartAxis* axisX = m_view->chart()->axisX();
203 QChartAxis* axisX = m_view->chart()->axisX();
201 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
204 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
202
205
203 QTest::keyPress(m_view, key);
206 QTest::keyPress(m_view, key);
204 QTest::keyRelease(m_view, key);
207 QTest::keyRelease(m_view, key);
205
208
206 QCOMPARE(spy0.count(), Ycount);
209 QCOMPARE(spy0.count(), Ycount);
207 QCOMPARE(spy1.count(), Xcount);
210 QCOMPARE(spy1.count(), Xcount);
208
211
209 }
212 }
210
213
211 QTEST_MAIN(tst_QChartView)
214 QTEST_MAIN(tst_QChartView)
212 #include "tst_qchartview.moc"
215 #include "tst_qchartview.moc"
213
216
General Comments 0
You need to be logged in to leave comments. Login now