##// END OF EJS Templates
fixed bug in category range handling in categoryaxis
sauimone -
r1572:739f255d74df
parent child
Show More
@@ -67,6 +67,9 int main(int argc, char *argv[])
67 QCategoriesAxis* axis = new QCategoriesAxis();
67 QCategoriesAxis* axis = new QCategoriesAxis();
68 axis->append(categories);
68 axis->append(categories);
69 chart->setAxisX(series,axis);
69 chart->setAxisX(series,axis);
70 // axis->setMinCategory(QString("Feb"));
71 // axis->setMaxCategory(QString("May"));
72 // axis->setRange(QString("Feb"), QString("Apr"));
70 //![4]
73 //![4]
71
74
72 //![5]
75 //![5]
@@ -22,6 +22,7
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
@@ -195,7 +196,12 void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory)
195 if (minIndex == -1) {
196 if (minIndex == -1) {
196 return;
197 return;
197 }
198 }
198 setRange(minIndex,m_max);
199
200 int maxIndex = m_max;
201 if (minIndex > maxIndex) {
202 maxIndex = m_categories.count()-1;
203 }
204 setRange(minIndex - 0.5, maxIndex + 0.5);
199 }
205 }
200
206
201 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
207 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
@@ -205,7 +211,10 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
205 if (maxIndex == -1) {
211 if (maxIndex == -1) {
206 return;
212 return;
207 }
213 }
208 setRange(m_min,maxIndex);
214 if (maxIndex < m_min) {
215 m_min = 0;
216 }
217 setRange(m_min - 0.5, maxIndex + 0.5);
209 }
218 }
210
219
211 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory)
220 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory)
@@ -219,7 +228,7 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const
219 if (maxIndex == -1) {
228 if (maxIndex == -1) {
220 return;
229 return;
221 }
230 }
222 setRange(minIndex,maxIndex);
231 setRange(minIndex -0.5, maxIndex + 0.5);
223 }
232 }
224
233
225 void QCategoriesAxisPrivate::setMin(const qreal min)
234 void QCategoriesAxisPrivate::setMin(const qreal min)
@@ -234,6 +243,10 void QCategoriesAxisPrivate::setMax(const qreal max)
234
243
235 void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max)
244 void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max)
236 {
245 {
246 if (max <= min) {
247 // max must be greater than min
248 return;
249 }
237 Q_Q(QCategoriesAxis);
250 Q_Q(QCategoriesAxis);
238 bool changed = false;
251 bool changed = false;
239 if (!qFuzzyIsNull(m_min - min)) {
252 if (!qFuzzyIsNull(m_min - min)) {
@@ -247,7 +260,7 void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max)
247 }
260 }
248
261
249 if (changed) {
262 if (changed) {
250 emit this->changed(m_min, m_max, m_ticksCount, false);
263 emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false);
251 emit q->categoriesChanged();
264 emit q->categoriesChanged();
252 }
265 }
253 }
266 }
@@ -234,6 +234,7 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
234 oldAxis->deleteLater();
234 oldAxis->deleteLater();
235 }
235 }
236
236
237 // TODO: should we take domain from axis (if it has min and max already defined)
237 Domain* domain = m_seriesDomainMap.value(series);
238 Domain* domain = m_seriesDomainMap.value(series);
238 Q_ASSERT(domain);
239 Q_ASSERT(domain);
239
240
General Comments 0
You need to be logged in to leave comments. Login now