@@ -72,14 +72,21 void HorizontalAxis::updateGeometry() | |||||
72 | QRectF titleBoundingRect; |
|
72 | QRectF titleBoundingRect; | |
73 | QString titleText = axis()->titleText(); |
|
73 | QString titleText = axis()->titleText(); | |
74 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
74 | if (!titleText.isEmpty() && titleItem()->isVisible()) { | |
75 | QFontMetrics fn(title->font()); |
|
|||
76 | int size(0); |
|
75 | int size(0); | |
77 | size = gridRect.width(); |
|
76 | size = gridRect.width(); | |
78 |
|
77 | |||
79 | if (fn.boundingRect(titleText).width() > size) { |
|
78 | QGraphicsSimpleTextItem dummyTitle; | |
|
79 | dummyTitle.setFont(axis()->titleFont()); | |||
|
80 | dummyTitle.setText(axis()->titleText()); | |||
|
81 | QRectF dummyRect = dummyTitle.boundingRect(); | |||
|
82 | ||||
|
83 | if (dummyRect.width() > size) { | |||
80 | QString string = titleText + "..."; |
|
84 | QString string = titleText + "..."; | |
81 |
while ( |
|
85 | while (dummyRect.width() > size && string.length() > 3) { | |
82 | string.remove(string.length() - 4, 1); |
|
86 | string.remove(string.length() - 4, 1); | |
|
87 | dummyTitle.setText(string); | |||
|
88 | dummyRect = dummyTitle.boundingRect(); | |||
|
89 | } | |||
83 | title->setText(string); |
|
90 | title->setText(string); | |
84 | } else { |
|
91 | } else { | |
85 | title->setText(titleText); |
|
92 | title->setText(titleText); | |
@@ -200,20 +207,26 void HorizontalAxis::updateGeometry() | |||||
200 | QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
207 | QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
201 | { |
|
208 | { | |
202 | Q_UNUSED(constraint); |
|
209 | Q_UNUSED(constraint); | |
203 | QFontMetrics fn(axis()->titleFont()); |
|
|||
204 | QSizeF sh(0,0); |
|
210 | QSizeF sh(0,0); | |
205 |
|
211 | |||
206 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) |
|
212 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) | |
207 | return sh; |
|
213 | return sh; | |
208 |
|
214 | |||
209 | switch (which) { |
|
215 | switch (which) { | |
210 | case Qt::MinimumSize: |
|
216 | case Qt::MinimumSize: { | |
|
217 | QFontMetrics fn(axis()->titleFont()); | |||
211 |
|
|
218 | sh = QSizeF(fn.boundingRect("...").width(), fn.height() + (titlePadding() * 2)); | |
212 | break; |
|
219 | break; | |
|
220 | } | |||
213 | case Qt::MaximumSize: |
|
221 | case Qt::MaximumSize: | |
214 | case Qt::PreferredSize: |
|
222 | case Qt::PreferredSize: { | |
215 | sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height() + (titlePadding() * 2)); |
|
223 | QGraphicsSimpleTextItem dummyTitle; | |
|
224 | dummyTitle.setFont(axis()->titleFont()); | |||
|
225 | dummyTitle.setText(axis()->titleText()); | |||
|
226 | QRectF titleRect = dummyTitle.boundingRect(); | |||
|
227 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); | |||
216 | break; |
|
228 | break; | |
|
229 | } | |||
217 | default: |
|
230 | default: | |
218 | break; |
|
231 | break; | |
219 | } |
|
232 | } |
@@ -224,11 +224,18 void PolarChartAxisAngular::updateGeometry() | |||||
224 | int size(0); |
|
224 | int size(0); | |
225 | size = axisGeometry().width(); |
|
225 | size = axisGeometry().width(); | |
226 |
|
226 | |||
227 | QFontMetrics titleMetrics(axis()->titleFont()); |
|
227 | QGraphicsSimpleTextItem dummyTitle; | |
228 | if (titleMetrics.boundingRect(titleText).width() > size) { |
|
228 | dummyTitle.setFont(axis()->titleFont()); | |
|
229 | dummyTitle.setText(titleText); | |||
|
230 | QRectF dummyRect = dummyTitle.boundingRect(); | |||
|
231 | ||||
|
232 | if (dummyRect.width() > size) { | |||
229 | QString string = titleText + "..."; |
|
233 | QString string = titleText + "..."; | |
230 |
while ( |
|
234 | while (dummyRect.width() > size && string.length() > 3) { | |
231 | string.remove(string.length() - 4, 1); |
|
235 | string.remove(string.length() - 4, 1); | |
|
236 | dummyTitle.setText(string); | |||
|
237 | dummyRect = dummyTitle.boundingRect(); | |||
|
238 | } | |||
232 | title->setText(string); |
|
239 | title->setText(string); | |
233 | } else { |
|
240 | } else { | |
234 | title->setText(titleText); |
|
241 | title->setText(titleText); | |
@@ -385,9 +392,12 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize) | |||||
385 | } |
|
392 | } | |
386 |
|
393 | |||
387 | if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) { |
|
394 | if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) { | |
388 | QFontMetrics titleMetrics(axis()->titleFont()); |
|
395 | QGraphicsSimpleTextItem dummyTitle; | |
389 | int titleHeight = titleMetrics.boundingRect(axis()->titleText()).height(); |
|
396 | dummyTitle.setFont(axis()->titleFont()); | |
390 | radius -= titlePadding() + (titleHeight / 2); |
|
397 | dummyTitle.setText(axis()->titleText()); | |
|
398 | QRectF dummyRect = dummyTitle.boundingRect(); | |||
|
399 | ||||
|
400 | radius -= titlePadding() + (dummyRect.height() / 2.0); | |||
391 | if (radius < 1.0) // safeguard |
|
401 | if (radius < 1.0) // safeguard | |
392 | return 1.0; |
|
402 | return 1.0; | |
393 | } |
|
403 | } |
@@ -205,11 +205,18 void PolarChartAxisRadial::updateGeometry() | |||||
205 | // Title, along the 0 axis |
|
205 | // Title, along the 0 axis | |
206 | QString titleText = axis()->titleText(); |
|
206 | QString titleText = axis()->titleText(); | |
207 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { |
|
207 | if (!titleText.isEmpty() && axis()->isTitleVisible()) { | |
208 | QFontMetrics titleMetrics(axis()->titleFont()); |
|
208 | QGraphicsSimpleTextItem dummyTitle; | |
209 | if (titleMetrics.boundingRect(titleText).width() > radius) { |
|
209 | dummyTitle.setFont(axis()->titleFont()); | |
|
210 | dummyTitle.setText(titleText); | |||
|
211 | QRectF dummyRect = dummyTitle.boundingRect(); | |||
|
212 | ||||
|
213 | if (dummyRect.width() > radius) { | |||
210 | QString string = titleText + "..."; |
|
214 | QString string = titleText + "..."; | |
211 |
while ( |
|
215 | while (dummyRect.width() > radius && string.length() > 3) { | |
212 | string.remove(string.length() - 4, 1); |
|
216 | string.remove(string.length() - 4, 1); | |
|
217 | dummyTitle.setText(string); | |||
|
218 | dummyRect = dummyTitle.boundingRect(); | |||
|
219 | } | |||
213 | title->setText(string); |
|
220 | title->setText(string); | |
214 | } else { |
|
221 | } else { | |
215 | title->setText(titleText); |
|
222 | title->setText(titleText); |
@@ -74,14 +74,21 void VerticalAxis::updateGeometry() | |||||
74 | QRectF titleBoundingRect; |
|
74 | QRectF titleBoundingRect; | |
75 | QString titleText = axis()->titleText(); |
|
75 | QString titleText = axis()->titleText(); | |
76 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
76 | if (!titleText.isEmpty() && titleItem()->isVisible()) { | |
77 | QFontMetrics fn(title->font()); |
|
|||
78 | int size(0); |
|
77 | int size(0); | |
79 | size = gridRect.height(); |
|
78 | size = gridRect.height(); | |
80 |
|
79 | |||
81 | if (fn.boundingRect(titleText).width() > size) { |
|
80 | QGraphicsSimpleTextItem dummyTitle; | |
|
81 | dummyTitle.setFont(axis()->titleFont()); | |||
|
82 | dummyTitle.setText(axis()->titleText()); | |||
|
83 | QRectF dummyRect = dummyTitle.boundingRect(); | |||
|
84 | ||||
|
85 | if (dummyRect.width() > size) { | |||
82 | QString string = titleText + "..."; |
|
86 | QString string = titleText + "..."; | |
83 |
while ( |
|
87 | while (dummyRect.width() > size && string.length() > 3) { | |
84 | string.remove(string.length() - 4, 1); |
|
88 | string.remove(string.length() - 4, 1); | |
|
89 | dummyTitle.setText(string); | |||
|
90 | dummyRect = dummyTitle.boundingRect(); | |||
|
91 | } | |||
85 | title->setText(string); |
|
92 | title->setText(string); | |
86 | } else { |
|
93 | } else { | |
87 | title->setText(titleText); |
|
94 | title->setText(titleText); | |
@@ -206,22 +213,27 void VerticalAxis::updateGeometry() | |||||
206 |
|
213 | |||
207 | QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
214 | QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
208 | { |
|
215 | { | |
209 |
|
||||
210 | Q_UNUSED(constraint); |
|
216 | Q_UNUSED(constraint); | |
211 | QFontMetrics fn(axis()->titleFont()); |
|
|||
212 | QSizeF sh(0, 0); |
|
217 | QSizeF sh(0, 0); | |
213 |
|
218 | |||
214 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) |
|
219 | if (axis()->titleText().isEmpty() || !titleItem()->isVisible()) | |
215 | return sh; |
|
220 | return sh; | |
216 |
|
221 | |||
217 | switch (which) { |
|
222 | switch (which) { | |
218 | case Qt::MinimumSize: |
|
223 | case Qt::MinimumSize: { | |
|
224 | QFontMetrics fn(axis()->titleFont()); | |||
219 |
|
|
225 | sh = QSizeF(fn.height() + (titlePadding() * 2), fn.boundingRect("...").width()); | |
220 | break; |
|
226 | break; | |
|
227 | } | |||
221 | case Qt::MaximumSize: |
|
228 | case Qt::MaximumSize: | |
222 | case Qt::PreferredSize: |
|
229 | case Qt::PreferredSize: { | |
223 | sh = QSizeF(fn.height() + (titlePadding() * 2), fn.boundingRect(axis()->titleText()).width()); |
|
230 | QGraphicsSimpleTextItem dummyTitle; | |
|
231 | dummyTitle.setFont(axis()->titleFont()); | |||
|
232 | dummyTitle.setText(axis()->titleText()); | |||
|
233 | QRectF titleRect = dummyTitle.boundingRect(); | |||
|
234 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); | |||
224 | break; |
|
235 | break; | |
|
236 | } | |||
225 | default: |
|
237 | default: | |
226 | break; |
|
238 | break; | |
227 | } |
|
239 | } |
@@ -58,8 +58,11 QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, const QLi | |||||
58 | && chartAxis->axis()->isTitleVisible() |
|
58 | && chartAxis->axis()->isTitleVisible() | |
59 | && !chartAxis->axis()->titleText().isEmpty()) { |
|
59 | && !chartAxis->axis()->titleText().isEmpty()) { | |
60 | // If axis has angular title, adjust geometry down by the space title takes |
|
60 | // If axis has angular title, adjust geometry down by the space title takes | |
61 | QFontMetrics titleMetrics(chartAxis->axis()->titleFont()); |
|
61 | QGraphicsSimpleTextItem dummyTitle; | |
62 | titleHeight = (titleMetrics.boundingRect(chartAxis->axis()->titleText()).height() / 2) + chartAxis->titlePadding(); |
|
62 | dummyTitle.setFont(chartAxis->axis()->titleFont()); | |
|
63 | dummyTitle.setText(chartAxis->axis()->titleText()); | |||
|
64 | QRectF dummyRect = dummyTitle.boundingRect(); | |||
|
65 | titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding(); | |||
63 | } |
|
66 | } | |
64 | } |
|
67 | } | |
65 |
|
68 |
General Comments 0
You need to be logged in to leave comments.
Login now