##// END OF EJS Templates
Example on main qdoc page.
Tero Ahola -
r334:d6ea428dc600
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,12 +1,42
1 /*!
1 /*!
2 \page index.html
2 \page index.html
3 \title About QCharts
3 \title About QCharts
4 \keyword About
4 \keyword About
5
5
6 \raw HTML
6 \raw HTML
7 <div class="qchart">
7 <div class="qchart">
8 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
8 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
9 <p>QCharts is a part of Qt Commercial addons package.</p>
9 <p>QCharts is a part of Qt Commercial addons package. TODO: Introduction... With QCharts you can easily create impressive graphs of your data in Qt and QtQuick applications...</p>
10 </div>
10 </div>
11 \endraw
12
13 For example, to create a chart with line series using a widget based application (TODO: decent screen shots):
14
15 \snippet ../example/chartview/main.cpp 1
16 \image chartview_example.jpg
17
18 \raw HTML
19 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
20 <tr>
21 <th class="titleheader" width="33%">
22 List of classes
23 </th>
24 </tr>
25 <tr>
26 <td valign="top">
27 <ul>
28 <li><a href="qchart.html">QChart</a></li>
29 <li><a href="qchartview.html">QChartView</a></li>
30 <li><a href="qchartseries.html">QChartSeries</a></li>
31 <li><a href="qlinechartseries.html">QLineChartSeries</a></li>
32 <li><a href="qpieseries.html">QPieSeries</a></li>
33 <li><a href="qbarchartseries.html">QBarChartSeries</a></li>
34 <li><a href="qstackedbarchartseries.html">QStackedBarChartSeries</a></li>
35 <li><a href="qpercentbarchartseries.html">QPercentBarChartSeries</a></li>
36 <li><a href="qscatterseries.html">QScatterSeries</a></li>
37 </ul>
38 </td>
39 </tr>
40 </table>
11 \endraw
41 \endraw
12 */
42 */
@@ -1,24 +1,26
1 /*!
1 /*!
2 \page tutorials.html
2 \page tutorials.html
3 \title Tutorials
3 \title Tutorials
4 \keyword Tutorials
4 \keyword Tutorials
5
5
6 QtCommercial Charts introduction...
7 For example, to create a chart with line series using a widget based application:
6 For example, to create a chart with line series using a widget based application:
8 \snippet ../example/chartview/main.cpp 1
7 \snippet ../example/chartview/main.cpp 1
9 \image chartview_example.jpg
8 \image chartview_example.jpg
10
9
11 Showing a few more series:
10 To replace the line series with a pie series you use the dedicated QPieSeries class:
12 \snippet ../example/chartview/main.cpp 3
11 \snippet ../example/chartview/main.cpp 3
13 \image chartview_example_pie.jpg
12 \image chartview_example_pie.jpg
13
14 To use a scatter series you use QScatterSeries class:
14 \snippet ../example/chartview/main.cpp 4
15 \snippet ../example/chartview/main.cpp 4
15 \image chartview_example_scatter.jpg
16 \image chartview_example_scatter.jpg
17
18 And to show a bar series you use one of the bar series classes, for example QBarChartSeries:
16 \snippet ../example/chartview/main.cpp 5
19 \snippet ../example/chartview/main.cpp 5
17 \image chartview_example_bar.jpg
20 \image chartview_example_bar.jpg
18
21
19 If you need to give a more professional touch to your chart you can switch to one of the
22 If you need to give a more professional touch to your chart you can switch from the default
20 pre-defined themes:
23 theme to one of the other themes:
21 \snippet ../example/chartview/main.cpp 2
24 \snippet ../example/chartview/main.cpp 2
22 \image chartview_example_theme.jpg
25 \image chartview_example_theme.jpg
23
24 */
26 */
@@ -1,73 +1,77
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qlinechartseries.h>
5 #include <qlinechartseries.h>
6 #include <qscatterseries.h>
6 #include <qscatterseries.h>
7 #include <qbarchartseries.h>
7 #include <qbarchartseries.h>
8 #include <qbarset.h>
8 #include <qbarset.h>
9 #include <qbarcategory.h>
9 #include <qbarcategory.h>
10 #include <qpieseries.h>
10 #include <qpieseries.h>
11
11
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
14 int main(int argc, char *argv[])
14 int main(int argc, char *argv[])
15 {
15 {
16 QApplication a(argc, argv);
16 QApplication a(argc, argv);
17
17
18 //! [1]
18 //! [1]
19 // Create chart view
19 // Create chart view
20 QChartView *chartView = new QChartView();
20 QChartView *chartView = new QChartView();
21 chartView->setRenderHint(QPainter::Antialiasing);
21 // Add series to the chart
22 // Add series to the chart
22 QLineChartSeries *line = new QLineChartSeries();
23 QLineChartSeries *line = new QLineChartSeries();
23 line->add(0.0, 0.8);
24 line->add(0.0, 0.8);
24 line->add(1.1, 1.1);
25 line->add(1.1, 1.1);
25 line->add(2.0, 2.5);
26 line->add(2.0, 2.5);
26 chartView->addSeries(line);
27 chartView->addSeries(line);
27 //! [1]
28 //! [1]
28
29
29 //! [2]
30 //! [2]
30 // Change theme
31 // Change theme
31 chartView->setChartTheme(QChart::ChartThemeScientific);
32 chartView->setChartTheme(QChart::ChartThemeScientific);
32 //! [2]
33 //! [2]
33
34
34 //! [3]
35 //! [3]
35 // Add pie series
36 // Add pie series
37 // ...
36 QPieSeries *pie = new QPieSeries();
38 QPieSeries *pie = new QPieSeries();
37 pie->add(3.4, "slice1");
39 pie->add(3.4, "slice1");
38 pie->add(6.7, "slice2");
40 pie->add(6.7, "slice2");
39 chartView->addSeries(pie);
41 chartView->addSeries(pie);
40 //! [3]
42 //! [3]
41
43
42 //! [4]
44 //! [4]
43 // Add scatter series
45 // Add scatter series
46 // ...
44 QScatterSeries *scatter = new QScatterSeries();
47 QScatterSeries *scatter = new QScatterSeries();
45 for (qreal x(0); x < 100; x += 0.5) {
48 for (qreal x(0); x < 100; x += 0.5) {
46 qreal y = rand() % 100;
49 qreal y = rand() % 100;
47 *(scatter) << QPointF(x, y);
50 *(scatter) << QPointF(x, y);
48 }
51 }
49 chartView->addSeries(scatter);
52 chartView->addSeries(scatter);
50 //! [4]
53 //! [4]
51
54
52 //! [5]
55 //! [5]
56 // ...
53 // Add bar series
57 // Add bar series
54 QBarCategory *barCategory = new QBarCategory();
58 QBarCategory *barCategory = new QBarCategory();
55 *barCategory << "Jan"
59 *barCategory << "Jan"
56 << "Feb"
60 << "Feb"
57 << "Mar";
61 << "Mar";
58 QBarChartSeries *bar = new QBarChartSeries(barCategory);
62 QBarChartSeries *bar = new QBarChartSeries(barCategory);
59 QBarSet *barSet = new QBarSet("Sales");
63 QBarSet *barSet = new QBarSet("Sales");
60 *barSet << 123.2
64 *barSet << 123.2
61 << 301.3
65 << 301.3
62 << 285.8;
66 << 285.8;
63 bar->addBarSet(barSet);
67 bar->addBarSet(barSet);
64 chartView->addSeries(bar);
68 chartView->addSeries(bar);
65 //! [5]
69 //! [5]
66
70
67 QMainWindow w;
71 QMainWindow w;
68 w.resize(350, 250);
72 w.resize(380, 250);
69 w.setCentralWidget(chartView);
73 w.setCentralWidget(chartView);
70 w.show();
74 w.show();
71
75
72 return a.exec();
76 return a.exec();
73 }
77 }
@@ -1,368 +1,351
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 For example, to create a chart with line series using a widget based application:
31 \snippet ../example/chartview/main.cpp 1
32 \image chartview_example.jpg
33
34 Showing a few more series:
35 \snippet ../example/chartview/main.cpp 3
36 \image chartview_example_pie.jpg
37 \snippet ../example/chartview/main.cpp 4
38 \image chartview_example_scatter.jpg
39 \snippet ../example/chartview/main.cpp 5
40 \image chartview_example_bar.jpg
41
42 If you need to give a more professional touch to your chart you can switch to one of the
43 pre-defined themes:
44 \snippet ../example/chartview/main.cpp 2
45 \image chartview_example_theme.jpg
46
47 \sa QChart
30 \sa QChart
48 */
31 */
49
32
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51
34
52 /*!
35 /*!
53 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.
54 */
37 */
55 QChartView::QChartView(QWidget *parent) :
38 QChartView::QChartView(QWidget *parent) :
56 QGraphicsView(parent),
39 QGraphicsView(parent),
57 m_scene(new QGraphicsScene(this)),
40 m_scene(new QGraphicsScene(this)),
58 m_chart(new QChart()),
41 m_chart(new QChart()),
59 m_rubberBand(0),
42 m_rubberBand(0),
60 m_verticalRubberBand(false),
43 m_verticalRubberBand(false),
61 m_horizonalRubberBand(false)
44 m_horizonalRubberBand(false)
62 {
45 {
63 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
64 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 setScene(m_scene);
48 setScene(m_scene);
66 m_chart->setMargin(50);
49 m_chart->setMargin(50);
67 m_scene->addItem(m_chart);
50 m_scene->addItem(m_chart);
68 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69 }
52 }
70
53
71
54
72 /*!
55 /*!
73 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.
74 */
57 */
75 QChartView::~QChartView()
58 QChartView::~QChartView()
76 {
59 {
77 }
60 }
78
61
79 /*!
62 /*!
80 Resizes and updates the chart area using the \a event data
63 Resizes and updates the chart area using the \a event data
81 */
64 */
82 void QChartView::resizeEvent(QResizeEvent *event)
65 void QChartView::resizeEvent(QResizeEvent *event)
83 {
66 {
84 m_scene->setSceneRect(0,0,size().width(),size().height());
67 m_scene->setSceneRect(0,0,size().width(),size().height());
85 m_chart->resize(size());
68 m_chart->resize(size());
86 QWidget::resizeEvent(event);
69 QWidget::resizeEvent(event);
87 }
70 }
88
71
89 /*!
72 /*!
90 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.
91 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
92 the y axis).
75 the y axis).
93 \sa removeSeries(), removeAllSeries()
76 \sa removeSeries(), removeAllSeries()
94 */
77 */
95 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
78 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
96 {
79 {
97 m_chart->addSeries(series,axisY);
80 m_chart->addSeries(series,axisY);
98 }
81 }
99
82
100 /*!
83 /*!
101 Removes the \a series specified in a perameter from the QChartView.
84 Removes the \a series specified in a perameter from the QChartView.
102 It releses its ownership of the specified QChartSeries object.
85 It releses its ownership of the specified QChartSeries object.
103 It does not delete the pointed QChartSeries data object
86 It does not delete the pointed QChartSeries data object
104 \sa addSeries(), removeAllSeries()
87 \sa addSeries(), removeAllSeries()
105 */
88 */
106 void QChartView::removeSeries(QChartSeries* series)
89 void QChartView::removeSeries(QChartSeries* series)
107 {
90 {
108 m_chart->removeSeries(series);
91 m_chart->removeSeries(series);
109 }
92 }
110
93
111 /*!
94 /*!
112 Removes all the QChartSeries that have been added to the QChartView
95 Removes all the QChartSeries that have been added to the QChartView
113 It also deletes the pointed QChartSeries data objects
96 It also deletes the pointed QChartSeries data objects
114 \sa addSeries(), removeSeries()
97 \sa addSeries(), removeSeries()
115 */
98 */
116 void QChartView::removeAllSeries()
99 void QChartView::removeAllSeries()
117 {
100 {
118 m_chart->removeAllSeries();
101 m_chart->removeAllSeries();
119 }
102 }
120
103
121 /*!
104 /*!
122 Zooms in the view by a factor of 2
105 Zooms in the view by a factor of 2
123 */
106 */
124 void QChartView::zoomIn()
107 void QChartView::zoomIn()
125 {
108 {
126 m_chart->zoomIn();
109 m_chart->zoomIn();
127 }
110 }
128
111
129 /*!
112 /*!
130 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.
131 */
114 */
132 void QChartView::zoomIn(const QRect& rect)
115 void QChartView::zoomIn(const QRect& rect)
133 {
116 {
134 m_chart->zoomIn(rect);
117 m_chart->zoomIn(rect);
135 }
118 }
136
119
137 /*!
120 /*!
138 Restores the view zoom level to the previous one.
121 Restores the view zoom level to the previous one.
139 */
122 */
140 void QChartView::zoomOut()
123 void QChartView::zoomOut()
141 {
124 {
142 m_chart->zoomOut();
125 m_chart->zoomOut();
143 }
126 }
144
127
145 /*!
128 /*!
146 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.
147 */
130 */
148 int QChartView::margin() const
131 int QChartView::margin() const
149 {
132 {
150 return m_chart->margin();
133 return m_chart->margin();
151 }
134 }
152
135
153 /*!
136 /*!
154 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 rendered above the chart.
155 */
138 */
156 void QChartView::setChartTitle(const QString& title)
139 void QChartView::setChartTitle(const QString& title)
157 {
140 {
158 m_chart->setChartTitle(title);
141 m_chart->setChartTitle(title);
159 }
142 }
160
143
161 /*!
144 /*!
162 Sets the \a font that is used for rendering the description text that is rendered above the chart.
145 Sets the \a font that is used for rendering the description text that is rendered above the chart.
163 */
146 */
164 void QChartView::setChartTitleFont(const QFont& font)
147 void QChartView::setChartTitleFont(const QFont& font)
165 {
148 {
166 m_chart->setChartTitleFont(font);
149 m_chart->setChartTitleFont(font);
167 }
150 }
168
151
169 /*!
152 /*!
170 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
153 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
171 */
154 */
172 void QChartView::setChartBackgroundBrush(const QBrush& brush)
155 void QChartView::setChartBackgroundBrush(const QBrush& brush)
173 {
156 {
174 m_chart->setChartBackgroundBrush(brush);
157 m_chart->setChartBackgroundBrush(brush);
175 }
158 }
176
159
177 /*!
160 /*!
178 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
161 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
179 */
162 */
180 void QChartView::setChartBackgroundPen(const QPen& pen)
163 void QChartView::setChartBackgroundPen(const QPen& pen)
181 {
164 {
182 m_chart->setChartBackgroundPen(pen);
165 m_chart->setChartBackgroundPen(pen);
183 }
166 }
184
167
185 /*!
168 /*!
186 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
169 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
187 */
170 */
188 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
171 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
189 {
172 {
190 switch(policy) {
173 switch(policy) {
191 case VerticalRubberBand:
174 case VerticalRubberBand:
192 m_verticalRubberBand = true;
175 m_verticalRubberBand = true;
193 m_horizonalRubberBand = false;
176 m_horizonalRubberBand = false;
194 break;
177 break;
195 case HorizonalRubberBand:
178 case HorizonalRubberBand:
196 m_verticalRubberBand = false;
179 m_verticalRubberBand = false;
197 m_horizonalRubberBand = true;
180 m_horizonalRubberBand = true;
198 break;
181 break;
199 case RectangleRubberBand:
182 case RectangleRubberBand:
200 m_verticalRubberBand = true;
183 m_verticalRubberBand = true;
201 m_horizonalRubberBand = true;
184 m_horizonalRubberBand = true;
202 break;
185 break;
203 case NoRubberBand:
186 case NoRubberBand:
204 default:
187 default:
205 delete m_rubberBand;
188 delete m_rubberBand;
206 m_rubberBand=0;
189 m_rubberBand=0;
207 m_horizonalRubberBand = false;
190 m_horizonalRubberBand = false;
208 m_verticalRubberBand = false;
191 m_verticalRubberBand = false;
209 return;
192 return;
210 }
193 }
211 if(!m_rubberBand) {
194 if(!m_rubberBand) {
212 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
195 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
213 m_rubberBand->setEnabled(true);
196 m_rubberBand->setEnabled(true);
214 }
197 }
215 }
198 }
216
199
217 /*!
200 /*!
218 Returns the RubberBandPolicy that is currently being used by the widget.
201 Returns the RubberBandPolicy that is currently being used by the widget.
219 */
202 */
220 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
203 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
221 {
204 {
222 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
205 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
223 if(m_horizonalRubberBand) return HorizonalRubberBand;
206 if(m_horizonalRubberBand) return HorizonalRubberBand;
224 if(m_verticalRubberBand) return VerticalRubberBand;
207 if(m_verticalRubberBand) return VerticalRubberBand;
225 return NoRubberBand;
208 return NoRubberBand;
226 }
209 }
227
210
228 /*!
211 /*!
229 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.
212 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.
230 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called.
213 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called.
231 */
214 */
232 void QChartView::mousePressEvent(QMouseEvent *event)
215 void QChartView::mousePressEvent(QMouseEvent *event)
233 {
216 {
234 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
217 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
235
218
236 int margin = m_chart->margin();
219 int margin = m_chart->margin();
237 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
220 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
238
221
239 if (rect.contains(event->pos())) {
222 if (rect.contains(event->pos())) {
240 m_rubberBandOrigin = event->pos();
223 m_rubberBandOrigin = event->pos();
241 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
224 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
242 m_rubberBand->show();
225 m_rubberBand->show();
243 event->accept();
226 event->accept();
244 }
227 }
245 }
228 }
246 else {
229 else {
247 QGraphicsView::mousePressEvent(event);
230 QGraphicsView::mousePressEvent(event);
248 }
231 }
249 }
232 }
250
233
251 /*!
234 /*!
252 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
235 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
253 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
236 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
254 */
237 */
255 void QChartView::mouseMoveEvent(QMouseEvent *event)
238 void QChartView::mouseMoveEvent(QMouseEvent *event)
256 {
239 {
257 if(m_rubberBand && m_rubberBand->isVisible()) {
240 if(m_rubberBand && m_rubberBand->isVisible()) {
258 int margin = m_chart->margin();
241 int margin = m_chart->margin();
259 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
242 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
260 int width = event->pos().x() - m_rubberBandOrigin.x();
243 int width = event->pos().x() - m_rubberBandOrigin.x();
261 int height = event->pos().y() - m_rubberBandOrigin.y();
244 int height = event->pos().y() - m_rubberBandOrigin.y();
262 if(!m_verticalRubberBand) {
245 if(!m_verticalRubberBand) {
263 m_rubberBandOrigin.setY(rect.top());
246 m_rubberBandOrigin.setY(rect.top());
264 height = rect.height();
247 height = rect.height();
265 }
248 }
266 if(!m_horizonalRubberBand) {
249 if(!m_horizonalRubberBand) {
267 m_rubberBandOrigin.setX(rect.left());
250 m_rubberBandOrigin.setX(rect.left());
268 width= rect.width();
251 width= rect.width();
269 }
252 }
270 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
253 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
271 }
254 }
272 else {
255 else {
273 QGraphicsView::mouseMoveEvent(event);
256 QGraphicsView::mouseMoveEvent(event);
274 }
257 }
275 }
258 }
276
259
277 /*!
260 /*!
278 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
261 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
279 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
262 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
280 */
263 */
281 void QChartView::mouseReleaseEvent(QMouseEvent *event)
264 void QChartView::mouseReleaseEvent(QMouseEvent *event)
282 {
265 {
283 if(m_rubberBand) {
266 if(m_rubberBand) {
284 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
267 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
285 m_rubberBand->hide();
268 m_rubberBand->hide();
286 QRect rect = m_rubberBand->geometry();
269 QRect rect = m_rubberBand->geometry();
287 m_chart->zoomIn(rect);
270 m_chart->zoomIn(rect);
288 event->accept();
271 event->accept();
289 }
272 }
290
273
291 if(event->button()==Qt::RightButton)
274 if(event->button()==Qt::RightButton)
292 m_chart->zoomReset();
275 m_chart->zoomReset();
293 }
276 }
294 else {
277 else {
295 QGraphicsView::mouseReleaseEvent(event);
278 QGraphicsView::mouseReleaseEvent(event);
296 }
279 }
297 }
280 }
298
281
299 /*!
282 /*!
300 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
283 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
301 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
284 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
302 */
285 */
303 void QChartView::keyPressEvent(QKeyEvent *event)
286 void QChartView::keyPressEvent(QKeyEvent *event)
304 {
287 {
305 switch (event->key()) {
288 switch (event->key()) {
306 case Qt::Key_Plus:
289 case Qt::Key_Plus:
307 zoomIn();
290 zoomIn();
308 break;
291 break;
309 case Qt::Key_Minus:
292 case Qt::Key_Minus:
310 zoomOut();
293 zoomOut();
311 break;
294 break;
312 default:
295 default:
313 QGraphicsView::keyPressEvent(event);
296 QGraphicsView::keyPressEvent(event);
314 break;
297 break;
315 }
298 }
316 }
299 }
317
300
318 /*!
301 /*!
319 Sets the \a theme used by the chart for rendering the graphical representation of the data
302 Sets the \a theme used by the chart for rendering the graphical representation of the data
320 \sa QChart::ChartTheme, chartTheme()
303 \sa QChart::ChartTheme, chartTheme()
321 */
304 */
322 void QChartView::setChartTheme(QChart::ChartTheme theme)
305 void QChartView::setChartTheme(QChart::ChartTheme theme)
323 {
306 {
324 m_chart->setChartTheme(theme);
307 m_chart->setChartTheme(theme);
325 }
308 }
326
309
327 /*!
310 /*!
328 Returns the theme enum used by the chart.
311 Returns the theme enum used by the chart.
329 \sa setChartTheme()
312 \sa setChartTheme()
330 */
313 */
331 QChart::ChartTheme QChartView::chartTheme() const
314 QChart::ChartTheme QChartView::chartTheme() const
332 {
315 {
333 return m_chart->chartTheme();
316 return m_chart->chartTheme();
334 }
317 }
335
318
336 /*!
319 /*!
337 Returns the pointer to the x axis object of the chart
320 Returns the pointer to the x axis object of the chart
338 */
321 */
339 QChartAxis* QChartView::axisX() const
322 QChartAxis* QChartView::axisX() const
340 {
323 {
341 return m_chart->axisX();
324 return m_chart->axisX();
342 }
325 }
343
326
344 /*!
327 /*!
345 Returns the pointer to the y axis object of the chart
328 Returns the pointer to the y axis object of the chart
346 */
329 */
347 QChartAxis* QChartView::axisY() const
330 QChartAxis* QChartView::axisY() const
348 {
331 {
349 return m_chart->axisY();
332 return m_chart->axisY();
350 }
333 }
351
334
352 /*!
335 /*!
353 Sets animation \a options for the chart
336 Sets animation \a options for the chart
354 */
337 */
355 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
338 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
356 {
339 {
357 m_chart->setAnimationOptions(options);
340 m_chart->setAnimationOptions(options);
358 }
341 }
359
342
360 /*!
343 /*!
361 Returns animation options for the chart
344 Returns animation options for the chart
362 */
345 */
363 QChart::AnimationOptions QChartView::animationOptions() const
346 QChart::AnimationOptions QChartView::animationOptions() const
364 {
347 {
365 return m_chart->animationOptions();
348 return m_chart->animationOptions();
366 }
349 }
367
350
368 QTCOMMERCIALCHART_END_NAMESPACE
351 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now