##// END OF EJS Templates
Fix vanishing labels for first and last ticks....
Miikka Heikkinen -
r2443:5b27b7b1d72a RC2_1.2.1
parent child
Show More
@@ -109,13 +109,12 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
109 109 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
110 110 QStringList ticksList = m_categoriesAxis->categories();
111 111
112 qreal width=0;
113 qreal height=0;
112 qreal width = 0; // Width is irrelevant for X axes with interval labels
113 qreal height = 0;
114 114
115 115 switch (which) {
116 116 case Qt::MinimumSize: {
117 117 QRectF boundingRect = labelBoundingRect(fn, "...");
118 width = qMax(boundingRect.width(), base.width());
119 118 height = boundingRect.height() + labelPadding();
120 119 height += base.height();
121 120 sh = QSizeF(width, height);
@@ -126,11 +125,9 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
126 125 foreach (const QString& s, ticksList) {
127 126 QRect rect = labelBoundingRect(fn, s);
128 127 labelHeight = qMax(rect.height(), labelHeight);
129 width += rect.width();
130 128 }
131 129 height = labelHeight + labelPadding();
132 130 height += base.height();
133 width = qMax(width, base.width());
134 131 sh = QSizeF(width, height);
135 132 break;
136 133 }
@@ -107,8 +107,8 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
107 107 QSizeF sh;
108 108 QSizeF base = VerticalAxis::sizeHint(which, constraint);
109 109 QStringList ticksList = m_categoriesAxis->categories();
110 qreal width=0;
111 qreal height=0;
110 qreal width = 0;
111 qreal height = 0; // Height is irrelevant for Y axes with interval labels
112 112
113 113 switch (which) {
114 114 case Qt::MinimumSize: {
@@ -117,7 +117,6 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
117 117 width += base.width();
118 118 if (base.width() > 0)
119 119 width += labelPadding();
120 height = qMax(boundingRect.height(), base.height());
121 120 sh = QSizeF(width, height);
122 121 break;
123 122 }
@@ -126,13 +125,11 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
126 125 foreach (const QString& s, ticksList) {
127 126 QRect rect = labelBoundingRect(fn, s);
128 127 labelWidth = qMax(rect.width(), labelWidth);
129 height += rect.height();
130 128 }
131 129 width = labelWidth + labelPadding() + 1;
132 130 width += base.width();
133 131 if (base.width() > 0)
134 132 width += labelPadding();
135 height = qMax(height, base.height());
136 133 sh = QSizeF(width, height);
137 134 break;
138 135 }
@@ -84,13 +84,12 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
84 84 QSizeF sh;
85 85 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
86 86 QStringList ticksList = m_axis->categoriesLabels();
87 qreal width = 0;
87 qreal width = 0; // Width is irrelevant for X axes with interval labels
88 88 qreal height = 0;
89 89
90 90 switch (which) {
91 91 case Qt::MinimumSize: {
92 92 QRectF boundingRect = labelBoundingRect(fn, "...");
93 width = qMax(boundingRect.width(), base.width());
94 93 height = boundingRect.height() + labelPadding();
95 94 height += base.height();
96 95 sh = QSizeF(width, height);
@@ -101,11 +100,9 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
101 100 foreach (const QString& s, ticksList) {
102 101 QRect rect = labelBoundingRect(fn, s);
103 102 labelHeight = qMax(rect.height(), labelHeight);
104 width += rect.width();
105 103 }
106 104 height = labelHeight + labelPadding();
107 105 height += base.height();
108 width = qMax(width, base.width());
109 106 sh = QSizeF(width, height);
110 107 break;
111 108 }
@@ -86,14 +86,13 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
86 86 QSizeF base = VerticalAxis::sizeHint(which, constraint);
87 87 QStringList ticksList = m_axis->categoriesLabels();
88 88 qreal width = 0;
89 qreal height = 0;
89 qreal height = 0; // Height is irrelevant for Y axes with interval labels
90 90
91 91 switch (which) {
92 92 case Qt::MinimumSize: {
93 93 QRectF boundingRect = labelBoundingRect(fn, "...");
94 94 width = boundingRect.width() + labelPadding();
95 95 width += base.width();
96 height = qMax(boundingRect.height(), base.height());
97 96 sh = QSizeF(width, height);
98 97 break;
99 98 }
@@ -102,11 +101,9 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
102 101 foreach (const QString& s, ticksList) {
103 102 QRect rect = labelBoundingRect(fn, s);
104 103 labelWidth = qMax(rect.width(), labelWidth);
105 height += rect.height();
106 104 }
107 105 width = labelWidth + labelPadding() + 1;
108 106 width += base.width();
109 height = qMax(height, base.height());
110 107 sh = QSizeF(width, height);
111 108 break;
112 109 }
@@ -90,17 +90,18 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
90 90
91 91 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
92 92 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
93 // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past
94 // first and last ticks. Base width is irrelevant.
93 95 qreal width = 0;
94 96 qreal height = 0;
95 97
96 if(ticksList.empty()){
98 if (ticksList.empty())
97 99 return sh;
98 }
99 100
100 101 switch (which) {
101 102 case Qt::MinimumSize:{
102 103 QRectF boundingRect = labelBoundingRect(fn, "...");
103 width = qMax(boundingRect.width(), base.width());
104 width = boundingRect.width() / 2.0;
104 105 height = boundingRect.height() + labelPadding();
105 106 height += base.height();
106 107 sh = QSizeF(width, height);
@@ -108,14 +109,17 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
108 109 }
109 110 case Qt::PreferredSize: {
110 111 int labelHeight = 0;
112 int firstWidth = -1;
111 113 foreach (const QString& s, ticksList) {
112 114 QRect rect = labelBoundingRect(fn, s);
113 115 labelHeight = qMax(rect.height(), labelHeight);
114 width += rect.width();
116 width = rect.width();
117 if (firstWidth < 0)
118 firstWidth = width;
115 119 }
116 120 height = labelHeight + labelPadding();
117 121 height += base.height();
118 width = qMax(width, base.width());
122 width = qMax(width, qreal(firstWidth)) / 2.0;
119 123 sh = QSizeF(width, height);
120 124 break;
121 125 }
@@ -92,32 +92,35 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
92 92 QSizeF base = VerticalAxis::sizeHint(which, constraint);
93 93 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
94 94 qreal width = 0;
95 // Height of vertical axis sizeHint indicates the maximum distance labels can extend past
96 // first and last ticks. Base height is irrelevant.
95 97 qreal height = 0;
96 98
97
98 if(ticksList.empty()){
99 if (ticksList.empty())
99 100 return sh;
100 }
101 101
102 102 switch (which) {
103 103 case Qt::MinimumSize: {
104 104 QRectF boundingRect = labelBoundingRect(fn, "...");
105 105 width = boundingRect.width() + labelPadding();
106 106 width += base.width();
107 height = qMax(boundingRect.height(), base.height());
107 height = boundingRect.height() / 2.0;
108 108 sh = QSizeF(width, height);
109 109 break;
110 110 }
111 111 case Qt::PreferredSize: {
112 112 int labelWidth = 0;
113 int firstHeight = -1;
113 114 foreach (const QString& s, ticksList) {
114 115 QRect rect = labelBoundingRect(fn, s);
115 116 labelWidth = qMax(rect.width(), labelWidth);
116 height += rect.height();
117 height = rect.height();
118 if (firstHeight < 0)
119 firstHeight = height;
117 120 }
118 121 width = labelWidth + labelPadding() + 2; //two pixels of tolerance
119 122 width += base.width();
120 height = qMax(height, base.height());
123 height = qMax(height, qreal(firstHeight)) / 2.0;
121 124 sh = QSizeF(width, height);
122 125 break;
123 126 }
@@ -99,14 +99,15 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
99 99 ticksList = createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), tickCount, m_axis->labelFormat());
100 100 else
101 101 ticksList.append(QString(" "));
102 // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past
103 // first and last ticks. Base width is irrelevant.
102 104 qreal width = 0;
103 105 qreal height = 0;
104 106
105
106 107 switch (which) {
107 108 case Qt::MinimumSize:{
108 109 QRectF boundingRect = labelBoundingRect(fn, "...");
109 width = qMax(boundingRect.width(), base.width());
110 width = boundingRect.width() / 2.0;
110 111 height = boundingRect.height() + labelPadding();
111 112 height += base.height();
112 113 sh = QSizeF(width, height);
@@ -114,14 +115,17 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
114 115 }
115 116 case Qt::PreferredSize: {
116 117 int labelHeight = 0;
118 int firstWidth = -1;
117 119 foreach (const QString& s, ticksList) {
118 120 QRect rect = labelBoundingRect(fn, s);
119 121 labelHeight = qMax(rect.height(), labelHeight);
120 width += rect.width();
122 width = rect.width();
123 if (firstWidth < 0)
124 firstWidth = width;
121 125 }
122 126 height = labelHeight + labelPadding();
123 127 height += base.height();
124 width = qMax(width, base.width());
128 width = qMax(width, qreal(firstWidth)) / 2.0;
125 129 sh = QSizeF(width, height);
126 130 break;
127 131 }
@@ -100,6 +100,8 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
100 100 else
101 101 ticksList.append(QString(" "));
102 102 qreal width = 0;
103 // Height of vertical axis sizeHint indicates the maximum distance labels can extend past
104 // first and last ticks. Base height is irrelevant.
103 105 qreal height = 0;
104 106
105 107 switch (which) {
@@ -107,20 +109,23 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
107 109 QRectF boundingRect = labelBoundingRect(fn, "...");
108 110 width = boundingRect.width() + labelPadding();
109 111 width += base.width();
110 height = qMax(boundingRect.height(), base.height());
112 height = boundingRect.height() / 2.0;
111 113 sh = QSizeF(width, height);
112 114 break;
113 115 }
114 116 case Qt::PreferredSize: {
115 117 int labelWidth = 0;
118 int firstHeight = -1;
116 119 foreach (const QString& s, ticksList) {
117 120 QRect rect = labelBoundingRect(fn, s);
118 121 labelWidth = qMax(rect.width(), labelWidth);
119 height += rect.height();
122 height = rect.height();
123 if (firstHeight < 0)
124 firstHeight = height;
120 125 }
121 126 width = labelWidth + labelPadding() + 2; //two pixels of tolerance
122 127 width += base.width();
123 height = qMax(height, base.height());
128 height = qMax(height, qreal(firstHeight)) / 2.0;
124 129 sh = QSizeF(width, height);
125 130 break;
126 131 }
@@ -92,14 +92,15 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
92 92
93 93 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
94 94 QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
95 // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past
96 // first and last ticks. Base width is irrelevant.
95 97 qreal width = 0;
96 98 qreal height = 0;
97 99
98
99 100 switch (which) {
100 101 case Qt::MinimumSize: {
101 102 QRectF boundingRect = labelBoundingRect(fn, "...");
102 width = qMax(boundingRect.width(), base.width());
103 width = boundingRect.width() / 2.0;
103 104 height = boundingRect.height() + labelPadding();
104 105 height += base.height();
105 106 sh = QSizeF(width, height);
@@ -107,14 +108,17 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
107 108 }
108 109 case Qt::PreferredSize: {
109 110 int labelHeight = 0;
111 int firstWidth = -1;
110 112 foreach (const QString& s, ticksList) {
111 113 QRect rect = labelBoundingRect(fn, s);
112 114 labelHeight = qMax(rect.height(), labelHeight);
113 width += rect.width();
115 width = rect.width();
116 if (firstWidth < 0)
117 firstWidth = width;
114 118 }
115 119 height = labelHeight + labelPadding();
116 120 height += base.height();
117 width = qMax(width, base.width());
121 width = qMax(width, qreal(firstWidth)) / 2.0;
118 122 sh = QSizeF(width, height);
119 123 break;
120 124 }
@@ -93,6 +93,8 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
93 93 QSizeF base = VerticalAxis::sizeHint(which, constraint);
94 94 QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
95 95 qreal width = 0;
96 // Height of vertical axis sizeHint indicates the maximum distance labels can extend past
97 // first and last ticks. Base height is irrelevant.
96 98 qreal height = 0;
97 99
98 100 switch (which) {
@@ -100,20 +102,23 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
100 102 QRectF boundingRect = labelBoundingRect(fn, "...");
101 103 width = boundingRect.width() + labelPadding();
102 104 width += base.width();
103 height = qMax(boundingRect.height(), base.height());
105 height = boundingRect.height() / 2.0;
104 106 sh = QSizeF(width, height);
105 107 break;
106 108 }
107 109 case Qt::PreferredSize: {
108 110 int labelWidth = 0;
111 int firstHeight = -1;
109 112 foreach (const QString& s, ticksList) {
110 113 QRect rect = labelBoundingRect(fn, s);
111 114 labelWidth = qMax(rect.width(), labelWidth);
112 height += rect.height();
115 height = rect.height();
116 if (firstHeight < 0)
117 firstHeight = height;
113 118 }
114 119 width = labelWidth + labelPadding() + 2; //two pixels of tolerance
115 120 width += base.width();
116 height = qMax(height, base.height());
121 height = qMax(height, qreal(firstHeight)) / 2.0;
117 122 sh = QSizeF(width, height);
118 123 break;
119 124 }
@@ -154,8 +154,8 void VerticalAxis::updateGeometry()
154 154
155 155 //label overlap detection
156 156 if(labelItem->pos().y() + boundingRect.height() > height ||
157 labelItem->pos().y() + boundingRect.height()/2 > gridRect.bottom() ||
158 labelItem->pos().y() + boundingRect.height()/2 < gridRect.top()) {
157 labelItem->pos().y() + boundingRect.height()/2 > axisRect.bottom() ||
158 labelItem->pos().y() + boundingRect.height()/2 < axisRect.top()) {
159 159 labelItem->setVisible(false);
160 160 }
161 161 else {
@@ -109,6 +109,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
109 109 QSizeF minBottom(0,0);
110 110 QSizeF top(0,0);
111 111 QSizeF minTop(0,0);
112 QSizeF labelExtents(0,0);
112 113 int leftCount = 0;
113 114 int rightCount = 0;
114 115 int topCount = 0;
@@ -119,7 +120,6 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
119 120 if (!axis->isVisible())
120 121 continue;
121 122
122
123 123 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
124 124 //this is used to get single thick font size
125 125 QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize);
@@ -130,6 +130,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
130 130 left.setHeight(qMax(left.height(),size.height()));
131 131 minLeft.setWidth(minLeft.width()+minSize.width());
132 132 minLeft.setHeight(qMax(minLeft.height(),minSize.height()));
133 labelExtents.setHeight(qMax(size.height(), labelExtents.height()));
133 134 leftCount++;
134 135 break;
135 136 case Qt::AlignRight:
@@ -137,6 +138,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
137 138 right.setHeight(qMax(right.height(),size.height()));
138 139 minRight.setWidth(minRight.width()+minSize.width());
139 140 minRight.setHeight(qMax(minRight.height(),minSize.height()));
141 labelExtents.setHeight(qMax(size.height(), labelExtents.height()));
140 142 rightCount++;
141 143 break;
142 144 case Qt::AlignTop:
@@ -144,6 +146,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
144 146 top.setHeight(top.height()+size.height());
145 147 minTop.setWidth(qMax(minTop.width(),minSize.width()));
146 148 minTop.setHeight(minTop.height()+minSize.height());
149 labelExtents.setWidth(qMax(size.width(), labelExtents.width()));
147 150 topCount++;
148 151 break;
149 152 case Qt::AlignBottom:
@@ -151,6 +154,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
151 154 bottom.setHeight(bottom.height() + size.height());
152 155 minBottom.setWidth(qMax(minBottom.width(),minSize.width()));
153 156 minBottom.setHeight(minBottom.height() + minSize.height());
157 labelExtents.setWidth(qMax(size.width(), labelExtents.width()));
154 158 bottomCount++;
155 159 break;
156 160 default:
@@ -208,6 +212,12 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
208 212 qreal minHeight = qMax(minLeft.height(),minRight.height()) + 1;
209 213 qreal minWidth = qMax(minTop.width(),minBottom.width()) + 1;
210 214
215 // Ensure that there is enough space for first and last tick labels.
216 left.setWidth(qMax(labelExtents.width(), left.width()));
217 right.setWidth(qMax(labelExtents.width(), right.width()));
218 top.setHeight(qMax(labelExtents.height(), top.height()));
219 bottom.setHeight(qMax(labelExtents.height(), bottom.height()));
220
211 221 QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2));
212 222
213 223 qreal leftOffset = 0;
General Comments 0
You need to be logged in to leave comments. Login now