##// END OF EJS Templates
minor. removes hardcoded label padding drom datetime axis
Michal Klocek -
r2112:0680e5f566cd
parent child
Show More
@@ -1,109 +1,106
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdatetimeaxisx_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qdatetimeaxis.h"
24 24 #include <QGraphicsLayout>
25 25 #include <QDateTime>
26 26 #include <QFontMetrics>
27 27 #include <qmath.h>
28 28
29
30 static int label_padding = 5;
31
32 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 30
34 31 ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter),
35 32 m_tickCount(0),m_axis(axis)
36 33 {
37 34 }
38 35
39 36 ChartDateTimeAxisX::~ChartDateTimeAxisX()
40 37 {
41 38 }
42 39
43 40 QVector<qreal> ChartDateTimeAxisX::calculateLayout() const
44 41 {
45 42 Q_ASSERT(m_tickCount>=2);
46 43
47 44 QVector<qreal> points;
48 45 points.resize(m_tickCount);
49 46 const QRectF& gridRect = gridGeometry();
50 47 const qreal deltaX = gridRect.width()/(m_tickCount-1);
51 48 for (int i = 0; i < m_tickCount; ++i) {
52 49 int x = i * deltaX + gridRect.left();
53 50 points[i] = x;
54 51 }
55 52 return points;
56 53 }
57 54
58 55 void ChartDateTimeAxisX::updateGeometry()
59 56 {
60 57 const QVector<qreal>& layout = ChartAxis::layout();
61 58 if(layout.isEmpty()) return;
62 59 setLabels(createDateTimeLabels(m_axis->format(),layout.size()));
63 60 HorizontalAxis::updateGeometry();
64 61 }
65 62
66 63 void ChartDateTimeAxisX::handleAxisUpdated()
67 64 {
68 65 m_tickCount = m_axis->tickCount();
69 66 ChartAxis::handleAxisUpdated();
70 67 }
71 68
72 69 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
73 70 {
74 71 Q_UNUSED(constraint)
75 72
76 73 QFontMetrics fn(font());
77 74 QSizeF sh;
78 75
79 76 switch (which) {
80 77 case Qt::MinimumSize:
81 78 sh = QSizeF(fn.boundingRect("...").width(),fn.height());
82 79 break;
83 80 case Qt::PreferredSize:{
84 81
85 82 const QVector<qreal>& layout = ChartAxis::layout();
86 83 if(layout.isEmpty()) break;
87 84 QStringList ticksList;
88 85
89 86
90 87 qreal width=0;
91 88 qreal height=0;
92 89
93 90 for (int i = 0; i < ticksList.size(); ++i)
94 91 {
95 92 QRectF rect = fn.boundingRect(ticksList.at(i));
96 93 width+=rect.width();
97 height+=qMax(rect.height()+label_padding,height);
94 height+=qMax(rect.height()+labelPadding(),height);
98 95 }
99 96 sh = QSizeF(width,height);
100 97 break;
101 98 }
102 99 default:
103 100 break;
104 101 }
105 102
106 103 return sh;
107 104 }
108 105
109 106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,110 +1,107
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdatetimeaxisy_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qdatetimeaxis.h"
24 24 #include <QGraphicsLayout>
25 25 #include <QFontMetrics>
26 26 #include <QDateTime>
27 27 #include <qmath.h>
28 28
29
30 static int label_padding = 5;
31
32 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 30
34 31 ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter),
35 32 m_tickCount(0),m_axis(axis)
36 33 {
37 34 }
38 35
39 36 ChartDateTimeAxisY::~ChartDateTimeAxisY()
40 37 {
41 38 }
42 39
43 40 QVector<qreal> ChartDateTimeAxisY::calculateLayout() const
44 41 {
45 42 Q_ASSERT(m_tickCount>=2);
46 43
47 44 QVector<qreal> points;
48 45 points.resize(m_tickCount);
49 46 const QRectF& gridRect = gridGeometry();
50 47 const qreal deltaY = gridRect.height()/(m_tickCount-1);
51 48 for (int i = 0; i < m_tickCount; ++i) {
52 49 int y = i * -deltaY + gridRect.bottom();
53 50 points[i] = y;
54 51 }
55 52
56 53 return points;
57 54 }
58 55
59 56 void ChartDateTimeAxisY::updateGeometry()
60 57 {
61 58 const QVector<qreal> &layout = ChartAxis::layout();
62 59 if(layout.isEmpty()) return;
63 60 setLabels(createDateTimeLabels(m_axis->format(),layout.size()));
64 61 VerticalAxis::updateGeometry();
65 62 }
66 63
67 64 void ChartDateTimeAxisY::handleAxisUpdated()
68 65 {
69 66 m_tickCount = m_axis->tickCount();
70 67 ChartAxis::handleAxisUpdated();
71 68 }
72 69
73 70 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
74 71 {
75 72 Q_UNUSED(constraint)
76 73
77 74 QFontMetrics fn(font());
78 75 QSizeF sh;
79 76
80 77 switch (which) {
81 78 case Qt::MinimumSize:
82 79 sh = QSizeF(fn.boundingRect("...").width(),fn.height());
83 80 break;
84 81 case Qt::PreferredSize:{
85 82
86 83 const QVector<qreal>& layout = ChartAxis::layout();
87 84 if(layout.isEmpty()) break;
88 85 QStringList ticksList;
89 86
90 87
91 88 qreal width=0;
92 89 qreal height=0;
93 90
94 91 for (int i = 0; i < ticksList.size(); ++i)
95 92 {
96 93 QRectF rect = fn.boundingRect(ticksList.at(i));
97 94 width+=rect.width();
98 height+=qMax(rect.height()+label_padding,height);
95 height+=qMax(rect.height()+labelPadding(),height);
99 96 }
100 97 sh = QSizeF(width,height);
101 98 break;
102 99 }
103 100 default:
104 101 break;
105 102 }
106 103
107 104 return sh;
108 105 }
109 106
110 107 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now