##// 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())
@@ -1,9 +1,5
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
@@ -51,16 +47,15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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 /*!
@@ -69,8 +64,8 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(
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 /*!
@@ -80,7 +75,7 QChart::~QChart()
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 /*!
@@ -91,7 +86,7 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
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 /*!
@@ -101,7 +96,7 void QChart::removeSeries(QSeries* series)
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 /*!
@@ -109,15 +104,15 void QChart::removeAllSeries()
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 /*!
@@ -125,15 +120,15 QBrush QChart::backgroundBrush() const
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 /*!
@@ -141,9 +136,9 QPen QChart::backgroundPen() const
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 /*!
@@ -151,8 +146,8 void QChart::setTitle(const QString& title)
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 }
@@ -162,9 +157,9 QString QChart::title() const
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 /*!
@@ -172,9 +167,9 void QChart::setTitleFont(const QFont& font)
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 /*!
@@ -182,43 +177,26 void QChart::setTitleBrush(const QBrush &brush)
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 /*!
@@ -226,7 +204,7 QChart::ChartTheme QChart::chartTheme() const
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 /*!
@@ -234,9 +212,8 void QChart::zoomIn()
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 /*!
@@ -244,7 +221,7 void QChart::zoomIn(const QRectF& rect)
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 /*!
@@ -252,7 +229,7 void QChart::zoomOut()
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 /*!
@@ -260,7 +237,7 QChartAxis* QChart::axisX() const
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 /*!
@@ -268,7 +245,7 QChartAxis* QChart::axisY() const
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 /*!
@@ -276,8 +253,8 QLegend& QChart::legend() const
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
@@ -286,19 +263,19 QLegend* QChart::takeLegend()
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 /*!
@@ -306,9 +283,8 void QChart::giveLegend(QLegend* legend)
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 }
@@ -318,7 +294,7 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
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 /*!
@@ -326,53 +302,108 void QChart::setAnimationOptions(AnimationOptions options)
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) {
331 d_ptr->m_padding = padding;
332 d_ptr->m_presenter->handleGeometryChanged();
333 d_ptr->updateLayout();
334 }
335 }
353
336
354 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
337 int QChart::padding() const
338 {
339 return d_ptr->m_padding;
340 }
355
341
356 // recalculate title position
342 void QChart::setBackgroundPadding(int padding)
357 if (m_titleItem) {
343 {
358 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
344 if(d_ptr->m_backgroundPadding!=padding) {
359 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
345 d_ptr->m_backgroundPadding = padding;
346 d_ptr->updateLayout();
347 }
360 }
348 }
361
349
362 //recalculate background gradient
350 void QChart::setBackgroundDiameter(int diameter)
363 if (m_backgroundItem) {
351 {
364 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
352 d_ptr->createChartBackgroundItem();
353 d_ptr->m_backgroundItem->setDimeter(diameter);
354 d_ptr->m_backgroundItem->update();
365 }
355 }
366
356
367 // recalculate legend position
357 void QChart::setBackgroundVisible(bool visible)
368 if (m_legend) {
358 {
369 if (m_legend->parentObject() == this) {
359 d_ptr->createChartBackgroundItem();
370 updateLegendLayout();
360 d_ptr->m_backgroundItem->setVisible(visible);
361 }
362
363 bool QChart::isBackgroundVisible() const
364 {
365 if(!d_ptr->m_backgroundItem) return false;
366 return d_ptr->m_backgroundItem->isVisible();
367 }
368
369 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
370
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)
380 {
381
371 }
382 }
383
384 QChartPrivate::~QChartPrivate()
385 {
386
387 }
388
389 void QChartPrivate::createChartBackgroundItem()
390 {
391 if(!m_backgroundItem) {
392 m_backgroundItem = new ChartBackground(q_ptr);
393 m_backgroundItem->setPen(Qt::NoPen);
394 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
372 }
395 }
373 }
396 }
374
397
375 void QChart::updateLegendLayout()
398 void QChartPrivate::createChartTitleItem()
399 {
400 if(!m_titleItem) {
401 m_titleItem = new QGraphicsSimpleTextItem(q_ptr);
402 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
403 }
404 }
405
406 void QChartPrivate::updateLegendLayout()
376 {
407 {
377 QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
408 QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
378 QRectF legendRect;
409 QRectF legendRect;
@@ -406,48 +437,30 void QChart::updateLegendLayout()
406 m_legend->setPos(legendRect.topLeft());
437 m_legend->setPos(legendRect.topLeft());
407 }
438 }
408
439
409
440 void QChartPrivate::updateLayout()
410 int QChart::padding() const
411 {
441 {
412 return m_padding;
442 if(!m_rect.isValid()) return;
413 }
414
443
415 void QChart::setPadding(int padding)
444 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
416 {
417 if(m_padding==padding){
418 m_padding = padding;
419 m_presenter->handleGeometryChanged();
420 updateLayout();
421 }
422 }
423
445
424 void QChart::setBackgroundPadding(int padding)
446 // recalculate title position
425 {
447 if (m_titleItem) {
426 if(m_backgroundPadding!=padding){
448 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
427 m_backgroundPadding = padding;
449 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
428 updateLayout();
429 }
430 }
450 }
431
451
432 void QChart::setBackgroundDiameter(int diameter)
452 //recalculate background gradient
433 {
453 if (m_backgroundItem) {
434 createChartBackgroundItem();
454 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
435 m_backgroundItem->setDimeter(diameter);
436 m_backgroundItem->update();
437 }
455 }
438
456
439 void QChart::setBackgroundVisible(bool visible)
457 // recalculate legend position
440 {
458 if (m_legend) {
441 createChartBackgroundItem();
459 if (m_legend->parentObject() == q_ptr) {
442 m_backgroundItem->setVisible(visible);
460 updateLegendLayout();
461 }
443 }
462 }
444
445 bool QChart::isBackgroundVisible() const
446 {
447 if(!m_backgroundItem) return false;
448 return m_backgroundItem->isVisible();
449 }
463 }
450
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 {
@@ -53,11 +43,11 public:
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