##// END OF EJS Templates
Fixes for docs , adds xyseries docs
Michal Klocek -
r481:676000b99479
parent child
Show More
@@ -1,54 +1,55
1 /*!
1 /*!
2 \page classes.html
2 \page classes.html
3 \title QtCommercial Charts API
3 \title QtCommercial Charts API
4 \keyword All Classes
4 \keyword All Classes
5
5
6
6
7 \image class_diagram.png
7 \image class_diagram.png
8 \raw HTML
8 \raw HTML
9 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
9 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
10 <tr>
10 <tr>
11 <th class="titleheader" width="33%">
11 <th class="titleheader" width="33%">
12 List of classes
12 List of classes
13 </th>
13 </th>
14 </tr>
14 </tr>
15 <tr>
15 <tr>
16 <td valign="top">
16 <td valign="top">
17 <ul>
17 <ul>
18 <li><a href="qareaseries.html">QAreaSeries</a></li>
18 <li><a href="qareaseries.html">QAreaSeries</a></li>
19 <li><a href="qbarseries.html">QBarSeries</a></li>
19 <li><a href="qbarseries.html">QBarSeries</a></li>
20 <li><a href="qbarset.html">QBarSet</a></li>
20 <li><a href="qbarset.html">QBarSet</a></li>
21 <li><a href="qchart.html">QChart</a></li>
21 <li><a href="qchart.html">QChart</a></li>
22 <li><a href="qchartaxis.html">QChartAxis</a></li>
22 <li><a href="qchartaxis.html">QChartAxis</a></li>
23 <li><a href="qchartview.html">QChartView</a></li>
23 <li><a href="qchartview.html">QChartView</a></li>
24 <li><a href="qlineseries.html">QLineSeries</a></li>
24 <li><a href="qlineseries.html">QLineSeries</a></li>
25 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
25 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
26 <li><a href="qpieseries.html">QPieSeries</a></li>
26 <li><a href="qpieseries.html">QPieSeries</a></li>
27 <li><a href="qpieslice.html">QPieSlice</a></li>
27 <li><a href="qpieslice.html">QPieSlice</a></li>
28 <li><a href="qscatterseries.html">QScatterSeries</a></li>
28 <li><a href="qscatterseries.html">QScatterSeries</a></li>
29 <li><a href="qseries.html">QSeries</a></li>
29 <li><a href="qseries.html">QSeries</a></li>
30 <li><a href="qsplineseries.html">QSplineSeries</a></li>
30 <li><a href="qsplineseries.html">QSplineSeries</a></li>
31 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
31 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
32 <li><a href="qxyseries.html">QXYSeries</a></li>
32 </ul>
33 </ul>
33 </td>
34 </td>
34 </tr>
35 </tr>
35 </table>
36 </table>
36
37
37 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
38 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
38 <tr>
39 <tr>
39 <th class="titleheader" width="33%">
40 <th class="titleheader" width="33%">
40 Other files:
41 Other files:
41 </th>
42 </th>
42 </tr>
43 </tr>
43 <tr>
44 <tr>
44 <td valign="top">
45 <td valign="top">
45 <ul>
46 <ul>
46 <li><a href="qchartglobal.html">QChartGlobal</a></li>
47 <li><a href="qchartglobal.html">QChartGlobal</a></li>
47 </ul>
48 </ul>
48 </td>
49 </td>
49 </tr>
50 </tr>
50 </table>
51 </table>
51
52
52 \endraw
53 \endraw
53
54
54 */
55 */
@@ -1,288 +1,288
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QGraphicsSceneResizeEvent>
6 #include <QGraphicsSceneResizeEvent>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 /*!
11 /*!
12 \enum QChart::ChartTheme
12 \enum QChart::ChartTheme
13
13
14 This enum describes the theme used by the chart.
14 This enum describes the theme used by the chart.
15
15
16 \value ChartThemeDefault
16 \value ChartThemeDefault
17 \value ChartThemeVanilla
17 \value ChartThemeVanilla
18 \value ChartThemeIcy
18 \value ChartThemeIcy
19 \value ChartThemeGrayscale
19 \value ChartThemeGrayscale
20 \value ChartThemeScientific
20 \value ChartThemeScientific
21 */
21 */
22
22
23 /*!
23 /*!
24 \enum QChart::AnimationOption
24 \enum QChart::AnimationOption
25
25
26 For enabling/disabling animations. Defaults to NoAnimation.
26 For enabling/disabling animations. Defaults to NoAnimation.
27
27
28 \value NoAnimation
28 \value NoAnimation
29 \value GridAxisAnimations
29 \value GridAxisAnimations
30 \value SeriesAnimations
30 \value SeriesAnimations
31 \value AllAnimations
31 \value AllAnimations
32 */
32 */
33
33
34 /*!
34 /*!
35 \class QChart
35 \class QChart
36 \brief QtCommercial chart API.
36 \brief QtCommercial chart API.
37
37
38 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
38 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
39 representation of different types of QChartSeries and other chart related objects like
39 representation of different types of QChartSeries and other chart related objects like
40 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
40 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
41 convenience class QChartView instead of QChart.
41 convenience class QChartView instead of QChart.
42 \sa QChartView
42 \sa QChartView
43 */
43 */
44
44
45 /*!
45 /*!
46 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
46 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
47 */
47 */
48 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
48 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
49 m_backgroundItem(0),
49 m_backgroundItem(0),
50 m_titleItem(0),
50 m_titleItem(0),
51 m_dataset(new ChartDataSet(this)),
51 m_dataset(new ChartDataSet(this)),
52 m_presenter(new ChartPresenter(this,m_dataset))
52 m_presenter(new ChartPresenter(this,m_dataset))
53 {
53 {
54 }
54 }
55
55
56 /*!
56 /*!
57 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
57 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
58 */
58 */
59 QChart::~QChart()
59 QChart::~QChart()
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
64 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
65 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
65 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
66 the y axis).
66 the y axis).
67 */
67 */
68 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
68 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
69 {
69 {
70 m_dataset->addSeries(series, axisY);
70 m_dataset->addSeries(series, axisY);
71 }
71 }
72
72
73 /*!
73 /*!
74 Removes the \a series specified in a perameter from the QChartView.
74 Removes the \a series specified in a perameter from the QChartView.
75 It releses its ownership of the specified QChartSeries object.
75 It releses its ownership of the specified QChartSeries object.
76 It does not delete the pointed QChartSeries data object
76 It does not delete the pointed QChartSeries data object
77 \sa addSeries(), removeAllSeries()
77 \sa addSeries(), removeAllSeries()
78 */
78 */
79 void QChart::removeSeries(QSeries* series)
79 void QChart::removeSeries(QSeries* series)
80 {
80 {
81 m_dataset->removeSeries(series);
81 m_dataset->removeSeries(series);
82 }
82 }
83
83
84 /*!
84 /*!
85 Removes all the QChartSeries that have been added to the QChartView
85 Removes all the QChartSeries that have been added to the QChartView
86 It also deletes the pointed QChartSeries data objects
86 It also deletes the pointed QChartSeries data objects
87 \sa addSeries(), removeSeries()
87 \sa addSeries(), removeSeries()
88 */
88 */
89 void QChart::removeAllSeries()
89 void QChart::removeAllSeries()
90 {
90 {
91 m_dataset->removeAllSeries();
91 m_dataset->removeAllSeries();
92 }
92 }
93
93
94 /*!
94 /*!
95 Sets the \a brush that is used for painting the background of the chart area.
95 Sets the \a brush that is used for painting the background of the chart area.
96 */
96 */
97 void QChart::setChartBackgroundBrush(const QBrush& brush)
97 void QChart::setChartBackgroundBrush(const QBrush& brush)
98 {
98 {
99 createChartBackgroundItem();
99 createChartBackgroundItem();
100 m_backgroundItem->setBrush(brush);
100 m_backgroundItem->setBrush(brush);
101 m_backgroundItem->update();
101 m_backgroundItem->update();
102 }
102 }
103
103
104 /*!
104 /*!
105 Sets the \a pen that is used for painting the background of the chart area.
105 Sets the \a pen that is used for painting the background of the chart area.
106 */
106 */
107 void QChart::setChartBackgroundPen(const QPen& pen)
107 void QChart::setChartBackgroundPen(const QPen& pen)
108 {
108 {
109 createChartBackgroundItem();
109 createChartBackgroundItem();
110 m_backgroundItem->setPen(pen);
110 m_backgroundItem->setPen(pen);
111 m_backgroundItem->update();
111 m_backgroundItem->update();
112 }
112 }
113
113
114 /*!
114 /*!
115 Sets the chart \a title. The description text that is rendered above the chart.
115 Sets the chart \a title. The description text that is drawn above the chart.
116 */
116 */
117 void QChart::setChartTitle(const QString& title)
117 void QChart::setChartTitle(const QString& title)
118 {
118 {
119 createChartTitleItem();
119 createChartTitleItem();
120 m_titleItem->setText(title);
120 m_titleItem->setText(title);
121 }
121 }
122
122
123 /*!
123 /*!
124 Gets the chart \a title. The description text that is rendered above the chart.
124 Returns the chart title. The description text that is drawn above the chart.
125 */
125 */
126 QString QChart::chartTitle() const
126 QString QChart::chartTitle() const
127 {
127 {
128 if(m_titleItem)
128 if(m_titleItem)
129 return m_titleItem->text();
129 return m_titleItem->text();
130 else
130 else
131 return QString();
131 return QString();
132 }
132 }
133
133
134 /*!
134 /*!
135 Sets the \a font that is used for rendering the description text that is rendered above the chart.
135 Sets the \a font that is used for rendering the description text that is rendered above the chart.
136 */
136 */
137 void QChart::setChartTitleFont(const QFont& font)
137 void QChart::setChartTitleFont(const QFont& font)
138 {
138 {
139 createChartTitleItem();
139 createChartTitleItem();
140 m_titleItem->setFont(font);
140 m_titleItem->setFont(font);
141 }
141 }
142
142
143 void QChart::createChartBackgroundItem()
143 void QChart::createChartBackgroundItem()
144 {
144 {
145 if(!m_backgroundItem) {
145 if(!m_backgroundItem) {
146 m_backgroundItem = new QGraphicsRectItem(this);
146 m_backgroundItem = new QGraphicsRectItem(this);
147 m_backgroundItem->setPen(Qt::NoPen);
147 m_backgroundItem->setPen(Qt::NoPen);
148 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
148 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
149 }
149 }
150 }
150 }
151
151
152 void QChart::createChartTitleItem()
152 void QChart::createChartTitleItem()
153 {
153 {
154 if(!m_titleItem) {
154 if(!m_titleItem) {
155 m_titleItem = new QGraphicsSimpleTextItem(this);
155 m_titleItem = new QGraphicsSimpleTextItem(this);
156 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
156 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
157 }
157 }
158 }
158 }
159
159
160 /*!
160 /*!
161 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
161 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
162 \sa setMargin()
162 \sa setMargin()
163 */
163 */
164 int QChart::margin() const
164 int QChart::margin() const
165 {
165 {
166 return m_presenter->margin();
166 return m_presenter->margin();
167 }
167 }
168
168
169 /*!
169 /*!
170 Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
170 Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
171 \sa margin()
171 \sa margin()
172 */
172 */
173 void QChart::setMargin(int margin)
173 void QChart::setMargin(int margin)
174 {
174 {
175 m_presenter->setMargin(margin);
175 m_presenter->setMargin(margin);
176 }
176 }
177
177
178 /*!
178 /*!
179 Sets the \a theme used by the chart for rendering the graphical representation of the data
179 Sets the \a theme used by the chart for rendering the graphical representation of the data
180 \sa ChartTheme, chartTheme()
180 \sa ChartTheme, chartTheme()
181 */
181 */
182 void QChart::setChartTheme(QChart::ChartTheme theme)
182 void QChart::setChartTheme(QChart::ChartTheme theme)
183 {
183 {
184 m_presenter->setChartTheme(theme);
184 m_presenter->setChartTheme(theme);
185 }
185 }
186
186
187 /*!
187 /*!
188 Returns the theme enum used by the chart.
188 Returns the theme enum used by the chart.
189 \sa ChartTheme, setChartTheme()
189 \sa ChartTheme, setChartTheme()
190 */
190 */
191 QChart::ChartTheme QChart::chartTheme() const
191 QChart::ChartTheme QChart::chartTheme() const
192 {
192 {
193 return m_presenter->chartTheme();
193 return m_presenter->chartTheme();
194 }
194 }
195
195
196 /*!
196 /*!
197 Zooms in the view by a factor of 2
197 Zooms in the view by a factor of 2
198 */
198 */
199 void QChart::zoomIn()
199 void QChart::zoomIn()
200 {
200 {
201 m_presenter->zoomIn();
201 m_presenter->zoomIn();
202 }
202 }
203
203
204 /*!
204 /*!
205 Zooms in the view to a maximum level at which \a rect is still fully visible.
205 Zooms in the view to a maximum level at which \a rect is still fully visible.
206 */
206 */
207 void QChart::zoomIn(const QRectF& rect)
207 void QChart::zoomIn(const QRectF& rect)
208 {
208 {
209
209
210 if(!rect.isValid()) return;
210 if(!rect.isValid()) return;
211 m_presenter->zoomIn(rect);
211 m_presenter->zoomIn(rect);
212 }
212 }
213
213
214 /*!
214 /*!
215 Restores the view zoom level to the previous one.
215 Restores the view zoom level to the previous one.
216 */
216 */
217 void QChart::zoomOut()
217 void QChart::zoomOut()
218 {
218 {
219 m_presenter->zoomOut();
219 m_presenter->zoomOut();
220 }
220 }
221
221
222 /*!
222 /*!
223 Resets to the default view.
223 Resets to the default view.
224 */
224 */
225 void QChart::zoomReset()
225 void QChart::zoomReset()
226 {
226 {
227 m_presenter->zoomReset();
227 m_presenter->zoomReset();
228 }
228 }
229
229
230 /*!
230 /*!
231 Returns the pointer to the x axis object of the chart
231 Returns the pointer to the x axis object of the chart
232 */
232 */
233 QChartAxis* QChart::axisX() const
233 QChartAxis* QChart::axisX() const
234 {
234 {
235 return m_dataset->axisX();
235 return m_dataset->axisX();
236 }
236 }
237
237
238 /*!
238 /*!
239 Returns the pointer to the y axis object of the chart
239 Returns the pointer to the y axis object of the chart
240 */
240 */
241 QChartAxis* QChart::axisY() const
241 QChartAxis* QChart::axisY() const
242 {
242 {
243 return m_dataset->axisY();
243 return m_dataset->axisY();
244 }
244 }
245
245
246 /*!
246 /*!
247 Resizes and updates the chart area using the \a event data
247 Resizes and updates the chart area using the \a event data
248 */
248 */
249 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
249 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
250 {
250 {
251
251
252 m_rect = QRectF(QPoint(0,0),event->newSize());
252 m_rect = QRectF(QPoint(0,0),event->newSize());
253 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
253 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
254
254
255 // recalculate title position
255 // recalculate title position
256 if (m_titleItem) {
256 if (m_titleItem) {
257 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
257 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
258 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
258 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
259 }
259 }
260
260
261 //recalculate background gradient
261 //recalculate background gradient
262 if (m_backgroundItem) {
262 if (m_backgroundItem) {
263 m_backgroundItem->setRect(rect);
263 m_backgroundItem->setRect(rect);
264 }
264 }
265
265
266 QGraphicsWidget::resizeEvent(event);
266 QGraphicsWidget::resizeEvent(event);
267 update();
267 update();
268 }
268 }
269
269
270 /*!
270 /*!
271 Sets animation \a options for the chart
271 Sets animation \a options for the chart
272 */
272 */
273 void QChart::setAnimationOptions(AnimationOptions options)
273 void QChart::setAnimationOptions(AnimationOptions options)
274 {
274 {
275 m_presenter->setAnimationOptions(options);
275 m_presenter->setAnimationOptions(options);
276 }
276 }
277
277
278 /*!
278 /*!
279 Returns animation options for the chart
279 Returns animation options for the chart
280 */
280 */
281 QChart::AnimationOptions QChart::animationOptions() const
281 QChart::AnimationOptions QChart::animationOptions() const
282 {
282 {
283 return m_presenter->animationOptions();
283 return m_presenter->animationOptions();
284 }
284 }
285
285
286 #include "moc_qchart.cpp"
286 #include "moc_qchart.cpp"
287
287
288 QTCOMMERCIALCHART_END_NAMESPACE
288 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,359 +1,359
1 #include "qchartview.h"
1 #include "qchartview.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QGraphicsView>
4 #include <QGraphicsView>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QRubberBand>
6 #include <QRubberBand>
7 #include <QResizeEvent>
7 #include <QResizeEvent>
8 #include <QDebug>
8 #include <QDebug>
9
9
10 /*!
10 /*!
11 \enum QChartView::RubberBandPolicy
11 \enum QChartView::RubberBandPolicy
12
12
13 This enum describes the different types of rubber bands that can be used for zoom rect selection
13 This enum describes the different types of rubber bands that can be used for zoom rect selection
14
14
15 \value NoRubberBand
15 \value NoRubberBand
16 \value VerticalRubberBand
16 \value VerticalRubberBand
17 \value HorizonalRubberBand
17 \value HorizonalRubberBand
18 \value RectangleRubberBand
18 \value RectangleRubberBand
19 */
19 */
20
20
21 /*!
21 /*!
22 \class QChartView
22 \class QChartView
23 \brief Standalone charting widget.
23 \brief Standalone charting widget.
24
24
25 QChartView is a standalone widget that can display charts. It does not require separate
25 QChartView is a standalone widget that can display charts. It does not require separate
26 QGraphicsScene to work. It manages the graphical representation of different types of
26 QGraphicsScene to work. It manages the graphical representation of different types of
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
29
29
30 \sa QChart
30 \sa QChart
31 */
31 */
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 Constructs a chartView object which is a child of a\a parent.
36 Constructs a chartView object which is a child of a\a parent.
37 */
37 */
38 QChartView::QChartView(QWidget *parent) :
38 QChartView::QChartView(QWidget *parent) :
39 QGraphicsView(parent),
39 QGraphicsView(parent),
40 m_scene(new QGraphicsScene(this)),
40 m_scene(new QGraphicsScene(this)),
41 m_chart(new QChart()),
41 m_chart(new QChart()),
42 m_rubberBand(0),
42 m_rubberBand(0),
43 m_verticalRubberBand(false),
43 m_verticalRubberBand(false),
44 m_horizonalRubberBand(false)
44 m_horizonalRubberBand(false)
45 {
45 {
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
48 setScene(m_scene);
48 setScene(m_scene);
49 m_chart->setMargin(50);
49 m_chart->setMargin(50);
50 m_scene->addItem(m_chart);
50 m_scene->addItem(m_chart);
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
52 }
52 }
53
53
54
54
55 /*!
55 /*!
56 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
56 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
57 */
57 */
58 QChartView::~QChartView()
58 QChartView::~QChartView()
59 {
59 {
60 }
60 }
61
61
62 /*!
62 /*!
63 Resizes and updates the chart area using the \a event data
63 Resizes and updates the chart area using the \a event data
64 */
64 */
65 void QChartView::resizeEvent(QResizeEvent *event)
65 void QChartView::resizeEvent(QResizeEvent *event)
66 {
66 {
67 m_scene->setSceneRect(0,0,size().width(),size().height());
67 m_scene->setSceneRect(0,0,size().width(),size().height());
68 m_chart->resize(size());
68 m_chart->resize(size());
69 QWidget::resizeEvent(event);
69 QWidget::resizeEvent(event);
70 }
70 }
71
71
72 /*!
72 /*!
73 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
73 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
74 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
74 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
75 the y axis).
75 the y axis).
76 \sa removeSeries(), removeAllSeries()
76 \sa removeSeries(), removeAllSeries()
77 */
77 */
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
79 {
79 {
80 m_chart->addSeries(series,axisY);
80 m_chart->addSeries(series,axisY);
81 }
81 }
82
82
83 /*!
83 /*!
84 Removes the \a series specified in a perameter from the QChartView.
84 Removes the \a series specified in a perameter from the QChartView.
85 It releses its ownership of the specified QChartSeries object.
85 It releses its ownership of the specified QChartSeries object.
86 It does not delete the pointed QChartSeries data object
86 It does not delete the pointed QChartSeries data object
87 \sa addSeries(), removeAllSeries()
87 \sa addSeries(), removeAllSeries()
88 */
88 */
89 void QChartView::removeSeries(QSeries* series)
89 void QChartView::removeSeries(QSeries* series)
90 {
90 {
91 m_chart->removeSeries(series);
91 m_chart->removeSeries(series);
92 }
92 }
93
93
94 /*!
94 /*!
95 Removes all the QChartSeries that have been added to the QChartView
95 Removes all the QChartSeries that have been added to the QChartView
96 It also deletes the pointed QChartSeries data objects
96 It also deletes the pointed QChartSeries data objects
97 \sa addSeries(), removeSeries()
97 \sa addSeries(), removeSeries()
98 */
98 */
99 void QChartView::removeAllSeries()
99 void QChartView::removeAllSeries()
100 {
100 {
101 m_chart->removeAllSeries();
101 m_chart->removeAllSeries();
102 }
102 }
103
103
104 /*!
104 /*!
105 Zooms in the view by a factor of 2
105 Zooms in the view by a factor of 2
106 */
106 */
107 void QChartView::zoomIn()
107 void QChartView::zoomIn()
108 {
108 {
109 m_chart->zoomIn();
109 m_chart->zoomIn();
110 }
110 }
111
111
112 /*!
112 /*!
113 Zooms in the view to a maximum level at which \a rect is still fully visible.
113 Zooms in the view to a maximum level at which \a rect is still fully visible.
114 */
114 */
115 void QChartView::zoomIn(const QRect& rect)
115 void QChartView::zoomIn(const QRect& rect)
116 {
116 {
117 m_chart->zoomIn(rect);
117 m_chart->zoomIn(rect);
118 }
118 }
119
119
120 /*!
120 /*!
121 Restores the view zoom level to the previous one.
121 Restores the view zoom level to the previous one.
122 */
122 */
123 void QChartView::zoomOut()
123 void QChartView::zoomOut()
124 {
124 {
125 m_chart->zoomOut();
125 m_chart->zoomOut();
126 }
126 }
127
127
128 /*!
128 /*!
129 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
129 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
130 */
130 */
131 int QChartView::margin() const
131 int QChartView::margin() const
132 {
132 {
133 return m_chart->margin();
133 return m_chart->margin();
134 }
134 }
135
135
136 /*!
136 /*!
137 Sets the chart \a title. A description text that is rendered above the chart.
137 Sets the chart \a title. A description text that is drawn above the chart.
138 */
138 */
139 void QChartView::setChartTitle(const QString& title)
139 void QChartView::setChartTitle(const QString& title)
140 {
140 {
141 m_chart->setChartTitle(title);
141 m_chart->setChartTitle(title);
142 }
142 }
143
143
144 /*!
144 /*!
145 Returns the chart's title. A description text that is rendered above the chart.
145 Returns the chart's title. A description text that is drawn above the chart.
146 */
146 */
147 QString QChartView::chartTitle() const
147 QString QChartView::chartTitle() const
148 {
148 {
149 return m_chart->chartTitle();
149 return m_chart->chartTitle();
150 }
150 }
151
151
152 /*!
152 /*!
153 Sets the \a font that is used for rendering the description text that is rendered above the chart.
153 Sets the \a font that is used for rendering the description text that is rendered above the chart.
154 */
154 */
155 void QChartView::setChartTitleFont(const QFont& font)
155 void QChartView::setChartTitleFont(const QFont& font)
156 {
156 {
157 m_chart->setChartTitleFont(font);
157 m_chart->setChartTitleFont(font);
158 }
158 }
159
159
160 /*!
160 /*!
161 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
161 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
162 */
162 */
163 void QChartView::setChartBackgroundBrush(const QBrush& brush)
163 void QChartView::setChartBackgroundBrush(const QBrush& brush)
164 {
164 {
165 m_chart->setChartBackgroundBrush(brush);
165 m_chart->setChartBackgroundBrush(brush);
166 }
166 }
167
167
168 /*!
168 /*!
169 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
169 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
170 */
170 */
171 void QChartView::setChartBackgroundPen(const QPen& pen)
171 void QChartView::setChartBackgroundPen(const QPen& pen)
172 {
172 {
173 m_chart->setChartBackgroundPen(pen);
173 m_chart->setChartBackgroundPen(pen);
174 }
174 }
175
175
176 /*!
176 /*!
177 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
177 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
178 */
178 */
179 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
179 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
180 {
180 {
181 switch(policy) {
181 switch(policy) {
182 case VerticalRubberBand:
182 case VerticalRubberBand:
183 m_verticalRubberBand = true;
183 m_verticalRubberBand = true;
184 m_horizonalRubberBand = false;
184 m_horizonalRubberBand = false;
185 break;
185 break;
186 case HorizonalRubberBand:
186 case HorizonalRubberBand:
187 m_verticalRubberBand = false;
187 m_verticalRubberBand = false;
188 m_horizonalRubberBand = true;
188 m_horizonalRubberBand = true;
189 break;
189 break;
190 case RectangleRubberBand:
190 case RectangleRubberBand:
191 m_verticalRubberBand = true;
191 m_verticalRubberBand = true;
192 m_horizonalRubberBand = true;
192 m_horizonalRubberBand = true;
193 break;
193 break;
194 case NoRubberBand:
194 case NoRubberBand:
195 default:
195 default:
196 delete m_rubberBand;
196 delete m_rubberBand;
197 m_rubberBand=0;
197 m_rubberBand=0;
198 m_horizonalRubberBand = false;
198 m_horizonalRubberBand = false;
199 m_verticalRubberBand = false;
199 m_verticalRubberBand = false;
200 return;
200 return;
201 }
201 }
202 if(!m_rubberBand) {
202 if(!m_rubberBand) {
203 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
203 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
204 m_rubberBand->setEnabled(true);
204 m_rubberBand->setEnabled(true);
205 }
205 }
206 }
206 }
207
207
208 /*!
208 /*!
209 Returns the RubberBandPolicy that is currently being used by the widget.
209 Returns the RubberBandPolicy that is currently being used by the widget.
210 */
210 */
211 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
211 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
212 {
212 {
213 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
213 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
214 if(m_horizonalRubberBand) return HorizonalRubberBand;
214 if(m_horizonalRubberBand) return HorizonalRubberBand;
215 if(m_verticalRubberBand) return VerticalRubberBand;
215 if(m_verticalRubberBand) return VerticalRubberBand;
216 return NoRubberBand;
216 return NoRubberBand;
217 }
217 }
218
218
219 /*!
219 /*!
220 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.
220 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.
221 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
221 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
222 */
222 */
223 void QChartView::mousePressEvent(QMouseEvent *event)
223 void QChartView::mousePressEvent(QMouseEvent *event)
224 {
224 {
225 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
225 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
226
226
227 int margin = m_chart->margin();
227 int margin = m_chart->margin();
228 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
228 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
229
229
230 if (rect.contains(event->pos())) {
230 if (rect.contains(event->pos())) {
231 m_rubberBandOrigin = event->pos();
231 m_rubberBandOrigin = event->pos();
232 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
232 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
233 m_rubberBand->show();
233 m_rubberBand->show();
234 event->accept();
234 event->accept();
235 }
235 }
236 }
236 }
237 else {
237 else {
238 QGraphicsView::mousePressEvent(event);
238 QGraphicsView::mousePressEvent(event);
239 }
239 }
240 }
240 }
241
241
242 /*!
242 /*!
243 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
243 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
244 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
244 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
245 */
245 */
246 void QChartView::mouseMoveEvent(QMouseEvent *event)
246 void QChartView::mouseMoveEvent(QMouseEvent *event)
247 {
247 {
248 if(m_rubberBand && m_rubberBand->isVisible()) {
248 if(m_rubberBand && m_rubberBand->isVisible()) {
249 int margin = m_chart->margin();
249 int margin = m_chart->margin();
250 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
250 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
251 int width = event->pos().x() - m_rubberBandOrigin.x();
251 int width = event->pos().x() - m_rubberBandOrigin.x();
252 int height = event->pos().y() - m_rubberBandOrigin.y();
252 int height = event->pos().y() - m_rubberBandOrigin.y();
253 if(!m_verticalRubberBand) {
253 if(!m_verticalRubberBand) {
254 m_rubberBandOrigin.setY(rect.top());
254 m_rubberBandOrigin.setY(rect.top());
255 height = rect.height();
255 height = rect.height();
256 }
256 }
257 if(!m_horizonalRubberBand) {
257 if(!m_horizonalRubberBand) {
258 m_rubberBandOrigin.setX(rect.left());
258 m_rubberBandOrigin.setX(rect.left());
259 width= rect.width();
259 width= rect.width();
260 }
260 }
261 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
261 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
262 }
262 }
263 else {
263 else {
264 QGraphicsView::mouseMoveEvent(event);
264 QGraphicsView::mouseMoveEvent(event);
265 }
265 }
266 }
266 }
267
267
268 /*!
268 /*!
269 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
269 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
270 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
270 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
271 */
271 */
272 void QChartView::mouseReleaseEvent(QMouseEvent *event)
272 void QChartView::mouseReleaseEvent(QMouseEvent *event)
273 {
273 {
274 if(m_rubberBand) {
274 if(m_rubberBand) {
275 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
275 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
276 m_rubberBand->hide();
276 m_rubberBand->hide();
277 QRect rect = m_rubberBand->geometry();
277 QRect rect = m_rubberBand->geometry();
278 m_chart->zoomIn(rect);
278 m_chart->zoomIn(rect);
279 event->accept();
279 event->accept();
280 }
280 }
281
281
282 if(event->button()==Qt::RightButton)
282 if(event->button()==Qt::RightButton)
283 m_chart->zoomReset();
283 m_chart->zoomReset();
284 }
284 }
285 else {
285 else {
286 QGraphicsView::mouseReleaseEvent(event);
286 QGraphicsView::mouseReleaseEvent(event);
287 }
287 }
288 }
288 }
289
289
290 /*!
290 /*!
291 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
291 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
292 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
292 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
293 */
293 */
294 void QChartView::keyPressEvent(QKeyEvent *event)
294 void QChartView::keyPressEvent(QKeyEvent *event)
295 {
295 {
296 switch (event->key()) {
296 switch (event->key()) {
297 case Qt::Key_Plus:
297 case Qt::Key_Plus:
298 zoomIn();
298 zoomIn();
299 break;
299 break;
300 case Qt::Key_Minus:
300 case Qt::Key_Minus:
301 zoomOut();
301 zoomOut();
302 break;
302 break;
303 default:
303 default:
304 QGraphicsView::keyPressEvent(event);
304 QGraphicsView::keyPressEvent(event);
305 break;
305 break;
306 }
306 }
307 }
307 }
308
308
309 /*!
309 /*!
310 Sets the \a theme used by the chart for rendering the graphical representation of the data
310 Sets the \a theme used by the chart for rendering the graphical representation of the data
311 \sa QChart::ChartTheme, chartTheme()
311 \sa QChart::ChartTheme, chartTheme()
312 */
312 */
313 void QChartView::setChartTheme(QChart::ChartTheme theme)
313 void QChartView::setChartTheme(QChart::ChartTheme theme)
314 {
314 {
315 m_chart->setChartTheme(theme);
315 m_chart->setChartTheme(theme);
316 }
316 }
317
317
318 /*!
318 /*!
319 Returns the theme enum used by the chart.
319 Returns the theme enum used by the chart.
320 \sa setChartTheme()
320 \sa setChartTheme()
321 */
321 */
322 QChart::ChartTheme QChartView::chartTheme() const
322 QChart::ChartTheme QChartView::chartTheme() const
323 {
323 {
324 return m_chart->chartTheme();
324 return m_chart->chartTheme();
325 }
325 }
326
326
327 /*!
327 /*!
328 Returns the pointer to the x axis object of the chart
328 Returns the pointer to the x axis object of the chart
329 */
329 */
330 QChartAxis* QChartView::axisX() const
330 QChartAxis* QChartView::axisX() const
331 {
331 {
332 return m_chart->axisX();
332 return m_chart->axisX();
333 }
333 }
334
334
335 /*!
335 /*!
336 Returns the pointer to the y axis object of the chart
336 Returns the pointer to the y axis object of the chart
337 */
337 */
338 QChartAxis* QChartView::axisY() const
338 QChartAxis* QChartView::axisY() const
339 {
339 {
340 return m_chart->axisY();
340 return m_chart->axisY();
341 }
341 }
342
342
343 /*!
343 /*!
344 Sets animation \a options for the chart
344 Sets animation \a options for the chart
345 */
345 */
346 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
346 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
347 {
347 {
348 m_chart->setAnimationOptions(options);
348 m_chart->setAnimationOptions(options);
349 }
349 }
350
350
351 /*!
351 /*!
352 Returns animation options for the chart
352 Returns animation options for the chart
353 */
353 */
354 QChart::AnimationOptions QChartView::animationOptions() const
354 QChart::AnimationOptions QChartView::animationOptions() const
355 {
355 {
356 return m_chart->animationOptions();
356 return m_chart->animationOptions();
357 }
357 }
358
358
359 QTCOMMERCIALCHART_END_NAMESPACE
359 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,206 +1,108
1 #include "qscatterseries.h"
1 #include "qscatterseries.h"
2 #include "qchart.h"
2 #include "qchart.h"
3
3
4 /*!
4 /*!
5 \class QScatterSeries
5 \class QScatterSeries
6 \brief QtCommercial Chart series API for showing scatter series.
6 \brief The QScatterSeries class is used for making scatter charts.
7
7
8 \mainclass
8 \mainclass
9
9
10 Example on how to create a chart with scatter series:
10 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
11 \snippet ../example/scatter/main.cpp 1
11 and the vertical axis.
12
12
13 The example code would result the following:
13 \image scatterchart.png
14
14
15 \image scatter_example1.jpg
15 Creating basic scatter chart is simple:
16
16 \code
17 To customize the graphical representation of the series, you can modify pen, brush, shape and
17 QScatterSeries* series = new QScatterSeries();
18 size of the marker items. For example:
18 series->add(0, 6);
19
19 series->add(2, 4);
20 \snippet ../example/scatter/main.cpp 3
20 ...
21
21 chartView->addSeries(series);
22 Would present your scatter markers as big rectangles with opaque, uglyish green outlines and
22 \endcode
23 opaque red filling instead of the beatiful markers defined by the chart's theme:
24 \image scatter_example_custom.jpg
25 */
23 */
26
24
27 /*!
25 /*!
28 \enum QScatterSeries::MarkerShape
26 \enum QScatterSeries::MarkerShape
29
27
30 This enum describes the shape used when rendering marker items.
28 This enum describes the shape used when rendering marker items.
31
29
32 \value MarkerShapeDefault
30 \value MarkerShapeDefault
33 \value MarkerShapeX
31 \value MarkerShapeX
34 \value MarkerShapeRectangle
32 \value MarkerShapeRectangle
35 \value MarkerShapeRoundedRectangle
33 \value MarkerShapeRoundedRectangle
36 \value MarkerShapeTiltedRectangle
34 \value MarkerShapeTiltedRectangle
37 \value MarkerShapeTriangle
35 \value MarkerShapeTriangle
38 \value MarkerShapeCircle
36 \value MarkerShapeCircle
39 */
37 */
40
38
41 /*!
39 /*!
42 \fn QChartSeriesType QScatterSeries::type() const
40 \fn QChartSeriesType QScatterSeries::type() const
43 \brief Returns QChartSeries::SeriesTypeScatter.
41 \brief Returns QChartSeries::SeriesTypeScatter.
42 \sa QSeries, QSeriesType
44 */
43 */
45
44
46 /*!
45 /*!
47 \fn void QScatterSeries::clicked(QPointF coordinate)
46 \fn void QScatterSeries::clicked(const QPointF& point)
48 User clicked the scatter series. Note that the \a coordinate is the chart coordinate that the
47 \brief Signal is emitted when user clicks the \a point on scatter chart.
49 click occurred on; not necessarily a data point coordinate. To find the corresponding (closest)
50 data point you can use closestPoint().
51 */
48 */
52
49
53 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
54
51
55 /*!
52 /*!
56 Constructs a series object which is a child of \a parent.
53 Constructs a series object which is a child of \a parent.
57 */
54 */
58 QScatterSeries::QScatterSeries(QObject *parent) :
55 QScatterSeries::QScatterSeries(QObject *parent) :
59 QXYSeries(parent),
56 QXYSeries(parent),
60 m_shape(QScatterSeries::MarkerShapeDefault),
57 m_shape(QScatterSeries::MarkerShapeDefault),
61 m_size(9.0)
58 m_size(9.0)
62 {
59 {
63 }
60 }
64
61
65 /*!
62 /*!
66 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
63 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
67 */
64 */
68 QScatterSeries::~QScatterSeries()
65 QScatterSeries::~QScatterSeries()
69 {
66 {
70 }
67 }
71
68
72
73
74 /*!
75 Stream operator for adding a data point with \a value to the series.
76 \sa add()
77
78 For example:
79 \snippet ../example/scatter/main.cpp 2
80 */
81
82
83 /*!
84 Stream operator for adding a list of points to the series.
85 \sa add()
86 */
87
88
89 /*!
90 Replaces the data of the series with the given list of data \a points.
91 */
92
93
94 /*!
95 Returns the current list of data points of the series.
96 */
97
98 /*!
99 Replaces the point at \a index with \a newPoint. Returns true if \a index is a valid position
100 in the series data, false otherwise.
101 */
102
103
104 /*!
105 Remove the data point at \a index. Returns true if a point was removed, false if the point
106 at \a index does not exist on the series.
107 */
108
109
110 /*!
111 Remove all occurrences of \a point from the series and returns the number of points removed.
112 */
113
114
115 /*!
116 Remove all data points from the series.
117 */
118
119 /*!
120 Returns the index of the data point that is closest to \a coordinate. If several data points
121 are at the same distance from the \a coordinate, returns the last one. If no points exist,
122 returns -1.
123
124 int QScatterSeries::closestPoint(QPointF coordinate)
125 {
126 qreal distance(-1);
127 int pointIndex(-1);
128 for (int i(0); i < d->m_data.count(); i++) {
129 QPointF dataPoint = d->m_data.at(i);
130 QPointF difference = dataPoint - coordinate;
131 if (i == 0 || difference.manhattanLength() <= distance) {
132 distance = difference.manhattanLength();
133 pointIndex = i;
134 }
135 }
136 return pointIndex;
137 }
138 */
139
140 /*!
141 Returns the pen used for drawing markers.
142 */
143
144
145 /*!
146 Overrides the default pen used for drawing a marker item with a user defined \a pen. The
147 default pen is defined by chart theme setting.
148
149 \sa setBrush()
150 \sa QChart::setChartTheme()
151 */
152
153
154 /*!
155 Returns the brush used for drawing markers.
156 */
157
158
159 /*!
160 Overrides the default brush of the marker items with a user defined \a brush. The default brush
161 is defined by chart theme setting.
162
163 \sa setPen()
164 \sa QChart::setChartTheme()
165 */
166
167 /*!
69 /*!
168 Returns the shape used for drawing markers.
70 Returns the shape used for drawing markers.
169 */
71 */
170 QScatterSeries::MarkerShape QScatterSeries::shape() const
72 QScatterSeries::MarkerShape QScatterSeries::shape() const
171 {
73 {
172 return (QScatterSeries::MarkerShape) m_shape;
74 return (QScatterSeries::MarkerShape) m_shape;
173 }
75 }
174
76
175 /*!
77 /*!
176 Overrides the default shape of the marker items with a user defined \a shape. The default shape
78 Overrides the default shape of the marker items with a user defined \a shape. The default shape
177 is defined by chart theme setting.
79 is defined by chart theme setting.
178 */
80 */
179 void QScatterSeries::setShape(MarkerShape shape)
81 void QScatterSeries::setShape(MarkerShape shape)
180 {
82 {
181 m_shape = shape;
83 m_shape = shape;
182 emit updated();
84 emit updated();
183 }
85 }
184
86
185 /*!
87 /*!
186 Returns the size of the marker items.
88 Returns the size of the marker items.
187 */
89 */
188 qreal QScatterSeries::size() const
90 qreal QScatterSeries::size() const
189 {
91 {
190 return m_size;
92 return m_size;
191 }
93 }
192
94
193 /*!
95 /*!
194 Set the \a size of the marker items. The default size is 9.0.
96 Set the \a size of the marker items. The default size is 9.0.
195 */
97 */
196 void QScatterSeries::setSize(qreal size)
98 void QScatterSeries::setSize(qreal size)
197 {
99 {
198 m_size = size;
100 m_size = size;
199 emit updated();
101 emit updated();
200 }
102 }
201
103
202
104
203
105
204 #include "moc_qscatterseries.cpp"
106 #include "moc_qscatterseries.cpp"
205
107
206 QTCOMMERCIALCHART_END_NAMESPACE
108 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +1,52
1 #ifndef QSCATTERSERIES_H
1 #ifndef QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qxyseries.h"
5 #include "qxyseries.h"
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 class QScatterSeriesPrivate;
10 class QScatterSeriesPrivate;
11
11
12 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries
12 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15
15
16 public:
16 public:
17 enum MarkerShape {
17 enum MarkerShape {
18 // TODO: to be defined by the graphics design
18 // TODO: to be defined by the graphics design
19 // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot
19 // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot
20 MarkerShapeDefault = 0,
20 MarkerShapeDefault = 0,
21 MarkerShapeX,
21 MarkerShapeX,
22 MarkerShapeRectangle,
22 MarkerShapeRectangle,
23 MarkerShapeRoundedRectangle,
23 MarkerShapeRoundedRectangle,
24 MarkerShapeTiltedRectangle,
24 MarkerShapeTiltedRectangle,
25 MarkerShapeTriangle,
25 MarkerShapeTriangle,
26 MarkerShapeCircle
26 MarkerShapeCircle
27 };
27 };
28
28
29 public:
29 public:
30 QScatterSeries(QObject *parent = 0);
30 QScatterSeries(QObject *parent = 0);
31 ~QScatterSeries();
31 ~QScatterSeries();
32
32
33 public: // from QChartSeries
33 public: // from QChartSeries
34 QSeriesType type() const { return QSeries::SeriesTypeScatter; }
34 QSeriesType type() const { return QSeries::SeriesTypeScatter; }
35
35
36 public:
36 public:
37 //int closestPoint(QPointF coordinate);
38
39 MarkerShape shape() const;
37 MarkerShape shape() const;
40 void setShape(MarkerShape shape);
38 void setShape(MarkerShape shape);
41 qreal size() const;
39 qreal size() const;
42 void setSize(qreal size);
40 void setSize(qreal size);
43
41
44 signals:
42 signals:
45 void clicked(QPointF coordinate);
43 void clicked(const QPointF& point);
46
44
47 private:
45 private:
48 MarkerShape m_shape;
46 MarkerShape m_shape;
49 qreal m_size;
47 qreal m_size;
50 };
48 };
51
49
52 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
53
51
54 #endif // QSCATTERSERIES_H
52 #endif // QSCATTERSERIES_H
@@ -1,196 +1,217
1 #include "qxyseries.h"
1 #include "qxyseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QXYSeries
6 \class QXYSeries
7 \brief The QXYSeries class is a base class for line, spline and scatter series.
7 \brief The QXYSeries class is a base class for line, spline and scatter series.
8 */
8 */
9
9
10 /*!
10 /*!
11 \fn virtual QSeriesType QXYSeries::type() const
12 \brief Returns type of series.
13 \sa QSeries, QSeriesType
14 */
15
16 /*!
17 \fn QPen QXYSeries::pen() const
11 \fn QPen QXYSeries::pen() const
18 \brief Returns pen used to draw points for series.
12 \brief Returns pen used to draw points for series.
19 \sa setPen()
13 \sa setPen()
20 */
14 */
21
15
22 /*!
16 /*!
23 \fn QBrush QXYSeries::brush() const
17 \fn QBrush QXYSeries::brush() const
24 \brief Returns brush used to draw points for series.
18 \brief Returns brush used to draw points for series.
25 \sa setBrush()
19 \sa setBrush()
26 */
20 */
27
21
28 /*!
22 /*!
29 \fn void QXYSeries::pointReplaced(int index)
23 \fn void QXYSeries::pointReplaced(int index)
30 \brief \internal \a index
24 \brief \internal \a index
31 */
25 */
32
26
33 /*!
27 /*!
34 \fn void QXYSeries::pointAdded(int index)
28 \fn void QXYSeries::pointAdded(int index)
35 \brief \internal \a index
29 \brief \internal \a index
36 */
30 */
37
31
38 /*!
32 /*!
39 \fn void QXYSeries::pointRemoved(int index)
33 \fn void QXYSeries::pointRemoved(int index)
40 \brief \internal \a index
34 \brief \internal \a index
41 */
35 */
42
36
43 /*!
37 /*!
44 \fn void QXYSeries::updated()
38 \fn void QXYSeries::updated()
45 \brief \internal
39 \brief \internal
46 */
40 */
47
41
48 /*!
42 /*!
49 Constructs empty series object which is a child of \a parent.
43 Constructs empty series object which is a child of \a parent.
50 When series object is added to QChartView or QChart instance ownerships is transfered.
44 When series object is added to QChartView or QChart instance ownerships is transfered.
51 */
45 */
52 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
46 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
53 {
47 {
54 }
48 }
55 /*!
49 /*!
56 Destroys the object. Series added to QChartView or QChart instances are owned by those,
50 Destroys the object. Series added to QChartView or QChart instances are owned by those,
57 and are deleted when mentioned object are destroyed.
51 and are deleted when mentioned object are destroyed.
58 */
52 */
59 QXYSeries::~QXYSeries()
53 QXYSeries::~QXYSeries()
60 {
54 {
61 }
55 }
62
56
63 /*!
57 /*!
64 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
58 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
65 */
59 */
66 void QXYSeries::add(qreal x,qreal y)
60 void QXYSeries::add(qreal x,qreal y)
67 {
61 {
68 Q_ASSERT(m_x.size() == m_y.size());
62 Q_ASSERT(m_x.size() == m_y.size());
69 m_x<<x;
63 m_x<<x;
70 m_y<<y;
64 m_y<<y;
71 emit pointAdded(m_x.size()-1);
65 emit pointAdded(m_x.size()-1);
72 }
66 }
73
67
74 /*!
68 /*!
75 This is an overloaded function.
69 This is an overloaded function.
76 Adds data \a point to the series. Points are connected with lines on the chart.
70 Adds data \a point to the series. Points are connected with lines on the chart.
77 */
71 */
78 void QXYSeries::add(const QPointF& point)
72 void QXYSeries::add(const QPointF& point)
79 {
73 {
80 add(point.x(),point.y());
74 add(point.x(),point.y());
81 }
75 }
82
76
83 /*!
77 /*!
78 This is an overloaded function.
79 Adds list of data \a points to the series. Points are connected with lines on the chart.
80 */
81 void QXYSeries::add(const QList<QPointF> points)
82 {
83 foreach(const QPointF& point , points) {
84 add(point.x(),point.y());
85 }
86 }
87
88 /*!
84 Modifies \a y value for given \a x a value.
89 Modifies \a y value for given \a x a value.
85 */
90 */
86 void QXYSeries::replace(qreal x,qreal y)
91 void QXYSeries::replace(qreal x,qreal y)
87 {
92 {
88 int index = m_x.indexOf(x);
93 int index = m_x.indexOf(x);
89 m_x[index]=x;
94 m_x[index]=x;
90 m_y[index]=y;
95 m_y[index]=y;
91 emit pointReplaced(index);
96 emit pointReplaced(index);
92 }
97 }
93
98
94 /*!
99 /*!
95 This is an overloaded function.
100 This is an overloaded function.
96 Replaces current y value of for given \a point x value with \a point y value.
101 Replaces current y value of for given \a point x value with \a point y value.
97 */
102 */
98 void QXYSeries::replace(const QPointF& point)
103 void QXYSeries::replace(const QPointF& point)
99 {
104 {
100 replace(point.x(),point.y());
105 replace(point.x(),point.y());
101 }
106 }
102
107
103 /*!
108 /*!
104 Removes current \a x and y value.
109 Removes current \a x and y value.
105 */
110 */
106 void QXYSeries::remove(qreal x)
111 void QXYSeries::remove(qreal x)
107 {
112 {
108 int index = m_x.indexOf(x);
113 int index = m_x.indexOf(x);
109 emit pointRemoved(index);
114 emit pointRemoved(index);
110 m_x.remove(index);
115 m_x.remove(index);
111 m_y.remove(index);
116 m_y.remove(index);
112 }
117 }
113
118
114 /*!
119 /*!
115 Removes current \a point x value. Note \a point y value is ignored.
120 Removes current \a point x value. Note \a point y value is ignored.
116 */
121 */
117 void QXYSeries::remove(const QPointF& point)
122 void QXYSeries::remove(const QPointF& point)
118 {
123 {
119 remove(point.x());
124 remove(point.x());
120 }
125 }
121
126
122 /*!
127 /*!
123 Clears all the data.
128 Removes all data points from the series.
124 */
129 */
125 void QXYSeries::clear()
130 void QXYSeries::removeAll()
126 {
131 {
127 m_x.clear();
132 m_x.clear();
128 m_y.clear();
133 m_y.clear();
129 }
134 }
130
135
131 /*!
136 /*!
132 \internal \a pos
137 \internal \a pos
133 */
138 */
134 qreal QXYSeries::x(int pos) const
139 qreal QXYSeries::x(int pos) const
135 {
140 {
136 return m_x.at(pos);
141 return m_x.at(pos);
137 }
142 }
138
143
139 /*!
144 /*!
140 \internal \a pos
145 \internal \a pos
141 */
146 */
142 qreal QXYSeries::y(int pos) const
147 qreal QXYSeries::y(int pos) const
143 {
148 {
144 return m_y.at(pos);
149 return m_y.at(pos);
145 }
150 }
146
151
147 /*!
152 /*!
148 Returns number of data points within series.
153 Returns number of data points within series.
149 */
154 */
150 int QXYSeries::count() const
155 int QXYSeries::count() const
151 {
156 {
152 Q_ASSERT(m_x.size() == m_y.size());
157 Q_ASSERT(m_x.size() == m_y.size());
153
158
154 return m_x.size();
159 return m_x.size();
155
160
156 }
161 }
157
162
158 /*!
163 /*!
159 Sets \a pen used for drawing points on the chart.
164 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
165 pen from chart theme is used.
166 \sa QChart::setChartTheme()
160 */
167 */
161 void QXYSeries::setPen(const QPen& pen)
168 void QXYSeries::setPen(const QPen& pen)
162 {
169 {
163 if(pen!=m_pen){
170 if(pen!=m_pen){
164 m_pen=pen;
171 m_pen=pen;
165 emit updated();
172 emit updated();
166 }
173 }
167 }
174 }
168
175
169 /*!
176 /*!
170 Sets \a brush used for drawing points on the chart.
177 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
178 from chart theme setting is used.
179 \sa QChart::setChartTheme()
171 */
180 */
172
181
173 void QXYSeries::setBrush(const QBrush& brush)
182 void QXYSeries::setBrush(const QBrush& brush)
174 {
183 {
175 if(brush!=m_brush){
184 if(brush!=m_brush){
176 m_brush=brush;
185 m_brush=brush;
177 emit updated();
186 emit updated();
178 }
187 }
179 }
188 }
180
189
181
190
182 /*!
191 /*!
183 Stream operator for adding a data \a point to the series.
192 Stream operator for adding a data \a point to the series.
184 \sa add()
193 \sa add()
185 */
194 */
186
195
187 QXYSeries& QXYSeries::operator<< (const QPointF &point)
196 QXYSeries& QXYSeries::operator<< (const QPointF &point)
188 {
197 {
189 add(point);
198 add(point);
190 return *this;
199 return *this;
191 }
200 }
192
201
193
202
203 /*!
204 Stream operator for adding a list of \a points to the series.
205 \sa add()
206 */
207
208 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
209 {
210 add(points);
211 return *this;
212 }
213
214
194 #include "moc_qxyseries.cpp"
215 #include "moc_qxyseries.cpp"
195
216
196 QTCOMMERCIALCHART_END_NAMESPACE
217 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,59
1 #ifndef QXYSERIES_H_
1 #ifndef QXYSERIES_H_
2 #define QXYSERIES_H_
2 #define QXYSERIES_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qseries.h"
5 #include "qseries.h"
6 #include <QDebug>
6 #include <QDebug>
7 #include <QPen>
7 #include <QPen>
8 #include <QBrush>
8 #include <QBrush>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
12 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 protected:
15 protected:
16 QXYSeries(QObject* parent=0);
16 QXYSeries(QObject* parent=0);
17 virtual ~QXYSeries();
17 virtual ~QXYSeries();
18
18
19 public:
19 public:
20 void add(qreal x, qreal y);
20 void add(qreal x, qreal y);
21 void add(const QPointF& point);
21 void add(const QPointF& point);
22 void add(const QList<QPointF> points);
22 void replace(qreal x,qreal y);
23 void replace(qreal x,qreal y);
23 void replace(const QPointF& point);
24 void replace(const QPointF& point);
24 void remove(qreal x);
25 void remove(qreal x);
25 void remove(const QPointF& point);
26 void remove(const QPointF& point);
26 void clear();
27 void removeAll();
27
28
28 int count() const;
29 int count() const;
29 qreal x(int pos) const;
30 qreal x(int pos) const;
30 qreal y(int pos) const;
31 qreal y(int pos) const;
31
32
32 QXYSeries& operator << (const QPointF &point);
33 QXYSeries& operator << (const QPointF &point);
33 /*
34 QXYSeries& operator << (const QList<QPointF> points);
34 void add(QList<QPointF> points);
35 void setData(QList<QPointF> points);
36 QScatterSeries& operator << (const QPointF &value);
37 QScatterSeries& operator << (QList<QPointF> points);
38 int removeAll(QPointF point);
39 */
40
35
41 void setPen(const QPen& pen);
36 void setPen(const QPen& pen);
42 QPen pen() const {return m_pen;}
37 QPen pen() const {return m_pen;}
43 void setBrush(const QBrush& pen);
38 void setBrush(const QBrush& pen);
44 QBrush brush() const {return m_brush;}
39 QBrush brush() const {return m_brush;}
45
40
46 signals:
41 signals:
47 void updated();
42 void updated();
48 void pointReplaced(int index);
43 void pointReplaced(int index);
49 void pointRemoved(int index);
44 void pointRemoved(int index);
50 void pointAdded(int index);
45 void pointAdded(int index);
51
46
52
47
53 protected:
48 protected:
54 QVector<qreal> m_x;
49 QVector<qreal> m_x;
55 QVector<qreal> m_y;
50 QVector<qreal> m_y;
56
51
57 QPen m_pen;
52 QPen m_pen;
58 QBrush m_brush;
53 QBrush m_brush;
59
54
60 };
55 };
61
56
62 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
63
58
64 #endif
59 #endif
General Comments 0
You need to be logged in to leave comments. Login now