##// END OF EJS Templates
Refactor categories implementation...
Michal Klocek -
r1611:9f1825280c4a
parent child
Show More
@@ -49,12 +49,12 Q_SIGNALS:
49 49
50 50 public:
51 51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52 virtual void updateRange() = 0;
52 virtual void emitRange() = 0;
53 53
54 54 protected:
55 55 virtual void setMin(const QVariant &min) = 0;
56 56 virtual void setMax(const QVariant &max) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max, bool force = false) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
58 58 virtual int ticksCount() const = 0;
59 59
60 60 public:
@@ -23,6 +23,7
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include <qmath.h>
26 #include <QDebug>
26 27
27 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 29
@@ -47,11 +48,12 void QCategoriesAxis::append(const QStringList &categories)
47 48 {
48 49 Q_D(QCategoriesAxis);
49 50 if (d->m_categories.isEmpty()) {
50 d->m_minCategory = categories.first();
51 d->m_maxCategory = categories.last();
51 d->m_categories.append(categories);
52 setRange(categories.first(),categories.last());
53 }else{
54 d->m_categories.append(categories);
52 55 }
53 56
54 d->m_categories.append(categories);
55 57 emit categoriesChanged();
56 58 }
57 59
@@ -60,14 +62,14 void QCategoriesAxis::append(const QStringList &categories)
60 62 */
61 63 void QCategoriesAxis::append(const QString &category)
62 64 {
63 Q_D(QCategoriesAxis);
64 if (d->m_categories.isEmpty()) {
65 d->m_minCategory = category;
66 d->m_maxCategory = category;
67 }
68
69 d->m_categories.append(category);
70 emit categoriesChanged();
65 Q_D(QCategoriesAxis);
66 if (d->m_categories.isEmpty()) {
67 d->m_categories.append(category);
68 setRange(category,category);
69 }else{
70 d->m_categories.append(category);
71 }
72 emit categoriesChanged();
71 73 }
72 74
73 75 /*!
@@ -78,8 +80,7 void QCategoriesAxis::remove(const QString &category)
78 80 Q_D(QCategoriesAxis);
79 81 if (d->m_categories.contains(category)) {
80 82 d->m_categories.removeAt(d->m_categories.indexOf(category));
81 d->m_minCategory = d->m_categories.first();
82 d->m_maxCategory = d->m_categories.last();
83 setRange(d->m_categories.first(),d->m_categories.last());
83 84 emit categoriesChanged();
84 85 }
85 86 }
@@ -91,10 +92,11 void QCategoriesAxis::insert(int index, const QString &category)
91 92 {
92 93 Q_D(QCategoriesAxis);
93 94 if (d->m_categories.isEmpty()) {
94 d->m_minCategory = category;
95 d->m_maxCategory = category;
95 d->m_categories.insert(index,category);
96 setRange(category,category);
97 }else{
98
96 99 }
97 d->m_categories.insert(index,category);
98 100 emit categoriesChanged();
99 101 }
100 102
@@ -105,18 +107,18 void QCategoriesAxis::clear()
105 107 {
106 108 Q_D(QCategoriesAxis);
107 109 d->m_categories.clear();
108 d->m_minCategory.clear();
109 d->m_maxCategory.clear();
110 setRange(QString::null,QString::null);
110 111 emit categoriesChanged();
111 112 }
112 113
113 114 void QCategoriesAxis::setCategories(const QStringList &categories)
114 115 {
115 116 Q_D(QCategoriesAxis);
117 if(d->m_categories!=categories){
116 118 d->m_categories = categories;
117 d->m_minCategory = categories.first();
118 d->m_maxCategory = categories.last();
119 setRange(categories.first(),categories.last());
119 120 emit categoriesChanged();
121 }
120 122 }
121 123
122 124 QStringList QCategoriesAxis::categories()
@@ -200,24 +202,21 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCat
200 202 return;
201 203 }
202 204
203 d->m_minCategory = minCategory;
204 d->m_maxCategory = maxCategory;
205
206 205 bool changed = false;
207 206 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
207 d->m_minCategory = minCategory;
208 208 d->m_min = minIndex;
209 209 changed = true;
210 210 }
211 211
212 212 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
213 213 d->m_max = maxIndex;
214 d->m_maxCategory = maxCategory;
214 215 changed = true;
215 216 }
216 217
217 218 if ((changed)) {
218 if(!signalsBlocked()){
219 emit d->changed(d->m_min -0.5, d->m_max +0.5, qCeil(d->m_max + 0.5) -qCeil(d->m_min - 0.5) +1, false);
220 }
219 d->emitRange();
221 220 emit categoriesChanged();
222 221 }
223 222 }
@@ -253,9 +252,8 void QCategoriesAxisPrivate::setMax(const QVariant &max)
253 252 setRange(m_minCategory,max);
254 253 }
255 254
256 void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
255 void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
257 256 {
258 Q_UNUSED(force); // TODO: use this?
259 257 Q_Q(QCategoriesAxis);
260 258 QString value1 = min.toString();
261 259 QString value2 = max.toString();
@@ -284,9 +282,12 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
284 282 }
285 283 }
286 284
287 void QCategoriesAxisPrivate::updateRange()
285 void QCategoriesAxisPrivate::emitRange()
288 286 {
289 setRange(m_min,m_max,true);
287 Q_Q( QCategoriesAxis);
288 if(!q->signalsBlocked()) {
289 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
290 }
290 291 }
291 292
292 293
@@ -31,6 +31,8 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
34 36
35 37 public:
36 38 explicit QCategoriesAxis(QObject *parent = 0);
@@ -60,6 +62,9 public:
60 62
61 63 Q_SIGNALS:
62 64 void categoriesChanged();
65 void minChanged(const QString &min);
66 void maxChanged(const QString &max);
67 void rangeChanged(const QString &min, const QString &max);
63 68
64 69 private:
65 70 Q_DECLARE_PRIVATE(QCategoriesAxis)
@@ -45,13 +45,13 public:
45 45
46 46 public:
47 47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 void updateRange();
48 void emitRange();
49 49
50 50 private:
51 51 //range handling
52 52 void setMin(const QVariant &min);
53 53 void setMax(const QVariant &max);
54 void setRange(const QVariant &min, const QVariant &max, bool force = false);
54 void setRange(const QVariant &min, const QVariant &max);
55 55 int ticksCount() const;
56 56
57 57 Q_SIGNALS:
@@ -165,10 +165,8 void QValuesAxis::setRange(qreal min, qreal max)
165 165 }
166 166
167 167 if (changed) {
168 d->emitRange();
168 169 emit rangeChanged(d->m_min,d->m_max);
169 if(!signalsBlocked()){
170 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
171 }
172 170 }
173 171 }
174 172
@@ -252,9 +250,8 void QValuesAxisPrivate::setMax(const QVariant &max)
252 250 if(ok) q->setMax(value);
253 251 }
254 252
255 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
253 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
256 254 {
257 Q_UNUSED(force); // TODO: use this
258 255 Q_Q(QValuesAxis);
259 256 bool ok1;
260 257 bool ok2;
@@ -279,9 +276,12 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
279 276
280 277 }
281 278
282 void QValuesAxisPrivate::updateRange()
279 void QValuesAxisPrivate::emitRange()
283 280 {
284 setRange(m_min,m_max,true);
281 Q_Q(QValuesAxis);
282 if(!q->signalsBlocked()) {
283 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
284 }
285 285 }
286 286
287 287 #include "moc_qvaluesaxis.cpp"
@@ -50,12 +50,12 public Q_SLOTS:
50 50
51 51 public:
52 52 ChartAxis* createGraphics(ChartPresenter* presenter);
53 void updateRange();
53 void emitRange();
54 54
55 55 protected:
56 56 void setMin(const QVariant &min);
57 57 void setMax(const QVariant &max);
58 void setRange(const QVariant &min, const QVariant &max, bool force = false);
58 void setRange(const QVariant &min, const QVariant &max);
59 59 int ticksCount() const;
60 60
61 61 private:
@@ -373,9 +373,7 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
373 373 }
374 374
375 375 m_seriesAxisXMap.insert(series,axis);
376
377 // Force range update
378 axis->d_ptr->updateRange();
376 axis->d_ptr->emitRange();
379 377 }
380 378
381 379 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
@@ -414,6 +412,7 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
414 412 }
415 413
416 414 m_seriesAxisYMap.insert(series,axis);
415 axis->d_ptr->emitRange();
417 416 }
418 417
419 418 Domain* ChartDataSet::domain(QAbstractSeries *series) const
General Comments 0
You need to be logged in to leave comments. Login now