##// END OF EJS Templates
QLogValueAxis added. Log domain missing
Marek Rosa -
r2274:2d2a1c8b0f36
parent child
Show More
@@ -0,0 +1,122
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartlogvalueaxisx_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlogvalueaxis.h"
24 #include "chartlayout_p.h"
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
27 #include <qmath.h>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item)
32 : HorizontalAxis(axis, item),
33 m_axis(axis)
34 {
35 }
36
37 ChartLogValueAxisX::~ChartLogValueAxisX()
38 {
39 }
40
41 QVector<qreal> ChartLogValueAxisX::calculateLayout() const
42 {
43 QVector<qreal> points;
44
45 qreal logMax = log10(m_axis->max()) / log10(m_axis->base());
46 qreal logMin = log10(m_axis->min()) / log10(m_axis->base());
47 int tickCount = qAbs(qRound(logMax - logMin));
48
49 points.resize(tickCount);
50 const QRectF &gridRect = gridGeometry();
51 const qreal deltaX = gridRect.width() / qAbs(logMax - logMin);
52 for (int i = 0; i < tickCount; ++i)
53 if (logMax > logMin)
54 points[i] = ((int)logMin + i) * deltaX - logMin * deltaX + gridRect.left();
55 else
56 points[i] = ((int)logMax + i) * deltaX - logMax * deltaX + gridRect.left();
57
58 return points;
59 }
60
61 void ChartLogValueAxisX::updateGeometry()
62 {
63 const QVector<qreal>& layout = ChartAxis::layout();
64 if (layout.isEmpty())
65 return;
66 setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
67 HorizontalAxis::updateGeometry();
68 }
69
70 //void ChartLogValueAxisX::handleAxisUpdated()
71 //{
72 // ChartAxis::handleAxisUpdated();
73 //}
74
75 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
76 {
77 Q_UNUSED(constraint)
78
79 QFontMetrics fn(font());
80 QSizeF sh;
81
82 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
83 QStringList ticksList;
84 qreal logMax = log10(m_axis->max()) / log10(m_axis->base());
85 qreal logMin = log10(m_axis->min()) / log10(m_axis->base());
86 int tickCount = qAbs(qRound(logMax - logMin));
87
88 if (m_axis->max() > m_axis->min() && tickCount > 1)
89 ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat());
90 else
91 ticksList.append(QString(" "));
92 qreal width = 0;
93 qreal height = 0;
94
95
96 switch (which) {
97 case Qt::MinimumSize:{
98 int count = qMax(ticksList.last().count(),ticksList.first().count());
99 width = fn.averageCharWidth() * count;
100 height = fn.height() + labelPadding();
101 width = qMax(width,base.width());
102 height += base.height();
103 sh = QSizeF(width,height);
104 break;
105 }
106 case Qt::PreferredSize: {
107 int count = qMax(ticksList.last().count(),ticksList.first().count());
108 width=fn.averageCharWidth() * count;
109 height=fn.height()+labelPadding();
110 width=qMax(width,base.width());
111 height+=base.height();
112 sh = QSizeF(width,height);
113 break;
114 }
115 default:
116 break;
117 }
118
119 return sh;
120 }
121
122 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,59
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef CHARTLOGVALUEAXISX_H
31 #define CHARTLOGVALUEAXISX_H
32
33 #include "horizontalaxis_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QLogValueAxis;
38 class ChartPresenter;
39
40 class ChartLogValueAxisX : public HorizontalAxis
41 {
42 public:
43 ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item);
44 ~ChartLogValueAxisX();
45
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
47
48 protected:
49 void handleAxisUpdated();
50 QVector<qreal> calculateLayout() const;
51 void updateGeometry();
52
53 private:
54 QLogValueAxis *m_axis;
55 };
56
57 QTCOMMERCIALCHART_END_NAMESPACE
58
59 #endif /* CHARTLOGVALUEAXISX_H */
@@ -0,0 +1,119
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartlogvalueaxisy_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlogvalueaxis.h"
24 #include "chartlayout_p.h"
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
27 #include <qmath.h>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item)
32 : VerticalAxis(axis, item),
33 m_axis(axis)
34 {
35 }
36
37 ChartLogValueAxisY::~ChartLogValueAxisY()
38 {
39 }
40
41 QVector<qreal> ChartLogValueAxisY::calculateLayout() const
42 {
43 QVector<qreal> points;
44 qreal logMax = log10(m_axis->max()) / log10(m_axis->base());
45 qreal logMin = log10(m_axis->min()) / log10(m_axis->base());
46 int tickCount = qAbs(qRound(logMax - logMin));
47
48 points.resize(tickCount);
49 const QRectF &gridRect = gridGeometry();
50 const qreal deltaY = gridRect.height() / qAbs(logMax - logMin);
51 for (int i = 0; i < tickCount; ++i)
52 if (logMax > logMin)
53 points[i] = ((int)logMin + i) * -deltaY - logMin * -deltaY + gridRect.bottom();
54 else
55 points[i] = ((int)logMax + i) * -deltaY - logMax * -deltaY + gridRect.bottom();
56
57 return points;
58 }
59
60
61 void ChartLogValueAxisY::updateGeometry()
62 {
63 const QVector<qreal> &layout = ChartAxis::layout();
64 if (layout.isEmpty())
65 return;
66 setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
67 VerticalAxis::updateGeometry();
68 }
69
70 //void ChartLogValueAxisY::handleAxisUpdated()
71 //{
72 // ChartAxis::handleAxisUpdated();
73 //}
74
75 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
76 {
77 Q_UNUSED(constraint)
78
79 QFontMetrics fn(font());
80 QSizeF sh;
81
82 QSizeF base = VerticalAxis::sizeHint(which, constraint);
83 QStringList ticksList;
84 qreal logMax = log10(m_axis->max()) / log10(m_axis->base());
85 qreal logMin = log10(m_axis->min()) / log10(m_axis->base());
86 int tickCount = qAbs(qRound(logMax - logMin));
87 if (m_axis->max() > m_axis->min() && tickCount > 1)
88 ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat());
89 else
90 ticksList.append(QString(" "));
91 qreal width = 0;
92 qreal height = 0;
93
94 switch (which) {
95 case Qt::MinimumSize: {
96 width = fn.boundingRect("...").width() + labelPadding();
97 width += base.width();
98 height = fn.height();
99 height = qMax(height,base.height());
100 sh = QSizeF(width,height);
101 break;
102 }
103 case Qt::PreferredSize: {
104 int count = qMax(ticksList.first().count() , ticksList.last().count());
105 width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance
106 width += base.width();
107 height = fn.height() * ticksList.count();
108 height = qMax(height,base.height());
109 sh = QSizeF(width,height);
110 break;
111 }
112 default:
113 break;
114 }
115
116 return sh;
117 }
118
119 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,59
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef CHARTLOGVALUEAXISY_H
31 #define CHARTLOGVALUEAXISY_H
32
33 #include "verticalaxis_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QLogValueAxis;
38 class ChartPresenter;
39
40 class ChartLogValueAxisY : public VerticalAxis
41 {
42 public:
43 ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item);
44 ~ChartLogValueAxisY();
45
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
47
48 protected:
49 void handleAxisUpdated();
50 QVector<qreal> calculateLayout() const;
51 void updateGeometry();
52
53 private:
54 QLogValueAxis *m_axis;
55 };
56
57 QTCOMMERCIALCHART_END_NAMESPACE
58
59 #endif /* CHARTLOGVALUEAXISY_H */
@@ -0,0 +1,315
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "qlogvalueaxis.h"
22 #include "qlogvalueaxis_p.h"
23 #include "chartlogvalueaxisx_p.h"
24 #include "chartlogvalueaxisy_p.h"
25 #include "domain_p.h"
26 #include <float.h>
27 #include <cmath>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
31 \class QLogValueAxis
32 \brief The QLogValueAxis class is used for manipulating chart's axis.
33 \mainclass
34 */
35
36 /*!
37 \qmlclass DateTimeAxis QLogValueAxis
38 \brief The DateTimeAxis element is used for manipulating chart's axes
39 \inherits AbstractAxis
40 */
41
42 /*!
43 \property QLogValueAxis::min
44 Defines the minimum value on the axis.
45 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
46 */
47 /*!
48 \qmlproperty real ValuesAxis::min
49 Defines the minimum value on the axis.
50 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
51 */
52
53 /*!
54 \property QLogValueAxis::max
55 Defines the maximum value on the axis.
56 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
57 */
58 /*!
59 \qmlproperty real ValuesAxis::max
60 Defines the maximum value on the axis.
61 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
62 */
63
64 /*!
65 \fn void QLogValueAxis::minChanged(qreal min)
66 Axis emits signal when \a min of axis has changed.
67 */
68 /*!
69 \qmlsignal ValuesAxis::onMinChanged(qreal min)
70 Axis emits signal when \a min of axis has changed.
71 */
72
73 /*!
74 \fn void QLogValueAxis::maxChanged(qreal max)
75 Axis emits signal when \a max of axis has changed.
76 */
77 /*!
78 \qmlsignal ValuesAxis::onMaxChanged(qreal max)
79 Axis emits signal when \a max of axis has changed.
80 */
81
82 /*!
83 \fn void QLogValueAxis::rangeChanged(qreal min, qreal max)
84 Axis emits signal when \a min or \a max of axis has changed.
85 */
86
87 /*!
88 Constructs an axis object which is a child of \a parent.
89 */
90 QLogValueAxis::QLogValueAxis(QObject *parent) :
91 QAbstractAxis(*new QLogValueAxisPrivate(this), parent)
92 {
93
94 }
95
96 /*!
97 \internal
98 */
99 QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
100 {
101
102 }
103
104 /*!
105 Destroys the object
106 */
107 QLogValueAxis::~QLogValueAxis()
108 {
109
110 }
111
112 void QLogValueAxis::setMin(qreal min)
113 {
114 Q_D(QLogValueAxis);
115 setRange(min, qMax(d->m_max, min));
116 }
117
118 qreal QLogValueAxis::min() const
119 {
120 Q_D(const QLogValueAxis);
121 return d->m_min;
122 }
123
124 void QLogValueAxis::setMax(qreal max)
125 {
126 Q_D(QLogValueAxis);
127 setRange(qMin(d->m_min, max), max);
128 }
129
130 qreal QLogValueAxis::max() const
131 {
132 Q_D(const QLogValueAxis);
133 return d->m_max;
134 }
135
136 /*!
137 Sets range from \a min to \a max on the axis.
138 If min is greater than max then this function returns without making any changes.
139 */
140 void QLogValueAxis::setRange(qreal min, qreal max)
141 {
142 Q_D(QLogValueAxis);
143 bool changed = false;
144
145 if (min > max)
146 return;
147
148 if (min > 0) {
149 if (!qFuzzyCompare(d->m_min, min)) {
150 d->m_min = min;
151 changed = true;
152 emit minChanged(min);
153 }
154
155 if (!qFuzzyCompare(d->m_max, max)) {
156 d->m_max = max;
157 changed = true;
158 emit maxChanged(max);
159 }
160
161 if (changed) {
162 emit rangeChanged(min, max);
163 emit d->rangeChanged(min,max);
164 }
165 }
166 }
167
168 void QLogValueAxis::setLabelFormat(const QString &format)
169 {
170 Q_D(QLogValueAxis);
171 d->m_format = format;
172 }
173
174 QString QLogValueAxis::labelFormat() const
175 {
176 Q_D(const QLogValueAxis);
177 return d->m_format;
178 }
179
180 void QLogValueAxis::setBase(qreal base)
181 {
182 // check if base is correct
183 if (base <= 0 || qFuzzyCompare(base, 1))
184 return;
185
186 Q_D(QLogValueAxis);
187 d->m_base = base;
188 }
189
190 qreal QLogValueAxis::base() const
191 {
192 Q_D(const QLogValueAxis);
193 return d->m_base;
194 }
195
196 /*!
197 Returns the type of the axis
198 */
199 QAbstractAxis::AxisType QLogValueAxis::type() const
200 {
201 return AxisTypeLogValue;
202 }
203
204 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
205
206 QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q)
207 : QAbstractAxisPrivate(q),
208 m_min(1),
209 m_max(10),
210 m_base(10),
211 m_format(QString::null)
212 {
213 }
214
215 QLogValueAxisPrivate::~QLogValueAxisPrivate()
216 {
217
218 }
219
220 void QLogValueAxisPrivate::setMin(const QVariant &min)
221 {
222 Q_Q(QLogValueAxis);
223 bool ok;
224 qreal value = min.toReal(&ok);
225 if (ok)
226 q->setMin(value);
227 }
228
229 void QLogValueAxisPrivate::setMax(const QVariant &max)
230 {
231
232 Q_Q(QLogValueAxis);
233 bool ok;
234 qreal value = max.toReal(&ok);
235 if (ok)
236 q->setMax(value);
237 }
238
239 void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
240 {
241 Q_Q(QLogValueAxis);
242 bool ok1;
243 bool ok2;
244 qreal value1 = min.toReal(&ok1);
245 qreal value2 = max.toReal(&ok2);
246 if (ok1 && ok2)
247 q->setRange(value1, value2);
248 }
249
250 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
251 {
252 Q_Q(QLogValueAxis);
253 bool changed = false;
254
255 if (min > max)
256 return;
257
258 if (min > 0) {
259 if (!qFuzzyCompare(m_min, min)) {
260 m_min = min;
261 changed = true;
262 emit q->minChanged(min);
263 }
264
265 if (!qFuzzyCompare(m_max, max)) {
266 m_max = max;
267 changed = true;
268 emit q->maxChanged(max);
269 }
270
271 if (changed) {
272 emit q->rangeChanged(min, max);
273 emit rangeChanged(min,max);
274 }
275 }
276 }
277
278 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
279 {
280 Q_Q(QLogValueAxis);
281 ChartAxis* axis(0);
282 if (orientation() == Qt::Vertical)
283 axis = new ChartLogValueAxisY(q,parent);
284 if (orientation() == Qt::Horizontal)
285 axis = new ChartLogValueAxisX(q,parent);
286
287 m_item.reset(axis);
288 QAbstractAxisPrivate::initializeGraphics(parent);
289 }
290
291
292 void QLogValueAxisPrivate::initializeDomain(Domain *domain)
293 {
294 if (orientation() == Qt::Vertical) {
295 if(!qFuzzyCompare(m_max, m_min)) {
296 domain->setRangeY(m_min, m_max);
297 }
298 else {
299 setRange(domain->minY() + 1, domain->maxY());
300 }
301 }
302 if (orientation() == Qt::Horizontal) {
303 if(!qFuzzyCompare(m_max, m_min)) {
304 domain->setRangeX(m_min, m_max);
305 }
306 else {
307 setRange(domain->minX() + 1, domain->maxX());
308 }
309 }
310 }
311
312 #include "moc_qlogvalueaxis.cpp"
313 #include "moc_qlogvalueaxis_p.cpp"
314
315 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,74
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef QLOGVALUEAXIS_H
22 #define QLOGVALUEAXIS_H
23
24 #include "qabstractaxis.h"
25
26 class QDateTime;
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class QLogValueAxisPrivate;
31
32 class QTCOMMERCIALCHART_EXPORT QLogValueAxis : public QAbstractAxis
33 {
34 Q_OBJECT
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat)
38
39 public:
40 explicit QLogValueAxis(QObject *parent = 0);
41 ~QLogValueAxis();
42
43 protected:
44 QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = 0);
45
46 public:
47 AxisType type() const;
48
49 //range handling
50 void setMin(qreal min);
51 qreal min() const;
52 void setMax(qreal max);
53 qreal max() const;
54 void setRange(qreal min, qreal max);
55
56 void setLabelFormat(const QString &format);
57 QString labelFormat() const;
58
59 void setBase(qreal base);
60 qreal base() const;
61
62 Q_SIGNALS:
63 void minChanged(qreal min);
64 void maxChanged(qreal max);
65 void rangeChanged(qreal min, qreal max);
66
67 private:
68 Q_DECLARE_PRIVATE(QLogValueAxis)
69 Q_DISABLE_COPY(QLogValueAxis)
70 };
71
72 QTCOMMERCIALCHART_END_NAMESPACE
73
74 #endif // QLOGVALUEAXIS_H
@@ -0,0 +1,69
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QLOGVALUEAXIS_P_H
31 #define QLOGVALUEAXIS_P_H
32
33 #include "qlogvalueaxis.h"
34 #include "qabstractaxis_p.h"
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QLogValueAxisPrivate : public QAbstractAxisPrivate
39 {
40 Q_OBJECT
41 public:
42 QLogValueAxisPrivate(QLogValueAxis *q);
43 ~QLogValueAxisPrivate();
44
45 public:
46 void initializeGraphics(QGraphicsItem* parent);
47 void initializeDomain(Domain *domain);
48
49 qreal min() { return m_min; }
50 qreal max() { return m_max; }
51 void setRange(qreal min,qreal max);
52
53 protected:
54 void setMin(const QVariant &min);
55 void setMax(const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
57 int tickCount() const;
58
59 protected:
60 qreal m_min;
61 qreal m_max;
62 qreal m_base;
63 QString m_format;
64 Q_DECLARE_PUBLIC(QLogValueAxis)
65 };
66
67 QTCOMMERCIALCHART_END_NAMESPACE
68
69 #endif // QLOGVALUEAXIS_P_H
@@ -3,12 +3,14
3 3 INCLUDEPATH += $$PWD \
4 4 $$PWD/valueaxis \
5 5 $$PWD/barcategoryaxis \
6 $$PWD/categoryaxis
6 $$PWD/categoryaxis \
7 $$PWD/logvalueaxis
7 8
8 9 DEPENDPATH += $$PWD \
9 10 $$PWD/valueaxis \
10 11 $$PWD/barcategoryaxis \
11 $$PWD/categoryaxis
12 $$PWD/categoryaxis \
13 $$PWD/logvalueaxis
12 14
13 15 SOURCES += \
14 16 $$PWD/chartaxis.cpp \
@@ -23,7 +25,10 SOURCES += \
23 25 $$PWD/barcategoryaxis/qbarcategoryaxis.cpp \
24 26 $$PWD/categoryaxis/chartcategoryaxisx.cpp \
25 27 $$PWD/categoryaxis/chartcategoryaxisy.cpp \
26 $$PWD/categoryaxis/qcategoryaxis.cpp
28 $$PWD/categoryaxis/qcategoryaxis.cpp \
29 $$PWD/logvalueaxis/chartlogvalueaxisx.cpp \
30 $$PWD/logvalueaxis/chartlogvalueaxisy.cpp \
31 $$PWD/logvalueaxis/qlogvalueaxis.cpp
27 32
28 33 PRIVATE_HEADERS += \
29 34 $$PWD/chartaxis_p.h \
@@ -38,13 +43,17 PRIVATE_HEADERS += \
38 43 $$PWD/barcategoryaxis/qbarcategoryaxis_p.h \
39 44 $$PWD/categoryaxis/chartcategoryaxisx_p.h \
40 45 $$PWD/categoryaxis/chartcategoryaxisy_p.h \
41 $$PWD/categoryaxis/qcategoryaxis_p.h
46 $$PWD/categoryaxis/qcategoryaxis_p.h \
47 $$PWD/logvalueaxis/chartlogvalueaxisx_p.h \
48 $$PWD/logvalueaxis/chartlogvalueaxisy_p.h \
49 $$PWD/logvalueaxis/qlogvalueaxis_p.h
42 50
43 51 PUBLIC_HEADERS += \
44 52 $$PWD/qabstractaxis.h \
45 53 $$PWD/valueaxis/qvalueaxis.h \
46 54 $$PWD/barcategoryaxis/qbarcategoryaxis.h \
47 $$PWD/categoryaxis/qcategoryaxis.h
55 $$PWD/categoryaxis/qcategoryaxis.h \
56 $$PWD/logvalueaxis/qlogvalueaxis.h \
48 57
49 58 !linux-arm*: {
50 59 INCLUDEPATH += \
@@ -66,3 +75,4 PRIVATE_HEADERS += \
66 75 PUBLIC_HEADERS += \
67 76 $$PWD/datetimeaxis/qdatetimeaxis.h
68 77 }
78
@@ -27,6 +27,7
27 27 #include <qmath.h>
28 28 #include <QDateTime>
29 29 #include <QValueAxis>
30 #include <QLogValueAxis>
30 31 #include <QGraphicsLayout>
31 32 #include <QFontMetrics>
32 33
@@ -438,6 +439,44 QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const Q
438 439 return labels;
439 440 }
440 441
442 QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format)
443 {
444 // Q_ASSERT(m_max > m_min);
445 // Q_ASSERT(ticks > 1);
446
447 QStringList labels;
448
449 int n = 0;
450 if (ticks > 1)
451 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
452 n++;
453
454 // QLogValueAxis *axis = qobject_cast<QLogValueAxis *>(m_chartAxis);
455
456 // QString format = axis->labelFormat();
457
458 int firstTick;
459 if (base > 1)
460 firstTick = (int)(log10(min) / log10(base));
461 else
462 firstTick = (int)(log10(max) / log10(base));
463
464 if (format.isNull()) {
465 for (int i = firstTick; i < ticks + firstTick; i++) {
466 qreal value = qPow(base, i);
467 labels << QString::number(value, 'f', n);
468 }
469 } else {
470 QByteArray array = format.toAscii();
471 for (int i = firstTick; i < ticks + firstTick; i++) {
472 qreal value = qPow(base, i);
473 labels << QString().sprintf(array, value);
474 }
475 }
476
477 return labels;
478 }
479
441 480 QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format)
442 481 {
443 482 //TODO: Q_ASSERT(m_max > m_min);
@@ -92,6 +92,7 public:
92 92
93 93 //helpers
94 94 static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format);
95 static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format);
95 96 static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format);
96 97
97 98 protected:
@@ -74,7 +74,8 public:
74 74 AxisTypeValue = 0x1,
75 75 AxisTypeBarCategory = 0x2,
76 76 AxisTypeCategory = 0x3,
77 AxisTypeDateTime = 0x4
77 AxisTypeDateTime = 0x4,
78 AxisTypeLogValue = 0x5
78 79 };
79 80
80 81 Q_DECLARE_FLAGS(AxisTypes, AxisType)
General Comments 0
You need to be logged in to leave comments. Login now