@@ -1,210 +1,210 | |||||
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 "horizontalaxis_p.h" |
|
21 | #include "horizontalaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include <QFontMetrics> |
|
23 | #include <QFontMetrics> | |
24 | #include <qmath.h> |
|
24 | #include <qmath.h> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) |
|
29 | HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | |
30 | : ChartAxis(axis, item, intervalAxis) |
|
30 | : ChartAxis(axis, item, intervalAxis) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | HorizontalAxis::~HorizontalAxis() |
|
34 | HorizontalAxis::~HorizontalAxis() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void HorizontalAxis::updateGeometry() |
|
38 | void HorizontalAxis::updateGeometry() | |
39 | { |
|
39 | { | |
40 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
40 | const QVector<qreal>& layout = ChartAxis::layout(); | |
41 |
|
41 | |||
42 | if (layout.isEmpty()) |
|
42 | if (layout.isEmpty()) | |
43 | return; |
|
43 | return; | |
44 |
|
44 | |||
45 | QStringList labelList = labels(); |
|
45 | QStringList labelList = labels(); | |
46 |
|
46 | |||
47 | QList<QGraphicsItem *> lines = lineItems(); |
|
47 | QList<QGraphicsItem *> lines = lineItems(); | |
48 | QList<QGraphicsItem *> labels = labelItems(); |
|
48 | QList<QGraphicsItem *> labels = labelItems(); | |
49 | QList<QGraphicsItem *> shades = shadeItems(); |
|
49 | QList<QGraphicsItem *> shades = shadeItems(); | |
50 | QList<QGraphicsItem *> axis = arrowItems(); |
|
50 | QList<QGraphicsItem *> axis = arrowItems(); | |
51 | QGraphicsSimpleTextItem* title = titleItem(); |
|
51 | QGraphicsSimpleTextItem* title = titleItem(); | |
52 |
|
52 | |||
53 | Q_ASSERT(labels.size() == labelList.size()); |
|
53 | Q_ASSERT(labels.size() == labelList.size()); | |
54 | Q_ASSERT(layout.size() == labelList.size()); |
|
54 | Q_ASSERT(layout.size() == labelList.size()); | |
55 |
|
55 | |||
56 | const QRectF &axisRect = axisGeometry(); |
|
56 | const QRectF &axisRect = axisGeometry(); | |
57 | const QRectF &gridRect = gridGeometry(); |
|
57 | const QRectF &gridRect = gridGeometry(); | |
58 |
|
58 | |||
59 | //arrow |
|
59 | //arrow | |
60 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(axis.at(0)); |
|
60 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(axis.at(0)); | |
61 |
|
61 | |||
62 | if (alignment() == Qt::AlignTop) |
|
62 | if (alignment() == Qt::AlignTop) | |
63 | arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom()); |
|
63 | arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom()); | |
64 | else if (alignment() == Qt::AlignBottom) |
|
64 | else if (alignment() == Qt::AlignBottom) | |
65 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); |
|
65 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); | |
66 |
|
66 | |||
67 | qreal width = 0; |
|
67 | qreal width = 0; | |
68 | QFontMetrics fn(font()); |
|
68 | QFontMetrics fn(font()); | |
69 |
|
69 | |||
70 | //title |
|
70 | //title | |
71 |
|
71 | |||
72 | if (!titleText().isNull()) { |
|
72 | if (!titleText().isNull()) { | |
73 | QFontMetrics fn(title->font()); |
|
73 | QFontMetrics fn(title->font()); | |
74 |
|
74 | |||
75 | int size(0); |
|
75 | int size(0); | |
76 |
|
76 | |||
77 | size = gridRect.width(); |
|
77 | size = gridRect.width(); | |
78 | QString titleText = this->titleText(); |
|
78 | QString titleText = this->titleText(); | |
79 |
|
79 | |||
80 | if (fn.boundingRect(titleText).width() > size) { |
|
80 | if (fn.boundingRect(titleText).width() > size) { | |
81 | QString string = titleText + "..."; |
|
81 | QString string = titleText + "..."; | |
82 | while (fn.boundingRect(string).width() > size && string.length() > 3) |
|
82 | while (fn.boundingRect(string).width() > size && string.length() > 3) | |
83 | string.remove(string.length() - 4, 1); |
|
83 | string.remove(string.length() - 4, 1); | |
84 | title->setText(string); |
|
84 | title->setText(string); | |
85 | } else { |
|
85 | } else { | |
86 | title->setText(titleText); |
|
86 | title->setText(titleText); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | QPointF center = gridRect.center() - title->boundingRect().center(); |
|
89 | QPointF center = gridRect.center() - title->boundingRect().center(); | |
90 | if (alignment() == Qt::AlignTop) { |
|
90 | if (alignment() == Qt::AlignTop) { | |
91 | title->setPos(center.x(), axisRect.top()); |
|
91 | title->setPos(center.x(), axisRect.top()); | |
92 | } else if (alignment() == Qt::AlignBottom) { |
|
92 | } else if (alignment() == Qt::AlignBottom) { | |
93 | title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height()); |
|
93 | title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height()); | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | for (int i = 0; i < layout.size(); ++i) { |
|
97 | for (int i = 0; i < layout.size(); ++i) { | |
98 |
|
98 | |||
99 | //items |
|
99 | //items | |
100 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
100 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
101 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i + 1)); |
|
101 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i + 1)); | |
102 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i)); |
|
102 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i)); | |
103 |
|
103 | |||
104 | //grid line |
|
104 | //grid line | |
105 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); |
|
105 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); | |
106 |
|
106 | |||
107 | //label text wrapping |
|
107 | //label text wrapping | |
108 | if(intervalAxis()&& i+1!=layout.size()) { |
|
108 | if(intervalAxis()&& i+1!=layout.size()) { | |
109 | //wrapping in case of interval axis |
|
109 | //wrapping in case of interval axis | |
110 | const qreal delta = layout[i+1] - layout[i]; |
|
110 | const qreal delta = layout[i+1] - layout[i]; | |
111 | QString text = labelList.at(i); |
|
111 | QString text = labelList.at(i); | |
112 | if (fn.boundingRect(text).width() + 1 > delta ) |
|
112 | if (fn.boundingRect(text).width() + 1 > delta ) | |
113 | { |
|
113 | { | |
114 | QString label = text + "..."; |
|
114 | QString label = text + "..."; | |
115 | while (fn.boundingRect(label).width() >= delta && label.length() > 3) |
|
115 | while (fn.boundingRect(label).width() >= delta && label.length() > 3) | |
116 | label.remove(label.length() - 4, 1); |
|
116 | label.remove(label.length() - 4, 1); | |
117 | labelItem->setText(label); |
|
117 | labelItem->setText(label); | |
118 | } |
|
118 | } | |
119 | else { |
|
119 | else { | |
120 | labelItem->setText(text); |
|
120 | labelItem->setText(text); | |
121 | } |
|
121 | } | |
122 | }else{ |
|
122 | }else{ | |
123 | labelItem->setText(labelList.at(i)); |
|
123 | labelItem->setText(labelList.at(i)); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | //label transformation origin point |
|
126 | //label transformation origin point | |
127 | const QRectF& rect = labelItem->boundingRect(); |
|
127 | const QRectF& rect = labelItem->boundingRect(); | |
128 | QPointF center = rect.center(); |
|
128 | QPointF center = rect.center(); | |
129 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
129 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
130 |
|
130 | |||
131 | //ticks and label position |
|
131 | //ticks and label position | |
132 | if (alignment() == Qt::AlignTop) { |
|
132 | if (alignment() == Qt::AlignTop) { | |
133 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding()); |
|
133 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding()); | |
134 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); |
|
134 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); | |
135 | } else if (alignment() == Qt::AlignBottom) { |
|
135 | } else if (alignment() == Qt::AlignBottom) { | |
136 | labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding()); |
|
136 | labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding()); | |
137 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); |
|
137 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | //label in beetwen |
|
140 | //label in beetwen | |
141 | if(intervalAxis()&& i+1!=layout.size()) { |
|
141 | if(intervalAxis()&& i+1!=layout.size()) { | |
142 | const qreal delta = (layout[i+1] - layout[i])/2; |
|
142 | const qreal delta = (layout[i+1] - layout[i])/2; | |
143 | labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); |
|
143 | labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | //label overlap detection |
|
146 | //label overlap detection | |
147 | if(labelItem->pos().x() < width || |
|
147 | if(labelItem->pos().x() < width || | |
148 | labelItem->pos().x() < axisRect.left() || |
|
148 | labelItem->pos().x() < axisRect.left() || | |
149 |
labelItem->pos().x() + rect.width() - |
|
149 | labelItem->pos().x() + rect.width() -1 > axisRect.right()){ | |
150 | labelItem->setVisible(false); |
|
150 | labelItem->setVisible(false); | |
151 | } else { |
|
151 | } else { | |
152 | labelItem->setVisible(true); |
|
152 | labelItem->setVisible(true); | |
153 | width=rect.width()+labelItem->pos().x(); |
|
153 | width=rect.width()+labelItem->pos().x(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | //shades |
|
156 | //shades | |
157 | if ((i + 1) % 2 && i > 1) { |
|
157 | if ((i + 1) % 2 && i > 1) { | |
158 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); |
|
158 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); | |
159 | rectItem->setRect(layout[i - 1], gridRect.top(), layout[i] - layout[i - 1], gridRect.height()); |
|
159 | rectItem->setRect(layout[i - 1], gridRect.top(), layout[i] - layout[i - 1], gridRect.height()); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | // check if the grid line and the axis tick should be shown |
|
162 | // check if the grid line and the axis tick should be shown | |
163 | qreal x = gridItem->line().p1().x(); |
|
163 | qreal x = gridItem->line().p1().x(); | |
164 | if (x < gridRect.left() || x > gridRect.right()) { |
|
164 | if (x < gridRect.left() || x > gridRect.right()) { | |
165 | gridItem->setVisible(false); |
|
165 | gridItem->setVisible(false); | |
166 | tickItem->setVisible(false); |
|
166 | tickItem->setVisible(false); | |
167 | }else{ |
|
167 | }else{ | |
168 | gridItem->setVisible(true); |
|
168 | gridItem->setVisible(true); | |
169 | tickItem->setVisible(true); |
|
169 | tickItem->setVisible(true); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | //begin/end grid line in case labels between |
|
174 | //begin/end grid line in case labels between | |
175 | if (intervalAxis()) { |
|
175 | if (intervalAxis()) { | |
176 | QGraphicsLineItem *gridLine; |
|
176 | QGraphicsLineItem *gridLine; | |
177 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); |
|
177 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); | |
178 | gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); |
|
178 | gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); | |
179 | gridLine->setVisible(true); |
|
179 | gridLine->setVisible(true); | |
180 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1)); |
|
180 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1)); | |
181 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); |
|
181 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); | |
182 | gridLine->setVisible(true); |
|
182 | gridLine->setVisible(true); | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
186 | QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
187 | { |
|
187 | { | |
188 | Q_UNUSED(constraint); |
|
188 | Q_UNUSED(constraint); | |
189 | QFontMetrics fn(titleFont()); |
|
189 | QFontMetrics fn(titleFont()); | |
190 | QSizeF sh(0,0); |
|
190 | QSizeF sh(0,0); | |
191 |
|
191 | |||
192 | if (titleText().isNull() || !titleItem()->isVisible()) |
|
192 | if (titleText().isNull() || !titleItem()->isVisible()) | |
193 | return sh; |
|
193 | return sh; | |
194 |
|
194 | |||
195 | switch (which) { |
|
195 | switch (which) { | |
196 | case Qt::MinimumSize: |
|
196 | case Qt::MinimumSize: | |
197 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); |
|
197 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); | |
198 | break; |
|
198 | break; | |
199 | case Qt::MaximumSize: |
|
199 | case Qt::MaximumSize: | |
200 | case Qt::PreferredSize: |
|
200 | case Qt::PreferredSize: | |
201 | sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height()); |
|
201 | sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height()); | |
202 | break; |
|
202 | break; | |
203 | default: |
|
203 | default: | |
204 | break; |
|
204 | break; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | return sh; |
|
207 | return sh; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
210 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,131 +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 | QGraphicsLayoutItem::updateGeometry(); | |
76 | if(presenter()) presenter()->layout()->invalidate(); |
|
76 | if(presenter()) presenter()->layout()->invalidate(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void ChartValueAxisX::handleLabelFormatChanged(const QString &format) |
|
79 | void ChartValueAxisX::handleLabelFormatChanged(const QString &format) | |
80 | { |
|
80 | { | |
81 | Q_UNUSED(format); |
|
81 | Q_UNUSED(format); | |
82 | QGraphicsLayoutItem::updateGeometry(); |
|
82 | QGraphicsLayoutItem::updateGeometry(); | |
83 | if(presenter()) presenter()->layout()->invalidate(); |
|
83 | if(presenter()) presenter()->layout()->invalidate(); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
86 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
87 | { |
|
87 | { | |
88 | Q_UNUSED(constraint) |
|
88 | Q_UNUSED(constraint) | |
89 |
|
89 | |||
90 | QFontMetrics fn(font()); |
|
90 | QFontMetrics fn(font()); | |
91 | QSizeF sh; |
|
91 | QSizeF sh; | |
92 |
|
92 | |||
93 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
93 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
94 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
|
94 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
95 | qreal width = 0; |
|
95 | qreal width = 0; | |
96 | qreal height = 0; |
|
96 | qreal height = 0; | |
97 |
|
97 | |||
98 | int count = 1; |
|
|||
99 |
|
||||
100 | if(!ticksList.empty()) { |
|
|||
101 | count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
|||
102 | } |
|
|||
103 |
|
98 | |||
104 | switch (which) { |
|
99 | switch (which) { | |
105 | case Qt::MinimumSize:{ |
|
100 | case Qt::MinimumSize: { | |
106 | count = qMin(count,5); |
|
101 | if(!ticksList.empty()) { | |
107 | width = fn.averageCharWidth() * count; |
|
102 | width = qMax(fn.boundingRect(ticksList.last()).width(),fn.boundingRect(ticksList.first()).width()); | |
108 | height = fn.height() + labelPadding(); |
|
103 | } | |
109 | width = qMax(width,base.width()); |
|
104 | height = fn.height() + labelPadding(); | |
110 | height += base.height(); |
|
105 | width = qMax(width,base.width()); | |
111 | sh = QSizeF(width,height); |
|
106 | height += base.height(); | |
112 | break; |
|
107 | sh = QSizeF(width,height); | |
113 | } |
|
108 | break; | |
114 | case Qt::PreferredSize:{ |
|
109 | } | |
115 | width=fn.averageCharWidth() * count; |
|
110 | case Qt::PreferredSize: { | |
116 | height=fn.height()+labelPadding(); |
|
111 | if(!ticksList.empty()) { | |
117 | width=qMax(width,base.width()); |
|
112 | foreach(QString label,ticksList) { | |
118 | height+=base.height(); |
|
113 | width+=fn.boundingRect(label).width(); | |
119 | sh = QSizeF(width,height); |
|
114 | } | |
120 | break; |
|
115 | } | |
121 | } |
|
116 | height=fn.height()+labelPadding(); | |
122 | default: |
|
117 | width=qMax(width,base.width()); | |
|
118 | height+=base.height(); | |||
|
119 | sh = QSizeF(width,height); | |||
|
120 | break; | |||
|
121 | } | |||
|
122 | default: | |||
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | return sh; |
|
126 | return sh; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | #include "moc_chartvalueaxisx_p.cpp" |
|
129 | #include "moc_chartvalueaxisx_p.cpp" | |
130 |
|
130 | |||
131 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now