##// END OF EJS Templates
Bugfix missing min max intialization when axis added to domain
Michal Klocek -
r442:6c610328d6c5
parent child
Show More
@@ -1,288 +1,291
1 #include "chartdataset_p.h"
1 #include "chartdataset_p.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 //series
3 //series
4 #include "qlineseries.h"
4 #include "qlineseries.h"
5 #include "qareaseries.h"
5 #include "qareaseries.h"
6 #include "qbarseries.h"
6 #include "qbarseries.h"
7 #include "qstackedbarseries.h"
7 #include "qstackedbarseries.h"
8 #include "qpercentbarseries.h"
8 #include "qpercentbarseries.h"
9 #include "qpieseries.h"
9 #include "qpieseries.h"
10 #include "qscatterseries.h"
10 #include "qscatterseries.h"
11 #include "qsplineseries.h"
11 #include "qsplineseries.h"
12
12
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
14
15 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
15 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
16 m_axisX(new QChartAxis(this)),
16 m_axisX(new QChartAxis(this)),
17 m_axisY(new QChartAxis(this)),
17 m_axisY(new QChartAxis(this)),
18 m_domainIndex(0),
18 m_domainIndex(0),
19 m_axisXInitialized(false)
19 m_axisXInitialized(false)
20 {
20 {
21 }
21 }
22
22
23 ChartDataSet::~ChartDataSet()
23 ChartDataSet::~ChartDataSet()
24 {
24 {
25 }
25 }
26
26
27 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
27 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
28 {
28 {
29 if(axisY==0) axisY = m_axisY;
29 if(axisY==0) axisY = m_axisY;
30
30
31 QChartAxis* axis = m_seriesAxisMap.value(series);
31 QChartAxis* axis = m_seriesAxisMap.value(series);
32
32
33 if(axis) {
33 if(axis) {
34 qWarning() << "Can not add series. Series already on the chart";
34 qWarning() << "Can not add series. Series already on the chart";
35 return;
35 return;
36 }
36 }
37
37
38 if(!series->parent()){
38 if(!series->parent()){
39 series->setParent(this); // take ownership
39 series->setParent(this); // take ownership
40 };
40 };
41
41
42 if(!axisY->parent()){
42 if(!axisY->parent()){
43 axisY->setParent(this); // take ownership
43 axisY->setParent(this); // take ownership
44 }
44 }
45
45
46 Domain* domain = m_axisDomainMap.value(axisY);
46 Domain* domain = m_axisDomainMap.value(axisY);
47
47
48 if(!domain) {
48 if(!domain) {
49 domain = new Domain();
49 domain = new Domain();
50
50
51 QObject::connect(axisY,SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeXChanged(qreal,qreal)));
51 QObject::connect(axisY,SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeXChanged(qreal,qreal)));
52 QObject::connect(axisX(),SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeYChanged(qreal,qreal)));
52 QObject::connect(axisX(),SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeYChanged(qreal,qreal)));
53
53 //initialize
54 qDebug()<<axisX()->min()<<axisX()->max();
55 domain->handleAxisRangeYChanged(axisY->min(),axisY->max());
56 domain->handleAxisRangeXChanged(axisX()->min(),axisX()->max());
54 m_axisDomainMap.insert(axisY,domain);
57 m_axisDomainMap.insert(axisY,domain);
55 emit axisAdded(axisY,domain);
58 emit axisAdded(axisY,domain);
56 }
59 }
57
60
58 if(!m_axisXInitialized){
61 if(!m_axisXInitialized){
59 emit axisAdded(axisX(),domain);
62 emit axisAdded(axisX(),domain);
60 m_axisXInitialized=true;
63 m_axisXInitialized=true;
61 }
64 }
62
65
63 calculateDomain(series,domain);
66 calculateDomain(series,domain);
64
67
65 m_seriesAxisMap.insert(series,axisY);
68 m_seriesAxisMap.insert(series,axisY);
66 emit seriesAdded(series,domain);
69 emit seriesAdded(series,domain);
67
70
68 }
71 }
69
72
70 void ChartDataSet::removeSeries(QSeries* series)
73 void ChartDataSet::removeSeries(QSeries* series)
71 {
74 {
72
75
73 QChartAxis* axis = m_seriesAxisMap.value(series);
76 QChartAxis* axis = m_seriesAxisMap.value(series);
74
77
75 if(!axis){
78 if(!axis){
76 qWarning()<<"Can not remove series. Series not found on the chart.";
79 qWarning()<<"Can not remove series. Series not found on the chart.";
77 return;
80 return;
78 }
81 }
79 emit seriesRemoved(series);
82 emit seriesRemoved(series);
80 m_seriesAxisMap.remove(series);
83 m_seriesAxisMap.remove(series);
81
84
82 if(series->parent()==this){
85 if(series->parent()==this){
83 delete series;
86 delete series;
84 series=0;
87 series=0;
85 }
88 }
86
89
87 QList<QChartAxis*> axes = m_seriesAxisMap.values();
90 QList<QChartAxis*> axes = m_seriesAxisMap.values();
88
91
89 int i = axes.indexOf(axis);
92 int i = axes.indexOf(axis);
90
93
91 if(i==-1){
94 if(i==-1){
92 Domain* domain = m_axisDomainMap.take(axis);
95 Domain* domain = m_axisDomainMap.take(axis);
93 emit axisRemoved(axis);
96 emit axisRemoved(axis);
94 delete domain;
97 delete domain;
95 }
98 }
96
99
97 if(m_seriesAxisMap.values().size()==0)
100 if(m_seriesAxisMap.values().size()==0)
98 {
101 {
99 m_axisXInitialized=false;
102 m_axisXInitialized=false;
100 emit axisRemoved(axisX());
103 emit axisRemoved(axisX());
101 }
104 }
102 }
105 }
103
106
104 void ChartDataSet::removeAllSeries()
107 void ChartDataSet::removeAllSeries()
105 {
108 {
106
109
107 QList<QSeries*> series = m_seriesAxisMap.keys();
110 QList<QSeries*> series = m_seriesAxisMap.keys();
108
111
109 foreach(QSeries* s , series) {
112 foreach(QSeries* s , series) {
110 removeSeries(s);
113 removeSeries(s);
111 }
114 }
112
115
113 Q_ASSERT(m_seriesAxisMap.count()==0);
116 Q_ASSERT(m_seriesAxisMap.count()==0);
114 Q_ASSERT(m_axisDomainMap.count()==0);
117 Q_ASSERT(m_axisDomainMap.count()==0);
115
118
116 }
119 }
117
120
118 //to be removed with PIMPL
121 //to be removed with PIMPL
119 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const
122 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const
120 {
123 {
121 switch(series->type())
124 switch(series->type())
122 {
125 {
123 case QSeries::SeriesTypeLine: {
126 case QSeries::SeriesTypeLine: {
124
127
125 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
128 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
126
129
127 for (int i = 0; i < lineSeries->count(); i++)
130 for (int i = 0; i < lineSeries->count(); i++)
128 {
131 {
129 qreal x = lineSeries->x(i);
132 qreal x = lineSeries->x(i);
130 qreal y = lineSeries->y(i);
133 qreal y = lineSeries->y(i);
131 domain->setMinX(qMin(domain->minX(),x));
134 domain->setMinX(qMin(domain->minX(),x));
132 domain->setMinY(qMin(domain->minY(),y));
135 domain->setMinY(qMin(domain->minY(),y));
133 domain->setMaxX(qMax(domain->maxX(),x));
136 domain->setMaxX(qMax(domain->maxX(),x));
134 domain->setMaxY(qMax(domain->maxY(),y));
137 domain->setMaxY(qMax(domain->maxY(),y));
135 }
138 }
136 break;
139 break;
137 }
140 }
138 case QSeries::SeriesTypeArea: {
141 case QSeries::SeriesTypeArea: {
139
142
140 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
143 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
141
144
142 QLineSeries* upperSeries = areaSeries->upperSeries();
145 QLineSeries* upperSeries = areaSeries->upperSeries();
143 QLineSeries* lowerSeries = areaSeries->lowerSeries();
146 QLineSeries* lowerSeries = areaSeries->lowerSeries();
144
147
145 for (int i = 0; i < upperSeries->count(); i++)
148 for (int i = 0; i < upperSeries->count(); i++)
146 {
149 {
147 qreal x = upperSeries->x(i);
150 qreal x = upperSeries->x(i);
148 qreal y = upperSeries->y(i);
151 qreal y = upperSeries->y(i);
149 domain->setMinX(qMin(domain->minX(),x));
152 domain->setMinX(qMin(domain->minX(),x));
150 domain->setMinY(qMin(domain->minY(),y));
153 domain->setMinY(qMin(domain->minY(),y));
151 domain->setMaxX(qMax(domain->maxX(),x));
154 domain->setMaxX(qMax(domain->maxX(),x));
152 domain->setMaxY(qMax(domain->maxY(),y));
155 domain->setMaxY(qMax(domain->maxY(),y));
153 }
156 }
154 if(lowerSeries) {
157 if(lowerSeries) {
155 for (int i = 0; i < lowerSeries->count(); i++)
158 for (int i = 0; i < lowerSeries->count(); i++)
156 {
159 {
157 qreal x = lowerSeries->x(i);
160 qreal x = lowerSeries->x(i);
158 qreal y = lowerSeries->y(i);
161 qreal y = lowerSeries->y(i);
159 domain->setMinX(qMin(domain->minX(),x));
162 domain->setMinX(qMin(domain->minX(),x));
160 domain->setMinY(qMin(domain->minY(),y));
163 domain->setMinY(qMin(domain->minY(),y));
161 domain->setMaxX(qMax(domain->maxX(),x));
164 domain->setMaxX(qMax(domain->maxX(),x));
162 domain->setMaxY(qMax(domain->maxY(),y));
165 domain->setMaxY(qMax(domain->maxY(),y));
163 }}
166 }}
164 break;
167 break;
165 }
168 }
166 case QSeries::SeriesTypeBar: {
169 case QSeries::SeriesTypeBar: {
167 qDebug() << "QChartSeries::SeriesTypeBar";
170 qDebug() << "QChartSeries::SeriesTypeBar";
168 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
171 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
169 qreal x = barSeries->categoryCount();
172 qreal x = barSeries->categoryCount();
170 qreal y = barSeries->max();
173 qreal y = barSeries->max();
171 domain->setMinX(qMin(domain->minX(),x));
174 domain->setMinX(qMin(domain->minX(),x));
172 domain->setMinY(qMin(domain->minY(),y));
175 domain->setMinY(qMin(domain->minY(),y));
173 domain->setMaxX(qMax(domain->maxX(),x));
176 domain->setMaxX(qMax(domain->maxX(),x));
174 domain->setMaxY(qMax(domain->maxY(),y));
177 domain->setMaxY(qMax(domain->maxY(),y));
175 break;
178 break;
176 }
179 }
177 case QSeries::SeriesTypeStackedBar: {
180 case QSeries::SeriesTypeStackedBar: {
178 qDebug() << "QChartSeries::SeriesTypeStackedBar";
181 qDebug() << "QChartSeries::SeriesTypeStackedBar";
179
182
180 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
183 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
181 qreal x = stackedBarSeries->categoryCount();
184 qreal x = stackedBarSeries->categoryCount();
182 qreal y = stackedBarSeries->maxCategorySum();
185 qreal y = stackedBarSeries->maxCategorySum();
183 domain->setMinX(qMin(domain->minX(),x));
186 domain->setMinX(qMin(domain->minX(),x));
184 domain->setMinY(qMin(domain->minY(),y));
187 domain->setMinY(qMin(domain->minY(),y));
185 domain->setMaxX(qMax(domain->maxX(),x));
188 domain->setMaxX(qMax(domain->maxX(),x));
186 domain->setMaxY(qMax(domain->maxY(),y));
189 domain->setMaxY(qMax(domain->maxY(),y));
187 break;
190 break;
188 }
191 }
189 case QSeries::SeriesTypePercentBar: {
192 case QSeries::SeriesTypePercentBar: {
190 qDebug() << "QChartSeries::SeriesTypePercentBar";
193 qDebug() << "QChartSeries::SeriesTypePercentBar";
191
194
192 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
195 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
193 qreal x = percentBarSeries->categoryCount();
196 qreal x = percentBarSeries->categoryCount();
194 domain->setMinX(qMin(domain->minX(),x));
197 domain->setMinX(qMin(domain->minX(),x));
195 domain->setMinY(0);
198 domain->setMinY(0);
196 domain->setMaxX(qMax(domain->maxX(),x));
199 domain->setMaxX(qMax(domain->maxX(),x));
197 domain->setMaxY(100);
200 domain->setMaxY(100);
198 break;
201 break;
199 }
202 }
200
203
201 case QSeries::SeriesTypePie: {
204 case QSeries::SeriesTypePie: {
202 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
205 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
203 // TODO: domain stuff
206 // TODO: domain stuff
204 break;
207 break;
205 }
208 }
206
209
207 case QSeries::SeriesTypeScatter: {
210 case QSeries::SeriesTypeScatter: {
208 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
211 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
209 Q_ASSERT(scatterSeries);
212 Q_ASSERT(scatterSeries);
210 foreach (QPointF point, scatterSeries->data()) {
213 foreach (QPointF point, scatterSeries->data()) {
211 domain->setMinX(qMin(domain->minX(), point.x()));
214 domain->setMinX(qMin(domain->minX(), point.x()));
212 domain->setMinY(qMax(domain->maxX(), point.x()));
215 domain->setMinY(qMax(domain->maxX(), point.x()));
213 domain->setMaxX(qMin(domain->minY(), point.y()));
216 domain->setMaxX(qMin(domain->minY(), point.y()));
214 domain->setMaxY(qMax(domain->maxY(), point.y()));
217 domain->setMaxY(qMax(domain->maxY(), point.y()));
215 }
218 }
216 break;
219 break;
217 }
220 }
218
221
219 case QSeries::SeriesTypeSpline: {
222 case QSeries::SeriesTypeSpline: {
220 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
223 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
221
224
222 for (int i = 0; i < splineSeries->count(); i++)
225 for (int i = 0; i < splineSeries->count(); i++)
223 {
226 {
224 qreal x = splineSeries->x(i);
227 qreal x = splineSeries->x(i);
225 qreal y = splineSeries->y(i);
228 qreal y = splineSeries->y(i);
226 domain->setMinX(qMin(domain->minX(),x));
229 domain->setMinX(qMin(domain->minX(),x));
227 domain->setMinY(qMin(domain->minY(),y));
230 domain->setMinY(qMin(domain->minY(),y));
228 domain->setMaxX(qMax(domain->maxX(),x));
231 domain->setMaxX(qMax(domain->maxX(),x));
229 domain->setMaxY(qMax(domain->maxY(),y));
232 domain->setMaxY(qMax(domain->maxY(),y));
230 }
233 }
231 break;
234 break;
232 }
235 }
233
236
234 default: {
237 default: {
235 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
238 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
236 return;
239 return;
237 break;
240 break;
238 }
241 }
239
242
240 }
243 }
241 }
244 }
242
245
243 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
246 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
244 {
247 {
245 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
248 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
246 while (i.hasNext()) {
249 while (i.hasNext()) {
247 i.next();
250 i.next();
248 i.value()->zoomIn(rect,size);
251 i.value()->zoomIn(rect,size);
249 }
252 }
250 }
253 }
251
254
252 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
255 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
253 {
256 {
254 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
257 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
255 while (i.hasNext()) {
258 while (i.hasNext()) {
256 i.next();
259 i.next();
257 i.value()->zoomOut(rect,size);
260 i.value()->zoomOut(rect,size);
258 }
261 }
259 }
262 }
260
263
261 QChartAxis* ChartDataSet::axisY(QSeries* series) const
264 QChartAxis* ChartDataSet::axisY(QSeries* series) const
262 {
265 {
263 if(series == 0) return m_axisY;
266 if(series == 0) return m_axisY;
264 return m_seriesAxisMap.value(series);
267 return m_seriesAxisMap.value(series);
265 }
268 }
266
269
267 Domain* ChartDataSet::domain(QSeries* series) const
270 Domain* ChartDataSet::domain(QSeries* series) const
268 {
271 {
269 QChartAxis* axis = m_seriesAxisMap.value(series);
272 QChartAxis* axis = m_seriesAxisMap.value(series);
270 if(axis){
273 if(axis){
271 return m_axisDomainMap.value(axis);
274 return m_axisDomainMap.value(axis);
272 }else
275 }else
273 return 0;
276 return 0;
274 }
277 }
275
278
276 Domain* ChartDataSet::domain(QChartAxis* axis) const
279 Domain* ChartDataSet::domain(QChartAxis* axis) const
277 {
280 {
278 return m_axisDomainMap.value(axis);
281 return m_axisDomainMap.value(axis);
279 }
282 }
280
283
281 QChartAxis* ChartDataSet::axis(QSeries* series) const
284 QChartAxis* ChartDataSet::axis(QSeries* series) const
282 {
285 {
283 return m_seriesAxisMap.value(series);
286 return m_seriesAxisMap.value(series);
284 }
287 }
285
288
286 #include "moc_chartdataset_p.cpp"
289 #include "moc_chartdataset_p.cpp"
287
290
288 QTCOMMERCIALCHART_END_NAMESPACE
291 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,396 +1,402
1 #include "qchartaxis.h"
1 #include "qchartaxis.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QChartAxis
6 \class QChartAxis
7 \brief The QChartAxis class is used for manipulating chart's axis
7 \brief The QChartAxis class is used for manipulating chart's axis
8 and for adding optional axes to the chart.
8 and for adding optional axes to the chart.
9 \mainclass
9 \mainclass
10
10
11 There is only one x Axis, however there can be multiple y axes.
11 There is only one x Axis, however there can be multiple y axes.
12 Each chart series can be bound to exactly one Y axis and the share common X axis.
12 Each chart series can be bound to exactly one Y axis and the share common X axis.
13 Axis can be setup to show axis line with ticks, gird lines and shades.
13 Axis can be setup to show axis line with ticks, gird lines and shades.
14
14
15 */
15 */
16
16
17 /*!
17 /*!
18 \fn bool QChartAxis::isAxisVisible() const
18 \fn bool QChartAxis::isAxisVisible() const
19 \brief Returns if axis is visible
19 \brief Returns if axis is visible
20 \sa setAxisVisible()
20 \sa setAxisVisible()
21 */
21 */
22
22
23 /*!
23 /*!
24 \fn QPen QChartAxis::axisPen() const
24 \fn QPen QChartAxis::axisPen() const
25 \brief Returns pen used to draw axis and ticks.
25 \brief Returns pen used to draw axis and ticks.
26 \sa setAxisPen()
26 \sa setAxisPen()
27 */
27 */
28
28
29
29
30 /*!
30 /*!
31 \fn bool QChartAxis::isGridVisible() const
31 \fn bool QChartAxis::isGridVisible() const
32 \brief Returns if grid is visible
32 \brief Returns if grid is visible
33 \sa setGridVisible()
33 \sa setGridVisible()
34 */
34 */
35
35
36 /*!
36 /*!
37 \fn QPen QChartAxis::gridPen() const
37 \fn QPen QChartAxis::gridPen() const
38 \brief Returns pen used to draw grid.
38 \brief Returns pen used to draw grid.
39 \sa setGridPen()
39 \sa setGridPen()
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn bool QChartAxis::labelsVisible() const
43 \fn bool QChartAxis::labelsVisible() const
44 \brief Returns if grid is visible
44 \brief Returns if grid is visible
45 \sa setLabelsVisible()
45 \sa setLabelsVisible()
46 */
46 */
47
47
48 /*!
48 /*!
49 \fn QPen QChartAxis::labelsPen() const
49 \fn QPen QChartAxis::labelsPen() const
50 \brief Returns the pen used to labels.
50 \brief Returns the pen used to labels.
51 \sa setLabelsPen()
51 \sa setLabelsPen()
52 */
52 */
53
53
54 /*!
54 /*!
55 \fn QBrush QChartAxis::labelsBrush() const
55 \fn QBrush QChartAxis::labelsBrush() const
56 \brief Returns brush used to draw labels.
56 \brief Returns brush used to draw labels.
57 \sa setLabelsBrush()
57 \sa setLabelsBrush()
58 */
58 */
59
59
60 /*!
60 /*!
61 \fn QFont QChartAxis::labelsFont() const
61 \fn QFont QChartAxis::labelsFont() const
62 \brief Returns font used to draw labels.
62 \brief Returns font used to draw labels.
63 \sa setLabelsFont()
63 \sa setLabelsFont()
64 */
64 */
65
65
66 /*!
66 /*!
67 \fn QFont QChartAxis::labelsAngle() const
67 \fn QFont QChartAxis::labelsAngle() const
68 \brief Returns angle used to draw labels.
68 \brief Returns angle used to draw labels.
69 \sa setLabelsAngle()
69 \sa setLabelsAngle()
70 */
70 */
71
71
72 /*!
72 /*!
73 \fn bool QChartAxis::shadesVisible() const
73 \fn bool QChartAxis::shadesVisible() const
74 \brief Returns if shades are visible.
74 \brief Returns if shades are visible.
75 \sa setShadesVisible()
75 \sa setShadesVisible()
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn qreal QChartAxis::shadesOpacity() const
79 \fn qreal QChartAxis::shadesOpacity() const
80 \brief Returns opacity of shades.
80 \brief Returns opacity of shades.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn QPen QChartAxis::shadesPen() const
84 \fn QPen QChartAxis::shadesPen() const
85 \brief Returns pen used to draw shades.
85 \brief Returns pen used to draw shades.
86 \sa setShadesPen()
86 \sa setShadesPen()
87 */
87 */
88
88
89 /*!
89 /*!
90 \fn QBrush QChartAxis::shadesBrush() const
90 \fn QBrush QChartAxis::shadesBrush() const
91 \brief Returns brush used to draw shades.
91 \brief Returns brush used to draw shades.
92 \sa setShadesBrush()
92 \sa setShadesBrush()
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn qreal QChartAxis::min() const
96 \fn qreal QChartAxis::min() const
97 \brief Returns minimum value on the axis.
97 \brief Returns minimum value on the axis.
98 \sa setMin()
98 \sa setMin()
99 */
99 */
100
100
101 /*!
101 /*!
102 \fn qreal QChartAxis::max() const
102 \fn qreal QChartAxis::max() const
103 \brief Returns maximim value on the axis.
103 \brief Returns maximim value on the axis.
104 \sa setMax()
104 \sa setMax()
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QChartAxis::minChanged(qreal min)
108 \fn void QChartAxis::minChanged(qreal min)
109 \brief Axis emits signal when \a min of axis has changed.
109 \brief Axis emits signal when \a min of axis has changed.
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QChartAxis::maxChanged(qreal max)
113 \fn void QChartAxis::maxChanged(qreal max)
114 \brief Axis emits signal when \a max of axis has changed.
114 \brief Axis emits signal when \a max of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
118 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
119 \brief Axis emits signal when \a min or \a max of axis has changed.
119 \brief Axis emits signal when \a min or \a max of axis has changed.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn int QChartAxis::ticksCount() const
123 \fn int QChartAxis::ticksCount() const
124 \brief Return number of ticks on the axis
124 \brief Return number of ticks on the axis
125 \sa setTicksCount()
125 \sa setTicksCount()
126 */
126 */
127
127
128 /*!
128 /*!
129 \fn void QChartAxis::updated()
129 \fn void QChartAxis::updated()
130 \brief \internal
130 \brief \internal
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
134 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
135 \brief \internal \a min \a max
135 \brief \internal \a min \a max
136 */
136 */
137
137
138 /*!
138 /*!
139 Constructs new axis object which is a child of \a parent. Ownership is taken by
139 Constructs new axis object which is a child of \a parent. Ownership is taken by
140 QChatView or QChart when axis added.
140 QChatView or QChart when axis added.
141 */
141 */
142
142
143 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
143 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
144 m_axisVisible(true),
144 m_axisVisible(true),
145 m_gridVisible(true),
145 m_gridVisible(true),
146 m_labelsVisible(true),
146 m_labelsVisible(true),
147 m_labelsAngle(0),
147 m_labelsAngle(0),
148 m_shadesVisible(true),
148 m_shadesVisible(true),
149 m_shadesOpacity(1.0),
149 m_shadesOpacity(1.0),
150 m_min(0),
150 m_min(0),
151 m_max(0),
151 m_max(0),
152 m_ticksCount(5)
152 m_ticksCount(5)
153 {
153 {
154
154
155 }
155 }
156
156
157 /*!
157 /*!
158 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
158 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
159 */
159 */
160
160
161 QChartAxis::~QChartAxis()
161 QChartAxis::~QChartAxis()
162 {
162 {
163 }
163 }
164
164
165 /*!
165 /*!
166 Sets \a pen used to draw axis line and ticks.
166 Sets \a pen used to draw axis line and ticks.
167 */
167 */
168 void QChartAxis::setAxisPen(const QPen& pen)
168 void QChartAxis::setAxisPen(const QPen& pen)
169 {
169 {
170 if (pen != m_axisPen) {
170 if (pen != m_axisPen) {
171 m_axisPen=pen;
171 m_axisPen=pen;
172 emit updated();
172 emit updated();
173 }
173 }
174 }
174 }
175
175
176 /*!
176 /*!
177 Sets if axis and ticks are \a visible.
177 Sets if axis and ticks are \a visible.
178 */
178 */
179 void QChartAxis::setAxisVisible(bool visible)
179 void QChartAxis::setAxisVisible(bool visible)
180 {
180 {
181 if (m_axisVisible!=visible) {
181 if (m_axisVisible!=visible) {
182 m_axisVisible=visible;
182 m_axisVisible=visible;
183 emit updated();
183 emit updated();
184 }
184 }
185 }
185 }
186
186
187 /*!
187 /*!
188 Sets if grid is \a visible.
188 Sets if grid is \a visible.
189 */
189 */
190 void QChartAxis::setGridVisible(bool visible)
190 void QChartAxis::setGridVisible(bool visible)
191 {
191 {
192 if (m_gridVisible!=visible) {
192 if (m_gridVisible!=visible) {
193 m_gridVisible=visible;
193 m_gridVisible=visible;
194 emit updated();
194 emit updated();
195 }
195 }
196 }
196 }
197
197
198 /*!
198 /*!
199 Sets \a pen used to draw grid.
199 Sets \a pen used to draw grid.
200 */
200 */
201 void QChartAxis::setGridPen(const QPen& pen)
201 void QChartAxis::setGridPen(const QPen& pen)
202 {
202 {
203 if (m_gridPen!=pen) {
203 if (m_gridPen!=pen) {
204 m_gridPen=pen;
204 m_gridPen=pen;
205 emit updated();
205 emit updated();
206 }
206 }
207 }
207 }
208
208
209 /*!
209 /*!
210 Sets if axis' labels are \a visible.
210 Sets if axis' labels are \a visible.
211 */
211 */
212 void QChartAxis::setLabelsVisible(bool visible)
212 void QChartAxis::setLabelsVisible(bool visible)
213 {
213 {
214 if(m_labelsVisible!=visible) {
214 if(m_labelsVisible!=visible) {
215 m_labelsVisible=visible;
215 m_labelsVisible=visible;
216 emit updated();
216 emit updated();
217 }
217 }
218 }
218 }
219
219
220 /*!
220 /*!
221 Sets \a pen used to draw labels.
221 Sets \a pen used to draw labels.
222 */
222 */
223 void QChartAxis::setLabelsPen(const QPen& pen)
223 void QChartAxis::setLabelsPen(const QPen& pen)
224 {
224 {
225 if(m_labelsPen!=pen) {
225 if(m_labelsPen!=pen) {
226 m_labelsPen=pen;
226 m_labelsPen=pen;
227 emit updated();
227 emit updated();
228 }
228 }
229 }
229 }
230
230
231 /*!
231 /*!
232 Sets \a brush used to draw labels.
232 Sets \a brush used to draw labels.
233 */
233 */
234 void QChartAxis::setLabelsBrush(const QBrush& brush)
234 void QChartAxis::setLabelsBrush(const QBrush& brush)
235 {
235 {
236 if(m_labelsBrush!=brush) {
236 if(m_labelsBrush!=brush) {
237 m_labelsBrush=brush;
237 m_labelsBrush=brush;
238 emit updated();
238 emit updated();
239 }
239 }
240 }
240 }
241
241
242 /*!
242 /*!
243 Sets \a font used to draw labels.
243 Sets \a font used to draw labels.
244 */
244 */
245 void QChartAxis::setLabelsFont(const QFont& font)
245 void QChartAxis::setLabelsFont(const QFont& font)
246 {
246 {
247 if(m_labelsFont!=font) {
247 if(m_labelsFont!=font) {
248 m_labelsFont=font;
248 m_labelsFont=font;
249 emit updated();
249 emit updated();
250 }
250 }
251 }
251 }
252
252
253 /*!
253 /*!
254 Sets \a angle for all the labels on given axis.
254 Sets \a angle for all the labels on given axis.
255 */
255 */
256 void QChartAxis::setLabelsAngle(int angle)
256 void QChartAxis::setLabelsAngle(int angle)
257 {
257 {
258 if(m_labelsAngle!=angle) {
258 if(m_labelsAngle!=angle) {
259 m_labelsAngle=angle;
259 m_labelsAngle=angle;
260 emit updated();
260 emit updated();
261 }
261 }
262 }
262 }
263
263
264 /*!
264 /*!
265 Sets if shades are \a visible.
265 Sets if shades are \a visible.
266 */
266 */
267 void QChartAxis::setShadesVisible(bool visible)
267 void QChartAxis::setShadesVisible(bool visible)
268 {
268 {
269 if(m_shadesVisible!=visible) {
269 if(m_shadesVisible!=visible) {
270 m_shadesVisible=visible;
270 m_shadesVisible=visible;
271 emit updated();
271 emit updated();
272 }
272 }
273 }
273 }
274
274
275 /*!
275 /*!
276 Sets \a pen used to draw shades.
276 Sets \a pen used to draw shades.
277 */
277 */
278 void QChartAxis::setShadesPen(const QPen& pen)
278 void QChartAxis::setShadesPen(const QPen& pen)
279 {
279 {
280 if(m_shadesPen!=pen) {
280 if(m_shadesPen!=pen) {
281 m_shadesPen=pen;
281 m_shadesPen=pen;
282 emit updated();
282 emit updated();
283 }
283 }
284 }
284 }
285
285
286 /*!
286 /*!
287 Sets \a brush used to draw shades.
287 Sets \a brush used to draw shades.
288 */
288 */
289 void QChartAxis::setShadesBrush(const QBrush& brush)
289 void QChartAxis::setShadesBrush(const QBrush& brush)
290 {
290 {
291 if(m_shadesBrush!=brush) {
291 if(m_shadesBrush!=brush) {
292 m_shadesBrush=brush;
292 m_shadesBrush=brush;
293 emit updated();
293 emit updated();
294 }
294 }
295 }
295 }
296
296
297 /*!
297 /*!
298 Sets \a opacity of the shades.
298 Sets \a opacity of the shades.
299 */
299 */
300 void QChartAxis::setShadesOpacity(qreal opacity)
300 void QChartAxis::setShadesOpacity(qreal opacity)
301 {
301 {
302 if(m_shadesOpacity!=opacity) {
302 if(m_shadesOpacity!=opacity) {
303 m_shadesOpacity=opacity;
303 m_shadesOpacity=opacity;
304 emit updated();
304 emit updated();
305 }
305 }
306 }
306 }
307
307
308 /*!
308 /*!
309 Sets \a min value on the axis.
309 Sets \a min value on the axis.
310 */
310 */
311 void QChartAxis::setMin(qreal min)
311 void QChartAxis::setMin(qreal min)
312 {
312 {
313 setRange(min,m_max);
313 setRange(min,m_max);
314 }
314 }
315
315
316 /*!
316 /*!
317 Sets \a max value on the axis.
317 Sets \a max value on the axis.
318 */
318 */
319 void QChartAxis::setMax(qreal max)
319 void QChartAxis::setMax(qreal max)
320 {
320 {
321 setRange(m_min,max);
321 setRange(m_min,max);
322 }
322 }
323
323
324 /*!
324 /*!
325 Sets range from \a min to \a max on the axis.
325 Sets range from \a min to \a max on the axis.
326 */
326 */
327 void QChartAxis::setRange(qreal min, qreal max)
327 void QChartAxis::setRange(qreal min, qreal max)
328 {
328 {
329
330
329 bool changed = false;
331 bool changed = false;
330 if(m_min!=min) {
332 if(m_min!=min) {
331 m_min=min;
333 m_min=min;
334 changed=true;
332 emit minChanged(min);
335 emit minChanged(min);
333 }
336 }
334
337
335 if(m_max!=max) {
338 if(m_max!=max) {
336 m_max=max;
339 m_max=max;
340 changed=true;
337 emit maxChanged(max);
341 emit maxChanged(max);
338 }
342 }
339
343
340 if(changed) emit rangeChanged(m_min,m_max);
344 if(changed) {
345 emit rangeChanged(m_min,m_max);
346 }
341 }
347 }
342
348
343 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
349 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
344 {
350 {
345 setRange(min,max);
351 setRange(min,max);
346 }
352 }
347
353
348 /*!
354 /*!
349 Sets \a count for ticks on the axis.
355 Sets \a count for ticks on the axis.
350 */
356 */
351 void QChartAxis::setTicksCount(int count)
357 void QChartAxis::setTicksCount(int count)
352 {
358 {
353 if(m_ticksCount!=count) {
359 if(m_ticksCount!=count) {
354 m_ticksCount=count;
360 m_ticksCount=count;
355 emit updated();
361 emit updated();
356 }
362 }
357 }
363 }
358
364
359 /*!
365 /*!
360 TODO: refactor me. Sets string \a label for \a value on the axis.
366 TODO: refactor me. Sets string \a label for \a value on the axis.
361 */
367 */
362 void QChartAxis::addAxisTickLabel(qreal value,const QString& label)
368 void QChartAxis::addAxisTickLabel(qreal value,const QString& label)
363 {
369 {
364 m_ticks.insert(value,label);
370 m_ticks.insert(value,label);
365 emit updated();
371 emit updated();
366 }
372 }
367
373
368 /*!
374 /*!
369 TODO: refactor me. Removes label for \a value on the axis.
375 TODO: refactor me. Removes label for \a value on the axis.
370 */
376 */
371 void QChartAxis::removeAxisTickLabel(qreal value)
377 void QChartAxis::removeAxisTickLabel(qreal value)
372 {
378 {
373 m_ticks.remove(value);
379 m_ticks.remove(value);
374 emit updated();
380 emit updated();
375 }
381 }
376
382
377 /*!
383 /*!
378 TODO: refactor me. Returns label for \a value on the axis.
384 TODO: refactor me. Returns label for \a value on the axis.
379 */
385 */
380 QString QChartAxis::axisTickLabel(qreal value) const
386 QString QChartAxis::axisTickLabel(qreal value) const
381 {
387 {
382 return m_ticks.value(value);
388 return m_ticks.value(value);
383 }
389 }
384
390
385 /*!
391 /*!
386 TODO: refactor me. Removes all the string labels for on the axis.
392 TODO: refactor me. Removes all the string labels for on the axis.
387 */
393 */
388 void QChartAxis::clearAxisTickLabels()
394 void QChartAxis::clearAxisTickLabels()
389 {
395 {
390 m_ticks.clear();
396 m_ticks.clear();
391 emit updated();
397 emit updated();
392 }
398 }
393
399
394 #include "moc_qchartaxis.cpp"
400 #include "moc_qchartaxis.cpp"
395
401
396 QTCOMMERCIALCHART_END_NAMESPACE
402 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now