##// END OF EJS Templates
Change sizeHint of vertical axis, caculate width based on each label
Michal Klocek -
r2336:03ff7a7fe0a8
parent child
Show More
@@ -1,129 +1,128
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdatetimeaxisx_p.h"
21 #include "chartdatetimeaxisx_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qdatetimeaxis.h"
23 #include "qdatetimeaxis.h"
24 #include "chartlayout_p.h"
24 #include "chartlayout_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDateTime>
26 #include <QDateTime>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <qmath.h>
28 #include <qmath.h>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem* item)
32 ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem* item)
33 : HorizontalAxis(axis, item),
33 : HorizontalAxis(axis, item),
34 m_axis(axis)
34 m_axis(axis)
35 {
35 {
36 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
36 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
37 QObject::connect(m_axis,SIGNAL(formatChanged(QString)),this, SLOT(handleFormatChanged(QString)));
37 QObject::connect(m_axis,SIGNAL(formatChanged(QString)),this, SLOT(handleFormatChanged(QString)));
38 }
38 }
39
39
40 ChartDateTimeAxisX::~ChartDateTimeAxisX()
40 ChartDateTimeAxisX::~ChartDateTimeAxisX()
41 {
41 {
42 }
42 }
43
43
44 QVector<qreal> ChartDateTimeAxisX::calculateLayout() const
44 QVector<qreal> ChartDateTimeAxisX::calculateLayout() const
45 {
45 {
46 int tickCount = m_axis->tickCount();
46 int tickCount = m_axis->tickCount();
47
47
48 Q_ASSERT(tickCount >= 2);
48 Q_ASSERT(tickCount >= 2);
49
49
50 QVector<qreal> points;
50 QVector<qreal> points;
51 points.resize(tickCount);
51 points.resize(tickCount);
52 const QRectF &gridRect = gridGeometry();
52 const QRectF &gridRect = gridGeometry();
53 const qreal deltaX = gridRect.width() / (tickCount - 1);
53 const qreal deltaX = gridRect.width() / (tickCount - 1);
54 for (int i = 0; i < tickCount; ++i) {
54 for (int i = 0; i < tickCount; ++i) {
55 int x = i * deltaX + gridRect.left();
55 int x = i * deltaX + gridRect.left();
56 points[i] = x;
56 points[i] = x;
57 }
57 }
58 return points;
58 return points;
59 }
59 }
60
60
61 void ChartDateTimeAxisX::updateGeometry()
61 void ChartDateTimeAxisX::updateGeometry()
62 {
62 {
63 const QVector<qreal>& layout = ChartAxis::layout();
63 const QVector<qreal>& layout = ChartAxis::layout();
64 if (layout.isEmpty())
64 if (layout.isEmpty())
65 return;
65 return;
66 setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format()));
66 setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format()));
67 HorizontalAxis::updateGeometry();
67 HorizontalAxis::updateGeometry();
68 }
68 }
69
69
70 void ChartDateTimeAxisX::handleTickCountChanged(int tick)
70 void ChartDateTimeAxisX::handleTickCountChanged(int tick)
71 {
71 {
72 Q_UNUSED(tick)
72 Q_UNUSED(tick)
73 QGraphicsLayoutItem::updateGeometry();
73 QGraphicsLayoutItem::updateGeometry();
74 if(presenter()) presenter()->layout()->invalidate();
74 if(presenter()) presenter()->layout()->invalidate();
75 }
75 }
76
76
77 void ChartDateTimeAxisX::handleFormatChanged(const QString &format)
77 void ChartDateTimeAxisX::handleFormatChanged(const QString &format)
78 {
78 {
79 Q_UNUSED(format);
79 Q_UNUSED(format);
80 QGraphicsLayoutItem::updateGeometry();
80 QGraphicsLayoutItem::updateGeometry();
81 if(presenter()) presenter()->layout()->invalidate();
81 if(presenter()) presenter()->layout()->invalidate();
82 }
82 }
83
83
84 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
84 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
85 {
85 {
86 Q_UNUSED(constraint)
86 Q_UNUSED(constraint)
87
87
88 QFontMetrics fn(font());
88 QFontMetrics fn(font());
89 QSizeF sh;
89 QSizeF sh;
90
90
91 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
91 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
92 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
92 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
93 qreal width = 0;
93 qreal width = 0;
94 qreal height = 0;
94 qreal height = 0;
95
95
96 if(ticksList.empty()){
96 if(ticksList.empty()){
97 return sh;
97 return sh;
98 }
98 }
99
99
100
101 switch (which) {
100 switch (which) {
102 case Qt::MinimumSize:{
101 case Qt::MinimumSize:{
103 int count = qMax(ticksList.last().count(),ticksList.first().count());
102 int count = qMax(ticksList.last().count(),ticksList.first().count());
104 width = fn.averageCharWidth() * count;
103 width = fn.averageCharWidth() * count;
105 height = fn.height() + labelPadding();
104 height = fn.height() + labelPadding();
106 width = qMax(width,base.width());
105 width = qMax(width,base.width());
107 height += base.height();
106 height += base.height();
108 sh = QSizeF(width,height);
107 sh = QSizeF(width,height);
109 break;
108 break;
110 }
109 }
111 case Qt::PreferredSize: {
110 case Qt::PreferredSize: {
112 int count = qMax(ticksList.last().count(),ticksList.first().count());
111 int count = qMax(ticksList.last().count(),ticksList.first().count());
113 width=fn.averageCharWidth() * count;
112 width=fn.averageCharWidth() * count;
114 height=fn.height()+labelPadding();
113 height=fn.height()+labelPadding();
115 width=qMax(width,base.width());
114 width=qMax(width,base.width());
116 height+=base.height();
115 height+=base.height();
117 sh = QSizeF(width,height);
116 sh = QSizeF(width,height);
118 break;
117 break;
119 }
118 }
120 default:
119 default:
121 break;
120 break;
122 }
121 }
123
122
124 return sh;
123 return sh;
125 }
124 }
126
125
127 #include "moc_chartdatetimeaxisx_p.cpp"
126 #include "moc_chartdatetimeaxisx_p.cpp"
128
127
129 QTCOMMERCIALCHART_END_NAMESPACE
128 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,128 +1,135
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdatetimeaxisy_p.h"
21 #include "chartdatetimeaxisy_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qdatetimeaxis.h"
23 #include "qdatetimeaxis.h"
24 #include "chartlayout_p.h"
24 #include "chartlayout_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <QDateTime>
27 #include <QDateTime>
28 #include <qmath.h>
28 #include <qmath.h>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem* item)
32 ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem* item)
33 : VerticalAxis(axis, item),
33 : VerticalAxis(axis, item),
34 m_axis(axis)
34 m_axis(axis)
35 {
35 {
36 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
36 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
37 QObject::connect(m_axis,SIGNAL(formatChanged(QString)),this, SLOT(handleFormatChanged(QString)));
37 QObject::connect(m_axis,SIGNAL(formatChanged(QString)),this, SLOT(handleFormatChanged(QString)));
38 }
38 }
39
39
40 ChartDateTimeAxisY::~ChartDateTimeAxisY()
40 ChartDateTimeAxisY::~ChartDateTimeAxisY()
41 {
41 {
42 }
42 }
43
43
44 QVector<qreal> ChartDateTimeAxisY::calculateLayout() const
44 QVector<qreal> ChartDateTimeAxisY::calculateLayout() const
45 {
45 {
46 int tickCount = m_axis->tickCount();
46 int tickCount = m_axis->tickCount();
47
47
48 Q_ASSERT(tickCount >= 2);
48 Q_ASSERT(tickCount >= 2);
49
49
50 QVector<qreal> points;
50 QVector<qreal> points;
51 points.resize(tickCount);
51 points.resize(tickCount);
52 const QRectF &gridRect = gridGeometry();
52 const QRectF &gridRect = gridGeometry();
53 const qreal deltaY = gridRect.height() / (tickCount - 1);
53 const qreal deltaY = gridRect.height() / (tickCount - 1);
54 for (int i = 0; i < tickCount; ++i) {
54 for (int i = 0; i < tickCount; ++i) {
55 int y = i * -deltaY + gridRect.bottom();
55 int y = i * -deltaY + gridRect.bottom();
56 points[i] = y;
56 points[i] = y;
57 }
57 }
58
58
59 return points;
59 return points;
60 }
60 }
61
61
62 void ChartDateTimeAxisY::updateGeometry()
62 void ChartDateTimeAxisY::updateGeometry()
63 {
63 {
64 const QVector<qreal> &layout = ChartAxis::layout();
64 const QVector<qreal> &layout = ChartAxis::layout();
65 if (layout.isEmpty())
65 if (layout.isEmpty())
66 return;
66 return;
67 setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format()));
67 setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format()));
68 VerticalAxis::updateGeometry();
68 VerticalAxis::updateGeometry();
69 }
69 }
70
70
71 void ChartDateTimeAxisY::handleTickCountChanged(int tick)
71 void ChartDateTimeAxisY::handleTickCountChanged(int tick)
72 {
72 {
73 Q_UNUSED(tick)
73 Q_UNUSED(tick)
74 QGraphicsLayoutItem::updateGeometry();
74 QGraphicsLayoutItem::updateGeometry();
75 if(presenter()) presenter()->layout()->invalidate();
75 if(presenter()) presenter()->layout()->invalidate();
76 }
76 }
77
77
78 void ChartDateTimeAxisY::handleFormatChanged(const QString &format)
78 void ChartDateTimeAxisY::handleFormatChanged(const QString &format)
79 {
79 {
80 Q_UNUSED(format);
80 Q_UNUSED(format);
81 QGraphicsLayoutItem::updateGeometry();
81 QGraphicsLayoutItem::updateGeometry();
82 if(presenter()) presenter()->layout()->invalidate();
82 if(presenter()) presenter()->layout()->invalidate();
83 }
83 }
84
84
85 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
85 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
86 {
86 {
87 Q_UNUSED(constraint)
87 Q_UNUSED(constraint)
88
88
89 QFontMetrics fn(font());
89 QFontMetrics fn(font());
90 QSizeF sh;
90 QSizeF sh;
91
91
92 QSizeF base = VerticalAxis::sizeHint(which, constraint);
92 QSizeF base = VerticalAxis::sizeHint(which, constraint);
93 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
93 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
94 qreal width = 0;
94 qreal width = 0;
95 qreal height = 0;
95 qreal height = 0;
96
96
97
97 if(ticksList.empty()){
98 if(ticksList.empty()){
98 return sh;
99 return sh;
99 }
100 }
100
101
102 int labelWidth = 0;
103
104 foreach(const QString& s, ticksList)
105 {
106 labelWidth=qMax(fn.width(s),labelWidth);
107 }
108
101 switch (which) {
109 switch (which) {
102 case Qt::MinimumSize: {
110 case Qt::MinimumSize: {
103 width = fn.boundingRect("...").width() + labelPadding();
111 width = fn.boundingRect("...").width() + labelPadding();
104 width += base.width();
112 width += base.width();
105 height = fn.height();
113 height = fn.height();
106 height = qMax(height,base.height());
114 height = qMax(height,base.height());
107 sh = QSizeF(width,height);
115 sh = QSizeF(width,height);
108 break;
116 break;
109 }
117 }
110 case Qt::PreferredSize: {
118 case Qt::PreferredSize: {
111 int count = qMax(ticksList.first().count() , ticksList.last().count());
119 width = labelWidth + labelPadding() + 2; //two pixels of tolerance
112 width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance
113 width += base.width();
120 width += base.width();
114 height = fn.height() * ticksList.count();
121 height = fn.height() * ticksList.count();
115 height = qMax(height,base.height());
122 height = qMax(height,base.height());
116 sh = QSizeF(width,height);
123 sh = QSizeF(width,height);
117 break;
124 break;
118 }
125 }
119 default:
126 default:
120 break;
127 break;
121 }
128 }
122
129
123 return sh;
130 return sh;
124 }
131 }
125
132
126 #include "moc_chartdatetimeaxisy_p.cpp"
133 #include "moc_chartdatetimeaxisy_p.cpp"
127
134
128 QTCOMMERCIALCHART_END_NAMESPACE
135 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,130 +1,131
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartvalueaxisy_p.h"
21 #include "chartvalueaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include "chartlayout_p.h"
25 #include "chartlayout_p.h"
26 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <qmath.h>
28 #include <qmath.h>
29 #include <QDebug>
29 #include <QDebug>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item)
33 ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item)
34 : VerticalAxis(axis, item),
34 : VerticalAxis(axis, item),
35 m_axis(axis)
35 m_axis(axis)
36 {
36 {
37 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
37 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
38 QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
38 QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
39 }
39 }
40
40
41 ChartValueAxisY::~ChartValueAxisY()
41 ChartValueAxisY::~ChartValueAxisY()
42 {
42 {
43 }
43 }
44
44
45 QVector<qreal> ChartValueAxisY::calculateLayout() const
45 QVector<qreal> ChartValueAxisY::calculateLayout() const
46 {
46 {
47 int tickCount = m_axis->tickCount();
47 int tickCount = m_axis->tickCount();
48
48
49 Q_ASSERT(tickCount >= 2);
49 Q_ASSERT(tickCount >= 2);
50
50
51 QVector<qreal> points;
51 QVector<qreal> points;
52 points.resize(tickCount);
52 points.resize(tickCount);
53
53
54 const QRectF &gridRect = gridGeometry();
54 const QRectF &gridRect = gridGeometry();
55
55
56 const qreal deltaY = gridRect.height() / (tickCount - 1);
56 const qreal deltaY = gridRect.height() / (tickCount - 1);
57 for (int i = 0; i < tickCount; ++i) {
57 for (int i = 0; i < tickCount; ++i) {
58 points[i] = i * -deltaY + gridRect.bottom();
58 points[i] = i * -deltaY + gridRect.bottom();
59 }
59 }
60
60
61 return points;
61 return points;
62 }
62 }
63
63
64 void ChartValueAxisY::updateGeometry()
64 void ChartValueAxisY::updateGeometry()
65 {
65 {
66 const QVector<qreal> &layout = ChartAxis::layout();
66 const QVector<qreal> &layout = ChartAxis::layout();
67 if (layout.isEmpty())
67 if (layout.isEmpty())
68 return;
68 return;
69 setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat()));
69 setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat()));
70 VerticalAxis::updateGeometry();
70 VerticalAxis::updateGeometry();
71 }
71 }
72
72
73 void ChartValueAxisY::handleTickCountChanged(int tick)
73 void ChartValueAxisY::handleTickCountChanged(int tick)
74 {
74 {
75 Q_UNUSED(tick);
75 Q_UNUSED(tick);
76 QGraphicsLayoutItem::updateGeometry();
76 QGraphicsLayoutItem::updateGeometry();
77 if(presenter()) presenter()->layout()->invalidate();
77 if(presenter()) presenter()->layout()->invalidate();
78 }
78 }
79
79
80 void ChartValueAxisY::handleLabelFormatChanged(const QString &format)
80 void ChartValueAxisY::handleLabelFormatChanged(const QString &format)
81 {
81 {
82 Q_UNUSED(format);
82 Q_UNUSED(format);
83 QGraphicsLayoutItem::updateGeometry();
83 QGraphicsLayoutItem::updateGeometry();
84 if(presenter()) presenter()->layout()->invalidate();
84 if(presenter()) presenter()->layout()->invalidate();
85 }
85 }
86
86
87 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
87 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
88 {
88 {
89 Q_UNUSED(constraint)
89 Q_UNUSED(constraint)
90
90
91 QFontMetrics fn(font());
91 QFontMetrics fn(font());
92 QSizeF sh;
92 QSizeF sh;
93 QSizeF base = VerticalAxis::sizeHint(which, constraint);
93 QSizeF base = VerticalAxis::sizeHint(which, constraint);
94 QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
94 QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
95 qreal width = 0;
95 qreal width = 0;
96 qreal height = 0;
96 qreal height = 0;
97
97
98 int count = 1;
98 int labelWidth = 0;
99
99
100 if(!ticksList.empty()){
100 foreach(const QString& s, ticksList)
101 count = qMax(ticksList.last().count(),ticksList.first().count());
101 {
102 labelWidth=qMax(fn.width(s),labelWidth);
102 }
103 }
103
104
104 switch (which) {
105 switch (which) {
105 case Qt::MinimumSize: {
106 case Qt::MinimumSize: {
106 width = fn.boundingRect("...").width() + labelPadding();
107 width = fn.boundingRect("...").width() + labelPadding();
107 width += base.width();
108 width += base.width();
108 height = fn.height();
109 height = fn.height();
109 height = qMax(height,base.height());
110 height = qMax(height,base.height());
110 sh = QSizeF(width,height);
111 sh = QSizeF(width,height);
111 break;
112 break;
112 }
113 }
113 case Qt::PreferredSize:
114 case Qt::PreferredSize:
114 {
115 {
115 width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance
116 width = labelWidth + labelPadding() + 2; //two pixels of tolerance
116 width += base.width();
117 width += base.width();
117 height = fn.height() * ticksList.count();
118 height = fn.height() * ticksList.count();
118 height = qMax(height,base.height());
119 height = qMax(height,base.height());
119 sh = QSizeF(width,height);
120 sh = QSizeF(width,height);
120 break;
121 break;
121 }
122 }
122 default:
123 default:
123 break;
124 break;
124 }
125 }
125 return sh;
126 return sh;
126 }
127 }
127
128
128 #include "moc_chartvalueaxisy_p.cpp"
129 #include "moc_chartvalueaxisy_p.cpp"
129
130
130 QTCOMMERCIALCHART_END_NAMESPACE
131 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now