##// END OF EJS Templates
added map for yaxises methods to set axis
sauimone -
r1554:9a708aa57671
parent child
Show More
@@ -1,292 +1,304
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdataset_p.h"
22 22 #include "qchart.h"
23 23 #include "qvaluesaxis.h"
24 24 #include "qvaluesaxis_p.h"
25 25 #include "qabstractseries_p.h"
26 26 #include "qbarseries.h"
27 27 #include "qstackedbarseries.h"
28 28 #include "qpercentbarseries.h"
29 29 #include "qpieseries.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
34 34 m_axisX(new QValuesAxis(this)),
35 35 m_axisY(new QValuesAxis(this)),
36 36 m_domainIndex(0),
37 37 m_axisXInitialized(false),
38 38 m_axisYInitialized(false)
39 39 {
40 40 //create main domain
41 41 Domain* domain = new Domain(m_axisY);
42 42 m_axisDomainMap.insert(m_axisY,domain);
43 43 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
44 44 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
45 45 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 46 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
47 47 }
48 48
49 49 ChartDataSet::~ChartDataSet()
50 50 {
51 51 removeAllSeries();
52 52 }
53 53
54 54 void ChartDataSet::addSeries(QAbstractSeries* series)
55 55 {
56 QAbstractAxis* axis = m_seriesAxisMap.value(series);
56 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
57 57
58 58 if(axis) {
59 59 qWarning() << "Can not add series. Series already on the chart";
60 60 return;
61 61 }
62 62
63 QAbstractAxis* axisX = m_axisX ; //series->d_ptr->createAxisX();
63 QAbstractAxis* axisX = series->d_ptr->createAxisX();
64 64 QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY();
65 65
66 66 series->setParent(this); // take ownership
67 67 //axisY->setParent(this); // take ownership
68 68
69 69 Domain* domain = m_axisDomainMap.value(axisY);
70 70
71 71 if(!domain) {
72 72 domain = new Domain(axisY);
73 73 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
74 74 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
75 75 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
76 76 //initialize
77 77 m_axisDomainMap.insert(axisY,domain);
78 78 emit axisAdded(axisY,domain);
79 79 }
80 80
81 81 if(!m_axisXInitialized){
82 82 m_axisXInitialized=true;
83 emit axisAdded(m_axisX,domain);
83 // emit axisAdded(m_axisX,domain);
84 emit axisAdded(axisX,domain);
84 85 }
85 86
86 87 if(!m_axisYInitialized && axisY==m_axisY){
87 88 m_axisYInitialized=true;
88 89 emit axisAdded(m_axisY,domain);
89 90 }
90 91
91 92 series->d_ptr->scaleDomain(*domain);
92 93
93 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
94 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisXMap.count() == 0) {
94 95 axisX->hide();
95 96 axisY->hide();
96 97 }
97 98
98 m_seriesAxisMap.insert(series,axisY);
99 m_seriesAxisXMap.insert(series,axisY);
99 100
100 101 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
101 102
102 103 int key=0;
103 104 while (i.hasNext()) {
104 105 i.next();
105 106 if(i.key()!=key) {
106 107 break;
107 108 }
108 109 key++;
109 110 }
110 111
111 112 m_indexSeriesMap.insert(key,series);
112 113
113 114 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
114 115 series->d_ptr->m_dataset = this;
115 116
116 117 emit seriesAdded(series,domain);
117 118
118 119 }
119 120
120 121 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
121 122 {
122 QAbstractAxis* axis = m_seriesAxisMap.value(series);
123 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
123 124
124 125 if(!axis){
125 126 qWarning()<<"Can not remove series. Series not found on the chart.";
126 127 return 0;
127 128 }
128 129
129 130 emit seriesRemoved(series);
130 131
131 m_seriesAxisMap.remove(series);
132 m_seriesAxisXMap.remove(series);
132 133 int key = seriesIndex(series);
133 134 Q_ASSERT(key!=-1);
134 135
135 136 m_indexSeriesMap.remove(key);
136 137
137 138 series->setParent(0);
138 139 series->d_ptr->m_chart = 0;
139 140 series->d_ptr->m_dataset = 0;
140 141
141 QList<QAbstractAxis*> axes = m_seriesAxisMap.values();
142 QList<QAbstractAxis*> axes = m_seriesAxisXMap.values();
142 143
143 144 int i = axes.indexOf(axis);
144 145
145 146 if(i==-1){
146 147 Domain* domain = m_axisDomainMap.take(axis);
147 148 emit axisRemoved(axis);
148 149 if(axis!=m_axisY){
149 150 axis->setParent(0);
150 151 delete domain;
151 152 }else{
152 153 m_axisYInitialized=false;
153 154 m_axisDomainMap.insert(m_axisY,domain);
154 155 }
155 156 }
156 157
157 if(m_seriesAxisMap.values().size()==0)
158 if(m_seriesAxisXMap.values().size()==0)
158 159 {
159 160 m_axisXInitialized=false;
160 161 emit axisRemoved(m_axisX);
161 162 }
162 163
163 164 return axis;
164 165 }
165 166
166 167 void ChartDataSet::removeAllSeries()
167 168 {
168 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
169 QList<QAbstractSeries*> series = m_seriesAxisXMap.keys();
169 170 QList<QAbstractAxis*> axes;
170 171 foreach(QAbstractSeries *s , series) {
171 172 QAbstractAxis* axis = removeSeries(s);
172 173 if(axis==m_axisY) continue;
173 174 int i = axes.indexOf(axis);
174 175 if(i==-1){
175 176 axes<<axis;
176 177 }
177 178 }
178 179
179 Q_ASSERT(m_seriesAxisMap.count()==0);
180 Q_ASSERT(m_seriesAxisXMap.count()==0);
180 181 Q_ASSERT(m_axisDomainMap.count()==1);
181 182
182 183 qDeleteAll(series);
183 184 qDeleteAll(axes);
184 185 }
185 186
186 187 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
187 188 {
188 189 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
189 190 //main domain has to be the last one;
190 191 Domain *domain = m_axisDomainMap.value(m_axisY);
191 192 Q_ASSERT(domain);
192 193 while (i.hasNext()) {
193 194 i.next();
194 195 if(i.value()==domain) continue;
195 196 i.value()->zoomIn(rect,size);
196 197 }
197 198 domain->zoomIn(rect,size);
198 199 }
199 200
200 201 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
201 202 {
202 203 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
203 204 //main domain has to be the last one;
204 205 Domain *domain = m_axisDomainMap.value(m_axisY);
205 206 Q_ASSERT(domain);
206 207 while (i.hasNext()) {
207 208 i.next();
208 209 if(i.value()==domain) continue;
209 210 i.value()->zoomOut(rect,size);
210 211 }
211 212 domain->zoomOut(rect,size);
212 213 }
213 214
214 215 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
215 216 {
216 217 int count=0;
217 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisMap);
218 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap);
218 219 while (i.hasNext()) {
219 220 i.next();
220 221 if(i.key()->type()==type) count++;
221 222 }
222 223 return count;
223 224 }
224 225
225 226 int ChartDataSet::seriesIndex(QAbstractSeries *series)
226 227 {
227 228 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
228 229 while (i.hasNext()) {
229 230 i.next();
230 231 if (i.value() == series)
231 232 return i.key();
232 233 }
233 234 return -1;
234 235 }
235 236
237 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
238 {
239 qDebug() << "axisX";
240 if (series == 0) return m_axisX;
241 return m_seriesAxisXMap.value(series);
242 }
243
236 244 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
237 245 {
238 246 if(series == 0) return m_axisY;
239 return m_seriesAxisMap.value(series);
247 return m_seriesAxisYMap.value(series);
240 248 }
241 249
242 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
250 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
251 {
252 m_seriesAxisXMap.insert(series,axis);
253 }
254
255 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
243 256 {
244 Q_UNUSED(series)
245 return m_axisX;
257 m_seriesAxisYMap.insert(series,axis);
246 258 }
247 259
248 260 Domain* ChartDataSet::domain(QAbstractSeries *series) const
249 261 {
250 QAbstractAxis* axis = m_seriesAxisMap.value(series);
262 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
251 263 if(axis){
252 264 return m_axisDomainMap.value(axis);
253 265 }else
254 266 return 0;
255 267 }
256 268
257 269 Domain* ChartDataSet::domain(QAbstractAxis* axis) const
258 270 {
259 271 if(!axis || axis==m_axisX) {
260 272 return m_axisDomainMap.value(m_axisY);
261 273 }
262 274 else {
263 275 return m_axisDomainMap.value(axis);
264 276 }
265 277 }
266 278
267 279 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
268 280 {
269 281 QMapIterator<QAbstractAxis*, Domain*> i( m_axisDomainMap);
270 282 //main domain has to be the last one;
271 283 Domain *domain = m_axisDomainMap.value(m_axisY);
272 284 while (i.hasNext()) {
273 285 i.next();
274 286 if(i.value()==domain) continue;
275 287 i.value()->move(dx,dy,size);
276 288 }
277 289 domain->move(dx,dy,size);
278 290 }
279 291
280 292 QList<QAbstractSeries*> ChartDataSet::series() const
281 293 {
282 return m_seriesAxisMap.keys();
294 return m_seriesAxisXMap.keys();
283 295 }
284 296
285 297 void ChartDataSet::updateSeries(QAbstractSeries *series)
286 298 {
287 299 emit seriesUpdated(series);
288 300 }
289 301
290 302 #include "moc_chartdataset_p.cpp"
291 303
292 304 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,93 +1,97
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTDATASET_P_H
31 31 #define CHARTDATASET_P_H
32 32
33 33 #include "qabstractseries.h"
34 34 #include "domain_p.h"
35 35 #include <QVector>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class QAbstractAxis;
40 40
41 41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
42 42 {
43 43 Q_OBJECT
44 44 public:
45 45 ChartDataSet(QChart* parent=0);
46 46 virtual ~ChartDataSet();
47 47
48 48 void addSeries(QAbstractSeries* series);
49 49 QAbstractAxis* removeSeries(QAbstractSeries* series);
50 50 void removeAllSeries();
51 51 void updateSeries(QAbstractSeries* series);
52 52
53 53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 55 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
56 56
57 57 int seriesCount(QAbstractSeries::SeriesType type);
58 58 int seriesIndex(QAbstractSeries *series);
59 59
60 60 Domain* domain(QAbstractSeries* series) const;
61 61 Domain* domain(QAbstractAxis* axis) const;
62 62
63 63 QAbstractAxis* axisX(QAbstractSeries *series) const;
64 64 QAbstractAxis* axisY(QAbstractSeries *series) const;
65 65
66 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
67 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
68
66 69 QList<QAbstractSeries*> series() const;
67 70
68 71 Q_SIGNALS:
69 72 void seriesAdded(QAbstractSeries* series, Domain* domain);
70 73 void seriesRemoved(QAbstractSeries* series);
71 74 void seriesUpdated(QAbstractSeries* series);
72 75 void axisAdded(QAbstractAxis* axis,Domain* domain);
73 76 void axisRemoved(QAbstractAxis* axis);
74 77
75 78 private:
76 79 QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max);
77 80 void calculateDomain(QAbstractSeries* series,Domain* domain);
78 81
79 82 private:
80 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisMap;
83 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
84 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
81 85 QMap<QAbstractAxis*, Domain*> m_axisDomainMap;
82 86 QMap<int, QAbstractSeries*> m_indexSeriesMap;
83 87 QAbstractAxis* m_axisX;
84 88 QAbstractAxis* m_axisY;
85 89
86 90 int m_domainIndex;
87 91 bool m_axisXInitialized;
88 92 bool m_axisYInitialized;
89 93 };
90 94
91 95 QTCOMMERCIALCHART_END_NAMESPACE
92 96
93 97 #endif /* CHARTENGINE_P_H_ */
@@ -1,437 +1,439
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qchart.h"
22 22 #include "qchart_p.h"
23 23 #include "legendscroller_p.h"
24 24 #include "qlegend_p.h"
25 25 #include "chartbackground_p.h"
26 26 #include "qabstractaxis.h"
27 27 #include <QGraphicsScene>
28 28 #include <QGraphicsSceneResizeEvent>
29 29 #include <QGraphicsLayout>
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \enum QChart::ChartTheme
35 35
36 36 This enum describes the theme used by the chart.
37 37
38 38 \value ChartThemeLight The default theme
39 39 \value ChartThemeBlueCerulean
40 40 \value ChartThemeDark
41 41 \value ChartThemeBrownSand
42 42 \value ChartThemeBlueNcs
43 43 \value ChartThemeHighContrast
44 44 \value ChartThemeBlueIcy
45 45 */
46 46
47 47 /*!
48 48 \enum QChart::AnimationOption
49 49
50 50 For enabling/disabling animations. Defaults to NoAnimation.
51 51
52 52 \value NoAnimation
53 53 \value GridAxisAnimations
54 54 \value SeriesAnimations
55 55 \value AllAnimations
56 56 */
57 57
58 58 /*!
59 59 \class QChart
60 60 \brief QtCommercial chart API.
61 61
62 62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 63 representation of different types of series and other chart related objects like
64 64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 65 convenience class QChartView instead of QChart.
66 66 \sa QChartView
67 67 */
68 68
69 69 /*!
70 70 \property QChart::animationOptions
71 71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 72 */
73 73
74 74 /*!
75 75 \property QChart::backgroundVisible
76 76 Whether the chart background is visible or not.
77 77 \sa setBackgroundBrush(), setBackgroundPen()
78 78 */
79 79
80 80 /*!
81 81 \property QChart::dropShadowEnabled
82 82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 84 */
85 85
86 86 /*!
87 87 \property QChart::margins
88 88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
89 89 */
90 90
91 91 /*!
92 92 \property QChart::theme
93 93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 95 different themes.
96 96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 97 */
98 98
99 99 /*!
100 100 \property QChart::title
101 101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 102 */
103 103
104 104 /*!
105 105 \fn void QChart::marginsChanged(QRectF newMargins)
106 106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 107 modify axes or hide/show legend.
108 108 */
109 109
110 110 /*!
111 111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 112 */
113 113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 114 d_ptr(new QChartPrivate())
115 115 {
116 116 d_ptr->m_dataset = new ChartDataSet(this);
117 117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 118 d_ptr->createConnections();
119 119 d_ptr->m_legend = new LegendScroller(this);
120 120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 122 setLayout(d_ptr->m_presenter->layout());
123 123 }
124 124
125 125 /*!
126 126 Destroys the object and it's children, like series and axis objects added to it.
127 127 */
128 128 QChart::~QChart()
129 129 {
130 130 //delete first presenter , since this is a root of all the graphical items
131 131 setLayout(0);
132 132 delete d_ptr->m_presenter;
133 133 d_ptr->m_presenter=0;
134 134 }
135 135
136 136 /*!
137 137 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
138 138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 139 the y axis).
140 140
141 141 \sa removeSeries(), removeAllSeries()
142 142 */
143 143 void QChart::addSeries(QAbstractSeries *series)
144 144 {
145 145 Q_ASSERT(series);
146 146 d_ptr->m_dataset->addSeries(series);
147 147 }
148 148
149 149 /*!
150 150 Removes the \a series specified in a perameter from the QChartView.
151 151 It releses its ownership of the specified QChartSeries object.
152 152 It does not delete the pointed QChartSeries data object
153 153 \sa addSeries(), removeAllSeries()
154 154 */
155 155 void QChart::removeSeries(QAbstractSeries *series)
156 156 {
157 157 Q_ASSERT(series);
158 158 d_ptr->m_dataset->removeSeries(series);
159 159 }
160 160
161 161 /*!
162 162 Removes all the QChartSeries that have been added to the QChartView
163 163 It also deletes the pointed QChartSeries data objects
164 164 \sa addSeries(), removeSeries()
165 165 */
166 166 void QChart::removeAllSeries()
167 167 {
168 168 d_ptr->m_dataset->removeAllSeries();
169 169 }
170 170
171 171 /*!
172 172 Sets the \a brush that is used for painting the background of the chart area.
173 173 */
174 174 void QChart::setBackgroundBrush(const QBrush& brush)
175 175 {
176 176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 177 }
178 178
179 179 /*!
180 180 Gets the brush that is used for painting the background of the chart area.
181 181 */
182 182 QBrush QChart::backgroundBrush() const
183 183 {
184 184 return d_ptr->m_presenter->backgroundBrush();
185 185 }
186 186
187 187 /*!
188 188 Sets the \a pen that is used for painting the background of the chart area.
189 189 */
190 190 void QChart::setBackgroundPen(const QPen& pen)
191 191 {
192 192 d_ptr->m_presenter->setBackgroundPen(pen);
193 193 }
194 194
195 195 /*!
196 196 Gets the pen that is used for painting the background of the chart area.
197 197 */
198 198 QPen QChart::backgroundPen() const
199 199 {
200 200 return d_ptr->m_presenter->backgroundPen();
201 201 }
202 202
203 203 /*!
204 204 Sets the chart \a title. The description text that is drawn above the chart.
205 205 */
206 206 void QChart::setTitle(const QString& title)
207 207 {
208 208 d_ptr->m_presenter->setTitle(title);
209 209 }
210 210
211 211 /*!
212 212 Returns the chart title. The description text that is drawn above the chart.
213 213 */
214 214 QString QChart::title() const
215 215 {
216 216 return d_ptr->m_presenter->title();
217 217 }
218 218
219 219 /*!
220 220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 221 */
222 222 void QChart::setTitleFont(const QFont& font)
223 223 {
224 224 d_ptr->m_presenter->setTitleFont(font);
225 225 }
226 226
227 227 /*!
228 228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 229 */
230 230 QFont QChart::titleFont() const
231 231 {
232 232 return d_ptr->m_presenter->titleFont();
233 233 }
234 234
235 235 /*!
236 236 Sets the \a brush used for rendering the title text.
237 237 */
238 238 void QChart::setTitleBrush(const QBrush &brush)
239 239 {
240 240 d_ptr->m_presenter->setTitleBrush(brush);
241 241 }
242 242
243 243 /*!
244 244 Returns the brush used for rendering the title text.
245 245 */
246 246 QBrush QChart::titleBrush() const
247 247 {
248 248 return d_ptr->m_presenter->titleBrush();
249 249 }
250 250
251 251 void QChart::setTheme(QChart::ChartTheme theme)
252 252 {
253 253 d_ptr->m_presenter->setTheme(theme);
254 254 }
255 255
256 256 QChart::ChartTheme QChart::theme() const
257 257 {
258 258 return d_ptr->m_presenter->theme();
259 259 }
260 260
261 261 /*!
262 262 Zooms in the view by a factor of 2
263 263 */
264 264 void QChart::zoomIn()
265 265 {
266 266 d_ptr->m_presenter->zoomIn(2.0);
267 267 }
268 268
269 269 /*!
270 270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 271 */
272 272 void QChart::zoomIn(const QRectF& rect)
273 273 {
274 274 if (!rect.isValid()) return;
275 275 d_ptr->m_presenter->zoomIn(rect);
276 276 }
277 277
278 278 /*!
279 279 Restores the view zoom level to the previous one.
280 280 */
281 281 void QChart::zoomOut()
282 282 {
283 283 d_ptr->m_presenter->zoomOut(2.0);
284 284 }
285 285
286 286 /*!
287 287 Zooms in the view by a \a factor.
288 288
289 289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 290 */
291 291 void QChart::zoom(qreal factor)
292 292 {
293 293 if (qFuzzyIsNull(factor))
294 294 return;
295 295
296 296 if (qFuzzyCompare(factor, 1.0))
297 297 return;
298 298
299 299 if (factor < 0)
300 300 return;
301 301
302 302 if (factor > 1.0)
303 303 d_ptr->m_presenter->zoomIn(factor);
304 304 else
305 305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 306 }
307 307
308 308 /*!
309 309 Returns the pointer to the x axis object of the chart
310 310 */
311 311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 312 {
313 313 return d_ptr->m_dataset->axisX(series);
314 314 }
315 315
316 316 /*!
317 317 Returns the pointer to the y axis object of the \a series
318 318 If no \a series is provided then default Y axis of the chart is returned.
319 319 */
320 320 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
321 321 {
322 322 return d_ptr->m_dataset->axisY(series);
323 323 }
324 324
325 325 /*!
326 326 Returns the legend object of the chart. Ownership stays in chart.
327 327 */
328 328 QLegend* QChart::legend() const
329 329 {
330 330 return d_ptr->m_legend;
331 331 }
332 332
333 333 /*!
334 334 Returns the rect that contains information about margins (distance between chart widget edge and axes).
335 335 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
336 336 */
337 337 QRectF QChart::margins() const
338 338 {
339 339 return d_ptr->m_presenter->margins();
340 340 }
341 341
342 342 /*!
343 343 Sets animation \a options for the chart
344 344 */
345 345
346 346 void QChart::setAnimationOptions(AnimationOptions options)
347 347 {
348 348 d_ptr->m_presenter->setAnimationOptions(options);
349 349 }
350 350
351 351 QChart::AnimationOptions QChart::animationOptions() const
352 352 {
353 353 return d_ptr->m_presenter->animationOptions();
354 354 }
355 355
356 356 /*!
357 357 Scrolls the visible area of the chart by the distance defined in the \a delta.
358 358 */
359 359 void QChart::scroll(qreal dx, qreal dy)
360 360 {
361 361 d_ptr->m_presenter->scroll(dx, dy);
362 362 }
363 363
364 364 void QChart::setBackgroundVisible(bool visible)
365 365 {
366 366 d_ptr->m_presenter->setBackgroundVisible(visible);
367 367 }
368 368
369 369 bool QChart::isBackgroundVisible() const
370 370 {
371 371 return d_ptr->m_presenter->isBackgroundVisible();
372 372 }
373 373
374 374 void QChart::setDropShadowEnabled(bool enabled)
375 375 {
376 376 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
377 377 }
378 378
379 379 bool QChart::isDropShadowEnabled() const
380 380 {
381 381 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
382 382 }
383 383
384 384 /*!
385 385 Returns all the series that are added to the chart.
386 386
387 387 \sa addSeries(), removeSeries(), removeAllSeries()
388 388 */
389 389 QList<QAbstractSeries*> QChart::series() const
390 390 {
391 391 return d_ptr->m_dataset->series();
392 392 }
393 393
394 394 void QChart::setMarginsMinimum(const QRectF& margins)
395 395 {
396 396 d_ptr->m_presenter->setMarginsMinimum(margins);
397 397 }
398 398
399 399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
400 400 {
401 Q_UNUSED(series);
402 Q_UNUSED(axis);
401 // Q_UNUSED(series);
402 // Q_UNUSED(axis);
403 d_ptr->m_dataset->setAxisX(series, axis);
403 404 }
404 405
405 406 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
406 407 {
407 Q_UNUSED(series);
408 Q_UNUSED(axis);
408 // Q_UNUSED(series);
409 // Q_UNUSED(axis);
410 d_ptr->m_dataset->setAxisY(series, axis);
409 411 }
410 412
411 413 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
412 414
413 415 QChartPrivate::QChartPrivate():
414 416 m_legend(0),
415 417 m_dataset(0),
416 418 m_presenter(0)
417 419 {
418 420
419 421 }
420 422
421 423 QChartPrivate::~QChartPrivate()
422 424 {
423 425
424 426 }
425 427
426 428 void QChartPrivate::createConnections()
427 429 {
428 430 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
429 431 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
430 432 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
431 433 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
432 434 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
433 435 }
434 436
435 437 #include "moc_qchart.cpp"
436 438
437 439 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now