##// END OF EJS Templates
adds QChartView PIMPL, refactor public API
Michal Klocek -
r746:646ccd5c026b
parent child
Show More
@@ -1,439 +1,459
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "qchart.h"
21 #include "qchart.h"
2 #include "qchart_p.h"
22 #include "qchart_p.h"
3 #include <QGraphicsScene>
23 #include <QGraphicsScene>
4 #include <QGraphicsSceneResizeEvent>
24 #include <QGraphicsSceneResizeEvent>
5
25
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
27
8 /*!
28 /*!
9 \enum QChart::ChartTheme
29 \enum QChart::ChartTheme
10
30
11 This enum describes the theme used by the chart.
31 This enum describes the theme used by the chart.
12
32
13 \value ChartThemeDefault Follows the GUI style of the Operating System
33 \value ChartThemeDefault Follows the GUI style of the Operating System
14 \value ChartThemeLight
34 \value ChartThemeLight
15 \value ChartThemeBlueCerulean
35 \value ChartThemeBlueCerulean
16 \value ChartThemeDark
36 \value ChartThemeDark
17 \value ChartThemeBrownSand
37 \value ChartThemeBrownSand
18 \value ChartThemeBlueNcs
38 \value ChartThemeBlueNcs
19 \value ChartThemeIcy
39 \value ChartThemeIcy
20 \value ChartThemeScientific
40 \value ChartThemeScientific
21 \value ChartThemeCount Not really a theme; the total count of themes.
41 \value ChartThemeCount Not really a theme; the total count of themes.
22 */
42 */
23
43
24 /*!
44 /*!
25 \enum QChart::AnimationOption
45 \enum QChart::AnimationOption
26
46
27 For enabling/disabling animations. Defaults to NoAnimation.
47 For enabling/disabling animations. Defaults to NoAnimation.
28
48
29 \value NoAnimation
49 \value NoAnimation
30 \value GridAxisAnimations
50 \value GridAxisAnimations
31 \value SeriesAnimations
51 \value SeriesAnimations
32 \value AllAnimations
52 \value AllAnimations
33 */
53 */
34
54
35 /*!
55 /*!
36 \class QChart
56 \class QChart
37 \brief QtCommercial chart API.
57 \brief QtCommercial chart API.
38
58
39 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
59 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
40 representation of different types of QChartSeries and other chart related objects like
60 representation of different types of QChartSeries and other chart related objects like
41 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
61 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
42 convenience class QChartView instead of QChart.
62 convenience class QChartView instead of QChart.
43 \sa QChartView
63 \sa QChartView
44 */
64 */
45
65
46 /*!
66 /*!
47 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
67 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
48 */
68 */
49 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
69 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
50 d_ptr(new QChartPrivate(this))
70 d_ptr(new QChartPrivate(this))
51 {
71 {
52 d_ptr->m_legend = new QLegend(this);
72 d_ptr->m_legend = new QLegend(this);
53 d_ptr->m_dataset = new ChartDataSet(this);
73 d_ptr->m_dataset = new ChartDataSet(this);
54 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
55
75
56 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
76 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
57 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
77 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
58 }
78 }
59
79
60 /*!
80 /*!
61 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
81 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
62 */
82 */
63 QChart::~QChart()
83 QChart::~QChart()
64 {
84 {
65 //delete first presenter , since this is a root of all the graphical items
85 //delete first presenter , since this is a root of all the graphical items
66 delete d_ptr->m_presenter;
86 delete d_ptr->m_presenter;
67 d_ptr->m_presenter=0;
87 d_ptr->m_presenter=0;
68 }
88 }
69
89
70 /*!
90 /*!
71 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
91 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
72 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
92 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
73 the y axis).
93 the y axis).
74 */
94 */
75 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
95 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
76 {
96 {
77 d_ptr->m_dataset->addSeries(series, axisY);
97 d_ptr->m_dataset->addSeries(series, axisY);
78 }
98 }
79
99
80 /*!
100 /*!
81 Removes the \a series specified in a perameter from the QChartView.
101 Removes the \a series specified in a perameter from the QChartView.
82 It releses its ownership of the specified QChartSeries object.
102 It releses its ownership of the specified QChartSeries object.
83 It does not delete the pointed QChartSeries data object
103 It does not delete the pointed QChartSeries data object
84 \sa addSeries(), removeAllSeries()
104 \sa addSeries(), removeAllSeries()
85 */
105 */
86 void QChart::removeSeries(QSeries* series)
106 void QChart::removeSeries(QSeries* series)
87 {
107 {
88 d_ptr->m_dataset->removeSeries(series);
108 d_ptr->m_dataset->removeSeries(series);
89 }
109 }
90
110
91 /*!
111 /*!
92 Removes all the QChartSeries that have been added to the QChartView
112 Removes all the QChartSeries that have been added to the QChartView
93 It also deletes the pointed QChartSeries data objects
113 It also deletes the pointed QChartSeries data objects
94 \sa addSeries(), removeSeries()
114 \sa addSeries(), removeSeries()
95 */
115 */
96 void QChart::removeAllSeries()
116 void QChart::removeAllSeries()
97 {
117 {
98 d_ptr->m_dataset->removeAllSeries();
118 d_ptr->m_dataset->removeAllSeries();
99 }
119 }
100
120
101 /*!
121 /*!
102 Sets the \a brush that is used for painting the background of the chart area.
122 Sets the \a brush that is used for painting the background of the chart area.
103 */
123 */
104 void QChart::setBackgroundBrush(const QBrush& brush)
124 void QChart::setBackgroundBrush(const QBrush& brush)
105 {
125 {
106 d_ptr->createChartBackgroundItem();
126 d_ptr->createChartBackgroundItem();
107 d_ptr->m_backgroundItem->setBrush(brush);
127 d_ptr->m_backgroundItem->setBrush(brush);
108 d_ptr->m_backgroundItem->update();
128 d_ptr->m_backgroundItem->update();
109 }
129 }
110
130
111 QBrush QChart::backgroundBrush() const
131 QBrush QChart::backgroundBrush() const
112 {
132 {
113 if (!d_ptr->m_backgroundItem) return QBrush();
133 if (!d_ptr->m_backgroundItem) return QBrush();
114 return (d_ptr->m_backgroundItem)->brush();
134 return (d_ptr->m_backgroundItem)->brush();
115 }
135 }
116
136
117 /*!
137 /*!
118 Sets the \a pen that is used for painting the background of the chart area.
138 Sets the \a pen that is used for painting the background of the chart area.
119 */
139 */
120 void QChart::setBackgroundPen(const QPen& pen)
140 void QChart::setBackgroundPen(const QPen& pen)
121 {
141 {
122 d_ptr->createChartBackgroundItem();
142 d_ptr->createChartBackgroundItem();
123 d_ptr->m_backgroundItem->setPen(pen);
143 d_ptr->m_backgroundItem->setPen(pen);
124 d_ptr->m_backgroundItem->update();
144 d_ptr->m_backgroundItem->update();
125 }
145 }
126
146
127 QPen QChart::backgroundPen() const
147 QPen QChart::backgroundPen() const
128 {
148 {
129 if (!d_ptr->m_backgroundItem) return QPen();
149 if (!d_ptr->m_backgroundItem) return QPen();
130 return d_ptr->m_backgroundItem->pen();
150 return d_ptr->m_backgroundItem->pen();
131 }
151 }
132
152
133 /*!
153 /*!
134 Sets the chart \a title. The description text that is drawn above the chart.
154 Sets the chart \a title. The description text that is drawn above the chart.
135 */
155 */
136 void QChart::setTitle(const QString& title)
156 void QChart::setTitle(const QString& title)
137 {
157 {
138 d_ptr->createChartTitleItem();
158 d_ptr->createChartTitleItem();
139 d_ptr->m_titleItem->setText(title);
159 d_ptr->m_titleItem->setText(title);
140 d_ptr->updateLayout();
160 d_ptr->updateLayout();
141 }
161 }
142
162
143 /*!
163 /*!
144 Returns the chart title. The description text that is drawn above the chart.
164 Returns the chart title. The description text that is drawn above the chart.
145 */
165 */
146 QString QChart::title() const
166 QString QChart::title() const
147 {
167 {
148 if (d_ptr->m_titleItem)
168 if (d_ptr->m_titleItem)
149 return d_ptr->m_titleItem->text();
169 return d_ptr->m_titleItem->text();
150 else
170 else
151 return QString();
171 return QString();
152 }
172 }
153
173
154 /*!
174 /*!
155 Sets the \a font that is used for rendering the description text that is rendered above the chart.
175 Sets the \a font that is used for rendering the description text that is rendered above the chart.
156 */
176 */
157 void QChart::setTitleFont(const QFont& font)
177 void QChart::setTitleFont(const QFont& font)
158 {
178 {
159 d_ptr->createChartTitleItem();
179 d_ptr->createChartTitleItem();
160 d_ptr->m_titleItem->setFont(font);
180 d_ptr->m_titleItem->setFont(font);
161 d_ptr->updateLayout();
181 d_ptr->updateLayout();
162 }
182 }
163
183
164 /*!
184 /*!
165 Sets the \a brush used for rendering the title text.
185 Sets the \a brush used for rendering the title text.
166 */
186 */
167 void QChart::setTitleBrush(const QBrush &brush)
187 void QChart::setTitleBrush(const QBrush &brush)
168 {
188 {
169 d_ptr->createChartTitleItem();
189 d_ptr->createChartTitleItem();
170 d_ptr->m_titleItem->setBrush(brush);
190 d_ptr->m_titleItem->setBrush(brush);
171 d_ptr->updateLayout();
191 d_ptr->updateLayout();
172 }
192 }
173
193
174 /*!
194 /*!
175 Returns the brush used for rendering the title text.
195 Returns the brush used for rendering the title text.
176 */
196 */
177 QBrush QChart::titleBrush() const
197 QBrush QChart::titleBrush() const
178 {
198 {
179 if (!d_ptr->m_titleItem) return QBrush();
199 if (!d_ptr->m_titleItem) return QBrush();
180 return d_ptr->m_titleItem->brush();
200 return d_ptr->m_titleItem->brush();
181 }
201 }
182
202
183 /*!
203 /*!
184 Sets the \a theme used by the chart for rendering the graphical representation of the data
204 Sets the \a theme used by the chart for rendering the graphical representation of the data
185 \sa ChartTheme, chartTheme()
205 \sa ChartTheme, chartTheme()
186 */
206 */
187 void QChart::setTheme(QChart::ChartTheme theme)
207 void QChart::setTheme(QChart::ChartTheme theme)
188 {
208 {
189 d_ptr->m_presenter->setTheme(theme);
209 d_ptr->m_presenter->setTheme(theme);
190 }
210 }
191
211
192 /*!
212 /*!
193 Returns the theme enum used by the chart.
213 Returns the theme enum used by the chart.
194 \sa ChartTheme, setChartTheme()
214 \sa ChartTheme, setChartTheme()
195 */
215 */
196 QChart::ChartTheme QChart::theme() const
216 QChart::ChartTheme QChart::theme() const
197 {
217 {
198 return d_ptr->m_presenter->theme();
218 return d_ptr->m_presenter->theme();
199 }
219 }
200
220
201 /*!
221 /*!
202 Zooms in the view by a factor of 2
222 Zooms in the view by a factor of 2
203 */
223 */
204 void QChart::zoomIn()
224 void QChart::zoomIn()
205 {
225 {
206 d_ptr->m_presenter->zoomIn();
226 d_ptr->m_presenter->zoomIn();
207 }
227 }
208
228
209 /*!
229 /*!
210 Zooms in the view to a maximum level at which \a rect is still fully visible.
230 Zooms in the view to a maximum level at which \a rect is still fully visible.
211 */
231 */
212 void QChart::zoomIn(const QRectF& rect)
232 void QChart::zoomIn(const QRectF& rect)
213 {
233 {
214 if (!rect.isValid()) return;
234 if (!rect.isValid()) return;
215 d_ptr->m_presenter->zoomIn(rect);
235 d_ptr->m_presenter->zoomIn(rect);
216 }
236 }
217
237
218 /*!
238 /*!
219 Restores the view zoom level to the previous one.
239 Restores the view zoom level to the previous one.
220 */
240 */
221 void QChart::zoomOut()
241 void QChart::zoomOut()
222 {
242 {
223 d_ptr->m_presenter->zoomOut();
243 d_ptr->m_presenter->zoomOut();
224 }
244 }
225
245
226 /*!
246 /*!
227 Returns the pointer to the x axis object of the chart
247 Returns the pointer to the x axis object of the chart
228 */
248 */
229 QChartAxis* QChart::axisX() const
249 QChartAxis* QChart::axisX() const
230 {
250 {
231 return d_ptr->m_dataset->axisX();
251 return d_ptr->m_dataset->axisX();
232 }
252 }
233
253
234 /*!
254 /*!
235 Returns the pointer to the y axis object of the chart
255 Returns the pointer to the y axis object of the chart
236 */
256 */
237 QChartAxis* QChart::axisY() const
257 QChartAxis* QChart::axisY() const
238 {
258 {
239 return d_ptr->m_dataset->axisY();
259 return d_ptr->m_dataset->axisY();
240 }
260 }
241
261
242 /*!
262 /*!
243 Returns the legend object of the chart. Ownership stays in chart.
263 Returns the legend object of the chart. Ownership stays in chart.
244 */
264 */
245 QLegend& QChart::legend() const
265 QLegend& QChart::legend() const
246 {
266 {
247 return *d_ptr->m_legend;
267 return *d_ptr->m_legend;
248 }
268 }
249
269
250 /*!
270 /*!
251 Gives ownership of legend to user.
271 Gives ownership of legend to user.
252 */
272 */
253 QLegend* QChart::takeLegend()
273 QLegend* QChart::takeLegend()
254 {
274 {
255 QLegend* l = d_ptr->m_legend;
275 QLegend* l = d_ptr->m_legend;
256 d_ptr->m_legend = 0;
276 d_ptr->m_legend = 0;
257 return l;
277 return l;
258 }
278 }
259
279
260 /*!
280 /*!
261 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
281 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
262 */
282 */
263 void QChart::giveLegend(QLegend *legend)
283 void QChart::giveLegend(QLegend *legend)
264 {
284 {
265 if (d_ptr->m_legend) {
285 if (d_ptr->m_legend) {
266 // Should not happen.
286 // Should not happen.
267 qDebug() << "Warning! Giving more than one legend to chart.";
287 qDebug() << "Warning! Giving more than one legend to chart.";
268 delete d_ptr->m_legend;
288 delete d_ptr->m_legend;
269 }
289 }
270
290
271 d_ptr->m_legend = legend;
291 d_ptr->m_legend = legend;
272
292
273 // Reconnect legend, in case not already connected.
293 // Reconnect legend, in case not already connected.
274 disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
294 disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
275 disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
295 disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
276 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
296 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
277 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
297 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
278 }
298 }
279
299
280 /*!
300 /*!
281 Resizes and updates the chart area using the \a event data
301 Resizes and updates the chart area using the \a event data
282 */
302 */
283 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
303 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
284 {
304 {
285 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
305 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
286 d_ptr->updateLayout();
306 d_ptr->updateLayout();
287 QGraphicsWidget::resizeEvent(event);
307 QGraphicsWidget::resizeEvent(event);
288 update();
308 update();
289 }
309 }
290
310
291 /*!
311 /*!
292 Sets animation \a options for the chart
312 Sets animation \a options for the chart
293 */
313 */
294 void QChart::setAnimationOptions(AnimationOptions options)
314 void QChart::setAnimationOptions(AnimationOptions options)
295 {
315 {
296 d_ptr->m_presenter->setAnimationOptions(options);
316 d_ptr->m_presenter->setAnimationOptions(options);
297 }
317 }
298
318
299 /*!
319 /*!
300 Returns animation options for the chart
320 Returns animation options for the chart
301 */
321 */
302 QChart::AnimationOptions QChart::animationOptions() const
322 QChart::AnimationOptions QChart::animationOptions() const
303 {
323 {
304 return d_ptr->m_presenter->animationOptions();
324 return d_ptr->m_presenter->animationOptions();
305 }
325 }
306
326
307 void QChart::scrollLeft()
327 void QChart::scrollLeft()
308 {
328 {
309 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
329 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
310 }
330 }
311
331
312 void QChart::scrollRight()
332 void QChart::scrollRight()
313 {
333 {
314 d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
334 d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
315 }
335 }
316
336
317 void QChart::scrollUp()
337 void QChart::scrollUp()
318 {
338 {
319 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
339 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
320 }
340 }
321
341
322 void QChart::scrollDown()
342 void QChart::scrollDown()
323 {
343 {
324 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
344 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
325 }
345 }
326
346
327 void QChart::setBackgroundVisible(bool visible)
347 void QChart::setBackgroundVisible(bool visible)
328 {
348 {
329 d_ptr->createChartBackgroundItem();
349 d_ptr->createChartBackgroundItem();
330 d_ptr->m_backgroundItem->setVisible(visible);
350 d_ptr->m_backgroundItem->setVisible(visible);
331 }
351 }
332
352
333 bool QChart::isBackgroundVisible() const
353 bool QChart::isBackgroundVisible() const
334 {
354 {
335 if (!d_ptr->m_backgroundItem) return false;
355 if (!d_ptr->m_backgroundItem) return false;
336 return d_ptr->m_backgroundItem->isVisible();
356 return d_ptr->m_backgroundItem->isVisible();
337 }
357 }
338
358
339 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
359 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
340
360
341 QChartPrivate::QChartPrivate(QChart *parent):
361 QChartPrivate::QChartPrivate(QChart *parent):
342 q_ptr(parent),
362 q_ptr(parent),
343 m_backgroundItem(0),
363 m_backgroundItem(0),
344 m_titleItem(0),
364 m_titleItem(0),
345 m_legend(0),
365 m_legend(0),
346 m_dataset(0),
366 m_dataset(0),
347 m_presenter(0)
367 m_presenter(0)
348 {
368 {
349
369
350 }
370 }
351
371
352 QChartPrivate::~QChartPrivate()
372 QChartPrivate::~QChartPrivate()
353 {
373 {
354
374
355 }
375 }
356
376
357 void QChartPrivate::createChartBackgroundItem()
377 void QChartPrivate::createChartBackgroundItem()
358 {
378 {
359 if (!m_backgroundItem) {
379 if (!m_backgroundItem) {
360 m_backgroundItem = new ChartBackground(q_ptr);
380 m_backgroundItem = new ChartBackground(q_ptr);
361 m_backgroundItem->setPen(Qt::NoPen);
381 m_backgroundItem->setPen(Qt::NoPen);
362 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
382 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
363 }
383 }
364 }
384 }
365
385
366 void QChartPrivate::createChartTitleItem()
386 void QChartPrivate::createChartTitleItem()
367 {
387 {
368 if (!m_titleItem) {
388 if (!m_titleItem) {
369 m_titleItem = new QGraphicsSimpleTextItem(q_ptr);
389 m_titleItem = new QGraphicsSimpleTextItem(q_ptr);
370 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
390 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
371 }
391 }
372 }
392 }
373
393
374 void QChartPrivate::updateLegendLayout()
394 void QChartPrivate::updateLegendLayout()
375 {
395 {
376 int padding = m_presenter->padding();
396 int padding = m_presenter->padding();
377 QRectF plotRect = m_rect.adjusted(padding,padding,-padding,-padding);
397 QRectF plotRect = m_rect.adjusted(padding,padding,-padding,-padding);
378 QRectF legendRect;
398 QRectF legendRect;
379
399
380 switch (m_legend->preferredLayout())
400 switch (m_legend->preferredLayout())
381 {
401 {
382 case QLegend::PreferredLayoutTop: {
402 case QLegend::PreferredLayoutTop: {
383 // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height());
403 // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height());
384 legendRect = plotRect.adjusted(0,0,0,-padding - plotRect.height());
404 legendRect = plotRect.adjusted(0,0,0,-padding - plotRect.height());
385 break;
405 break;
386 }
406 }
387 case QLegend::PreferredLayoutBottom: {
407 case QLegend::PreferredLayoutBottom: {
388 legendRect = plotRect.adjusted(padding,padding + plotRect.height(),-padding,0);
408 legendRect = plotRect.adjusted(padding,padding + plotRect.height(),-padding,0);
389 break;
409 break;
390 }
410 }
391 case QLegend::PreferredLayoutLeft: {
411 case QLegend::PreferredLayoutLeft: {
392 legendRect = plotRect.adjusted(0,padding,-padding - plotRect.width(),-padding);
412 legendRect = plotRect.adjusted(0,padding,-padding - plotRect.width(),-padding);
393 break;
413 break;
394 }
414 }
395 case QLegend::PreferredLayoutRight: {
415 case QLegend::PreferredLayoutRight: {
396 legendRect = plotRect.adjusted(padding + plotRect.width(),padding,0,-padding);
416 legendRect = plotRect.adjusted(padding + plotRect.width(),padding,0,-padding);
397 break;
417 break;
398 }
418 }
399 default: {
419 default: {
400 legendRect = plotRect;
420 legendRect = plotRect;
401 break;
421 break;
402 }
422 }
403 }
423 }
404
424
405 m_legend->setMaximumSize(legendRect.size());
425 m_legend->setMaximumSize(legendRect.size());
406 m_legend->setPos(legendRect.topLeft());
426 m_legend->setPos(legendRect.topLeft());
407 }
427 }
408
428
409 void QChartPrivate::updateLayout()
429 void QChartPrivate::updateLayout()
410 {
430 {
411 if (!m_rect.isValid()) return;
431 if (!m_rect.isValid()) return;
412
432
413 int padding = m_presenter->padding();
433 int padding = m_presenter->padding();
414 int backgroundPadding = m_presenter->backgroundPadding();
434 int backgroundPadding = m_presenter->backgroundPadding();
415
435
416 QRectF rect = m_rect.adjusted(padding,padding,-padding,-padding);
436 QRectF rect = m_rect.adjusted(padding,padding,-padding,-padding);
417
437
418 // recalculate title position
438 // recalculate title position
419 if (m_titleItem) {
439 if (m_titleItem) {
420 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
440 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
421 m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2);
441 m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2);
422 }
442 }
423
443
424 //recalculate background gradient
444 //recalculate background gradient
425 if (m_backgroundItem) {
445 if (m_backgroundItem) {
426 m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding));
446 m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding));
427 }
447 }
428
448
429 // recalculate legend position
449 // recalculate legend position
430 if (m_legend) {
450 if (m_legend) {
431 if (m_legend->parentObject() == q_ptr) {
451 if (m_legend->parentObject() == q_ptr) {
432 updateLegendLayout();
452 updateLegendLayout();
433 }
453 }
434 }
454 }
435 }
455 }
436
456
437 #include "moc_qchart.cpp"
457 #include "moc_qchart.cpp"
438
458
439 QTCOMMERCIALCHART_END_NAMESPACE
459 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,117 +1,117
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 class QChartPrivate;
34 class 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 public:
39 public:
40 enum ChartTheme {
40 enum ChartTheme {
41 ChartThemeDefault,
41 ChartThemeDefault,
42 ChartThemeLight,
42 ChartThemeLight,
43 ChartThemeBlueCerulean,
43 ChartThemeBlueCerulean,
44 ChartThemeDark,
44 ChartThemeDark,
45 ChartThemeBrownSand,
45 ChartThemeBrownSand,
46 ChartThemeBlueNcs,
46 ChartThemeBlueNcs,
47 ChartThemeIcy,
47 ChartThemeIcy,
48 ChartThemeScientific,
48 ChartThemeScientific,
49 ChartThemeCount
49 ChartThemeCount
50 };
50 };
51
51
52 enum AnimationOption {
52 enum AnimationOption {
53 NoAnimation = 0x0,
53 NoAnimation = 0x0,
54 GridAxisAnimations = 0x1,
54 GridAxisAnimations = 0x1,
55 SeriesAnimations =0x2,
55 SeriesAnimations =0x2,
56 AllAnimations = 0x3
56 AllAnimations = 0x3
57 };
57 };
58
58
59 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
59 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
60
60
61 public:
61 public:
62 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
62 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
63 ~QChart();
63 ~QChart();
64
64
65 void addSeries(QSeries *series, QChartAxis *axisY = 0);
65 void addSeries(QSeries *series, QChartAxis *axisY = 0);
66 void removeSeries(QSeries *series);
66 void removeSeries(QSeries *series);
67 void removeAllSeries();
67 void removeAllSeries();
68
68
69 void setTheme(QChart::ChartTheme theme);
69 void setTheme(QChart::ChartTheme theme);
70 QChart::ChartTheme theme() const;
70 QChart::ChartTheme theme() const;
71
71
72 void setTitle(const QString& title);
72 void setTitle(const QString& title);
73 QString title() const;
73 QString title() const;
74 void setTitleFont(const QFont& font);
74 void setTitleFont(const QFont& font);
75 QFont titleFont() const;
75 QFont titleFont() const;
76 void setTitleBrush(const QBrush &brush);
76 void setTitleBrush(const QBrush &brush);
77 QBrush titleBrush() const;
77 QBrush titleBrush() const;
78 void setBackgroundBrush(const QBrush& brush);
78 void setBackgroundBrush(const QBrush& brush);
79 QBrush backgroundBrush() const;
79 QBrush backgroundBrush() const;
80 void setBackgroundPen(const QPen& pen);
80 void setBackgroundPen(const QPen& pen);
81 QPen backgroundPen() const;
81 QPen backgroundPen() const;
82
82
83 void setBackgroundVisible(bool visible);
83 void setBackgroundVisible(bool visible);
84 bool isBackgroundVisible() const;
84 bool isBackgroundVisible() const;
85
85
86 void setAnimationOptions(AnimationOptions options);
86 void setAnimationOptions(AnimationOptions options);
87 AnimationOptions animationOptions() const;
87 AnimationOptions animationOptions() const;
88
88
89 void zoomIn();
89 void zoomIn();
90 void zoomIn(const QRectF& rect);
90 void zoomIn(const QRectF& rect);
91 void zoomOut();
91 void zoomOut();
92 void scrollLeft();
92 void scrollLeft();
93 void scrollRight();
93 void scrollRight();
94 void scrollUp();
94 void scrollUp();
95 void scrollDown();
95 void scrollDown();
96
96
97 QChartAxis* axisX() const;
97 QChartAxis* axisX() const;
98 QChartAxis* axisY() const;
98 QChartAxis* axisY() const;
99
99
100 QLegend& legend() const;
100 QLegend& legend() const;
101 QLegend* takeLegend();
101 QLegend* takeLegend();
102 void giveLegend(QLegend* legend);
102 void giveLegend(QLegend* legend);
103
103
104 protected:
104 protected:
105 void resizeEvent(QGraphicsSceneResizeEvent *event);
105 void resizeEvent(QGraphicsSceneResizeEvent *event);
106
106
107 protected:
107 protected:
108 QScopedPointer<QChartPrivate> d_ptr;
108 QScopedPointer<QChartPrivate> d_ptr;
109 friend class QChartView;
109 friend class QChartView;
110 Q_DISABLE_COPY(QChart);
110 Q_DISABLE_COPY(QChart);
111 };
111 };
112
112
113 QTCOMMERCIALCHART_END_NAMESPACE
113 QTCOMMERCIALCHART_END_NAMESPACE
114
114
115 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
115 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
116
116
117 #endif
117 #endif
@@ -1,38 +1,43
1 // W A R N I N G
2 // -------------
3 //
4 // This file is not part of the QtCommercial Chart API. It exists purely as an
5 // implementation detail. This header file may change from version to
6 // version without notice, or even be removed.
7 //
8 // We mean it.
9
1 #ifndef QCHART_P_H
10 #ifndef QCHART_P_H
2 #define QCHART_P_H
11 #define QCHART_P_H
3
12
4 #include "private/qgraphicswidget_p.h"
5 #include "qchartaxis.h"
13 #include "qchartaxis.h"
6 #include "qlegend.h"
14 #include "qlegend.h"
7 #include "chartpresenter_p.h"
15 #include "chartpresenter_p.h"
8 #include "chartdataset_p.h"
16 #include "chartdataset_p.h"
9 #include "chartbackground_p.h"
17 #include "chartbackground_p.h"
10
18
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
19 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
20
13 class QChart;
21 class QChart;
14
22
15 class QChartPrivate
23 struct QChartPrivate
16 {
24 {
17 public:
18 QChartPrivate(QChart *parent);
25 QChartPrivate(QChart *parent);
19 ~QChartPrivate();
26 ~QChartPrivate();
20
27
21 void createChartBackgroundItem();
28 void createChartBackgroundItem();
22 void createChartTitleItem();
29 void createChartTitleItem();
23 void updateLayout();
30 void updateLayout();
24 void updateLegendLayout();
31 void updateLegendLayout();
25
32
26 QChart *q_ptr;
33 QChart *q_ptr;
27 ChartBackground* m_backgroundItem;
34 ChartBackground* m_backgroundItem;
28 QGraphicsSimpleTextItem* m_titleItem;
35 QGraphicsSimpleTextItem* m_titleItem;
29 QRectF m_rect;
36 QRectF m_rect;
30 QLegend* m_legend;
37 QLegend* m_legend;
31 ChartDataSet *m_dataset;
38 ChartDataSet *m_dataset;
32 ChartPresenter *m_presenter;
39 ChartPresenter *m_presenter;
33
34 Q_DECLARE_PUBLIC(QChart);
35 };
40 };
36
41
37 QTCOMMERCIALCHART_END_NAMESPACE
42 QTCOMMERCIALCHART_END_NAMESPACE
38 #endif
43 #endif
@@ -1,416 +1,233
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "qchartview.h"
21 #include "qchartview.h"
2 #include "qchart.h"
3 #include "qchart_p.h"
22 #include "qchart_p.h"
4 #include "qchartaxis.h"
23 #include "qchartview_p.h"
5 #include <QGraphicsView>
6 #include <QGraphicsScene>
24 #include <QGraphicsScene>
7 #include <QRubberBand>
25 #include <QRubberBand>
8 #include <QResizeEvent>
26
9
27
10 /*!
28 /*!
11 \enum QChartView::RubberBandPolicy
29 \enum QChartView::RubberBandPolicy
12
30
13 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
14
32
15 \value NoRubberBand
33 \value NoRubberBand
16 \value VerticalRubberBand
34 \value VerticalRubberBand
17 \value HorizonalRubberBand
35 \value HorizonalRubberBand
18 \value RectangleRubberBand
36 \value RectangleRubberBand
19 */
37 */
20
38
21 /*!
39 /*!
22 \class QChartView
40 \class QChartView
23 \brief Standalone charting widget.
41 \brief Standalone charting widget.
24
42
25 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
26 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
27 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
28 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.
29
47
30 \sa QChart
48 \sa QChart
31 */
49 */
32
50
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
52
35 /*!
53 /*!
36 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.
37 */
55 */
38 QChartView::QChartView(QWidget *parent) :
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
39 QGraphicsView(parent),
57 QGraphicsView(parent),
40 m_scene(new QGraphicsScene(this)),
58 d_ptr(new QChartViewPrivate())
41 m_chart(new QChart()),
42 m_rubberBand(0),
43 m_verticalRubberBand(false),
44 m_horizonalRubberBand(false)
45 {
59 {
60 d_ptr->m_scene = new QGraphicsScene(this);
61 d_ptr->m_chart = chart;
62 d_ptr->m_presenter = chart->d_ptr->m_presenter;
63
46 setFrameShape(QFrame::NoFrame);
64 setFrameShape(QFrame::NoFrame);
47 setBackgroundRole(QPalette::Window);
65 setBackgroundRole(QPalette::Window);
48 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
49 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
50 setScene(m_scene);
68 setScene(d_ptr->m_scene);
51 m_scene->addItem(m_chart);
69 d_ptr->m_scene->addItem(chart);
52 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
70 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
53 }
71 }
54
72
55
73
56 /*!
74 /*!
57 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
75 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
58 */
76 */
59 QChartView::~QChartView()
77 QChartView::~QChartView()
60 {
78 {
61 }
79 }
62
80
63 /*!
81 QChart* QChartView::chart() const
64 Resizes and updates the chart area using the \a event data
65 */
66 void QChartView::resizeEvent(QResizeEvent *event)
67 {
68 m_chart->resize(size());
69 QGraphicsView::resizeEvent(event);
70 }
71
72 /*!
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
75 the y axis).
76 \sa removeSeries(), removeAllSeries()
77 */
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
79 {
80 m_chart->addSeries(series,axisY);
81 }
82
83 /*!
84 Removes the \a series specified in a perameter from the QChartView.
85 It releses its ownership of the specified QChartSeries object.
86 It does not delete the pointed QChartSeries data object
87 \sa addSeries(), removeAllSeries()
88 */
89 void QChartView::removeSeries(QSeries* series)
90 {
91 m_chart->removeSeries(series);
92 }
93
94 /*!
95 Removes all the QChartSeries that have been added to the QChartView
96 It also deletes the pointed QChartSeries data objects
97 \sa addSeries(), removeSeries()
98 */
99 void QChartView::removeAllSeries()
100 {
101 m_chart->removeAllSeries();
102 }
103
104 /*!
105 Zooms in the view by a factor of 2
106 */
107 void QChartView::zoomIn()
108 {
109 m_chart->zoomIn();
110 }
111
112 /*!
113 Zooms in the view to a maximum level at which \a rect is still fully visible.
114 */
115 void QChartView::zoomIn(const QRect& rect)
116 {
117 m_chart->zoomIn(rect);
118 }
119
120 /*!
121 Restores the view zoom level to the previous one.
122 */
123 void QChartView::zoomOut()
124 {
125 m_chart->zoomOut();
126 }
127
128 /*!
129 Sets the chart \a title. A description text that is drawn above the chart.
130 */
131 void QChartView::setChartTitle(const QString& title)
132 {
133 m_chart->setTitle(title);
134 }
135
136 /*!
137 Returns the chart's title. A description text that is drawn above the chart.
138 */
139 QString QChartView::chartTitle() const
140 {
141 return m_chart->title();
142 }
143
144 /*!
145 Sets the \a font that is used for rendering the description text that is rendered above the chart.
146 */
147 void QChartView::setChartTitleFont(const QFont& font)
148 {
149 m_chart->setTitleFont(font);
150 }
151
152 /*!
153 Sets the \a brush used for rendering the title text.
154 */
155 void QChartView::setChartTitleBrush(const QBrush &brush)
156 {
157 m_chart->setTitleBrush(brush);
158 }
159
160 /*!
161 Returns the brush used for rendering the title text.
162 */
163 QBrush QChartView::chartTitleBrush()
164 {
165 return m_chart->titleBrush();
166 }
167
168 /*!
169 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
170 */
171 void QChartView::setChartBackgroundBrush(const QBrush& brush)
172 {
173 m_chart->setBackgroundBrush(brush);
174 }
175
176 /*!
177 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
178 */
179 void QChartView::setChartBackgroundPen(const QPen& pen)
180 {
82 {
181 m_chart->setBackgroundPen(pen);
83 return d_ptr->m_chart;
182 }
84 }
183
85
184 /*!
86 /*!
185 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
87 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
186 */
88 */
187 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
89 void QChartView::setRubberBand(const RubberBands& rubberBand)
188 {
90 {
189 switch(policy) {
91 d_ptr->m_rubberBandFlags=rubberBand;
190 case VerticalRubberBand:
92
191 m_verticalRubberBand = true;
93 if (!d_ptr->m_rubberBandFlags) {
192 m_horizonalRubberBand = false;
94 delete d_ptr->m_rubberBand;
193 break;
95 d_ptr->m_rubberBand=0;
194 case HorizonalRubberBand:
195 m_verticalRubberBand = false;
196 m_horizonalRubberBand = true;
197 break;
198 case RectangleRubberBand:
199 m_verticalRubberBand = true;
200 m_horizonalRubberBand = true;
201 break;
202 case NoRubberBand:
203 default:
204 delete m_rubberBand;
205 m_rubberBand=0;
206 m_horizonalRubberBand = false;
207 m_verticalRubberBand = false;
208 return;
96 return;
209 }
97 }
210 if(!m_rubberBand) {
98
211 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
99 if (!d_ptr->m_rubberBand) {
212 m_rubberBand->setEnabled(true);
100 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
101 d_ptr->m_rubberBand->setEnabled(true);
213 }
102 }
214 }
103 }
215
104
216 /*!
105 /*!
217 Returns the RubberBandPolicy that is currently being used by the widget.
106 Returns the RubberBandPolicy that is currently being used by the widget.
218 */
107 */
219 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
108 QChartView::RubberBands QChartView::rubberBand() const
220 {
109 {
221 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
110 return d_ptr->m_rubberBandFlags;
222 if(m_horizonalRubberBand) return HorizonalRubberBand;
223 if(m_verticalRubberBand) return VerticalRubberBand;
224 return NoRubberBand;
225 }
111 }
226
112
227 /*!
113 /*!
228 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.
114 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.
229 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
115 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
230 */
116 */
231 void QChartView::mousePressEvent(QMouseEvent *event)
117 void QChartView::mousePressEvent(QMouseEvent *event)
232 {
118 {
233 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
119 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
234
120
235 int padding = m_chart->d_ptr->m_presenter->padding();
121 int padding = d_ptr->m_presenter->padding();
236 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
122 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
237
123
238 if (rect.contains(event->pos())) {
124 if (rect.contains(event->pos())) {
239 m_rubberBandOrigin = event->pos();
125 d_ptr->m_rubberBandOrigin = event->pos();
240 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
126 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
241 m_rubberBand->show();
127 d_ptr->m_rubberBand->show();
242 event->accept();
128 event->accept();
243 }
129 }
244 }
130 }
245 else {
131 else {
246 QGraphicsView::mousePressEvent(event);
132 QGraphicsView::mousePressEvent(event);
247 }
133 }
248 }
134 }
249
135
250 /*!
136 /*!
251 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
137 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
252 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
138 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
253 */
139 */
254 void QChartView::mouseMoveEvent(QMouseEvent *event)
140 void QChartView::mouseMoveEvent(QMouseEvent *event)
255 {
141 {
256 if(m_rubberBand && m_rubberBand->isVisible()) {
142 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
257 int padding = m_chart->d_ptr->m_presenter->padding();
143 int padding = d_ptr->m_presenter->padding();
258 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
144 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
259 int width = event->pos().x() - m_rubberBandOrigin.x();
145 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
260 int height = event->pos().y() - m_rubberBandOrigin.y();
146 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
261 if(!m_verticalRubberBand) {
147 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
262 m_rubberBandOrigin.setY(rect.top());
148 d_ptr->m_rubberBandOrigin.setY(rect.top());
263 height = rect.height();
149 height = rect.height();
264 }
150 }
265 if(!m_horizonalRubberBand) {
151 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
266 m_rubberBandOrigin.setX(rect.left());
152 d_ptr->m_rubberBandOrigin.setX(rect.left());
267 width= rect.width();
153 width= rect.width();
268 }
154 }
269 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
155 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
270 }
156 }
271 else {
157 else {
272 QGraphicsView::mouseMoveEvent(event);
158 QGraphicsView::mouseMoveEvent(event);
273 }
159 }
274 }
160 }
275
161
276 /*!
162 /*!
277 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
163 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
278 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
164 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
279 */
165 */
280 void QChartView::mouseReleaseEvent(QMouseEvent *event)
166 void QChartView::mouseReleaseEvent(QMouseEvent *event)
281 {
167 {
282 if(m_rubberBand) {
168 if(d_ptr->m_rubberBand) {
283 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
169 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
284 m_rubberBand->hide();
170 d_ptr->m_rubberBand->hide();
285 QRect rect = m_rubberBand->geometry();
171 QRect rect = d_ptr->m_rubberBand->geometry();
286 m_chart->zoomIn(rect);
172 d_ptr->m_chart->zoomIn(rect);
287 event->accept();
173 event->accept();
288 }
174 }
289
175
290 if(event->button()==Qt::RightButton){
176 if(event->button()==Qt::RightButton){
291 m_chart->zoomOut();
177 d_ptr->m_chart->zoomOut();
292 event->accept();
178 event->accept();
293 }
179 }
294 }
180 }
295 else {
181 else {
296 QGraphicsView::mouseReleaseEvent(event);
182 QGraphicsView::mouseReleaseEvent(event);
297 }
183 }
298 }
184 }
299
185
300 /*!
186 /*!
301 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
187 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
302 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
188 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
303 */
189 */
304 void QChartView::keyPressEvent(QKeyEvent *event)
190 void QChartView::keyPressEvent(QKeyEvent *event)
305 {
191 {
306 switch (event->key()) {
192 switch (event->key()) {
307 case Qt::Key_Plus:
193 case Qt::Key_Plus:
308 zoomIn();
194 d_ptr->m_chart->zoomIn();
309 break;
195 break;
310 case Qt::Key_Minus:
196 case Qt::Key_Minus:
311 zoomOut();
197 d_ptr->m_chart->zoomOut();
312 break;
198 break;
313 default:
199 default:
314 QGraphicsView::keyPressEvent(event);
200 QGraphicsView::keyPressEvent(event);
315 break;
201 break;
316 }
202 }
317 }
203 }
318
204
319 /*!
205 /*!
320 Sets the \a theme used by the chart for rendering the graphical representation of the data
206 Resizes and updates the chart area using the \a event data
321 \sa QChart::ChartTheme, chartTheme()
322 */
323 void QChartView::setChartTheme(QChart::ChartTheme theme)
324 {
325 m_chart->setTheme(theme);
326 }
327
328 /*!
329 Returns the theme enum used by the chart.
330 \sa setChartTheme()
331 */
332 QChart::ChartTheme QChartView::chartTheme() const
333 {
334 return m_chart->theme();
335 }
336
337 /*!
338 Returns the pointer to the x axis object of the chart
339 */
340 QChartAxis* QChartView::axisX() const
341 {
342 return m_chart->axisX();
343 }
344
345 /*!
346 Returns the pointer to the y axis object of the chart
347 */
348 QChartAxis* QChartView::axisY() const
349 {
350 return m_chart->axisY();
351 }
352
353 /*!
354 Returns the pointer to legend object of the chart
355 */
356 QLegend& QChartView::legend() const
357 {
358 return m_chart->legend();
359 }
360
361 /*!
362 Gives ownership of legend to user.
363 */
364 QLegend* QChartView::takeLegend()
365 {
366 return m_chart->takeLegend();
367 }
368
369 /*!
370 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
371 */
372 void QChartView::giveLegend(QLegend* legend)
373 {
374 m_chart->giveLegend(legend);
375 }
376
377 /*!
378 Sets animation \a options for the chart
379 */
207 */
380 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
208 void QChartView::resizeEvent(QResizeEvent *event)
381 {
209 {
382 m_chart->setAnimationOptions(options);
210 d_ptr->m_chart->resize(size());
211 QGraphicsView::resizeEvent(event);
383 }
212 }
384
213
385 /*!
214 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
386 Returns animation options for the chart
387 */
388 QChart::AnimationOptions QChartView::animationOptions() const
389 {
390 return m_chart->animationOptions();
391 }
392
215
393 void QChartView::scrollLeft()
216 QChartViewPrivate::QChartViewPrivate():
217 m_scene(0),
218 m_chart(0),
219 m_presenter(0),
220 m_rubberBand(0),
221 m_rubberBandFlags(QChartView::NoRubberBand)
394 {
222 {
395 m_chart->scrollLeft();
396 }
397
223
398 void QChartView::scrollRight()
399 {
400 m_chart->scrollRight();
401 }
224 }
402
225
403 void QChartView::scrollUp()
226 QChartViewPrivate::~QChartViewPrivate()
404 {
227 {
405 m_chart->scrollUp();
406 }
407
228
408 void QChartView::scrollDown()
409 {
410 m_chart->scrollDown();
411 }
229 }
412
230
413
414 #include "moc_qchartview.cpp"
231 #include "moc_qchartview.cpp"
415
232
416 QTCOMMERCIALCHART_END_NAMESPACE
233 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +1,72
1 #ifndef QCHARTWIDGET_H
1 /****************************************************************************
2 #define QCHARTWIDGET_H
2 **
3
3 ** Copyright (C) 2012 Digia Plc
4 #include <qchartglobal.h>
4 ** All rights reserved.
5 #include <qchartaxis.h>
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 #include <qseries.h>
6 **
7 #include <qchart.h>
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef QCHARTVIEW_H
22 #define QCHARTVIEW_H
23
24 #include <QChartAxis>
25 #include <QSeries>
26 #include <QChart>
8 #include <QGraphicsView>
27 #include <QGraphicsView>
9
28
10 class QGraphicsScene;
29 class QGraphicsScene;
11 class QRubberBand;
30 class QRubberBand;
12
31
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
33
15 class QChart;
34 class QChartViewPrivate;
16
35
17 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
36 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
18 {
37 {
19 Q_OBJECT
38 Q_OBJECT
20
39
21 public:
40 public:
22 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
23
24 explicit QChartView(QWidget *parent = 0);
25 ~QChartView();
26
27 //implement from QWidget
28 void resizeEvent(QResizeEvent *event);
29
30 void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
31 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
32 void removeAllSeries(); // deletes series and axis
33
41
34 void setChartTitle(const QString& title);
42 enum RubberBand{
35 QString chartTitle() const;
43 NoRubberBand = 0x0,
36 void setChartTitleFont(const QFont& font);
44 VerticalRubberBand = 0x1,
37 void setChartTitleBrush(const QBrush &brush);
45 HorizonalRubberBand = 0x2,
38 QBrush chartTitleBrush();
46 RectangleRubberBand = 0x3
39 void setChartBackgroundBrush(const QBrush& brush);
47 };
40 void setChartBackgroundPen(const QPen& pen);
41
48
42 void zoomIn();
49 Q_DECLARE_FLAGS(RubberBands, RubberBand)
43 void zoomIn(const QRect& rect);
44 void zoomOut();
45 void scrollLeft();
46 void scrollRight();
47 void scrollUp();
48 void scrollDown();
49
50
50 void setRubberBandPolicy(const RubberBandPolicy );
51 explicit QChartView(QChart *chart,QWidget *parent = 0);
51 RubberBandPolicy rubberBandPolicy() const;
52 ~QChartView();
52
53 void setChartTheme(QChart::ChartTheme theme);
54 QChart::ChartTheme chartTheme() const;
55
56 void setAnimationOptions(QChart::AnimationOptions options);
57 QChart::AnimationOptions animationOptions() const;
58
59 QChartAxis* axisX() const;
60 QChartAxis* axisY() const;
61
53
62 QLegend &legend() const;
54 void setRubberBand(const RubberBands& rubberBands);
63 QLegend* takeLegend();
55 RubberBands rubberBand() const;
64 void giveLegend(QLegend* legend);
56 QChart* chart() const;
65
57
66 protected:
58 protected:
59 void resizeEvent(QResizeEvent *event);
67 void mousePressEvent(QMouseEvent *event);
60 void mousePressEvent(QMouseEvent *event);
68 void mouseMoveEvent(QMouseEvent *event);
61 void mouseMoveEvent(QMouseEvent *event);
69 void mouseReleaseEvent(QMouseEvent *event);
62 void mouseReleaseEvent(QMouseEvent *event);
70 void keyPressEvent(QKeyEvent *event);
63 void keyPressEvent(QKeyEvent *event);
71
64
72 private:
65 protected:
73 QGraphicsScene *m_scene;
66 QScopedPointer<QChartViewPrivate> d_ptr;
74 QChart* m_chart;
75 QPoint m_rubberBandOrigin;
76 QRubberBand* m_rubberBand;
77 bool m_verticalRubberBand;
78 bool m_horizonalRubberBand;
79 Q_DISABLE_COPY(QChartView)
67 Q_DISABLE_COPY(QChartView)
80 };
68 };
81
69
82 QTCOMMERCIALCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
83
71
84 #endif // QCHARTWIDGET_H
72 #endif // QCHARTWIDGET_H
@@ -1,158 +1,159
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 TARGET = QtCommercialChart
2 TARGET = QtCommercialChart
3 DESTDIR = $$CHART_BUILD_LIB_DIR
3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 TEMPLATE = lib
4 TEMPLATE = lib
5 QT += core \
5 QT += core \
6 gui
6 gui
7 win32-msvc*: LIBS += User32.lib
7 win32-msvc*: LIBS += User32.lib
8 CONFIG += debug_and_release
8 CONFIG += debug_and_release
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
10 SOURCES += \
10 SOURCES += \
11 $$PWD/chartdataset.cpp \
11 $$PWD/chartdataset.cpp \
12 $$PWD/chartpresenter.cpp \
12 $$PWD/chartpresenter.cpp \
13 $$PWD/charttheme.cpp \
13 $$PWD/charttheme.cpp \
14 $$PWD/domain.cpp \
14 $$PWD/domain.cpp \
15 $$PWD/qchart.cpp \
15 $$PWD/qchart.cpp \
16 $$PWD/qchartview.cpp \
16 $$PWD/qchartview.cpp \
17 $$PWD/qseries.cpp \
17 $$PWD/qseries.cpp \
18 $$PWD/qlegend.cpp \
18 $$PWD/qlegend.cpp \
19 $$PWD/legendmarker.cpp \
19 $$PWD/legendmarker.cpp \
20 $$PWD/legendscrollbutton.cpp \
20 $$PWD/legendscrollbutton.cpp \
21 $$PWD/chartbackground.cpp \
21 $$PWD/chartbackground.cpp \
22 $$PWD/chart.cpp
22 $$PWD/chart.cpp
23 PRIVATE_HEADERS += \
23 PRIVATE_HEADERS += \
24 $$PWD/chartdataset_p.h \
24 $$PWD/chartdataset_p.h \
25 $$PWD/chartitem_p.h \
25 $$PWD/chartitem_p.h \
26 $$PWD/chartpresenter_p.h \
26 $$PWD/chartpresenter_p.h \
27 $$PWD/charttheme_p.h \
27 $$PWD/charttheme_p.h \
28 $$PWD/domain_p.h \
28 $$PWD/domain_p.h \
29 $$PWD/legendmarker_p.h \
29 $$PWD/legendmarker_p.h \
30 $$PWD/legendscrollbutton_p.h \
30 $$PWD/legendscrollbutton_p.h \
31 $$PWD/chartbackground_p.h \
31 $$PWD/chartbackground_p.h \
32 $$PWD/chart_p.h \
32 $$PWD/chart_p.h \
33 $$PWD/chartconfig_p.h \
33 $$PWD/chartconfig_p.h \
34 $$PWD/qchart_p.h
34 $$PWD/qchart_p.h \
35 $$PWD/qchartview_p.h
35 PUBLIC_HEADERS += \
36 PUBLIC_HEADERS += \
36 $$PWD/qchart.h \
37 $$PWD/qchart.h \
37 $$PWD/qchartglobal.h \
38 $$PWD/qchartglobal.h \
38 $$PWD/qseries.h \
39 $$PWD/qseries.h \
39 $$PWD/qchartview.h \
40 $$PWD/qchartview.h \
40 $$PWD/qlegend.h
41 $$PWD/qlegend.h
41
42
42 include(animations/animations.pri)
43 include(animations/animations.pri)
43 include(axis/axis.pri)
44 include(axis/axis.pri)
44 include(xychart/xychart.pri)
45 include(xychart/xychart.pri)
45 include(linechart/linechart.pri)
46 include(linechart/linechart.pri)
46 include(areachart/areachart.pri)
47 include(areachart/areachart.pri)
47 include(barchart/barchart.pri)
48 include(barchart/barchart.pri)
48 include(piechart/piechart.pri)
49 include(piechart/piechart.pri)
49 include(scatterseries/scatter.pri)
50 include(scatterseries/scatter.pri)
50 include(splinechart/splinechart.pri)
51 include(splinechart/splinechart.pri)
51 include(themes/themes.pri)
52 include(themes/themes.pri)
52
53
53
54
54 HEADERS += $$PUBLIC_HEADERS
55 HEADERS += $$PUBLIC_HEADERS
55 HEADERS += $$PRIVATE_HEADERS
56 HEADERS += $$PRIVATE_HEADERS
56 HEADERS += $$THEMES
57 HEADERS += $$THEMES
57 INCLUDEPATH += ../include .
58 INCLUDEPATH += ../include .
58
59
59 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
60 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
60 MOC_DIR = $$CHART_BUILD_DIR/lib
61 MOC_DIR = $$CHART_BUILD_DIR/lib
61 UI_DIR = $$CHART_BUILD_DIR/lib
62 UI_DIR = $$CHART_BUILD_DIR/lib
62 RCC_DIR = $$CHART_BUILD_DIR/lib
63 RCC_DIR = $$CHART_BUILD_DIR/lib
63 DEFINES += QTCOMMERCIALCHART_LIBRARY
64 DEFINES += QTCOMMERCIALCHART_LIBRARY
64
65
65 #qt public headers
66 #qt public headers
66 #this is very primitive and lame parser , TODO: make perl script insted
67 #this is very primitive and lame parser , TODO: make perl script insted
67 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal)
68 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal)
68 {
69 {
69 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
70 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
70 win32:{
71 win32:{
71 command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
72 command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
72 }else{
73 }else{
73 command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
74 command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
74 }
75 }
75 system($$command)
76 system($$command)
76 }
77 }
77
78
78 for(file, PUBLIC_HEADERS) {
79 for(file, PUBLIC_HEADERS) {
79 name = $$split(file,'/')
80 name = $$split(file,'/')
80 name = $$last(name)
81 name = $$last(name)
81 class = "$$cat($$file)"
82 class = "$$cat($$file)"
82 class = $$find(class,class)
83 class = $$find(class,class)
83 !isEmpty(class){
84 !isEmpty(class){
84 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
85 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
85 class = $$member(class,1)
86 class = $$member(class,1)
86 class = $$split(class,' ')
87 class = $$split(class,' ')
87 class = $$replace(class,' ','')
88 class = $$replace(class,' ','')
88 class = $$member(class,0)
89 class = $$member(class,0)
89 win32:{
90 win32:{
90 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
91 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
91 }else{
92 }else{
92 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
93 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
93 }
94 }
94 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
95 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
95 system($$command)
96 system($$command)
96 }
97 }
97 }
98 }
98
99
99 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
100 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
100 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
101 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
101
102
102 target.path = $$[QT_INSTALL_LIBS]
103 target.path = $$[QT_INSTALL_LIBS]
103 INSTALLS += target public_headers
104 INSTALLS += target public_headers
104
105
105 install_build_public_headers.name = build_public_headers
106 install_build_public_headers.name = build_public_headers
106 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
107 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
107 install_build_public_headers.input = PUBLIC_HEADERS
108 install_build_public_headers.input = PUBLIC_HEADERS
108 install_build_public_headers.commands = $$QMAKE_COPY \
109 install_build_public_headers.commands = $$QMAKE_COPY \
109 ${QMAKE_FILE_NAME} \
110 ${QMAKE_FILE_NAME} \
110 $$CHART_BUILD_PUBLIC_HEADER_DIR
111 $$CHART_BUILD_PUBLIC_HEADER_DIR
111 install_build_public_headers.CONFIG += target_predeps \
112 install_build_public_headers.CONFIG += target_predeps \
112 no_link
113 no_link
113
114
114 install_build_private_headers.name = buld_private_headers
115 install_build_private_headers.name = buld_private_headers
115 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
116 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
116 install_build_private_headers.input = PRIVATE_HEADERS
117 install_build_private_headers.input = PRIVATE_HEADERS
117 install_build_private_headers.commands = $$QMAKE_COPY \
118 install_build_private_headers.commands = $$QMAKE_COPY \
118 ${QMAKE_FILE_NAME} \
119 ${QMAKE_FILE_NAME} \
119 $$CHART_BUILD_PRIVATE_HEADER_DIR
120 $$CHART_BUILD_PRIVATE_HEADER_DIR
120 install_build_private_headers.CONFIG += target_predeps \
121 install_build_private_headers.CONFIG += target_predeps \
121 no_link
122 no_link
122
123
123 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
124 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
124 install_build_private_headers \
125 install_build_private_headers \
125
126
126
127
127 chartversion.target = $$PWD/qchartversion_p.h
128 chartversion.target = $$PWD/qchartversion_p.h
128 unix:{
129 unix:{
129 chartversion.commands = @echo \
130 chartversion.commands = @echo \
130 "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \
131 "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \
131 const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \
132 const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \
132 > \
133 > \
133 $$chartversion.target;
134 $$chartversion.target;
134 }else{
135 }else{
135 chartversion.commands = @echo \
136 chartversion.commands = @echo \
136 "const char *buildTime = \"%date%_%time%\" ; \
137 "const char *buildTime = \"%date%_%time%\" ; \
137 const char *gitHead = \"unknown\" ; " \
138 const char *gitHead = \"unknown\" ; " \
138 > \
139 > \
139 $$chartversion.target
140 $$chartversion.target
140 }
141 }
141 chartversion.depends = $$HEADERS \
142 chartversion.depends = $$HEADERS \
142 $$SOURCES
143 $$SOURCES
143 PRE_TARGETDEPS += $$PWD/qchartversion_p.h
144 PRE_TARGETDEPS += $$PWD/qchartversion_p.h
144 QMAKE_CLEAN += $$PWD/qchartversion_p.h
145 QMAKE_CLEAN += $$PWD/qchartversion_p.h
145 QMAKE_EXTRA_TARGETS += chartversion
146 QMAKE_EXTRA_TARGETS += chartversion
146 unix:QMAKE_DISTCLEAN += -r \
147 unix:QMAKE_DISTCLEAN += -r \
147 $$CHART_BUILD_HEADER_DIR \
148 $$CHART_BUILD_HEADER_DIR \
148 $$CHART_BUILD_LIB_DIR
149 $$CHART_BUILD_LIB_DIR
149 win32:QMAKE_DISTCLEAN += /Q \
150 win32:QMAKE_DISTCLEAN += /Q \
150 $$CHART_BUILD_HEADER_DIR \
151 $$CHART_BUILD_HEADER_DIR \
151 $$CHART_BUILD_LIB_DIR
152 $$CHART_BUILD_LIB_DIR
152
153
153 # treat warnings as errors
154 # treat warnings as errors
154 win32-msvc*: {
155 win32-msvc*: {
155 QMAKE_CXXFLAGS += /WX
156 QMAKE_CXXFLAGS += /WX
156 } else {
157 } else {
157 QMAKE_CXXFLAGS += -Werror
158 QMAKE_CXXFLAGS += -Werror
158 }
159 }
General Comments 0
You need to be logged in to leave comments. Login now