@@ -0,0 +1,138 | |||||
|
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 "chartdatetimeaxisx_p.h" | |||
|
22 | #include "qabstractaxis.h" | |||
|
23 | #include "chartpresenter_p.h" | |||
|
24 | #include "chartanimator_p.h" | |||
|
25 | #include "qdatetimeaxis.h" | |||
|
26 | #include <QGraphicsLayout> | |||
|
27 | #include <QDebug> | |||
|
28 | #include <QFontMetrics> | |||
|
29 | #include <cmath> | |||
|
30 | #include <QDateTime> | |||
|
31 | ||||
|
32 | static int label_padding = 5; | |||
|
33 | ||||
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
35 | ||||
|
36 | ChartDateTimeAxisX::ChartDateTimeAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |||
|
37 | m_tickCount(0) | |||
|
38 | { | |||
|
39 | } | |||
|
40 | ||||
|
41 | ChartDateTimeAxisX::~ChartDateTimeAxisX() | |||
|
42 | { | |||
|
43 | } | |||
|
44 | ||||
|
45 | void ChartDateTimeAxisX::createLabels(QStringList &labels,qreal min, qreal max, int ticks) | |||
|
46 | { | |||
|
47 | Q_ASSERT(max>min); | |||
|
48 | Q_ASSERT(ticks>1); | |||
|
49 | ||||
|
50 | QDateTimeAxis *axis = qobject_cast<QDateTimeAxis *>(m_chartAxis); | |||
|
51 | ||||
|
52 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |||
|
53 | n++; | |||
|
54 | for (int i=0; i< ticks; i++) { | |||
|
55 | qreal value = min + (i * (max - min)/ (ticks-1)); | |||
|
56 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(axis->formatString()); | |||
|
57 | } | |||
|
58 | } | |||
|
59 | ||||
|
60 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |||
|
61 | { | |||
|
62 | Q_ASSERT(m_tickCount>=2); | |||
|
63 | ||||
|
64 | QVector<qreal> points; | |||
|
65 | points.resize(m_tickCount); | |||
|
66 | ||||
|
67 | const qreal deltaX = m_rect.width()/(m_tickCount-1); | |||
|
68 | for (int i = 0; i < m_tickCount; ++i) { | |||
|
69 | int x = i * deltaX + m_rect.left(); | |||
|
70 | points[i] = x; | |||
|
71 | } | |||
|
72 | return points; | |||
|
73 | } | |||
|
74 | ||||
|
75 | void ChartDateTimeAxisX::updateGeometry() | |||
|
76 | { | |||
|
77 | const QVector<qreal>& layout = ChartAxis::layout(); | |||
|
78 | ||||
|
79 | m_minWidth = 0; | |||
|
80 | m_minHeight = 0; | |||
|
81 | ||||
|
82 | if(layout.isEmpty()) return; | |||
|
83 | ||||
|
84 | QStringList ticksList; | |||
|
85 | ||||
|
86 | createLabels(ticksList,m_min,m_max,layout.size()); | |||
|
87 | ||||
|
88 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |||
|
89 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |||
|
90 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |||
|
91 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |||
|
92 | ||||
|
93 | Q_ASSERT(labels.size() == ticksList.size()); | |||
|
94 | Q_ASSERT(layout.size() == ticksList.size()); | |||
|
95 | ||||
|
96 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |||
|
97 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |||
|
98 | ||||
|
99 | qreal width = 0; | |||
|
100 | for (int i = 0; i < layout.size(); ++i) { | |||
|
101 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |||
|
102 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |||
|
103 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |||
|
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] - center.x(), m_rect.bottom() + label_padding); | |||
|
109 | ||||
|
110 | if(labelItem->pos().x()<=width){ | |||
|
111 | labelItem->setVisible(false); | |||
|
112 | lineItem->setVisible(false); | |||
|
113 | }else{ | |||
|
114 | labelItem->setVisible(true); | |||
|
115 | lineItem->setVisible(true); | |||
|
116 | width=rect.width()+labelItem->pos().x(); | |||
|
117 | } | |||
|
118 | m_minWidth+=rect.width(); | |||
|
119 | m_minHeight=qMax(rect.height(),m_minHeight); | |||
|
120 | ||||
|
121 | if ((i+1)%2 && i>1) { | |||
|
122 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |||
|
123 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |||
|
124 | } | |||
|
125 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |||
|
126 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |||
|
127 | } | |||
|
128 | } | |||
|
129 | ||||
|
130 | void ChartDateTimeAxisX::handleAxisUpdated() | |||
|
131 | { | |||
|
132 | //TODO:: fix this | |||
|
133 | QDateTimeAxis* axis = qobject_cast<QDateTimeAxis*>(m_chartAxis); | |||
|
134 | m_tickCount = axis->ticksCount(); | |||
|
135 | ChartAxis::handleAxisUpdated(); | |||
|
136 | } | |||
|
137 | ||||
|
138 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,61 | |||||
|
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 CHARTDATETIMEAXISX_H | |||
|
31 | #define CHARTDATETIMEAXISX_H | |||
|
32 | ||||
|
33 | #include "chartaxis_p.h" | |||
|
34 | ||||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
36 | ||||
|
37 | class QAbstractAxis; | |||
|
38 | class ChartPresenter; | |||
|
39 | ||||
|
40 | class ChartDateTimeAxisX : public ChartAxis | |||
|
41 | { | |||
|
42 | public: | |||
|
43 | ChartDateTimeAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |||
|
44 | ~ChartDateTimeAxisX(); | |||
|
45 | ||||
|
46 | AxisType axisType() const { return X_AXIS;} | |||
|
47 | ||||
|
48 | protected: | |||
|
49 | void createLabels(QStringList &labels,qreal min, qreal max, int ticks); | |||
|
50 | void handleAxisUpdated(); | |||
|
51 | QVector<qreal> calculateLayout() const; | |||
|
52 | void updateGeometry(); | |||
|
53 | ||||
|
54 | private: | |||
|
55 | int m_tickCount; | |||
|
56 | ||||
|
57 | }; | |||
|
58 | ||||
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
60 | ||||
|
61 | #endif /* CHARTDATETIMEAXISX_H */ |
@@ -0,0 +1,144 | |||||
|
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 "chartdatetimeaxisy_p.h" | |||
|
22 | #include "qabstractaxis.h" | |||
|
23 | #include "chartpresenter_p.h" | |||
|
24 | #include "chartanimator_p.h" | |||
|
25 | #include "qdatetimeaxis.h" | |||
|
26 | #include <QGraphicsLayout> | |||
|
27 | #include <QDebug> | |||
|
28 | #include <QFontMetrics> | |||
|
29 | #include <cmath> | |||
|
30 | #include <QDateTime> | |||
|
31 | ||||
|
32 | static int label_padding = 5; | |||
|
33 | ||||
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
35 | ||||
|
36 | ChartDateTimeAxisY::ChartDateTimeAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |||
|
37 | m_tickCount(0) | |||
|
38 | { | |||
|
39 | } | |||
|
40 | ||||
|
41 | ChartDateTimeAxisY::~ChartDateTimeAxisY() | |||
|
42 | { | |||
|
43 | } | |||
|
44 | ||||
|
45 | void ChartDateTimeAxisY::createLabels(QStringList &labels,qreal min, qreal max, int ticks) | |||
|
46 | { | |||
|
47 | Q_ASSERT(max>min); | |||
|
48 | Q_ASSERT(ticks>1); | |||
|
49 | ||||
|
50 | QDateTimeAxis *axis = qobject_cast<QDateTimeAxis *>(m_chartAxis); | |||
|
51 | ||||
|
52 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |||
|
53 | n++; | |||
|
54 | for (int i=0; i< ticks; i++) { | |||
|
55 | qreal value = min + (i * (max - min)/ (ticks-1)); | |||
|
56 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(axis->formatString()); | |||
|
57 | } | |||
|
58 | } | |||
|
59 | ||||
|
60 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |||
|
61 | { | |||
|
62 | Q_ASSERT(m_tickCount>=2); | |||
|
63 | ||||
|
64 | QVector<qreal> points; | |||
|
65 | points.resize(m_tickCount); | |||
|
66 | ||||
|
67 | const qreal deltaY = m_rect.height()/(m_tickCount-1); | |||
|
68 | for (int i = 0; i < m_tickCount; ++i) { | |||
|
69 | int y = i * -deltaY + m_rect.bottom(); | |||
|
70 | points[i] = y; | |||
|
71 | } | |||
|
72 | ||||
|
73 | return points; | |||
|
74 | } | |||
|
75 | ||||
|
76 | void ChartDateTimeAxisY::updateGeometry() | |||
|
77 | { | |||
|
78 | const QVector<qreal> &layout = ChartAxis::layout(); | |||
|
79 | m_minWidth = 0; | |||
|
80 | m_minHeight = 0; | |||
|
81 | ||||
|
82 | if(layout.isEmpty()) return; | |||
|
83 | ||||
|
84 | QStringList ticksList; | |||
|
85 | ||||
|
86 | createLabels(ticksList,m_min,m_max,layout.size()); | |||
|
87 | ||||
|
88 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |||
|
89 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |||
|
90 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |||
|
91 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |||
|
92 | ||||
|
93 | Q_ASSERT(labels.size() == ticksList.size()); | |||
|
94 | Q_ASSERT(layout.size() == ticksList.size()); | |||
|
95 | ||||
|
96 | qreal height = 2*m_rect.bottom(); | |||
|
97 | ||||
|
98 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |||
|
99 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |||
|
100 | ||||
|
101 | for (int i = 0; i < layout.size(); ++i) { | |||
|
102 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |||
|
103 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |||
|
104 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |||
|
105 | ||||
|
106 | labelItem->setText(ticksList.at(i)); | |||
|
107 | const QRectF& rect = labelItem->boundingRect(); | |||
|
108 | ||||
|
109 | QPointF center = rect.center(); | |||
|
110 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |||
|
111 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |||
|
112 | ||||
|
113 | if(labelItem->pos().y()+rect.height()>height) { | |||
|
114 | labelItem->setVisible(false); | |||
|
115 | lineItem->setVisible(false); | |||
|
116 | } | |||
|
117 | else { | |||
|
118 | labelItem->setVisible(true); | |||
|
119 | lineItem->setVisible(true); | |||
|
120 | height=labelItem->pos().y(); | |||
|
121 | } | |||
|
122 | ||||
|
123 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); | |||
|
124 | m_minHeight+=rect.height(); | |||
|
125 | ||||
|
126 | if ((i+1)%2 && i>1) { | |||
|
127 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |||
|
128 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |||
|
129 | } | |||
|
130 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |||
|
131 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |||
|
132 | } | |||
|
133 | } | |||
|
134 | ||||
|
135 | void ChartDateTimeAxisY::handleAxisUpdated() | |||
|
136 | { | |||
|
137 | //TODO:: fix this | |||
|
138 | QDateTimeAxis* axis = qobject_cast<QDateTimeAxis*>(m_chartAxis); | |||
|
139 | m_tickCount = axis->ticksCount(); | |||
|
140 | ChartAxis::handleAxisUpdated(); | |||
|
141 | } | |||
|
142 | ||||
|
143 | ||||
|
144 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,59 | |||||
|
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 CHARTDATETIMEAXISY_H | |||
|
31 | #define CHARTDATETIMEAXISY_H | |||
|
32 | ||||
|
33 | #include "chartaxis_p.h" | |||
|
34 | ||||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
36 | ||||
|
37 | class QAbstractAxis; | |||
|
38 | class ChartPresenter; | |||
|
39 | ||||
|
40 | class ChartDateTimeAxisY : public ChartAxis | |||
|
41 | { | |||
|
42 | public: | |||
|
43 | ChartDateTimeAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |||
|
44 | ~ChartDateTimeAxisY(); | |||
|
45 | ||||
|
46 | AxisType axisType() const { return Y_AXIS;} | |||
|
47 | ||||
|
48 | protected: | |||
|
49 | void createLabels(QStringList &labels,qreal min, qreal max, int ticks); | |||
|
50 | QVector<qreal> calculateLayout() const; | |||
|
51 | void updateGeometry(); | |||
|
52 | void handleAxisUpdated(); | |||
|
53 | private: | |||
|
54 | int m_tickCount; | |||
|
55 | }; | |||
|
56 | ||||
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
58 | ||||
|
59 | #endif /* CHARTDATETIMEAXISY_H */ |
@@ -0,0 +1,323 | |||||
|
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 "qdatetimeaxis.h" | |||
|
22 | #include "qdatetimeaxis_p.h" | |||
|
23 | #include "chartdatetimeaxisx_p.h" | |||
|
24 | #include "chartdatetimeaxisy_p.h" | |||
|
25 | #include "domain_p.h" | |||
|
26 | #include <cmath> | |||
|
27 | #include <QDebug> | |||
|
28 | ||||
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
30 | /*! | |||
|
31 | \class QDateTimeAxis | |||
|
32 | \brief The QDateTimeAxis class is used for manipulating chart's axis. | |||
|
33 | \mainclass | |||
|
34 | ||||
|
35 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. | |||
|
36 | Values of axis are drawn to position of ticks | |||
|
37 | */ | |||
|
38 | ||||
|
39 | /*! | |||
|
40 | \qmlclass ValuesAxis QDateTimeAxis | |||
|
41 | \brief The ValuesAxis element is used for manipulating chart's axes | |||
|
42 | ||||
|
43 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |||
|
44 | Values of axis are drawn to position of ticks | |||
|
45 | ||||
|
46 | To access Axes you can use ChartView API. For example: | |||
|
47 | \code | |||
|
48 | ChartView { | |||
|
49 | ValuesAxis { | |||
|
50 | id: xAxis | |||
|
51 | min: 0 | |||
|
52 | max: 10 | |||
|
53 | } | |||
|
54 | // Add a few series... | |||
|
55 | } | |||
|
56 | \endcode | |||
|
57 | */ | |||
|
58 | ||||
|
59 | /*! | |||
|
60 | \property QDateTimeAxis::min | |||
|
61 | Defines the minimum value on the axis. | |||
|
62 | */ | |||
|
63 | /*! | |||
|
64 | \qmlproperty real ValuesAxis::min | |||
|
65 | Defines the minimum value on the axis. | |||
|
66 | */ | |||
|
67 | ||||
|
68 | /*! | |||
|
69 | \property QDateTimeAxis::max | |||
|
70 | Defines the maximum value on the axis. | |||
|
71 | */ | |||
|
72 | /*! | |||
|
73 | \qmlproperty real ValuesAxis::max | |||
|
74 | Defines the maximum value on the axis. | |||
|
75 | */ | |||
|
76 | ||||
|
77 | /*! | |||
|
78 | \fn void QDateTimeAxis::minChanged(qreal min) | |||
|
79 | Axis emits signal when \a min of axis has changed. | |||
|
80 | */ | |||
|
81 | /*! | |||
|
82 | \qmlsignal ValuesAxis::onMinChanged(real min) | |||
|
83 | Axis emits signal when \a min of axis has changed. | |||
|
84 | */ | |||
|
85 | ||||
|
86 | /*! | |||
|
87 | \fn void QDateTimeAxis::maxChanged(qreal max) | |||
|
88 | Axis emits signal when \a max of axis has changed. | |||
|
89 | */ | |||
|
90 | /*! | |||
|
91 | \qmlsignal ValuesAxis::onMaxChanged(real max) | |||
|
92 | Axis emits signal when \a max of axis has changed. | |||
|
93 | */ | |||
|
94 | ||||
|
95 | /*! | |||
|
96 | \fn void QDateTimeAxis::rangeChanged(qreal min, qreal max) | |||
|
97 | Axis emits signal when \a min or \a max of axis has changed. | |||
|
98 | */ | |||
|
99 | ||||
|
100 | /*! | |||
|
101 | \property QDateTimeAxis::ticksCount | |||
|
102 | The number of tick marks for the axis. | |||
|
103 | */ | |||
|
104 | ||||
|
105 | /*! | |||
|
106 | \qmlproperty int ValuesAxis::ticksCount | |||
|
107 | The number of tick marks for the axis. | |||
|
108 | */ | |||
|
109 | ||||
|
110 | /*! | |||
|
111 | \property QDateTimeAxis::niceNumbersEnabled | |||
|
112 | Whether the nice numbers algorithm is enabled or not for the axis. | |||
|
113 | */ | |||
|
114 | ||||
|
115 | /*! | |||
|
116 | \qmlproperty bool ValuesAxis::niceNumbersEnabled | |||
|
117 | Whether the nice numbers algorithm is enabled or not for the axis. | |||
|
118 | */ | |||
|
119 | ||||
|
120 | /*! | |||
|
121 | Constructs an axis object which is a child of \a parent. | |||
|
122 | */ | |||
|
123 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : | |||
|
124 | QAbstractAxis(*new QDateTimeAxisPrivate(this),parent) | |||
|
125 | { | |||
|
126 | ||||
|
127 | } | |||
|
128 | ||||
|
129 | /*! | |||
|
130 | \internal | |||
|
131 | */ | |||
|
132 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |||
|
133 | { | |||
|
134 | ||||
|
135 | } | |||
|
136 | ||||
|
137 | /*! | |||
|
138 | Destroys the object | |||
|
139 | */ | |||
|
140 | QDateTimeAxis::~QDateTimeAxis() | |||
|
141 | { | |||
|
142 | ||||
|
143 | } | |||
|
144 | ||||
|
145 | void QDateTimeAxis::setMin(QDateTime min) | |||
|
146 | { | |||
|
147 | Q_D(QDateTimeAxis); | |||
|
148 | setRange(min,d->m_max); | |||
|
149 | } | |||
|
150 | ||||
|
151 | QDateTime QDateTimeAxis::min() const | |||
|
152 | { | |||
|
153 | Q_D(const QDateTimeAxis); | |||
|
154 | return d->m_min; | |||
|
155 | } | |||
|
156 | ||||
|
157 | void QDateTimeAxis::setMax(QDateTime max) | |||
|
158 | { | |||
|
159 | Q_D(QDateTimeAxis); | |||
|
160 | setRange(d->m_min,max); | |||
|
161 | } | |||
|
162 | ||||
|
163 | QDateTime QDateTimeAxis::max() const | |||
|
164 | { | |||
|
165 | Q_D(const QDateTimeAxis); | |||
|
166 | return d->m_max; | |||
|
167 | } | |||
|
168 | ||||
|
169 | /*! | |||
|
170 | Sets range from \a min to \a max on the axis. | |||
|
171 | */ | |||
|
172 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |||
|
173 | { | |||
|
174 | Q_D(QDateTimeAxis); | |||
|
175 | bool changed = false; | |||
|
176 | ||||
|
177 | if (d->m_min != min) { | |||
|
178 | d->m_min = min; | |||
|
179 | changed = true; | |||
|
180 | emit minChanged(min); | |||
|
181 | } | |||
|
182 | ||||
|
183 | if (d->m_max != max) { | |||
|
184 | d->m_max = max; | |||
|
185 | changed = true; | |||
|
186 | emit maxChanged(max); | |||
|
187 | } | |||
|
188 | ||||
|
189 | // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); | |||
|
190 | ||||
|
191 | if (changed) { | |||
|
192 | emit rangeChanged(d->m_min,d->m_max); | |||
|
193 | d->emitUpdated(); | |||
|
194 | } | |||
|
195 | } | |||
|
196 | ||||
|
197 | void QDateTimeAxis::setFormatString(QString format) | |||
|
198 | { | |||
|
199 | Q_D(QDateTimeAxis); | |||
|
200 | d->m_format = format; | |||
|
201 | } | |||
|
202 | ||||
|
203 | QString QDateTimeAxis::formatString() const | |||
|
204 | { | |||
|
205 | Q_D(const QDateTimeAxis); | |||
|
206 | return d->m_format; | |||
|
207 | } | |||
|
208 | ||||
|
209 | /*! | |||
|
210 | Sets \a count for ticks on the axis. | |||
|
211 | */ | |||
|
212 | void QDateTimeAxis::setTicksCount(int count) | |||
|
213 | { | |||
|
214 | Q_D(QDateTimeAxis); | |||
|
215 | if (d->m_tickCount != count && count >=2) { | |||
|
216 | d->m_tickCount = count; | |||
|
217 | d->emitUpdated(); | |||
|
218 | } | |||
|
219 | } | |||
|
220 | ||||
|
221 | /*! | |||
|
222 | \fn int QDateTimeAxis::ticksCount() const | |||
|
223 | Return number of ticks on the axis | |||
|
224 | */ | |||
|
225 | int QDateTimeAxis::ticksCount() const | |||
|
226 | { | |||
|
227 | Q_D(const QDateTimeAxis); | |||
|
228 | return d->m_tickCount; | |||
|
229 | } | |||
|
230 | ||||
|
231 | /*! | |||
|
232 | Returns the type of the axis | |||
|
233 | */ | |||
|
234 | QAbstractAxis::AxisType QDateTimeAxis::type() const | |||
|
235 | { | |||
|
236 | return AxisTypeDateTime; | |||
|
237 | } | |||
|
238 | ||||
|
239 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
240 | ||||
|
241 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): | |||
|
242 | QAbstractAxisPrivate(q), | |||
|
243 | m_tickCount(5) | |||
|
244 | { | |||
|
245 | m_min = QDateTime::fromMSecsSinceEpoch(0); | |||
|
246 | m_max = QDateTime::fromMSecsSinceEpoch(0); | |||
|
247 | m_format = "hh:mm:ss\ndd-mm-yyyy"; | |||
|
248 | } | |||
|
249 | ||||
|
250 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |||
|
251 | { | |||
|
252 | ||||
|
253 | } | |||
|
254 | ||||
|
255 | void QDateTimeAxisPrivate::handleDomainUpdated() | |||
|
256 | { | |||
|
257 | Q_Q(QDateTimeAxis); | |||
|
258 | Domain* domain = qobject_cast<Domain*>(sender()); | |||
|
259 | Q_ASSERT(domain); | |||
|
260 | ||||
|
261 | if(orientation()==Qt::Horizontal){ | |||
|
262 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |||
|
263 | }else if(orientation()==Qt::Vertical){ | |||
|
264 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |||
|
265 | } | |||
|
266 | } | |||
|
267 | ||||
|
268 | ||||
|
269 | void QDateTimeAxisPrivate::setMin(const QVariant &min) | |||
|
270 | { | |||
|
271 | Q_Q(QDateTimeAxis); | |||
|
272 | if (min.canConvert(QVariant::DateTime)) | |||
|
273 | q->setMin(min.toDateTime()); | |||
|
274 | } | |||
|
275 | ||||
|
276 | void QDateTimeAxisPrivate::setMax(const QVariant &max) | |||
|
277 | { | |||
|
278 | ||||
|
279 | Q_Q(QDateTimeAxis); | |||
|
280 | if (max.canConvert(QVariant::DateTime)) | |||
|
281 | q->setMax(max.toDateTime()); | |||
|
282 | } | |||
|
283 | ||||
|
284 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |||
|
285 | { | |||
|
286 | Q_Q(QDateTimeAxis); | |||
|
287 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) | |||
|
288 | q->setRange(min.toDateTime(), max.toDateTime()); | |||
|
289 | } | |||
|
290 | ||||
|
291 | ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter) | |||
|
292 | { | |||
|
293 | Q_Q(QDateTimeAxis); | |||
|
294 | if(m_orientation == Qt::Vertical){ | |||
|
295 | return new ChartDateTimeAxisY(q,presenter); | |||
|
296 | }else{ | |||
|
297 | return new ChartDateTimeAxisX(q,presenter); | |||
|
298 | } | |||
|
299 | ||||
|
300 | } | |||
|
301 | ||||
|
302 | void QDateTimeAxisPrivate::intializeDomain(Domain* domain) | |||
|
303 | { | |||
|
304 | Q_Q(QDateTimeAxis); | |||
|
305 | if(m_max == m_min) { | |||
|
306 | if(m_orientation==Qt::Vertical){ | |||
|
307 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |||
|
308 | }else{ | |||
|
309 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |||
|
310 | } | |||
|
311 | } else { | |||
|
312 | if(m_orientation==Qt::Vertical){ | |||
|
313 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |||
|
314 | }else{ | |||
|
315 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |||
|
316 | } | |||
|
317 | } | |||
|
318 | } | |||
|
319 | ||||
|
320 | #include "moc_qdatetimeaxis.cpp" | |||
|
321 | #include "moc_qdatetimeaxis_p.cpp" | |||
|
322 | ||||
|
323 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,75 | |||||
|
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 | #ifndef QDATETIMEAXIS_H | |||
|
22 | #define QDATETIMEAXIS_H | |||
|
23 | ||||
|
24 | #include "qabstractaxis.h" | |||
|
25 | ||||
|
26 | class QDateTime; | |||
|
27 | ||||
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
29 | ||||
|
30 | class QDateTimeAxisPrivate; | |||
|
31 | ||||
|
32 | class QTCOMMERCIALCHART_EXPORT QDateTimeAxis : public QAbstractAxis | |||
|
33 | { | |||
|
34 | Q_OBJECT | |||
|
35 | Q_PROPERTY(int ticksCount READ ticksCount WRITE setTicksCount) | |||
|
36 | Q_PROPERTY(QDateTime min READ min WRITE setMin NOTIFY minChanged) | |||
|
37 | Q_PROPERTY(QDateTime max READ max WRITE setMax NOTIFY maxChanged) | |||
|
38 | ||||
|
39 | public: | |||
|
40 | explicit QDateTimeAxis(QObject *parent = 0); | |||
|
41 | ~QDateTimeAxis(); | |||
|
42 | ||||
|
43 | protected: | |||
|
44 | QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent = 0); | |||
|
45 | ||||
|
46 | public: | |||
|
47 | AxisType type() const; | |||
|
48 | ||||
|
49 | //range handling | |||
|
50 | void setMin(QDateTime min); | |||
|
51 | QDateTime min() const; | |||
|
52 | void setMax(QDateTime max); | |||
|
53 | QDateTime max() const; | |||
|
54 | void setRange(QDateTime min, QDateTime max); | |||
|
55 | ||||
|
56 | void setFormatString(QString format); | |||
|
57 | QString formatString() const; | |||
|
58 | ||||
|
59 | //ticks handling | |||
|
60 | void setTicksCount(int count); | |||
|
61 | int ticksCount() const; | |||
|
62 | ||||
|
63 | Q_SIGNALS: | |||
|
64 | void minChanged(QDateTime min); | |||
|
65 | void maxChanged(QDateTime max); | |||
|
66 | void rangeChanged(QDateTime min, QDateTime max); | |||
|
67 | ||||
|
68 | private: | |||
|
69 | Q_DECLARE_PRIVATE(QDateTimeAxis) | |||
|
70 | Q_DISABLE_COPY(QDateTimeAxis) | |||
|
71 | }; | |||
|
72 | ||||
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
74 | ||||
|
75 | #endif // QDATETIMEAXIS_H |
@@ -0,0 +1,69 | |||||
|
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 QVALUESAXIS_P_H | |||
|
31 | #define QVALUESAXIS_P_H | |||
|
32 | ||||
|
33 | #include "qdatetimeaxis.h" | |||
|
34 | #include "qabstractaxis_p.h" | |||
|
35 | #include <QDateTime> | |||
|
36 | ||||
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
38 | ||||
|
39 | class QDateTimeAxisPrivate : public QAbstractAxisPrivate | |||
|
40 | { | |||
|
41 | Q_OBJECT | |||
|
42 | public: | |||
|
43 | QDateTimeAxisPrivate(QDateTimeAxis *q); | |||
|
44 | ~QDateTimeAxisPrivate(); | |||
|
45 | ||||
|
46 | public: | |||
|
47 | ChartAxis* createGraphics(ChartPresenter* presenter); | |||
|
48 | void intializeDomain(Domain* domain); | |||
|
49 | void handleDomainUpdated(); | |||
|
50 | qreal min(){ return m_min.toMSecsSinceEpoch(); } | |||
|
51 | qreal max(){ return m_max.toMSecsSinceEpoch(); } | |||
|
52 | ||||
|
53 | protected: | |||
|
54 | void setMin(const QVariant &min); | |||
|
55 | void setMax(const QVariant &max); | |||
|
56 | void setRange(const QVariant &min, const QVariant &max); | |||
|
57 | int ticksCount() const; | |||
|
58 | ||||
|
59 | protected: | |||
|
60 | QDateTime m_min; | |||
|
61 | QDateTime m_max; | |||
|
62 | int m_tickCount; | |||
|
63 | QString m_format; | |||
|
64 | Q_DECLARE_PUBLIC(QDateTimeAxis) | |||
|
65 | }; | |||
|
66 | ||||
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
68 | ||||
|
69 | #endif // QVALUESAXIS_P_H |
@@ -3,12 +3,14 | |||||
3 | INCLUDEPATH += $$PWD \ |
|
3 | INCLUDEPATH += $$PWD \ | |
4 | $$PWD/valuesaxis \ |
|
4 | $$PWD/valuesaxis \ | |
5 | $$PWD/categoriesaxis \ |
|
5 | $$PWD/categoriesaxis \ | |
6 | $$PWD/intervalsaxis |
|
6 | $$PWD/intervalsaxis \ | |
|
7 | $$PWD/datetimeaxis | |||
7 |
|
8 | |||
8 | DEPENDPATH += $$PWD \ |
|
9 | DEPENDPATH += $$PWD \ | |
9 | $$PWD/valuesaxis \ |
|
10 | $$PWD/valuesaxis \ | |
10 | $$PWD/categoriesaxis \ |
|
11 | $$PWD/categoriesaxis \ | |
11 | $$PWD/intervalsaxis |
|
12 | $$PWD/intervalsaxis \ | |
|
13 | $$PWD/datetimeaxis | |||
12 |
|
14 | |||
13 | SOURCES += \ |
|
15 | SOURCES += \ | |
14 | $$PWD/chartaxis.cpp \ |
|
16 | $$PWD/chartaxis.cpp \ | |
@@ -21,7 +23,10 SOURCES += \ | |||||
21 | $$PWD/categoriesaxis/qbarcategoriesaxis.cpp \ |
|
23 | $$PWD/categoriesaxis/qbarcategoriesaxis.cpp \ | |
22 | $$PWD/intervalsaxis/chartintervalsaxisx.cpp \ |
|
24 | $$PWD/intervalsaxis/chartintervalsaxisx.cpp \ | |
23 | $$PWD/intervalsaxis/chartintervalsaxisy.cpp \ |
|
25 | $$PWD/intervalsaxis/chartintervalsaxisy.cpp \ | |
24 | $$PWD/intervalsaxis/qintervalsaxis.cpp |
|
26 | $$PWD/intervalsaxis/qintervalsaxis.cpp \ | |
|
27 | $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \ | |||
|
28 | $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \ | |||
|
29 | $$PWD/datetimeaxis/qdatetimeaxis.cpp | |||
25 |
|
30 | |||
26 | PRIVATE_HEADERS += \ |
|
31 | PRIVATE_HEADERS += \ | |
27 | $$PWD/chartaxis_p.h \ |
|
32 | $$PWD/chartaxis_p.h \ | |
@@ -34,10 +39,14 PRIVATE_HEADERS += \ | |||||
34 | $$PWD/categoriesaxis/qbarcategoriesaxis_p.h \ |
|
39 | $$PWD/categoriesaxis/qbarcategoriesaxis_p.h \ | |
35 | $$PWD/intervalsaxis/chartintervalsaxisx_p.h \ |
|
40 | $$PWD/intervalsaxis/chartintervalsaxisx_p.h \ | |
36 | $$PWD/intervalsaxis/chartintervalsaxisy_p.h \ |
|
41 | $$PWD/intervalsaxis/chartintervalsaxisy_p.h \ | |
37 | $$PWD/intervalsaxis/qintervalsaxis_p.h |
|
42 | $$PWD/intervalsaxis/qintervalsaxis_p.h \ | |
|
43 | $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \ | |||
|
44 | $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \ | |||
|
45 | $$PWD/datetimeaxis/qdatetimeaxis_p.h | |||
38 |
|
46 | |||
39 | PUBLIC_HEADERS += \ |
|
47 | PUBLIC_HEADERS += \ | |
40 | $$PWD/qabstractaxis.h \ |
|
48 | $$PWD/qabstractaxis.h \ | |
41 | $$PWD/valuesaxis/qvaluesaxis.h \ |
|
49 | $$PWD/valuesaxis/qvaluesaxis.h \ | |
42 | $$PWD/categoriesaxis/qbarcategoriesaxis.h \ |
|
50 | $$PWD/categoriesaxis/qbarcategoriesaxis.h \ | |
43 | $$PWD/intervalsaxis/qintervalsaxis.h |
|
51 | $$PWD/intervalsaxis/qintervalsaxis.h \ | |
|
52 | $$PWD/datetimeaxis/qdatetimeaxis.h |
@@ -27,6 +27,7 | |||||
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 | #include <qmath.h> |
|
29 | #include <qmath.h> | |
|
30 | #include <QDateTime> | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 |
@@ -51,7 +51,8 public: | |||||
51 | AxisTypeNoAxis = 0x0, |
|
51 | AxisTypeNoAxis = 0x0, | |
52 | AxisTypeValues = 0x1, |
|
52 | AxisTypeValues = 0x1, | |
53 | AxisTypeCategories = 0x2, |
|
53 | AxisTypeCategories = 0x2, | |
54 | AxisTypeIntervals = 0x3 |
|
54 | AxisTypeIntervals = 0x3, | |
|
55 | AxisTypeDateTime = 0x4 | |||
55 | }; |
|
56 | }; | |
56 |
|
57 | |||
57 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
58 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
@@ -23,6 +23,8 | |||||
23 | #include "qvaluesaxis.h" |
|
23 | #include "qvaluesaxis.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include "qbarcategoriesaxis.h" | |
25 | #include "qvaluesaxis_p.h" |
|
25 | #include "qvaluesaxis_p.h" | |
|
26 | #include "qintervalsaxis.h" | |||
|
27 | #include "qdatetimeaxis.h" | |||
26 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
27 | #include "qabstractbarseries.h" |
|
29 | #include "qabstractbarseries.h" | |
28 | #include "qstackedbarseries.h" |
|
30 | #include "qstackedbarseries.h" | |
@@ -122,20 +124,20 void ChartDataSet::createDefaultAxes() | |||||
122 |
|
124 | |||
123 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
125 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
124 | while (i.hasNext()) { |
|
126 | while (i.hasNext()) { | |
125 |
|
|
127 | i.next(); | |
126 |
|
|
128 | removeAxes(i.key()); | |
127 | } |
|
129 | } | |
128 |
|
130 | |||
129 | i.toFront(); |
|
131 | i.toFront(); | |
130 |
|
132 | |||
131 | while (i.hasNext()) { |
|
133 | while (i.hasNext()) { | |
132 |
|
|
134 | i.next(); | |
133 |
|
|
135 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
134 |
|
|
136 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
135 |
|
|
137 | if(axisX) typeX&=axisX->type(); | |
136 |
|
|
138 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); | |
137 |
|
|
139 | if(axisY) typeY&=axisY->type(); | |
138 |
|
|
140 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); | |
139 | } |
|
141 | } | |
140 |
|
142 | |||
141 | createAxes(typeX,Qt::Horizontal); |
|
143 | createAxes(typeX,Qt::Horizontal); | |
@@ -174,13 +176,19 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orienta | |||||
174 | QAbstractAxis* axis =0; |
|
176 | QAbstractAxis* axis =0; | |
175 |
|
177 | |||
176 | switch(type) { |
|
178 | switch(type) { | |
177 |
|
|
179 | case QAbstractAxis::AxisTypeValues: | |
178 | axis = new QValuesAxis(this); |
|
180 | axis = new QValuesAxis(this); | |
179 | break; |
|
181 | break; | |
180 |
|
|
182 | case QAbstractAxis::AxisTypeCategories: | |
181 | axis = new QBarCategoriesAxis(this); |
|
183 | axis = new QBarCategoriesAxis(this); | |
182 | break; |
|
184 | break; | |
183 | default: |
|
185 | case QAbstractAxis::AxisTypeIntervals: | |
|
186 | axis = new QIntervalsAxis(this); | |||
|
187 | break; | |||
|
188 | case QAbstractAxis::AxisTypeDateTime: | |||
|
189 | axis = new QDateTimeAxis(this); | |||
|
190 | break; | |||
|
191 | default: | |||
184 | axis = 0; |
|
192 | axis = 0; | |
185 | break; |
|
193 | break; | |
186 | } |
|
194 | } | |
@@ -289,12 +297,12 void ChartDataSet::blockAxisSignals(bool enabled) | |||||
289 | { |
|
297 | { | |
290 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
298 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
291 | while (i.hasNext()) { |
|
299 | while (i.hasNext()) { | |
292 |
|
|
300 | i.next(); | |
293 |
|
|
301 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
294 |
|
|
302 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
295 |
|
|
303 | if(axisX) axisX->d_ptr->blockSignals(enabled); | |
296 |
|
|
304 | if(axisY) axisY->d_ptr->blockSignals(enabled); | |
297 |
|
|
305 | } | |
298 | } |
|
306 | } | |
299 |
|
307 | |||
300 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
308 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
@@ -302,8 +310,8 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |||||
302 | int count=0; |
|
310 | int count=0; | |
303 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
311 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
304 | while (i.hasNext()) { |
|
312 | while (i.hasNext()) { | |
305 |
|
|
313 | i.next(); | |
306 |
|
|
314 | if(i.key()->type()==type) count++; | |
307 | } |
|
315 | } | |
308 | return count; |
|
316 | return count; | |
309 | } |
|
317 | } | |
@@ -323,13 +331,13 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |||||
323 | { |
|
331 | { | |
324 | if(series == 0) { |
|
332 | if(series == 0) { | |
325 |
|
333 | |||
326 |
|
|
334 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); | |
327 |
|
335 | |||
328 |
|
|
336 | while (i.hasNext()) { | |
329 |
|
|
337 | i.next(); | |
330 |
|
|
338 | if(i.value()->isVisible()) return i.value(); | |
331 |
|
|
339 | } | |
332 |
|
|
340 | return 0; | |
333 | } |
|
341 | } | |
334 | return m_seriesAxisXMap.value(series); |
|
342 | return m_seriesAxisXMap.value(series); | |
335 | } |
|
343 | } |
General Comments 0
You need to be logged in to leave comments.
Login now