##// END OF EJS Templates
Adds title support for mulitaxis...
Michal Klocek -
r2139:19aaaff66111
parent child
Show More
@@ -363,35 +363,6 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
363 if (isEmpty())
363 if (isEmpty())
364 return;
364 return;
365
365
366 if (!m_titleText.isNull()) {
367 QFontMetrics fn(m_title->font());
368
369 int size(0);
370
371 if (orientation() == Qt::Horizontal)
372 size = grid.width();
373 else if (orientation() == Qt::Vertical)
374 size = grid.height();
375
376 if (fn.boundingRect(m_titleText).width() > size) {
377 QString string = m_titleText + "...";
378 while (fn.boundingRect(string).width() > size && string.length() > 3)
379 string.remove(string.length() - 4, 1);
380 m_title->setText(string);
381 } else {
382 m_title->setText(m_titleText);
383 }
384
385 QPointF center = grid.center() - m_title->boundingRect().center();
386 if (orientation() == Qt::Horizontal) {
387 m_title->setPos(center.x(), m_axisRect.bottom() - m_title->boundingRect().height());
388 } else if (orientation() == Qt::Vertical) {
389 m_title->setTransformOriginPoint(m_title->boundingRect().center());
390 m_title->setRotation(270);
391 m_title->setPos(m_axisRect.left() - m_title->boundingRect().width() / 2 + m_title->boundingRect().height() / 2, center.y());
392 }
393 }
394
395 QVector<qreal> layout = calculateLayout();
366 QVector<qreal> layout = calculateLayout();
396 updateLayout(layout);
367 updateLayout(layout);
397
368
@@ -87,6 +87,7 public:
87 void setTitlePen(const QPen &pen);
87 void setTitlePen(const QPen &pen);
88 void setTitleBrush(const QBrush &brush);
88 void setTitleBrush(const QBrush &brush);
89 void setTitleFont(const QFont &font);
89 void setTitleFont(const QFont &font);
90 QFont titleFont() const { return m_titleFont; };
90 void setTitleText(const QString &title);
91 void setTitleText(const QString &title);
91 QString titleText() const {return m_titleText; };
92 QString titleText() const {return m_titleText; };
92
93
@@ -157,6 +158,7 private:
157 qreal m_max;
158 qreal m_max;
158 AxisAnimation *m_animation;
159 AxisAnimation *m_animation;
159 QFont m_font;
160 QFont m_font;
161 QFont m_titleFont;
160 QString m_titleText;
162 QString m_titleText;
161 int m_labelPadding;
163 int m_labelPadding;
162 QStringList m_labelsList;
164 QStringList m_labelsList;
@@ -48,6 +48,7 void HorizontalAxis::updateGeometry()
48 QList<QGraphicsItem *> labels = labelItems();
48 QList<QGraphicsItem *> labels = labelItems();
49 QList<QGraphicsItem *> shades = shadeItems();
49 QList<QGraphicsItem *> shades = shadeItems();
50 QList<QGraphicsItem *> axis = arrowItems();
50 QList<QGraphicsItem *> axis = arrowItems();
51 QGraphicsSimpleTextItem* 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());
@@ -154,12 +155,40 void HorizontalAxis::updateGeometry()
154 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom());
155 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom());
155 gridLine->setVisible(true);
156 gridLine->setVisible(true);
156 }
157 }
158
159 //title
160
161 if (!titleText().isNull()) {
162 QFontMetrics fn(title->font());
163
164 int size(0);
165
166 size = gridRect.width();
167 QString titleText = this->titleText();
168
169 if (fn.boundingRect(titleText).width() > size) {
170 QString string = titleText + "...";
171 while (fn.boundingRect(string).width() > size && string.length() > 3)
172 string.remove(string.length() - 4, 1);
173 title->setText(string);
174 } else {
175 title->setText(titleText);
176 }
177
178 QPointF center = gridRect.center() - title->boundingRect().center();
179 if (alignment() == Qt::AlignTop) {
180 title->setPos(center.x(), axisRect.top());
181 } else if (alignment() == Qt::AlignBottom) {
182 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height());
183 }
184 }
185
157 }
186 }
158
187
159 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
188 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
160 {
189 {
161 Q_UNUSED(constraint);
190 Q_UNUSED(constraint);
162 QFontMetrics fn(titleItem()->font());
191 QFontMetrics fn(titleFont());
163 QSizeF sh;
192 QSizeF sh;
164
193
165 if (titleText().isNull())
194 if (titleText().isNull())
@@ -21,6 +21,7
21 #include "verticalaxis_p.h"
21 #include "verticalaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include <QFontMetrics>
23 #include <QFontMetrics>
24 #include <QDebug>
24
25
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27
@@ -48,6 +49,7 void VerticalAxis::updateGeometry()
48 QList<QGraphicsItem *> labels = labelItems();
49 QList<QGraphicsItem *> labels = labelItems();
49 QList<QGraphicsItem *> shades = shadeItems();
50 QList<QGraphicsItem *> shades = shadeItems();
50 QList<QGraphicsItem *> axis = arrowItems();
51 QList<QGraphicsItem *> axis = arrowItems();
52 QGraphicsSimpleTextItem* title = titleItem();
51
53
52 Q_ASSERT(labels.size() == labelList.size());
54 Q_ASSERT(labels.size() == labelList.size());
53 Q_ASSERT(layout.size() == labelList.size());
55 Q_ASSERT(layout.size() == labelList.size());
@@ -149,13 +151,41 void VerticalAxis::updateGeometry()
149 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
151 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
150 gridLine->setVisible(true);
152 gridLine->setVisible(true);
151 }
153 }
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 }
152 }
182 }
153
183
154 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
184 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
155 {
185 {
156
186
157 Q_UNUSED(constraint);
187 Q_UNUSED(constraint);
158 QFontMetrics fn(titleItem()->font());
188 QFontMetrics fn(titleFont());
159 QSizeF sh;
189 QSizeF sh;
160
190
161 if (titleText().isNull())
191 if (titleText().isNull())
@@ -29,7 +29,7
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 static const qreal golden_ratio = 0.4;
32 static const qreal golden_ratio = 0.8;//0.4;
33
33
34 ChartLayout::ChartLayout(ChartPresenter *presenter)
34 ChartLayout::ChartLayout(ChartPresenter *presenter)
35 : m_presenter(presenter),
35 : m_presenter(presenter),
General Comments 0
You need to be logged in to leave comments. Login now