##// END OF EJS Templates
renamed setRange to setCategoryRange in category axis.
sauimone -
r1576:89c5fcadff3e
parent child
Show More
@@ -1,131 +1,132
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartcategoriesaxisx_p.h"
21 #include "chartcategoriesaxisx_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QCategoriesAxis>
28 #include <QCategoriesAxis>
29 #include <qmath.h>
29 #include <qmath.h>
30
30
31 static int label_padding = 5;
31 static int label_padding = 5;
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartCategoriesAxisX::ChartCategoriesAxisX(QCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
35 ChartCategoriesAxisX::ChartCategoriesAxisX(QCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
36 m_categoriesAxis(axis)
36 m_categoriesAxis(axis)
37 {
37 {
38 }
38 }
39
39
40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
41 {
41 {
42 }
42 }
43
43
44 bool ChartCategoriesAxisX::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
44 bool ChartCategoriesAxisX::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
45 {
45 {
46 Q_ASSERT(max>min);
46 Q_ASSERT(max>min);
47 Q_UNUSED(ticks);
47 Q_UNUSED(ticks);
48 Q_UNUSED(max);
48 Q_UNUSED(max);
49
49
50 QStringList categories = m_categoriesAxis->categories();
50 QStringList categories = m_categoriesAxis->categories();
51
51
52 int x = qCeil(min);
52 int x = qCeil(min);
53 int count = 0;
53 int count = 0;
54
54
55 // Try to find category for x coordinate
55 // Try to find category for x coordinate
56 while (count < ticks) {
56 while (count < ticks) {
57 if ((x < categories.count()) && (x >= 0)) {
57 if ((x < categories.count()) && (x >= 0)) {
58 labels << categories.at(x);
58 labels << categories.at(x);
59 } else {
59 } else {
60 // No label for x coordinate
60 // No label for x coordinate
61 labels << "";
61 labels << "";
62 }
62 }
63 x++;
63 x++;
64 count++;
64 count++;
65 }
65 }
66
66
67 return true;
67 return true;
68 }
68 }
69
69
70 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
70 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
71 {
71 {
72 Q_ASSERT(m_ticksCount>=2);
72 Q_ASSERT(m_ticksCount>=2);
73
73
74 QVector<qreal> points;
74 QVector<qreal> points;
75 points.resize(m_ticksCount);
75 points.resize(m_ticksCount);
76
76
77 // TODO: shift logic
77 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
78 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
78 for (int i = 0; i < m_ticksCount; ++i) {
79 for (int i = 0; i < m_ticksCount; ++i) {
79 int x = i * deltaX + m_rect.left();
80 int x = i * deltaX + m_rect.left();
80 points[i] = x;
81 points[i] = x;
81 }
82 }
82 return points;
83 return points;
83 }
84 }
84
85
85 void ChartCategoriesAxisX::updateGeometry()
86 void ChartCategoriesAxisX::updateGeometry()
86 {
87 {
87 const QVector<qreal>& layout = ChartAxis::layout();
88 const QVector<qreal>& layout = ChartAxis::layout();
88
89
89 m_minWidth = 0;
90 m_minWidth = 0;
90 m_minHeight = 0;
91 m_minHeight = 0;
91
92
92 if(layout.isEmpty()) return;
93 if(layout.isEmpty()) return;
93
94
94 QStringList ticksList;
95 QStringList ticksList;
95
96
96 createLabels(ticksList,m_min,m_max,layout.size());
97 createLabels(ticksList,m_min,m_max,layout.size());
97
98
98 QList<QGraphicsItem *> lines = m_grid->childItems();
99 QList<QGraphicsItem *> lines = m_grid->childItems();
99 QList<QGraphicsItem *> labels = m_labels->childItems();
100 QList<QGraphicsItem *> labels = m_labels->childItems();
100 QList<QGraphicsItem *> shades = m_shades->childItems();
101 QList<QGraphicsItem *> shades = m_shades->childItems();
101 QList<QGraphicsItem *> axis = m_axis->childItems();
102 QList<QGraphicsItem *> axis = m_axis->childItems();
102
103
103 Q_ASSERT(labels.size() == ticksList.size());
104 Q_ASSERT(labels.size() == ticksList.size());
104 Q_ASSERT(layout.size() == ticksList.size());
105 Q_ASSERT(layout.size() == ticksList.size());
105
106
106 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
107 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
107 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
108 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
108
109
109 for (int i = 1; i < layout.size(); ++i) {
110 for (int i = 1; i < layout.size(); ++i) {
110 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
111 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
111 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
112 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
112 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i-1));
113 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i-1));
113
114
114 labelItem->setText(ticksList.at(i-1));
115 labelItem->setText(ticksList.at(i-1));
115 const QRectF& rect = labelItem->boundingRect();
116 const QRectF& rect = labelItem->boundingRect();
116 QPointF center = rect.center();
117 QPointF center = rect.center();
117 labelItem->setTransformOriginPoint(center.x(), center.y());
118 labelItem->setTransformOriginPoint(center.x(), center.y());
118 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
119 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
119 m_minWidth+=rect.width();
120 m_minWidth+=rect.width();
120 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
121 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
121
122
122 if ((i+1)%2 && i>1) {
123 if ((i+1)%2 && i>1) {
123 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
124 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
124 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
125 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
125 }
126 }
126 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
127 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
127 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
128 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
128 }
129 }
129 }
130 }
130
131
131 QTCOMMERCIALCHART_END_NAMESPACE
132 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,301 +1,301
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
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 #include <qmath.h>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 QCategoriesAxis::QCategoriesAxis(QObject *parent):
29 QCategoriesAxis::QCategoriesAxis(QObject *parent):
30 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
30 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
31 {
31 {
32 }
32 }
33
33
34 QCategoriesAxis::~QCategoriesAxis()
34 QCategoriesAxis::~QCategoriesAxis()
35 {
35 {
36 }
36 }
37
37
38 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
38 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 {
39 {
40
40
41 }
41 }
42
42
43 /*!
43 /*!
44 Appends \a categories to axis
44 Appends \a categories to axis
45 */
45 */
46 void QCategoriesAxis::append(const QStringList &categories)
46 void QCategoriesAxis::append(const QStringList &categories)
47 {
47 {
48 Q_D(QCategoriesAxis);
48 Q_D(QCategoriesAxis);
49 d->m_categories.append(categories);
49 d->m_categories.append(categories);
50 emit categoriesChanged();
50 emit categoriesChanged();
51 }
51 }
52
52
53 /*!
53 /*!
54 Appends \a category to axis
54 Appends \a category to axis
55 */
55 */
56 void QCategoriesAxis::append(const QString &category)
56 void QCategoriesAxis::append(const QString &category)
57 {
57 {
58 Q_D(QCategoriesAxis);
58 Q_D(QCategoriesAxis);
59 d->m_categories.append(category);
59 d->m_categories.append(category);
60 emit categoriesChanged();
60 emit categoriesChanged();
61 }
61 }
62
62
63 /*!
63 /*!
64 Removes \a category from axis
64 Removes \a category from axis
65 */
65 */
66 void QCategoriesAxis::remove(const QString &category)
66 void QCategoriesAxis::remove(const QString &category)
67 {
67 {
68 Q_D(QCategoriesAxis);
68 Q_D(QCategoriesAxis);
69 if (d->m_categories.contains(category)) {
69 if (d->m_categories.contains(category)) {
70 d->m_categories.removeAt(d->m_categories.indexOf(category));
70 d->m_categories.removeAt(d->m_categories.indexOf(category));
71 emit categoriesChanged();
71 emit categoriesChanged();
72 }
72 }
73 }
73 }
74
74
75 /*!
75 /*!
76 Inserts \a category to axis at \a index
76 Inserts \a category to axis at \a index
77 */
77 */
78 void QCategoriesAxis::insert(int index, const QString &category)
78 void QCategoriesAxis::insert(int index, const QString &category)
79 {
79 {
80 Q_D(QCategoriesAxis);
80 Q_D(QCategoriesAxis);
81 d->m_categories.insert(index,category);
81 d->m_categories.insert(index,category);
82 emit categoriesChanged();
82 emit categoriesChanged();
83 }
83 }
84
84
85 /*!
85 /*!
86 Removes all categories.
86 Removes all categories.
87 */
87 */
88 void QCategoriesAxis::clear()
88 void QCategoriesAxis::clear()
89 {
89 {
90 Q_D(QCategoriesAxis);
90 Q_D(QCategoriesAxis);
91 d->m_categories.clear();
91 d->m_categories.clear();
92 emit categoriesChanged();
92 emit categoriesChanged();
93 }
93 }
94
94
95 void QCategoriesAxis::setCategories(const QStringList &categories)
95 void QCategoriesAxis::setCategories(const QStringList &categories)
96 {
96 {
97 Q_D(QCategoriesAxis);
97 Q_D(QCategoriesAxis);
98 d->m_categories = categories;
98 d->m_categories = categories;
99 emit categoriesChanged();
99 emit categoriesChanged();
100 }
100 }
101
101
102 QStringList QCategoriesAxis::categories()
102 QStringList QCategoriesAxis::categories()
103 {
103 {
104 Q_D(QCategoriesAxis);
104 Q_D(QCategoriesAxis);
105 return d->m_categories;
105 return d->m_categories;
106 }
106 }
107
107
108 /*!
108 /*!
109 Returns number of categories.
109 Returns number of categories.
110 */
110 */
111 int QCategoriesAxis::count() const
111 int QCategoriesAxis::count() const
112 {
112 {
113 Q_D(const QCategoriesAxis);
113 Q_D(const QCategoriesAxis);
114 return d->m_categories.count();
114 return d->m_categories.count();
115 }
115 }
116
116
117 /*!
117 /*!
118 Returns category at \a index. Index must be valid.
118 Returns category at \a index. Index must be valid.
119 */
119 */
120 QString QCategoriesAxis::at(int index) const
120 QString QCategoriesAxis::at(int index) const
121 {
121 {
122 Q_D(const QCategoriesAxis);
122 Q_D(const QCategoriesAxis);
123 return d->m_categories.at(index);
123 return d->m_categories.at(index);
124 }
124 }
125
125
126 /*!
126 /*!
127 Sets minimum category to \a minCategory.
127 Sets minimum category to \a minCategory.
128 */
128 */
129 void QCategoriesAxis::setMinCategory(const QString& minCategory)
129 void QCategoriesAxis::setMinCategory(const QString& minCategory)
130 {
130 {
131 Q_D(QCategoriesAxis);
131 Q_D(QCategoriesAxis);
132 d->setMinCategory(minCategory);
132 d->setMinCategory(minCategory);
133 }
133 }
134
134
135 /*!
135 /*!
136 Returns minimum category.
136 Returns minimum category.
137 */
137 */
138 QString QCategoriesAxis::minCategory() const
138 QString QCategoriesAxis::minCategory() const
139 {
139 {
140 Q_D(const QCategoriesAxis);
140 Q_D(const QCategoriesAxis);
141 return d->m_minCategory;
141 return d->m_minCategory;
142 }
142 }
143
143
144 /*!
144 /*!
145 Sets maximum category to \a maxCategory.
145 Sets maximum category to \a maxCategory.
146 */
146 */
147 void QCategoriesAxis::setMaxCategory(const QString& maxCategory)
147 void QCategoriesAxis::setMaxCategory(const QString& maxCategory)
148 {
148 {
149 Q_D(QCategoriesAxis);
149 Q_D(QCategoriesAxis);
150 d->setMaxCategory(maxCategory);
150 d->setMaxCategory(maxCategory);
151 }
151 }
152
152
153 /*!
153 /*!
154 Returns maximum category
154 Returns maximum category
155 */
155 */
156 QString QCategoriesAxis::maxCategory() const
156 QString QCategoriesAxis::maxCategory() const
157 {
157 {
158 Q_D(const QCategoriesAxis);
158 Q_D(const QCategoriesAxis);
159 return d->m_maxCategory;
159 return d->m_maxCategory;
160 }
160 }
161
161
162 /*!
162 /*!
163 Sets range from \a minCategory to \a maxCategory
163 Sets range from \a minCategory to \a maxCategory
164 */
164 */
165 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
165 void QCategoriesAxis::setCategoryRange(const QString& minCategory, const QString& maxCategory)
166 {
166 {
167 Q_D(QCategoriesAxis);
167 Q_D(QCategoriesAxis);
168 d->setRangeCategory(minCategory,maxCategory);
168 d->setRangeCategory(minCategory,maxCategory);
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns the type of axis.
172 Returns the type of axis.
173 */
173 */
174 QAbstractAxis::AxisType QCategoriesAxis::type() const
174 QAbstractAxis::AxisType QCategoriesAxis::type() const
175 {
175 {
176 return AxisTypeCategories;
176 return AxisTypeCategories;
177 }
177 }
178
178
179 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180
180
181 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
181 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
182 QAbstractAxisPrivate(q)
182 QAbstractAxisPrivate(q)
183 {
183 {
184
184
185 }
185 }
186
186
187 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
187 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
188 {
188 {
189
189
190 }
190 }
191
191
192 void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory)
192 void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory)
193 {
193 {
194 // Convert the category to value
194 // Convert the category to value
195 int minIndex = m_categories.indexOf(minCategory);
195 int minIndex = m_categories.indexOf(minCategory);
196 if (minIndex == -1) {
196 if (minIndex == -1) {
197 return;
197 return;
198 }
198 }
199
199
200 int maxIndex = qFloor(m_max);
200 int maxIndex = qFloor(m_max);
201 if (minIndex > maxIndex) {
201 if (minIndex > maxIndex) {
202 maxIndex = m_categories.count()-1;
202 maxIndex = m_categories.count()-1;
203 }
203 }
204 setRange(minIndex - 0.5, maxIndex + 0.5);
204 setRange(minIndex - 0.5, maxIndex + 0.5);
205 }
205 }
206
206
207 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
207 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
208 {
208 {
209 // Convert the category to value
209 // Convert the category to value
210 int maxIndex = m_categories.indexOf(maxCategory);
210 int maxIndex = m_categories.indexOf(maxCategory);
211 if (maxIndex == -1) {
211 if (maxIndex == -1) {
212 return;
212 return;
213 }
213 }
214
214
215 int minIndex = qCeil(m_min);
215 int minIndex = qCeil(m_min);
216 if (maxIndex < minIndex) {
216 if (maxIndex < minIndex) {
217 minIndex = 0;
217 minIndex = 0;
218 }
218 }
219 setRange(minIndex - 0.5, maxIndex + 0.5);
219 setRange(minIndex - 0.5, maxIndex + 0.5);
220 }
220 }
221
221
222 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory)
222 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory)
223 {
223 {
224 // TODO:
224 // TODO:
225 int minIndex = m_categories.indexOf(minCategory);
225 int minIndex = m_categories.indexOf(minCategory);
226 if (minIndex == -1) {
226 if (minIndex == -1) {
227 return;
227 return;
228 }
228 }
229 int maxIndex = m_categories.indexOf(maxCategory);
229 int maxIndex = m_categories.indexOf(maxCategory);
230 if (maxIndex == -1) {
230 if (maxIndex == -1) {
231 return;
231 return;
232 }
232 }
233 setRange(minIndex -0.5, maxIndex + 0.5);
233 setRange(minIndex -0.5, maxIndex + 0.5);
234 }
234 }
235
235
236 void QCategoriesAxisPrivate::setMin(const qreal min)
236 void QCategoriesAxisPrivate::setMin(const qreal min)
237 {
237 {
238 setRange(min,m_max);
238 setRange(min,m_max);
239 }
239 }
240
240
241 void QCategoriesAxisPrivate::setMax(const qreal max)
241 void QCategoriesAxisPrivate::setMax(const qreal max)
242 {
242 {
243 setRange(m_min,max);
243 setRange(m_min,max);
244 }
244 }
245
245
246 void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max, bool force)
246 void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max, bool force)
247 {
247 {
248 if (max <= min) {
248 if (max <= min) {
249 // max must be greater than min
249 // max must be greater than min
250 return;
250 return;
251 }
251 }
252 Q_Q(QCategoriesAxis);
252 Q_Q(QCategoriesAxis);
253 bool changed = false;
253 bool changed = false;
254 if (!qFuzzyIsNull(m_min - min)) {
254 if (!qFuzzyIsNull(m_min - min)) {
255 m_min = min;
255 m_min = min;
256 changed = true;
256 changed = true;
257 }
257 }
258
258
259 if (!qFuzzyIsNull(m_max - max)) {
259 if (!qFuzzyIsNull(m_max - max)) {
260 m_max = max;
260 m_max = max;
261 changed = true;
261 changed = true;
262 }
262 }
263
263
264 if ((changed) ||(force)) {
264 if ((changed) ||(force)) {
265 emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false);
265 emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false);
266 emit q->categoriesChanged();
266 emit q->categoriesChanged();
267 }
267 }
268 }
268 }
269
269
270 int QCategoriesAxisPrivate::ticksCount() const
270 int QCategoriesAxisPrivate::ticksCount() const
271 {
271 {
272 return m_categories.count()+1;
272 return m_categories.count()+1;
273 }
273 }
274
274
275 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
275 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
276 {
276 {
277 m_min = min;
277 m_min = min;
278 m_max = max;
278 m_max = max;
279 m_ticksCount = count;
279 m_ticksCount = count;
280 }
280 }
281
281
282 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
282 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
283 {
283 {
284 Q_Q( QCategoriesAxis);
284 Q_Q( QCategoriesAxis);
285 if(m_orientation == Qt::Vertical){
285 if(m_orientation == Qt::Vertical){
286 return new ChartCategoriesAxisY(q,presenter);
286 return new ChartCategoriesAxisY(q,presenter);
287 }else{
287 }else{
288 return new ChartCategoriesAxisX(q,presenter);
288 return new ChartCategoriesAxisX(q,presenter);
289 }
289 }
290 }
290 }
291
291
292 void QCategoriesAxisPrivate::updateRange()
292 void QCategoriesAxisPrivate::updateRange()
293 {
293 {
294 setRange(m_min,m_max,true);
294 setRange(m_min,m_max,true);
295 }
295 }
296
296
297
297
298 #include "moc_qcategoriesaxis.cpp"
298 #include "moc_qcategoriesaxis.cpp"
299 #include "moc_qcategoriesaxis_p.cpp"
299 #include "moc_qcategoriesaxis_p.cpp"
300
300
301 QTCOMMERCIALCHART_END_NAMESPACE
301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,72
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCATEGORIESAXIS_H
21 #ifndef QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QCategoriesAxisPrivate;
28 class QCategoriesAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34
34
35 public:
35 public:
36 explicit QCategoriesAxis(QObject *parent = 0);
36 explicit QCategoriesAxis(QObject *parent = 0);
37 ~QCategoriesAxis();
37 ~QCategoriesAxis();
38
38
39 protected:
39 protected:
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
41
41
42 public:
42 public:
43 AxisType type() const;
43 AxisType type() const;
44 void append(const QStringList &categories);
44 void append(const QStringList &categories);
45 void append(const QString &category);
45 void append(const QString &category);
46 void remove(const QString &category);
46 void remove(const QString &category);
47 void insert(int index, const QString &category);
47 void insert(int index, const QString &category);
48 void clear();
48 void clear();
49 void setCategories(const QStringList &categories);
49 void setCategories(const QStringList &categories);
50 QStringList categories();
50 QStringList categories();
51 int count() const;
51 int count() const;
52
52
53 QString at(int index) const;
53 QString at(int index) const;
54
54
55 //range handling convenience functions
55 //range handling convenience functions
56 void setMinCategory(const QString& minCategory);
56 void setMinCategory(const QString& minCategory);
57 QString minCategory() const;
57 QString minCategory() const;
58 void setMaxCategory(const QString& maxCategory);
58 void setMaxCategory(const QString& maxCategory);
59 QString maxCategory() const;
59 QString maxCategory() const;
60 void setRange(const QString& minCategory, const QString& maxCategory);
60 void setCategoryRange(const QString& minCategory, const QString& maxCategory);
61
61
62 Q_SIGNALS:
62 Q_SIGNALS:
63 void categoriesChanged();
63 void categoriesChanged();
64
64
65 private:
65 private:
66 Q_DECLARE_PRIVATE(QCategoriesAxis)
66 Q_DECLARE_PRIVATE(QCategoriesAxis)
67 Q_DISABLE_COPY(QCategoriesAxis)
67 Q_DISABLE_COPY(QCategoriesAxis)
68 };
68 };
69
69
70 QTCOMMERCIALCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
71
71
72 #endif // QCATEGORIESAXIS_H
72 #endif // QCATEGORIESAXIS_H
General Comments 0
You need to be logged in to leave comments. Login now