##// END OF EJS Templates
Adds consider title boundary for axis label wrapping
Michal Klocek -
r2148:b2d455450b59
parent child
Show More
@@ -67,6 +67,33 void HorizontalAxis::updateGeometry()
67 67 qreal width = 0;
68 68 QFontMetrics fn(font());
69 69
70 //title
71
72 if (!titleText().isNull()) {
73 QFontMetrics fn(title->font());
74
75 int size(0);
76
77 size = gridRect.width();
78 QString titleText = this->titleText();
79
80 if (fn.boundingRect(titleText).width() > size) {
81 QString string = titleText + "...";
82 while (fn.boundingRect(string).width() > size && string.length() > 3)
83 string.remove(string.length() - 4, 1);
84 title->setText(string);
85 } else {
86 title->setText(titleText);
87 }
88
89 QPointF center = gridRect.center() - title->boundingRect().center();
90 if (alignment() == Qt::AlignTop) {
91 title->setPos(center.x(), axisRect.top());
92 } else if (alignment() == Qt::AlignBottom) {
93 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height());
94 }
95 }
96
70 97 for (int i = 0; i < layout.size(); ++i) {
71 98
72 99 //items
@@ -154,34 +181,6 void HorizontalAxis::updateGeometry()
154 181 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom());
155 182 gridLine->setVisible(true);
156 183 }
157
158 //title
159
160 if (!titleText().isNull()) {
161 QFontMetrics fn(title->font());
162
163 int size(0);
164
165 size = gridRect.width();
166 QString titleText = this->titleText();
167
168 if (fn.boundingRect(titleText).width() > size) {
169 QString string = titleText + "...";
170 while (fn.boundingRect(string).width() > size && string.length() > 3)
171 string.remove(string.length() - 4, 1);
172 title->setText(string);
173 } else {
174 title->setText(titleText);
175 }
176
177 QPointF center = gridRect.center() - title->boundingRect().center();
178 if (alignment() == Qt::AlignTop) {
179 title->setPos(center.x(), axisRect.top());
180 } else if (alignment() == Qt::AlignBottom) {
181 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height());
182 }
183 }
184
185 184 }
186 185
187 186 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
@@ -71,6 +71,36 void VerticalAxis::updateGeometry()
71 71
72 72 QFontMetrics fn(font());
73 73
74 //title
75
76 if (!titleText().isNull()) {
77 QFontMetrics fn(title->font());
78
79 int size(0);
80 size = gridRect.height();
81 QString titleText = this->titleText();
82
83 if (fn.boundingRect(titleText).width() > size) {
84 QString string = titleText + "...";
85 while (fn.boundingRect(string).width() > size && string.length() > 3)
86 string.remove(string.length() - 4, 1);
87 title->setText(string);
88 }
89 else {
90 title->setText(titleText);
91 }
92
93 QPointF center = gridRect.center() - title->boundingRect().center();
94 if (alignment() == Qt::AlignLeft) {
95 title->setPos(axisRect.left() - title->boundingRect().width()/2 + title->boundingRect().height()/2 , center.y());
96 }
97 else if (alignment() == Qt::AlignRight) {
98 title->setPos(axisRect.right()- title->boundingRect().width()/2 - title->boundingRect().height()/2, center.y());
99 }
100 title->setTransformOriginPoint(title->boundingRect().center());
101 title->setRotation(270);
102 }
103
74 104 for (int i = 0; i < layout.size(); ++i) {
75 105
76 106 //items
@@ -83,9 +113,10 void VerticalAxis::updateGeometry()
83 113
84 114 //label text wrapping
85 115 QString text = labelList.at(i);
86 if (fn.boundingRect(text).width() > axisRect.right() - axisRect.left() - labelPadding()) {
116 qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height();
117 if (fn.boundingRect(text).width() > size) {
87 118 QString label = text + "...";
88 while (fn.boundingRect(label).width() > axisRect.right() - axisRect.left() - labelPadding() && label.length() > 3)
119 while (fn.boundingRect(label).width() > size && label.length() > 3)
89 120 label.remove(label.length() - 4, 1);
90 121 labelItem->setText(label);
91 122 } else {
@@ -151,34 +182,6 void VerticalAxis::updateGeometry()
151 182 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
152 183 gridLine->setVisible(true);
153 184 }
154
155 //title
156
157 if (!titleText().isNull()) {
158 QFontMetrics fn(title->font());
159
160 int size(0);
161 size = gridRect.height();
162 QString titleText = this->titleText();
163
164 if (fn.boundingRect(titleText).width() > size) {
165 QString string = titleText + "...";
166 while (fn.boundingRect(string).width() > size && string.length() > 3)
167 string.remove(string.length() - 4, 1);
168 title->setText(string);
169 } else {
170 title->setText(titleText);
171 }
172
173 QPointF center = gridRect.center() - title->boundingRect().center();
174 if (alignment() == Qt::AlignLeft) {
175 title->setPos(axisRect.left() - title->boundingRect().width()/2 + title->boundingRect().height()/2 , center.y());
176 }else if (alignment() == Qt::AlignRight) {
177 title->setPos(axisRect.right()- title->boundingRect().width()/2 - title->boundingRect().height()/2, center.y());
178 }
179 title->setTransformOriginPoint(title->boundingRect().center());
180 title->setRotation(270);
181 }
182 185 }
183 186
184 187 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
@@ -29,7 +29,7
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 static const qreal golden_ratio = 0.8;//0.4;
32 static const qreal golden_ratio = 0.4;
33 33
34 34 ChartLayout::ChartLayout(ChartPresenter *presenter)
35 35 : m_presenter(presenter),
General Comments 0
You need to be logged in to leave comments. Login now