##// END OF EJS Templates
added map for yaxises methods to set axis
sauimone -
r1554:9a708aa57671
parent child
Show More
@@ -53,14 +53,14 ChartDataSet::~ChartDataSet()
53
53
54 void ChartDataSet::addSeries(QAbstractSeries* series)
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 if(axis) {
58 if(axis) {
59 qWarning() << "Can not add series. Series already on the chart";
59 qWarning() << "Can not add series. Series already on the chart";
60 return;
60 return;
61 }
61 }
62
62
63 QAbstractAxis* axisX = m_axisX ; //series->d_ptr->createAxisX();
63 QAbstractAxis* axisX = series->d_ptr->createAxisX();
64 QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY();
64 QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY();
65
65
66 series->setParent(this); // take ownership
66 series->setParent(this); // take ownership
@@ -80,7 +80,8 void ChartDataSet::addSeries(QAbstractSeries* series)
80
80
81 if(!m_axisXInitialized){
81 if(!m_axisXInitialized){
82 m_axisXInitialized=true;
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 if(!m_axisYInitialized && axisY==m_axisY){
87 if(!m_axisYInitialized && axisY==m_axisY){
@@ -90,12 +91,12 void ChartDataSet::addSeries(QAbstractSeries* series)
90
91
91 series->d_ptr->scaleDomain(*domain);
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 axisX->hide();
95 axisX->hide();
95 axisY->hide();
96 axisY->hide();
96 }
97 }
97
98
98 m_seriesAxisMap.insert(series,axisY);
99 m_seriesAxisXMap.insert(series,axisY);
99
100
100 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
101 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
101
102
@@ -119,7 +120,7 void ChartDataSet::addSeries(QAbstractSeries* series)
119
120
120 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
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 if(!axis){
125 if(!axis){
125 qWarning()<<"Can not remove series. Series not found on the chart.";
126 qWarning()<<"Can not remove series. Series not found on the chart.";
@@ -128,7 +129,7 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
128
129
129 emit seriesRemoved(series);
130 emit seriesRemoved(series);
130
131
131 m_seriesAxisMap.remove(series);
132 m_seriesAxisXMap.remove(series);
132 int key = seriesIndex(series);
133 int key = seriesIndex(series);
133 Q_ASSERT(key!=-1);
134 Q_ASSERT(key!=-1);
134
135
@@ -138,7 +139,7 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
138 series->d_ptr->m_chart = 0;
139 series->d_ptr->m_chart = 0;
139 series->d_ptr->m_dataset = 0;
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 int i = axes.indexOf(axis);
144 int i = axes.indexOf(axis);
144
145
@@ -154,7 +155,7 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
154 }
155 }
155 }
156 }
156
157
157 if(m_seriesAxisMap.values().size()==0)
158 if(m_seriesAxisXMap.values().size()==0)
158 {
159 {
159 m_axisXInitialized=false;
160 m_axisXInitialized=false;
160 emit axisRemoved(m_axisX);
161 emit axisRemoved(m_axisX);
@@ -165,7 +166,7 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
165
166
166 void ChartDataSet::removeAllSeries()
167 void ChartDataSet::removeAllSeries()
167 {
168 {
168 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
169 QList<QAbstractSeries*> series = m_seriesAxisXMap.keys();
169 QList<QAbstractAxis*> axes;
170 QList<QAbstractAxis*> axes;
170 foreach(QAbstractSeries *s , series) {
171 foreach(QAbstractSeries *s , series) {
171 QAbstractAxis* axis = removeSeries(s);
172 QAbstractAxis* axis = removeSeries(s);
@@ -176,7 +177,7 void ChartDataSet::removeAllSeries()
176 }
177 }
177 }
178 }
178
179
179 Q_ASSERT(m_seriesAxisMap.count()==0);
180 Q_ASSERT(m_seriesAxisXMap.count()==0);
180 Q_ASSERT(m_axisDomainMap.count()==1);
181 Q_ASSERT(m_axisDomainMap.count()==1);
181
182
182 qDeleteAll(series);
183 qDeleteAll(series);
@@ -214,7 +215,7 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
214 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
215 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
215 {
216 {
216 int count=0;
217 int count=0;
217 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisMap);
218 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap);
218 while (i.hasNext()) {
219 while (i.hasNext()) {
219 i.next();
220 i.next();
220 if(i.key()->type()==type) count++;
221 if(i.key()->type()==type) count++;
@@ -233,21 +234,32 int ChartDataSet::seriesIndex(QAbstractSeries *series)
233 return -1;
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 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
244 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
237 {
245 {
238 if(series == 0) return m_axisY;
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)
257 m_seriesAxisYMap.insert(series,axis);
245 return m_axisX;
246 }
258 }
247
259
248 Domain* ChartDataSet::domain(QAbstractSeries *series) const
260 Domain* ChartDataSet::domain(QAbstractSeries *series) const
249 {
261 {
250 QAbstractAxis* axis = m_seriesAxisMap.value(series);
262 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
251 if(axis){
263 if(axis){
252 return m_axisDomainMap.value(axis);
264 return m_axisDomainMap.value(axis);
253 }else
265 }else
@@ -279,7 +291,7 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
279
291
280 QList<QAbstractSeries*> ChartDataSet::series() const
292 QList<QAbstractSeries*> ChartDataSet::series() const
281 {
293 {
282 return m_seriesAxisMap.keys();
294 return m_seriesAxisXMap.keys();
283 }
295 }
284
296
285 void ChartDataSet::updateSeries(QAbstractSeries *series)
297 void ChartDataSet::updateSeries(QAbstractSeries *series)
@@ -63,6 +63,9 public:
63 QAbstractAxis* axisX(QAbstractSeries *series) const;
63 QAbstractAxis* axisX(QAbstractSeries *series) const;
64 QAbstractAxis* axisY(QAbstractSeries *series) const;
64 QAbstractAxis* axisY(QAbstractSeries *series) const;
65
65
66 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
67 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
68
66 QList<QAbstractSeries*> series() const;
69 QList<QAbstractSeries*> series() const;
67
70
68 Q_SIGNALS:
71 Q_SIGNALS:
@@ -77,7 +80,8 private:
77 void calculateDomain(QAbstractSeries* series,Domain* domain);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
78
81
79 private:
82 private:
80 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisMap;
83 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
84 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
81 QMap<QAbstractAxis*, Domain*> m_axisDomainMap;
85 QMap<QAbstractAxis*, Domain*> m_axisDomainMap;
82 QMap<int, QAbstractSeries*> m_indexSeriesMap;
86 QMap<int, QAbstractSeries*> m_indexSeriesMap;
83 QAbstractAxis* m_axisX;
87 QAbstractAxis* m_axisX;
@@ -398,14 +398,16 void QChart::setMarginsMinimum(const QRectF& margins)
398
398
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
400 {
400 {
401 Q_UNUSED(series);
401 // Q_UNUSED(series);
402 Q_UNUSED(axis);
402 // Q_UNUSED(axis);
403 d_ptr->m_dataset->setAxisX(series, axis);
403 }
404 }
404
405
405 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
406 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
406 {
407 {
407 Q_UNUSED(series);
408 // Q_UNUSED(series);
408 Q_UNUSED(axis);
409 // Q_UNUSED(axis);
410 d_ptr->m_dataset->setAxisY(series, axis);
409 }
411 }
410
412
411 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
413 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
General Comments 0
You need to be logged in to leave comments. Login now