@@ -0,0 +1,122 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "chartcategoriesaxisx_p.h" | |
|
22 | #include "qabstractaxis.h" | |
|
23 | #include "chartpresenter_p.h" | |
|
24 | #include "chartanimator_p.h" | |
|
25 | #include <QGraphicsLayout> | |
|
26 | #include <QDebug> | |
|
27 | #include <QFontMetrics> | |
|
28 | ||
|
29 | static int label_padding = 5; | |
|
30 | ||
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
32 | ||
|
33 | ChartCategoriesAxisX::ChartCategoriesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | ChartCategoriesAxisX::~ChartCategoriesAxisX() | |
|
38 | { | |
|
39 | } | |
|
40 | ||
|
41 | QVector<qreal> ChartCategoriesAxisX::calculateLayout() const | |
|
42 | { | |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
|
44 | ||
|
45 | QVector<qreal> points; | |
|
46 | points.resize(m_ticksCount); | |
|
47 | ||
|
48 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
|
50 | int x = i * deltaX + m_rect.left(); | |
|
51 | points[i] = x; | |
|
52 | } | |
|
53 | return points; | |
|
54 | } | |
|
55 | ||
|
56 | void ChartCategoriesAxisX::updateGeometry() | |
|
57 | { | |
|
58 | const QVector<qreal>& layout = ChartAxis::layout(); | |
|
59 | ||
|
60 | m_minWidth = 0; | |
|
61 | m_minHeight = 0; | |
|
62 | ||
|
63 | if(layout.isEmpty()) return; | |
|
64 | ||
|
65 | QStringList ticksList; | |
|
66 | ||
|
67 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
|
68 | ||
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
|
72 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
|
73 | ||
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
|
76 | ||
|
77 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
|
78 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
|
79 | ||
|
80 | qreal width = 0; | |
|
81 | for (int i = 0; i < layout.size(); ++i) { | |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
|
83 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
|
84 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
|
85 | if (!categories || i<1) { | |
|
86 | labelItem->setText(ticksList.at(i)); | |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
|
88 | QPointF center = rect.center(); | |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
|
91 | ||
|
92 | if(labelItem->pos().x()<=width){ | |
|
93 | labelItem->setVisible(false); | |
|
94 | lineItem->setVisible(false); | |
|
95 | }else{ | |
|
96 | labelItem->setVisible(true); | |
|
97 | lineItem->setVisible(true); | |
|
98 | width=rect.width()+labelItem->pos().x(); | |
|
99 | } | |
|
100 | m_minWidth+=rect.width(); | |
|
101 | m_minHeight=qMax(rect.height(),m_minHeight); | |
|
102 | } | |
|
103 | else { | |
|
104 | labelItem->setText(ticksList.at(i)); | |
|
105 | const QRectF& rect = labelItem->boundingRect(); | |
|
106 | QPointF center = rect.center(); | |
|
107 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
108 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
|
109 | m_minWidth+=rect.width(); | |
|
110 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
|
111 | } | |
|
112 | ||
|
113 | if ((i+1)%2 && i>1) { | |
|
114 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
|
115 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
|
116 | } | |
|
117 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
|
118 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
|
119 | } | |
|
120 | } | |
|
121 | ||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,55 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | // W A R N I N G | |
|
22 | // ------------- | |
|
23 | // | |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
|
25 | // implementation detail. This header file may change from version to | |
|
26 | // version without notice, or even be removed. | |
|
27 | // | |
|
28 | // We mean it. | |
|
29 | ||
|
30 | #ifndef CHARTCATEGORIESAXISX_H | |
|
31 | #define CHARTCATEGORIESAXISX_H | |
|
32 | ||
|
33 | #include "chartaxis_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | class QAbstractAxis; | |
|
38 | class ChartPresenter; | |
|
39 | ||
|
40 | class ChartCategoriesAxisX : public ChartAxis | |
|
41 | { | |
|
42 | public: | |
|
43 | ChartCategoriesAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
|
44 | ~ChartCategoriesAxisX(); | |
|
45 | ||
|
46 | AxisType axisType() const { return X_AXIS;} | |
|
47 | ||
|
48 | protected: | |
|
49 | QVector<qreal> calculateLayout() const; | |
|
50 | void updateGeometry(); | |
|
51 | }; | |
|
52 | ||
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
54 | ||
|
55 | #endif /* CHARTCATEGORIESAXISX_H */ |
@@ -0,0 +1,122 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "chartcategoriesaxisy_p.h" | |
|
22 | #include "qabstractaxis.h" | |
|
23 | #include "chartpresenter_p.h" | |
|
24 | #include "chartanimator_p.h" | |
|
25 | #include <QGraphicsLayout> | |
|
26 | #include <QDebug> | |
|
27 | #include <QFontMetrics> | |
|
28 | ||
|
29 | static int label_padding = 5; | |
|
30 | ||
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
32 | ||
|
33 | ChartCategoriesAxisY::ChartCategoriesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | ChartCategoriesAxisY::~ChartCategoriesAxisY() | |
|
38 | { | |
|
39 | } | |
|
40 | ||
|
41 | QVector<qreal> ChartCategoriesAxisY::calculateLayout() const | |
|
42 | { | |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
|
44 | ||
|
45 | QVector<qreal> points; | |
|
46 | points.resize(m_ticksCount); | |
|
47 | ||
|
48 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
|
50 | int x = i * deltaX + m_rect.left(); | |
|
51 | points[i] = x; | |
|
52 | } | |
|
53 | return points; | |
|
54 | } | |
|
55 | ||
|
56 | void ChartCategoriesAxisY::updateGeometry() | |
|
57 | { | |
|
58 | const QVector<qreal>& layout = ChartAxis::layout(); | |
|
59 | ||
|
60 | m_minWidth = 0; | |
|
61 | m_minHeight = 0; | |
|
62 | ||
|
63 | if(layout.isEmpty()) return; | |
|
64 | ||
|
65 | QStringList ticksList; | |
|
66 | ||
|
67 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
|
68 | ||
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
|
72 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
|
73 | ||
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
|
76 | ||
|
77 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
|
78 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
|
79 | ||
|
80 | qreal width = 0; | |
|
81 | for (int i = 0; i < layout.size(); ++i) { | |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
|
83 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
|
84 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
|
85 | if (!categories || i<1) { | |
|
86 | labelItem->setText(ticksList.at(i)); | |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
|
88 | QPointF center = rect.center(); | |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
|
91 | ||
|
92 | if(labelItem->pos().x()<=width){ | |
|
93 | labelItem->setVisible(false); | |
|
94 | lineItem->setVisible(false); | |
|
95 | }else{ | |
|
96 | labelItem->setVisible(true); | |
|
97 | lineItem->setVisible(true); | |
|
98 | width=rect.width()+labelItem->pos().x(); | |
|
99 | } | |
|
100 | m_minWidth+=rect.width(); | |
|
101 | m_minHeight=qMax(rect.height(),m_minHeight); | |
|
102 | } | |
|
103 | else { | |
|
104 | labelItem->setText(ticksList.at(i)); | |
|
105 | const QRectF& rect = labelItem->boundingRect(); | |
|
106 | QPointF center = rect.center(); | |
|
107 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
108 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
|
109 | m_minWidth+=rect.width(); | |
|
110 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
|
111 | } | |
|
112 | ||
|
113 | if ((i+1)%2 && i>1) { | |
|
114 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
|
115 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
|
116 | } | |
|
117 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
|
118 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
|
119 | } | |
|
120 | } | |
|
121 | ||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,55 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | // W A R N I N G | |
|
22 | // ------------- | |
|
23 | // | |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
|
25 | // implementation detail. This header file may change from version to | |
|
26 | // version without notice, or even be removed. | |
|
27 | // | |
|
28 | // We mean it. | |
|
29 | ||
|
30 | #ifndef CHARTCATEGORIESAXISY_H | |
|
31 | #define CHARTCATEGORIESAXISY_H | |
|
32 | ||
|
33 | #include "chartaxis_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | class QAbstractAxis; | |
|
38 | class ChartPresenter; | |
|
39 | ||
|
40 | class ChartCategoriesAxisY : public ChartAxis | |
|
41 | { | |
|
42 | public: | |
|
43 | ChartCategoriesAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
|
44 | ~ChartCategoriesAxisY(); | |
|
45 | ||
|
46 | AxisType axisType() const { return Y_AXIS;} | |
|
47 | ||
|
48 | protected: | |
|
49 | QVector<qreal> calculateLayout() const; | |
|
50 | void updateGeometry(); | |
|
51 | }; | |
|
52 | ||
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
54 | ||
|
55 | #endif /* CHARTCATEGORIESAXISY_H */ |
@@ -0,0 +1,122 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "chartvaluesaxisx_p.h" | |
|
22 | #include "qabstractaxis.h" | |
|
23 | #include "chartpresenter_p.h" | |
|
24 | #include "chartanimator_p.h" | |
|
25 | #include <QGraphicsLayout> | |
|
26 | #include <QDebug> | |
|
27 | #include <QFontMetrics> | |
|
28 | ||
|
29 | static int label_padding = 5; | |
|
30 | ||
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
32 | ||
|
33 | ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | ChartValuesAxisX::~ChartValuesAxisX() | |
|
38 | { | |
|
39 | } | |
|
40 | ||
|
41 | QVector<qreal> ChartValuesAxisX::calculateLayout() const | |
|
42 | { | |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
|
44 | ||
|
45 | QVector<qreal> points; | |
|
46 | points.resize(m_ticksCount); | |
|
47 | ||
|
48 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
|
50 | int x = i * deltaX + m_rect.left(); | |
|
51 | points[i] = x; | |
|
52 | } | |
|
53 | return points; | |
|
54 | } | |
|
55 | ||
|
56 | void ChartValuesAxisX::updateGeometry() | |
|
57 | { | |
|
58 | const QVector<qreal>& layout = ChartAxis::layout(); | |
|
59 | ||
|
60 | m_minWidth = 0; | |
|
61 | m_minHeight = 0; | |
|
62 | ||
|
63 | if(layout.isEmpty()) return; | |
|
64 | ||
|
65 | QStringList ticksList; | |
|
66 | ||
|
67 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
|
68 | ||
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
|
72 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
|
73 | ||
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
|
76 | ||
|
77 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
|
78 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
|
79 | ||
|
80 | qreal width = 0; | |
|
81 | for (int i = 0; i < layout.size(); ++i) { | |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
|
83 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
|
84 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
|
85 | if (!categories || i<1) { | |
|
86 | labelItem->setText(ticksList.at(i)); | |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
|
88 | QPointF center = rect.center(); | |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
|
91 | ||
|
92 | if(labelItem->pos().x()<=width){ | |
|
93 | labelItem->setVisible(false); | |
|
94 | lineItem->setVisible(false); | |
|
95 | }else{ | |
|
96 | labelItem->setVisible(true); | |
|
97 | lineItem->setVisible(true); | |
|
98 | width=rect.width()+labelItem->pos().x(); | |
|
99 | } | |
|
100 | m_minWidth+=rect.width(); | |
|
101 | m_minHeight=qMax(rect.height(),m_minHeight); | |
|
102 | } | |
|
103 | else { | |
|
104 | labelItem->setText(ticksList.at(i)); | |
|
105 | const QRectF& rect = labelItem->boundingRect(); | |
|
106 | QPointF center = rect.center(); | |
|
107 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
108 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
|
109 | m_minWidth+=rect.width(); | |
|
110 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
|
111 | } | |
|
112 | ||
|
113 | if ((i+1)%2 && i>1) { | |
|
114 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
|
115 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
|
116 | } | |
|
117 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
|
118 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
|
119 | } | |
|
120 | } | |
|
121 | ||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,55 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | // W A R N I N G | |
|
22 | // ------------- | |
|
23 | // | |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
|
25 | // implementation detail. This header file may change from version to | |
|
26 | // version without notice, or even be removed. | |
|
27 | // | |
|
28 | // We mean it. | |
|
29 | ||
|
30 | #ifndef CHARTVALUESAXISX_H | |
|
31 | #define CHARTVALUESAXISX_H | |
|
32 | ||
|
33 | #include "chartaxis_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | class QAbstractAxis; | |
|
38 | class ChartPresenter; | |
|
39 | ||
|
40 | class ChartValuesAxisX : public ChartAxis | |
|
41 | { | |
|
42 | public: | |
|
43 | ChartValuesAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
|
44 | ~ChartValuesAxisX(); | |
|
45 | ||
|
46 | AxisType axisType() const { return X_AXIS;} | |
|
47 | ||
|
48 | protected: | |
|
49 | QVector<qreal> calculateLayout() const; | |
|
50 | void updateGeometry(); | |
|
51 | }; | |
|
52 | ||
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
54 | ||
|
55 | #endif /* CHARTVALUESAXISX_H */ |
@@ -0,0 +1,122 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "chartvaluesaxisy_p.h" | |
|
22 | #include "qabstractaxis.h" | |
|
23 | #include "chartpresenter_p.h" | |
|
24 | #include "chartanimator_p.h" | |
|
25 | #include <QGraphicsLayout> | |
|
26 | #include <QDebug> | |
|
27 | #include <QFontMetrics> | |
|
28 | ||
|
29 | static int label_padding = 5; | |
|
30 | ||
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
32 | ||
|
33 | ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | ChartValuesAxisY::~ChartValuesAxisY() | |
|
38 | { | |
|
39 | } | |
|
40 | ||
|
41 | QVector<qreal> ChartValuesAxisY::calculateLayout() const | |
|
42 | { | |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
|
44 | ||
|
45 | QVector<qreal> points; | |
|
46 | points.resize(m_ticksCount); | |
|
47 | ||
|
48 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
|
50 | int x = i * deltaX + m_rect.left(); | |
|
51 | points[i] = x; | |
|
52 | } | |
|
53 | return points; | |
|
54 | } | |
|
55 | ||
|
56 | void ChartValuesAxisY::updateGeometry() | |
|
57 | { | |
|
58 | const QVector<qreal>& layout = ChartAxis::layout(); | |
|
59 | ||
|
60 | m_minWidth = 0; | |
|
61 | m_minHeight = 0; | |
|
62 | ||
|
63 | if(layout.isEmpty()) return; | |
|
64 | ||
|
65 | QStringList ticksList; | |
|
66 | ||
|
67 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
|
68 | ||
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
|
72 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
|
73 | ||
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
|
76 | ||
|
77 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
|
78 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
|
79 | ||
|
80 | qreal width = 0; | |
|
81 | for (int i = 0; i < layout.size(); ++i) { | |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
|
83 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
|
84 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
|
85 | if (!categories || i<1) { | |
|
86 | labelItem->setText(ticksList.at(i)); | |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
|
88 | QPointF center = rect.center(); | |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
|
91 | ||
|
92 | if(labelItem->pos().x()<=width){ | |
|
93 | labelItem->setVisible(false); | |
|
94 | lineItem->setVisible(false); | |
|
95 | }else{ | |
|
96 | labelItem->setVisible(true); | |
|
97 | lineItem->setVisible(true); | |
|
98 | width=rect.width()+labelItem->pos().x(); | |
|
99 | } | |
|
100 | m_minWidth+=rect.width(); | |
|
101 | m_minHeight=qMax(rect.height(),m_minHeight); | |
|
102 | } | |
|
103 | else { | |
|
104 | labelItem->setText(ticksList.at(i)); | |
|
105 | const QRectF& rect = labelItem->boundingRect(); | |
|
106 | QPointF center = rect.center(); | |
|
107 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
108 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
|
109 | m_minWidth+=rect.width(); | |
|
110 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
|
111 | } | |
|
112 | ||
|
113 | if ((i+1)%2 && i>1) { | |
|
114 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
|
115 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
|
116 | } | |
|
117 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
|
118 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
|
119 | } | |
|
120 | } | |
|
121 | ||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,55 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | // W A R N I N G | |
|
22 | // ------------- | |
|
23 | // | |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
|
25 | // implementation detail. This header file may change from version to | |
|
26 | // version without notice, or even be removed. | |
|
27 | // | |
|
28 | // We mean it. | |
|
29 | ||
|
30 | #ifndef CHARTVALUESAXISY_H | |
|
31 | #define CHARTVALUESAXISY_H | |
|
32 | ||
|
33 | #include "chartaxis_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | class QAbstractAxis; | |
|
38 | class ChartPresenter; | |
|
39 | ||
|
40 | class ChartValuesAxisY : public ChartAxis | |
|
41 | { | |
|
42 | public: | |
|
43 | ChartValuesAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
|
44 | ~ChartValuesAxisY(); | |
|
45 | ||
|
46 | AxisType axisType() const { return Y_AXIS;} | |
|
47 | ||
|
48 | protected: | |
|
49 | QVector<qreal> calculateLayout() const; | |
|
50 | void updateGeometry(); | |
|
51 | }; | |
|
52 | ||
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
54 | ||
|
55 | #endif /* CHARTVALUESAXISY_H */ |
@@ -5,7 +5,10 SOURCES += \ | |||
|
5 | 5 | $$PWD/chartaxis.cpp \ |
|
6 | 6 | $$PWD/chartaxisx.cpp \ |
|
7 | 7 | $$PWD/chartaxisy.cpp \ |
|
8 |
|
|
|
8 | $$PWD/chartvaluesaxisx.cpp \ | |
|
9 | $$PWD/chartvaluesaxisy.cpp \ | |
|
10 | $$PWD/chartcategoriesaxisx.cpp \ | |
|
11 | $$PWD/chartcategoriesaxisy.cpp \ | |
|
9 | 12 | $$PWD/qcategoriesaxis.cpp \ |
|
10 | 13 | $$PWD/qvaluesaxis.cpp \ |
|
11 | 14 | $$PWD/qabstractaxis.cpp |
@@ -14,13 +17,15 PRIVATE_HEADERS += \ | |||
|
14 | 17 | $$PWD/chartaxis_p.h \ |
|
15 | 18 | $$PWD/chartaxisx_p.h \ |
|
16 | 19 | $$PWD/chartaxisy_p.h \ |
|
17 |
|
|
|
20 | $$PWD/chartvaluesaxisx_p.h \ | |
|
21 | $$PWD/chartvaluesaxisy_p.h \ | |
|
22 | $$PWD/chartcategoriesaxisx_p.h \ | |
|
23 | $$PWD/chartcategoriesaxisy_p.h \ | |
|
18 | 24 | $$PWD/qcategoriesaxis_p.h \ |
|
19 | 25 | $$PWD/qvaluesaxis_p.h \ |
|
20 | 26 | $$PWD/qabstractaxis_p.h |
|
21 | 27 | |
|
22 | 28 |
PUBLIC_HEADERS += \ |
|
23 | # $$PWD/qaxiscategories.h \ | |
|
24 | 29 | $$PWD/qcategoriesaxis.h \ |
|
25 | 30 | $$PWD/qvaluesaxis.h \ |
|
26 | 31 | $$PWD/qabstractaxis.h |
General Comments 0
You need to be logged in to leave comments.
Login now