@@ -59,8 +59,8 public: | |||
|
59 | 59 | QAbstractAxis *axis() const { return m_axis; } |
|
60 | 60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } |
|
61 | 61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference |
|
62 |
in |
|
|
63 |
in |
|
|
62 | inline qreal labelPadding() const { return qreal(5.0); } | |
|
63 | inline qreal titlePadding() const { return qreal(3.0); } | |
|
64 | 64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } |
|
65 | 65 | QStringList labels() const { return m_labelsList; } |
|
66 | 66 |
@@ -67,21 +67,39 void HorizontalAxis::updateGeometry() | |||
|
67 | 67 | qreal width = 0; |
|
68 | 68 | |
|
69 | 69 | //title |
|
70 | int titlePad = 0; | |
|
71 | 70 | QRectF titleBoundingRect; |
|
72 | 71 | QString titleText = axis()->titleText(); |
|
72 | qreal availableSpace = axisRect.height() - labelPadding(); | |
|
73 | 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 | 94 | titleBoundingRect = title->boundingRect(); |
|
78 | 95 | |
|
79 | 96 | QPointF center = gridRect.center() - titleBoundingRect.center(); |
|
80 |
if (axis()->alignment() == Qt::AlignTop) |
|
|
81 | title->setPos(center.x(), axisRect.top() + titlePad); | |
|
82 |
|
|
|
83 | title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad); | |
|
84 | } | |
|
97 | if (axis()->alignment() == Qt::AlignTop) | |
|
98 | title->setPos(center.x(), axisRect.top() + titlePadding()); | |
|
99 | else if (axis()->alignment() == Qt::AlignBottom) | |
|
100 | title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePadding()); | |
|
101 | ||
|
102 | availableSpace -= titleBoundingRect.height(); | |
|
85 | 103 | } |
|
86 | 104 | |
|
87 | 105 | for (int i = 0; i < layout.size(); ++i) { |
@@ -96,22 +114,21 void HorizontalAxis::updateGeometry() | |||
|
96 | 114 | //label text wrapping |
|
97 | 115 | QString text = labelList.at(i); |
|
98 | 116 | QRectF boundingRect; |
|
99 | qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); | |
|
100 | 117 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), |
|
101 |
|
|
|
118 | availableSpace, Qt::Vertical, boundingRect)); | |
|
102 | 119 | |
|
103 | 120 | //label transformation origin point |
|
104 | 121 | const QRectF& rect = labelItem->boundingRect(); |
|
105 | 122 | QPointF center = rect.center(); |
|
106 | 123 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
107 |
|
|
|
124 | qreal heightDiff = rect.height() - boundingRect.height(); | |
|
108 | 125 | |
|
109 | 126 | //ticks and label position |
|
110 | 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 | 129 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); |
|
113 | 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 | 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 | 204 | switch (which) { |
|
188 | 205 | case Qt::MinimumSize: { |
|
189 | 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 | 208 | break; |
|
192 | 209 | } |
|
193 | 210 | case Qt::MaximumSize: |
|
194 | 211 | case Qt::PreferredSize: { |
|
195 | 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 | 214 | break; |
|
198 | 215 | } |
|
199 | 216 | default: |
@@ -223,7 +223,7 void PolarChartAxisAngular::updateGeometry() | |||
|
223 | 223 | |
|
224 | 224 | QRectF titleBoundingRect = title->boundingRect(); |
|
225 | 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 | 209 | QPointF titleCenter = titleBoundingRect.center(); |
|
210 | 210 | QPointF arrowCenter = axisLine->boundingRect().center(); |
|
211 | 211 | QPointF titleCenterDiff = arrowCenter - titleCenter; |
|
212 |
title->setPos(titleCenterDiff.x() - |
|
|
212 | title->setPos(titleCenterDiff.x() - titlePadding() - (titleBoundingRect.height() / 2.0), titleCenterDiff.y()); | |
|
213 | 213 | title->setTransformOriginPoint(titleCenter); |
|
214 | 214 | title->setRotation(270.0); |
|
215 | 215 | } |
@@ -68,24 +68,42 void VerticalAxis::updateGeometry() | |||
|
68 | 68 | arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom()); |
|
69 | 69 | |
|
70 | 70 | //title |
|
71 | int titlePad = 0; | |
|
72 | 71 | QRectF titleBoundingRect; |
|
73 | 72 | QString titleText = axis()->titleText(); |
|
73 | qreal availableSpace = axisRect.width() - labelPadding(); | |
|
74 | 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 | 95 | titleBoundingRect = title->boundingRect(); |
|
79 | 96 | |
|
80 | 97 | QPointF center = gridRect.center() - titleBoundingRect.center(); |
|
81 |
if (axis()->alignment() == Qt::AlignLeft) |
|
|
82 | title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y()); | |
|
83 | } | |
|
84 | else if (axis()->alignment() == Qt::AlignRight) { | |
|
85 | title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y()); | |
|
86 | } | |
|
98 | if (axis()->alignment() == Qt::AlignLeft) | |
|
99 | title->setPos(axisRect.left() - titleBoundingRect.width() / 2.0 + titleBoundingRect.height() / 2.0 + titlePadding(), center.y()); | |
|
100 | else if (axis()->alignment() == Qt::AlignRight) | |
|
101 | title->setPos(axisRect.right() - titleBoundingRect.width() / 2.0 - titleBoundingRect.height() / 2.0 - titlePadding(), center.y()); | |
|
102 | ||
|
87 | 103 | title->setTransformOriginPoint(titleBoundingRect.center()); |
|
88 | 104 | title->setRotation(270); |
|
105 | ||
|
106 | availableSpace -= titleBoundingRect.height(); | |
|
89 | 107 | } |
|
90 | 108 | |
|
91 | 109 | for (int i = 0; i < layout.size(); ++i) { |
@@ -100,22 +118,21 void VerticalAxis::updateGeometry() | |||
|
100 | 118 | //label text wrapping |
|
101 | 119 | QString text = labelList.at(i); |
|
102 | 120 | QRectF boundingRect; |
|
103 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2); | |
|
104 | 121 | labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(), |
|
105 |
|
|
|
122 | availableSpace, Qt::Horizontal, boundingRect)); | |
|
106 | 123 | |
|
107 | 124 | //label transformation origin point |
|
108 | 125 | const QRectF &rect = labelItem->boundingRect(); |
|
109 | 126 | QPointF center = rect.center(); |
|
110 | 127 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
111 |
|
|
|
128 | qreal widthDiff = rect.width() - boundingRect.width(); | |
|
112 | 129 | |
|
113 | 130 | //ticks and label position |
|
114 | 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 | 133 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); |
|
117 | 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 | 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 | 209 | switch (which) { |
|
193 | 210 | case Qt::MinimumSize: { |
|
194 | 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 | 213 | break; |
|
197 | 214 | } |
|
198 | 215 | case Qt::MaximumSize: |
|
199 | 216 | case Qt::PreferredSize: { |
|
200 | 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 | 219 | break; |
|
203 | 220 | } |
|
204 | 221 | default: |
General Comments 0
You need to be logged in to leave comments.
Login now