@@ -111,31 +111,32 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||||
111 | qreal width=0; |
|
111 | qreal width=0; | |
112 | qreal height=0; |
|
112 | qreal height=0; | |
113 |
|
113 | |||
114 |
|
|
114 | switch (which) { | |
115 | case Qt::MinimumSize: |
|
115 | case Qt::MinimumSize: { | |
116 | width = fn.boundingRect("...").width(); |
|
116 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
117 | height = fn.height()+labelPadding(); |
|
117 | width = qMax(boundingRect.width(), base.width()); | |
118 | width=qMax(width,base.width()); |
|
118 | height = boundingRect.height() + labelPadding(); | |
119 | height += base.height(); |
|
119 | height += base.height(); | |
120 | sh = QSizeF(width,height); |
|
120 | sh = QSizeF(width, height); | |
121 | break; |
|
121 | break; | |
|
122 | } | |||
122 | case Qt::PreferredSize:{ |
|
123 | case Qt::PreferredSize:{ | |
123 |
|
124 | int labelHeight = 0; | ||
124 |
for ( |
|
125 | foreach (const QString& s, ticksList) { | |
125 | { |
|
126 | QRect rect = labelBoundingRect(fn, s); | |
126 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
127 | labelHeight = qMax(rect.height(), labelHeight); | |
127 | width += rect.width(); |
|
128 | width += rect.width(); | |
128 | } |
|
129 | } | |
129 |
height = |
|
130 | height = labelHeight + labelPadding(); | |
130 | width = qMax(width,base.width()); |
|
|||
131 | height += base.height(); |
|
131 | height += base.height(); | |
132 |
|
|
132 | width = qMax(width, base.width()); | |
|
133 | sh = QSizeF(width, height); | |||
133 | break; |
|
134 | break; | |
134 | } |
|
135 | } | |
135 | default: |
|
136 | default: | |
136 | break; |
|
137 | break; | |
137 |
|
|
138 | } | |
138 |
|
|
139 | return sh; | |
139 | } |
|
140 | } | |
140 |
|
141 | |||
141 | #include "moc_chartbarcategoryaxisx_p.cpp" |
|
142 | #include "moc_chartbarcategoryaxisx_p.cpp" |
@@ -109,27 +109,30 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||||
109 | qreal width=0; |
|
109 | qreal width=0; | |
110 | qreal height=0; |
|
110 | qreal height=0; | |
111 |
|
111 | |||
112 |
|
|
112 | switch (which) { | |
113 | case Qt::MinimumSize: |
|
113 | case Qt::MinimumSize: { | |
114 | width = fn.boundingRect("...").width() + labelPadding(); |
|
114 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
115 | height = fn.height(); |
|
115 | width = boundingRect.width() + labelPadding(); | |
116 | width+=base.width(); |
|
116 | width += base.width(); | |
117 |
if(base.width()>0) |
|
117 | if (base.width() > 0) | |
118 | height=qMax(height,base.height()); |
|
118 | width += labelPadding(); | |
119 | sh = QSizeF(width,height); |
|
119 | height = qMax(boundingRect.height(), base.height()); | |
|
120 | sh = QSizeF(width, height); | |||
120 | break; |
|
121 | break; | |
|
122 | } | |||
121 | case Qt::PreferredSize:{ |
|
123 | case Qt::PreferredSize:{ | |
122 |
|
124 | int labelWidth = 0; | ||
123 |
for ( |
|
125 | foreach (const QString& s, ticksList) { | |
124 | { |
|
126 | QRect rect = labelBoundingRect(fn, s); | |
125 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
127 | labelWidth = qMax(rect.width(), labelWidth); | |
126 | height+=rect.height(); |
|
128 | height += rect.height(); | |
127 | width=qMax(rect.width()+labelPadding(),width); //one pixel torelance |
|
|||
128 | } |
|
129 | } | |
129 | height=qMax(height,base.height()); |
|
130 | width = labelWidth + labelPadding() + 1; | |
130 | width+=base.width(); |
|
131 | width += base.width(); | |
131 |
if(base.width()>0) |
|
132 | if (base.width() > 0) | |
132 |
|
|
133 | width += labelPadding(); | |
|
134 | height = qMax(height, base.height()); | |||
|
135 | sh = QSizeF(width, height); | |||
133 | break; |
|
136 | break; | |
134 | } |
|
137 | } | |
135 | default: |
|
138 | default: |
@@ -90,22 +90,24 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
90 | qreal height = 0; |
|
90 | qreal height = 0; | |
91 |
|
91 | |||
92 | switch (which) { |
|
92 | switch (which) { | |
93 | case Qt::MinimumSize: |
|
93 | case Qt::MinimumSize: { | |
94 | width = fn.boundingRect("...").width(); |
|
94 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
95 | height = fn.height() + labelPadding(); |
|
95 | width = qMax(boundingRect.width(), base.width()); | |
96 | width = qMax(width, base.width()); |
|
96 | height = boundingRect.height() + labelPadding(); | |
97 | height += base.height(); |
|
97 | height += base.height(); | |
98 | sh = QSizeF(width, height); |
|
98 | sh = QSizeF(width, height); | |
99 | break; |
|
99 | break; | |
|
100 | } | |||
100 | case Qt::PreferredSize: { |
|
101 | case Qt::PreferredSize: { | |
101 |
|
102 | int labelHeight = 0; | ||
102 | for (int i = 0; i < ticksList.size(); ++i) { |
|
103 | foreach (const QString& s, ticksList) { | |
103 |
QRect |
|
104 | QRect rect = labelBoundingRect(fn, s); | |
|
105 | labelHeight = qMax(rect.height(), labelHeight); | |||
104 | width += rect.width(); |
|
106 | width += rect.width(); | |
105 | height = qMax(rect.height() + labelPadding(), height); |
|
|||
106 | } |
|
107 | } | |
107 | width = qMax(width, base.width()); |
|
108 | height = labelHeight + labelPadding(); | |
108 | height += base.height(); |
|
109 | height += base.height(); | |
|
110 | width = qMax(width, base.width()); | |||
109 | sh = QSizeF(width, height); |
|
111 | sh = QSizeF(width, height); | |
110 | break; |
|
112 | break; | |
111 | } |
|
113 | } |
@@ -90,22 +90,24 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
90 | qreal height = 0; |
|
90 | qreal height = 0; | |
91 |
|
91 | |||
92 | switch (which) { |
|
92 | switch (which) { | |
93 | case Qt::MinimumSize: |
|
93 | case Qt::MinimumSize: { | |
94 | width = fn.boundingRect("...").width() + labelPadding(); |
|
94 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
95 | height = fn.height(); |
|
95 | width = boundingRect.width() + labelPadding(); | |
96 | width += base.width(); |
|
96 | width += base.width(); | |
97 |
height = qMax(height, base.height()); |
|
97 | height = qMax(boundingRect.height(), base.height()); | |
98 | sh = QSizeF(width, height); |
|
98 | sh = QSizeF(width, height); | |
99 | break; |
|
99 | break; | |
|
100 | } | |||
100 | case Qt::PreferredSize: { |
|
101 | case Qt::PreferredSize: { | |
101 |
|
102 | int labelWidth = 0; | ||
102 | for (int i = 0; i < ticksList.size(); ++i) { |
|
103 | foreach (const QString& s, ticksList) { | |
103 |
QRect |
|
104 | QRect rect = labelBoundingRect(fn, s); | |
104 |
|
|
105 | labelWidth = qMax(rect.width(), labelWidth); | |
105 | height += rect.height(); |
|
106 | height += rect.height(); | |
106 | } |
|
107 | } | |
107 | height = qMax(height, base.height()); |
|
108 | width = labelWidth + labelPadding() + 1; | |
108 | width += base.width(); |
|
109 | width += base.width(); | |
|
110 | height = qMax(height, base.height()); | |||
109 | sh = QSizeF(width, height); |
|
111 | sh = QSizeF(width, height); | |
110 | break; |
|
112 | break; | |
111 | } |
|
113 | } |
@@ -527,6 +527,20 QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const | |||||
527 | return labels; |
|
527 | return labels; | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
|
530 | QRect ChartAxis::labelBoundingRect(const QFontMetrics &fn, const QString &label) const | |||
|
531 | { | |||
|
532 | QRect boundingRect = fn.boundingRect(label); | |||
|
533 | ||||
|
534 | // Take label rotation into account | |||
|
535 | if (m_labelsAngle) { | |||
|
536 | QTransform transform; | |||
|
537 | transform.rotate(m_labelsAngle); | |||
|
538 | boundingRect = transform.mapRect(boundingRect); | |||
|
539 | } | |||
|
540 | ||||
|
541 | return boundingRect; | |||
|
542 | } | |||
|
543 | ||||
530 | #include "moc_chartaxis_p.cpp" |
|
544 | #include "moc_chartaxis_p.cpp" | |
531 |
|
545 | |||
532 | QTCOMMERCIALCHART_END_NAMESPACE |
|
546 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -109,6 +109,7 protected: | |||||
109 | QFont font() const; |
|
109 | QFont font() const; | |
110 | qreal min() const; |
|
110 | qreal min() const; | |
111 | qreal max() const; |
|
111 | qreal max() const; | |
|
112 | QRect labelBoundingRect(const QFontMetrics &fn, const QString &label) const; | |||
112 |
|
113 | |||
113 | //handlers |
|
114 | //handlers | |
114 | public Q_SLOTS: |
|
115 | public Q_SLOTS: |
@@ -99,21 +99,24 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
99 |
|
99 | |||
100 | switch (which) { |
|
100 | switch (which) { | |
101 | case Qt::MinimumSize:{ |
|
101 | case Qt::MinimumSize:{ | |
102 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
102 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
103 | width = fn.averageCharWidth() * count; |
|
103 | width = qMax(boundingRect.width(), base.width()); | |
104 |
height = |
|
104 | height = boundingRect.height() + labelPadding(); | |
105 | width = qMax(width,base.width()); |
|
|||
106 | height += base.height(); |
|
105 | height += base.height(); | |
107 | sh = QSizeF(width,height); |
|
106 | sh = QSizeF(width, height); | |
108 | break; |
|
107 | break; | |
109 | } |
|
108 | } | |
110 | case Qt::PreferredSize: { |
|
109 | case Qt::PreferredSize: { | |
111 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
110 | int labelHeight = 0; | |
112 | width=fn.averageCharWidth() * count; |
|
111 | foreach (const QString& s, ticksList) { | |
113 | height=fn.height()+labelPadding(); |
|
112 | QRect rect = labelBoundingRect(fn, s); | |
114 | width=qMax(width,base.width()); |
|
113 | labelHeight = qMax(rect.height(), labelHeight); | |
115 | height+=base.height(); |
|
114 | width += rect.width(); | |
116 | sh = QSizeF(width,height); |
|
115 | } | |
|
116 | height = labelHeight + labelPadding(); | |||
|
117 | height += base.height(); | |||
|
118 | width = qMax(width, base.width()); | |||
|
119 | sh = QSizeF(width, height); | |||
117 | break; |
|
120 | break; | |
118 | } |
|
121 | } | |
119 | default: |
|
122 | default: |
@@ -99,28 +99,26 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
99 | return sh; |
|
99 | return sh; | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | int labelWidth = 0; |
|
|||
103 |
|
||||
104 | foreach(const QString& s, ticksList) |
|
|||
105 | { |
|
|||
106 | labelWidth=qMax(fn.width(s),labelWidth); |
|
|||
107 | } |
|
|||
108 |
|
||||
109 | switch (which) { |
|
102 | switch (which) { | |
110 | case Qt::MinimumSize: { |
|
103 | case Qt::MinimumSize: { | |
111 | width = fn.boundingRect("...").width() + labelPadding(); |
|
104 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
|
105 | width = boundingRect.width() + labelPadding(); | |||
112 | width += base.width(); |
|
106 | width += base.width(); | |
113 |
height = |
|
107 | height = qMax(boundingRect.height(), base.height()); | |
114 | height = qMax(height,base.height()); |
|
108 | sh = QSizeF(width, height); | |
115 | sh = QSizeF(width,height); |
|
|||
116 | break; |
|
109 | break; | |
117 | } |
|
110 | } | |
118 | case Qt::PreferredSize: { |
|
111 | case Qt::PreferredSize: { | |
|
112 | int labelWidth = 0; | |||
|
113 | foreach (const QString& s, ticksList) { | |||
|
114 | QRect rect = labelBoundingRect(fn, s); | |||
|
115 | labelWidth = qMax(rect.width(), labelWidth); | |||
|
116 | height += rect.height(); | |||
|
117 | } | |||
119 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance |
|
118 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance | |
120 | width += base.width(); |
|
119 | width += base.width(); | |
121 |
height = |
|
120 | height = qMax(height, base.height()); | |
122 | height = qMax(height,base.height()); |
|
121 | sh = QSizeF(width, height); | |
123 | sh = QSizeF(width,height); |
|
|||
124 | break; |
|
122 | break; | |
125 | } |
|
123 | } | |
126 | default: |
|
124 | default: |
@@ -105,35 +105,32 void HorizontalAxis::updateGeometry() | |||||
105 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); |
|
105 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); | |
106 |
|
106 | |||
107 | //label text wrapping |
|
107 | //label text wrapping | |
108 | if(intervalAxis()&& i+1!=layout.size()) { |
|
108 | QString text = labelList.at(i); | |
109 | //wrapping in case of interval axis |
|
109 | QRectF boundingRect = labelBoundingRect(fn, text); | |
110 | const qreal delta = layout[i+1] - layout[i]; |
|
110 | qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - title->boundingRect().height(); | |
111 | QString text = labelList.at(i); |
|
111 | if (boundingRect.height() > size) { | |
112 | if (fn.boundingRect(text).width() + 1 > delta ) |
|
112 | QString label = text + "..."; | |
113 | { |
|
113 | while (boundingRect.height() >= size && label.length() > 3) { | |
114 | QString label = text + "..."; |
|
|||
115 | while (fn.boundingRect(label).width() >= delta && label.length() > 3) |
|
|||
116 | label.remove(label.length() - 4, 1); |
|
114 | label.remove(label.length() - 4, 1); | |
117 |
|
|
115 | boundingRect = labelBoundingRect(fn, label); | |
118 | } |
|
|||
119 | else { |
|
|||
120 | labelItem->setText(text); |
|
|||
121 | } |
|
116 | } | |
122 | }else{ |
|
117 | labelItem->setText(label); | |
123 | labelItem->setText(labelList.at(i)); |
|
118 | } else { | |
|
119 | labelItem->setText(text); | |||
124 | } |
|
120 | } | |
125 |
|
121 | |||
126 | //label transformation origin point |
|
122 | //label transformation origin point | |
127 | const QRectF& rect = labelItem->boundingRect(); |
|
123 | const QRectF& rect = labelItem->boundingRect(); | |
128 | QPointF center = rect.center(); |
|
124 | QPointF center = rect.center(); | |
129 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
125 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
126 | int heightDiff = rect.height() - boundingRect.height(); | |||
130 |
|
127 | |||
131 | //ticks and label position |
|
128 | //ticks and label position | |
132 | if (alignment() == Qt::AlignTop) { |
|
129 | if (alignment() == Qt::AlignTop) { | |
133 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding()); |
|
130 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2) - labelPadding()); | |
134 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); |
|
131 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); | |
135 | } else if (alignment() == Qt::AlignBottom) { |
|
132 | } else if (alignment() == Qt::AlignBottom) { | |
136 | labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding()); |
|
133 | labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2) + labelPadding()); | |
137 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); |
|
134 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); | |
138 | } |
|
135 | } | |
139 |
|
136 | |||
@@ -146,11 +143,11 void HorizontalAxis::updateGeometry() | |||||
146 | //label overlap detection |
|
143 | //label overlap detection | |
147 | if(labelItem->pos().x() < width || |
|
144 | if(labelItem->pos().x() < width || | |
148 | labelItem->pos().x() < axisRect.left() || |
|
145 | labelItem->pos().x() < axisRect.left() || | |
149 |
labelItem->pos().x() + |
|
146 | labelItem->pos().x() + boundingRect.width() -1 > axisRect.right()){ | |
150 | labelItem->setVisible(false); |
|
147 | labelItem->setVisible(false); | |
151 | } else { |
|
148 | } else { | |
152 | labelItem->setVisible(true); |
|
149 | labelItem->setVisible(true); | |
153 |
width= |
|
150 | width = boundingRect.width() + labelItem->pos().x(); | |
154 | } |
|
151 | } | |
155 |
|
152 | |||
156 | //shades |
|
153 | //shades |
@@ -105,21 +105,24 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
105 |
|
105 | |||
106 | switch (which) { |
|
106 | switch (which) { | |
107 | case Qt::MinimumSize:{ |
|
107 | case Qt::MinimumSize:{ | |
108 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
108 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
109 | width = fn.averageCharWidth() * count; |
|
109 | width = qMax(boundingRect.width(), base.width()); | |
110 |
height = |
|
110 | height = boundingRect.height() + labelPadding(); | |
111 | width = qMax(width,base.width()); |
|
|||
112 | height += base.height(); |
|
111 | height += base.height(); | |
113 | sh = QSizeF(width,height); |
|
112 | sh = QSizeF(width, height); | |
114 | break; |
|
113 | break; | |
115 | } |
|
114 | } | |
116 | case Qt::PreferredSize: { |
|
115 | case Qt::PreferredSize: { | |
117 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
116 | int labelHeight = 0; | |
118 | width=fn.averageCharWidth() * count; |
|
117 | foreach (const QString& s, ticksList) { | |
119 | height=fn.height()+labelPadding(); |
|
118 | QRect rect = labelBoundingRect(fn, s); | |
120 | width=qMax(width,base.width()); |
|
119 | labelHeight = qMax(rect.height(), labelHeight); | |
121 | height+=base.height(); |
|
120 | width += rect.width(); | |
122 | sh = QSizeF(width,height); |
|
121 | } | |
|
122 | height = labelHeight + labelPadding(); | |||
|
123 | height += base.height(); | |||
|
124 | width = qMax(width, base.width()); | |||
|
125 | sh = QSizeF(width, height); | |||
123 | break; |
|
126 | break; | |
124 | } |
|
127 | } | |
125 | default: |
|
128 | default: |
@@ -102,29 +102,26 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
102 | qreal width = 0; |
|
102 | qreal width = 0; | |
103 | qreal height = 0; |
|
103 | qreal height = 0; | |
104 |
|
104 | |||
105 |
|
||||
106 | int labelWidth = 0; |
|
|||
107 |
|
||||
108 | foreach(const QString& s, ticksList) |
|
|||
109 | { |
|
|||
110 | labelWidth=qMax(fn.width(s),labelWidth); |
|
|||
111 | } |
|
|||
112 |
|
||||
113 | switch (which) { |
|
105 | switch (which) { | |
114 | case Qt::MinimumSize: { |
|
106 | case Qt::MinimumSize: { | |
115 | width = fn.boundingRect("...").width() + labelPadding(); |
|
107 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
|
108 | width = boundingRect.width() + labelPadding(); | |||
116 | width += base.width(); |
|
109 | width += base.width(); | |
117 |
height = |
|
110 | height = qMax(boundingRect.height(), base.height()); | |
118 | height = qMax(height,base.height()); |
|
111 | sh = QSizeF(width, height); | |
119 | sh = QSizeF(width,height); |
|
|||
120 | break; |
|
112 | break; | |
121 | } |
|
113 | } | |
122 | case Qt::PreferredSize: { |
|
114 | case Qt::PreferredSize: { | |
|
115 | int labelWidth = 0; | |||
|
116 | foreach (const QString& s, ticksList) { | |||
|
117 | QRect rect = labelBoundingRect(fn, s); | |||
|
118 | labelWidth = qMax(rect.width(), labelWidth); | |||
|
119 | height += rect.height(); | |||
|
120 | } | |||
123 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance |
|
121 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance | |
124 | width += base.width(); |
|
122 | width += base.width(); | |
125 | height = fn.height() * ticksList.count(); |
|
123 | height = qMax(height, base.height()); | |
126 | height = qMax(height,base.height()); |
|
124 | sh = QSizeF(width, height); | |
127 | sh = QSizeF(width,height); |
|
|||
128 | break; |
|
125 | break; | |
129 | } |
|
126 | } | |
130 | default: |
|
127 | default: |
@@ -98,33 +98,29 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
98 |
|
98 | |||
99 | switch (which) { |
|
99 | switch (which) { | |
100 | case Qt::MinimumSize: { |
|
100 | case Qt::MinimumSize: { | |
101 | if(!ticksList.empty()) { |
|
101 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
102 | foreach(QString label,ticksList) { |
|
102 | width = qMax(boundingRect.width(), base.width()); | |
103 | width = qMax(qreal(fn.boundingRect(label).width()),width); |
|
103 | height = boundingRect.height() + labelPadding(); | |
104 | } |
|
|||
105 | } |
|
|||
106 | height = fn.height() + labelPadding(); |
|
|||
107 | width = qMax(width,base.width()); |
|
|||
108 | height += base.height(); |
|
104 | height += base.height(); | |
109 | sh = QSizeF(width,height); |
|
105 | sh = QSizeF(width, height); | |
110 | break; |
|
106 | break; | |
111 | } |
|
107 | } | |
112 | case Qt::PreferredSize: { |
|
108 | case Qt::PreferredSize: { | |
113 | if(!ticksList.empty()) { |
|
109 | int labelHeight = 0; | |
114 |
|
|
110 | foreach (const QString& s, ticksList) { | |
115 |
|
|
111 | QRect rect = labelBoundingRect(fn, s); | |
116 | } |
|
112 | labelHeight = qMax(rect.height(), labelHeight); | |
|
113 | width += rect.width(); | |||
117 | } |
|
114 | } | |
118 |
height= |
|
115 | height = labelHeight + labelPadding(); | |
119 |
|
|
116 | height += base.height(); | |
120 |
|
|
117 | width = qMax(width, base.width()); | |
121 | sh = QSizeF(width,height); |
|
118 | sh = QSizeF(width, height); | |
122 | break; |
|
119 | break; | |
123 | } |
|
120 | } | |
124 | default: |
|
121 | default: | |
125 | break; |
|
122 | break; | |
126 | } |
|
123 | } | |
127 |
|
||||
128 | return sh; |
|
124 | return sh; | |
129 | } |
|
125 | } | |
130 |
|
126 |
@@ -95,29 +95,26 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||||
95 | qreal width = 0; |
|
95 | qreal width = 0; | |
96 | qreal height = 0; |
|
96 | qreal height = 0; | |
97 |
|
97 | |||
98 | int labelWidth = 0; |
|
|||
99 |
|
||||
100 | foreach(const QString& s, ticksList) |
|
|||
101 | { |
|
|||
102 | labelWidth=qMax(fn.width(s),labelWidth); |
|
|||
103 | } |
|
|||
104 |
|
||||
105 | switch (which) { |
|
98 | switch (which) { | |
106 | case Qt::MinimumSize: { |
|
99 | case Qt::MinimumSize: { | |
107 | width = fn.boundingRect("...").width() + labelPadding(); |
|
100 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
|
101 | width = boundingRect.width() + labelPadding(); | |||
108 | width += base.width(); |
|
102 | width += base.width(); | |
109 |
height = |
|
103 | height = qMax(boundingRect.height(), base.height()); | |
110 | height = qMax(height,base.height()); |
|
104 | sh = QSizeF(width, height); | |
111 | sh = QSizeF(width,height); |
|
|||
112 | break; |
|
105 | break; | |
113 | } |
|
106 | } | |
114 | case Qt::PreferredSize: |
|
107 | case Qt::PreferredSize: { | |
115 | { |
|
108 | int labelWidth = 0; | |
|
109 | foreach (const QString& s, ticksList) { | |||
|
110 | QRect rect = labelBoundingRect(fn, s); | |||
|
111 | labelWidth = qMax(rect.width(), labelWidth); | |||
|
112 | height += rect.height(); | |||
|
113 | } | |||
116 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance |
|
114 | width = labelWidth + labelPadding() + 2; //two pixels of tolerance | |
117 | width += base.width(); |
|
115 | width += base.width(); | |
118 | height = fn.height() * ticksList.count(); |
|
116 | height = qMax(height, base.height()); | |
119 | height = qMax(height,base.height()); |
|
117 | sh = QSizeF(width, height); | |
120 | sh = QSizeF(width,height); |
|
|||
121 | break; |
|
118 | break; | |
122 | } |
|
119 | } | |
123 | default: |
|
120 | default: |
@@ -113,27 +113,33 void VerticalAxis::updateGeometry() | |||||
113 |
|
113 | |||
114 | //label text wrapping |
|
114 | //label text wrapping | |
115 | QString text = labelList.at(i); |
|
115 | QString text = labelList.at(i); | |
|
116 | QRectF boundingRect = labelBoundingRect(fn, text); | |||
|
117 | ||||
116 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height(); |
|
118 | qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height(); | |
117 |
if ( |
|
119 | if (boundingRect.width() > size) { | |
118 | QString label = text + "..."; |
|
120 | QString label = text + "..."; | |
119 |
while ( |
|
121 | while (boundingRect.width() > size && label.length() > 3) { | |
120 | label.remove(label.length() - 4, 1); |
|
122 | label.remove(label.length() - 4, 1); | |
|
123 | boundingRect = labelBoundingRect(fn, label); | |||
|
124 | } | |||
121 | labelItem->setText(label); |
|
125 | labelItem->setText(label); | |
122 | } else { |
|
126 | } else { | |
123 | labelItem->setText(text); |
|
127 | labelItem->setText(text); | |
124 | } |
|
128 | } | |
|
129 | ||||
125 | //label transformation origin point |
|
130 | //label transformation origin point | |
126 | const QRectF &rect = labelItem->boundingRect(); |
|
131 | const QRectF &rect = labelItem->boundingRect(); | |
127 |
|
132 | |||
128 | QPointF center = rect.center(); |
|
133 | QPointF center = rect.center(); | |
129 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
134 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
135 | int widthDiff = rect.width() - boundingRect.width(); | |||
130 |
|
136 | |||
131 | //ticks and label position |
|
137 | //ticks and label position | |
132 | if (alignment() == Qt::AlignLeft) { |
|
138 | if (alignment() == Qt::AlignLeft) { | |
133 |
labelItem->setPos(axisRect.right() - rect.width() - labelPadding() |
|
139 | labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2) - labelPadding(), layout[i] - center.y()); | |
134 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); |
|
140 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); | |
135 | } else if (alignment() == Qt::AlignRight) { |
|
141 | } else if (alignment() == Qt::AlignRight) { | |
136 | labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y()); |
|
142 | labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2), layout[i] - center.y()); | |
137 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); |
|
143 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); | |
138 | } |
|
144 | } | |
139 |
|
145 | |||
@@ -144,9 +150,9 void VerticalAxis::updateGeometry() | |||||
144 | } |
|
150 | } | |
145 |
|
151 | |||
146 | //label overlap detection |
|
152 | //label overlap detection | |
147 |
if(labelItem->pos().y() + |
|
153 | if(labelItem->pos().y() + boundingRect.height() > height || | |
148 |
labelItem->pos().y() + |
|
154 | labelItem->pos().y() + boundingRect.height()/2 > gridRect.bottom() || | |
149 |
labelItem->pos().y() + |
|
155 | labelItem->pos().y() + boundingRect.height()/2 < gridRect.top()) { | |
150 | labelItem->setVisible(false); |
|
156 | labelItem->setVisible(false); | |
151 | } |
|
157 | } | |
152 | else { |
|
158 | else { |
General Comments 0
You need to be logged in to leave comments.
Login now