##// END OF EJS Templates
Refactors ChartAxis...
Michal Klocek -
r2138:44f1f46281dd
parent child
Show More
@@ -112,7 +112,7 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
112
112
113 QFontMetrics fn(font());
113 QFontMetrics fn(font());
114 QSizeF sh;
114 QSizeF sh;
115 QSizeF base = ChartAxis::sizeHint(which, constraint);
115 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
116 QStringList ticksList = createCategoryLabels(ChartAxis::layout());
116 QStringList ticksList = createCategoryLabels(ChartAxis::layout());
117
117
118 qreal width=0;
118 qreal width=0;
@@ -110,7 +110,7 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
110
110
111 QFontMetrics fn(font());
111 QFontMetrics fn(font());
112 QSizeF sh;
112 QSizeF sh;
113 QSizeF base = ChartAxis::sizeHint(which, constraint);
113 QSizeF base = VerticalAxis::sizeHint(which, constraint);
114 QStringList ticksList = createCategoryLabels(ChartAxis::layout());
114 QStringList ticksList = createCategoryLabels(ChartAxis::layout());
115
115
116 qreal width=0;
116 qreal width=0;
@@ -84,7 +84,7 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
84
84
85 QFontMetrics fn(font());
85 QFontMetrics fn(font());
86 QSizeF sh;
86 QSizeF sh;
87 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
88 QStringList ticksList = m_axis->categoriesLabels();
88 QStringList ticksList = m_axis->categoriesLabels();
89 qreal width = 0;
89 qreal width = 0;
90 qreal height = 0;
90 qreal height = 0;
@@ -84,7 +84,7 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
84
84
85 QFontMetrics fn(font());
85 QFontMetrics fn(font());
86 QSizeF sh;
86 QSizeF sh;
87 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QSizeF base = VerticalAxis::sizeHint(which, constraint);
88 QStringList ticksList = m_axis->categoriesLabels();
88 QStringList ticksList = m_axis->categoriesLabels();
89 qreal width = 0;
89 qreal width = 0;
90 qreal height = 0;
90 qreal height = 0;
@@ -422,37 +422,6 void ChartAxis::setLabels(const QStringList &labels)
422 m_labelsList = labels;
422 m_labelsList = labels;
423 }
423 }
424
424
425 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
426 {
427
428 Q_UNUSED(constraint);
429 QFontMetrics fn(m_title->font());
430 QSizeF sh;
431
432 if (m_titleText.isNull())
433 return sh;
434
435 switch (which) {
436 case Qt::MinimumSize:
437 if (orientation() == Qt::Horizontal)
438 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
439 else if (orientation() == Qt::Vertical)
440 sh = QSizeF(fn.height(), fn.boundingRect("...").width());
441 break;
442 case Qt::MaximumSize:
443 case Qt::PreferredSize:
444 if (orientation() == Qt::Horizontal)
445 sh = QSizeF(fn.boundingRect(m_chartAxis->title()).width(), fn.height());
446 else if (orientation() == Qt::Vertical)
447 sh = QSizeF(fn.height(), fn.boundingRect(m_chartAxis->title()).width());
448 break;
449 default:
450 break;
451 }
452
453 return sh;
454 }
455
456 QStringList ChartAxis::createValueLabels(int ticks) const
425 QStringList ChartAxis::createValueLabels(int ticks) const
457 {
426 {
458 Q_ASSERT(m_max > m_min);
427 Q_ASSERT(m_max > m_min);
@@ -497,6 +466,13 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) co
497 return labels;
466 return labels;
498 }
467 }
499
468
469 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
470 {
471 Q_UNUSED(which);
472 Q_UNUSED(constraint);
473 return QSizeF();
474 }
475
500 #include "moc_chartaxis_p.cpp"
476 #include "moc_chartaxis_p.cpp"
501
477
502 QTCOMMERCIALCHART_END_NAMESPACE
478 QTCOMMERCIALCHART_END_NAMESPACE
@@ -51,6 +51,8 public:
51 ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
51 ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
52 ~ChartAxis();
52 ~ChartAxis();
53
53
54 QAbstractAxis* axis() const { return m_chartAxis; }
55
54 void setArrowOpacity(qreal opacity);
56 void setArrowOpacity(qreal opacity);
55 qreal arrowOpacity() const;
57 qreal arrowOpacity() const;
56 void setArrowVisibility(bool visible);
58 void setArrowVisibility(bool visible);
@@ -86,6 +88,7 public:
86 void setTitleBrush(const QBrush &brush);
88 void setTitleBrush(const QBrush &brush);
87 void setTitleFont(const QFont &font);
89 void setTitleFont(const QFont &font);
88 void setTitleText(const QString &title);
90 void setTitleText(const QString &title);
91 QString titleText() const {return m_titleText; };
89
92
90 void setLayout(QVector<qreal> &layout);
93 void setLayout(QVector<qreal> &layout);
91 QVector<qreal> layout() const { return m_layoutVector; }
94 QVector<qreal> layout() const { return m_layoutVector; }
@@ -120,6 +123,7 protected:
120 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
123 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
121 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
124 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
122 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
125 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
126 QGraphicsSimpleTextItem* titleItem() const { return m_title;}
123
127
124 QFont font() const { return m_font; }
128 QFont font() const { return m_font; }
125 qreal min() const {return m_min; }
129 qreal min() const {return m_min; }
@@ -156,4 +156,28 void HorizontalAxis::updateGeometry()
156 }
156 }
157 }
157 }
158
158
159 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
160 {
161 Q_UNUSED(constraint);
162 QFontMetrics fn(titleItem()->font());
163 QSizeF sh;
164
165 if (titleText().isNull())
166 return sh;
167
168 switch (which) {
169 case Qt::MinimumSize:
170 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
171 break;
172 case Qt::MaximumSize:
173 case Qt::PreferredSize:
174 sh = QSizeF(fn.boundingRect(axis()->title()).width(), fn.height());
175 break;
176 default:
177 break;
178 }
179
180 return sh;
181 }
182
159 QTCOMMERCIALCHART_END_NAMESPACE
183 QTCOMMERCIALCHART_END_NAMESPACE
@@ -39,6 +39,7 class HorizontalAxis : public ChartAxis
39 public:
39 public:
40 HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
40 HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
41 ~HorizontalAxis();
41 ~HorizontalAxis();
42 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
42 protected:
43 protected:
43 void updateGeometry();
44 void updateGeometry();
44
45
@@ -82,7 +82,7 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
82 QFontMetrics fn(font());
82 QFontMetrics fn(font());
83 QSizeF sh;
83 QSizeF sh;
84
84
85 QSizeF base = ChartAxis::sizeHint(which, constraint);
85 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
86 QStringList ticksList = createValueLabels(m_tickCount);
86 QStringList ticksList = createValueLabels(m_tickCount);
87 qreal width = 0;
87 qreal width = 0;
88 qreal height = 0;
88 qreal height = 0;
@@ -84,7 +84,7 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
84
84
85 QFontMetrics fn(font());
85 QFontMetrics fn(font());
86 QSizeF sh;
86 QSizeF sh;
87 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QSizeF base = VerticalAxis::sizeHint(which, constraint);
88 QStringList ticksList = createValueLabels(m_tickCount);
88 QStringList ticksList = createValueLabels(m_tickCount);
89 qreal width = 0;
89 qreal width = 0;
90 qreal height = 0;
90 qreal height = 0;
@@ -151,4 +151,29 void VerticalAxis::updateGeometry()
151 }
151 }
152 }
152 }
153
153
154 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
155 {
156
157 Q_UNUSED(constraint);
158 QFontMetrics fn(titleItem()->font());
159 QSizeF sh;
160
161 if (titleText().isNull())
162 return sh;
163
164 switch (which) {
165 case Qt::MinimumSize:
166 sh = QSizeF(fn.height(), fn.boundingRect("...").width());
167 break;
168 case Qt::MaximumSize:
169 case Qt::PreferredSize:
170 sh = QSizeF(fn.height(), fn.boundingRect(axis()->title()).width());
171 break;
172 default:
173 break;
174 }
175
176 return sh;
177 }
178
154 QTCOMMERCIALCHART_END_NAMESPACE
179 QTCOMMERCIALCHART_END_NAMESPACE
@@ -39,6 +39,7 class VerticalAxis : public ChartAxis
39 public:
39 public:
40 VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
40 VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
41 ~VerticalAxis();
41 ~VerticalAxis();
42 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
42 protected:
43 protected:
43 void updateGeometry();
44 void updateGeometry();
44
45
General Comments 0
You need to be logged in to leave comments. Login now