##// END OF EJS Templates
Adds PIMPL to qchart
Michal Klocek -
r740:344f31f1bb27
parent child
Show More
@@ -17,7 +17,7 DeclarativeChart::~DeclarativeChart()
17
17
18 DeclarativeChart::ChartTheme DeclarativeChart::theme()
18 DeclarativeChart::ChartTheme DeclarativeChart::theme()
19 {
19 {
20 return (ChartTheme) m_chart->chartTheme();
20 return (ChartTheme) m_chart->theme();
21 }
21 }
22
22
23 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
23 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
@@ -34,7 +34,7 public: // From QDeclarativeItem/QGraphicsItem
34 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
34 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
35
35
36 public:
36 public:
37 void setTheme(ChartTheme theme) {m_chart->setChartTheme((QChart::ChartTheme) theme);}
37 void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);}
38 ChartTheme theme();
38 ChartTheme theme();
39
39
40 public:
40 public:
@@ -28,6 +28,8 private:
28
28
29 };
29 };
30
30
31 QTCOMMERCIALCHART_END_NAMESPACE
32
31 #endif /* CHARTBACKGROUND_H_ */
33 #endif /* CHARTBACKGROUND_H_ */
32
34
33 QTCOMMERCIALCHART_END_NAMESPACE
35
@@ -36,7 +36,7 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char
36 m_themeForce(false)
36 m_themeForce(false)
37 {
37 {
38 createConnections();
38 createConnections();
39 setChartTheme(QChart::ChartThemeDefault,false);
39 setTheme(QChart::ChartThemeDefault,false);
40 }
40 }
41
41
42 ChartPresenter::~ChartPresenter()
42 ChartPresenter::~ChartPresenter()
@@ -270,7 +270,7 void ChartPresenter::handleSeriesRemoved(QSeries* series)
270 delete item;
270 delete item;
271 }
271 }
272
272
273 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force)
273 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
274 {
274 {
275 if(m_chartTheme && m_chartTheme->id() == theme) return;
275 if(m_chartTheme && m_chartTheme->id() == theme) return;
276 delete m_chartTheme;
276 delete m_chartTheme;
@@ -281,7 +281,7 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force)
281 resetAllElements();
281 resetAllElements();
282 }
282 }
283
283
284 QChart::ChartTheme ChartPresenter::chartTheme()
284 QChart::ChartTheme ChartPresenter::theme()
285 {
285 {
286 return m_chartTheme->id();
286 return m_chartTheme->id();
287 }
287 }
@@ -41,11 +41,11 public:
41 QRectF geometry() const;
41 QRectF geometry() const;
42
42
43 ChartAnimator* animator() const {return m_animator;}
43 ChartAnimator* animator() const {return m_animator;}
44 ChartTheme *theme() { return m_chartTheme; }
44 ChartTheme *chartTheme() { return m_chartTheme; }
45 ChartDataSet *dataSet() { return m_dataset; }
45 ChartDataSet *dataSet() { return m_dataset; }
46
46
47 void setChartTheme(QChart::ChartTheme theme,bool force = true);
47 void setTheme(QChart::ChartTheme theme,bool force = true);
48 QChart::ChartTheme chartTheme();
48 QChart::ChartTheme theme();
49
49
50 void setAnimationOptions(QChart::AnimationOptions options);
50 void setAnimationOptions(QChart::AnimationOptions options);
51 QChart::AnimationOptions animationOptions() const;
51 QChart::AnimationOptions animationOptions() const;
@@ -51,7 +51,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
51 {
51 {
52 bool isEmpty = m_slices.isEmpty();
52 bool isEmpty = m_slices.isEmpty();
53
53
54 presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
54 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
55
55
56 foreach (QPieSlice *s, slices) {
56 foreach (QPieSlice *s, slices) {
57 PieSliceItem* item = new PieSliceItem(this);
57 PieSliceItem* item = new PieSliceItem(this);
@@ -72,7 +72,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
72
72
73 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
73 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
74 {
74 {
75 presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
75 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
76
76
77 foreach (QPieSlice *s, slices) {
77 foreach (QPieSlice *s, slices) {
78 if (animator())
78 if (animator())
This diff has been collapsed as it changes many lines, (503 lines changed) Show them Hide them
@@ -1,453 +1,466
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchart_p.h"
3 #include "qlegend.h"
4 #include "chartpresenter_p.h"
5 #include "chartdataset_p.h"
6 #include "chartbackground_p.h"
7 #include <QGraphicsScene>
3 #include <QGraphicsScene>
8 #include <QGraphicsSceneResizeEvent>
4 #include <QGraphicsSceneResizeEvent>
9
5
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
7
12 /*!
8 /*!
13 \enum QChart::ChartTheme
9 \enum QChart::ChartTheme
14
10
15 This enum describes the theme used by the chart.
11 This enum describes the theme used by the chart.
16
12
17 \value ChartThemeDefault Follows the GUI style of the Operating System
13 \value ChartThemeDefault Follows the GUI style of the Operating System
18 \value ChartThemeLight
14 \value ChartThemeLight
19 \value ChartThemeBlueCerulean
15 \value ChartThemeBlueCerulean
20 \value ChartThemeDark
16 \value ChartThemeDark
21 \value ChartThemeBrownSand
17 \value ChartThemeBrownSand
22 \value ChartThemeBlueNcs
18 \value ChartThemeBlueNcs
23 \value ChartThemeIcy
19 \value ChartThemeIcy
24 \value ChartThemeScientific
20 \value ChartThemeScientific
25 \value ChartThemeCount Not really a theme; the total count of themes.
21 \value ChartThemeCount Not really a theme; the total count of themes.
26 */
22 */
27
23
28 /*!
24 /*!
29 \enum QChart::AnimationOption
25 \enum QChart::AnimationOption
30
26
31 For enabling/disabling animations. Defaults to NoAnimation.
27 For enabling/disabling animations. Defaults to NoAnimation.
32
28
33 \value NoAnimation
29 \value NoAnimation
34 \value GridAxisAnimations
30 \value GridAxisAnimations
35 \value SeriesAnimations
31 \value SeriesAnimations
36 \value AllAnimations
32 \value AllAnimations
37 */
33 */
38
34
39 /*!
35 /*!
40 \class QChart
36 \class QChart
41 \brief QtCommercial chart API.
37 \brief QtCommercial chart API.
42
38
43 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
39 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
44 representation of different types of QChartSeries and other chart related objects like
40 representation of different types of QChartSeries and other chart related objects like
45 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
41 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
46 convenience class QChartView instead of QChart.
42 convenience class QChartView instead of QChart.
47 \sa QChartView
43 \sa QChartView
48 */
44 */
49
45
50 /*!
46 /*!
51 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
47 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
52 */
48 */
53 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
49 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
54 m_backgroundItem(0),
50 d_ptr(new QChartPrivate(this))
55 m_titleItem(0),
56 m_legend(new QLegend(this)),
57 m_dataset(new ChartDataSet(this)),
58 m_presenter(new ChartPresenter(this,m_dataset)),
59 m_padding(50),
60 m_backgroundPadding(10)
61 {
51 {
62 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
52
63 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
53 d_ptr->m_legend = new QLegend(this);
54 d_ptr->m_dataset = new ChartDataSet(this);
55 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
56
57 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
58 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
64 }
59 }
65
60
66 /*!
61 /*!
67 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
62 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
68 */
63 */
69 QChart::~QChart()
64 QChart::~QChart()
70 {
65 {
71 //delete first presenter , since this is a root of all the graphical items
66 //delete first presenter , since this is a root of all the graphical items
72 delete m_presenter;
67 delete d_ptr->m_presenter;
73 m_presenter=0;
68 d_ptr->m_presenter=0;
74 }
69 }
75
70
76 /*!
71 /*!
77 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
72 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
78 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
73 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
79 the y axis).
74 the y axis).
80 */
75 */
81 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
76 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
82 {
77 {
83 m_dataset->addSeries(series, axisY);
78 d_ptr->m_dataset->addSeries(series, axisY);
84 }
79 }
85
80
86 /*!
81 /*!
87 Removes the \a series specified in a perameter from the QChartView.
82 Removes the \a series specified in a perameter from the QChartView.
88 It releses its ownership of the specified QChartSeries object.
83 It releses its ownership of the specified QChartSeries object.
89 It does not delete the pointed QChartSeries data object
84 It does not delete the pointed QChartSeries data object
90 \sa addSeries(), removeAllSeries()
85 \sa addSeries(), removeAllSeries()
91 */
86 */
92 void QChart::removeSeries(QSeries* series)
87 void QChart::removeSeries(QSeries* series)
93 {
88 {
94 m_dataset->removeSeries(series);
89 d_ptr->m_dataset->removeSeries(series);
95 }
90 }
96
91
97 /*!
92 /*!
98 Removes all the QChartSeries that have been added to the QChartView
93 Removes all the QChartSeries that have been added to the QChartView
99 It also deletes the pointed QChartSeries data objects
94 It also deletes the pointed QChartSeries data objects
100 \sa addSeries(), removeSeries()
95 \sa addSeries(), removeSeries()
101 */
96 */
102 void QChart::removeAllSeries()
97 void QChart::removeAllSeries()
103 {
98 {
104 m_dataset->removeAllSeries();
99 d_ptr->m_dataset->removeAllSeries();
105 }
100 }
106
101
107 /*!
102 /*!
108 Sets the \a brush that is used for painting the background of the chart area.
103 Sets the \a brush that is used for painting the background of the chart area.
109 */
104 */
110 void QChart::setBackgroundBrush(const QBrush& brush)
105 void QChart::setBackgroundBrush(const QBrush& brush)
111 {
106 {
112 createChartBackgroundItem();
107 d_ptr->createChartBackgroundItem();
113 m_backgroundItem->setBrush(brush);
108 d_ptr->m_backgroundItem->setBrush(brush);
114 m_backgroundItem->update();
109 d_ptr->m_backgroundItem->update();
115 }
110 }
116
111
117 QBrush QChart::backgroundBrush() const
112 QBrush QChart::backgroundBrush() const
118 {
113 {
119 if(!m_backgroundItem) return QBrush();
114 if(!d_ptr->m_backgroundItem) return QBrush();
120 return m_backgroundItem->brush();
115 return (d_ptr->m_backgroundItem)->brush();
121 }
116 }
122
117
123 /*!
118 /*!
124 Sets the \a pen that is used for painting the background of the chart area.
119 Sets the \a pen that is used for painting the background of the chart area.
125 */
120 */
126 void QChart::setBackgroundPen(const QPen& pen)
121 void QChart::setBackgroundPen(const QPen& pen)
127 {
122 {
128 createChartBackgroundItem();
123 d_ptr->createChartBackgroundItem();
129 m_backgroundItem->setPen(pen);
124 d_ptr->m_backgroundItem->setPen(pen);
130 m_backgroundItem->update();
125 d_ptr->m_backgroundItem->update();
131 }
126 }
132
127
133 QPen QChart::backgroundPen() const
128 QPen QChart::backgroundPen() const
134 {
129 {
135 if(!m_backgroundItem) return QPen();
130 if(!d_ptr->m_backgroundItem) return QPen();
136 return m_backgroundItem->pen();
131 return d_ptr->m_backgroundItem->pen();
137 }
132 }
138
133
139 /*!
134 /*!
140 Sets the chart \a title. The description text that is drawn above the chart.
135 Sets the chart \a title. The description text that is drawn above the chart.
141 */
136 */
142 void QChart::setTitle(const QString& title)
137 void QChart::setTitle(const QString& title)
143 {
138 {
144 createChartTitleItem();
139 d_ptr->createChartTitleItem();
145 m_titleItem->setText(title);
140 d_ptr->m_titleItem->setText(title);
146 updateLayout();
141 d_ptr->updateLayout();
147 }
142 }
148
143
149 /*!
144 /*!
150 Returns the chart title. The description text that is drawn above the chart.
145 Returns the chart title. The description text that is drawn above the chart.
151 */
146 */
152 QString QChart::title() const
147 QString QChart::title() const
153 {
148 {
154 if(m_titleItem)
149 if(d_ptr->m_titleItem)
155 return m_titleItem->text();
150 return d_ptr->m_titleItem->text();
156 else
151 else
157 return QString();
152 return QString();
158 }
153 }
159
154
160 /*!
155 /*!
161 Sets the \a font that is used for rendering the description text that is rendered above the chart.
156 Sets the \a font that is used for rendering the description text that is rendered above the chart.
162 */
157 */
163 void QChart::setTitleFont(const QFont& font)
158 void QChart::setTitleFont(const QFont& font)
164 {
159 {
165 createChartTitleItem();
160 d_ptr->createChartTitleItem();
166 m_titleItem->setFont(font);
161 d_ptr->m_titleItem->setFont(font);
167 updateLayout();
162 d_ptr->updateLayout();
168 }
163 }
169
164
170 /*!
165 /*!
171 Sets the \a brush used for rendering the title text.
166 Sets the \a brush used for rendering the title text.
172 */
167 */
173 void QChart::setTitleBrush(const QBrush &brush)
168 void QChart::setTitleBrush(const QBrush &brush)
174 {
169 {
175 createChartTitleItem();
170 d_ptr->createChartTitleItem();
176 m_titleItem->setBrush(brush);
171 d_ptr->m_titleItem->setBrush(brush);
177 updateLayout();
172 d_ptr->updateLayout();
178 }
173 }
179
174
180 /*!
175 /*!
181 Returns the brush used for rendering the title text.
176 Returns the brush used for rendering the title text.
182 */
177 */
183 QBrush QChart::titleBrush() const
178 QBrush QChart::titleBrush() const
184 {
179 {
185 if(!m_titleItem) return QBrush();
180 if(!d_ptr->m_titleItem) return QBrush();
186 return m_titleItem->brush();
181 return d_ptr->m_titleItem->brush();
187 }
188
189 void QChart::createChartBackgroundItem()
190 {
191 if(!m_backgroundItem) {
192 m_backgroundItem = new ChartBackground(this);
193 m_backgroundItem->setPen(Qt::NoPen);
194 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
195 }
196 }
197
198 void QChart::createChartTitleItem()
199 {
200 if(!m_titleItem) {
201 m_titleItem = new QGraphicsSimpleTextItem(this);
202 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
203 }
204 }
182 }
205
183
206 /*!
184 /*!
207 Sets the \a theme used by the chart for rendering the graphical representation of the data
185 Sets the \a theme used by the chart for rendering the graphical representation of the data
208 \sa ChartTheme, chartTheme()
186 \sa ChartTheme, chartTheme()
209 */
187 */
210 void QChart::setChartTheme(QChart::ChartTheme theme)
188 void QChart::setTheme(QChart::ChartTheme theme)
211 {
189 {
212 m_presenter->setChartTheme(theme);
190 d_ptr->m_presenter->setTheme(theme);
213 }
191 }
214
192
215 /*!
193 /*!
216 Returns the theme enum used by the chart.
194 Returns the theme enum used by the chart.
217 \sa ChartTheme, setChartTheme()
195 \sa ChartTheme, setChartTheme()
218 */
196 */
219 QChart::ChartTheme QChart::chartTheme() const
197 QChart::ChartTheme QChart::theme() const
220 {
198 {
221 return m_presenter->chartTheme();
199 return d_ptr->m_presenter->theme();
222 }
200 }
223
201
224 /*!
202 /*!
225 Zooms in the view by a factor of 2
203 Zooms in the view by a factor of 2
226 */
204 */
227 void QChart::zoomIn()
205 void QChart::zoomIn()
228 {
206 {
229 m_presenter->zoomIn();
207 d_ptr->m_presenter->zoomIn();
230 }
208 }
231
209
232 /*!
210 /*!
233 Zooms in the view to a maximum level at which \a rect is still fully visible.
211 Zooms in the view to a maximum level at which \a rect is still fully visible.
234 */
212 */
235 void QChart::zoomIn(const QRectF& rect)
213 void QChart::zoomIn(const QRectF& rect)
236 {
214 {
237
238 if(!rect.isValid()) return;
215 if(!rect.isValid()) return;
239 m_presenter->zoomIn(rect);
216 d_ptr->m_presenter->zoomIn(rect);
240 }
217 }
241
218
242 /*!
219 /*!
243 Restores the view zoom level to the previous one.
220 Restores the view zoom level to the previous one.
244 */
221 */
245 void QChart::zoomOut()
222 void QChart::zoomOut()
246 {
223 {
247 m_presenter->zoomOut();
224 d_ptr->m_presenter->zoomOut();
248 }
225 }
249
226
250 /*!
227 /*!
251 Returns the pointer to the x axis object of the chart
228 Returns the pointer to the x axis object of the chart
252 */
229 */
253 QChartAxis* QChart::axisX() const
230 QChartAxis* QChart::axisX() const
254 {
231 {
255 return m_dataset->axisX();
232 return d_ptr->m_dataset->axisX();
256 }
233 }
257
234
258 /*!
235 /*!
259 Returns the pointer to the y axis object of the chart
236 Returns the pointer to the y axis object of the chart
260 */
237 */
261 QChartAxis* QChart::axisY() const
238 QChartAxis* QChart::axisY() const
262 {
239 {
263 return m_dataset->axisY();
240 return d_ptr->m_dataset->axisY();
264 }
241 }
265
242
266 /*!
243 /*!
267 Returns the legend object of the chart. Ownership stays in chart.
244 Returns the legend object of the chart. Ownership stays in chart.
268 */
245 */
269 QLegend& QChart::legend() const
246 QLegend& QChart::legend() const
270 {
247 {
271 return *m_legend;
248 return *d_ptr->m_legend;
272 }
249 }
273
250
274 /*!
251 /*!
275 Gives ownership of legend to user.
252 Gives ownership of legend to user.
276 */
253 */
277 QLegend* QChart::takeLegend()
254 QLegend* QChart::takeLegend()
278 {
255 {
279 QLegend* l = m_legend;
256 QLegend* l = d_ptr->m_legend;
280 m_legend = 0;
257 d_ptr->m_legend = 0;
281 return l;
258 return l;
282 }
259 }
283
260
284 /*!
261 /*!
285 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
262 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
286 */
263 */
287 void QChart::giveLegend(QLegend* legend)
264 void QChart::giveLegend(QLegend *legend)
288 {
265 {
289 if (m_legend) {
266 if (d_ptr->m_legend) {
290 // Should not happen.
267 // Should not happen.
291 qDebug() << "Warning! Giving more than one legend to chart.";
268 qDebug() << "Warning! Giving more than one legend to chart.";
292 delete m_legend;
269 delete d_ptr->m_legend;
293 }
270 }
294
271
295 m_legend = legend;
272 d_ptr->m_legend = legend;
296
273
297 // Reconnect legend, in case not already connected.
274 // Reconnect legend, in case not already connected.
298 disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
275 disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
299 disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
276 disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
300 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
277 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
301 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
278 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
302 }
279 }
303
280
304 /*!
281 /*!
305 Resizes and updates the chart area using the \a event data
282 Resizes and updates the chart area using the \a event data
306 */
283 */
307 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
284 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
308 {
285 {
309
286 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
310 m_rect = QRectF(QPoint(0,0),event->newSize());
287 d_ptr->updateLayout();
311 updateLayout();
312 QGraphicsWidget::resizeEvent(event);
288 QGraphicsWidget::resizeEvent(event);
313 update();
289 update();
314 }
290 }
315
291
316 /*!
292 /*!
317 Sets animation \a options for the chart
293 Sets animation \a options for the chart
318 */
294 */
319 void QChart::setAnimationOptions(AnimationOptions options)
295 void QChart::setAnimationOptions(AnimationOptions options)
320 {
296 {
321 m_presenter->setAnimationOptions(options);
297 d_ptr->m_presenter->setAnimationOptions(options);
322 }
298 }
323
299
324 /*!
300 /*!
325 Returns animation options for the chart
301 Returns animation options for the chart
326 */
302 */
327 QChart::AnimationOptions QChart::animationOptions() const
303 QChart::AnimationOptions QChart::animationOptions() const
328 {
304 {
329 return m_presenter->animationOptions();
305 return d_ptr->m_presenter->animationOptions();
330 }
306 }
331
307
332 void QChart::scrollLeft()
308 void QChart::scrollLeft()
333 {
309 {
334 m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
310 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
335 }
311 }
336
312
337 void QChart::scrollRight()
313 void QChart::scrollRight()
338 {
314 {
339 m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
315 d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
340 }
316 }
317
341 void QChart::scrollUp()
318 void QChart::scrollUp()
342 {
319 {
343 m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1));
320 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
344 }
321 }
322
345 void QChart::scrollDown()
323 void QChart::scrollDown()
346 {
324 {
347 m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1));
325 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
348 }
326 }
349
327
350 void QChart::updateLayout()
328 void QChart::setPadding(int padding)
351 {
329 {
352 if(!m_rect.isValid()) return;
330 if(d_ptr->m_padding==padding) {
353
331 d_ptr->m_padding = padding;
354 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
332 d_ptr->m_presenter->handleGeometryChanged();
355
333 d_ptr->updateLayout();
356 // recalculate title position
357 if (m_titleItem) {
358 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
359 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
360 }
334 }
335 }
361
336
362 //recalculate background gradient
337 int QChart::padding() const
363 if (m_backgroundItem) {
338 {
364 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
339 return d_ptr->m_padding;
365 }
340 }
366
341
367 // recalculate legend position
342 void QChart::setBackgroundPadding(int padding)
368 if (m_legend) {
343 {
369 if (m_legend->parentObject() == this) {
344 if(d_ptr->m_backgroundPadding!=padding) {
370 updateLegendLayout();
345 d_ptr->m_backgroundPadding = padding;
371 }
346 d_ptr->updateLayout();
372 }
347 }
373 }
348 }
374
349
375 void QChart::updateLegendLayout()
350 void QChart::setBackgroundDiameter(int diameter)
376 {
351 {
377 QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
352 d_ptr->createChartBackgroundItem();
378 QRectF legendRect;
353 d_ptr->m_backgroundItem->setDimeter(diameter);
354 d_ptr->m_backgroundItem->update();
355 }
379
356
380 switch (m_legend->preferredLayout())
357 void QChart::setBackgroundVisible(bool visible)
381 {
358 {
382 case QLegend::PreferredLayoutTop:{
359 d_ptr->createChartBackgroundItem();
383 // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height());
360 d_ptr->m_backgroundItem->setVisible(visible);
384 legendRect = plotRect.adjusted(0,0,0,-m_padding - plotRect.height());
361 }
385 break;
386 }
387 case QLegend::PreferredLayoutBottom: {
388 legendRect = plotRect.adjusted(m_padding,m_padding + plotRect.height(),-m_padding,0);
389 break;
390 }
391 case QLegend::PreferredLayoutLeft: {
392 legendRect = plotRect.adjusted(0,m_padding,-m_padding - plotRect.width(),-m_padding);
393 break;
394 }
395 case QLegend::PreferredLayoutRight: {
396 legendRect = plotRect.adjusted(m_padding + plotRect.width(),m_padding,0,-m_padding);
397 break;
398 }
399 default: {
400 legendRect = plotRect;
401 break;
402 }
403 }
404
362
405 m_legend->setMaximumSize(legendRect.size());
363 bool QChart::isBackgroundVisible() const
406 m_legend->setPos(legendRect.topLeft());
364 {
365 if(!d_ptr->m_backgroundItem) return false;
366 return d_ptr->m_backgroundItem->isVisible();
407 }
367 }
408
368
369 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409
370
410 int QChart::padding() const
371 QChartPrivate::QChartPrivate(QChart *parent):
372 q_ptr(parent),
373 m_backgroundItem(0),
374 m_titleItem(0),
375 m_legend(0),
376 m_dataset(0),
377 m_presenter(0),
378 m_padding(50),
379 m_backgroundPadding(10)
411 {
380 {
412 return m_padding;
381
413 }
382 }
414
383
415 void QChart::setPadding(int padding)
384 QChartPrivate::~QChartPrivate()
416 {
385 {
417 if(m_padding==padding){
386
418 m_padding = padding;
419 m_presenter->handleGeometryChanged();
420 updateLayout();
421 }
422 }
387 }
423
388
424 void QChart::setBackgroundPadding(int padding)
389 void QChartPrivate::createChartBackgroundItem()
425 {
390 {
426 if(m_backgroundPadding!=padding){
391 if(!m_backgroundItem) {
427 m_backgroundPadding = padding;
392 m_backgroundItem = new ChartBackground(q_ptr);
428 updateLayout();
393 m_backgroundItem->setPen(Qt::NoPen);
394 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
429 }
395 }
430 }
396 }
431
397
432 void QChart::setBackgroundDiameter(int diameter)
398 void QChartPrivate::createChartTitleItem()
433 {
399 {
434 createChartBackgroundItem();
400 if(!m_titleItem) {
435 m_backgroundItem->setDimeter(diameter);
401 m_titleItem = new QGraphicsSimpleTextItem(q_ptr);
436 m_backgroundItem->update();
402 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
403 }
437 }
404 }
438
405
439 void QChart::setBackgroundVisible(bool visible)
406 void QChartPrivate::updateLegendLayout()
440 {
407 {
441 createChartBackgroundItem();
408 QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
442 m_backgroundItem->setVisible(visible);
409 QRectF legendRect;
410
411 switch (m_legend->preferredLayout())
412 {
413 case QLegend::PreferredLayoutTop: {
414 // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height());
415 legendRect = plotRect.adjusted(0,0,0,-m_padding - plotRect.height());
416 break;
417 }
418 case QLegend::PreferredLayoutBottom: {
419 legendRect = plotRect.adjusted(m_padding,m_padding + plotRect.height(),-m_padding,0);
420 break;
421 }
422 case QLegend::PreferredLayoutLeft: {
423 legendRect = plotRect.adjusted(0,m_padding,-m_padding - plotRect.width(),-m_padding);
424 break;
425 }
426 case QLegend::PreferredLayoutRight: {
427 legendRect = plotRect.adjusted(m_padding + plotRect.width(),m_padding,0,-m_padding);
428 break;
429 }
430 default: {
431 legendRect = plotRect;
432 break;
433 }
434 }
435
436 m_legend->setMaximumSize(legendRect.size());
437 m_legend->setPos(legendRect.topLeft());
443 }
438 }
444
439
445 bool QChart::isBackgroundVisible() const
440 void QChartPrivate::updateLayout()
446 {
441 {
447 if(!m_backgroundItem) return false;
442 if(!m_rect.isValid()) return;
448 return m_backgroundItem->isVisible();
443
449 }
444 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
445
446 // recalculate title position
447 if (m_titleItem) {
448 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
449 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
450 }
451
452 //recalculate background gradient
453 if (m_backgroundItem) {
454 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
455 }
450
456
457 // recalculate legend position
458 if (m_legend) {
459 if (m_legend->parentObject() == q_ptr) {
460 updateLegendLayout();
461 }
462 }
463 }
451
464
452 #include "moc_qchart.cpp"
465 #include "moc_qchart.cpp"
453
466
@@ -1,11 +1,8
1 #ifndef QCHART_H
1 #ifndef QCHART_H
2 #define QCHART_H
2 #define QCHART_H
3
3
4 #include <qchartglobal.h>
4 #include <QSeries>
5 #include <qseries.h>
6 #include <QGraphicsWidget>
5 #include <QGraphicsWidget>
7 #include <QLinearGradient>
8 #include <QFont>
9
6
10 class QGraphicsSceneResizeEvent;
7 class QGraphicsSceneResizeEvent;
11
8
@@ -13,16 +10,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
10
14 class Axis;
11 class Axis;
15 class QSeries;
12 class QSeries;
16 class PlotDomain;
17 class BarChartItem;
18 class QChartAxis;
13 class QChartAxis;
19 class ChartTheme;
20 class ChartItem;
21 class ChartDataSet;
22 class ChartPresenter;
23 class QLegend;
14 class QLegend;
24 class ChartBackground;
15 class QChartPrivate;
25
26
16
27 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
17 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
28 {
18 {
@@ -52,12 +42,12 public:
52 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
42 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
53 ~QChart();
43 ~QChart();
54
44
55 void addSeries(QSeries* series, QChartAxis* axisY = 0);
45 void addSeries(QSeries *series, QChartAxis *axisY = 0);
56 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
46 void removeSeries(QSeries *series);
57 void removeAllSeries(); // deletes series and axis
47 void removeAllSeries();
58
48
59 void setChartTheme(QChart::ChartTheme theme);
49 void setTheme(QChart::ChartTheme theme);
60 QChart::ChartTheme chartTheme() const;
50 QChart::ChartTheme theme() const;
61
51
62 void setTitle(const QString& title);
52 void setTitle(const QString& title);
63 QString title() const;
53 QString title() const;
@@ -96,25 +86,16 public:
96 protected:
86 protected:
97 void resizeEvent(QGraphicsSceneResizeEvent *event);
87 void resizeEvent(QGraphicsSceneResizeEvent *event);
98
88
89 protected:
90 QScopedPointer<QChartPrivate> d_ptr;
91
99 private:
92 private:
100 inline void createChartBackgroundItem();
101 inline void createChartTitleItem();
102 void setPadding(int padding);
93 void setPadding(int padding);
103 void setBackgroundPadding(int padding);
94 void setBackgroundPadding(int padding);
104 void setBackgroundDiameter(int diameter);
95 void setBackgroundDiameter(int diameter);
105 void updateLayout();
106 void updateLegendLayout();
107
96
108 private:
97 private:
109 Q_DISABLE_COPY(QChart)
98 Q_DISABLE_COPY(QChart);
110 ChartBackground* m_backgroundItem;
111 QGraphicsSimpleTextItem* m_titleItem;
112 QRectF m_rect;
113 QLegend* m_legend;
114 ChartDataSet *m_dataset;
115 ChartPresenter *m_presenter;
116 int m_padding;
117 int m_backgroundPadding;
118 };
99 };
119
100
120 QTCOMMERCIALCHART_END_NAMESPACE
101 QTCOMMERCIALCHART_END_NAMESPACE
@@ -322,7 +322,7 void QChartView::keyPressEvent(QKeyEvent *event)
322 */
322 */
323 void QChartView::setChartTheme(QChart::ChartTheme theme)
323 void QChartView::setChartTheme(QChart::ChartTheme theme)
324 {
324 {
325 m_chart->setChartTheme(theme);
325 m_chart->setTheme(theme);
326 }
326 }
327
327
328 /*!
328 /*!
@@ -331,7 +331,7 void QChartView::setChartTheme(QChart::ChartTheme theme)
331 */
331 */
332 QChart::ChartTheme QChartView::chartTheme() const
332 QChart::ChartTheme QChartView::chartTheme() const
333 {
333 {
334 return m_chart->chartTheme();
334 return m_chart->theme();
335 }
335 }
336
336
337 /*!
337 /*!
@@ -30,7 +30,8 PRIVATE_HEADERS += \
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 PUBLIC_HEADERS += \
35 PUBLIC_HEADERS += \
35 $$PWD/qchart.h \
36 $$PWD/qchart.h \
36 $$PWD/qchartglobal.h \
37 $$PWD/qchartglobal.h \
@@ -53,10 +54,8 include(themes/themes.pri)
53 HEADERS += $$PUBLIC_HEADERS
54 HEADERS += $$PUBLIC_HEADERS
54 HEADERS += $$PRIVATE_HEADERS
55 HEADERS += $$PRIVATE_HEADERS
55 HEADERS += $$THEMES
56 HEADERS += $$THEMES
56 INCLUDEPATH += linechart \
57 INCLUDEPATH += ../include
57 barchart \
58
58 themes \
59 .
60 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
59 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
61 MOC_DIR = $$CHART_BUILD_DIR/lib
60 MOC_DIR = $$CHART_BUILD_DIR/lib
62 UI_DIR = $$CHART_BUILD_DIR/lib
61 UI_DIR = $$CHART_BUILD_DIR/lib
General Comments 0
You need to be logged in to leave comments. Login now