@@ -1,109 +1,106 | |||||
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 <QGraphicsLayout> |
|
24 | #include <QGraphicsLayout> | |
25 | #include <QDateTime> |
|
25 | #include <QDateTime> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
||||
30 | static int label_padding = 5; |
|
|||
31 |
|
||||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
30 | |||
34 | ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter), |
|
31 | ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter), | |
35 | m_tickCount(0),m_axis(axis) |
|
32 | m_tickCount(0),m_axis(axis) | |
36 | { |
|
33 | { | |
37 | } |
|
34 | } | |
38 |
|
35 | |||
39 | ChartDateTimeAxisX::~ChartDateTimeAxisX() |
|
36 | ChartDateTimeAxisX::~ChartDateTimeAxisX() | |
40 | { |
|
37 | { | |
41 | } |
|
38 | } | |
42 |
|
39 | |||
43 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const |
|
40 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |
44 | { |
|
41 | { | |
45 | Q_ASSERT(m_tickCount>=2); |
|
42 | Q_ASSERT(m_tickCount>=2); | |
46 |
|
43 | |||
47 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
48 | points.resize(m_tickCount); |
|
45 | points.resize(m_tickCount); | |
49 | const QRectF& gridRect = gridGeometry(); |
|
46 | const QRectF& gridRect = gridGeometry(); | |
50 | const qreal deltaX = gridRect.width()/(m_tickCount-1); |
|
47 | const qreal deltaX = gridRect.width()/(m_tickCount-1); | |
51 | for (int i = 0; i < m_tickCount; ++i) { |
|
48 | for (int i = 0; i < m_tickCount; ++i) { | |
52 | int x = i * deltaX + gridRect.left(); |
|
49 | int x = i * deltaX + gridRect.left(); | |
53 | points[i] = x; |
|
50 | points[i] = x; | |
54 | } |
|
51 | } | |
55 | return points; |
|
52 | return points; | |
56 | } |
|
53 | } | |
57 |
|
54 | |||
58 | void ChartDateTimeAxisX::updateGeometry() |
|
55 | void ChartDateTimeAxisX::updateGeometry() | |
59 | { |
|
56 | { | |
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
57 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 | if(layout.isEmpty()) return; |
|
58 | if(layout.isEmpty()) return; | |
62 | setLabels(createDateTimeLabels(m_axis->format(),layout.size())); |
|
59 | setLabels(createDateTimeLabels(m_axis->format(),layout.size())); | |
63 | HorizontalAxis::updateGeometry(); |
|
60 | HorizontalAxis::updateGeometry(); | |
64 | } |
|
61 | } | |
65 |
|
62 | |||
66 | void ChartDateTimeAxisX::handleAxisUpdated() |
|
63 | void ChartDateTimeAxisX::handleAxisUpdated() | |
67 | { |
|
64 | { | |
68 | m_tickCount = m_axis->tickCount(); |
|
65 | m_tickCount = m_axis->tickCount(); | |
69 | ChartAxis::handleAxisUpdated(); |
|
66 | ChartAxis::handleAxisUpdated(); | |
70 | } |
|
67 | } | |
71 |
|
68 | |||
72 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
69 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
73 | { |
|
70 | { | |
74 | Q_UNUSED(constraint) |
|
71 | Q_UNUSED(constraint) | |
75 |
|
72 | |||
76 | QFontMetrics fn(font()); |
|
73 | QFontMetrics fn(font()); | |
77 | QSizeF sh; |
|
74 | QSizeF sh; | |
78 |
|
75 | |||
79 | switch (which) { |
|
76 | switch (which) { | |
80 | case Qt::MinimumSize: |
|
77 | case Qt::MinimumSize: | |
81 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); |
|
78 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); | |
82 | break; |
|
79 | break; | |
83 | case Qt::PreferredSize:{ |
|
80 | case Qt::PreferredSize:{ | |
84 |
|
81 | |||
85 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
82 | const QVector<qreal>& layout = ChartAxis::layout(); | |
86 | if(layout.isEmpty()) break; |
|
83 | if(layout.isEmpty()) break; | |
87 | QStringList ticksList; |
|
84 | QStringList ticksList; | |
88 |
|
85 | |||
89 |
|
86 | |||
90 | qreal width=0; |
|
87 | qreal width=0; | |
91 | qreal height=0; |
|
88 | qreal height=0; | |
92 |
|
89 | |||
93 | for (int i = 0; i < ticksList.size(); ++i) |
|
90 | for (int i = 0; i < ticksList.size(); ++i) | |
94 | { |
|
91 | { | |
95 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
92 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
96 | width+=rect.width(); |
|
93 | width+=rect.width(); | |
97 |
height+=qMax(rect.height()+label |
|
94 | height+=qMax(rect.height()+labelPadding(),height); | |
98 | } |
|
95 | } | |
99 | sh = QSizeF(width,height); |
|
96 | sh = QSizeF(width,height); | |
100 | break; |
|
97 | break; | |
101 | } |
|
98 | } | |
102 | default: |
|
99 | default: | |
103 | break; |
|
100 | break; | |
104 | } |
|
101 | } | |
105 |
|
102 | |||
106 | return sh; |
|
103 | return sh; | |
107 | } |
|
104 | } | |
108 |
|
105 | |||
109 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,110 +1,107 | |||||
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 <QGraphicsLayout> |
|
24 | #include <QGraphicsLayout> | |
25 | #include <QFontMetrics> |
|
25 | #include <QFontMetrics> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
||||
30 | static int label_padding = 5; |
|
|||
31 |
|
||||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
30 | |||
34 | ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter), |
|
31 | ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter), | |
35 | m_tickCount(0),m_axis(axis) |
|
32 | m_tickCount(0),m_axis(axis) | |
36 | { |
|
33 | { | |
37 | } |
|
34 | } | |
38 |
|
35 | |||
39 | ChartDateTimeAxisY::~ChartDateTimeAxisY() |
|
36 | ChartDateTimeAxisY::~ChartDateTimeAxisY() | |
40 | { |
|
37 | { | |
41 | } |
|
38 | } | |
42 |
|
39 | |||
43 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const |
|
40 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |
44 | { |
|
41 | { | |
45 | Q_ASSERT(m_tickCount>=2); |
|
42 | Q_ASSERT(m_tickCount>=2); | |
46 |
|
43 | |||
47 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
48 | points.resize(m_tickCount); |
|
45 | points.resize(m_tickCount); | |
49 | const QRectF& gridRect = gridGeometry(); |
|
46 | const QRectF& gridRect = gridGeometry(); | |
50 | const qreal deltaY = gridRect.height()/(m_tickCount-1); |
|
47 | const qreal deltaY = gridRect.height()/(m_tickCount-1); | |
51 | for (int i = 0; i < m_tickCount; ++i) { |
|
48 | for (int i = 0; i < m_tickCount; ++i) { | |
52 | int y = i * -deltaY + gridRect.bottom(); |
|
49 | int y = i * -deltaY + gridRect.bottom(); | |
53 | points[i] = y; |
|
50 | points[i] = y; | |
54 | } |
|
51 | } | |
55 |
|
52 | |||
56 | return points; |
|
53 | return points; | |
57 | } |
|
54 | } | |
58 |
|
55 | |||
59 | void ChartDateTimeAxisY::updateGeometry() |
|
56 | void ChartDateTimeAxisY::updateGeometry() | |
60 | { |
|
57 | { | |
61 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
58 | const QVector<qreal> &layout = ChartAxis::layout(); | |
62 | if(layout.isEmpty()) return; |
|
59 | if(layout.isEmpty()) return; | |
63 | setLabels(createDateTimeLabels(m_axis->format(),layout.size())); |
|
60 | setLabels(createDateTimeLabels(m_axis->format(),layout.size())); | |
64 | VerticalAxis::updateGeometry(); |
|
61 | VerticalAxis::updateGeometry(); | |
65 | } |
|
62 | } | |
66 |
|
63 | |||
67 | void ChartDateTimeAxisY::handleAxisUpdated() |
|
64 | void ChartDateTimeAxisY::handleAxisUpdated() | |
68 | { |
|
65 | { | |
69 | m_tickCount = m_axis->tickCount(); |
|
66 | m_tickCount = m_axis->tickCount(); | |
70 | ChartAxis::handleAxisUpdated(); |
|
67 | ChartAxis::handleAxisUpdated(); | |
71 | } |
|
68 | } | |
72 |
|
69 | |||
73 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
70 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
74 | { |
|
71 | { | |
75 | Q_UNUSED(constraint) |
|
72 | Q_UNUSED(constraint) | |
76 |
|
73 | |||
77 | QFontMetrics fn(font()); |
|
74 | QFontMetrics fn(font()); | |
78 | QSizeF sh; |
|
75 | QSizeF sh; | |
79 |
|
76 | |||
80 | switch (which) { |
|
77 | switch (which) { | |
81 | case Qt::MinimumSize: |
|
78 | case Qt::MinimumSize: | |
82 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); |
|
79 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); | |
83 | break; |
|
80 | break; | |
84 | case Qt::PreferredSize:{ |
|
81 | case Qt::PreferredSize:{ | |
85 |
|
82 | |||
86 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
83 | const QVector<qreal>& layout = ChartAxis::layout(); | |
87 | if(layout.isEmpty()) break; |
|
84 | if(layout.isEmpty()) break; | |
88 | QStringList ticksList; |
|
85 | QStringList ticksList; | |
89 |
|
86 | |||
90 |
|
87 | |||
91 | qreal width=0; |
|
88 | qreal width=0; | |
92 | qreal height=0; |
|
89 | qreal height=0; | |
93 |
|
90 | |||
94 | for (int i = 0; i < ticksList.size(); ++i) |
|
91 | for (int i = 0; i < ticksList.size(); ++i) | |
95 | { |
|
92 | { | |
96 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
93 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
97 | width+=rect.width(); |
|
94 | width+=rect.width(); | |
98 |
height+=qMax(rect.height()+label |
|
95 | height+=qMax(rect.height()+labelPadding(),height); | |
99 | } |
|
96 | } | |
100 | sh = QSizeF(width,height); |
|
97 | sh = QSizeF(width,height); | |
101 | break; |
|
98 | break; | |
102 | } |
|
99 | } | |
103 | default: |
|
100 | default: | |
104 | break; |
|
101 | break; | |
105 | } |
|
102 | } | |
106 |
|
103 | |||
107 | return sh; |
|
104 | return sh; | |
108 | } |
|
105 | } | |
109 |
|
106 | |||
110 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now