@@ -1,526 +1,527 | |||||
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 "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartlayout_p.h" |
|
25 | #include "chartlayout_p.h" | |
26 | #include "abstractdomain_p.h" |
|
26 | #include "abstractdomain_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDateTime> |
|
28 | #include <QDateTime> | |
29 | #include <QValueAxis> |
|
29 | #include <QValueAxis> | |
30 | #include <QLogValueAxis> |
|
30 | #include <QLogValueAxis> | |
31 | #include <QGraphicsLayout> |
|
31 | #include <QGraphicsLayout> | |
32 | #include <QFontMetrics> |
|
32 | #include <QFontMetrics> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) |
|
36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | |
37 | : ChartElement(item), |
|
37 | : ChartElement(item), | |
38 | m_axis(axis), |
|
38 | m_axis(axis), | |
39 | m_labelsAngle(0), |
|
39 | m_labelsAngle(0), | |
40 | m_grid(new QGraphicsItemGroup(item)), |
|
40 | m_grid(new QGraphicsItemGroup(item)), | |
41 | m_arrow(new QGraphicsItemGroup(item)), |
|
41 | m_arrow(new QGraphicsItemGroup(item)), | |
42 | m_shades(new QGraphicsItemGroup(item)), |
|
42 | m_shades(new QGraphicsItemGroup(item)), | |
43 | m_labels(new QGraphicsItemGroup(item)), |
|
43 | m_labels(new QGraphicsItemGroup(item)), | |
44 | m_title(new QGraphicsSimpleTextItem(item)), |
|
44 | m_title(new QGraphicsSimpleTextItem(item)), | |
45 | m_animation(0), |
|
45 | m_animation(0), | |
46 | m_labelPadding(5), |
|
46 | m_labelPadding(5), | |
47 | m_intervalAxis(intervalAxis) |
|
47 | m_intervalAxis(intervalAxis) | |
48 | { |
|
48 | { | |
49 | Q_ASSERT(item); |
|
49 | Q_ASSERT(item); | |
50 | //initial initialization |
|
50 | //initial initialization | |
51 | m_arrow->setHandlesChildEvents(false); |
|
51 | m_arrow->setHandlesChildEvents(false); | |
52 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
52 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
53 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
53 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
54 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
54 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
55 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
55 | m_grid->setZValue(ChartPresenter::GridZValue); | |
56 | m_title->setZValue(ChartPresenter::GridZValue); |
|
56 | m_title->setZValue(ChartPresenter::GridZValue); | |
57 | handleVisibleChanged(m_axis->isVisible()); |
|
57 | handleVisibleChanged(m_axis->isVisible()); | |
58 | connectSlots(); |
|
58 | connectSlots(); | |
59 |
|
59 | |||
60 | setFlag(QGraphicsItem::ItemHasNoContents,true); |
|
60 | setFlag(QGraphicsItem::ItemHasNoContents,true); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartAxis::connectSlots() |
|
63 | void ChartAxis::connectSlots() | |
64 | { |
|
64 | { | |
65 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); |
|
65 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); | |
66 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); |
|
66 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); | |
67 | QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); |
|
67 | QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); | |
68 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); |
|
68 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); | |
69 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); |
|
69 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); | |
70 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); |
|
70 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); | |
71 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); |
|
71 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); | |
72 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); |
|
72 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); | |
73 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
73 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); | |
74 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); |
|
74 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); | |
75 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); |
|
75 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); | |
76 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); |
|
76 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); | |
77 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); |
|
77 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); | |
78 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); |
|
78 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); | |
79 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); |
|
79 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); | |
80 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); |
|
80 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); | |
81 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); |
|
81 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); | |
82 | QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool))); |
|
82 | QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool))); | |
83 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); |
|
83 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | ChartAxis::~ChartAxis() |
|
86 | ChartAxis::~ChartAxis() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void ChartAxis::setAnimation(AxisAnimation *animation) |
|
90 | void ChartAxis::setAnimation(AxisAnimation *animation) | |
91 | { |
|
91 | { | |
92 | m_animation = animation; |
|
92 | m_animation = animation; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
95 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
96 | { |
|
96 | { | |
97 | m_layoutVector = layout; |
|
97 | m_layoutVector = layout; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void ChartAxis::createItems(int count) |
|
100 | void ChartAxis::createItems(int count) | |
101 | { |
|
101 | { | |
102 | if (m_arrow->childItems().size() == 0){ |
|
102 | if (m_arrow->childItems().size() == 0){ | |
103 | QGraphicsLineItem* arrow = new ArrowItem(this, this); |
|
103 | QGraphicsLineItem* arrow = new ArrowItem(this, this); | |
104 | arrow->setPen(m_axis->linePen()); |
|
104 | arrow->setPen(m_axis->linePen()); | |
105 | m_arrow->addToGroup(arrow); |
|
105 | m_arrow->addToGroup(arrow); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | if (m_intervalAxis && m_grid->childItems().size() == 0) { |
|
108 | if (m_intervalAxis && m_grid->childItems().size() == 0) { | |
109 | for (int i = 0 ; i < 2 ; i ++){ |
|
109 | for (int i = 0 ; i < 2 ; i ++){ | |
110 | QGraphicsLineItem* item = new QGraphicsLineItem(this); |
|
110 | QGraphicsLineItem* item = new QGraphicsLineItem(this); | |
111 | item->setPen(m_axis->gridLinePen()); |
|
111 | item->setPen(m_axis->gridLinePen()); | |
112 | m_grid->addToGroup(item); |
|
112 | m_grid->addToGroup(item); | |
113 | } |
|
113 | } | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | for (int i = 0; i < count; ++i) { |
|
116 | for (int i = 0; i < count; ++i) { | |
117 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); |
|
117 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); | |
118 | arrow->setPen(m_axis->linePen()); |
|
118 | arrow->setPen(m_axis->linePen()); | |
119 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); |
|
119 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); | |
120 | grid->setPen(m_axis->gridLinePen()); |
|
120 | grid->setPen(m_axis->gridLinePen()); | |
121 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); |
|
121 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); | |
122 | label->setFont(m_axis->labelsFont()); |
|
122 | label->setFont(m_axis->labelsFont()); | |
123 | label->setPen(m_axis->labelsPen()); |
|
123 | label->setPen(m_axis->labelsPen()); | |
124 | label->setBrush(m_axis->labelsBrush()); |
|
124 | label->setBrush(m_axis->labelsBrush()); | |
|
125 | label->setRotation(m_labelsAngle); | |||
125 | m_arrow->addToGroup(arrow); |
|
126 | m_arrow->addToGroup(arrow); | |
126 | m_grid->addToGroup(grid); |
|
127 | m_grid->addToGroup(grid); | |
127 | m_labels->addToGroup(label); |
|
128 | m_labels->addToGroup(label); | |
128 |
|
129 | |||
129 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ |
|
130 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ | |
130 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); |
|
131 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | |
131 | shades->setPen(m_axis->shadesPen()); |
|
132 | shades->setPen(m_axis->shadesPen()); | |
132 | shades->setBrush(m_axis->shadesBrush()); |
|
133 | shades->setBrush(m_axis->shadesBrush()); | |
133 | m_shades->addToGroup(shades); |
|
134 | m_shades->addToGroup(shades); | |
134 | } |
|
135 | } | |
135 | } |
|
136 | } | |
136 |
|
137 | |||
137 | } |
|
138 | } | |
138 |
|
139 | |||
139 | void ChartAxis::deleteItems(int count) |
|
140 | void ChartAxis::deleteItems(int count) | |
140 | { |
|
141 | { | |
141 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
142 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
142 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
143 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
143 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
144 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
144 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
145 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
145 |
|
146 | |||
146 | for (int i = 0; i < count; ++i) { |
|
147 | for (int i = 0; i < count; ++i) { | |
147 | if (lines.size() % 2 && lines.size() > 1) |
|
148 | if (lines.size() % 2 && lines.size() > 1) | |
148 | delete(shades.takeLast()); |
|
149 | delete(shades.takeLast()); | |
149 | delete(lines.takeLast()); |
|
150 | delete(lines.takeLast()); | |
150 | delete(labels.takeLast()); |
|
151 | delete(labels.takeLast()); | |
151 | delete(axis.takeLast()); |
|
152 | delete(axis.takeLast()); | |
152 | } |
|
153 | } | |
153 | } |
|
154 | } | |
154 |
|
155 | |||
155 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
156 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
156 | { |
|
157 | { | |
157 | int diff = m_layoutVector.size() - layout.size(); |
|
158 | int diff = m_layoutVector.size() - layout.size(); | |
158 |
|
159 | |||
159 | if (diff > 0) |
|
160 | if (diff > 0) | |
160 | deleteItems(diff); |
|
161 | deleteItems(diff); | |
161 | else if (diff < 0) |
|
162 | else if (diff < 0) | |
162 | createItems(-diff); |
|
163 | createItems(-diff); | |
163 |
|
164 | |||
164 | if (m_animation) { |
|
165 | if (m_animation) { | |
165 | switch (presenter()->state()) { |
|
166 | switch (presenter()->state()) { | |
166 | case ChartPresenter::ZoomInState: |
|
167 | case ChartPresenter::ZoomInState: | |
167 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
168 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
168 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
169 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
169 | break; |
|
170 | break; | |
170 | case ChartPresenter::ZoomOutState: |
|
171 | case ChartPresenter::ZoomOutState: | |
171 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
172 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
172 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
173 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
173 | break; |
|
174 | break; | |
174 | case ChartPresenter::ScrollUpState: |
|
175 | case ChartPresenter::ScrollUpState: | |
175 | case ChartPresenter::ScrollLeftState: |
|
176 | case ChartPresenter::ScrollLeftState: | |
176 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
177 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
177 | break; |
|
178 | break; | |
178 | case ChartPresenter::ScrollDownState: |
|
179 | case ChartPresenter::ScrollDownState: | |
179 | case ChartPresenter::ScrollRightState: |
|
180 | case ChartPresenter::ScrollRightState: | |
180 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
181 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
181 | break; |
|
182 | break; | |
182 | case ChartPresenter::ShowState: |
|
183 | case ChartPresenter::ShowState: | |
183 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
184 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
184 | break; |
|
185 | break; | |
185 | } |
|
186 | } | |
186 | m_animation->setValues(m_layoutVector, layout); |
|
187 | m_animation->setValues(m_layoutVector, layout); | |
187 | presenter()->startAnimation(m_animation); |
|
188 | presenter()->startAnimation(m_animation); | |
188 | } else { |
|
189 | } else { | |
189 | setLayout(layout); |
|
190 | setLayout(layout); | |
190 | updateGeometry(); |
|
191 | updateGeometry(); | |
191 | } |
|
192 | } | |
192 | } |
|
193 | } | |
193 |
|
194 | |||
194 | void ChartAxis::setLabelPadding(int padding) |
|
195 | void ChartAxis::setLabelPadding(int padding) | |
195 | { |
|
196 | { | |
196 | m_labelPadding = padding; |
|
197 | m_labelPadding = padding; | |
197 | } |
|
198 | } | |
198 |
|
199 | |||
199 | bool ChartAxis::isEmpty() |
|
200 | bool ChartAxis::isEmpty() | |
200 | { |
|
201 | { | |
201 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); |
|
202 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); | |
202 | } |
|
203 | } | |
203 |
|
204 | |||
204 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
205 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |
205 | { |
|
206 | { | |
206 | m_gridRect = grid; |
|
207 | m_gridRect = grid; | |
207 | m_axisRect = axis; |
|
208 | m_axisRect = axis; | |
208 |
|
209 | |||
209 | if (isEmpty()) |
|
210 | if (isEmpty()) | |
210 | return; |
|
211 | return; | |
211 |
|
212 | |||
212 | QVector<qreal> layout = calculateLayout(); |
|
213 | QVector<qreal> layout = calculateLayout(); | |
213 | updateLayout(layout); |
|
214 | updateLayout(layout); | |
214 | } |
|
215 | } | |
215 |
|
216 | |||
216 | qreal ChartAxis::min() const |
|
217 | qreal ChartAxis::min() const | |
217 | { |
|
218 | { | |
218 | return m_axis->d_ptr->min(); |
|
219 | return m_axis->d_ptr->min(); | |
219 | } |
|
220 | } | |
220 |
|
221 | |||
221 | qreal ChartAxis::max() const |
|
222 | qreal ChartAxis::max() const | |
222 | { |
|
223 | { | |
223 | return m_axis->d_ptr->max(); |
|
224 | return m_axis->d_ptr->max(); | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | QFont ChartAxis::font() const |
|
227 | QFont ChartAxis::font() const | |
227 | { |
|
228 | { | |
228 | return m_axis->labelsFont(); |
|
229 | return m_axis->labelsFont(); | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
231 | QFont ChartAxis::titleFont() const |
|
232 | QFont ChartAxis::titleFont() const | |
232 | { |
|
233 | { | |
233 | return m_axis->titleFont(); |
|
234 | return m_axis->titleFont(); | |
234 | } |
|
235 | } | |
235 |
|
236 | |||
236 | QString ChartAxis::titleText() const |
|
237 | QString ChartAxis::titleText() const | |
237 | { |
|
238 | { | |
238 | return m_axis->titleText(); |
|
239 | return m_axis->titleText(); | |
239 | } |
|
240 | } | |
240 |
|
241 | |||
241 | void ChartAxis::axisSelected() |
|
242 | void ChartAxis::axisSelected() | |
242 | { |
|
243 | { | |
243 | emit clicked(); |
|
244 | emit clicked(); | |
244 | } |
|
245 | } | |
245 |
|
246 | |||
246 | Qt::Orientation ChartAxis::orientation() const |
|
247 | Qt::Orientation ChartAxis::orientation() const | |
247 | { |
|
248 | { | |
248 | return m_axis->orientation(); |
|
249 | return m_axis->orientation(); | |
249 | } |
|
250 | } | |
250 |
|
251 | |||
251 | Qt::Alignment ChartAxis::alignment() const |
|
252 | Qt::Alignment ChartAxis::alignment() const | |
252 | { |
|
253 | { | |
253 | return m_axis->alignment(); |
|
254 | return m_axis->alignment(); | |
254 | } |
|
255 | } | |
255 |
|
256 | |||
256 | void ChartAxis::setLabels(const QStringList &labels) |
|
257 | void ChartAxis::setLabels(const QStringList &labels) | |
257 | { |
|
258 | { | |
258 | m_labelsList = labels; |
|
259 | m_labelsList = labels; | |
259 | } |
|
260 | } | |
260 |
|
261 | |||
261 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
262 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
262 | { |
|
263 | { | |
263 | Q_UNUSED(which); |
|
264 | Q_UNUSED(which); | |
264 | Q_UNUSED(constraint); |
|
265 | Q_UNUSED(constraint); | |
265 | return QSizeF(); |
|
266 | return QSizeF(); | |
266 | } |
|
267 | } | |
267 |
|
268 | |||
268 | //handlers |
|
269 | //handlers | |
269 |
|
270 | |||
270 | void ChartAxis::handleArrowVisibleChanged(bool visible) |
|
271 | void ChartAxis::handleArrowVisibleChanged(bool visible) | |
271 | { |
|
272 | { | |
272 | m_arrow->setVisible(visible); |
|
273 | m_arrow->setVisible(visible); | |
273 | } |
|
274 | } | |
274 |
|
275 | |||
275 | void ChartAxis::handleGridVisibleChanged(bool visible) |
|
276 | void ChartAxis::handleGridVisibleChanged(bool visible) | |
276 | { |
|
277 | { | |
277 | m_grid->setVisible(visible); |
|
278 | m_grid->setVisible(visible); | |
278 | } |
|
279 | } | |
279 |
|
280 | |||
280 | void ChartAxis::handleLabelsVisibleChanged(bool visible) |
|
281 | void ChartAxis::handleLabelsVisibleChanged(bool visible) | |
281 | { |
|
282 | { | |
282 | m_labels->setVisible(visible); |
|
283 | m_labels->setVisible(visible); | |
283 | } |
|
284 | } | |
284 |
|
285 | |||
285 | void ChartAxis::handleShadesVisibleChanged(bool visible) |
|
286 | void ChartAxis::handleShadesVisibleChanged(bool visible) | |
286 | { |
|
287 | { | |
287 | m_shades->setVisible(visible); |
|
288 | m_shades->setVisible(visible); | |
288 | } |
|
289 | } | |
289 |
|
290 | |||
290 | void ChartAxis::handleTitleVisibleChanged(bool visible) |
|
291 | void ChartAxis::handleTitleVisibleChanged(bool visible) | |
291 | { |
|
292 | { | |
292 | m_title->setVisible(visible); |
|
293 | m_title->setVisible(visible); | |
293 | presenter()->layout()->invalidate(); |
|
294 | presenter()->layout()->invalidate(); | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | void ChartAxis::handleLabelsAngleChanged(int angle) |
|
297 | void ChartAxis::handleLabelsAngleChanged(int angle) | |
297 | { |
|
298 | { | |
298 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
299 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
299 | item->setRotation(angle); |
|
300 | item->setRotation(angle); | |
300 |
|
301 | |||
301 | m_labelsAngle = angle; |
|
302 | m_labelsAngle = angle; | |
302 | } |
|
303 | } | |
303 |
|
304 | |||
304 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) |
|
305 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) | |
305 | { |
|
306 | { | |
306 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
307 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
307 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
308 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | |
308 | } |
|
309 | } | |
309 |
|
310 | |||
310 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) |
|
311 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) | |
311 | { |
|
312 | { | |
312 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
313 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
313 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); |
|
314 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | |
314 | } |
|
315 | } | |
315 |
|
316 | |||
316 | void ChartAxis::handleLabelsFontChanged(const QFont &font) |
|
317 | void ChartAxis::handleLabelsFontChanged(const QFont &font) | |
317 | { |
|
318 | { | |
318 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
319 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
319 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); |
|
320 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
320 | QGraphicsLayoutItem::updateGeometry(); |
|
321 | QGraphicsLayoutItem::updateGeometry(); | |
321 | presenter()->layout()->invalidate(); |
|
322 | presenter()->layout()->invalidate(); | |
322 | } |
|
323 | } | |
323 |
|
324 | |||
324 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) |
|
325 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) | |
325 | { |
|
326 | { | |
326 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
327 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
327 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
328 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
328 | } |
|
329 | } | |
329 |
|
330 | |||
330 | void ChartAxis::handleShadesPenChanged(const QPen &pen) |
|
331 | void ChartAxis::handleShadesPenChanged(const QPen &pen) | |
331 | { |
|
332 | { | |
332 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
333 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
333 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
334 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
334 | } |
|
335 | } | |
335 |
|
336 | |||
336 | void ChartAxis::handleArrowPenChanged(const QPen &pen) |
|
337 | void ChartAxis::handleArrowPenChanged(const QPen &pen) | |
337 | { |
|
338 | { | |
338 | foreach (QGraphicsItem *item , m_arrow->childItems()) |
|
339 | foreach (QGraphicsItem *item , m_arrow->childItems()) | |
339 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
340 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
340 | } |
|
341 | } | |
341 |
|
342 | |||
342 | void ChartAxis::handleGridPenChanged(const QPen &pen) |
|
343 | void ChartAxis::handleGridPenChanged(const QPen &pen) | |
343 | { |
|
344 | { | |
344 | foreach (QGraphicsItem *item , m_grid->childItems()) |
|
345 | foreach (QGraphicsItem *item , m_grid->childItems()) | |
345 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
346 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
346 | } |
|
347 | } | |
347 |
|
348 | |||
348 | void ChartAxis::handleTitleTextChanged(const QString &title) |
|
349 | void ChartAxis::handleTitleTextChanged(const QString &title) | |
349 | { |
|
350 | { | |
350 | Q_UNUSED(title) |
|
351 | Q_UNUSED(title) | |
351 | QGraphicsLayoutItem::updateGeometry(); |
|
352 | QGraphicsLayoutItem::updateGeometry(); | |
352 | presenter()->layout()->invalidate(); |
|
353 | presenter()->layout()->invalidate(); | |
353 | } |
|
354 | } | |
354 |
|
355 | |||
355 |
|
356 | |||
356 | void ChartAxis::handleTitlePenChanged(const QPen &pen) |
|
357 | void ChartAxis::handleTitlePenChanged(const QPen &pen) | |
357 | { |
|
358 | { | |
358 | m_title->setPen(pen); |
|
359 | m_title->setPen(pen); | |
359 | } |
|
360 | } | |
360 |
|
361 | |||
361 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) |
|
362 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) | |
362 | { |
|
363 | { | |
363 | m_title->setBrush(brush); |
|
364 | m_title->setBrush(brush); | |
364 | } |
|
365 | } | |
365 |
|
366 | |||
366 | void ChartAxis::handleTitleFontChanged(const QFont &font) |
|
367 | void ChartAxis::handleTitleFontChanged(const QFont &font) | |
367 | { |
|
368 | { | |
368 | if(m_title->font() != font){ |
|
369 | if(m_title->font() != font){ | |
369 | m_title->setFont(font); |
|
370 | m_title->setFont(font); | |
370 | QGraphicsLayoutItem::updateGeometry(); |
|
371 | QGraphicsLayoutItem::updateGeometry(); | |
371 | presenter()->layout()->invalidate(); |
|
372 | presenter()->layout()->invalidate(); | |
372 | } |
|
373 | } | |
373 | } |
|
374 | } | |
374 |
|
375 | |||
375 | void ChartAxis::handleVisibleChanged(bool visible) |
|
376 | void ChartAxis::handleVisibleChanged(bool visible) | |
376 | { |
|
377 | { | |
377 | setVisible(visible); |
|
378 | setVisible(visible); | |
378 | if(!visible) { |
|
379 | if(!visible) { | |
379 | m_grid->setVisible(visible); |
|
380 | m_grid->setVisible(visible); | |
380 | m_arrow->setVisible(visible); |
|
381 | m_arrow->setVisible(visible); | |
381 | m_shades->setVisible(visible); |
|
382 | m_shades->setVisible(visible); | |
382 | m_labels->setVisible(visible); |
|
383 | m_labels->setVisible(visible); | |
383 | m_title->setVisible(visible); |
|
384 | m_title->setVisible(visible); | |
384 | }else { |
|
385 | }else { | |
385 | m_grid->setVisible(m_axis->isGridLineVisible()); |
|
386 | m_grid->setVisible(m_axis->isGridLineVisible()); | |
386 | m_arrow->setVisible(m_axis->isLineVisible()); |
|
387 | m_arrow->setVisible(m_axis->isLineVisible()); | |
387 | m_shades->setVisible(m_axis->shadesVisible()); |
|
388 | m_shades->setVisible(m_axis->shadesVisible()); | |
388 | m_labels->setVisible(m_axis->labelsVisible()); |
|
389 | m_labels->setVisible(m_axis->labelsVisible()); | |
389 | m_title->setVisible(m_axis->isTitleVisible()); |
|
390 | m_title->setVisible(m_axis->isTitleVisible()); | |
390 | } |
|
391 | } | |
391 |
|
392 | |||
392 | if(presenter()) presenter()->layout()->invalidate(); |
|
393 | if(presenter()) presenter()->layout()->invalidate(); | |
393 | } |
|
394 | } | |
394 |
|
395 | |||
395 | void ChartAxis::handleRangeChanged(qreal min, qreal max) |
|
396 | void ChartAxis::handleRangeChanged(qreal min, qreal max) | |
396 | { |
|
397 | { | |
397 | Q_UNUSED(min); |
|
398 | Q_UNUSED(min); | |
398 | Q_UNUSED(max); |
|
399 | Q_UNUSED(max); | |
399 |
|
400 | |||
400 | if (!isEmpty()) { |
|
401 | if (!isEmpty()) { | |
401 |
|
402 | |||
402 | QVector<qreal> layout = calculateLayout(); |
|
403 | QVector<qreal> layout = calculateLayout(); | |
403 | updateLayout(layout); |
|
404 | updateLayout(layout); | |
404 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
405 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
405 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
406 | QSizeF after = sizeHint(Qt::PreferredSize); | |
406 |
|
407 | |||
407 | if (before != after) { |
|
408 | if (before != after) { | |
408 | QGraphicsLayoutItem::updateGeometry(); |
|
409 | QGraphicsLayoutItem::updateGeometry(); | |
409 | //we don't want to call invalidate on layout, since it will change minimum size of component, |
|
410 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
410 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, |
|
411 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
411 | //instead recalculate layout and use plotArea for extra space. |
|
412 | //instead recalculate layout and use plotArea for extra space. | |
412 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
413 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
413 | } |
|
414 | } | |
414 | } |
|
415 | } | |
415 |
|
416 | |||
416 | } |
|
417 | } | |
417 |
|
418 | |||
418 | //helpers |
|
419 | //helpers | |
419 |
|
420 | |||
420 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) |
|
421 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) | |
421 | { |
|
422 | { | |
422 | QStringList labels; |
|
423 | QStringList labels; | |
423 |
|
424 | |||
424 | if(max <= min || ticks < 1){ |
|
425 | if(max <= min || ticks < 1){ | |
425 | return labels; |
|
426 | return labels; | |
426 | } |
|
427 | } | |
427 |
|
428 | |||
428 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
429 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
429 | n++; |
|
430 | n++; | |
430 |
|
431 | |||
431 | if (format.isNull()) { |
|
432 | if (format.isNull()) { | |
432 | for (int i = 0; i < ticks; i++) { |
|
433 | for (int i = 0; i < ticks; i++) { | |
433 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
434 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
434 | labels << QString::number(value, 'f', n); |
|
435 | labels << QString::number(value, 'f', n); | |
435 | } |
|
436 | } | |
436 | } else { |
|
437 | } else { | |
437 | QByteArray array = format.toLatin1(); |
|
438 | QByteArray array = format.toLatin1(); | |
438 | for (int i = 0; i < ticks; i++) { |
|
439 | for (int i = 0; i < ticks; i++) { | |
439 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
440 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
440 | if (format.contains("d") |
|
441 | if (format.contains("d") | |
441 | || format.contains("i") |
|
442 | || format.contains("i") | |
442 | || format.contains("c")) |
|
443 | || format.contains("c")) | |
443 | labels << QString().sprintf(array, (qint64)value); |
|
444 | labels << QString().sprintf(array, (qint64)value); | |
444 | else if (format.contains("u") |
|
445 | else if (format.contains("u") | |
445 | || format.contains("o") |
|
446 | || format.contains("o") | |
446 | || format.contains("x", Qt::CaseInsensitive)) |
|
447 | || format.contains("x", Qt::CaseInsensitive)) | |
447 | labels << QString().sprintf(array, (quint64)value); |
|
448 | labels << QString().sprintf(array, (quint64)value); | |
448 | else if (format.contains("f", Qt::CaseInsensitive) |
|
449 | else if (format.contains("f", Qt::CaseInsensitive) | |
449 | || format.contains("e", Qt::CaseInsensitive) |
|
450 | || format.contains("e", Qt::CaseInsensitive) | |
450 | || format.contains("g", Qt::CaseInsensitive)) |
|
451 | || format.contains("g", Qt::CaseInsensitive)) | |
451 | labels << QString().sprintf(array, value); |
|
452 | labels << QString().sprintf(array, value); | |
452 | else |
|
453 | else | |
453 | labels << QString(); |
|
454 | labels << QString(); | |
454 | } |
|
455 | } | |
455 | } |
|
456 | } | |
456 |
|
457 | |||
457 | return labels; |
|
458 | return labels; | |
458 | } |
|
459 | } | |
459 |
|
460 | |||
460 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) |
|
461 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) | |
461 | { |
|
462 | { | |
462 | // Q_ASSERT(m_max > m_min); |
|
463 | // Q_ASSERT(m_max > m_min); | |
463 | // Q_ASSERT(ticks > 1); |
|
464 | // Q_ASSERT(ticks > 1); | |
464 |
|
465 | |||
465 | QStringList labels; |
|
466 | QStringList labels; | |
466 |
|
467 | |||
467 | int n = 0; |
|
468 | int n = 0; | |
468 | if (ticks > 1) |
|
469 | if (ticks > 1) | |
469 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
470 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
470 | n++; |
|
471 | n++; | |
471 |
|
472 | |||
472 | int firstTick; |
|
473 | int firstTick; | |
473 | if (base > 1) |
|
474 | if (base > 1) | |
474 | firstTick = ceil(log10(min) / log10(base)); |
|
475 | firstTick = ceil(log10(min) / log10(base)); | |
475 | else |
|
476 | else | |
476 | firstTick = ceil(log10(max) / log10(base)); |
|
477 | firstTick = ceil(log10(max) / log10(base)); | |
477 |
|
478 | |||
478 | if (format.isNull()) { |
|
479 | if (format.isNull()) { | |
479 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
480 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
480 | qreal value = qPow(base, i); |
|
481 | qreal value = qPow(base, i); | |
481 | labels << QString::number(value, 'f', n); |
|
482 | labels << QString::number(value, 'f', n); | |
482 | } |
|
483 | } | |
483 | } else { |
|
484 | } else { | |
484 | QByteArray array = format.toLatin1(); |
|
485 | QByteArray array = format.toLatin1(); | |
485 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
486 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
486 | qreal value = qPow(base, i); |
|
487 | qreal value = qPow(base, i); | |
487 | if (format.contains("d") |
|
488 | if (format.contains("d") | |
488 | || format.contains("i") |
|
489 | || format.contains("i") | |
489 | || format.contains("c")) |
|
490 | || format.contains("c")) | |
490 | labels << QString().sprintf(array, (qint64)value); |
|
491 | labels << QString().sprintf(array, (qint64)value); | |
491 | else if (format.contains("u") |
|
492 | else if (format.contains("u") | |
492 | || format.contains("o") |
|
493 | || format.contains("o") | |
493 | || format.contains("x", Qt::CaseInsensitive)) |
|
494 | || format.contains("x", Qt::CaseInsensitive)) | |
494 | labels << QString().sprintf(array, (quint64)value); |
|
495 | labels << QString().sprintf(array, (quint64)value); | |
495 | else if (format.contains("f", Qt::CaseInsensitive) |
|
496 | else if (format.contains("f", Qt::CaseInsensitive) | |
496 | || format.contains("e", Qt::CaseInsensitive) |
|
497 | || format.contains("e", Qt::CaseInsensitive) | |
497 | || format.contains("g", Qt::CaseInsensitive)) |
|
498 | || format.contains("g", Qt::CaseInsensitive)) | |
498 | labels << QString().sprintf(array, value); |
|
499 | labels << QString().sprintf(array, value); | |
499 | else |
|
500 | else | |
500 | labels << QString(); |
|
501 | labels << QString(); | |
501 | } |
|
502 | } | |
502 | } |
|
503 | } | |
503 |
|
504 | |||
504 | return labels; |
|
505 | return labels; | |
505 | } |
|
506 | } | |
506 |
|
507 | |||
507 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) |
|
508 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) | |
508 | { |
|
509 | { | |
509 | QStringList labels; |
|
510 | QStringList labels; | |
510 |
|
511 | |||
511 | if(max <= min || ticks < 1) { |
|
512 | if(max <= min || ticks < 1) { | |
512 | return labels; |
|
513 | return labels; | |
513 | } |
|
514 | } | |
514 |
|
515 | |||
515 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
516 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |
516 | n++; |
|
517 | n++; | |
517 | for (int i = 0; i < ticks; i++) { |
|
518 | for (int i = 0; i < ticks; i++) { | |
518 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
519 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
519 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
520 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
520 | } |
|
521 | } | |
521 | return labels; |
|
522 | return labels; | |
522 | } |
|
523 | } | |
523 |
|
524 | |||
524 | #include "moc_chartaxis_p.cpp" |
|
525 | #include "moc_chartaxis_p.cpp" | |
525 |
|
526 | |||
526 | QTCOMMERCIALCHART_END_NAMESPACE |
|
527 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now