##// END OF EJS Templates
Fix axis geometry when there is no axis title...
Miikka Heikkinen -
r2415:65ea14fdb747
parent child
Show More
@@ -296,8 +296,9 void ChartAxis::handleShadesVisibleChanged(bool visible)
296 296
297 297 void ChartAxis::handleTitleVisibleChanged(bool visible)
298 298 {
299 m_title->setVisible(visible);
299 QGraphicsLayoutItem::updateGeometry();
300 300 presenter()->layout()->invalidate();
301 m_title->setVisible(visible);
301 302 }
302 303
303 304 void ChartAxis::handleLabelsAngleChanged(int angle)
@@ -354,9 +355,9 void ChartAxis::handleGridPenChanged(const QPen &pen)
354 355
355 356 void ChartAxis::handleTitleTextChanged(const QString &title)
356 357 {
357 Q_UNUSED(title)
358 358 QGraphicsLayoutItem::updateGeometry();
359 359 presenter()->layout()->invalidate();
360 m_title->setText(title);
360 361 }
361 362
362 363
@@ -68,12 +68,11 void HorizontalAxis::updateGeometry()
68 68 QFontMetrics fn(font());
69 69
70 70 //title
71
72 if (!titleText().isNull()) {
71 int titlePad = 0;
72 QRectF titleBoundingRect;
73 if (!titleText().isEmpty() && titleItem()->isVisible()) {
73 74 QFontMetrics fn(title->font());
74
75 75 int size(0);
76
77 76 size = gridRect.width();
78 77 QString titleText = this->titleText();
79 78
@@ -86,11 +85,14 void HorizontalAxis::updateGeometry()
86 85 title->setText(titleText);
87 86 }
88 87
89 QPointF center = gridRect.center() - title->boundingRect().center();
88 titlePad = titlePadding();
89 titleBoundingRect = title->boundingRect();
90
91 QPointF center = gridRect.center() - titleBoundingRect.center();
90 92 if (alignment() == Qt::AlignTop) {
91 title->setPos(center.x(), axisRect.top() + titlePadding());
93 title->setPos(center.x(), axisRect.top() + titlePad);
92 94 } else if (alignment() == Qt::AlignBottom) {
93 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height() - titlePadding());
95 title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad);
94 96 }
95 97 }
96 98
@@ -107,7 +109,7 void HorizontalAxis::updateGeometry()
107 109 //label text wrapping
108 110 QString text = labelList.at(i);
109 111 QRectF boundingRect = labelBoundingRect(fn, text);
110 qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - title->boundingRect().height() - (titlePadding() * 2);
112 qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2);
111 113 if (boundingRect.height() > size) {
112 114 QString label = text + "...";
113 115 while (boundingRect.height() >= size && label.length() > 3) {
@@ -186,7 +188,7 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co
186 188 QFontMetrics fn(titleFont());
187 189 QSizeF sh(0,0);
188 190
189 if (titleText().isNull() || !titleItem()->isVisible())
191 if (titleText().isEmpty() || !titleItem()->isVisible())
190 192 return sh;
191 193
192 194 switch (which) {
@@ -72,10 +72,10 void VerticalAxis::updateGeometry()
72 72 QFontMetrics fn(font());
73 73
74 74 //title
75
76 if (!titleText().isNull()) {
75 int titlePad = 0;
76 QRectF titleBoundingRect;
77 if (!titleText().isEmpty() && titleItem()->isVisible()) {
77 78 QFontMetrics fn(title->font());
78
79 79 int size(0);
80 80 size = gridRect.height();
81 81 QString titleText = this->titleText();
@@ -90,14 +90,17 void VerticalAxis::updateGeometry()
90 90 title->setText(titleText);
91 91 }
92 92
93 QPointF center = gridRect.center() - title->boundingRect().center();
93 titlePad = titlePadding();
94 titleBoundingRect = title->boundingRect();
95
96 QPointF center = gridRect.center() - titleBoundingRect.center();
94 97 if (alignment() == Qt::AlignLeft) {
95 title->setPos(axisRect.left() - title->boundingRect().width() / 2 + title->boundingRect().height() / 2 + titlePadding(), center.y());
98 title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y());
96 99 }
97 100 else if (alignment() == Qt::AlignRight) {
98 title->setPos(axisRect.right() - title->boundingRect().width() / 2 - title->boundingRect().height() / 2 - titlePadding(), center.y());
101 title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y());
99 102 }
100 title->setTransformOriginPoint(title->boundingRect().center());
103 title->setTransformOriginPoint(titleBoundingRect.center());
101 104 title->setRotation(270);
102 105 }
103 106
@@ -115,7 +118,7 void VerticalAxis::updateGeometry()
115 118 QString text = labelList.at(i);
116 119 QRectF boundingRect = labelBoundingRect(fn, text);
117 120
118 qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height() - (titlePadding() * 2);
121 qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2);
119 122 if (boundingRect.width() > size) {
120 123 QString label = text + "...";
121 124 while (boundingRect.width() > size && label.length() > 3) {
@@ -197,7 +200,7 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
197 200 QFontMetrics fn(titleFont());
198 201 QSizeF sh(0,0);
199 202
200 if (titleText().isNull() || !titleItem()->isVisible())
203 if (titleText().isEmpty() || !titleItem()->isVisible())
201 204 return sh;
202 205
203 206 switch (which) {
General Comments 0
You need to be logged in to leave comments. Login now