@@ -1,112 +1,112 | |||||
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 "chartaxisx_p.h" |
|
21 | #include "chartaxisx_p.h" | |
22 | #include "qaxis.h" |
|
22 | #include "qaxis.h" | |
23 | #include "qaxis_p.h" |
|
23 | #include "qaxis_p.h" | |
24 | #include "qaxiscategories_p.h" |
|
24 | #include "qaxiscategories_p.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | static int label_padding = 5; |
|
28 | static int label_padding = 5; | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartAxisX::ChartAxisX(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
32 | ChartAxisX::ChartAxisX(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | ChartAxisX::~ChartAxisX() |
|
36 | ChartAxisX::~ChartAxisX() | |
37 | { |
|
37 | { | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | QVector<qreal> ChartAxisX::calculateLayout() const |
|
40 | QVector<qreal> ChartAxisX::calculateLayout() const | |
41 | { |
|
41 | { | |
42 | Q_ASSERT(m_ticksCount>=2); |
|
42 | Q_ASSERT(m_ticksCount>=2); | |
43 |
|
43 | |||
44 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
45 | points.resize(m_ticksCount); |
|
45 | points.resize(m_ticksCount); | |
46 |
|
46 | |||
47 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); |
|
47 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
48 | for (int i = 0; i < m_ticksCount; ++i) { |
|
48 | for (int i = 0; i < m_ticksCount; ++i) { | |
49 | int x = i * deltaX + m_rect.left(); |
|
49 | int x = i * deltaX + m_rect.left(); | |
50 | points[i] = x; |
|
50 | points[i] = x; | |
51 | } |
|
51 | } | |
52 | return points; |
|
52 | return points; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void ChartAxisX::updateGeometry() |
|
55 | void ChartAxisX::updateGeometry() | |
56 | { |
|
56 | { | |
57 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
57 | const QVector<qreal>& layout = ChartAxis::layout(); | |
58 |
|
58 | |||
59 | QStringList ticksList; |
|
59 | QStringList ticksList; | |
60 |
|
60 | |||
61 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
61 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
62 |
|
62 | |||
63 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
63 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
64 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
64 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
65 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
65 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
66 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
66 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
67 |
|
67 | |||
68 | Q_ASSERT(labels.size() == ticksList.size()); |
|
68 | Q_ASSERT(labels.size() == ticksList.size()); | |
69 | Q_ASSERT(layout.size() == ticksList.size()); |
|
69 | Q_ASSERT(layout.size() == ticksList.size()); | |
70 |
|
70 | |||
71 | qreal minWidth = 0; |
|
71 | qreal minWidth = 0; | |
72 | qreal minHeight = 0; |
|
72 | qreal minHeight = 0; | |
73 |
|
73 | |||
74 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
74 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
75 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
75 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
76 |
|
76 | |||
77 | for (int i = 0; i < layout.size(); ++i) { |
|
77 | for (int i = 0; i < layout.size(); ++i) { | |
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
79 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
79 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
80 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
80 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
81 | if (!categories || i<1) { |
|
81 | if (!categories || i<1) { | |
82 | labelItem->setText(ticksList.at(i)); |
|
82 | labelItem->setText(ticksList.at(i)); | |
83 | const QRectF& rect = labelItem->boundingRect(); |
|
83 | const QRectF& rect = labelItem->boundingRect(); | |
84 | minWidth+=rect.width(); |
|
84 | minWidth+=rect.width(); | |
85 | minHeight=qMax(rect.height(),minHeight); |
|
85 | minHeight=qMax(rect.height(),minHeight); | |
86 | QPointF center = rect.center(); |
|
86 | QPointF center = rect.center(); | |
87 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
87 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
88 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
88 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
89 | } |
|
89 | } | |
90 | else { |
|
90 | else { | |
91 | labelItem->setText(ticksList.at(i)); |
|
91 | labelItem->setText(ticksList.at(i)); | |
92 | const QRectF& rect = labelItem->boundingRect(); |
|
92 | const QRectF& rect = labelItem->boundingRect(); | |
93 | minWidth+=rect.width(); |
|
93 | minWidth+=rect.width(); | |
94 | minHeight=qMax(rect.height()+label_padding,minHeight); |
|
94 | minHeight=qMax(rect.height()+label_padding,minHeight); | |
95 | QPointF center = rect.center(); |
|
95 | QPointF center = rect.center(); | |
96 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
96 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
97 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
97 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | if ((i+1)%2 && i>1) { |
|
100 | if ((i+1)%2 && i>1) { | |
101 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
101 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
102 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
102 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
103 | } |
|
103 | } | |
104 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
104 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
105 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
105 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | presenter()->setMinimumMarginWidth(this,minWidth); |
|
108 | //presenter()->setMinimumMarginWidth(this,minWidth); | |
109 | presenter()->setMinimumMarginHeight(this,minHeight); |
|
109 | //presenter()->setMinimumMarginHeight(this,minHeight); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | QTCOMMERCIALCHART_END_NAMESPACE |
|
112 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,116 +1,116 | |||||
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 "chartaxisy_p.h" |
|
21 | #include "chartaxisy_p.h" | |
22 | #include "qaxis.h" |
|
22 | #include "qaxis.h" | |
23 | #include "qaxis_p.h" |
|
23 | #include "qaxis_p.h" | |
24 | #include "qaxiscategories_p.h" |
|
24 | #include "qaxiscategories_p.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartAxisY::ChartAxisY(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
33 | ChartAxisY::ChartAxisY(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
34 | { |
|
34 | { | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | ChartAxisY::~ChartAxisY() |
|
37 | ChartAxisY::~ChartAxisY() | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QVector<qreal> ChartAxisY::calculateLayout() const |
|
41 | QVector<qreal> ChartAxisY::calculateLayout() const | |
42 | { |
|
42 | { | |
43 | Q_ASSERT(m_ticksCount>=2); |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
44 |
|
44 | |||
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 | points.resize(m_ticksCount); |
|
46 | points.resize(m_ticksCount); | |
47 |
|
47 | |||
48 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); |
|
48 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); | |
49 | for (int i = 0; i < m_ticksCount; ++i) { |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
50 | int y = i * -deltaY + m_rect.bottom(); |
|
50 | int y = i * -deltaY + m_rect.bottom(); | |
51 | points[i] = y; |
|
51 | points[i] = y; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | return points; |
|
54 | return points; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void ChartAxisY::updateGeometry() |
|
57 | void ChartAxisY::updateGeometry() | |
58 | { |
|
58 | { | |
59 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
59 | const QVector<qreal> &layout = ChartAxis::layout(); | |
60 |
|
60 | |||
61 | QStringList ticksList; |
|
61 | QStringList ticksList; | |
62 |
|
62 | |||
63 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
63 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
64 |
|
64 | |||
65 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
65 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
66 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
66 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
67 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
67 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
68 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
68 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
69 |
|
69 | |||
70 | Q_ASSERT(labels.size() == ticksList.size()); |
|
70 | Q_ASSERT(labels.size() == ticksList.size()); | |
71 | Q_ASSERT(layout.size() == ticksList.size()); |
|
71 | Q_ASSERT(layout.size() == ticksList.size()); | |
72 |
|
72 | |||
73 | qreal minWidth = 0; |
|
73 | qreal minWidth = 0; | |
74 | qreal minHeight = 0; |
|
74 | qreal minHeight = 0; | |
75 |
|
75 | |||
76 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
76 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
77 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
77 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
78 |
|
78 | |||
79 | for (int i = 0; i < layout.size(); ++i) { |
|
79 | for (int i = 0; i < layout.size(); ++i) { | |
80 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
80 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
81 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
81 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
82 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
82 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
83 |
|
83 | |||
84 | if (!categories || i<1) { |
|
84 | if (!categories || i<1) { | |
85 | labelItem->setText(ticksList.at(i)); |
|
85 | labelItem->setText(ticksList.at(i)); | |
86 | const QRectF& rect = labelItem->boundingRect(); |
|
86 | const QRectF& rect = labelItem->boundingRect(); | |
87 | minWidth=qMax(rect.width()+label_padding,minWidth); |
|
87 | minWidth=qMax(rect.width()+label_padding,minWidth); | |
88 | minHeight+=rect.height(); |
|
88 | minHeight+=rect.height(); | |
89 | QPointF center = rect.center(); |
|
89 | QPointF center = rect.center(); | |
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
91 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
91 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
92 | } |
|
92 | } | |
93 | else { |
|
93 | else { | |
94 | labelItem->setText(ticksList.at(i)); |
|
94 | labelItem->setText(ticksList.at(i)); | |
95 | const QRectF& rect = labelItem->boundingRect(); |
|
95 | const QRectF& rect = labelItem->boundingRect(); | |
96 | minWidth=qMax(rect.width(),minWidth); |
|
96 | minWidth=qMax(rect.width(),minWidth); | |
97 | minHeight+=rect.height(); |
|
97 | minHeight+=rect.height(); | |
98 | QPointF center = rect.center(); |
|
98 | QPointF center = rect.center(); | |
99 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
99 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
100 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); |
|
100 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | if ((i+1)%2 && i>1) { |
|
103 | if ((i+1)%2 && i>1) { | |
104 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
104 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
105 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
105 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
106 | } |
|
106 | } | |
107 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
107 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
108 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
108 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | presenter()->setMinimumMarginWidth(this,minWidth); |
|
111 | //presenter()->setMinimumMarginWidth(this,minWidth); | |
112 | presenter()->setMinimumMarginHeight(this,minHeight); |
|
112 | //presenter()->setMinimumMarginHeight(this,minHeight); | |
113 |
|
113 | |||
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now