@@ -59,8 +59,8 public: | |||||
59 | QAbstractAxis *axis() const { return m_axis; } |
|
59 | QAbstractAxis *axis() const { return m_axis; } | |
60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } |
|
60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } | |
61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference |
|
61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference | |
62 |
in |
|
62 | inline qreal labelPadding() const { return qreal(5.0); } | |
63 |
in |
|
63 | inline qreal titlePadding() const { return qreal(3.0); } | |
64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } |
|
64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } | |
65 | QStringList labels() const { return m_labelsList; } |
|
65 | QStringList labels() const { return m_labelsList; } | |
66 |
|
66 |
@@ -67,21 +67,39 void HorizontalAxis::updateGeometry() | |||||
67 | qreal width = 0; |
|
67 | qreal width = 0; | |
68 |
|
68 | |||
69 | //title |
|
69 | //title | |
70 | int titlePad = 0; |
|
|||
71 | QRectF titleBoundingRect; |
|
70 | QRectF titleBoundingRect; | |
72 | QString titleText = axis()->titleText(); |
|
71 | QString titleText = axis()->titleText(); | |
|
72 | qreal availableSpace = axisRect.height() - labelPadding(); | |||
73 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
73 | if (!titleText.isEmpty() && titleItem()->isVisible()) { | |
74 | title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.width(), Qt::Horizontal, QRectF())); |
|
74 | availableSpace -= titlePadding() * 2.0; | |
|
75 | qreal minimumLabelHeight = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...").height(); | |||
|
76 | QString truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), | |||
|
77 | gridRect.width(), Qt::Horizontal, titleBoundingRect); | |||
|
78 | qreal titleSpace = availableSpace - minimumLabelHeight; | |||
|
79 | if (titleSpace < titleBoundingRect.height()) { | |||
|
80 | // Need to also truncate title vertically (multiline title) | |||
|
81 | bool skip = false; | |||
|
82 | if (truncatedTitle.endsWith("...")) { | |||
|
83 | if (truncatedTitle.size() == 3) | |||
|
84 | skip = true; // Already truncated to minimum | |||
|
85 | else | |||
|
86 | truncatedTitle.chop(3); | |||
|
87 | } | |||
|
88 | if (!skip) | |||
|
89 | truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), truncatedTitle, qreal(0.0), | |||
|
90 | titleSpace, Qt::Vertical, titleBoundingRect); | |||
|
91 | } | |||
|
92 | title->setHtml(truncatedTitle); | |||
75 |
|
93 | |||
76 | titlePad = titlePadding(); |
|
|||
77 | titleBoundingRect = title->boundingRect(); |
|
94 | titleBoundingRect = title->boundingRect(); | |
78 |
|
95 | |||
79 | QPointF center = gridRect.center() - titleBoundingRect.center(); |
|
96 | QPointF center = gridRect.center() - titleBoundingRect.center(); | |
80 |
if (axis()->alignment() == Qt::AlignTop) |
|
97 | if (axis()->alignment() == Qt::AlignTop) | |
81 | title->setPos(center.x(), axisRect.top() + titlePad); |
|
98 | title->setPos(center.x(), axisRect.top() + titlePadding()); | |
82 |
|
|
99 | else if (axis()->alignment() == Qt::AlignBottom) | |
83 | title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad); |
|
100 | title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePadding()); | |
84 | } |
|
101 | ||
|
102 | availableSpace -= titleBoundingRect.height(); | |||
85 | } |
|
103 | } | |
86 |
|
104 | |||
87 | for (int i = 0; i < layout.size(); ++i) { |
|
105 | for (int i = 0; i < layout.size(); ++i) { | |
@@ -96,22 +114,21 void HorizontalAxis::updateGeometry() | |||||
96 | //label text wrapping |
|
114 | //label text wrapping | |
97 | QString text = labelList.at(i); |
|
115 | QString text = labelList.at(i); | |
98 | QRectF boundingRect; |
|
116 | QRectF boundingRect; | |
99 | qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); |
|
|||
100 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), |
|
117 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), | |
101 |
|
|
118 | availableSpace, Qt::Vertical, boundingRect)); | |
102 |
|
119 | |||
103 | //label transformation origin point |
|
120 | //label transformation origin point | |
104 | const QRectF& rect = labelItem->boundingRect(); |
|
121 | const QRectF& rect = labelItem->boundingRect(); | |
105 | QPointF center = rect.center(); |
|
122 | QPointF center = rect.center(); | |
106 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
123 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
107 |
|
|
124 | qreal heightDiff = rect.height() - boundingRect.height(); | |
108 |
|
125 | |||
109 | //ticks and label position |
|
126 | //ticks and label position | |
110 | if (axis()->alignment() == Qt::AlignTop) { |
|
127 | if (axis()->alignment() == Qt::AlignTop) { | |
111 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2) - labelPadding()); |
|
128 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2.0) - labelPadding()); | |
112 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); |
|
129 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); | |
113 | } else if (axis()->alignment() == Qt::AlignBottom) { |
|
130 | } else if (axis()->alignment() == Qt::AlignBottom) { | |
114 | labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2) + labelPadding()); |
|
131 | labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2.0) + labelPadding()); | |
115 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); |
|
132 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); | |
116 | } |
|
133 | } | |
117 |
|
134 | |||
@@ -187,13 +204,13 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co | |||||
187 | switch (which) { |
|
204 | switch (which) { | |
188 | case Qt::MinimumSize: { |
|
205 | case Qt::MinimumSize: { | |
189 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "..."); |
|
206 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "..."); | |
190 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); |
|
207 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2.0)); | |
191 | break; |
|
208 | break; | |
192 | } |
|
209 | } | |
193 | case Qt::MaximumSize: |
|
210 | case Qt::MaximumSize: | |
194 | case Qt::PreferredSize: { |
|
211 | case Qt::PreferredSize: { | |
195 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); |
|
212 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
196 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2)); |
|
213 | sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2.0)); | |
197 | break; |
|
214 | break; | |
198 | } |
|
215 | } | |
199 | default: |
|
216 | default: |
@@ -223,7 +223,7 void PolarChartAxisAngular::updateGeometry() | |||||
223 |
|
223 | |||
224 | QRectF titleBoundingRect = title->boundingRect(); |
|
224 | QRectF titleBoundingRect = title->boundingRect(); | |
225 | QPointF titleCenter = center - titleBoundingRect.center(); |
|
225 | QPointF titleCenter = center - titleBoundingRect.center(); | |
226 |
title->setPos(titleCenter.x(), axisGeometry().top() - |
|
226 | title->setPos(titleCenter.x(), axisGeometry().top() - titlePadding() * 2.0 - titleBoundingRect.height() - labelHeight); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 |
|
229 |
@@ -209,7 +209,7 void PolarChartAxisRadial::updateGeometry() | |||||
209 | QPointF titleCenter = titleBoundingRect.center(); |
|
209 | QPointF titleCenter = titleBoundingRect.center(); | |
210 | QPointF arrowCenter = axisLine->boundingRect().center(); |
|
210 | QPointF arrowCenter = axisLine->boundingRect().center(); | |
211 | QPointF titleCenterDiff = arrowCenter - titleCenter; |
|
211 | QPointF titleCenterDiff = arrowCenter - titleCenter; | |
212 |
title->setPos(titleCenterDiff.x() - |
|
212 | title->setPos(titleCenterDiff.x() - titlePadding() - (titleBoundingRect.height() / 2.0), titleCenterDiff.y()); | |
213 | title->setTransformOriginPoint(titleCenter); |
|
213 | title->setTransformOriginPoint(titleCenter); | |
214 | title->setRotation(270.0); |
|
214 | title->setRotation(270.0); | |
215 | } |
|
215 | } |
@@ -68,24 +68,42 void VerticalAxis::updateGeometry() | |||||
68 | arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom()); |
|
68 | arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom()); | |
69 |
|
69 | |||
70 | //title |
|
70 | //title | |
71 | int titlePad = 0; |
|
|||
72 | QRectF titleBoundingRect; |
|
71 | QRectF titleBoundingRect; | |
73 | QString titleText = axis()->titleText(); |
|
72 | QString titleText = axis()->titleText(); | |
|
73 | qreal availableSpace = axisRect.width() - labelPadding(); | |||
74 | if (!titleText.isEmpty() && titleItem()->isVisible()) { |
|
74 | if (!titleText.isEmpty() && titleItem()->isVisible()) { | |
75 | title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.height(), Qt::Horizontal, QRectF())); |
|
75 | availableSpace -= titlePadding() * 2.0; | |
|
76 | qreal minimumLabelWidth = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...").width(); | |||
|
77 | QString truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), | |||
|
78 | gridRect.height(), Qt::Horizontal, titleBoundingRect); | |||
|
79 | qreal titleSpace = availableSpace - minimumLabelWidth; | |||
|
80 | if (titleSpace < titleBoundingRect.width()) { | |||
|
81 | // Need to also truncate title vertically (multiline title) | |||
|
82 | bool skip = false; | |||
|
83 | if (truncatedTitle.endsWith("...")) { | |||
|
84 | if (truncatedTitle.size() == 3) | |||
|
85 | skip = true; // Already truncated to minimum | |||
|
86 | else | |||
|
87 | truncatedTitle.chop(3); | |||
|
88 | } | |||
|
89 | if (!skip) | |||
|
90 | truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), truncatedTitle, qreal(0.0), | |||
|
91 | titleSpace, Qt::Vertical, titleBoundingRect); | |||
|
92 | } | |||
|
93 | title->setHtml(truncatedTitle); | |||
76 |
|
94 | |||
77 | titlePad = titlePadding(); |
|
|||
78 | titleBoundingRect = title->boundingRect(); |
|
95 | titleBoundingRect = title->boundingRect(); | |
79 |
|
96 | |||
80 | QPointF center = gridRect.center() - titleBoundingRect.center(); |
|
97 | QPointF center = gridRect.center() - titleBoundingRect.center(); | |
81 |
if (axis()->alignment() == Qt::AlignLeft) |
|
98 | if (axis()->alignment() == Qt::AlignLeft) | |
82 | title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y()); |
|
99 | title->setPos(axisRect.left() - titleBoundingRect.width() / 2.0 + titleBoundingRect.height() / 2.0 + titlePadding(), center.y()); | |
83 | } |
|
100 | else if (axis()->alignment() == Qt::AlignRight) | |
84 | else if (axis()->alignment() == Qt::AlignRight) { |
|
101 | title->setPos(axisRect.right() - titleBoundingRect.width() / 2.0 - titleBoundingRect.height() / 2.0 - titlePadding(), center.y()); | |
85 | title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y()); |
|
102 | ||
86 | } |
|
|||
87 | title->setTransformOriginPoint(titleBoundingRect.center()); |
|
103 | title->setTransformOriginPoint(titleBoundingRect.center()); | |
88 | title->setRotation(270); |
|
104 | title->setRotation(270); | |
|
105 | ||||
|
106 | availableSpace -= titleBoundingRect.height(); | |||
89 | } |
|
107 | } | |
90 |
|
108 | |||
91 | for (int i = 0; i < layout.size(); ++i) { |
|
109 | for (int i = 0; i < layout.size(); ++i) { | |
@@ -100,22 +118,21 void VerticalAxis::updateGeometry() | |||||
100 | //label text wrapping |
|
118 | //label text wrapping | |
101 | QString text = labelList.at(i); |
|
119 | QString text = labelList.at(i); | |
102 | QRectF boundingRect; |
|
120 | QRectF boundingRect; | |
103 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); |
|
|||
104 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), |
|
121 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), | |
105 |
|
|
122 | availableSpace, Qt::Horizontal, boundingRect)); | |
106 |
|
123 | |||
107 | //label transformation origin point |
|
124 | //label transformation origin point | |
108 | const QRectF &rect = labelItem->boundingRect(); |
|
125 | const QRectF &rect = labelItem->boundingRect(); | |
109 | QPointF center = rect.center(); |
|
126 | QPointF center = rect.center(); | |
110 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
127 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
111 |
|
|
128 | qreal widthDiff = rect.width() - boundingRect.width(); | |
112 |
|
129 | |||
113 | //ticks and label position |
|
130 | //ticks and label position | |
114 | if (axis()->alignment() == Qt::AlignLeft) { |
|
131 | if (axis()->alignment() == Qt::AlignLeft) { | |
115 | labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2) - labelPadding(), layout[i] - center.y()); |
|
132 | labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2.0) - labelPadding(), layout[i] - center.y()); | |
116 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); |
|
133 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); | |
117 | } else if (axis()->alignment() == Qt::AlignRight) { |
|
134 | } else if (axis()->alignment() == Qt::AlignRight) { | |
118 | labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2), layout[i] - center.y()); |
|
135 | labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2.0), layout[i] - center.y()); | |
119 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); |
|
136 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); | |
120 | } |
|
137 | } | |
121 |
|
138 | |||
@@ -192,13 +209,13 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons | |||||
192 | switch (which) { |
|
209 | switch (which) { | |
193 | case Qt::MinimumSize: { |
|
210 | case Qt::MinimumSize: { | |
194 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "..."); |
|
211 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "..."); | |
195 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); |
|
212 | sh = QSizeF(titleRect.height() + (titlePadding() * 2.0), titleRect.width()); | |
196 | break; |
|
213 | break; | |
197 | } |
|
214 | } | |
198 | case Qt::MaximumSize: |
|
215 | case Qt::MaximumSize: | |
199 | case Qt::PreferredSize: { |
|
216 | case Qt::PreferredSize: { | |
200 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); |
|
217 | QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText()); | |
201 | sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width()); |
|
218 | sh = QSizeF(titleRect.height() + (titlePadding() * 2.0), titleRect.width()); | |
202 | break; |
|
219 | break; | |
203 | } |
|
220 | } | |
204 | default: |
|
221 | default: |
General Comments 0
You need to be logged in to leave comments.
Login now