@@ -1,134 +1,137 | |||||
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 "chartlogvalueaxisx_p.h" |
|
21 | #include "chartlogvalueaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlogvalueaxis.h" |
|
23 | #include "qlogvalueaxis.h" | |
24 | #include "chartlayout_p.h" |
|
24 | #include "chartlayout_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
|
28 | #include <QDebug> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item) |
|
32 | ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item) | |
32 | : HorizontalAxis(axis, item), |
|
33 | : HorizontalAxis(axis, item), | |
33 | m_axis(axis) |
|
34 | m_axis(axis) | |
34 | { |
|
35 | { | |
35 | QObject::connect(m_axis,SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal))); |
|
36 | QObject::connect(m_axis,SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal))); | |
36 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); |
|
37 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | ChartLogValueAxisX::~ChartLogValueAxisX() |
|
40 | ChartLogValueAxisX::~ChartLogValueAxisX() | |
40 | { |
|
41 | { | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | QVector<qreal> ChartLogValueAxisX::calculateLayout() const |
|
44 | QVector<qreal> ChartLogValueAxisX::calculateLayout() const | |
44 | { |
|
45 | { | |
45 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
46 |
|
47 | |||
47 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
48 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
48 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
49 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
49 | qreal leftEdge = logMin < logMax ? logMin : logMax; |
|
50 | qreal leftEdge = logMin < logMax ? logMin : logMax; | |
50 | qreal ceilEdge = ceil(leftEdge); |
|
51 | qreal ceilEdge = ceil(leftEdge); | |
51 | int tickCount = qAbs(qRound(logMax - logMin)); |
|
52 | int tickCount = qAbs(qRound(logMax - logMin)); | |
52 | tickCount++; |
|
53 | tickCount++; | |
53 |
|
54 | |||
54 | points.resize(tickCount); |
|
55 | points.resize(tickCount); | |
55 | const QRectF &gridRect = gridGeometry(); |
|
56 | const QRectF &gridRect = gridGeometry(); | |
56 | const qreal deltaX = gridRect.width() / qAbs(logMax - logMin); |
|
57 | const qreal deltaX = gridRect.width() / qAbs(logMax - logMin); | |
57 | for (int i = 0; i < tickCount; ++i) |
|
58 | for (int i = 0; i < tickCount; ++i) | |
58 | points[i] = (ceilEdge + i) * deltaX - leftEdge * deltaX + gridRect.left(); |
|
59 | points[i] = (ceilEdge + i) * deltaX - leftEdge * deltaX + gridRect.left(); | |
59 |
|
60 | |||
60 | return points; |
|
61 | return points; | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | void ChartLogValueAxisX::updateGeometry() |
|
64 | void ChartLogValueAxisX::updateGeometry() | |
64 | { |
|
65 | { | |
65 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
66 | const QVector<qreal>& layout = ChartAxis::layout(); | |
66 | if (layout.isEmpty()) |
|
67 | if (layout.isEmpty()) | |
67 | return; |
|
68 | return; | |
68 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); |
|
69 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); | |
69 | HorizontalAxis::updateGeometry(); |
|
70 | HorizontalAxis::updateGeometry(); | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | void ChartLogValueAxisX::handleBaseChanged(qreal base) |
|
73 | void ChartLogValueAxisX::handleBaseChanged(qreal base) | |
73 | { |
|
74 | { | |
74 | Q_UNUSED(base); |
|
75 | Q_UNUSED(base); | |
|
76 | QGraphicsLayoutItem::updateGeometry(); | |||
75 | if(presenter()) presenter()->layout()->invalidate(); |
|
77 | if(presenter()) presenter()->layout()->invalidate(); | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | void ChartLogValueAxisX::handleLabelFormatChanged(const QString &format) |
|
80 | void ChartLogValueAxisX::handleLabelFormatChanged(const QString &format) | |
79 | { |
|
81 | { | |
80 | Q_UNUSED(format); |
|
82 | Q_UNUSED(format); | |
|
83 | QGraphicsLayoutItem::updateGeometry(); | |||
81 | if(presenter()) presenter()->layout()->invalidate(); |
|
84 | if(presenter()) presenter()->layout()->invalidate(); | |
82 | } |
|
85 | } | |
83 |
|
86 | |||
84 | QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
87 | QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
85 | { |
|
88 | { | |
86 | Q_UNUSED(constraint) |
|
89 | Q_UNUSED(constraint) | |
87 |
|
90 | |||
88 | QFontMetrics fn(font()); |
|
91 | QFontMetrics fn(font()); | |
89 | QSizeF sh; |
|
92 | QSizeF sh; | |
90 |
|
93 | |||
91 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
94 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
92 | QStringList ticksList; |
|
95 | QStringList ticksList; | |
93 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
96 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
94 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
97 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
95 | int tickCount = qAbs(qRound(logMax - logMin)); |
|
98 | int tickCount = qAbs(qRound(logMax - logMin)); | |
96 | tickCount++; |
|
99 | tickCount++; | |
97 |
|
100 | |||
98 | if (m_axis->max() > m_axis->min() && tickCount > 1) |
|
101 | if (m_axis->max() > m_axis->min() && tickCount > 1) | |
99 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); |
|
102 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); | |
100 | else |
|
103 | else | |
101 | ticksList.append(QString(" ")); |
|
104 | ticksList.append(QString(" ")); | |
102 | qreal width = 0; |
|
105 | qreal width = 0; | |
103 | qreal height = 0; |
|
106 | qreal height = 0; | |
104 |
|
107 | |||
105 |
|
108 | |||
106 | switch (which) { |
|
109 | switch (which) { | |
107 | case Qt::MinimumSize:{ |
|
110 | case Qt::MinimumSize:{ | |
108 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
111 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | |
109 | width = fn.averageCharWidth() * count; |
|
112 | width = fn.averageCharWidth() * count; | |
110 | height = fn.height() + labelPadding(); |
|
113 | height = fn.height() + labelPadding(); | |
111 | width = qMax(width,base.width()); |
|
114 | width = qMax(width,base.width()); | |
112 | height += base.height(); |
|
115 | height += base.height(); | |
113 | sh = QSizeF(width,height); |
|
116 | sh = QSizeF(width,height); | |
114 | break; |
|
117 | break; | |
115 | } |
|
118 | } | |
116 | case Qt::PreferredSize: { |
|
119 | case Qt::PreferredSize: { | |
117 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
120 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | |
118 | width=fn.averageCharWidth() * count; |
|
121 | width=fn.averageCharWidth() * count; | |
119 | height=fn.height()+labelPadding(); |
|
122 | height=fn.height()+labelPadding(); | |
120 | width=qMax(width,base.width()); |
|
123 | width=qMax(width,base.width()); | |
121 | height+=base.height(); |
|
124 | height+=base.height(); | |
122 | sh = QSizeF(width,height); |
|
125 | sh = QSizeF(width,height); | |
123 | break; |
|
126 | break; | |
124 | } |
|
127 | } | |
125 | default: |
|
128 | default: | |
126 | break; |
|
129 | break; | |
127 | } |
|
130 | } | |
128 |
|
131 | |||
129 | return sh; |
|
132 | return sh; | |
130 | } |
|
133 | } | |
131 |
|
134 | |||
132 | #include "moc_chartlogvalueaxisx_p.cpp" |
|
135 | #include "moc_chartlogvalueaxisx_p.cpp" | |
133 |
|
136 | |||
134 | QTCOMMERCIALCHART_END_NAMESPACE |
|
137 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,131 +1,133 | |||||
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 "chartlogvalueaxisy_p.h" |
|
21 | #include "chartlogvalueaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlogvalueaxis.h" |
|
23 | #include "qlogvalueaxis.h" | |
24 | #include "chartlayout_p.h" |
|
24 | #include "chartlayout_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item) |
|
31 | ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item) | |
32 | : VerticalAxis(axis, item), |
|
32 | : VerticalAxis(axis, item), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | QObject::connect(m_axis, SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal))); |
|
35 | QObject::connect(m_axis, SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal))); | |
36 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); |
|
36 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartLogValueAxisY::~ChartLogValueAxisY() |
|
39 | ChartLogValueAxisY::~ChartLogValueAxisY() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVector<qreal> ChartLogValueAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartLogValueAxisY::calculateLayout() const | |
44 | { |
|
44 | { | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
46 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
47 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
47 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
48 | qreal leftEdge = logMin < logMax ? logMin : logMax; |
|
48 | qreal leftEdge = logMin < logMax ? logMin : logMax; | |
49 | qreal ceilEdge = ceil(leftEdge); |
|
49 | qreal ceilEdge = ceil(leftEdge); | |
50 | int tickCount = qAbs(qRound(logMax - logMin)); |
|
50 | int tickCount = qAbs(qRound(logMax - logMin)); | |
51 | tickCount++; |
|
51 | tickCount++; | |
52 |
|
52 | |||
53 | points.resize(tickCount); |
|
53 | points.resize(tickCount); | |
54 | const QRectF &gridRect = gridGeometry(); |
|
54 | const QRectF &gridRect = gridGeometry(); | |
55 | const qreal deltaY = gridRect.height() / qAbs(logMax - logMin); |
|
55 | const qreal deltaY = gridRect.height() / qAbs(logMax - logMin); | |
56 | for (int i = 0; i < tickCount; ++i) |
|
56 | for (int i = 0; i < tickCount; ++i) | |
57 | points[i] = (ceilEdge + i) * -deltaY - leftEdge * -deltaY + gridRect.bottom(); |
|
57 | points[i] = (ceilEdge + i) * -deltaY - leftEdge * -deltaY + gridRect.bottom(); | |
58 |
|
58 | |||
59 | return points; |
|
59 | return points; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 |
|
62 | |||
63 | void ChartLogValueAxisY::updateGeometry() |
|
63 | void ChartLogValueAxisY::updateGeometry() | |
64 | { |
|
64 | { | |
65 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
65 | const QVector<qreal> &layout = ChartAxis::layout(); | |
66 | if (layout.isEmpty()) |
|
66 | if (layout.isEmpty()) | |
67 | return; |
|
67 | return; | |
68 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); |
|
68 | setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); | |
69 | VerticalAxis::updateGeometry(); |
|
69 | VerticalAxis::updateGeometry(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void ChartLogValueAxisY::handleBaseChanged(qreal base) |
|
72 | void ChartLogValueAxisY::handleBaseChanged(qreal base) | |
73 | { |
|
73 | { | |
74 | Q_UNUSED(base); |
|
74 | Q_UNUSED(base); | |
|
75 | QGraphicsLayoutItem::updateGeometry(); | |||
75 | if(presenter()) presenter()->layout()->invalidate(); |
|
76 | if(presenter()) presenter()->layout()->invalidate(); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void ChartLogValueAxisY::handleLabelFormatChanged(const QString &format) |
|
79 | void ChartLogValueAxisY::handleLabelFormatChanged(const QString &format) | |
79 | { |
|
80 | { | |
80 | Q_UNUSED(format); |
|
81 | Q_UNUSED(format); | |
|
82 | QGraphicsLayoutItem::updateGeometry(); | |||
81 | if(presenter()) presenter()->layout()->invalidate(); |
|
83 | if(presenter()) presenter()->layout()->invalidate(); | |
82 | } |
|
84 | } | |
83 |
|
85 | |||
84 | QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
86 | QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
85 | { |
|
87 | { | |
86 | Q_UNUSED(constraint) |
|
88 | Q_UNUSED(constraint) | |
87 |
|
89 | |||
88 | QFontMetrics fn(font()); |
|
90 | QFontMetrics fn(font()); | |
89 | QSizeF sh; |
|
91 | QSizeF sh; | |
90 |
|
92 | |||
91 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
93 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
92 | QStringList ticksList; |
|
94 | QStringList ticksList; | |
93 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); |
|
95 | qreal logMax = log10(m_axis->max()) / log10(m_axis->base()); | |
94 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); |
|
96 | qreal logMin = log10(m_axis->min()) / log10(m_axis->base()); | |
95 | int tickCount = qAbs(qRound(logMax - logMin)); |
|
97 | int tickCount = qAbs(qRound(logMax - logMin)); | |
96 | tickCount++; |
|
98 | tickCount++; | |
97 | if (m_axis->max() > m_axis->min() && tickCount > 1) |
|
99 | if (m_axis->max() > m_axis->min() && tickCount > 1) | |
98 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); |
|
100 | ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat()); | |
99 | else |
|
101 | else | |
100 | ticksList.append(QString(" ")); |
|
102 | ticksList.append(QString(" ")); | |
101 | qreal width = 0; |
|
103 | qreal width = 0; | |
102 | qreal height = 0; |
|
104 | qreal height = 0; | |
103 |
|
105 | |||
104 | switch (which) { |
|
106 | switch (which) { | |
105 | case Qt::MinimumSize: { |
|
107 | case Qt::MinimumSize: { | |
106 | width = fn.boundingRect("...").width() + labelPadding(); |
|
108 | width = fn.boundingRect("...").width() + labelPadding(); | |
107 | width += base.width(); |
|
109 | width += base.width(); | |
108 | height = fn.height(); |
|
110 | height = fn.height(); | |
109 | height = qMax(height,base.height()); |
|
111 | height = qMax(height,base.height()); | |
110 | sh = QSizeF(width,height); |
|
112 | sh = QSizeF(width,height); | |
111 | break; |
|
113 | break; | |
112 | } |
|
114 | } | |
113 | case Qt::PreferredSize: { |
|
115 | case Qt::PreferredSize: { | |
114 | int count = qMax(ticksList.first().count() , ticksList.last().count()); |
|
116 | int count = qMax(ticksList.first().count() , ticksList.last().count()); | |
115 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance |
|
117 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance | |
116 | width += base.width(); |
|
118 | width += base.width(); | |
117 | height = fn.height() * ticksList.count(); |
|
119 | height = fn.height() * ticksList.count(); | |
118 | height = qMax(height,base.height()); |
|
120 | height = qMax(height,base.height()); | |
119 | sh = QSizeF(width,height); |
|
121 | sh = QSizeF(width,height); | |
120 | break; |
|
122 | break; | |
121 | } |
|
123 | } | |
122 | default: |
|
124 | default: | |
123 | break; |
|
125 | break; | |
124 | } |
|
126 | } | |
125 |
|
127 | |||
126 | return sh; |
|
128 | return sh; | |
127 | } |
|
129 | } | |
128 |
|
130 | |||
129 | #include "moc_chartlogvalueaxisy_p.cpp" |
|
131 | #include "moc_chartlogvalueaxisy_p.cpp" | |
130 |
|
132 | |||
131 | QTCOMMERCIALCHART_END_NAMESPACE |
|
133 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,325 +1,325 | |||||
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 "qlogvalueaxis.h" |
|
21 | #include "qlogvalueaxis.h" | |
22 | #include "qlogvalueaxis_p.h" |
|
22 | #include "qlogvalueaxis_p.h" | |
23 | #include "chartlogvalueaxisx_p.h" |
|
23 | #include "chartlogvalueaxisx_p.h" | |
24 | #include "chartlogvalueaxisy_p.h" |
|
24 | #include "chartlogvalueaxisy_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include <float.h> |
|
26 | #include <float.h> | |
27 | #include <cmath> |
|
27 | #include <cmath> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QLogValueAxis |
|
31 | \class QLogValueAxis | |
32 | \brief The QLogValueAxis class is used for manipulating chart's axis. |
|
32 | \brief The QLogValueAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \qmlclass DateTimeAxis QLogValueAxis |
|
37 | \qmlclass DateTimeAxis QLogValueAxis | |
38 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
38 | \brief The DateTimeAxis element is used for manipulating chart's axes | |
39 | \inherits AbstractAxis |
|
39 | \inherits AbstractAxis | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \property QLogValueAxis::min |
|
43 | \property QLogValueAxis::min | |
44 | Defines the minimum value on the axis. |
|
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. |
|
45 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
46 | */ |
|
46 | */ | |
47 | /*! |
|
47 | /*! | |
48 | \qmlproperty real ValuesAxis::min |
|
48 | \qmlproperty real ValuesAxis::min | |
49 | Defines the minimum value on the axis. |
|
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. |
|
50 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \property QLogValueAxis::max |
|
54 | \property QLogValueAxis::max | |
55 | Defines the maximum value on the axis. |
|
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. |
|
56 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
57 | */ |
|
57 | */ | |
58 | /*! |
|
58 | /*! | |
59 | \qmlproperty real ValuesAxis::max |
|
59 | \qmlproperty real ValuesAxis::max | |
60 | Defines the maximum value on the axis. |
|
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. |
|
61 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \fn void QLogValueAxis::minChanged(qreal min) |
|
65 | \fn void QLogValueAxis::minChanged(qreal min) | |
66 | Axis emits signal when \a min of axis has changed. |
|
66 | Axis emits signal when \a min of axis has changed. | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlsignal ValuesAxis::onMinChanged(qreal min) |
|
69 | \qmlsignal ValuesAxis::onMinChanged(qreal min) | |
70 | Axis emits signal when \a min of axis has changed. |
|
70 | Axis emits signal when \a min of axis has changed. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \fn void QLogValueAxis::maxChanged(qreal max) |
|
74 | \fn void QLogValueAxis::maxChanged(qreal max) | |
75 | Axis emits signal when \a max of axis has changed. |
|
75 | Axis emits signal when \a max of axis has changed. | |
76 | */ |
|
76 | */ | |
77 | /*! |
|
77 | /*! | |
78 | \qmlsignal ValuesAxis::onMaxChanged(qreal max) |
|
78 | \qmlsignal ValuesAxis::onMaxChanged(qreal max) | |
79 | Axis emits signal when \a max of axis has changed. |
|
79 | Axis emits signal when \a max of axis has changed. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) |
|
83 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) | |
84 | Axis emits signal when \a min or \a max of axis has changed. |
|
84 | Axis emits signal when \a min or \a max of axis has changed. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Constructs an axis object which is a child of \a parent. |
|
88 | Constructs an axis object which is a child of \a parent. | |
89 | */ |
|
89 | */ | |
90 | QLogValueAxis::QLogValueAxis(QObject *parent) : |
|
90 | QLogValueAxis::QLogValueAxis(QObject *parent) : | |
91 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) |
|
91 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) | |
92 | { |
|
92 | { | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \internal |
|
97 | \internal | |
98 | */ |
|
98 | */ | |
99 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
99 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) | |
100 | { |
|
100 | { | |
101 |
|
101 | |||
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Destroys the object |
|
105 | Destroys the object | |
106 | */ |
|
106 | */ | |
107 | QLogValueAxis::~QLogValueAxis() |
|
107 | QLogValueAxis::~QLogValueAxis() | |
108 | { |
|
108 | { | |
109 | Q_D(QLogValueAxis); |
|
109 | Q_D(QLogValueAxis); | |
110 | if (d->m_chart) |
|
110 | if (d->m_chart) | |
111 | d->m_chart->removeAxis(this); |
|
111 | d->m_chart->removeAxis(this); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void QLogValueAxis::setMin(qreal min) |
|
114 | void QLogValueAxis::setMin(qreal min) | |
115 | { |
|
115 | { | |
116 | Q_D(QLogValueAxis); |
|
116 | Q_D(QLogValueAxis); | |
117 | setRange(min, qMax(d->m_max, min)); |
|
117 | setRange(min, qMax(d->m_max, min)); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | qreal QLogValueAxis::min() const |
|
120 | qreal QLogValueAxis::min() const | |
121 | { |
|
121 | { | |
122 | Q_D(const QLogValueAxis); |
|
122 | Q_D(const QLogValueAxis); | |
123 | return d->m_min; |
|
123 | return d->m_min; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void QLogValueAxis::setMax(qreal max) |
|
126 | void QLogValueAxis::setMax(qreal max) | |
127 | { |
|
127 | { | |
128 | Q_D(QLogValueAxis); |
|
128 | Q_D(QLogValueAxis); | |
129 | setRange(qMin(d->m_min, max), max); |
|
129 | setRange(qMin(d->m_min, max), max); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | qreal QLogValueAxis::max() const |
|
132 | qreal QLogValueAxis::max() const | |
133 | { |
|
133 | { | |
134 | Q_D(const QLogValueAxis); |
|
134 | Q_D(const QLogValueAxis); | |
135 | return d->m_max; |
|
135 | return d->m_max; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Sets range from \a min to \a max on the axis. |
|
139 | Sets range from \a min to \a max on the axis. | |
140 | If min is greater than max then this function returns without making any changes. |
|
140 | If min is greater than max then this function returns without making any changes. | |
141 | */ |
|
141 | */ | |
142 | void QLogValueAxis::setRange(qreal min, qreal max) |
|
142 | void QLogValueAxis::setRange(qreal min, qreal max) | |
143 | { |
|
143 | { | |
144 | Q_D(QLogValueAxis); |
|
144 | Q_D(QLogValueAxis); | |
145 | bool changed = false; |
|
145 | bool changed = false; | |
146 |
|
146 | |||
147 | if (min > max) |
|
147 | if (min > max) | |
148 | return; |
|
148 | return; | |
149 |
|
149 | |||
150 | if (min > 0) { |
|
150 | if (min > 0) { | |
151 | if (!qFuzzyCompare(d->m_min, min)) { |
|
151 | if (!qFuzzyCompare(d->m_min, min)) { | |
152 | d->m_min = min; |
|
152 | d->m_min = min; | |
153 | changed = true; |
|
153 | changed = true; | |
154 | emit minChanged(min); |
|
154 | emit minChanged(min); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | if (!qFuzzyCompare(d->m_max, max)) { |
|
157 | if (!qFuzzyCompare(d->m_max, max)) { | |
158 | d->m_max = max; |
|
158 | d->m_max = max; | |
159 | changed = true; |
|
159 | changed = true; | |
160 | emit maxChanged(max); |
|
160 | emit maxChanged(max); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | if (changed) { |
|
163 | if (changed) { | |
164 | emit rangeChanged(min, max); |
|
164 | emit rangeChanged(min, max); | |
165 | emit d->rangeChanged(min,max); |
|
165 | emit d->rangeChanged(min,max); | |
166 | } |
|
166 | } | |
167 | } |
|
167 | } | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void QLogValueAxis::setLabelFormat(const QString &format) |
|
170 | void QLogValueAxis::setLabelFormat(const QString &format) | |
171 | { |
|
171 | { | |
172 | Q_D(QLogValueAxis); |
|
172 | Q_D(QLogValueAxis); | |
173 | d->m_format = format; |
|
173 | d->m_format = format; | |
174 | emit labelFormatChanged(format); |
|
174 | emit labelFormatChanged(format); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QString QLogValueAxis::labelFormat() const |
|
177 | QString QLogValueAxis::labelFormat() const | |
178 | { |
|
178 | { | |
179 | Q_D(const QLogValueAxis); |
|
179 | Q_D(const QLogValueAxis); | |
180 | return d->m_format; |
|
180 | return d->m_format; | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void QLogValueAxis::setBase(qreal base) |
|
183 | void QLogValueAxis::setBase(qreal base) | |
184 | { |
|
184 | { | |
185 | // check if base is correct |
|
185 | // check if base is correct | |
186 | if (qFuzzyCompare(base, 1)) |
|
186 | if (qFuzzyCompare(base, 1)) | |
187 | return; |
|
187 | return; | |
188 |
|
188 | |||
189 | if (base > 0) { |
|
189 | if (base > 0) { | |
190 | Q_D(QLogValueAxis); |
|
190 | Q_D(QLogValueAxis); | |
191 | d->m_base = base; |
|
191 | d->m_base = base; | |
192 | emit baseChanged(base); |
|
192 | emit baseChanged(base); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | qreal QLogValueAxis::base() const |
|
196 | qreal QLogValueAxis::base() const | |
197 | { |
|
197 | { | |
198 | Q_D(const QLogValueAxis); |
|
198 | Q_D(const QLogValueAxis); | |
199 | return d->m_base; |
|
199 | return d->m_base; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | Returns the type of the axis |
|
203 | Returns the type of the axis | |
204 | */ |
|
204 | */ | |
205 | QAbstractAxis::AxisType QLogValueAxis::type() const |
|
205 | QAbstractAxis::AxisType QLogValueAxis::type() const | |
206 | { |
|
206 | { | |
207 | return AxisTypeLogValue; |
|
207 | return AxisTypeLogValue; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
210 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
211 |
|
211 | |||
212 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) |
|
212 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) | |
213 | : QAbstractAxisPrivate(q), |
|
213 | : QAbstractAxisPrivate(q), | |
214 | m_min(1), |
|
214 | m_min(1), | |
215 | m_max(1), |
|
215 | m_max(1), | |
216 | m_base(10), |
|
216 | m_base(10), | |
217 | m_format(QString::null) |
|
217 | m_format(QString::null) | |
218 | { |
|
218 | { | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | QLogValueAxisPrivate::~QLogValueAxisPrivate() |
|
221 | QLogValueAxisPrivate::~QLogValueAxisPrivate() | |
222 | { |
|
222 | { | |
223 |
|
223 | |||
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void QLogValueAxisPrivate::setMin(const QVariant &min) |
|
226 | void QLogValueAxisPrivate::setMin(const QVariant &min) | |
227 | { |
|
227 | { | |
228 | Q_Q(QLogValueAxis); |
|
228 | Q_Q(QLogValueAxis); | |
229 | bool ok; |
|
229 | bool ok; | |
230 | qreal value = min.toReal(&ok); |
|
230 | qreal value = min.toReal(&ok); | |
231 | if (ok) |
|
231 | if (ok) | |
232 | q->setMin(value); |
|
232 | q->setMin(value); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void QLogValueAxisPrivate::setMax(const QVariant &max) |
|
235 | void QLogValueAxisPrivate::setMax(const QVariant &max) | |
236 | { |
|
236 | { | |
237 |
|
237 | |||
238 | Q_Q(QLogValueAxis); |
|
238 | Q_Q(QLogValueAxis); | |
239 | bool ok; |
|
239 | bool ok; | |
240 | qreal value = max.toReal(&ok); |
|
240 | qreal value = max.toReal(&ok); | |
241 | if (ok) |
|
241 | if (ok) | |
242 | q->setMax(value); |
|
242 | q->setMax(value); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
245 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
246 | { |
|
246 | { | |
247 | Q_Q(QLogValueAxis); |
|
247 | Q_Q(QLogValueAxis); | |
248 | bool ok1; |
|
248 | bool ok1; | |
249 | bool ok2; |
|
249 | bool ok2; | |
250 | qreal value1 = min.toReal(&ok1); |
|
250 | qreal value1 = min.toReal(&ok1); | |
251 | qreal value2 = max.toReal(&ok2); |
|
251 | qreal value2 = max.toReal(&ok2); | |
252 | if (ok1 && ok2) |
|
252 | if (ok1 && ok2) | |
253 | q->setRange(value1, value2); |
|
253 | q->setRange(value1, value2); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) |
|
256 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) | |
257 | { |
|
257 | { | |
258 | Q_Q(QLogValueAxis); |
|
258 | Q_Q(QLogValueAxis); | |
259 | bool changed = false; |
|
259 | bool changed = false; | |
260 |
|
260 | |||
261 | if (min > max) |
|
261 | if (min > max) | |
262 | return; |
|
262 | return; | |
263 |
|
263 | |||
264 | if (min > 0) { |
|
264 | if (min > 0) { | |
265 | if (!qFuzzyCompare(m_min, min)) { |
|
265 | if (!qFuzzyCompare(m_min, min)) { | |
266 | m_min = min; |
|
266 | m_min = min; | |
267 | changed = true; |
|
267 | changed = true; | |
268 | emit q->minChanged(min); |
|
268 | emit q->minChanged(min); | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | if (!qFuzzyCompare(m_max, max)) { |
|
271 | if (!qFuzzyCompare(m_max, max)) { | |
272 | m_max = max; |
|
272 | m_max = max; | |
273 | changed = true; |
|
273 | changed = true; | |
274 | emit q->maxChanged(max); |
|
274 | emit q->maxChanged(max); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | if (changed) { |
|
277 | if (changed) { | |
278 | emit q->rangeChanged(min, max); |
|
|||
279 | emit rangeChanged(min,max); |
|
278 | emit rangeChanged(min,max); | |
|
279 | emit q->rangeChanged(min, max); | |||
280 | } |
|
280 | } | |
281 | } |
|
281 | } | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
284 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
285 | { |
|
285 | { | |
286 | Q_Q(QLogValueAxis); |
|
286 | Q_Q(QLogValueAxis); | |
287 | ChartAxis* axis(0); |
|
287 | ChartAxis* axis(0); | |
288 | if (orientation() == Qt::Vertical) |
|
288 | if (orientation() == Qt::Vertical) | |
289 | axis = new ChartLogValueAxisY(q,parent); |
|
289 | axis = new ChartLogValueAxisY(q,parent); | |
290 | if (orientation() == Qt::Horizontal) |
|
290 | if (orientation() == Qt::Horizontal) | |
291 | axis = new ChartLogValueAxisX(q,parent); |
|
291 | axis = new ChartLogValueAxisX(q,parent); | |
292 |
|
292 | |||
293 | m_item.reset(axis); |
|
293 | m_item.reset(axis); | |
294 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
294 | QAbstractAxisPrivate::initializeGraphics(parent); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 |
|
297 | |||
298 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
298 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
299 | { |
|
299 | { | |
300 | if (orientation() == Qt::Vertical) { |
|
300 | if (orientation() == Qt::Vertical) { | |
301 | if(!qFuzzyCompare(m_max, m_min)) { |
|
301 | if(!qFuzzyCompare(m_max, m_min)) { | |
302 | domain->setRangeY(m_min, m_max); |
|
302 | domain->setRangeY(m_min, m_max); | |
303 | } |
|
303 | } | |
304 | else if ( domain->minY() > 0) { |
|
304 | else if ( domain->minY() > 0) { | |
305 | setRange(domain->minY(), domain->maxY()); |
|
305 | setRange(domain->minY(), domain->maxY()); | |
306 | } else { |
|
306 | } else { | |
307 | domain->setRangeY(m_min, domain->maxY()); |
|
307 | domain->setRangeY(m_min, domain->maxY()); | |
308 | } |
|
308 | } | |
309 | } |
|
309 | } | |
310 | if (orientation() == Qt::Horizontal) { |
|
310 | if (orientation() == Qt::Horizontal) { | |
311 | if(!qFuzzyCompare(m_max, m_min)) { |
|
311 | if(!qFuzzyCompare(m_max, m_min)) { | |
312 | domain->setRangeX(m_min, m_max); |
|
312 | domain->setRangeX(m_min, m_max); | |
313 | } |
|
313 | } | |
314 | else if (domain->minX() > 0){ |
|
314 | else if (domain->minX() > 0){ | |
315 | setRange(domain->minX(), domain->maxX()); |
|
315 | setRange(domain->minX(), domain->maxX()); | |
316 | } else { |
|
316 | } else { | |
317 | domain->setRangeX(m_min, domain->maxX()); |
|
317 | domain->setRangeX(m_min, domain->maxX()); | |
318 | } |
|
318 | } | |
319 | } |
|
319 | } | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | #include "moc_qlogvalueaxis.cpp" |
|
322 | #include "moc_qlogvalueaxis.cpp" | |
323 | #include "moc_qlogvalueaxis_p.cpp" |
|
323 | #include "moc_qlogvalueaxis_p.cpp" | |
324 |
|
324 | |||
325 | QTCOMMERCIALCHART_END_NAMESPACE |
|
325 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,129 +1,131 | |||||
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 "chartvalueaxisx_p.h" |
|
21 | #include "chartvalueaxisx_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "chartlayout_p.h" |
|
25 | #include "chartlayout_p.h" | |
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <QFontMetrics> |
|
27 | #include <QFontMetrics> | |
28 | #include <qmath.h> |
|
28 | #include <qmath.h> | |
29 | #include <QDebug> |
|
29 | #include <QDebug> | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item ) |
|
34 | ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item ) | |
35 | : HorizontalAxis(axis, item), |
|
35 | : HorizontalAxis(axis, item), | |
36 | m_axis(axis) |
|
36 | m_axis(axis) | |
37 | { |
|
37 | { | |
38 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); |
|
38 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); | |
39 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); |
|
39 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | ChartValueAxisX::~ChartValueAxisX() |
|
42 | ChartValueAxisX::~ChartValueAxisX() | |
43 | { |
|
43 | { | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QVector<qreal> ChartValueAxisX::calculateLayout() const |
|
46 | QVector<qreal> ChartValueAxisX::calculateLayout() const | |
47 | { |
|
47 | { | |
48 | int tickCount = m_axis->tickCount(); |
|
48 | int tickCount = m_axis->tickCount(); | |
49 |
|
49 | |||
50 | Q_ASSERT(tickCount >= 2); |
|
50 | Q_ASSERT(tickCount >= 2); | |
51 |
|
51 | |||
52 | QVector<qreal> points; |
|
52 | QVector<qreal> points; | |
53 | points.resize(tickCount); |
|
53 | points.resize(tickCount); | |
54 |
|
54 | |||
55 | const QRectF &gridRect = gridGeometry(); |
|
55 | const QRectF &gridRect = gridGeometry(); | |
56 | const qreal deltaX = gridRect.width() / (tickCount - 1); |
|
56 | const qreal deltaX = gridRect.width() / (tickCount - 1); | |
57 | for (int i = 0; i < tickCount; ++i) { |
|
57 | for (int i = 0; i < tickCount; ++i) { | |
58 | points[i] = i * deltaX + gridRect.left(); |
|
58 | points[i] = i * deltaX + gridRect.left(); | |
59 | } |
|
59 | } | |
60 | return points; |
|
60 | return points; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartValueAxisX::updateGeometry() |
|
63 | void ChartValueAxisX::updateGeometry() | |
64 | { |
|
64 | { | |
65 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
65 | const QVector<qreal>& layout = ChartAxis::layout(); | |
66 | if (layout.isEmpty()) |
|
66 | if (layout.isEmpty()) | |
67 | return; |
|
67 | return; | |
68 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); |
|
68 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
69 | HorizontalAxis::updateGeometry(); |
|
69 | HorizontalAxis::updateGeometry(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void ChartValueAxisX::handleTickCountChanged(int tick) |
|
72 | void ChartValueAxisX::handleTickCountChanged(int tick) | |
73 | { |
|
73 | { | |
74 | Q_UNUSED(tick); |
|
74 | Q_UNUSED(tick); | |
|
75 | QGraphicsLayoutItem::updateGeometry(); | |||
75 | if(presenter()) presenter()->layout()->invalidate(); |
|
76 | if(presenter()) presenter()->layout()->invalidate(); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void ChartValueAxisX::handleLabelFormatChanged(const QString &format) |
|
79 | void ChartValueAxisX::handleLabelFormatChanged(const QString &format) | |
79 | { |
|
80 | { | |
80 | Q_UNUSED(format); |
|
81 | Q_UNUSED(format); | |
|
82 | QGraphicsLayoutItem::updateGeometry(); | |||
81 | if(presenter()) presenter()->layout()->invalidate(); |
|
83 | if(presenter()) presenter()->layout()->invalidate(); | |
82 | } |
|
84 | } | |
83 |
|
85 | |||
84 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
86 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
85 | { |
|
87 | { | |
86 | Q_UNUSED(constraint) |
|
88 | Q_UNUSED(constraint) | |
87 |
|
89 | |||
88 | QFontMetrics fn(font()); |
|
90 | QFontMetrics fn(font()); | |
89 | QSizeF sh; |
|
91 | QSizeF sh; | |
90 |
|
92 | |||
91 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
93 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
92 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
|
94 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
93 | qreal width = 0; |
|
95 | qreal width = 0; | |
94 | qreal height = 0; |
|
96 | qreal height = 0; | |
95 |
|
97 | |||
96 | int count = 1; |
|
98 | int count = 1; | |
97 |
|
99 | |||
98 | if(!ticksList.empty()) { |
|
100 | if(!ticksList.empty()) { | |
99 | count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
101 | count = qMax(ticksList.last().count(),ticksList.first().count()); | |
100 | } |
|
102 | } | |
101 |
|
103 | |||
102 | switch (which) { |
|
104 | switch (which) { | |
103 | case Qt::MinimumSize:{ |
|
105 | case Qt::MinimumSize:{ | |
104 | count = qMin(count,5); |
|
106 | count = qMin(count,5); | |
105 | width = fn.averageCharWidth() * count; |
|
107 | width = fn.averageCharWidth() * count; | |
106 | height = fn.height() + labelPadding(); |
|
108 | height = fn.height() + labelPadding(); | |
107 | width = qMax(width,base.width()); |
|
109 | width = qMax(width,base.width()); | |
108 | height += base.height(); |
|
110 | height += base.height(); | |
109 | sh = QSizeF(width,height); |
|
111 | sh = QSizeF(width,height); | |
110 | break; |
|
112 | break; | |
111 | } |
|
113 | } | |
112 | case Qt::PreferredSize:{ |
|
114 | case Qt::PreferredSize:{ | |
113 | width=fn.averageCharWidth() * count; |
|
115 | width=fn.averageCharWidth() * count; | |
114 | height=fn.height()+labelPadding(); |
|
116 | height=fn.height()+labelPadding(); | |
115 | width=qMax(width,base.width()); |
|
117 | width=qMax(width,base.width()); | |
116 | height+=base.height(); |
|
118 | height+=base.height(); | |
117 | sh = QSizeF(width,height); |
|
119 | sh = QSizeF(width,height); | |
118 | break; |
|
120 | break; | |
119 | } |
|
121 | } | |
120 | default: |
|
122 | default: | |
121 | break; |
|
123 | break; | |
122 | } |
|
124 | } | |
123 |
|
125 | |||
124 | return sh; |
|
126 | return sh; | |
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | #include "moc_chartvalueaxisx_p.cpp" |
|
129 | #include "moc_chartvalueaxisx_p.cpp" | |
128 |
|
130 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,128 +1,130 | |||||
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 "chartvalueaxisy_p.h" |
|
21 | #include "chartvalueaxisy_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "chartlayout_p.h" |
|
25 | #include "chartlayout_p.h" | |
26 | #include <QGraphicsLayout> |
|
26 | #include <QGraphicsLayout> | |
27 | #include <QFontMetrics> |
|
27 | #include <QFontMetrics> | |
28 | #include <qmath.h> |
|
28 | #include <qmath.h> | |
29 | #include <QDebug> |
|
29 | #include <QDebug> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item) |
|
33 | ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item) | |
34 | : VerticalAxis(axis, item), |
|
34 | : VerticalAxis(axis, item), | |
35 | m_axis(axis) |
|
35 | m_axis(axis) | |
36 | { |
|
36 | { | |
37 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); |
|
37 | QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int))); | |
38 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); |
|
38 | QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString))); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartValueAxisY::~ChartValueAxisY() |
|
41 | ChartValueAxisY::~ChartValueAxisY() | |
42 | { |
|
42 | { | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QVector<qreal> ChartValueAxisY::calculateLayout() const |
|
45 | QVector<qreal> ChartValueAxisY::calculateLayout() const | |
46 | { |
|
46 | { | |
47 | int tickCount = m_axis->tickCount(); |
|
47 | int tickCount = m_axis->tickCount(); | |
48 |
|
48 | |||
49 | Q_ASSERT(tickCount >= 2); |
|
49 | Q_ASSERT(tickCount >= 2); | |
50 |
|
50 | |||
51 | QVector<qreal> points; |
|
51 | QVector<qreal> points; | |
52 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
53 |
|
53 | |||
54 | const QRectF &gridRect = gridGeometry(); |
|
54 | const QRectF &gridRect = gridGeometry(); | |
55 |
|
55 | |||
56 | const qreal deltaY = gridRect.height() / (tickCount - 1); |
|
56 | const qreal deltaY = gridRect.height() / (tickCount - 1); | |
57 | for (int i = 0; i < tickCount; ++i) { |
|
57 | for (int i = 0; i < tickCount; ++i) { | |
58 | points[i] = i * -deltaY + gridRect.bottom(); |
|
58 | points[i] = i * -deltaY + gridRect.bottom(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | return points; |
|
61 | return points; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void ChartValueAxisY::updateGeometry() |
|
64 | void ChartValueAxisY::updateGeometry() | |
65 | { |
|
65 | { | |
66 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
66 | const QVector<qreal> &layout = ChartAxis::layout(); | |
67 | if (layout.isEmpty()) |
|
67 | if (layout.isEmpty()) | |
68 | return; |
|
68 | return; | |
69 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); |
|
69 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
70 | VerticalAxis::updateGeometry(); |
|
70 | VerticalAxis::updateGeometry(); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartValueAxisY::handleTickCountChanged(int tick) |
|
73 | void ChartValueAxisY::handleTickCountChanged(int tick) | |
74 | { |
|
74 | { | |
75 | Q_UNUSED(tick); |
|
75 | Q_UNUSED(tick); | |
|
76 | QGraphicsLayoutItem::updateGeometry(); | |||
76 | if(presenter()) presenter()->layout()->invalidate(); |
|
77 | if(presenter()) presenter()->layout()->invalidate(); | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | void ChartValueAxisY::handleLabelFormatChanged(const QString &format) |
|
80 | void ChartValueAxisY::handleLabelFormatChanged(const QString &format) | |
80 | { |
|
81 | { | |
81 | Q_UNUSED(format); |
|
82 | Q_UNUSED(format); | |
|
83 | QGraphicsLayoutItem::updateGeometry(); | |||
82 | if(presenter()) presenter()->layout()->invalidate(); |
|
84 | if(presenter()) presenter()->layout()->invalidate(); | |
83 | } |
|
85 | } | |
84 |
|
86 | |||
85 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
87 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
86 | { |
|
88 | { | |
87 | Q_UNUSED(constraint) |
|
89 | Q_UNUSED(constraint) | |
88 |
|
90 | |||
89 | QFontMetrics fn(font()); |
|
91 | QFontMetrics fn(font()); | |
90 | QSizeF sh; |
|
92 | QSizeF sh; | |
91 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
93 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
92 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
|
94 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
93 | qreal width = 0; |
|
95 | qreal width = 0; | |
94 | qreal height = 0; |
|
96 | qreal height = 0; | |
95 |
|
97 | |||
96 | int count = 1; |
|
98 | int count = 1; | |
97 |
|
99 | |||
98 | if(!ticksList.empty()){ |
|
100 | if(!ticksList.empty()){ | |
99 | count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
101 | count = qMax(ticksList.last().count(),ticksList.first().count()); | |
100 | } |
|
102 | } | |
101 |
|
103 | |||
102 | switch (which) { |
|
104 | switch (which) { | |
103 | case Qt::MinimumSize: { |
|
105 | case Qt::MinimumSize: { | |
104 | width = fn.boundingRect("...").width() + labelPadding(); |
|
106 | width = fn.boundingRect("...").width() + labelPadding(); | |
105 | width += base.width(); |
|
107 | width += base.width(); | |
106 | height = fn.height(); |
|
108 | height = fn.height(); | |
107 | height = qMax(height,base.height()); |
|
109 | height = qMax(height,base.height()); | |
108 | sh = QSizeF(width,height); |
|
110 | sh = QSizeF(width,height); | |
109 | break; |
|
111 | break; | |
110 | } |
|
112 | } | |
111 | case Qt::PreferredSize: |
|
113 | case Qt::PreferredSize: | |
112 | { |
|
114 | { | |
113 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance |
|
115 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance | |
114 | width += base.width(); |
|
116 | width += base.width(); | |
115 | height = fn.height() * ticksList.count(); |
|
117 | height = fn.height() * ticksList.count(); | |
116 | height = qMax(height,base.height()); |
|
118 | height = qMax(height,base.height()); | |
117 | sh = QSizeF(width,height); |
|
119 | sh = QSizeF(width,height); | |
118 | break; |
|
120 | break; | |
119 | } |
|
121 | } | |
120 | default: |
|
122 | default: | |
121 | break; |
|
123 | break; | |
122 | } |
|
124 | } | |
123 | return sh; |
|
125 | return sh; | |
124 | } |
|
126 | } | |
125 |
|
127 | |||
126 | #include "moc_chartvalueaxisy_p.cpp" |
|
128 | #include "moc_chartvalueaxisy_p.cpp" | |
127 |
|
129 | |||
128 | QTCOMMERCIALCHART_END_NAMESPACE |
|
130 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now