@@ -22,7 +22,6 | |||
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "qbarcategoryaxis_p.h" |
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | #include <QFontMetrics> | |
|
26 | 25 | #include <QDebug> |
|
27 | 26 | #include <qmath.h> |
|
28 | 27 | |
@@ -104,7 +103,6 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
104 | 103 | { |
|
105 | 104 | Q_UNUSED(constraint) |
|
106 | 105 | |
|
107 | QFontMetrics fn(axis()->labelsFont()); | |
|
108 | 106 | QSizeF sh; |
|
109 | 107 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
110 | 108 | QStringList ticksList = m_categoriesAxis->categories(); |
@@ -114,20 +112,18 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
114 | 112 | |
|
115 | 113 | switch (which) { |
|
116 | 114 | case Qt::MinimumSize: { |
|
117 |
QRectF boundingRect = |
|
|
118 | height = boundingRect.height() + labelPadding(); | |
|
119 | height += base.height(); | |
|
115 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
116 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
|
120 | 117 | sh = QSizeF(width, height); |
|
121 | 118 | break; |
|
122 | 119 | } |
|
123 | 120 | case Qt::PreferredSize:{ |
|
124 |
|
|
|
121 | qreal labelHeight = 0.0; | |
|
125 | 122 | foreach (const QString& s, ticksList) { |
|
126 |
QRect rect = |
|
|
123 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
127 | 124 | labelHeight = qMax(rect.height(), labelHeight); |
|
128 | 125 | } |
|
129 | height = labelHeight + labelPadding(); | |
|
130 | height += base.height(); | |
|
126 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
|
131 | 127 | sh = QSizeF(width, height); |
|
132 | 128 | break; |
|
133 | 129 | } |
@@ -23,7 +23,6 | |||
|
23 | 23 | #include "qbarcategoryaxis_p.h" |
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | #include <QFontMetrics> | |
|
27 | 26 | #include <QDebug> |
|
28 | 27 | |
|
29 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -103,7 +102,6 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
103 | 102 | { |
|
104 | 103 | Q_UNUSED(constraint) |
|
105 | 104 | |
|
106 | QFontMetrics fn(axis()->labelsFont()); | |
|
107 | 105 | QSizeF sh; |
|
108 | 106 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
109 | 107 | QStringList ticksList = m_categoriesAxis->categories(); |
@@ -112,23 +110,21 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
112 | 110 | |
|
113 | 111 | switch (which) { |
|
114 | 112 | case Qt::MinimumSize: { |
|
115 |
QRectF boundingRect = |
|
|
116 | width = boundingRect.width() + labelPadding(); | |
|
117 |
|
|
|
118 | if (base.width() > 0) | |
|
113 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
114 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
115 | if (base.width() > 0.0) | |
|
119 | 116 | width += labelPadding(); |
|
120 | 117 | sh = QSizeF(width, height); |
|
121 | 118 | break; |
|
122 | 119 | } |
|
123 | 120 | case Qt::PreferredSize:{ |
|
124 |
|
|
|
121 | qreal labelWidth = 0.0; | |
|
125 | 122 | foreach (const QString& s, ticksList) { |
|
126 |
QRect rect = |
|
|
123 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
127 | 124 | labelWidth = qMax(rect.width(), labelWidth); |
|
128 | 125 | } |
|
129 | width = labelWidth + labelPadding() + 1; | |
|
130 |
|
|
|
131 | if (base.width() > 0) | |
|
126 | width = labelWidth + labelPadding() + base.width() + 1.0; | |
|
127 | if (base.width() > 0.0) | |
|
132 | 128 | width += labelPadding(); |
|
133 | 129 | sh = QSizeF(width, height); |
|
134 | 130 | break; |
@@ -24,7 +24,6 | |||
|
24 | 24 | #include "chartpresenter_p.h" |
|
25 | 25 | #include "abstractchartlayout_p.h" |
|
26 | 26 | #include <QGraphicsLayout> |
|
27 | #include <QFontMetrics> | |
|
28 | 27 | #include <qmath.h> |
|
29 | 28 | |
|
30 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -78,7 +77,6 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
78 | 77 | { |
|
79 | 78 | Q_UNUSED(constraint) |
|
80 | 79 | |
|
81 | QFontMetrics fn(axis()->labelsFont()); | |
|
82 | 80 | QSizeF sh; |
|
83 | 81 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
84 | 82 | QStringList ticksList = m_axis->categoriesLabels(); |
@@ -87,20 +85,18 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
87 | 85 | |
|
88 | 86 | switch (which) { |
|
89 | 87 | case Qt::MinimumSize: { |
|
90 |
QRectF boundingRect = |
|
|
91 | height = boundingRect.height() + labelPadding(); | |
|
92 | height += base.height(); | |
|
88 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
89 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
|
93 | 90 | sh = QSizeF(width, height); |
|
94 | 91 | break; |
|
95 | 92 | } |
|
96 | 93 | case Qt::PreferredSize: { |
|
97 |
|
|
|
94 | qreal labelHeight = 0.0; | |
|
98 | 95 | foreach (const QString& s, ticksList) { |
|
99 |
QRect rect = |
|
|
96 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
100 | 97 | labelHeight = qMax(rect.height(), labelHeight); |
|
101 | 98 | } |
|
102 | height = labelHeight + labelPadding(); | |
|
103 | height += base.height(); | |
|
99 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
|
104 | 100 | sh = QSizeF(width, height); |
|
105 | 101 | break; |
|
106 | 102 | } |
@@ -24,7 +24,6 | |||
|
24 | 24 | #include "chartpresenter_p.h" |
|
25 | 25 | #include "abstractchartlayout_p.h" |
|
26 | 26 | #include <QGraphicsLayout> |
|
27 | #include <QFontMetrics> | |
|
28 | 27 | #include <qmath.h> |
|
29 | 28 | #include <QDebug> |
|
30 | 29 | |
@@ -78,7 +77,6 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
78 | 77 | { |
|
79 | 78 | Q_UNUSED(constraint) |
|
80 | 79 | |
|
81 | QFontMetrics fn(axis()->labelsFont()); | |
|
82 | 80 | QSizeF sh; |
|
83 | 81 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
84 | 82 | QStringList ticksList = m_axis->categoriesLabels(); |
@@ -87,20 +85,18 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
87 | 85 | |
|
88 | 86 | switch (which) { |
|
89 | 87 | case Qt::MinimumSize: { |
|
90 |
QRectF boundingRect = |
|
|
91 | width = boundingRect.width() + labelPadding(); | |
|
92 | width += base.width(); | |
|
88 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
89 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
93 | 90 | sh = QSizeF(width, height); |
|
94 | 91 | break; |
|
95 | 92 | } |
|
96 | 93 | case Qt::PreferredSize: { |
|
97 |
|
|
|
94 | qreal labelWidth = 0.0; | |
|
98 | 95 | foreach (const QString& s, ticksList) { |
|
99 |
QRect rect = |
|
|
96 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
100 | 97 | labelWidth = qMax(rect.width(), labelWidth); |
|
101 | 98 | } |
|
102 | width = labelWidth + labelPadding() + 1; | |
|
103 | width += base.width(); | |
|
99 | width = labelWidth + labelPadding() + base.width() + 1.0; | |
|
104 | 100 | sh = QSizeF(width, height); |
|
105 | 101 | break; |
|
106 | 102 | } |
@@ -24,10 +24,18 | |||
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | 26 | #include <QDateTime> |
|
27 | #include <QFontMetrics> | |
|
28 | 27 | |
|
29 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 29 | |
|
30 | QGraphicsSimpleTextItem *dummyTextItem = 0; | |
|
31 | class StaticDeleter | |
|
32 | { | |
|
33 | public: | |
|
34 | StaticDeleter() {} | |
|
35 | ~StaticDeleter() { delete dummyTextItem; } | |
|
36 | }; | |
|
37 | StaticDeleter staticDeleter; | |
|
38 | ||
|
31 | 39 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
32 | 40 | : ChartElement(item), |
|
33 | 41 | m_axis(axis), |
@@ -41,6 +49,8 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, boo | |||
|
41 | 49 | |
|
42 | 50 | { |
|
43 | 51 | //initial initialization |
|
52 | if (!dummyTextItem) | |
|
53 | dummyTextItem = new QGraphicsSimpleTextItem; | |
|
44 | 54 | m_arrow->setHandlesChildEvents(false); |
|
45 | 55 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
46 | 56 | m_labels->setZValue(ChartPresenter::AxisZValue); |
@@ -184,19 +194,44 void ChartAxisElement::handleVisibleChanged(bool visible) | |||
|
184 | 194 | if (presenter()) presenter()->layout()->invalidate(); |
|
185 | 195 | } |
|
186 | 196 | |
|
187 |
QRect ChartAxisElement:: |
|
|
197 | QRectF ChartAxisElement::textBoundingRect(const QFont &font, const QString &text, qreal angle) const | |
|
188 | 198 | { |
|
189 | QRect boundingRect = fn.boundingRect(label); | |
|
190 | // Take label rotation into account | |
|
191 | if (axis()->labelsAngle()) { | |
|
199 | dummyTextItem->setFont(font); | |
|
200 | dummyTextItem->setText(text); | |
|
201 | QRectF boundingRect = dummyTextItem->boundingRect(); | |
|
202 | ||
|
203 | // Take rotation into account | |
|
204 | if (angle) { | |
|
192 | 205 | QTransform transform; |
|
193 |
transform.rotate(a |
|
|
206 | transform.rotate(angle); | |
|
194 | 207 | boundingRect = transform.mapRect(boundingRect); |
|
195 | 208 | } |
|
196 | 209 | |
|
197 | 210 | return boundingRect; |
|
198 | 211 | } |
|
199 | 212 | |
|
213 | // boundingRect parameter returns the rotated bounding rect of the text | |
|
214 | QString ChartAxisElement::truncatedText(const QFont &font, const QString &text, qreal angle, | |
|
215 | qreal maxSize, Qt::Orientation constraintOrientation, | |
|
216 | QRectF &boundingRect) const | |
|
217 | { | |
|
218 | QString truncatedString(text); | |
|
219 | boundingRect = textBoundingRect(font, truncatedString, angle); | |
|
220 | qreal checkDimension = ((constraintOrientation == Qt::Horizontal) | |
|
221 | ? boundingRect.width() : boundingRect.height()); | |
|
222 | if (checkDimension > maxSize) { | |
|
223 | truncatedString.append("..."); | |
|
224 | while (checkDimension > maxSize && truncatedString.length() > 3) { | |
|
225 | truncatedString.remove(truncatedString.length() - 4, 1); | |
|
226 | boundingRect = textBoundingRect(font, truncatedString, angle); | |
|
227 | checkDimension = ((constraintOrientation == Qt::Horizontal) | |
|
228 | ? boundingRect.width() : boundingRect.height()); | |
|
229 | } | |
|
230 | } | |
|
231 | ||
|
232 | return truncatedString; | |
|
233 | } | |
|
234 | ||
|
200 | 235 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) |
|
201 | 236 | { |
|
202 | 237 | Q_UNUSED(min); |
@@ -70,7 +70,9 public: | |||
|
70 | 70 | QRectF axisGeometry() const { return m_axisRect; } |
|
71 | 71 | void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; } |
|
72 | 72 | |
|
73 |
QRect |
|
|
73 | QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0) const; | |
|
74 | QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, | |
|
75 | Qt::Orientation constraintOrientation, QRectF &boundingRect) const; | |
|
74 | 76 | |
|
75 | 77 | void axisSelected(); |
|
76 | 78 |
@@ -24,7 +24,6 | |||
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | 25 | #include <QGraphicsLayout> |
|
26 | 26 | #include <QDateTime> |
|
27 | #include <QFontMetrics> | |
|
28 | 27 | #include <qmath.h> |
|
29 | 28 | |
|
30 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -85,7 +84,6 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
85 | 84 | { |
|
86 | 85 | Q_UNUSED(constraint) |
|
87 | 86 | |
|
88 | QFontMetrics fn(axis()->labelsFont()); | |
|
89 | 87 | QSizeF sh; |
|
90 | 88 | |
|
91 | 89 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
@@ -100,26 +98,24 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
100 | 98 | |
|
101 | 99 | switch (which) { |
|
102 | 100 | case Qt::MinimumSize: { |
|
103 |
QRectF boundingRect = |
|
|
101 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
104 | 102 | width = boundingRect.width() / 2.0; |
|
105 | height = boundingRect.height() + labelPadding(); | |
|
106 | height += base.height(); | |
|
103 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
|
107 | 104 | sh = QSizeF(width, height); |
|
108 | 105 | break; |
|
109 | 106 | } |
|
110 | 107 | case Qt::PreferredSize: { |
|
111 |
|
|
|
112 |
|
|
|
108 | qreal labelHeight = 0.0; | |
|
109 | qreal firstWidth = -1.0; | |
|
113 | 110 | foreach (const QString& s, ticksList) { |
|
114 |
QRect rect = |
|
|
111 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
115 | 112 | labelHeight = qMax(rect.height(), labelHeight); |
|
116 | 113 | width = rect.width(); |
|
117 | if (firstWidth < 0) | |
|
114 | if (firstWidth < 0.0) | |
|
118 | 115 | firstWidth = width; |
|
119 | 116 | } |
|
120 | height = labelHeight + labelPadding(); | |
|
121 | height += base.height(); | |
|
122 | width = qMax(width, qreal(firstWidth)) / 2.0; | |
|
117 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
|
118 | width = qMax(width, firstWidth) / 2.0; | |
|
123 | 119 | sh = QSizeF(width, height); |
|
124 | 120 | break; |
|
125 | 121 | } |
@@ -23,7 +23,6 | |||
|
23 | 23 | #include "qdatetimeaxis.h" |
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | 25 | #include <QGraphicsLayout> |
|
26 | #include <QFontMetrics> | |
|
27 | 26 | #include <QDateTime> |
|
28 | 27 | #include <qmath.h> |
|
29 | 28 | |
@@ -86,7 +85,6 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
86 | 85 | { |
|
87 | 86 | Q_UNUSED(constraint) |
|
88 | 87 | |
|
89 | QFontMetrics fn(axis()->labelsFont()); | |
|
90 | 88 | QSizeF sh; |
|
91 | 89 | |
|
92 | 90 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
@@ -101,26 +99,24 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
101 | 99 | |
|
102 | 100 | switch (which) { |
|
103 | 101 | case Qt::MinimumSize: { |
|
104 |
QRectF boundingRect = |
|
|
105 | width = boundingRect.width() + labelPadding(); | |
|
106 | width += base.width(); | |
|
102 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
103 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
107 | 104 | height = boundingRect.height() / 2.0; |
|
108 | 105 | sh = QSizeF(width, height); |
|
109 | 106 | break; |
|
110 | 107 | } |
|
111 | 108 | case Qt::PreferredSize: { |
|
112 |
|
|
|
113 |
|
|
|
109 | qreal labelWidth = 0.0; | |
|
110 | qreal firstHeight = -1.0; | |
|
114 | 111 | foreach (const QString& s, ticksList) { |
|
115 |
QRect rect = |
|
|
112 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
116 | 113 | labelWidth = qMax(rect.width(), labelWidth); |
|
117 | 114 | height = rect.height(); |
|
118 | if (firstHeight < 0) | |
|
115 | if (firstHeight < 0.0) | |
|
119 | 116 | firstHeight = height; |
|
120 | 117 | } |
|
121 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance | |
|
122 | width += base.width(); | |
|
123 | height = qMax(height, qreal(firstHeight)) / 2.0; | |
|
118 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
|
119 | height = qMax(height, firstHeight) / 2.0; | |
|
124 | 120 | sh = QSizeF(width, height); |
|
125 | 121 | break; |
|
126 | 122 | } |
@@ -20,7 +20,6 | |||
|
20 | 20 | |
|
21 | 21 | #include "horizontalaxis_p.h" |
|
22 | 22 | #include "qabstractaxis_p.h" |
|
23 | #include <QFontMetrics> | |
|
24 | 23 | #include <qmath.h> |
|
25 | 24 | #include <QDebug> |
|
26 | 25 | |
@@ -65,32 +64,13 void HorizontalAxis::updateGeometry() | |||
|
65 | 64 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); |
|
66 | 65 | |
|
67 | 66 | qreal width = 0; |
|
68 | QFontMetrics fn(axis()->labelsFont()); | |
|
69 | 67 | |
|
70 | 68 | //title |
|
71 | 69 | int titlePad = 0; |
|
72 | 70 | QRectF titleBoundingRect; |
|
73 | 71 | QString titleText = axis()->titleText(); |
|
74 | 72 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
75 | int size(0); | |
|
76 | size = gridRect.width(); | |
|
77 | ||
|
78 | QGraphicsSimpleTextItem dummyTitle; | |
|
79 | dummyTitle.setFont(axis()->titleFont()); | |
|
80 | dummyTitle.setText(axis()->titleText()); | |
|
81 | QRectF dummyRect = dummyTitle.boundingRect(); | |
|
82 | ||
|
83 | if (dummyRect.width() > size) { | |
|
84 | QString string = titleText + "..."; | |
|
85 | while (dummyRect.width() > size && string.length() > 3) { | |
|
86 | string.remove(string.length() - 4, 1); | |
|
87 | dummyTitle.setText(string); | |
|
88 | dummyRect = dummyTitle.boundingRect(); | |
|
89 | } | |
|
90 | title->setText(string); | |
|
91 | } else { | |
|
92 | title->setText(titleText); | |
|
93 | } | |
|
73 | title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, gridRect.width(), Qt::Horizontal, QRectF())); | |
|
94 | 74 | |
|
95 | 75 | titlePad = titlePadding(); |
|
96 | 76 | titleBoundingRect = title->boundingRect(); |
@@ -104,7 +84,6 void HorizontalAxis::updateGeometry() | |||
|
104 | 84 | } |
|
105 | 85 | |
|
106 | 86 | for (int i = 0; i < layout.size(); ++i) { |
|
107 | ||
|
108 | 87 | //items |
|
109 | 88 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
110 | 89 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(arrow.at(i + 1)); |
@@ -115,18 +94,10 void HorizontalAxis::updateGeometry() | |||
|
115 | 94 | |
|
116 | 95 | //label text wrapping |
|
117 | 96 | QString text = labelList.at(i); |
|
118 |
QRectF boundingRect |
|
|
97 | QRectF boundingRect; | |
|
119 | 98 | qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); |
|
120 | if (boundingRect.height() > size) { | |
|
121 | QString label = text + "..."; | |
|
122 | while (boundingRect.height() >= size && label.length() > 3) { | |
|
123 | label.remove(label.length() - 4, 1); | |
|
124 | boundingRect = labelBoundingRect(fn, label); | |
|
125 | } | |
|
126 | labelItem->setText(label); | |
|
127 | } else { | |
|
128 | labelItem->setText(text); | |
|
129 | } | |
|
99 | labelItem->setText(truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), | |
|
100 | size, Qt::Vertical, boundingRect)); | |
|
130 | 101 | |
|
131 | 102 | //label transformation origin point |
|
132 | 103 | const QRectF& rect = labelItem->boundingRect(); |
@@ -214,16 +185,13 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co | |||
|
214 | 185 | |
|
215 | 186 | switch (which) { |
|
216 | 187 | case Qt::MinimumSize: { |
|
217 | QFontMetrics fn(axis()->titleFont()); | |
|
218 |
sh = QSizeF( |
|
|
188 | QRectF titleRect = textBoundingRect(axis()->titleFont(), "..."); | |
|
189 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); | |
|
219 | 190 | break; |
|
220 | 191 | } |
|
221 | 192 | case Qt::MaximumSize: |
|
222 | 193 | case Qt::PreferredSize: { |
|
223 | QGraphicsSimpleTextItem dummyTitle; | |
|
224 | dummyTitle.setFont(axis()->titleFont()); | |
|
225 | dummyTitle.setText(axis()->titleText()); | |
|
226 | QRectF titleRect = dummyTitle.boundingRect(); | |
|
194 | QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
|
227 | 195 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); |
|
228 | 196 | break; |
|
229 | 197 | } |
@@ -23,7 +23,6 | |||
|
23 | 23 | #include "qlogvalueaxis.h" |
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | 25 | #include <QGraphicsLayout> |
|
26 | #include <QFontMetrics> | |
|
27 | 26 | #include <qmath.h> |
|
28 | 27 | #include <QDebug> |
|
29 | 28 | |
@@ -87,7 +86,6 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
87 | 86 | { |
|
88 | 87 | Q_UNUSED(constraint) |
|
89 | 88 | |
|
90 | QFontMetrics fn(axis()->labelsFont()); | |
|
91 | 89 | QSizeF sh; |
|
92 | 90 | |
|
93 | 91 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
@@ -106,26 +104,24 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
106 | 104 | |
|
107 | 105 | switch (which) { |
|
108 | 106 | case Qt::MinimumSize:{ |
|
109 |
QRectF boundingRect = |
|
|
107 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
110 | 108 | width = boundingRect.width() / 2.0; |
|
111 | height = boundingRect.height() + labelPadding(); | |
|
112 | height += base.height(); | |
|
109 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
|
113 | 110 | sh = QSizeF(width, height); |
|
114 | 111 | break; |
|
115 | 112 | } |
|
116 | 113 | case Qt::PreferredSize: { |
|
117 |
|
|
|
118 |
|
|
|
114 | qreal labelHeight = 0.0; | |
|
115 | qreal firstWidth = -1.0; | |
|
119 | 116 | foreach (const QString& s, ticksList) { |
|
120 |
QRect rect = |
|
|
117 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
121 | 118 | labelHeight = qMax(rect.height(), labelHeight); |
|
122 | 119 | width = rect.width(); |
|
123 | if (firstWidth < 0) | |
|
120 | if (firstWidth < 0.0) | |
|
124 | 121 | firstWidth = width; |
|
125 | 122 | } |
|
126 | height = labelHeight + labelPadding(); | |
|
127 | height += base.height(); | |
|
128 | width = qMax(width, qreal(firstWidth)) / 2.0; | |
|
123 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
|
124 | width = qMax(width, firstWidth) / 2.0; | |
|
129 | 125 | sh = QSizeF(width, height); |
|
130 | 126 | break; |
|
131 | 127 | } |
@@ -23,7 +23,6 | |||
|
23 | 23 | #include "qlogvalueaxis.h" |
|
24 | 24 | #include "abstractchartlayout_p.h" |
|
25 | 25 | #include <QGraphicsLayout> |
|
26 | #include <QFontMetrics> | |
|
27 | 26 | #include <qmath.h> |
|
28 | 27 | #include <QDebug> |
|
29 | 28 | |
@@ -87,7 +86,6 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
87 | 86 | { |
|
88 | 87 | Q_UNUSED(constraint) |
|
89 | 88 | |
|
90 | QFontMetrics fn(axis()->labelsFont()); | |
|
91 | 89 | QSizeF sh; |
|
92 | 90 | |
|
93 | 91 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
@@ -106,26 +104,24 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||
|
106 | 104 | |
|
107 | 105 | switch (which) { |
|
108 | 106 | case Qt::MinimumSize: { |
|
109 |
QRectF boundingRect = |
|
|
110 | width = boundingRect.width() + labelPadding(); | |
|
111 | width += base.width(); | |
|
107 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
108 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
112 | 109 | height = boundingRect.height() / 2.0; |
|
113 | 110 | sh = QSizeF(width, height); |
|
114 | 111 | break; |
|
115 | 112 | } |
|
116 | 113 | case Qt::PreferredSize: { |
|
117 |
|
|
|
118 |
|
|
|
114 | qreal labelWidth = 0.0; | |
|
115 | qreal firstHeight = -1.0; | |
|
119 | 116 | foreach (const QString& s, ticksList) { |
|
120 |
QRect rect = |
|
|
117 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
121 | 118 | labelWidth = qMax(rect.width(), labelWidth); |
|
122 | 119 | height = rect.height(); |
|
123 | if (firstHeight < 0) | |
|
120 | if (firstHeight < 0.0) | |
|
124 | 121 | firstHeight = height; |
|
125 | 122 | } |
|
126 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance | |
|
127 | width += base.width(); | |
|
128 | height = qMax(height, qreal(firstHeight)) / 2.0; | |
|
123 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
|
124 | height = qMax(height, firstHeight) / 2.0; | |
|
129 | 125 | sh = QSizeF(width, height); |
|
130 | 126 | break; |
|
131 | 127 | } |
@@ -23,7 +23,6 | |||
|
23 | 23 | #include "abstractchartlayout_p.h" |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | #include "qabstractaxis_p.h" |
|
26 | #include <QFontMetrics> | |
|
27 | 26 | #include <QDebug> |
|
28 | 27 | |
|
29 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -59,7 +58,6 void PolarChartAxisAngular::updateGeometry() | |||
|
59 | 58 | |
|
60 | 59 | qreal radius = axisGeometry().height() / 2.0; |
|
61 | 60 | |
|
62 | QFontMetrics fn(axis()->labelsFont()); | |
|
63 | 61 | QRectF previousLabelRect; |
|
64 | 62 | QRectF firstLabelRect; |
|
65 | 63 | |
@@ -124,7 +122,7 void PolarChartAxisAngular::updateGeometry() | |||
|
124 | 122 | const QRectF &rect = labelItem->boundingRect(); |
|
125 | 123 | QPointF labelCenter = rect.center(); |
|
126 | 124 | labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); |
|
127 |
QRectF boundingRect = |
|
|
125 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); | |
|
128 | 126 | boundingRect.moveCenter(labelCenter); |
|
129 | 127 | QPointF positionDiff(rect.topLeft() - boundingRect.topLeft()); |
|
130 | 128 | |
@@ -221,28 +219,9 void PolarChartAxisAngular::updateGeometry() | |||
|
221 | 219 | // Title, centered above the chart |
|
222 | 220 | QString titleText = axis()->titleText(); |
|
223 | 221 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { |
|
224 | int size(0); | |
|
225 | size = axisGeometry().width(); | |
|
226 | ||
|
227 | QGraphicsSimpleTextItem dummyTitle; | |
|
228 | dummyTitle.setFont(axis()->titleFont()); | |
|
229 | dummyTitle.setText(titleText); | |
|
230 | QRectF dummyRect = dummyTitle.boundingRect(); | |
|
231 | ||
|
232 | if (dummyRect.width() > size) { | |
|
233 | QString string = titleText + "..."; | |
|
234 | while (dummyRect.width() > size && string.length() > 3) { | |
|
235 | string.remove(string.length() - 4, 1); | |
|
236 | dummyTitle.setText(string); | |
|
237 | dummyRect = dummyTitle.boundingRect(); | |
|
238 | } | |
|
239 | title->setText(string); | |
|
240 | } else { | |
|
241 | title->setText(titleText); | |
|
242 | } | |
|
222 | title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, axisGeometry().width(), Qt::Horizontal, QRectF())); | |
|
243 | 223 | |
|
244 | QRectF titleBoundingRect; | |
|
245 | titleBoundingRect = title->boundingRect(); | |
|
224 | QRectF titleBoundingRect = title->boundingRect(); | |
|
246 | 225 | QPointF titleCenter = center - titleBoundingRect.center(); |
|
247 | 226 | title->setPos(titleCenter.x(), axisGeometry().top() - qreal(titlePadding()) * 2.0 - titleBoundingRect.height() - labelHeight); |
|
248 | 227 | } |
@@ -339,7 +318,6 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize) | |||
|
339 | 318 | // This is a horrible way to find out the maximum radius for angular axis and its labels. |
|
340 | 319 | // It just increments the radius down until everyhing fits the constraint size. |
|
341 | 320 | // Proper way would be to actually calculate it but this seems to work reasonably fast as it is. |
|
342 | QFontMetrics fm(font); | |
|
343 | 321 | bool nextTickVisible = false; |
|
344 | 322 | for (int i = 0; i < layout.size(); ) { |
|
345 | 323 | if ((i == layout.size() - 1) |
@@ -377,7 +355,7 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize) | |||
|
377 | 355 | continue; |
|
378 | 356 | } |
|
379 | 357 | |
|
380 |
QRectF boundingRect = |
|
|
358 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); | |
|
381 | 359 | QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2(); |
|
382 | 360 | |
|
383 | 361 | boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect); |
@@ -392,12 +370,9 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize) | |||
|
392 | 370 | } |
|
393 | 371 | |
|
394 | 372 | if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) { |
|
395 | QGraphicsSimpleTextItem dummyTitle; | |
|
396 | dummyTitle.setFont(axis()->titleFont()); | |
|
397 | dummyTitle.setText(axis()->titleText()); | |
|
398 | QRectF dummyRect = dummyTitle.boundingRect(); | |
|
373 | QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
|
399 | 374 | |
|
400 |
radius -= titlePadding() + ( |
|
|
375 | radius -= titlePadding() + (titleRect.height() / 2.0); | |
|
401 | 376 | if (radius < 1.0) // safeguard |
|
402 | 377 | return 1.0; |
|
403 | 378 | } |
@@ -23,7 +23,6 | |||
|
23 | 23 | #include "abstractchartlayout_p.h" |
|
24 | 24 | #include "qabstractaxis_p.h" |
|
25 | 25 | #include "linearrowitem_p.h" |
|
26 | #include <QFontMetrics> | |
|
27 | 26 | |
|
28 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 28 | |
@@ -56,7 +55,6 void PolarChartAxisRadial::updateGeometry() | |||
|
56 | 55 | QGraphicsLineItem *axisLine = static_cast<QGraphicsLineItem *>(arrowItemList.at(0)); |
|
57 | 56 | axisLine->setLine(line); |
|
58 | 57 | |
|
59 | QFontMetrics fn(axis()->labelsFont()); | |
|
60 | 58 | QRectF previousLabelRect; |
|
61 | 59 | bool firstShade = true; |
|
62 | 60 | bool nextTickVisible = false; |
@@ -112,7 +110,7 void PolarChartAxisRadial::updateGeometry() | |||
|
112 | 110 | QRectF labelRect = labelItem->boundingRect(); |
|
113 | 111 | QPointF labelCenter = labelRect.center(); |
|
114 | 112 | labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); |
|
115 |
QRectF boundingRect = |
|
|
113 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); | |
|
116 | 114 | boundingRect.moveCenter(labelCenter); |
|
117 | 115 | QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft()); |
|
118 | 116 | QPointF labelPoint = center; |
@@ -205,25 +203,9 void PolarChartAxisRadial::updateGeometry() | |||
|
205 | 203 | // Title, along the 0 axis |
|
206 | 204 | QString titleText = axis()->titleText(); |
|
207 | 205 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { |
|
208 | QGraphicsSimpleTextItem dummyTitle; | |
|
209 | dummyTitle.setFont(axis()->titleFont()); | |
|
210 | dummyTitle.setText(titleText); | |
|
211 | QRectF dummyRect = dummyTitle.boundingRect(); | |
|
212 | ||
|
213 | if (dummyRect.width() > radius) { | |
|
214 | QString string = titleText + "..."; | |
|
215 | while (dummyRect.width() > radius && string.length() > 3) { | |
|
216 | string.remove(string.length() - 4, 1); | |
|
217 | dummyTitle.setText(string); | |
|
218 | dummyRect = dummyTitle.boundingRect(); | |
|
219 | } | |
|
220 | title->setText(string); | |
|
221 | } else { | |
|
222 | title->setText(titleText); | |
|
223 | } | |
|
206 | title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, radius, Qt::Horizontal, QRectF())); | |
|
224 | 207 | |
|
225 | QRectF titleBoundingRect; | |
|
226 | titleBoundingRect = title->boundingRect(); | |
|
208 | QRectF titleBoundingRect = title->boundingRect(); | |
|
227 | 209 | QPointF titleCenter = titleBoundingRect.center(); |
|
228 | 210 | QPointF arrowCenter = axisLine->boundingRect().center(); |
|
229 | 211 | QPointF titleCenterDiff = arrowCenter - titleCenter; |
@@ -24,7 +24,6 | |||
|
24 | 24 | #include "qvalueaxis.h" |
|
25 | 25 | #include "abstractchartlayout_p.h" |
|
26 | 26 | #include <QGraphicsLayout> |
|
27 | #include <QFontMetrics> | |
|
28 | 27 | #include <qmath.h> |
|
29 | 28 | #include <QDebug> |
|
30 | 29 | |
@@ -86,7 +85,6 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||
|
86 | 85 | { |
|
87 | 86 | Q_UNUSED(constraint) |
|
88 | 87 | |
|
89 | QFontMetrics fn(axis()->labelsFont()); | |
|
90 | 88 | QSizeF sh; |
|
91 | 89 | |
|
92 | 90 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
@@ -98,26 +96,24 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||
|
98 | 96 | |
|
99 | 97 | switch (which) { |
|
100 | 98 | case Qt::MinimumSize: { |
|
101 |
QRectF boundingRect = |
|
|
99 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
102 | 100 | width = boundingRect.width() / 2.0; |
|
103 | height = boundingRect.height() + labelPadding(); | |
|
104 | height += base.height(); | |
|
101 | height = boundingRect.height() + labelPadding() + base.height() + 1.0; | |
|
105 | 102 | sh = QSizeF(width, height); |
|
106 | 103 | break; |
|
107 | 104 | } |
|
108 | 105 | case Qt::PreferredSize: { |
|
109 |
|
|
|
110 |
|
|
|
106 | qreal labelHeight = 0.0; | |
|
107 | qreal firstWidth = -1.0; | |
|
111 | 108 | foreach (const QString& s, ticksList) { |
|
112 |
QRect rect = |
|
|
109 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
113 | 110 | labelHeight = qMax(rect.height(), labelHeight); |
|
114 | 111 | width = rect.width(); |
|
115 | if (firstWidth < 0) | |
|
112 | if (firstWidth < 0.0) | |
|
116 | 113 | firstWidth = width; |
|
117 | 114 | } |
|
118 | height = labelHeight + labelPadding(); | |
|
119 | height += base.height(); | |
|
120 | width = qMax(width, qreal(firstWidth)) / 2.0; | |
|
115 | height = labelHeight + labelPadding() + base.height() + 1.0; | |
|
116 | width = qMax(width, firstWidth) / 2.0; | |
|
121 | 117 | sh = QSizeF(width, height); |
|
122 | 118 | break; |
|
123 | 119 | } |
@@ -24,7 +24,6 | |||
|
24 | 24 | #include "qvalueaxis.h" |
|
25 | 25 | #include "abstractchartlayout_p.h" |
|
26 | 26 | #include <QGraphicsLayout> |
|
27 | #include <QFontMetrics> | |
|
28 | 27 | #include <qmath.h> |
|
29 | 28 | #include <QDebug> |
|
30 | 29 | |
@@ -87,7 +86,6 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||
|
87 | 86 | { |
|
88 | 87 | Q_UNUSED(constraint) |
|
89 | 88 | |
|
90 | QFontMetrics fn(axis()->labelsFont()); | |
|
91 | 89 | QSizeF sh; |
|
92 | 90 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
93 | 91 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
@@ -98,26 +96,24 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||
|
98 | 96 | |
|
99 | 97 | switch (which) { |
|
100 | 98 | case Qt::MinimumSize: { |
|
101 |
QRectF boundingRect = |
|
|
102 | width = boundingRect.width() + labelPadding(); | |
|
103 | width += base.width(); | |
|
99 | QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle()); | |
|
100 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
104 | 101 | height = boundingRect.height() / 2.0; |
|
105 | 102 | sh = QSizeF(width, height); |
|
106 | 103 | break; |
|
107 | 104 | } |
|
108 | 105 | case Qt::PreferredSize: { |
|
109 |
|
|
|
110 |
|
|
|
106 | qreal labelWidth = 0.0; | |
|
107 | qreal firstHeight = -1.0; | |
|
111 | 108 | foreach (const QString& s, ticksList) { |
|
112 |
QRect rect = |
|
|
109 | QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
113 | 110 | labelWidth = qMax(rect.width(), labelWidth); |
|
114 | 111 | height = rect.height(); |
|
115 | if (firstHeight < 0) | |
|
112 | if (firstHeight < 0.0) | |
|
116 | 113 | firstHeight = height; |
|
117 | 114 | } |
|
118 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance | |
|
119 | width += base.width(); | |
|
120 | height = qMax(height, qreal(firstHeight)) / 2.0; | |
|
115 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
|
116 | height = qMax(height, firstHeight) / 2.0; | |
|
121 | 117 | sh = QSizeF(width, height); |
|
122 | 118 | break; |
|
123 | 119 | } |
@@ -20,7 +20,6 | |||
|
20 | 20 | |
|
21 | 21 | #include "verticalaxis_p.h" |
|
22 | 22 | #include "qabstractaxis.h" |
|
23 | #include <QFontMetrics> | |
|
24 | 23 | #include <QDebug> |
|
25 | 24 | |
|
26 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -67,32 +66,12 void VerticalAxis::updateGeometry() | |||
|
67 | 66 | else if (axis()->alignment() == Qt::AlignRight) |
|
68 | 67 | arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom()); |
|
69 | 68 | |
|
70 | QFontMetrics fn(axis()->labelsFont()); | |
|
71 | ||
|
72 | 69 | //title |
|
73 | 70 | int titlePad = 0; |
|
74 | 71 | QRectF titleBoundingRect; |
|
75 | 72 | QString titleText = axis()->titleText(); |
|
76 | 73 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
77 | int size(0); | |
|
78 | size = gridRect.height(); | |
|
79 | ||
|
80 | QGraphicsSimpleTextItem dummyTitle; | |
|
81 | dummyTitle.setFont(axis()->titleFont()); | |
|
82 | dummyTitle.setText(axis()->titleText()); | |
|
83 | QRectF dummyRect = dummyTitle.boundingRect(); | |
|
84 | ||
|
85 | if (dummyRect.width() > size) { | |
|
86 | QString string = titleText + "..."; | |
|
87 | while (dummyRect.width() > size && string.length() > 3) { | |
|
88 | string.remove(string.length() - 4, 1); | |
|
89 | dummyTitle.setText(string); | |
|
90 | dummyRect = dummyTitle.boundingRect(); | |
|
91 | } | |
|
92 | title->setText(string); | |
|
93 | } else { | |
|
94 | title->setText(titleText); | |
|
95 | } | |
|
74 | title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, gridRect.height(), Qt::Horizontal, QRectF())); | |
|
96 | 75 | |
|
97 | 76 | titlePad = titlePadding(); |
|
98 | 77 | titleBoundingRect = title->boundingRect(); |
@@ -119,23 +98,13 void VerticalAxis::updateGeometry() | |||
|
119 | 98 | |
|
120 | 99 | //label text wrapping |
|
121 | 100 | QString text = labelList.at(i); |
|
122 |
QRectF boundingRect |
|
|
123 | ||
|
101 | QRectF boundingRect; | |
|
124 | 102 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); |
|
125 | if (boundingRect.width() > size) { | |
|
126 | QString label = text + "..."; | |
|
127 | while (boundingRect.width() > size && label.length() > 3) { | |
|
128 | label.remove(label.length() - 4, 1); | |
|
129 | boundingRect = labelBoundingRect(fn, label); | |
|
130 | } | |
|
131 | labelItem->setText(label); | |
|
132 | } else { | |
|
133 | labelItem->setText(text); | |
|
134 | } | |
|
103 | labelItem->setText(truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), | |
|
104 | size, Qt::Horizontal, boundingRect)); | |
|
135 | 105 | |
|
136 | 106 | //label transformation origin point |
|
137 | 107 | const QRectF &rect = labelItem->boundingRect(); |
|
138 | ||
|
139 | 108 | QPointF center = rect.center(); |
|
140 | 109 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
141 | 110 | int widthDiff = rect.width() - boundingRect.width(); |
@@ -221,16 +190,13 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons | |||
|
221 | 190 | |
|
222 | 191 | switch (which) { |
|
223 | 192 | case Qt::MinimumSize: { |
|
224 | QFontMetrics fn(axis()->titleFont()); | |
|
225 |
sh = QSizeF( |
|
|
193 | QRectF titleRect = textBoundingRect(axis()->titleFont(), "..."); | |
|
194 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); | |
|
226 | 195 | break; |
|
227 | 196 | } |
|
228 | 197 | case Qt::MaximumSize: |
|
229 | 198 | case Qt::PreferredSize: { |
|
230 | QGraphicsSimpleTextItem dummyTitle; | |
|
231 | dummyTitle.setFont(axis()->titleFont()); | |
|
232 | dummyTitle.setText(axis()->titleText()); | |
|
233 | QRectF titleRect = dummyTitle.boundingRect(); | |
|
199 | QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
|
234 | 200 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); |
|
235 | 201 | break; |
|
236 | 202 | } |
@@ -22,7 +22,6 | |||
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "polarchartaxis_p.h" |
|
24 | 24 | #include <QDebug> |
|
25 | #include <QFontMetrics> | |
|
26 | 25 | |
|
27 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 27 | |
@@ -58,10 +57,7 QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, const QLi | |||
|
58 | 57 | && chartAxis->axis()->isTitleVisible() |
|
59 | 58 | && !chartAxis->axis()->titleText().isEmpty()) { |
|
60 | 59 | // If axis has angular title, adjust geometry down by the space title takes |
|
61 | QGraphicsSimpleTextItem dummyTitle; | |
|
62 | dummyTitle.setFont(chartAxis->axis()->titleFont()); | |
|
63 | dummyTitle.setText(chartAxis->axis()->titleText()); | |
|
64 | QRectF dummyRect = dummyTitle.boundingRect(); | |
|
60 | QRectF dummyRect = chartAxis->textBoundingRect(chartAxis->axis()->titleFont(), chartAxis->axis()->titleText()); | |
|
65 | 61 | titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding(); |
|
66 | 62 | } |
|
67 | 63 | } |
General Comments 0
You need to be logged in to leave comments.
Login now