##// END OF EJS Templates
Fixes categoryaxis sizeHints
Michal Klocek -
r2136:44641cd4faa0
parent child
Show More
@@ -130,7 +130,7 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
130 {
130 {
131 QRectF rect = fn.boundingRect(ticksList.at(i));
131 QRectF rect = fn.boundingRect(ticksList.at(i));
132 height+=rect.height();
132 height+=rect.height();
133 width=qMax(rect.width()+labelPadding() +1 ,width); //one pixel torelance
133 width=qMax(rect.width()+labelPadding() + 1 ,width); //one pixel torelance
134 }
134 }
135 height=qMax(height,base.height());
135 height=qMax(height,base.height());
136 width+=base.width();
136 width+=base.width();
@@ -47,16 +47,16 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
47 return points;
47 return points;
48
48
49 const QRectF &gridRect = gridGeometry();
49 const QRectF &gridRect = gridGeometry();
50 qreal range = m_axis->max() - m_axis->min();
50 qreal range = max() - min();
51 if (range > 0) {
51 if (range > 0) {
52 points.resize(tickCount);
52 points.resize(tickCount);
53 qreal scale = gridRect.width() / range;
53 qreal scale = gridRect.width() / range;
54 for (int i = 0; i < tickCount; ++i) {
54 for (int i = 0; i < tickCount; ++i) {
55 if (i < tickCount - 1) {
55 if (i < tickCount - 1) {
56 int x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - m_axis->min()) * scale + gridRect.left();
56 int x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
57 points[i] = x;
57 points[i] = x;
58 } else {
58 } else {
59 int x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - m_axis->min()) * scale + gridRect.left();
59 int x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
60 points[i] = x;
60 points[i] = x;
61 }
61 }
62 }
62 }
@@ -67,6 +67,7 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
67
67
68 void ChartCategoryAxisX::updateGeometry()
68 void ChartCategoryAxisX::updateGeometry()
69 {
69 {
70 //TODO: this is not optimal when many categories :( , create only visible lables
70 setLabels(m_axis->categoriesLabels() << "");
71 setLabels(m_axis->categoriesLabels() << "");
71 HorizontalAxis::updateGeometry();
72 HorizontalAxis::updateGeometry();
72 }
73 }
@@ -84,7 +85,7 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
84 QFontMetrics fn(font());
85 QFontMetrics fn(font());
85 QSizeF sh;
86 QSizeF sh;
86 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QStringList ticksList ; //TODO:
88 QStringList ticksList = m_axis->categoriesLabels();
88 qreal width = 0;
89 qreal width = 0;
89 qreal height = 0;
90 qreal height = 0;
90
91
@@ -25,6 +25,7
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QDebug>
28
29
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31
@@ -47,16 +48,16 QVector<qreal> ChartCategoryAxisY::calculateLayout() const
47 return points;
48 return points;
48
49
49 const QRectF &gridRect = gridGeometry();
50 const QRectF &gridRect = gridGeometry();
50 qreal range = m_axis->max() - m_axis->min();
51 qreal range = max() - min();
51 if (range > 0) {
52 if (range > 0) {
52 points.resize(tickCount);
53 points.resize(tickCount);
53 qreal scale = gridRect.height() / range;
54 qreal scale = gridRect.height() / range;
54 for (int i = 0; i < tickCount; ++i) {
55 for (int i = 0; i < tickCount; ++i) {
55 if (i < tickCount - 1) {
56 if (i < tickCount - 1) {
56 int y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - m_axis->min()) * scale + gridRect.bottom();
57 int y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom();
57 points[i] = y;
58 points[i] = y;
58 } else {
59 } else {
59 int y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - m_axis->min()) * scale + gridRect.bottom();
60 int y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom();
60 points[i] = y;
61 points[i] = y;
61 }
62 }
62 }
63 }
@@ -84,7 +85,7 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
84 QFontMetrics fn(font());
85 QFontMetrics fn(font());
85 QSizeF sh;
86 QSizeF sh;
86 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QSizeF base = ChartAxis::sizeHint(which, constraint);
87 QStringList ticksList; //TODO::
88 QStringList ticksList = m_axis->categoriesLabels();
88 qreal width = 0;
89 qreal width = 0;
89 qreal height = 0;
90 qreal height = 0;
90
91
@@ -92,16 +93,16 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
92 case Qt::MinimumSize:
93 case Qt::MinimumSize:
93 width = fn.boundingRect("...").width() + labelPadding();
94 width = fn.boundingRect("...").width() + labelPadding();
94 height = fn.height();
95 height = fn.height();
95 width = qMax(width, base.width());
96 width += base.width();
96 height += base.height();
97 height = qMax(height, base.height());;
97 sh = QSizeF(width, height);
98 sh = QSizeF(width, height);
98 break;
99 break;
99 case Qt::PreferredSize: {
100 case Qt::PreferredSize: {
100
101
101 for (int i = 0; i < ticksList.size(); ++i) {
102 for (int i = 0; i < ticksList.size(); ++i) {
102 QRectF rect = fn.boundingRect(ticksList.at(i));
103 QRectF rect = fn.boundingRect(ticksList.at(i));
104 width = qMax(rect.width() + labelPadding() + 1, width);
103 height += rect.height();
105 height += rect.height();
104 width = qMax(rect.width() + labelPadding(), width);
105 }
106 }
106 height = qMax(height, base.height());
107 height = qMax(height, base.height());
107 width += base.width();
108 width += base.width();
@@ -111,7 +112,6 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
111 default:
112 default:
112 break;
113 break;
113 }
114 }
114
115 return sh;
115 return sh;
116 }
116 }
117
117
General Comments 0
You need to be logged in to leave comments. Login now