@@ -17,7 +17,7 DeclarativeChart::~DeclarativeChart() | |||
|
17 | 17 | |
|
18 | 18 | DeclarativeChart::ChartTheme DeclarativeChart::theme() |
|
19 | 19 | { |
|
20 |
return (ChartTheme) m_chart-> |
|
|
20 | return (ChartTheme) m_chart->theme(); | |
|
21 | 21 | } |
|
22 | 22 | |
|
23 | 23 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
@@ -34,7 +34,7 public: // From QDeclarativeItem/QGraphicsItem | |||
|
34 | 34 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
35 | 35 | |
|
36 | 36 | public: |
|
37 |
void setTheme(ChartTheme theme) {m_chart->set |
|
|
37 | void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);} | |
|
38 | 38 | ChartTheme theme(); |
|
39 | 39 | |
|
40 | 40 | public: |
@@ -28,6 +28,8 private: | |||
|
28 | 28 | |
|
29 | 29 | }; |
|
30 | 30 | |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
32 | ||
|
31 | 33 | #endif /* CHARTBACKGROUND_H_ */ |
|
32 | 34 | |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
35 |
@@ -36,7 +36,7 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char | |||
|
36 | 36 | m_themeForce(false) |
|
37 | 37 | { |
|
38 | 38 | createConnections(); |
|
39 |
set |
|
|
39 | setTheme(QChart::ChartThemeDefault,false); | |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | ChartPresenter::~ChartPresenter() |
@@ -270,7 +270,7 void ChartPresenter::handleSeriesRemoved(QSeries* series) | |||
|
270 | 270 | delete item; |
|
271 | 271 | } |
|
272 | 272 | |
|
273 |
void ChartPresenter::set |
|
|
273 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
|
274 | 274 | { |
|
275 | 275 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
276 | 276 | delete m_chartTheme; |
@@ -281,7 +281,7 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force) | |||
|
281 | 281 | resetAllElements(); |
|
282 | 282 | } |
|
283 | 283 | |
|
284 |
QChart::ChartTheme ChartPresenter:: |
|
|
284 | QChart::ChartTheme ChartPresenter::theme() | |
|
285 | 285 | { |
|
286 | 286 | return m_chartTheme->id(); |
|
287 | 287 | } |
@@ -41,11 +41,11 public: | |||
|
41 | 41 | QRectF geometry() const; |
|
42 | 42 | |
|
43 | 43 | ChartAnimator* animator() const {return m_animator;} |
|
44 | ChartTheme *theme() { return m_chartTheme; } | |
|
44 | ChartTheme *chartTheme() { return m_chartTheme; } | |
|
45 | 45 | ChartDataSet *dataSet() { return m_dataset; } |
|
46 | 46 | |
|
47 |
void set |
|
|
48 |
QChart::ChartTheme |
|
|
47 | void setTheme(QChart::ChartTheme theme,bool force = true); | |
|
48 | QChart::ChartTheme theme(); | |
|
49 | 49 | |
|
50 | 50 | void setAnimationOptions(QChart::AnimationOptions options); |
|
51 | 51 | QChart::AnimationOptions animationOptions() const; |
@@ -51,7 +51,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||
|
51 | 51 | { |
|
52 | 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 | 56 | foreach (QPieSlice *s, slices) { |
|
57 | 57 | PieSliceItem* item = new PieSliceItem(this); |
@@ -72,7 +72,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||
|
72 | 72 | |
|
73 | 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 | 77 | foreach (QPieSlice *s, slices) { |
|
78 | 78 | if (animator()) |
@@ -1,9 +1,5 | |||
|
1 | 1 | #include "qchart.h" |
|
2 |
#include "qchart |
|
|
3 | #include "qlegend.h" | |
|
4 | #include "chartpresenter_p.h" | |
|
5 | #include "chartdataset_p.h" | |
|
6 | #include "chartbackground_p.h" | |
|
2 | #include "qchart_p.h" | |
|
7 | 3 | #include <QGraphicsScene> |
|
8 | 4 | #include <QGraphicsSceneResizeEvent> |
|
9 | 5 | |
@@ -51,16 +47,15 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
51 | 47 |
|
|
52 | 48 | */ |
|
53 | 49 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
54 | m_backgroundItem(0), | |
|
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) | |
|
50 | d_ptr(new QChartPrivate(this)) | |
|
61 | 51 | { |
|
62 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
|
63 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
|
52 | ||
|
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 | 64 | QChart::~QChart() |
|
70 | 65 | { |
|
71 | 66 | //delete first presenter , since this is a root of all the graphical items |
|
72 | delete m_presenter; | |
|
73 | m_presenter=0; | |
|
67 | delete d_ptr->m_presenter; | |
|
68 | d_ptr->m_presenter=0; | |
|
74 | 69 | } |
|
75 | 70 | |
|
76 | 71 | /*! |
@@ -80,7 +75,7 QChart::~QChart() | |||
|
80 | 75 | */ |
|
81 | 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 | 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 | 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 | 105 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
111 | 106 | { |
|
112 | createChartBackgroundItem(); | |
|
113 | m_backgroundItem->setBrush(brush); | |
|
114 | m_backgroundItem->update(); | |
|
107 | d_ptr->createChartBackgroundItem(); | |
|
108 | d_ptr->m_backgroundItem->setBrush(brush); | |
|
109 | d_ptr->m_backgroundItem->update(); | |
|
115 | 110 | } |
|
116 | 111 | |
|
117 | 112 | QBrush QChart::backgroundBrush() const |
|
118 | 113 | { |
|
119 | if(!m_backgroundItem) return QBrush(); | |
|
120 | return m_backgroundItem->brush(); | |
|
114 | if(!d_ptr->m_backgroundItem) return QBrush(); | |
|
115 | return (d_ptr->m_backgroundItem)->brush(); | |
|
121 | 116 | } |
|
122 | 117 | |
|
123 | 118 | /*! |
@@ -125,15 +120,15 QBrush QChart::backgroundBrush() const | |||
|
125 | 120 | */ |
|
126 | 121 | void QChart::setBackgroundPen(const QPen& pen) |
|
127 | 122 | { |
|
128 | createChartBackgroundItem(); | |
|
129 | m_backgroundItem->setPen(pen); | |
|
130 | m_backgroundItem->update(); | |
|
123 | d_ptr->createChartBackgroundItem(); | |
|
124 | d_ptr->m_backgroundItem->setPen(pen); | |
|
125 | d_ptr->m_backgroundItem->update(); | |
|
131 | 126 | } |
|
132 | 127 | |
|
133 | 128 | QPen QChart::backgroundPen() const |
|
134 | 129 | { |
|
135 | if(!m_backgroundItem) return QPen(); | |
|
136 | return m_backgroundItem->pen(); | |
|
130 | if(!d_ptr->m_backgroundItem) return QPen(); | |
|
131 | return d_ptr->m_backgroundItem->pen(); | |
|
137 | 132 | } |
|
138 | 133 | |
|
139 | 134 | /*! |
@@ -141,9 +136,9 QPen QChart::backgroundPen() const | |||
|
141 | 136 | */ |
|
142 | 137 | void QChart::setTitle(const QString& title) |
|
143 | 138 | { |
|
144 | createChartTitleItem(); | |
|
145 | m_titleItem->setText(title); | |
|
146 | updateLayout(); | |
|
139 | d_ptr->createChartTitleItem(); | |
|
140 | d_ptr->m_titleItem->setText(title); | |
|
141 | d_ptr->updateLayout(); | |
|
147 | 142 | } |
|
148 | 143 | |
|
149 | 144 | /*! |
@@ -151,8 +146,8 void QChart::setTitle(const QString& title) | |||
|
151 | 146 | */ |
|
152 | 147 | QString QChart::title() const |
|
153 | 148 | { |
|
154 | if(m_titleItem) | |
|
155 | return m_titleItem->text(); | |
|
149 | if(d_ptr->m_titleItem) | |
|
150 | return d_ptr->m_titleItem->text(); | |
|
156 | 151 | else |
|
157 | 152 | return QString(); |
|
158 | 153 | } |
@@ -162,9 +157,9 QString QChart::title() const | |||
|
162 | 157 | */ |
|
163 | 158 | void QChart::setTitleFont(const QFont& font) |
|
164 | 159 | { |
|
165 | createChartTitleItem(); | |
|
166 | m_titleItem->setFont(font); | |
|
167 | updateLayout(); | |
|
160 | d_ptr->createChartTitleItem(); | |
|
161 | d_ptr->m_titleItem->setFont(font); | |
|
162 | d_ptr->updateLayout(); | |
|
168 | 163 | } |
|
169 | 164 | |
|
170 | 165 | /*! |
@@ -172,9 +167,9 void QChart::setTitleFont(const QFont& font) | |||
|
172 | 167 | */ |
|
173 | 168 | void QChart::setTitleBrush(const QBrush &brush) |
|
174 | 169 | { |
|
175 | createChartTitleItem(); | |
|
176 | m_titleItem->setBrush(brush); | |
|
177 | updateLayout(); | |
|
170 | d_ptr->createChartTitleItem(); | |
|
171 | d_ptr->m_titleItem->setBrush(brush); | |
|
172 | d_ptr->updateLayout(); | |
|
178 | 173 | } |
|
179 | 174 | |
|
180 | 175 | /*! |
@@ -182,43 +177,26 void QChart::setTitleBrush(const QBrush &brush) | |||
|
182 | 177 | */ |
|
183 | 178 | QBrush QChart::titleBrush() const |
|
184 | 179 | { |
|
185 | if(!m_titleItem) return QBrush(); | |
|
186 | return 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 | } | |
|
180 | if(!d_ptr->m_titleItem) return QBrush(); | |
|
181 | return d_ptr->m_titleItem->brush(); | |
|
204 | 182 | } |
|
205 | 183 | |
|
206 | 184 | /*! |
|
207 | 185 |
|
|
208 | 186 |
|
|
209 | 187 | */ |
|
210 |
void QChart::set |
|
|
188 | void QChart::setTheme(QChart::ChartTheme theme) | |
|
211 | 189 | { |
|
212 |
m_presenter->set |
|
|
190 | d_ptr->m_presenter->setTheme(theme); | |
|
213 | 191 | } |
|
214 | 192 | |
|
215 | 193 | /*! |
|
216 | 194 |
|
|
217 | 195 |
|
|
218 | 196 | */ |
|
219 |
QChart::ChartTheme QChart:: |
|
|
197 | QChart::ChartTheme QChart::theme() const | |
|
220 | 198 | { |
|
221 |
return m_presenter-> |
|
|
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 | 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 | 213 | void QChart::zoomIn(const QRectF& rect) |
|
236 | 214 | { |
|
237 | ||
|
238 | 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 | 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 | 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 | 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 | 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 | 254 | QLegend* QChart::takeLegend() |
|
278 | 255 | { |
|
279 | QLegend* l = m_legend; | |
|
280 | m_legend = 0; | |
|
256 | QLegend* l = d_ptr->m_legend; | |
|
257 | d_ptr->m_legend = 0; | |
|
281 | 258 | return l; |
|
282 | 259 | } |
|
283 | 260 | |
@@ -286,19 +263,19 QLegend* QChart::takeLegend() | |||
|
286 | 263 | */ |
|
287 | 264 |
void QChart::giveLegend(QLegend* |
|
288 | 265 | { |
|
289 | if (m_legend) { | |
|
266 | if (d_ptr->m_legend) { | |
|
290 | 267 | // Should not happen. |
|
291 | 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 | 274 | // Reconnect legend, in case not already connected. |
|
298 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
|
299 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
|
300 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
|
301 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
|
275 | disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
|
276 | disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
|
277 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
|
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 | 284 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
308 | 285 | { |
|
309 | ||
|
310 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
|
311 | updateLayout(); | |
|
286 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
|
287 | d_ptr->updateLayout(); | |
|
312 | 288 | QGraphicsWidget::resizeEvent(event); |
|
313 | 289 | update(); |
|
314 | 290 | } |
@@ -318,7 +294,7 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |||
|
318 | 294 | */ |
|
319 | 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 | 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 | 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 | 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 | 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 | 323 | void QChart::scrollDown() |
|
346 | 324 | { |
|
347 |
|
|
|
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 | |
|
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); | |
|
342 | void QChart::setBackgroundPadding(int padding) | |
|
343 | { | |
|
344 | if(d_ptr->m_backgroundPadding!=padding) { | |
|
345 | d_ptr->m_backgroundPadding = padding; | |
|
346 | d_ptr->updateLayout(); | |
|
347 | } | |
|
360 | 348 | } |
|
361 | 349 | |
|
362 | //recalculate background gradient | |
|
363 | if (m_backgroundItem) { | |
|
364 | m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding)); | |
|
350 | void QChart::setBackgroundDiameter(int diameter) | |
|
351 | { | |
|
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 | |
|
368 | if (m_legend) { | |
|
369 | if (m_legend->parentObject() == this) { | |
|
370 | updateLegendLayout(); | |
|
357 | void QChart::setBackgroundVisible(bool visible) | |
|
358 | { | |
|
359 | d_ptr->createChartBackgroundItem(); | |
|
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 | 408 | QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); |
|
378 | 409 | QRectF legendRect; |
@@ -406,48 +437,30 void QChart::updateLegendLayout() | |||
|
406 | 437 | m_legend->setPos(legendRect.topLeft()); |
|
407 | 438 | } |
|
408 | 439 | |
|
409 | ||
|
410 | int QChart::padding() const | |
|
440 | void QChartPrivate::updateLayout() | |
|
411 | 441 | { |
|
412 | return m_padding; | |
|
413 | } | |
|
442 | if(!m_rect.isValid()) return; | |
|
414 | 443 | |
|
415 | void QChart::setPadding(int padding) | |
|
416 | { | |
|
417 | if(m_padding==padding){ | |
|
418 | m_padding = padding; | |
|
419 | m_presenter->handleGeometryChanged(); | |
|
420 | updateLayout(); | |
|
421 | } | |
|
422 | } | |
|
444 | QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); | |
|
423 | 445 | |
|
424 | void QChart::setBackgroundPadding(int padding) | |
|
425 | { | |
|
426 | if(m_backgroundPadding!=padding){ | |
|
427 | m_backgroundPadding = padding; | |
|
428 | updateLayout(); | |
|
429 | } | |
|
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); | |
|
430 | 450 | } |
|
431 | 451 | |
|
432 | void QChart::setBackgroundDiameter(int diameter) | |
|
433 | { | |
|
434 | createChartBackgroundItem(); | |
|
435 | m_backgroundItem->setDimeter(diameter); | |
|
436 | m_backgroundItem->update(); | |
|
452 | //recalculate background gradient | |
|
453 | if (m_backgroundItem) { | |
|
454 | m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding)); | |
|
437 | 455 | } |
|
438 | 456 | |
|
439 | void QChart::setBackgroundVisible(bool visible) | |
|
440 | { | |
|
441 | createChartBackgroundItem(); | |
|
442 | m_backgroundItem->setVisible(visible); | |
|
457 | // recalculate legend position | |
|
458 | if (m_legend) { | |
|
459 | if (m_legend->parentObject() == q_ptr) { | |
|
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 | 465 | #include "moc_qchart.cpp" |
|
453 | 466 |
@@ -1,11 +1,8 | |||
|
1 | 1 | #ifndef QCHART_H |
|
2 | 2 | #define QCHART_H |
|
3 | 3 | |
|
4 | #include <qchartglobal.h> | |
|
5 | #include <qseries.h> | |
|
4 | #include <QSeries> | |
|
6 | 5 | #include <QGraphicsWidget> |
|
7 | #include <QLinearGradient> | |
|
8 | #include <QFont> | |
|
9 | 6 | |
|
10 | 7 | class QGraphicsSceneResizeEvent; |
|
11 | 8 | |
@@ -13,16 +10,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
13 | 10 | |
|
14 | 11 | class Axis; |
|
15 | 12 | class QSeries; |
|
16 | class PlotDomain; | |
|
17 | class BarChartItem; | |
|
18 | 13 | class QChartAxis; |
|
19 | class ChartTheme; | |
|
20 | class ChartItem; | |
|
21 | class ChartDataSet; | |
|
22 | class ChartPresenter; | |
|
23 | 14 | class QLegend; |
|
24 |
class |
|
|
25 | ||
|
15 | class QChartPrivate; | |
|
26 | 16 | |
|
27 | 17 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
28 | 18 | { |
@@ -53,11 +43,11 public: | |||
|
53 | 43 | ~QChart(); |
|
54 | 44 | |
|
55 | 45 |
void addSeries(QSeries* |
|
56 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
|
57 |
void removeAllSeries(); |
|
|
46 | void removeSeries(QSeries *series); | |
|
47 | void removeAllSeries(); | |
|
58 | 48 | |
|
59 |
void set |
|
|
60 |
QChart::ChartTheme |
|
|
49 | void setTheme(QChart::ChartTheme theme); | |
|
50 | QChart::ChartTheme theme() const; | |
|
61 | 51 | |
|
62 | 52 | void setTitle(const QString& title); |
|
63 | 53 | QString title() const; |
@@ -96,25 +86,16 public: | |||
|
96 | 86 | protected: |
|
97 | 87 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
98 | 88 | |
|
89 | protected: | |
|
90 | QScopedPointer<QChartPrivate> d_ptr; | |
|
91 | ||
|
99 | 92 | private: |
|
100 | inline void createChartBackgroundItem(); | |
|
101 | inline void createChartTitleItem(); | |
|
102 | 93 | void setPadding(int padding); |
|
103 | 94 | void setBackgroundPadding(int padding); |
|
104 | 95 | void setBackgroundDiameter(int diameter); |
|
105 | void updateLayout(); | |
|
106 | void updateLegendLayout(); | |
|
107 | 96 | |
|
108 | 97 | private: |
|
109 | 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; | |
|
98 | Q_DISABLE_COPY(QChart); | |
|
118 | 99 | }; |
|
119 | 100 | |
|
120 | 101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -322,7 +322,7 void QChartView::keyPressEvent(QKeyEvent *event) | |||
|
322 | 322 | */ |
|
323 | 323 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
324 | 324 | { |
|
325 |
m_chart->set |
|
|
325 | m_chart->setTheme(theme); | |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | /*! |
@@ -331,7 +331,7 void QChartView::setChartTheme(QChart::ChartTheme theme) | |||
|
331 | 331 | */ |
|
332 | 332 | QChart::ChartTheme QChartView::chartTheme() const |
|
333 | 333 | { |
|
334 |
return m_chart-> |
|
|
334 | return m_chart->theme(); | |
|
335 | 335 | } |
|
336 | 336 | |
|
337 | 337 | /*! |
@@ -30,7 +30,8 PRIVATE_HEADERS += \ | |||
|
30 | 30 | $$PWD/legendscrollbutton_p.h \ |
|
31 | 31 | $$PWD/chartbackground_p.h \ |
|
32 | 32 | $$PWD/chart_p.h \ |
|
33 | $$PWD/chartconfig_p.h | |
|
33 | $$PWD/chartconfig_p.h \ | |
|
34 | $$PWD/qchart_p.h | |
|
34 | 35 | PUBLIC_HEADERS += \ |
|
35 | 36 | $$PWD/qchart.h \ |
|
36 | 37 | $$PWD/qchartglobal.h \ |
@@ -53,10 +54,8 include(themes/themes.pri) | |||
|
53 | 54 | HEADERS += $$PUBLIC_HEADERS |
|
54 | 55 | HEADERS += $$PRIVATE_HEADERS |
|
55 | 56 | HEADERS += $$THEMES |
|
56 |
INCLUDEPATH += |
|
|
57 | barchart \ | |
|
58 | themes \ | |
|
59 | . | |
|
57 | INCLUDEPATH += ../include | |
|
58 | ||
|
60 | 59 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
61 | 60 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
62 | 61 | UI_DIR = $$CHART_BUILD_DIR/lib |
General Comments 0
You need to be logged in to leave comments.
Login now