##// END OF EJS Templates
Added HTML support for various text items...
Miikka Heikkinen -
r2539:74f3dbde7a75
parent child
Show More
@@ -112,7 +112,7 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
112
112
113 switch (which) {
113 switch (which) {
114 case Qt::MinimumSize: {
114 case Qt::MinimumSize: {
115 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
115 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
116 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
116 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
117 sh = QSizeF(width, height);
117 sh = QSizeF(width, height);
118 break;
118 break;
@@ -120,7 +120,7 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
120 case Qt::PreferredSize:{
120 case Qt::PreferredSize:{
121 qreal labelHeight = 0.0;
121 qreal labelHeight = 0.0;
122 foreach (const QString& s, ticksList) {
122 foreach (const QString& s, ticksList) {
123 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
123 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
124 labelHeight = qMax(rect.height(), labelHeight);
124 labelHeight = qMax(rect.height(), labelHeight);
125 }
125 }
126 height = labelHeight + labelPadding() + base.height() + 1.0;
126 height = labelHeight + labelPadding() + base.height() + 1.0;
@@ -110,7 +110,7 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
110
110
111 switch (which) {
111 switch (which) {
112 case Qt::MinimumSize: {
112 case Qt::MinimumSize: {
113 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
113 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
114 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
114 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
115 if (base.width() > 0.0)
115 if (base.width() > 0.0)
116 width += labelPadding();
116 width += labelPadding();
@@ -120,7 +120,7 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
120 case Qt::PreferredSize:{
120 case Qt::PreferredSize:{
121 qreal labelWidth = 0.0;
121 qreal labelWidth = 0.0;
122 foreach (const QString& s, ticksList) {
122 foreach (const QString& s, ticksList) {
123 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
123 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
124 labelWidth = qMax(rect.width(), labelWidth);
124 labelWidth = qMax(rect.width(), labelWidth);
125 }
125 }
126 width = labelWidth + labelPadding() + base.width() + 1.0;
126 width = labelWidth + labelPadding() + base.width() + 1.0;
@@ -61,18 +61,16 void CartesianChartAxis::createItems(int count)
61 for (int i = 0; i < count; ++i) {
61 for (int i = 0; i < count; ++i) {
62 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
62 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
63 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
63 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
64 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
64 QGraphicsTextItem *label = new QGraphicsTextItem(this);
65 QGraphicsSimpleTextItem *title = titleItem();
65 QGraphicsTextItem *title = titleItem();
66 arrow->setPen(axis()->linePen());
66 arrow->setPen(axis()->linePen());
67 grid->setPen(axis()->gridLinePen());
67 grid->setPen(axis()->gridLinePen());
68 label->setFont(axis()->labelsFont());
68 label->setFont(axis()->labelsFont());
69 label->setPen(axis()->labelsPen());
69 label->setDefaultTextColor(axis()->labelsBrush().color());
70 label->setBrush(axis()->labelsBrush());
71 label->setRotation(axis()->labelsAngle());
70 label->setRotation(axis()->labelsAngle());
72 title->setFont(axis()->titleFont());
71 title->setFont(axis()->titleFont());
73 title->setPen(axis()->titlePen());
72 title->setDefaultTextColor(axis()->titleBrush().color());
74 title->setBrush(axis()->titleBrush());
73 title->setHtml(axis()->titleText());
75 title->setText(axis()->titleText());
76 arrowGroup()->addToGroup(arrow);
74 arrowGroup()->addToGroup(arrow);
77 gridGroup()->addToGroup(grid);
75 gridGroup()->addToGroup(grid);
78 labelGroup()->addToGroup(label);
76 labelGroup()->addToGroup(label);
@@ -85,7 +85,7 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
85
85
86 switch (which) {
86 switch (which) {
87 case Qt::MinimumSize: {
87 case Qt::MinimumSize: {
88 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
88 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
89 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
89 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
90 sh = QSizeF(width, height);
90 sh = QSizeF(width, height);
91 break;
91 break;
@@ -93,7 +93,7 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
93 case Qt::PreferredSize: {
93 case Qt::PreferredSize: {
94 qreal labelHeight = 0.0;
94 qreal labelHeight = 0.0;
95 foreach (const QString& s, ticksList) {
95 foreach (const QString& s, ticksList) {
96 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
96 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
97 labelHeight = qMax(rect.height(), labelHeight);
97 labelHeight = qMax(rect.height(), labelHeight);
98 }
98 }
99 height = labelHeight + labelPadding() + base.height() + 1.0;
99 height = labelHeight + labelPadding() + base.height() + 1.0;
@@ -85,7 +85,7 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
85
85
86 switch (which) {
86 switch (which) {
87 case Qt::MinimumSize: {
87 case Qt::MinimumSize: {
88 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
88 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
89 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
89 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
90 sh = QSizeF(width, height);
90 sh = QSizeF(width, height);
91 break;
91 break;
@@ -93,7 +93,7 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
93 case Qt::PreferredSize: {
93 case Qt::PreferredSize: {
94 qreal labelWidth = 0.0;
94 qreal labelWidth = 0.0;
95 foreach (const QString& s, ticksList) {
95 foreach (const QString& s, ticksList) {
96 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
96 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
97 labelWidth = qMax(rect.width(), labelWidth);
97 labelWidth = qMax(rect.width(), labelWidth);
98 }
98 }
99 width = labelWidth + labelPadding() + base.width() + 1.0;
99 width = labelWidth + labelPadding() + base.width() + 1.0;
@@ -27,14 +27,15
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 QGraphicsSimpleTextItem *dummyTextItem = 0;
30 static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])";
31 class StaticDeleter
31 static QRegExp *labelFormatMatcher = 0;
32 class StaticLabelFormatMatcherDeleter
32 {
33 {
33 public:
34 public:
34 StaticDeleter() {}
35 StaticLabelFormatMatcherDeleter() {}
35 ~StaticDeleter() { delete dummyTextItem; }
36 ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; }
36 };
37 };
37 StaticDeleter staticDeleter;
38 StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter;
38
39
39 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
40 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
40 : ChartElement(item),
41 : ChartElement(item),
@@ -44,13 +45,11 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, boo
44 m_arrow(new QGraphicsItemGroup(item)),
45 m_arrow(new QGraphicsItemGroup(item)),
45 m_shades(new QGraphicsItemGroup(item)),
46 m_shades(new QGraphicsItemGroup(item)),
46 m_labels(new QGraphicsItemGroup(item)),
47 m_labels(new QGraphicsItemGroup(item)),
47 m_title(new QGraphicsSimpleTextItem(item)),
48 m_title(new QGraphicsTextItem(item)),
48 m_intervalAxis(intervalAxis)
49 m_intervalAxis(intervalAxis)
49
50
50 {
51 {
51 //initial initialization
52 //initial initialization
52 if (!dummyTextItem)
53 dummyTextItem = new QGraphicsSimpleTextItem;
54 m_arrow->setHandlesChildEvents(false);
53 m_arrow->setHandlesChildEvents(false);
55 m_arrow->setZValue(ChartPresenter::AxisZValue);
54 m_arrow->setZValue(ChartPresenter::AxisZValue);
56 m_labels->setZValue(ChartPresenter::AxisZValue);
55 m_labels->setZValue(ChartPresenter::AxisZValue);
@@ -130,20 +129,19 void ChartAxisElement::handleLabelsAngleChanged(int angle)
130
129
131 void ChartAxisElement::handleLabelsPenChanged(const QPen &pen)
130 void ChartAxisElement::handleLabelsPenChanged(const QPen &pen)
132 {
131 {
133 foreach (QGraphicsItem *item, m_labels->childItems())
132 Q_UNUSED(pen)
134 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
135 }
133 }
136
134
137 void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush)
135 void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush)
138 {
136 {
139 foreach (QGraphicsItem *item, m_labels->childItems())
137 foreach (QGraphicsItem *item, m_labels->childItems())
140 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
138 static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color());
141 }
139 }
142
140
143 void ChartAxisElement::handleLabelsFontChanged(const QFont &font)
141 void ChartAxisElement::handleLabelsFontChanged(const QFont &font)
144 {
142 {
145 foreach (QGraphicsItem *item, m_labels->childItems())
143 foreach (QGraphicsItem *item, m_labels->childItems())
146 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
144 static_cast<QGraphicsTextItem *>(item)->setFont(font);
147 QGraphicsLayoutItem::updateGeometry();
145 QGraphicsLayoutItem::updateGeometry();
148 presenter()->layout()->invalidate();
146 presenter()->layout()->invalidate();
149 }
147 }
@@ -152,17 +150,17 void ChartAxisElement::handleTitleTextChanged(const QString &title)
152 {
150 {
153 QGraphicsLayoutItem::updateGeometry();
151 QGraphicsLayoutItem::updateGeometry();
154 presenter()->layout()->invalidate();
152 presenter()->layout()->invalidate();
155 m_title->setText(title);
153 m_title->setHtml(title);
156 }
154 }
157
155
158 void ChartAxisElement::handleTitlePenChanged(const QPen &pen)
156 void ChartAxisElement::handleTitlePenChanged(const QPen &pen)
159 {
157 {
160 m_title->setPen(pen);
158 Q_UNUSED(pen)
161 }
159 }
162
160
163 void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush)
161 void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush)
164 {
162 {
165 m_title->setBrush(brush);
163 m_title->setDefaultTextColor(brush.color());
166 }
164 }
167
165
168 void ChartAxisElement::handleTitleFontChanged(const QFont &font)
166 void ChartAxisElement::handleTitleFontChanged(const QFont &font)
@@ -194,44 +192,6 void ChartAxisElement::handleVisibleChanged(bool visible)
194 if (presenter()) presenter()->layout()->invalidate();
192 if (presenter()) presenter()->layout()->invalidate();
195 }
193 }
196
194
197 QRectF ChartAxisElement::textBoundingRect(const QFont &font, const QString &text, qreal angle) const
198 {
199 dummyTextItem->setFont(font);
200 dummyTextItem->setText(text);
201 QRectF boundingRect = dummyTextItem->boundingRect();
202
203 // Take rotation into account
204 if (angle) {
205 QTransform transform;
206 transform.rotate(angle);
207 boundingRect = transform.mapRect(boundingRect);
208 }
209
210 return boundingRect;
211 }
212
213 // boundingRect parameter returns the rotated bounding rect of the text
214 QString ChartAxisElement::truncatedText(const QFont &font, const QString &text, qreal angle,
215 qreal maxSize, Qt::Orientation constraintOrientation,
216 QRectF &boundingRect) const
217 {
218 QString truncatedString(text);
219 boundingRect = textBoundingRect(font, truncatedString, angle);
220 qreal checkDimension = ((constraintOrientation == Qt::Horizontal)
221 ? boundingRect.width() : boundingRect.height());
222 if (checkDimension > maxSize) {
223 truncatedString.append("...");
224 while (checkDimension > maxSize && truncatedString.length() > 3) {
225 truncatedString.remove(truncatedString.length() - 4, 1);
226 boundingRect = textBoundingRect(font, truncatedString, angle);
227 checkDimension = ((constraintOrientation == Qt::Horizontal)
228 ? boundingRect.width() : boundingRect.height());
229 }
230 }
231
232 return truncatedString;
233 }
234
235 void ChartAxisElement::handleRangeChanged(qreal min, qreal max)
195 void ChartAxisElement::handleRangeChanged(qreal min, qreal max)
236 {
196 {
237 Q_UNUSED(min);
197 Q_UNUSED(min);
@@ -270,6 +230,32 qreal ChartAxisElement::max() const
270 return m_axis->d_ptr->max();
230 return m_axis->d_ptr->max();
271 }
231 }
272
232
233 static void appendFormattedLabel(const QString &capStr, const QByteArray &array,
234 QStringList &labels, qreal value)
235 {
236 if (capStr.isEmpty()) {
237 labels << QString();
238 } else if (capStr.at(0) == QLatin1Char('d')
239 || capStr.at(0) == QLatin1Char('i')
240 || capStr.at(0) == QLatin1Char('c')) {
241 labels << QString().sprintf(array, (qint64)value);
242 } else if (capStr.at(0) == QLatin1Char('u')
243 || capStr.at(0) == QLatin1Char('o')
244 || capStr.at(0) == QLatin1Char('x')
245 || capStr.at(0) == QLatin1Char('X')) {
246 labels << QString().sprintf(array, (quint64)value);
247 } else if (capStr.at(0) == QLatin1Char('f')
248 || capStr.at(0) == QLatin1Char('F')
249 || capStr.at(0) == QLatin1Char('e')
250 || capStr.at(0) == QLatin1Char('E')
251 || capStr.at(0) == QLatin1Char('g')
252 || capStr.at(0) == QLatin1Char('G')) {
253 labels << QString().sprintf(array, value);
254 } else {
255 labels << QString();
256 }
257 }
258
273 QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format)
259 QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format)
274 {
260 {
275 QStringList labels;
261 QStringList labels;
@@ -287,23 +273,14 QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks,
287 }
273 }
288 } else {
274 } else {
289 QByteArray array = format.toLatin1();
275 QByteArray array = format.toLatin1();
276 QString capStr;
277 if (!labelFormatMatcher)
278 labelFormatMatcher = new QRegExp(labelFormatMatchString);
279 if (labelFormatMatcher->indexIn(format, 0) != -1)
280 capStr = labelFormatMatcher->cap(1);
290 for (int i = 0; i < ticks; i++) {
281 for (int i = 0; i < ticks; i++) {
291 qreal value = min + (i * (max - min) / (ticks - 1));
282 qreal value = min + (i * (max - min) / (ticks - 1));
292 if (format.contains("d")
283 appendFormattedLabel(capStr, array, labels, value);
293 || format.contains("i")
294 || format.contains("c")) {
295 labels << QString().sprintf(array, (qint64)value);
296 } else if (format.contains("u")
297 || format.contains("o")
298 || format.contains("x", Qt::CaseInsensitive)) {
299 labels << QString().sprintf(array, (quint64)value);
300 } else if (format.contains("f", Qt::CaseInsensitive)
301 || format.contains("e", Qt::CaseInsensitive)
302 || format.contains("g", Qt::CaseInsensitive)) {
303 labels << QString().sprintf(array, value);
304 } else {
305 labels << QString();
306 }
307 }
284 }
308 }
285 }
309
286
@@ -335,23 +312,14 QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal b
335 }
312 }
336 } else {
313 } else {
337 QByteArray array = format.toLatin1();
314 QByteArray array = format.toLatin1();
315 QString capStr;
316 if (!labelFormatMatcher)
317 labelFormatMatcher = new QRegExp(labelFormatMatchString);
318 if (labelFormatMatcher->indexIn(format, 0) != -1)
319 capStr = labelFormatMatcher->cap(1);
338 for (int i = firstTick; i < ticks + firstTick; i++) {
320 for (int i = firstTick; i < ticks + firstTick; i++) {
339 qreal value = qPow(base, i);
321 qreal value = qPow(base, i);
340 if (format.contains("d")
322 appendFormattedLabel(capStr, array, labels, value);
341 || format.contains("i")
342 || format.contains("c")) {
343 labels << QString().sprintf(array, (qint64)value);
344 } else if (format.contains("u")
345 || format.contains("o")
346 || format.contains("x", Qt::CaseInsensitive)) {
347 labels << QString().sprintf(array, (quint64)value);
348 } else if (format.contains("f", Qt::CaseInsensitive)
349 || format.contains("e", Qt::CaseInsensitive)
350 || format.contains("g", Qt::CaseInsensitive)) {
351 labels << QString().sprintf(array, value);
352 } else {
353 labels << QString();
354 }
355 }
323 }
356 }
324 }
357
325
@@ -70,10 +70,6 public:
70 QRectF axisGeometry() const { return m_axisRect; }
70 QRectF axisGeometry() const { return m_axisRect; }
71 void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; }
71 void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; }
72
72
73 QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0) const;
74 QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize,
75 Qt::Orientation constraintOrientation, QRectF &boundingRect) const;
76
77 void axisSelected();
73 void axisSelected();
78
74
79 //this flag indicates that axis is used to show intervals it means labels are in between ticks
75 //this flag indicates that axis is used to show intervals it means labels are in between ticks
@@ -102,7 +98,7 protected:
102 QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); }
98 QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); }
103 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); }
99 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); }
104 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); }
100 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); }
105 QGraphicsSimpleTextItem *titleItem() const { return m_title.data(); }
101 QGraphicsTextItem *titleItem() const { return m_title.data(); }
106 QGraphicsItemGroup *gridGroup() { return m_grid.data(); }
102 QGraphicsItemGroup *gridGroup() { return m_grid.data(); }
107 QGraphicsItemGroup *labelGroup() { return m_labels.data(); }
103 QGraphicsItemGroup *labelGroup() { return m_labels.data(); }
108 QGraphicsItemGroup *shadeGroup() { return m_shades.data(); }
104 QGraphicsItemGroup *shadeGroup() { return m_shades.data(); }
@@ -144,7 +140,7 private:
144 QScopedPointer<QGraphicsItemGroup> m_arrow;
140 QScopedPointer<QGraphicsItemGroup> m_arrow;
145 QScopedPointer<QGraphicsItemGroup> m_shades;
141 QScopedPointer<QGraphicsItemGroup> m_shades;
146 QScopedPointer<QGraphicsItemGroup> m_labels;
142 QScopedPointer<QGraphicsItemGroup> m_labels;
147 QScopedPointer<QGraphicsSimpleTextItem> m_title;
143 QScopedPointer<QGraphicsTextItem> m_title;
148 bool m_intervalAxis;
144 bool m_intervalAxis;
149 };
145 };
150
146
@@ -98,7 +98,7 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
98
98
99 switch (which) {
99 switch (which) {
100 case Qt::MinimumSize: {
100 case Qt::MinimumSize: {
101 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
101 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
102 width = boundingRect.width() / 2.0;
102 width = boundingRect.width() / 2.0;
103 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
103 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
104 sh = QSizeF(width, height);
104 sh = QSizeF(width, height);
@@ -108,7 +108,7 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
108 qreal labelHeight = 0.0;
108 qreal labelHeight = 0.0;
109 qreal firstWidth = -1.0;
109 qreal firstWidth = -1.0;
110 foreach (const QString& s, ticksList) {
110 foreach (const QString& s, ticksList) {
111 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
111 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
112 labelHeight = qMax(rect.height(), labelHeight);
112 labelHeight = qMax(rect.height(), labelHeight);
113 width = rect.width();
113 width = rect.width();
114 if (firstWidth < 0.0)
114 if (firstWidth < 0.0)
@@ -99,7 +99,7 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
99
99
100 switch (which) {
100 switch (which) {
101 case Qt::MinimumSize: {
101 case Qt::MinimumSize: {
102 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
102 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
103 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
103 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
104 height = boundingRect.height() / 2.0;
104 height = boundingRect.height() / 2.0;
105 sh = QSizeF(width, height);
105 sh = QSizeF(width, height);
@@ -109,7 +109,7 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
109 qreal labelWidth = 0.0;
109 qreal labelWidth = 0.0;
110 qreal firstHeight = -1.0;
110 qreal firstHeight = -1.0;
111 foreach (const QString& s, ticksList) {
111 foreach (const QString& s, ticksList) {
112 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
112 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
113 labelWidth = qMax(rect.width(), labelWidth);
113 labelWidth = qMax(rect.width(), labelWidth);
114 height = rect.height();
114 height = rect.height();
115 if (firstHeight < 0.0)
115 if (firstHeight < 0.0)
@@ -20,6 +20,7
20
20
21 #include "horizontalaxis_p.h"
21 #include "horizontalaxis_p.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartpresenter_p.h"
23 #include <qmath.h>
24 #include <qmath.h>
24 #include <QDebug>
25 #include <QDebug>
25
26
@@ -47,7 +48,7 void HorizontalAxis::updateGeometry()
47 QList<QGraphicsItem *> labels = labelItems();
48 QList<QGraphicsItem *> labels = labelItems();
48 QList<QGraphicsItem *> shades = shadeItems();
49 QList<QGraphicsItem *> shades = shadeItems();
49 QList<QGraphicsItem *> arrow = arrowItems();
50 QList<QGraphicsItem *> arrow = arrowItems();
50 QGraphicsSimpleTextItem *title = titleItem();
51 QGraphicsTextItem *title = titleItem();
51
52
52 Q_ASSERT(labels.size() == labelList.size());
53 Q_ASSERT(labels.size() == labelList.size());
53 Q_ASSERT(layout.size() == labelList.size());
54 Q_ASSERT(layout.size() == labelList.size());
@@ -70,7 +71,7 void HorizontalAxis::updateGeometry()
70 QRectF titleBoundingRect;
71 QRectF titleBoundingRect;
71 QString titleText = axis()->titleText();
72 QString titleText = axis()->titleText();
72 if (!titleText.isEmpty() && titleItem()->isVisible()) {
73 if (!titleText.isEmpty() && titleItem()->isVisible()) {
73 title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, gridRect.width(), Qt::Horizontal, QRectF()));
74 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.width(), Qt::Horizontal, QRectF()));
74
75
75 titlePad = titlePadding();
76 titlePad = titlePadding();
76 titleBoundingRect = title->boundingRect();
77 titleBoundingRect = title->boundingRect();
@@ -87,7 +88,7 void HorizontalAxis::updateGeometry()
87 //items
88 //items
88 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
89 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
89 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(arrow.at(i + 1));
90 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(arrow.at(i + 1));
90 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
91 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labels.at(i));
91
92
92 //grid line
93 //grid line
93 gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom());
94 gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom());
@@ -96,8 +97,8 void HorizontalAxis::updateGeometry()
96 QString text = labelList.at(i);
97 QString text = labelList.at(i);
97 QRectF boundingRect;
98 QRectF boundingRect;
98 qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2);
99 qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - titleBoundingRect.height() - (titlePad * 2);
99 labelItem->setText(truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(),
100 labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(),
100 size, Qt::Vertical, boundingRect));
101 size, Qt::Vertical, boundingRect));
101
102
102 //label transformation origin point
103 //label transformation origin point
103 const QRectF& rect = labelItem->boundingRect();
104 const QRectF& rect = labelItem->boundingRect();
@@ -185,13 +186,13 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co
185
186
186 switch (which) {
187 switch (which) {
187 case Qt::MinimumSize: {
188 case Qt::MinimumSize: {
188 QRectF titleRect = textBoundingRect(axis()->titleFont(), "...");
189 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "...");
189 sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2));
190 sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2));
190 break;
191 break;
191 }
192 }
192 case Qt::MaximumSize:
193 case Qt::MaximumSize:
193 case Qt::PreferredSize: {
194 case Qt::PreferredSize: {
194 QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText());
195 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
195 sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2));
196 sh = QSizeF(titleRect.width(), titleRect.height() + (titlePadding() * 2));
196 break;
197 break;
197 }
198 }
@@ -104,7 +104,7 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
104
104
105 switch (which) {
105 switch (which) {
106 case Qt::MinimumSize:{
106 case Qt::MinimumSize:{
107 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
107 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
108 width = boundingRect.width() / 2.0;
108 width = boundingRect.width() / 2.0;
109 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
109 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
110 sh = QSizeF(width, height);
110 sh = QSizeF(width, height);
@@ -114,7 +114,7 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
114 qreal labelHeight = 0.0;
114 qreal labelHeight = 0.0;
115 qreal firstWidth = -1.0;
115 qreal firstWidth = -1.0;
116 foreach (const QString& s, ticksList) {
116 foreach (const QString& s, ticksList) {
117 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
117 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
118 labelHeight = qMax(rect.height(), labelHeight);
118 labelHeight = qMax(rect.height(), labelHeight);
119 width = rect.width();
119 width = rect.width();
120 if (firstWidth < 0.0)
120 if (firstWidth < 0.0)
@@ -104,7 +104,7 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
104
104
105 switch (which) {
105 switch (which) {
106 case Qt::MinimumSize: {
106 case Qt::MinimumSize: {
107 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
107 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
108 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
108 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
109 height = boundingRect.height() / 2.0;
109 height = boundingRect.height() / 2.0;
110 sh = QSizeF(width, height);
110 sh = QSizeF(width, height);
@@ -114,7 +114,7 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
114 qreal labelWidth = 0.0;
114 qreal labelWidth = 0.0;
115 qreal firstHeight = -1.0;
115 qreal firstHeight = -1.0;
116 foreach (const QString& s, ticksList) {
116 foreach (const QString& s, ticksList) {
117 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
117 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
118 labelWidth = qMax(rect.width(), labelWidth);
118 labelWidth = qMax(rect.width(), labelWidth);
119 height = rect.height();
119 height = rect.height();
120 if (firstHeight < 0.0)
120 if (firstHeight < 0.0)
@@ -51,7 +51,7 void PolarChartAxisAngular::updateGeometry()
51 QList<QGraphicsItem *> gridItemList = gridItems();
51 QList<QGraphicsItem *> gridItemList = gridItems();
52 QList<QGraphicsItem *> labelItemList = labelItems();
52 QList<QGraphicsItem *> labelItemList = labelItems();
53 QList<QGraphicsItem *> shadeItemList = shadeItems();
53 QList<QGraphicsItem *> shadeItemList = shadeItems();
54 QGraphicsSimpleTextItem *title = titleItem();
54 QGraphicsTextItem *title = titleItem();
55
55
56 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
56 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
57 axisLine->setRect(axisGeometry());
57 axisLine->setRect(axisGeometry());
@@ -73,7 +73,7 void PolarChartAxisAngular::updateGeometry()
73
73
74 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
74 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
75 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
75 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
76 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labelItemList.at(i));
76 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
77 QGraphicsPathItem *shadeItem = 0;
77 QGraphicsPathItem *shadeItem = 0;
78 if (i == 0)
78 if (i == 0)
79 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
79 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
@@ -118,11 +118,11 void PolarChartAxisAngular::updateGeometry()
118
118
119 // Angular axis label
119 // Angular axis label
120 if (axis()->labelsVisible() && labelVisible) {
120 if (axis()->labelsVisible() && labelVisible) {
121 labelItem->setText(labelList.at(i));
121 labelItem->setHtml(labelList.at(i));
122 const QRectF &rect = labelItem->boundingRect();
122 const QRectF &rect = labelItem->boundingRect();
123 QPointF labelCenter = rect.center();
123 QPointF labelCenter = rect.center();
124 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
124 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
125 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
125 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
126 boundingRect.moveCenter(labelCenter);
126 boundingRect.moveCenter(labelCenter);
127 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
127 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
128
128
@@ -219,7 +219,7 void PolarChartAxisAngular::updateGeometry()
219 // Title, centered above the chart
219 // Title, centered above the chart
220 QString titleText = axis()->titleText();
220 QString titleText = axis()->titleText();
221 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
221 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
222 title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, axisGeometry().width(), Qt::Horizontal, QRectF()));
222 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), axisGeometry().width(), Qt::Horizontal, QRectF()));
223
223
224 QRectF titleBoundingRect = title->boundingRect();
224 QRectF titleBoundingRect = title->boundingRect();
225 QPointF titleCenter = center - titleBoundingRect.center();
225 QPointF titleCenter = center - titleBoundingRect.center();
@@ -245,18 +245,16 void PolarChartAxisAngular::createItems(int count)
245 for (int i = 0; i < count; ++i) {
245 for (int i = 0; i < count; ++i) {
246 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
246 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
247 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
247 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
248 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
248 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
249 QGraphicsSimpleTextItem *title = titleItem();
249 QGraphicsTextItem *title = titleItem();
250 arrow->setPen(axis()->linePen());
250 arrow->setPen(axis()->linePen());
251 grid->setPen(axis()->gridLinePen());
251 grid->setPen(axis()->gridLinePen());
252 label->setFont(axis()->labelsFont());
252 label->setFont(axis()->labelsFont());
253 label->setPen(axis()->labelsPen());
253 label->setDefaultTextColor(axis()->labelsBrush().color());
254 label->setBrush(axis()->labelsBrush());
255 label->setRotation(axis()->labelsAngle());
254 label->setRotation(axis()->labelsAngle());
256 title->setFont(axis()->titleFont());
255 title->setFont(axis()->titleFont());
257 title->setPen(axis()->titlePen());
256 title->setDefaultTextColor(axis()->titleBrush().color());
258 title->setBrush(axis()->titleBrush());
257 title->setHtml(axis()->titleText());
259 title->setText(axis()->titleText());
260 arrowGroup()->addToGroup(arrow);
258 arrowGroup()->addToGroup(arrow);
261 gridGroup()->addToGroup(grid);
259 gridGroup()->addToGroup(grid);
262 labelGroup()->addToGroup(label);
260 labelGroup()->addToGroup(label);
@@ -355,7 +353,7 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
355 continue;
353 continue;
356 }
354 }
357
355
358 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
356 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
359 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
357 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
360
358
361 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
359 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
@@ -370,7 +368,7 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
370 }
368 }
371
369
372 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
370 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
373 QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText());
371 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
374
372
375 radius -= titlePadding() + (titleRect.height() / 2.0);
373 radius -= titlePadding() + (titleRect.height() / 2.0);
376 if (radius < 1.0) // safeguard
374 if (radius < 1.0) // safeguard
@@ -48,7 +48,7 void PolarChartAxisRadial::updateGeometry()
48 QList<QGraphicsItem *> gridItemList = gridItems();
48 QList<QGraphicsItem *> gridItemList = gridItems();
49 QList<QGraphicsItem *> labelItemList = labelItems();
49 QList<QGraphicsItem *> labelItemList = labelItems();
50 QList<QGraphicsItem *> shadeItemList = shadeItems();
50 QList<QGraphicsItem *> shadeItemList = shadeItems();
51 QGraphicsSimpleTextItem* title = titleItem();
51 QGraphicsTextItem* title = titleItem();
52 qreal radius = axisGeometry().height() / 2.0;
52 qreal radius = axisGeometry().height() / 2.0;
53
53
54 QLineF line(center, center + QPointF(0, -radius));
54 QLineF line(center, center + QPointF(0, -radius));
@@ -66,7 +66,7 void PolarChartAxisRadial::updateGeometry()
66
66
67 QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i));
67 QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i));
68 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
68 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
69 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labelItemList.at(i));
69 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
70 QGraphicsPathItem *shadeItem = 0;
70 QGraphicsPathItem *shadeItem = 0;
71 if (i == 0)
71 if (i == 0)
72 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
72 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
@@ -106,11 +106,11 void PolarChartAxisRadial::updateGeometry()
106
106
107 // Radial axis label
107 // Radial axis label
108 if (axis()->labelsVisible() && labelVisible) {
108 if (axis()->labelsVisible() && labelVisible) {
109 labelItem->setText(labelList.at(i));
109 labelItem->setHtml(labelList.at(i));
110 QRectF labelRect = labelItem->boundingRect();
110 QRectF labelRect = labelItem->boundingRect();
111 QPointF labelCenter = labelRect.center();
111 QPointF labelCenter = labelRect.center();
112 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
112 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
113 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
113 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
114 boundingRect.moveCenter(labelCenter);
114 boundingRect.moveCenter(labelCenter);
115 QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft());
115 QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft());
116 QPointF labelPoint = center;
116 QPointF labelPoint = center;
@@ -203,7 +203,7 void PolarChartAxisRadial::updateGeometry()
203 // Title, along the 0 axis
203 // Title, along the 0 axis
204 QString titleText = axis()->titleText();
204 QString titleText = axis()->titleText();
205 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
205 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
206 title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, radius, Qt::Horizontal, QRectF()));
206 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), radius, Qt::Horizontal, QRectF()));
207
207
208 QRectF titleBoundingRect = title->boundingRect();
208 QRectF titleBoundingRect = title->boundingRect();
209 QPointF titleCenter = titleBoundingRect.center();
209 QPointF titleCenter = titleBoundingRect.center();
@@ -234,18 +234,16 void PolarChartAxisRadial::createItems(int count)
234 for (int i = 0; i < count; ++i) {
234 for (int i = 0; i < count; ++i) {
235 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
235 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
236 QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem());
236 QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem());
237 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
237 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
238 QGraphicsSimpleTextItem *title = titleItem();
238 QGraphicsTextItem *title = titleItem();
239 arrow->setPen(axis()->linePen());
239 arrow->setPen(axis()->linePen());
240 grid->setPen(axis()->gridLinePen());
240 grid->setPen(axis()->gridLinePen());
241 label->setFont(axis()->labelsFont());
241 label->setFont(axis()->labelsFont());
242 label->setPen(axis()->labelsPen());
242 label->setDefaultTextColor(axis()->labelsBrush().color());
243 label->setBrush(axis()->labelsBrush());
244 label->setRotation(axis()->labelsAngle());
243 label->setRotation(axis()->labelsAngle());
245 title->setFont(axis()->titleFont());
244 title->setFont(axis()->titleFont());
246 title->setPen(axis()->titlePen());
245 title->setDefaultTextColor(axis()->titleBrush().color());
247 title->setBrush(axis()->titleBrush());
246 title->setHtml(axis()->titleText());
248 title->setText(axis()->titleText());
249 arrowGroup()->addToGroup(arrow);
247 arrowGroup()->addToGroup(arrow);
250 gridGroup()->addToGroup(grid);
248 gridGroup()->addToGroup(grid);
251 labelGroup()->addToGroup(label);
249 labelGroup()->addToGroup(label);
@@ -92,12 +92,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
92
92
93 /*!
93 /*!
94 \property QAbstractAxis::labelsPen
94 \property QAbstractAxis::labelsPen
95 \deprecated
95 The pen of the labels.
96 The pen of the labels.
96 */
97 */
97
98
98 /*!
99 /*!
99 \property QAbstractAxis::labelsBrush
100 \property QAbstractAxis::labelsBrush
100 The brush of the labels.
101 The brush of the labels. Only the color of the brush is relevant.
101 */
102 */
102
103
103 /*!
104 /*!
@@ -210,21 +211,22 QTCOMMERCIALCHART_BEGIN_NAMESPACE
210
211
211 /*!
212 /*!
212 \property QAbstractAxis::titleText
213 \property QAbstractAxis::titleText
213 The title of the axis. Empty by default.
214 The title of the axis. Empty by default. Axis titles support html formatting.
214 */
215 */
215 /*!
216 /*!
216 \qmlproperty String AbstractAxis::titleText
217 \qmlproperty String AbstractAxis::titleText
217 The title of the axis. Empty by default.
218 The title of the axis. Empty by default. Axis titles support html formatting.
218 */
219 */
219
220
220 /*!
221 /*!
221 \property QAbstractAxis::titlePen
222 \property QAbstractAxis::titlePen
223 \deprecated
222 The pen of the title text.
224 The pen of the title text.
223 */
225 */
224
226
225 /*!
227 /*!
226 \property QAbstractAxis::titleBrush
228 \property QAbstractAxis::titleBrush
227 The brush of the title text.
229 The brush of the title text. Only the color of the brush is relevant.
228 */
230 */
229
231
230 /*!
232 /*!
@@ -297,6 +299,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
297
299
298 /*!
300 /*!
299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
301 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
302 \deprecated
300 The pen of the axis labels has changed to \a pen.
303 The pen of the axis labels has changed to \a pen.
301 */
304 */
302
305
@@ -366,6 +369,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
366
369
367 /*!
370 /*!
368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
371 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
372 \deprecated
369 The pen of the axis shades has changed to \a pen.
373 The pen of the axis shades has changed to \a pen.
370 */
374 */
371
375
@@ -544,9 +548,6 bool QAbstractAxis::labelsVisible() const
544 return d_ptr->m_labelsVisible;
548 return d_ptr->m_labelsVisible;
545 }
549 }
546
550
547 /*!
548 Sets \a pen used to draw labels.
549 */
550 void QAbstractAxis::setLabelsPen(const QPen &pen)
551 void QAbstractAxis::setLabelsPen(const QPen &pen)
551 {
552 {
552 if (d_ptr->m_labelsPen != pen) {
553 if (d_ptr->m_labelsPen != pen) {
@@ -555,9 +556,6 void QAbstractAxis::setLabelsPen(const QPen &pen)
555 }
556 }
556 }
557 }
557
558
558 /*!
559 Returns the pen used to labels.
560 */
561 QPen QAbstractAxis::labelsPen() const
559 QPen QAbstractAxis::labelsPen() const
562 {
560 {
563 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
561 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
@@ -651,9 +649,6 bool QAbstractAxis::isTitleVisible() const
651 return d_ptr->m_titleVisible;
649 return d_ptr->m_titleVisible;
652 }
650 }
653
651
654 /*!
655 Sets \a pen used to draw title.
656 */
657 void QAbstractAxis::setTitlePen(const QPen &pen)
652 void QAbstractAxis::setTitlePen(const QPen &pen)
658 {
653 {
659 if (d_ptr->m_titlePen != pen) {
654 if (d_ptr->m_titlePen != pen) {
@@ -662,9 +657,6 void QAbstractAxis::setTitlePen(const QPen &pen)
662 }
657 }
663 }
658 }
664
659
665 /*!
666 Returns the pen used to title.
667 */
668 QPen QAbstractAxis::titlePen() const
660 QPen QAbstractAxis::titlePen() const
669 {
661 {
670 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
662 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
@@ -96,7 +96,7 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
96
96
97 switch (which) {
97 switch (which) {
98 case Qt::MinimumSize: {
98 case Qt::MinimumSize: {
99 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
99 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
100 width = boundingRect.width() / 2.0;
100 width = boundingRect.width() / 2.0;
101 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
101 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
102 sh = QSizeF(width, height);
102 sh = QSizeF(width, height);
@@ -106,7 +106,7 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
106 qreal labelHeight = 0.0;
106 qreal labelHeight = 0.0;
107 qreal firstWidth = -1.0;
107 qreal firstWidth = -1.0;
108 foreach (const QString& s, ticksList) {
108 foreach (const QString& s, ticksList) {
109 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
109 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
110 labelHeight = qMax(rect.height(), labelHeight);
110 labelHeight = qMax(rect.height(), labelHeight);
111 width = rect.width();
111 width = rect.width();
112 if (firstWidth < 0.0)
112 if (firstWidth < 0.0)
@@ -96,7 +96,7 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
96
96
97 switch (which) {
97 switch (which) {
98 case Qt::MinimumSize: {
98 case Qt::MinimumSize: {
99 QRectF boundingRect = textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
99 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
100 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
100 width = boundingRect.width() + labelPadding() + base.width() + 1.0;
101 height = boundingRect.height() / 2.0;
101 height = boundingRect.height() / 2.0;
102 sh = QSizeF(width, height);
102 sh = QSizeF(width, height);
@@ -106,7 +106,7 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
106 qreal labelWidth = 0.0;
106 qreal labelWidth = 0.0;
107 qreal firstHeight = -1.0;
107 qreal firstHeight = -1.0;
108 foreach (const QString& s, ticksList) {
108 foreach (const QString& s, ticksList) {
109 QRectF rect = textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
109 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
110 labelWidth = qMax(rect.width(), labelWidth);
110 labelWidth = qMax(rect.width(), labelWidth);
111 height = rect.height();
111 height = rect.height();
112 if (firstHeight < 0.0)
112 if (firstHeight < 0.0)
@@ -20,6 +20,7
20
20
21 #include "verticalaxis_p.h"
21 #include "verticalaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include <QDebug>
24 #include <QDebug>
24
25
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -46,7 +47,7 void VerticalAxis::updateGeometry()
46 QList<QGraphicsItem *> labels = labelItems();
47 QList<QGraphicsItem *> labels = labelItems();
47 QList<QGraphicsItem *> shades = shadeItems();
48 QList<QGraphicsItem *> shades = shadeItems();
48 QList<QGraphicsItem *> arrow = arrowItems();
49 QList<QGraphicsItem *> arrow = arrowItems();
49 QGraphicsSimpleTextItem *title = titleItem();
50 QGraphicsTextItem *title = titleItem();
50
51
51 Q_ASSERT(labels.size() == labelList.size());
52 Q_ASSERT(labels.size() == labelList.size());
52 Q_ASSERT(layout.size() == labelList.size());
53 Q_ASSERT(layout.size() == labelList.size());
@@ -71,7 +72,7 void VerticalAxis::updateGeometry()
71 QRectF titleBoundingRect;
72 QRectF titleBoundingRect;
72 QString titleText = axis()->titleText();
73 QString titleText = axis()->titleText();
73 if (!titleText.isEmpty() && titleItem()->isVisible()) {
74 if (!titleText.isEmpty() && titleItem()->isVisible()) {
74 title->setText(truncatedText(axis()->titleFont(), titleText, 0.0, gridRect.height(), Qt::Horizontal, QRectF()));
75 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.height(), Qt::Horizontal, QRectF()));
75
76
76 titlePad = titlePadding();
77 titlePad = titlePadding();
77 titleBoundingRect = title->boundingRect();
78 titleBoundingRect = title->boundingRect();
@@ -91,7 +92,7 void VerticalAxis::updateGeometry()
91 //items
92 //items
92 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
93 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
93 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrow.at(i + 1));
94 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrow.at(i + 1));
94 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
95 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labels.at(i));
95
96
96 //grid line
97 //grid line
97 gridItem->setLine(gridRect.left(), layout[i], gridRect.right(), layout[i]);
98 gridItem->setLine(gridRect.left(), layout[i], gridRect.right(), layout[i]);
@@ -100,7 +101,7 void VerticalAxis::updateGeometry()
100 QString text = labelList.at(i);
101 QString text = labelList.at(i);
101 QRectF boundingRect;
102 QRectF boundingRect;
102 qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2);
103 qreal size = axisRect.right() - axisRect.left() - labelPadding() - titleBoundingRect.height() - (titlePad * 2);
103 labelItem->setText(truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(),
104 labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, axis()->labelsAngle(),
104 size, Qt::Horizontal, boundingRect));
105 size, Qt::Horizontal, boundingRect));
105
106
106 //label transformation origin point
107 //label transformation origin point
@@ -190,13 +191,13 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
190
191
191 switch (which) {
192 switch (which) {
192 case Qt::MinimumSize: {
193 case Qt::MinimumSize: {
193 QRectF titleRect = textBoundingRect(axis()->titleFont(), "...");
194 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), "...");
194 sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width());
195 sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width());
195 break;
196 break;
196 }
197 }
197 case Qt::MaximumSize:
198 case Qt::MaximumSize:
198 case Qt::PreferredSize: {
199 case Qt::PreferredSize: {
199 QRectF titleRect = textBoundingRect(axis()->titleFont(), axis()->titleText());
200 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
200 sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width());
201 sh = QSizeF(titleRect.height() + (titlePadding() * 2), titleRect.width());
201 break;
202 break;
202 }
203 }
@@ -100,7 +100,7 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
100
100
101 for (int i = 0; i < m_bars.count(); i++) {
101 for (int i = 0; i < m_bars.count(); i++) {
102 m_bars.at(i)->setRect(layout.at(i));
102 m_bars.at(i)->setRect(layout.at(i));
103 QGraphicsSimpleTextItem *label = m_labels.at(i);
103 QGraphicsTextItem *label = m_labels.at(i);
104 label->setPos(layout.at(i).center() - label->boundingRect().center());
104 label->setPos(layout.at(i).center() - label->boundingRect().center());
105
105
106 }
106 }
@@ -135,7 +135,7 void AbstractBarChartItem::handleLayoutChanged()
135
135
136 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
136 void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
137 {
137 {
138 foreach (QGraphicsSimpleTextItem *label, m_labels)
138 foreach (QGraphicsTextItem *label, m_labels)
139 label->setVisible(visible);
139 label->setVisible(visible);
140 update();
140 update();
141 }
141 }
@@ -164,7 +164,7 void AbstractBarChartItem::handleDataStructureChanged()
164 // m_layout.append(QRectF(0, 0, 1, 1));
164 // m_layout.append(QRectF(0, 0, 1, 1));
165
165
166 // Labels
166 // Labels
167 m_labels.append(new QGraphicsSimpleTextItem(this));
167 m_labels.append(new QGraphicsTextItem(this));
168 }
168 }
169 }
169 }
170
170
@@ -206,10 +206,10 void AbstractBarChartItem::handleUpdatedBars()
206 bar->setBrush(barSet->m_brush);
206 bar->setBrush(barSet->m_brush);
207 bar->update();
207 bar->update();
208
208
209 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
209 QGraphicsTextItem *label = m_labels.at(itemIndex);
210 label->setText(QString("%1").arg(barSet->value(category)));
210 label->setHtml(QString("%1").arg(barSet->value(category)));
211 label->setFont(barSet->m_labelFont);
211 label->setFont(barSet->m_labelFont);
212 label->setBrush(barSet->m_labelBrush);
212 label->setDefaultTextColor(barSet->m_labelBrush.color());
213 label->update();
213 label->update();
214 itemIndex++;
214 itemIndex++;
215 }
215 }
@@ -85,7 +85,7 protected:
85
85
86 QAbstractBarSeries *m_series; // Not owned.
86 QAbstractBarSeries *m_series; // Not owned.
87 QList<Bar *> m_bars;
87 QList<Bar *> m_bars;
88 QList<QGraphicsSimpleTextItem *> m_labels;
88 QList<QGraphicsTextItem *> m_labels;
89 QSizeF m_oldSize;
89 QSizeF m_oldSize;
90 };
90 };
91
91
@@ -108,14 +108,14 void HorizontalPercentBarChartItem::handleUpdatedBars()
108 bar->setBrush(barSet->m_brush);
108 bar->setBrush(barSet->m_brush);
109 bar->update();
109 bar->update();
110
110
111 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
111 QGraphicsTextItem *label = m_labels.at(itemIndex);
112 int p = m_series->d_func()->percentageAt(set, category) * 100;
112 int p = m_series->d_func()->percentageAt(set, category) * 100;
113 QString vString(QString::number(p));
113 QString vString(QString::number(p));
114 vString.truncate(3);
114 vString.truncate(3);
115 vString.append("%");
115 vString.append("%");
116 label->setText(vString);
116 label->setHtml(vString);
117 label->setFont(barSet->m_labelFont);
117 label->setFont(barSet->m_labelFont);
118 label->setBrush(barSet->m_labelBrush);
118 label->setDefaultTextColor(barSet->m_labelBrush.color());
119 label->update();
119 label->update();
120 itemIndex++;
120 itemIndex++;
121 }
121 }
@@ -110,14 +110,14 void PercentBarChartItem::handleUpdatedBars()
110 bar->setBrush(barSet->m_brush);
110 bar->setBrush(barSet->m_brush);
111 bar->update();
111 bar->update();
112
112
113 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
113 QGraphicsTextItem *label = m_labels.at(itemIndex);
114 int p = m_series->d_func()->percentageAt(set, category) * 100;
114 int p = m_series->d_func()->percentageAt(set, category) * 100;
115 QString vString(QString::number(p));
115 QString vString(QString::number(p));
116 vString.truncate(3);
116 vString.truncate(3);
117 vString.append("%");
117 vString.append("%");
118 label->setText(vString);
118 label->setHtml(vString);
119 label->setFont(barSet->m_labelFont);
119 label->setFont(barSet->m_labelFont);
120 label->setBrush(barSet->m_labelBrush);
120 label->setDefaultTextColor(barSet->m_labelBrush.color());
121 label->update();
121 label->update();
122 itemIndex++;
122 itemIndex++;
123 }
123 }
@@ -36,6 +36,15
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 QGraphicsTextItem *dummyTextItem = 0;
40 class StaticDummyTextDeleter
41 {
42 public:
43 StaticDummyTextDeleter() {}
44 ~StaticDummyTextDeleter() { delete dummyTextItem; }
45 };
46 StaticDummyTextDeleter staticDummyTextDeleter;
47
39 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
48 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
40 : QObject(chart),
49 : QObject(chart),
41 m_chart(chart),
50 m_chart(chart),
@@ -286,7 +295,7 QFont ChartPresenter::titleFont() const
286 void ChartPresenter::setTitleBrush(const QBrush &brush)
295 void ChartPresenter::setTitleBrush(const QBrush &brush)
287 {
296 {
288 createTitleItem();
297 createTitleItem();
289 m_title->setBrush(brush);
298 m_title->setDefaultTextColor(brush.color());
290 m_layout->invalidate();
299 m_layout->invalidate();
291 }
300 }
292
301
@@ -294,7 +303,7 QBrush ChartPresenter::titleBrush() const
294 {
303 {
295 if (!m_title)
304 if (!m_title)
296 return QBrush();
305 return QBrush();
297 return m_title->brush();
306 return QBrush(m_title->defaultTextColor());
298 }
307 }
299
308
300 void ChartPresenter::setBackgroundVisible(bool visible)
309 void ChartPresenter::setBackgroundVisible(bool visible)
@@ -378,6 +387,58 ChartTitle *ChartPresenter::titleElement()
378 return m_title;
387 return m_title;
379 }
388 }
380
389
390 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
391 {
392 if (!dummyTextItem)
393 dummyTextItem = new QGraphicsTextItem;
394
395 dummyTextItem->setFont(font);
396 dummyTextItem->setHtml(text);
397 QRectF boundingRect = dummyTextItem->boundingRect();
398
399 // Take rotation into account
400 if (angle) {
401 QTransform transform;
402 transform.rotate(angle);
403 boundingRect = transform.mapRect(boundingRect);
404 }
405
406 return boundingRect;
407 }
408
409 // boundingRect parameter returns the rotated bounding rect of the text
410 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle,
411 qreal maxSize, Qt::Orientation constraintOrientation,
412 QRectF &boundingRect)
413 {
414 QString truncatedString(text);
415 boundingRect = textBoundingRect(font, truncatedString, angle);
416 qreal checkDimension = ((constraintOrientation == Qt::Horizontal)
417 ? boundingRect.width() : boundingRect.height());
418 if (checkDimension > maxSize) {
419 truncatedString.append("...");
420 while (checkDimension > maxSize && truncatedString.length() > 3) {
421 // Crude truncation logic - simply remove any html tag completely
422 int removeIndex(-1);
423 int removeCount(1);
424 if (truncatedString.at(truncatedString.length() - 4) == QLatin1Char('>')) {
425 removeIndex = truncatedString.lastIndexOf(QLatin1Char('<'));
426 if (removeIndex != -1)
427 removeCount = truncatedString.length() - 3 - removeIndex;
428 }
429 if (removeIndex == -1)
430 removeIndex = truncatedString.length() - 4;
431
432 truncatedString.remove(removeIndex, removeCount);
433 boundingRect = textBoundingRect(font, truncatedString, angle);
434 checkDimension = ((constraintOrientation == Qt::Horizontal)
435 ? boundingRect.width() : boundingRect.height());
436 }
437 }
438
439 return truncatedString;
440 }
441
381 #include "moc_chartpresenter_p.cpp"
442 #include "moc_chartpresenter_p.cpp"
382
443
383 QTCOMMERCIALCHART_END_NAMESPACE
444 QTCOMMERCIALCHART_END_NAMESPACE
@@ -141,6 +141,9 public:
141 QChart::ChartType chartType() const { return m_chart->chartType(); }
141 QChart::ChartType chartType() const { return m_chart->chartType(); }
142 QChart *chart() { return m_chart; }
142 QChart *chart() { return m_chart; }
143
143
144 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
145 static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize,
146 Qt::Orientation constraintOrientation, QRectF &boundingRect);
144 private:
147 private:
145 void createBackgroundItem();
148 void createBackgroundItem();
146 void createPlotAreaBackgroundItem();
149 void createPlotAreaBackgroundItem();
@@ -19,6 +19,7
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "charttitle_p.h"
21 #include "charttitle_p.h"
22 #include "chartpresenter_p.h"
22 #include <QFont>
23 #include <QFont>
23 #include <QFontMetrics>
24 #include <QFontMetrics>
24 #include <QDebug>
25 #include <QDebug>
@@ -26,7 +27,7
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 ChartTitle::ChartTitle(QGraphicsItem *parent)
29 ChartTitle::ChartTitle(QGraphicsItem *parent)
29 : QGraphicsSimpleTextItem(parent)
30 : QGraphicsTextItem(parent)
30 {
31 {
31
32
32 }
33 }
@@ -48,19 +49,7 QString ChartTitle::text() const
48
49
49 void ChartTitle::setGeometry(const QRectF &rect)
50 void ChartTitle::setGeometry(const QRectF &rect)
50 {
51 {
51 QFontMetrics fn(font());
52 QGraphicsTextItem::setHtml(ChartPresenter::truncatedText(font(), m_text, qreal(0.0), rect.width(), Qt::Horizontal, QRectF()));
52
53 int width = rect.width();
54
55 if (fn.boundingRect(m_text).width() > width) {
56 QString string = m_text + "...";
57 while (fn.boundingRect(string).width() > width && string.length() > 3)
58 string.remove(string.length() - 4, 1);
59 QGraphicsSimpleTextItem::setText(string);
60 } else {
61 QGraphicsSimpleTextItem::setText(m_text);
62 }
63
64 setPos(rect.topLeft());
53 setPos(rect.topLeft());
65 }
54 }
66
55
@@ -68,22 +57,25 void ChartTitle::setGeometry(const QRectF &rect)
68 QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
57 QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
69 {
58 {
70 Q_UNUSED(constraint);
59 Q_UNUSED(constraint);
71 QFontMetrics fn(font());
72 QSizeF sh;
60 QSizeF sh;
73
61
74 switch (which) {
62 switch (which) {
75 case Qt::MinimumSize:
63 case Qt::MinimumSize: {
76 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
64 QRectF titleRect = ChartPresenter::textBoundingRect(font(), "...");
65 sh = QSizeF(titleRect.width(), titleRect.height());
77 break;
66 break;
67 }
78 case Qt::PreferredSize:
68 case Qt::PreferredSize:
79 sh = fn.boundingRect(m_text).size();
69 case Qt::MaximumSize: {
80 break;
70 QRectF titleRect = ChartPresenter::textBoundingRect(font(), m_text);
81 case Qt::MaximumSize:
71 sh = QSizeF(titleRect.width(), titleRect.height());
82 sh = fn.boundingRect(m_text).size();
83 break;
72 break;
84 case Qt::MinimumDescent:
73 }
74 case Qt::MinimumDescent: {
75 QFontMetrics fn(font());
85 sh = QSizeF(0, fn.descent());
76 sh = QSizeF(0, fn.descent());
86 break;
77 break;
78 }
87 default:
79 default:
88 break;
80 break;
89 }
81 }
@@ -31,11 +31,11
31 #define CHARTTITLE_P_H_
31 #define CHARTTITLE_P_H_
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsTextItem>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class ChartTitle : public QGraphicsSimpleTextItem
38 class ChartTitle : public QGraphicsTextItem
39 {
39 {
40 public:
40 public:
41 ChartTitle(QGraphicsItem *parent = 0);
41 ChartTitle(QGraphicsItem *parent = 0);
@@ -57,7 +57,7 QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, const QLi
57 && chartAxis->axis()->isTitleVisible()
57 && chartAxis->axis()->isTitleVisible()
58 && !chartAxis->axis()->titleText().isEmpty()) {
58 && !chartAxis->axis()->titleText().isEmpty()) {
59 // If axis has angular title, adjust geometry down by the space title takes
59 // If axis has angular title, adjust geometry down by the space title takes
60 QRectF dummyRect = chartAxis->textBoundingRect(chartAxis->axis()->titleFont(), chartAxis->axis()->titleText());
60 QRectF dummyRect = ChartPresenter::textBoundingRect(chartAxis->axis()->titleFont(), chartAxis->axis()->titleText());
61 titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding();
61 titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding();
62 }
62 }
63 }
63 }
@@ -20,13 +20,14
20
20
21 #include <QPainter>
21 #include <QPainter>
22 #include <QGraphicsSceneEvent>
22 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSimpleTextItem>
23 #include <QGraphicsTextItem>
24
24
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qlegend_p.h"
26 #include "qlegend_p.h"
27 #include "qlegendmarker.h"
27 #include "qlegendmarker.h"
28 #include "qlegendmarker_p.h"
28 #include "qlegendmarker_p.h"
29 #include "legendmarkeritem_p.h"
29 #include "legendmarkeritem_p.h"
30 #include "chartpresenter_p.h"
30
31
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
33
@@ -35,7 +36,7 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject
35 m_marker(marker),
36 m_marker(marker),
36 m_markerRect(0,0,10.0,10.0),
37 m_markerRect(0,0,10.0,10.0),
37 m_boundingRect(0,0,0,0),
38 m_boundingRect(0,0,0,0),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
39 m_textItem(new QGraphicsTextItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
40 m_rectItem(new QGraphicsRectItem(this)),
40 m_margin(4),
41 m_margin(4),
41 m_space(4),
42 m_space(4),
@@ -99,41 +100,32 QString LegendMarkerItem::label() const
99
100
100 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
101 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
101 {
102 {
102 m_textItem->setBrush(brush);
103 m_textItem->setDefaultTextColor(brush.color());
103 }
104 }
104
105
105 QBrush LegendMarkerItem::labelBrush() const
106 QBrush LegendMarkerItem::labelBrush() const
106 {
107 {
107 return m_textItem->brush();
108 return QBrush(m_textItem->defaultTextColor());
108 }
109 }
109
110
110 void LegendMarkerItem::setGeometry(const QRectF &rect)
111 void LegendMarkerItem::setGeometry(const QRectF &rect)
111 {
112 {
112 QFontMetrics fn (m_font);
113
114 int width = rect.width();
113 int width = rect.width();
115 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
114 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
116 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
115 QRectF truncatedRect;
117
118 if (fn.boundingRect(m_label).width() + x > width)
119 {
120 QString string = m_label + "...";
121 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
122 string.remove(string.length() - 4, 1);
123 m_textItem->setText(string);
124 }
125 else
126 m_textItem->setText(m_label);
127
116
128 const QRectF &textRect = m_textItem->boundingRect();
117 m_textItem->setHtml(ChartPresenter::truncatedText(m_font, m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
129
118
119 qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);
120
121 const QRectF &textRect = m_textItem->boundingRect();
130
122
131 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
123 m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2);
132 m_rectItem->setRect(m_markerRect);
124 m_rectItem->setRect(m_markerRect);
133 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
125 m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2);
134
126
135 prepareGeometryChange();
127 prepareGeometryChange();
136 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
128 m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y);
137 }
129 }
138
130
139 QRectF LegendMarkerItem::boundingRect() const
131 QRectF LegendMarkerItem::boundingRect() const
@@ -35,7 +35,7
35 #include <QFont>
35 #include <QFont>
36 #include <QBrush>
36 #include <QBrush>
37 #include <QPen>
37 #include <QPen>
38 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsTextItem>
39 #include <QGraphicsLayoutItem>
39 #include <QGraphicsLayoutItem>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -78,7 +78,7 protected:
78 QLegendMarkerPrivate *m_marker; // Knows
78 QLegendMarkerPrivate *m_marker; // Knows
79 QRectF m_markerRect;
79 QRectF m_markerRect;
80 QRectF m_boundingRect;
80 QRectF m_boundingRect;
81 QGraphicsSimpleTextItem *m_textItem;
81 QGraphicsTextItem *m_textItem;
82 QGraphicsRectItem *m_rectItem;
82 QGraphicsRectItem *m_rectItem;
83 qreal m_margin;
83 qreal m_margin;
84 qreal m_space;
84 qreal m_space;
@@ -34,7 +34,6
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
37 #include <QGraphicsLayoutItem>
39
38
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -75,11 +75,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
75
75
76 /*!
76 /*!
77 \property QAbstractSeries::name
77 \property QAbstractSeries::name
78 \brief name of the series property. The name is shown in legend for QXYSeries.
78 \brief name of the series property. The name is shown in legend for series and supports html formatting.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty string AbstractSeries::name
81 \qmlproperty string AbstractSeries::name
82 Name of the series. The name is shown in legend for QXYSeries.
82 Name of the series. The name is shown in legend for series and supports html formatting.
83 */
83 */
84
84
85 /*!
85 /*!
@@ -119,7 +119,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
119
119
120 /*!
120 /*!
121 \property QChart::title
121 \property QChart::title
122 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
122 Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting.
123 */
123 */
124
124
125 /*!
125 /*!
@@ -754,7 +754,7 void tst_QChart::titleBrush()
754 {
754 {
755 QFETCH(QBrush, titleBrush);
755 QFETCH(QBrush, titleBrush);
756 m_chart->setTitleBrush(titleBrush);
756 m_chart->setTitleBrush(titleBrush);
757 QCOMPARE(m_chart->titleBrush(), titleBrush);
757 QCOMPARE(m_chart->titleBrush().color(), titleBrush.color());
758 }
758 }
759
759
760 void tst_QChart::titleFont_data()
760 void tst_QChart::titleFont_data()
General Comments 0
You need to be logged in to leave comments. Login now