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