@@ -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()) |
This diff has been collapsed as it changes many lines, (503 lines changed) Show them Hide them | |||
@@ -1,453 +1,466 | |||
|
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 | |
|
10 | 6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 7 | |
|
12 | 8 | /*! |
|
13 |
|
|
|
9 | \enum QChart::ChartTheme | |
|
14 | 10 | |
|
15 |
|
|
|
11 | This enum describes the theme used by the chart. | |
|
16 | 12 | |
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 | */ | |
|
13 | \value ChartThemeDefault Follows the GUI style of the Operating System | |
|
14 | \value ChartThemeLight | |
|
15 | \value ChartThemeBlueCerulean | |
|
16 | \value ChartThemeDark | |
|
17 | \value ChartThemeBrownSand | |
|
18 | \value ChartThemeBlueNcs | |
|
19 | \value ChartThemeIcy | |
|
20 | \value ChartThemeScientific | |
|
21 | \value ChartThemeCount Not really a theme; the total count of themes. | |
|
22 | */ | |
|
27 | 23 | |
|
28 | 24 | /*! |
|
29 |
|
|
|
25 | \enum QChart::AnimationOption | |
|
30 | 26 | |
|
31 |
|
|
|
27 | For enabling/disabling animations. Defaults to NoAnimation. | |
|
32 | 28 | |
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 | */ | |
|
29 | \value NoAnimation | |
|
30 | \value GridAxisAnimations | |
|
31 | \value SeriesAnimations | |
|
32 | \value AllAnimations | |
|
33 | */ | |
|
38 | 34 | |
|
39 | 35 | /*! |
|
40 |
|
|
|
41 |
|
|
|
36 | \class QChart | |
|
37 | \brief QtCommercial chart API. | |
|
42 | 38 | |
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 | */ | |
|
39 | 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 | |
|
41 | 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. | |
|
43 | \sa QChartView | |
|
44 | */ | |
|
49 | 45 | |
|
50 | 46 | /*! |
|
51 |
|
|
|
52 | */ | |
|
47 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
|
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 | /*! |
|
67 |
|
|
|
68 | */ | |
|
62 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
|
63 | */ | |
|
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 | /*! |
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 | */ | |
|
72 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
|
73 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
|
74 | the y axis). | |
|
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 | /*! |
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 | */ | |
|
82 | Removes the \a series specified in a perameter from the QChartView. | |
|
83 | It releses its ownership of the specified QChartSeries object. | |
|
84 | It does not delete the pointed QChartSeries data object | |
|
85 | \sa addSeries(), removeAllSeries() | |
|
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 | /*! |
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 | */ | |
|
93 | Removes all the QChartSeries that have been added to the QChartView | |
|
94 | It also deletes the pointed QChartSeries data objects | |
|
95 | \sa addSeries(), removeSeries() | |
|
96 | */ | |
|
102 | 97 | void QChart::removeAllSeries() |
|
103 | 98 | { |
|
104 | m_dataset->removeAllSeries(); | |
|
99 | d_ptr->m_dataset->removeAllSeries(); | |
|
105 | 100 | } |
|
106 | 101 | |
|
107 | 102 | /*! |
|
108 |
|
|
|
109 | */ | |
|
103 | Sets the \a brush that is used for painting the background of the chart area. | |
|
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 | /*! |
|
124 |
|
|
|
125 | */ | |
|
119 | Sets the \a pen that is used for painting the background of the chart area. | |
|
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 | /*! |
|
140 |
|
|
|
141 | */ | |
|
135 | Sets the chart \a title. The description text that is drawn above the chart. | |
|
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 | /*! |
|
150 |
|
|
|
151 | */ | |
|
145 | Returns the chart title. The description text that is drawn above the chart. | |
|
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 | } |
|
159 | 154 | |
|
160 | 155 | /*! |
|
161 |
|
|
|
162 | */ | |
|
156 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
|
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 | /*! |
|
171 |
|
|
|
172 | */ | |
|
166 | Sets the \a brush used for rendering the title text. | |
|
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 | /*! |
|
181 |
|
|
|
182 | */ | |
|
176 | Returns the brush used for rendering the title text. | |
|
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 |
|
|
|
208 |
|
|
|
209 | */ | |
|
210 |
void QChart::set |
|
|
185 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
|
186 | \sa ChartTheme, chartTheme() | |
|
187 | */ | |
|
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 |
|
|
|
217 |
|
|
|
218 | */ | |
|
219 |
QChart::ChartTheme QChart:: |
|
|
194 | Returns the theme enum used by the chart. | |
|
195 | \sa ChartTheme, setChartTheme() | |
|
196 | */ | |
|
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 | /*! |
|
225 |
|
|
|
226 | */ | |
|
203 | Zooms in the view by a factor of 2 | |
|
204 | */ | |
|
227 | 205 | void QChart::zoomIn() |
|
228 | 206 | { |
|
229 | m_presenter->zoomIn(); | |
|
207 | d_ptr->m_presenter->zoomIn(); | |
|
230 | 208 | } |
|
231 | 209 | |
|
232 | 210 | /*! |
|
233 |
|
|
|
234 | */ | |
|
211 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
|
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 | /*! |
|
243 |
|
|
|
244 | */ | |
|
220 | Restores the view zoom level to the previous one. | |
|
221 | */ | |
|
245 | 222 | void QChart::zoomOut() |
|
246 | 223 | { |
|
247 | m_presenter->zoomOut(); | |
|
224 | d_ptr->m_presenter->zoomOut(); | |
|
248 | 225 | } |
|
249 | 226 | |
|
250 | 227 | /*! |
|
251 |
|
|
|
252 | */ | |
|
228 | Returns the pointer to the x axis object of the chart | |
|
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 | /*! |
|
259 |
|
|
|
260 | */ | |
|
236 | Returns the pointer to the y axis object of the chart | |
|
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 | /*! |
|
267 |
|
|
|
268 | */ | |
|
244 | Returns the legend object of the chart. Ownership stays in chart. | |
|
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 | /*! |
|
275 |
|
|
|
276 | */ | |
|
252 | Gives ownership of legend to user. | |
|
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 | |
|
284 | 261 | /*! |
|
285 |
|
|
|
286 | */ | |
|
287 |
void QChart::giveLegend(QLegend* |
|
|
262 | Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one | |
|
263 | */ | |
|
264 | void QChart::giveLegend(QLegend *legend) | |
|
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 | /*! |
|
305 |
|
|
|
306 | */ | |
|
282 | Resizes and updates the chart area using the \a event data | |
|
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 | } |
|
315 | 291 | |
|
316 | 292 | /*! |
|
317 |
|
|
|
318 | */ | |
|
293 | Sets animation \a options for the chart | |
|
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 | /*! |
|
325 |
|
|
|
326 | */ | |
|
301 | Returns animation options for the chart | |
|
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; | |
|
353 | ||
|
354 | QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); | |
|
355 | ||
|
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); | |
|
330 | if(d_ptr->m_padding==padding) { | |
|
331 | d_ptr->m_padding = padding; | |
|
332 | d_ptr->m_presenter->handleGeometryChanged(); | |
|
333 | d_ptr->updateLayout(); | |
|
360 | 334 | } |
|
335 | } | |
|
361 | 336 | |
|
362 | //recalculate background gradient | |
|
363 | if (m_backgroundItem) { | |
|
364 | m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding)); | |
|
365 | } | |
|
337 | int QChart::padding() const | |
|
338 | { | |
|
339 | return d_ptr->m_padding; | |
|
340 | } | |
|
366 | 341 | |
|
367 | // recalculate legend position | |
|
368 | if (m_legend) { | |
|
369 | if (m_legend->parentObject() == this) { | |
|
370 | updateLegendLayout(); | |
|
371 | } | |
|
342 | void QChart::setBackgroundPadding(int padding) | |
|
343 | { | |
|
344 | if(d_ptr->m_backgroundPadding!=padding) { | |
|
345 | d_ptr->m_backgroundPadding = padding; | |
|
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); | |
|
378 | QRectF legendRect; | |
|
352 | d_ptr->createChartBackgroundItem(); | |
|
353 | d_ptr->m_backgroundItem->setDimeter(diameter); | |
|
354 | d_ptr->m_backgroundItem->update(); | |
|
355 | } | |
|
379 | 356 | |
|
380 | switch (m_legend->preferredLayout()) | |
|
381 | { | |
|
382 | case QLegend::PreferredLayoutTop:{ | |
|
383 | // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height()); | |
|
384 | legendRect = plotRect.adjusted(0,0,0,-m_padding - plotRect.height()); | |
|
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 | } | |
|
357 | void QChart::setBackgroundVisible(bool visible) | |
|
358 | { | |
|
359 | d_ptr->createChartBackgroundItem(); | |
|
360 | d_ptr->m_backgroundItem->setVisible(visible); | |
|
361 | } | |
|
404 | 362 | |
|
405 | m_legend->setMaximumSize(legendRect.size()); | |
|
406 | m_legend->setPos(legendRect.topLeft()); | |
|
363 | bool QChart::isBackgroundVisible() const | |
|
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){ | |
|
418 | m_padding = padding; | |
|
419 | m_presenter->handleGeometryChanged(); | |
|
420 | updateLayout(); | |
|
421 | } | |
|
386 | ||
|
422 | 387 | } |
|
423 | 388 | |
|
424 | void QChart::setBackgroundPadding(int padding) | |
|
389 | void QChartPrivate::createChartBackgroundItem() | |
|
425 | 390 | { |
|
426 |
if( |
|
|
427 | m_backgroundPadding = padding; | |
|
428 | updateLayout(); | |
|
391 | if(!m_backgroundItem) { | |
|
392 | m_backgroundItem = new ChartBackground(q_ptr); | |
|
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(); | |
|
435 | m_backgroundItem->setDimeter(diameter); | |
|
436 | m_backgroundItem->update(); | |
|
400 | if(!m_titleItem) { | |
|
401 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); | |
|
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(); | |
|
442 | m_backgroundItem->setVisible(visible); | |
|
408 | QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); | |
|
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; | |
|
448 | return m_backgroundItem->isVisible(); | |
|
449 | } | |
|
442 | if(!m_rect.isValid()) return; | |
|
443 | ||
|
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 | 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 | { |
@@ -52,12 +42,12 public: | |||
|
52 | 42 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
53 | 43 | ~QChart(); |
|
54 | 44 | |
|
55 |
void addSeries(QSeries* |
|
|
56 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
|
57 |
void removeAllSeries(); |
|
|
45 | void addSeries(QSeries *series, QChartAxis *axisY = 0); | |
|
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