@@ -1,117 +1,117 | |||||
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 "chartcategoriesaxisx_p.h" |
|
21 | #include "chartcategoriesaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "chartanimator_p.h" |
|
23 | #include "chartanimator_p.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include "qbarcategoriesaxis.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
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 | ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
32 | ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
33 | m_categoriesAxis(axis) |
|
33 | m_categoriesAxis(axis) | |
34 | { |
|
34 | { | |
35 |
|
35 | |||
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | ChartCategoriesAxisX::~ChartCategoriesAxisX() |
|
38 | ChartCategoriesAxisX::~ChartCategoriesAxisX() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QVector<qreal> ChartCategoriesAxisX::calculateLayout() const |
|
42 | QVector<qreal> ChartCategoriesAxisX::calculateLayout() const | |
43 | { |
|
43 | { | |
44 |
Q_ASSERT(m_categoriesAxis->categories().count()>= |
|
44 | Q_ASSERT(m_categoriesAxis->categories().count()>=1); | |
45 |
|
45 | |||
46 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
47 | points.resize(m_categoriesAxis->categories().count()); |
|
47 | points.resize(m_categoriesAxis->categories().count()+1); | |
48 |
|
48 | |||
49 | // TODO: shift logic |
|
49 | // TODO: shift logic | |
50 |
const qreal deltaX = m_rect.width()/(m_categoriesAxis->categories().count() |
|
50 | const qreal deltaX = m_rect.width()/(m_categoriesAxis->categories().count()); | |
51 | for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { |
|
51 | for (int i = 0; i < m_categoriesAxis->categories().count()+1; ++i) { | |
52 | int x = i * deltaX + m_rect.left(); |
|
52 | int x = i * deltaX + m_rect.left(); | |
53 | points[i] = x; |
|
53 | points[i] = x; | |
54 | } |
|
54 | } | |
55 | return points; |
|
55 | return points; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void ChartCategoriesAxisX::updateGeometry() |
|
58 | void ChartCategoriesAxisX::updateGeometry() | |
59 | { |
|
59 | { | |
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
60 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 |
|
61 | |||
62 | m_minWidth = 0; |
|
62 | m_minWidth = 0; | |
63 | m_minHeight = 0; |
|
63 | m_minHeight = 0; | |
64 |
|
64 | |||
65 | if(layout.isEmpty()) return; |
|
65 | if(layout.isEmpty()) return; | |
66 |
|
66 | |||
67 | QStringList ticksList; |
|
67 | QStringList ticksList; | |
68 |
|
68 | |||
69 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); |
|
69 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); | |
70 |
|
70 | |||
71 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
71 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
72 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
72 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
73 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
73 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
74 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
74 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
75 |
|
75 | |||
76 | Q_ASSERT(labels.size() == ticksList.size()); |
|
76 | Q_ASSERT(labels.size()-1 == ticksList.size()); | |
77 | Q_ASSERT(layout.size() == ticksList.size()); |
|
77 | Q_ASSERT(layout.size()-1 == ticksList.size()); | |
78 |
|
78 | |||
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
80 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
80 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
81 |
|
81 | |||
82 | for (int i = 0; i < layout.size(); ++i) { |
|
82 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
84 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | if (i>=1) { |
|
86 | if (i>=1) { | |
87 | labelItem->setText(ticksList.at(i-1)); |
|
87 | labelItem->setText(ticksList.at(i-1)); | |
88 | const QRectF& rect = labelItem->boundingRect(); |
|
88 | const QRectF& rect = labelItem->boundingRect(); | |
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(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
91 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
92 | m_minWidth+=rect.width(); |
|
92 | m_minWidth+=rect.width(); | |
93 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); |
|
93 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
94 | }else{ |
|
94 | }else{ | |
95 | labelItem->setVisible(false); |
|
95 | labelItem->setVisible(false); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | if ((i+1)%2 && i>1) { |
|
98 | if ((i+1)%2 && i>1) { | |
99 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
99 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
100 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
100 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
101 | } |
|
101 | } | |
102 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
102 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
103 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
103 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
104 | } |
|
104 | } | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void ChartCategoriesAxisX::handleAxisUpdated() |
|
107 | void ChartCategoriesAxisX::handleAxisUpdated() | |
108 | { |
|
108 | { | |
109 | if(m_categoriesAxis->categories()!=m_categories) |
|
109 | if(m_categoriesAxis->categories()!=m_categories) | |
110 | { |
|
110 | { | |
111 | m_categories=m_categoriesAxis->categories(); |
|
111 | m_categories=m_categoriesAxis->categories(); | |
112 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); |
|
112 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); | |
113 | } |
|
113 | } | |
114 | ChartAxis::handleAxisUpdated(); |
|
114 | ChartAxis::handleAxisUpdated(); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
117 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,120 | |||||
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 "chartcategoriesaxisy_p.h" |
|
21 | #include "chartcategoriesaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "chartanimator_p.h" |
|
23 | #include "chartanimator_p.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include "qbarcategoriesaxis.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <QBarCategoriesAxis> |
|
27 | #include <QBarCategoriesAxis> | |
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 | ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
33 | ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
34 | m_categoriesAxis(axis) |
|
34 | m_categoriesAxis(axis) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | ChartCategoriesAxisY::~ChartCategoriesAxisY() |
|
38 | ChartCategoriesAxisY::~ChartCategoriesAxisY() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QVector<qreal> ChartCategoriesAxisY::calculateLayout() const |
|
42 | QVector<qreal> ChartCategoriesAxisY::calculateLayout() const | |
43 | { |
|
43 | { | |
44 |
Q_ASSERT(m_categoriesAxis->categories().count()>= |
|
44 | Q_ASSERT(m_categoriesAxis->categories().count()>=1); | |
45 |
|
45 | |||
46 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
47 | points.resize(m_categoriesAxis->categories().count()); |
|
47 | points.resize(m_categoriesAxis->categories().count()+1); | |
48 |
|
48 | |||
49 |
const qreal deltaY = m_rect.height()/(m_categoriesAxis->categories().count() |
|
49 | const qreal deltaY = m_rect.height()/(m_categoriesAxis->categories().count()); | |
50 | for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { |
|
50 | for (int i = 0; i < m_categoriesAxis->categories().count()+1; ++i) { | |
51 | int y = i * -deltaY + m_rect.bottom(); |
|
51 | int y = i * -deltaY + m_rect.bottom(); | |
52 | points[i] = y; |
|
52 | points[i] = y; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | return points; |
|
55 | return points; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void ChartCategoriesAxisY::updateGeometry() |
|
58 | void ChartCategoriesAxisY::updateGeometry() | |
59 | { |
|
59 | { | |
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
60 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 |
|
61 | |||
62 | m_minWidth = 0; |
|
62 | m_minWidth = 0; | |
63 | m_minHeight = 0; |
|
63 | m_minHeight = 0; | |
64 |
|
64 | |||
65 | if(layout.isEmpty()) return; |
|
65 | if(layout.isEmpty()) return; | |
66 |
|
66 | |||
67 | QStringList ticksList; |
|
67 | QStringList ticksList; | |
68 |
|
68 | |||
69 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); |
|
69 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); | |
70 |
|
70 | |||
71 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
71 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
72 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
72 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
73 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
73 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
74 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
74 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
75 |
|
75 | |||
76 | Q_ASSERT(labels.size() == ticksList.size()); |
|
76 | Q_ASSERT(labels.size()-1 == ticksList.size()); | |
77 | Q_ASSERT(layout.size() == ticksList.size()); |
|
77 | Q_ASSERT(layout.size()-1 == ticksList.size()); | |
78 |
|
78 | |||
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
80 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
80 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
81 |
|
81 | |||
82 | for (int i = 0; i < layout.size(); ++i) { |
|
82 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
84 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | if(i>=1){ |
|
86 | if(i>=1){ | |
87 | labelItem->setText(ticksList.at(i-1)); |
|
87 | labelItem->setText(ticksList.at(i-1)); | |
88 | const QRectF& rect = labelItem->boundingRect(); |
|
88 | const QRectF& rect = labelItem->boundingRect(); | |
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] - (layout[i] - layout[i-1])/2 -center.y()); |
|
91 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); | |
92 | m_minWidth+=rect.width(); |
|
92 | m_minWidth+=rect.width(); | |
93 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); |
|
93 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
94 | }else{ |
|
94 | }else{ | |
95 | labelItem->setVisible(false); |
|
95 | labelItem->setVisible(false); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 |
|
98 | |||
99 | if ((i+1)%2 && i>1) { |
|
99 | if ((i+1)%2 && i>1) { | |
100 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
100 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
101 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
101 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
102 | } |
|
102 | } | |
103 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
103 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
104 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
104 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
105 | } |
|
105 | } | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | void ChartCategoriesAxisY::handleAxisUpdated() |
|
109 | void ChartCategoriesAxisY::handleAxisUpdated() | |
110 | { |
|
110 | { | |
111 |
|
111 | |||
112 | if(m_categoriesAxis->categories()!=m_categories) |
|
112 | if(m_categoriesAxis->categories()!=m_categories) | |
113 | { |
|
113 | { | |
114 | m_categories=m_categoriesAxis->categories(); |
|
114 | m_categories=m_categoriesAxis->categories(); | |
115 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); |
|
115 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); | |
116 | } |
|
116 | } | |
117 | ChartAxis::handleAxisUpdated(); |
|
117 | ChartAxis::handleAxisUpdated(); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,427 +1,427 | |||||
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 "qbarcategoriesaxis.h" |
|
21 | #include "qbarcategoriesaxis.h" | |
22 | #include "qbarcategoriesaxis_p.h" |
|
22 | #include "qbarcategoriesaxis_p.h" | |
23 | #include "chartcategoriesaxisx_p.h" |
|
23 | #include "chartcategoriesaxisx_p.h" | |
24 | #include "chartcategoriesaxisy_p.h" |
|
24 | #include "chartcategoriesaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QBarCategoriesAxis |
|
31 | \class QBarCategoriesAxis | |
32 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. |
|
32 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \qmlclass BarCategoriesAxis QBarCategoriesAxis |
|
41 | \qmlclass BarCategoriesAxis QBarCategoriesAxis | |
42 | \brief The Axis element is used for manipulating chart's axes. |
|
42 | \brief The Axis element is used for manipulating chart's axes. | |
43 |
|
43 | |||
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
46 |
|
46 | |||
47 | To access BarCategoriesAxis you can use ChartView API. For example: |
|
47 | To access BarCategoriesAxis you can use ChartView API. For example: | |
48 | \code |
|
48 | \code | |
49 | ChartView { |
|
49 | ChartView { | |
50 | BarCategoriesAxis { |
|
50 | BarCategoriesAxis { | |
51 | id: categoryAxis |
|
51 | id: categoryAxis | |
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
53 | } |
|
53 | } | |
54 | // Add a few series... |
|
54 | // Add a few series... | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QBarCategoriesAxis::categories |
|
60 | \property QBarCategoriesAxis::categories | |
61 | Defines the categories of axis |
|
61 | Defines the categories of axis | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty QStringList BarCategoriesAxis::categories |
|
64 | \qmlproperty QStringList BarCategoriesAxis::categories | |
65 | Defines the categories of axis |
|
65 | Defines the categories of axis | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarCategoriesAxis::min |
|
69 | \property QBarCategoriesAxis::min | |
70 | Defines the minimum value on the axis. |
|
70 | Defines the minimum value on the axis. | |
71 | */ |
|
71 | */ | |
72 | /*! |
|
72 | /*! | |
73 | \qmlproperty QString BarCategoriesAxis::min |
|
73 | \qmlproperty QString BarCategoriesAxis::min | |
74 | Defines the minimum value on the axis. |
|
74 | Defines the minimum value on the axis. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QBarCategoriesAxis::max |
|
78 | \property QBarCategoriesAxis::max | |
79 | Defines the maximum value on the axis. |
|
79 | Defines the maximum value on the axis. | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty QString BarCategoriesAxis::max |
|
82 | \qmlproperty QString BarCategoriesAxis::max | |
83 | Defines the maximum value on the axis. |
|
83 | Defines the maximum value on the axis. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \fn void QBarCategoriesAxis::categoriesChanged() |
|
88 | \fn void QBarCategoriesAxis::categoriesChanged() | |
89 | Axis emits signal when the categories of the axis has changed. |
|
89 | Axis emits signal when the categories of the axis has changed. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \fn void QBarCategoriesAxis::minChanged(const QString &min) |
|
92 | \fn void QBarCategoriesAxis::minChanged(const QString &min) | |
93 | Axis emits signal when \a min of axis has changed. |
|
93 | Axis emits signal when \a min of axis has changed. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) |
|
96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) | |
97 | Axis emits signal when \a min of axis has changed. |
|
97 | Axis emits signal when \a min of axis has changed. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) |
|
101 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) | |
102 | Axis emits signal when \a max of axis has changed. |
|
102 | Axis emits signal when \a max of axis has changed. | |
103 | */ |
|
103 | */ | |
104 | /*! |
|
104 | /*! | |
105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) |
|
105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) | |
106 | Axis emits signal when \a max of axis has changed. |
|
106 | Axis emits signal when \a max of axis has changed. | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) |
|
110 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) | |
111 | Axis emits signal when \a min or \a max of axis has changed. |
|
111 | Axis emits signal when \a min or \a max of axis has changed. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Constructs an axis object which is a child of \a parent. |
|
115 | Constructs an axis object which is a child of \a parent. | |
116 | */ |
|
116 | */ | |
117 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): |
|
117 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): | |
118 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) |
|
118 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Destroys the object |
|
123 | Destroys the object | |
124 | */ |
|
124 | */ | |
125 | QBarCategoriesAxis::~QBarCategoriesAxis() |
|
125 | QBarCategoriesAxis::~QBarCategoriesAxis() | |
126 | { |
|
126 | { | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \internal |
|
130 | \internal | |
131 | */ |
|
131 | */ | |
132 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
132 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) | |
133 | { |
|
133 | { | |
134 |
|
134 | |||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Appends \a categories to axis |
|
138 | Appends \a categories to axis | |
139 | */ |
|
139 | */ | |
140 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
140 | void QBarCategoriesAxis::append(const QStringList &categories) | |
141 | { |
|
141 | { | |
142 | if(categories.isEmpty()) return; |
|
142 | if(categories.isEmpty()) return; | |
143 |
|
143 | |||
144 | Q_D(QBarCategoriesAxis); |
|
144 | Q_D(QBarCategoriesAxis); | |
145 | if (d->m_categories.isEmpty()) { |
|
145 | if (d->m_categories.isEmpty()) { | |
146 | d->m_categories.append(categories); |
|
146 | d->m_categories.append(categories); | |
147 | setRange(categories.first(),categories.last()); |
|
147 | setRange(categories.first(),categories.last()); | |
148 | }else{ |
|
148 | }else{ | |
149 | d->m_categories.append(categories); |
|
149 | d->m_categories.append(categories); | |
150 | } |
|
150 | } | |
151 | emit d->updated(); |
|
151 | emit d->updated(); | |
152 | emit categoriesChanged(); |
|
152 | emit categoriesChanged(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | Appends \a category to axis |
|
156 | Appends \a category to axis | |
157 | */ |
|
157 | */ | |
158 | void QBarCategoriesAxis::append(const QString &category) |
|
158 | void QBarCategoriesAxis::append(const QString &category) | |
159 | { |
|
159 | { | |
160 | Q_D(QBarCategoriesAxis); |
|
160 | Q_D(QBarCategoriesAxis); | |
161 | if (d->m_categories.isEmpty()) { |
|
161 | if (d->m_categories.isEmpty()) { | |
162 | d->m_categories.append(category); |
|
162 | d->m_categories.append(category); | |
163 | setRange(category,category); |
|
163 | setRange(category,category); | |
164 | }else{ |
|
164 | }else{ | |
165 | d->m_categories.append(category); |
|
165 | d->m_categories.append(category); | |
166 | } |
|
166 | } | |
167 | emit d->updated(); |
|
167 | emit d->updated(); | |
168 | emit categoriesChanged(); |
|
168 | emit categoriesChanged(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Removes \a category from axis |
|
172 | Removes \a category from axis | |
173 | */ |
|
173 | */ | |
174 | void QBarCategoriesAxis::remove(const QString &category) |
|
174 | void QBarCategoriesAxis::remove(const QString &category) | |
175 | { |
|
175 | { | |
176 | Q_D(QBarCategoriesAxis); |
|
176 | Q_D(QBarCategoriesAxis); | |
177 | if (d->m_categories.contains(category)) { |
|
177 | if (d->m_categories.contains(category)) { | |
178 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
178 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
179 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
179 | setRange(d->m_categories.first(),d->m_categories.last()); | |
180 | emit d->updated(); |
|
180 | emit d->updated(); | |
181 | emit categoriesChanged(); |
|
181 | emit categoriesChanged(); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Inserts \a category to axis at \a index |
|
186 | Inserts \a category to axis at \a index | |
187 | */ |
|
187 | */ | |
188 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
188 | void QBarCategoriesAxis::insert(int index, const QString &category) | |
189 | { |
|
189 | { | |
190 | Q_D(QBarCategoriesAxis); |
|
190 | Q_D(QBarCategoriesAxis); | |
191 | if (d->m_categories.isEmpty()) { |
|
191 | if (d->m_categories.isEmpty()) { | |
192 | d->m_categories.insert(index,category); |
|
192 | d->m_categories.insert(index,category); | |
193 | setRange(category,category); |
|
193 | setRange(category,category); | |
194 | }else{ |
|
194 | }else{ | |
195 | d->m_categories.insert(index,category); |
|
195 | d->m_categories.insert(index,category); | |
196 | } |
|
196 | } | |
197 | emit d->updated(); |
|
197 | emit d->updated(); | |
198 | emit categoriesChanged(); |
|
198 | emit categoriesChanged(); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | Removes all categories. |
|
202 | Removes all categories. | |
203 | */ |
|
203 | */ | |
204 | void QBarCategoriesAxis::clear() |
|
204 | void QBarCategoriesAxis::clear() | |
205 | { |
|
205 | { | |
206 | Q_D(QBarCategoriesAxis); |
|
206 | Q_D(QBarCategoriesAxis); | |
207 | d->m_categories.clear(); |
|
207 | d->m_categories.clear(); | |
208 | setRange(QString::null,QString::null); |
|
208 | setRange(QString::null,QString::null); | |
209 | emit d->updated(); |
|
209 | emit d->updated(); | |
210 | emit categoriesChanged(); |
|
210 | emit categoriesChanged(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
213 | void QBarCategoriesAxis::setCategories(const QStringList &categories) | |
214 | { |
|
214 | { | |
215 | Q_D(QBarCategoriesAxis); |
|
215 | Q_D(QBarCategoriesAxis); | |
216 | if(d->m_categories!=categories){ |
|
216 | if(d->m_categories!=categories){ | |
217 | d->m_categories = categories; |
|
217 | d->m_categories = categories; | |
218 | setRange(categories.first(),categories.last()); |
|
218 | setRange(categories.first(),categories.last()); | |
219 | emit d->updated(); |
|
219 | emit d->updated(); | |
220 | emit categoriesChanged(); |
|
220 | emit categoriesChanged(); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | QStringList QBarCategoriesAxis::categories() |
|
224 | QStringList QBarCategoriesAxis::categories() | |
225 | { |
|
225 | { | |
226 | Q_D(QBarCategoriesAxis); |
|
226 | Q_D(QBarCategoriesAxis); | |
227 | return d->m_categories; |
|
227 | return d->m_categories; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | Returns number of categories. |
|
231 | Returns number of categories. | |
232 | */ |
|
232 | */ | |
233 | int QBarCategoriesAxis::count() const |
|
233 | int QBarCategoriesAxis::count() const | |
234 | { |
|
234 | { | |
235 | Q_D(const QBarCategoriesAxis); |
|
235 | Q_D(const QBarCategoriesAxis); | |
236 | return d->m_categories.count(); |
|
236 | return d->m_categories.count(); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Returns category at \a index. Index must be valid. |
|
240 | Returns category at \a index. Index must be valid. | |
241 | */ |
|
241 | */ | |
242 | QString QBarCategoriesAxis::at(int index) const |
|
242 | QString QBarCategoriesAxis::at(int index) const | |
243 | { |
|
243 | { | |
244 | Q_D(const QBarCategoriesAxis); |
|
244 | Q_D(const QBarCategoriesAxis); | |
245 | return d->m_categories.at(index); |
|
245 | return d->m_categories.at(index); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | Sets minimum category to \a min. |
|
249 | Sets minimum category to \a min. | |
250 | */ |
|
250 | */ | |
251 | void QBarCategoriesAxis::setMin(const QString& min) |
|
251 | void QBarCategoriesAxis::setMin(const QString& min) | |
252 | { |
|
252 | { | |
253 | Q_D(QBarCategoriesAxis); |
|
253 | Q_D(QBarCategoriesAxis); | |
254 | if (d->m_minCategory!=min && d->m_categories.contains(min)) { |
|
254 | if (d->m_minCategory!=min && d->m_categories.contains(min)) { | |
255 | d->m_minCategory = min; |
|
255 | d->m_minCategory = min; | |
256 | d->emitUpdated(); |
|
256 | d->emitUpdated(); | |
257 | emit minChanged(min); |
|
257 | emit minChanged(min); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | Returns minimum category. |
|
263 | Returns minimum category. | |
264 | */ |
|
264 | */ | |
265 | QString QBarCategoriesAxis::min() const |
|
265 | QString QBarCategoriesAxis::min() const | |
266 | { |
|
266 | { | |
267 | Q_D(const QBarCategoriesAxis); |
|
267 | Q_D(const QBarCategoriesAxis); | |
268 | return d->m_minCategory; |
|
268 | return d->m_minCategory; | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | /*! |
|
271 | /*! | |
272 | Sets maximum category to \a max. |
|
272 | Sets maximum category to \a max. | |
273 | */ |
|
273 | */ | |
274 | void QBarCategoriesAxis::setMax(const QString& max) |
|
274 | void QBarCategoriesAxis::setMax(const QString& max) | |
275 | { |
|
275 | { | |
276 | Q_D(QBarCategoriesAxis); |
|
276 | Q_D(QBarCategoriesAxis); | |
277 | if (d->m_maxCategory!=max && d->m_categories.contains(max)) { |
|
277 | if (d->m_maxCategory!=max && d->m_categories.contains(max)) { | |
278 | d->m_maxCategory = max; |
|
278 | d->m_maxCategory = max; | |
279 | d->emitUpdated(); |
|
279 | d->emitUpdated(); | |
280 | emit maxChanged(max); |
|
280 | emit maxChanged(max); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | /*! |
|
285 | /*! | |
286 | Returns maximum category |
|
286 | Returns maximum category | |
287 | */ |
|
287 | */ | |
288 | QString QBarCategoriesAxis::max() const |
|
288 | QString QBarCategoriesAxis::max() const | |
289 | { |
|
289 | { | |
290 | Q_D(const QBarCategoriesAxis); |
|
290 | Q_D(const QBarCategoriesAxis); | |
291 | return d->m_maxCategory; |
|
291 | return d->m_maxCategory; | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Sets range from \a minCategory to \a maxCategory |
|
295 | Sets range from \a minCategory to \a maxCategory | |
296 | */ |
|
296 | */ | |
297 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
297 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
298 | { |
|
298 | { | |
299 | setMin(minCategory); |
|
299 | setMin(minCategory); | |
300 | setMax(maxCategory); |
|
300 | setMax(maxCategory); | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | /*! |
|
303 | /*! | |
304 | Returns the type of the axis |
|
304 | Returns the type of the axis | |
305 | */ |
|
305 | */ | |
306 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
306 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const | |
307 | { |
|
307 | { | |
308 | return AxisTypeCategories; |
|
308 | return AxisTypeCategories; | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
311 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
312 |
|
312 | |||
313 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
313 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): | |
314 | QAbstractAxisPrivate(q) |
|
314 | QAbstractAxisPrivate(q) | |
315 | { |
|
315 | { | |
316 |
|
316 | |||
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
319 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() | |
320 | { |
|
320 | { | |
321 |
|
321 | |||
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
324 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) | |
325 | { |
|
325 | { | |
326 | setRange(min,m_maxCategory); |
|
326 | setRange(min,m_maxCategory); | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
329 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) | |
330 | { |
|
330 | { | |
331 | setRange(m_minCategory,max); |
|
331 | setRange(m_minCategory,max); | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
334 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
335 | { |
|
335 | { | |
336 | Q_Q(QBarCategoriesAxis); |
|
336 | Q_Q(QBarCategoriesAxis); | |
337 | QString value1 = min.toString(); |
|
337 | QString value1 = min.toString(); | |
338 | QString value2 = max.toString(); |
|
338 | QString value2 = max.toString(); | |
339 | q->setRange(value1,value2); |
|
339 | q->setRange(value1,value2); | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | qreal QBarCategoriesAxisPrivate::min() |
|
342 | qreal QBarCategoriesAxisPrivate::min() | |
343 | { |
|
343 | { | |
344 | //TODO:: cache it |
|
344 | //TODO:: cache it | |
345 |
return m_categories.indexOf(m_minCategory) |
|
345 | return m_categories.indexOf(m_minCategory) - 0.5; | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | qreal QBarCategoriesAxisPrivate::max() |
|
348 | qreal QBarCategoriesAxisPrivate::max() | |
349 | { |
|
349 | { | |
350 | //TODO:: cache it |
|
350 | //TODO:: cache it | |
351 | return m_categories.indexOf(m_maxCategory) + 0.5; |
|
351 | return m_categories.indexOf(m_maxCategory) + 0.5; | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | void QBarCategoriesAxisPrivate::handleDomainUpdated() |
|
354 | void QBarCategoriesAxisPrivate::handleDomainUpdated() | |
355 | { |
|
355 | { | |
356 | // Q_Q(QBarCategoriesAxis); |
|
356 | // Q_Q(QBarCategoriesAxis); | |
357 |
|
357 | |||
358 | // TODO: causes crash in some situations. added to known issues |
|
358 | // TODO: causes crash in some situations. added to known issues | |
359 | /* |
|
359 | /* | |
360 | int minIndex = qFloor(min); |
|
360 | int minIndex = qFloor(min); | |
361 | int maxIndex = qFloor(max); |
|
361 | int maxIndex = qFloor(max); | |
362 |
|
362 | |||
363 | if (minIndex < 0) { |
|
363 | if (minIndex < 0) { | |
364 | minIndex = 0; |
|
364 | minIndex = 0; | |
365 | } |
|
365 | } | |
366 | if (maxIndex > m_categories.count()-1){ |
|
366 | if (maxIndex > m_categories.count()-1){ | |
367 | maxIndex = m_categories.count()-1; |
|
367 | maxIndex = m_categories.count()-1; | |
368 | if (maxIndex<0) { |
|
368 | if (maxIndex<0) { | |
369 | maxIndex = 0; |
|
369 | maxIndex = 0; | |
370 | } |
|
370 | } | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | bool changed = false; |
|
373 | bool changed = false; | |
374 | if (m_minCategory != m_categories.at(minIndex)) { |
|
374 | if (m_minCategory != m_categories.at(minIndex)) { | |
375 | m_minCategory = m_categories.at(minIndex); |
|
375 | m_minCategory = m_categories.at(minIndex); | |
376 | emit q->minChanged(m_minCategory); |
|
376 | emit q->minChanged(m_minCategory); | |
377 | changed = true; |
|
377 | changed = true; | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | if (m_maxCategory != m_categories.at(maxIndex)) { |
|
380 | if (m_maxCategory != m_categories.at(maxIndex)) { | |
381 | m_maxCategory = m_categories.at(maxIndex); |
|
381 | m_maxCategory = m_categories.at(maxIndex); | |
382 | emit q->maxChanged(m_maxCategory); |
|
382 | emit q->maxChanged(m_maxCategory); | |
383 | changed = true; |
|
383 | changed = true; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | if (changed) { |
|
386 | if (changed) { | |
387 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
387 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
388 | } |
|
388 | } | |
389 | */ |
|
389 | */ | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
392 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
393 | { |
|
393 | { | |
394 | Q_Q(QBarCategoriesAxis); |
|
394 | Q_Q(QBarCategoriesAxis); | |
395 | if(m_orientation == Qt::Vertical){ |
|
395 | if(m_orientation == Qt::Vertical){ | |
396 | return new ChartCategoriesAxisY(q,presenter); |
|
396 | return new ChartCategoriesAxisY(q,presenter); | |
397 | }else{ |
|
397 | }else{ | |
398 | return new ChartCategoriesAxisX(q,presenter); |
|
398 | return new ChartCategoriesAxisX(q,presenter); | |
399 | } |
|
399 | } | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | /* |
|
402 | /* | |
403 | void QBarCategoriesAxisPrivate::emitRange() |
|
403 | void QBarCategoriesAxisPrivate::emitRange() | |
404 | { |
|
404 | { | |
405 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); |
|
405 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); | |
406 | } |
|
406 | } | |
407 | */ |
|
407 | */ | |
408 |
|
408 | |||
409 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) |
|
409 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) | |
410 | { |
|
410 | { | |
411 | Q_UNUSED(domain); |
|
411 | Q_UNUSED(domain); | |
412 | // TODO: this causes crash now. added to known issues. |
|
412 | // TODO: this causes crash now. added to known issues. | |
413 | /* |
|
413 | /* | |
414 | if (qFuzzyCompare(m_max, m_min)) { |
|
414 | if (qFuzzyCompare(m_max, m_min)) { | |
415 | if(m_orientation==Qt::Vertical){ |
|
415 | if(m_orientation==Qt::Vertical){ | |
416 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); |
|
416 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); | |
417 | }else{ |
|
417 | }else{ | |
418 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); |
|
418 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); | |
419 | } |
|
419 | } | |
420 | } |
|
420 | } | |
421 | */ |
|
421 | */ | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | #include "moc_qbarcategoriesaxis.cpp" |
|
424 | #include "moc_qbarcategoriesaxis.cpp" | |
425 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
425 | #include "moc_qbarcategoriesaxis_p.cpp" | |
426 |
|
426 | |||
427 | QTCOMMERCIALCHART_END_NAMESPACE |
|
427 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,726 +1,728 | |||||
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 "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 | #include "qvaluesaxis.h" |
|
30 | #include "qvaluesaxis.h" | |
31 | #include "qbarcategoriesaxis.h" |
|
31 | #include "qbarcategoriesaxis.h" | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QAbstractBarSeries |
|
36 | \class QAbstractBarSeries | |
37 | \brief Series for creating a bar chart |
|
37 | \brief Series for creating a bar chart | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
43 | shows the x-values. |
|
43 | shows the x-values. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 | /*! |
|
50 | /*! | |
51 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
51 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
52 | \inherits QAbstractSeries |
|
52 | \inherits QAbstractSeries | |
53 |
|
53 | |||
54 | The following QML shows how to create a simple bar chart: |
|
54 | The following QML shows how to create a simple bar chart: | |
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
56 |
|
56 | |||
57 | \beginfloatleft |
|
57 | \beginfloatleft | |
58 | \image demos_qmlchart6.png |
|
58 | \image demos_qmlchart6.png | |
59 | \endfloat |
|
59 | \endfloat | |
60 | \clearfloat |
|
60 | \clearfloat | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QAbstractBarSeries::barWidth |
|
64 | \property QAbstractBarSeries::barWidth | |
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
68 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
68 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
69 | \sa QBarSeries |
|
69 | \sa QBarSeries | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty real AbstractBarSeries::barWidth |
|
72 | \qmlproperty real AbstractBarSeries::barWidth | |
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
76 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
76 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QAbstractBarSeries::count |
|
80 | \property QAbstractBarSeries::count | |
81 | Holds the number of sets in series. |
|
81 | Holds the number of sets in series. | |
82 | */ |
|
82 | */ | |
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty int AbstractBarSeries::count |
|
84 | \qmlproperty int AbstractBarSeries::count | |
85 | Holds the number of sets in series. |
|
85 | Holds the number of sets in series. | |
86 | */ |
|
86 | */ | |
87 |
|
87 | |||
88 | /*! |
|
88 | /*! | |
89 | \property QAbstractBarSeries::labelsVisible |
|
89 | \property QAbstractBarSeries::labelsVisible | |
90 | Defines the visibility of the labels in series |
|
90 | Defines the visibility of the labels in series | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
93 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
94 | Defines the visibility of the labels in series |
|
94 | Defines the visibility of the labels in series | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
100 | Clicked bar inside set is indexed by \a index |
|
100 | Clicked bar inside set is indexed by \a index | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
105 | Clicked bar inside set is indexed by \a index |
|
105 | Clicked bar inside set is indexed by \a index | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
110 |
|
110 | |||
111 | The signal is emitted if mouse is hovered on top of series. |
|
111 | The signal is emitted if mouse is hovered on top of series. | |
112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | Parameter \a barset is the pointer of barset, where hover happened. | |
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
117 |
|
117 | |||
118 | The signal is emitted if mouse is hovered on top of series. |
|
118 | The signal is emitted if mouse is hovered on top of series. | |
119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | Parameter \a barset is the pointer of barset, where hover happened. | |
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QAbstractBarSeries::countChanged() |
|
124 | \fn void QAbstractBarSeries::countChanged() | |
125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | This signal is emitted when barset count has been changed, for example by append or remove. | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
128 | \qmlsignal AbstractBarSeries::onCountChanged() | |
129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | This signal is emitted when barset count has been changed, for example by append or remove. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
134 | This signal is emitted when labels visibility have changed. |
|
134 | This signal is emitted when labels visibility have changed. | |
135 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | \sa isLabelsVisible(), setLabelsVisible() | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
140 | This signal is emitted when \a sets have been added to the series. |
|
140 | This signal is emitted when \a sets have been added to the series. | |
141 | \sa append(), insert() |
|
141 | \sa append(), insert() | |
142 | */ |
|
142 | */ | |
143 | /*! |
|
143 | /*! | |
144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
145 | Emitted when \a barset has been added to the series. |
|
145 | Emitted when \a barset has been added to the series. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
150 | This signal is emitted when \a sets have been removed from the series. |
|
150 | This signal is emitted when \a sets have been removed from the series. | |
151 | \sa remove() |
|
151 | \sa remove() | |
152 | */ |
|
152 | */ | |
153 | /*! |
|
153 | /*! | |
154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
155 | Emitted when \a barset has been removed from the series. |
|
155 | Emitted when \a barset has been removed from the series. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
160 | Returns bar set at \a index. Returns null if the index is not valid. | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
166 | For example: |
|
166 | For example: | |
167 | \code |
|
167 | \code | |
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
170 | \endcode |
|
170 | \endcode | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
177 | appended. |
|
177 | appended. | |
178 | \sa AbstractBarSeries::append() |
|
178 | \sa AbstractBarSeries::append() | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
183 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
184 | */ |
|
184 | */ | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \qmlmethod AbstractBarSeries::clear() |
|
187 | \qmlmethod AbstractBarSeries::clear() | |
188 | Removes all barsets from the series. |
|
188 | Removes all barsets from the series. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Constructs empty QAbstractBarSeries. |
|
192 | Constructs empty QAbstractBarSeries. | |
193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
193 | QAbstractBarSeries is QObject which is a child of a \a parent. | |
194 | */ |
|
194 | */ | |
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) | |
197 | { |
|
197 | { | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Destructs abstractbarseries and owned barsets. |
|
201 | Destructs abstractbarseries and owned barsets. | |
202 | */ |
|
202 | */ | |
203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
203 | QAbstractBarSeries::~QAbstractBarSeries() | |
204 | { |
|
204 | { | |
205 | Q_D(QAbstractBarSeries); |
|
205 | Q_D(QAbstractBarSeries); | |
206 | if(d->m_dataset){ |
|
206 | if(d->m_dataset){ | |
207 | d->m_dataset->removeSeries(this); |
|
207 | d->m_dataset->removeSeries(this); | |
208 | } |
|
208 | } | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | \internal |
|
212 | \internal | |
213 | */ |
|
213 | */ | |
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
215 | QAbstractSeries(d,parent) |
|
215 | QAbstractSeries(d,parent) | |
216 | { |
|
216 | { | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
223 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
223 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
224 | */ |
|
224 | */ | |
225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
225 | void QAbstractBarSeries::setBarWidth(qreal width) | |
226 | { |
|
226 | { | |
227 | Q_D(QAbstractBarSeries); |
|
227 | Q_D(QAbstractBarSeries); | |
228 | d->setBarWidth(width); |
|
228 | d->setBarWidth(width); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Returns the width of the bars of the series. |
|
232 | Returns the width of the bars of the series. | |
233 | \sa setBarWidth() |
|
233 | \sa setBarWidth() | |
234 | */ |
|
234 | */ | |
235 | qreal QAbstractBarSeries::barWidth() const |
|
235 | qreal QAbstractBarSeries::barWidth() const | |
236 | { |
|
236 | { | |
237 | Q_D(const QAbstractBarSeries); |
|
237 | Q_D(const QAbstractBarSeries); | |
238 | return d->barWidth(); |
|
238 | return d->barWidth(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
243 | Returns true, if appending succeeded. |
|
243 | Returns true, if appending succeeded. | |
244 | */ |
|
244 | */ | |
245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
245 | bool QAbstractBarSeries::append(QBarSet *set) | |
246 | { |
|
246 | { | |
247 | Q_D(QAbstractBarSeries); |
|
247 | Q_D(QAbstractBarSeries); | |
248 | bool success = d->append(set); |
|
248 | bool success = d->append(set); | |
249 | if (success) { |
|
249 | if (success) { | |
250 | QList<QBarSet*> sets; |
|
250 | QList<QBarSet*> sets; | |
251 | sets.append(set); |
|
251 | sets.append(set); | |
252 | emit barsetsAdded(sets); |
|
252 | emit barsetsAdded(sets); | |
253 | emit countChanged(); |
|
253 | emit countChanged(); | |
254 | } |
|
254 | } | |
255 | return success; |
|
255 | return success; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
260 | Returns true, if set was removed. |
|
260 | Returns true, if set was removed. | |
261 | */ |
|
261 | */ | |
262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
262 | bool QAbstractBarSeries::remove(QBarSet *set) | |
263 | { |
|
263 | { | |
264 | Q_D(QAbstractBarSeries); |
|
264 | Q_D(QAbstractBarSeries); | |
265 | bool success = d->remove(set); |
|
265 | bool success = d->remove(set); | |
266 | if (success) { |
|
266 | if (success) { | |
267 | QList<QBarSet*> sets; |
|
267 | QList<QBarSet*> sets; | |
268 | sets.append(set); |
|
268 | sets.append(set); | |
269 | emit barsetsRemoved(sets); |
|
269 | emit barsetsRemoved(sets); | |
270 | emit countChanged(); |
|
270 | emit countChanged(); | |
271 | } |
|
271 | } | |
272 | return success; |
|
272 | return success; | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
276 | Adds a list of barsets to series. Takes ownership of \a sets. | |
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
279 | and function returns false. |
|
279 | and function returns false. | |
280 | */ |
|
280 | */ | |
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
282 | { |
|
282 | { | |
283 | Q_D(QAbstractBarSeries); |
|
283 | Q_D(QAbstractBarSeries); | |
284 | bool success = d->append(sets); |
|
284 | bool success = d->append(sets); | |
285 | if (success) { |
|
285 | if (success) { | |
286 | emit barsetsAdded(sets); |
|
286 | emit barsetsAdded(sets); | |
287 | emit countChanged(); |
|
287 | emit countChanged(); | |
288 | } |
|
288 | } | |
289 | return success; |
|
289 | return success; | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
294 | Returns true, if inserting succeeded. |
|
294 | Returns true, if inserting succeeded. | |
295 |
|
295 | |||
296 | */ |
|
296 | */ | |
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
298 | { |
|
298 | { | |
299 | Q_D(QAbstractBarSeries); |
|
299 | Q_D(QAbstractBarSeries); | |
300 | bool success = d->insert(index, set); |
|
300 | bool success = d->insert(index, set); | |
301 | if (success) { |
|
301 | if (success) { | |
302 | QList<QBarSet*> sets; |
|
302 | QList<QBarSet*> sets; | |
303 | sets.append(set); |
|
303 | sets.append(set); | |
304 | emit barsetsAdded(sets); |
|
304 | emit barsetsAdded(sets); | |
305 | emit countChanged(); |
|
305 | emit countChanged(); | |
306 | } |
|
306 | } | |
307 | return success; |
|
307 | return success; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Removes all of the bar sets from the series |
|
311 | Removes all of the bar sets from the series | |
312 | */ |
|
312 | */ | |
313 | void QAbstractBarSeries::clear() |
|
313 | void QAbstractBarSeries::clear() | |
314 | { |
|
314 | { | |
315 | Q_D(QAbstractBarSeries); |
|
315 | Q_D(QAbstractBarSeries); | |
316 | QList<QBarSet *> sets = barSets(); |
|
316 | QList<QBarSet *> sets = barSets(); | |
317 | bool success = d->remove(sets); |
|
317 | bool success = d->remove(sets); | |
318 | if (success) { |
|
318 | if (success) { | |
319 | emit barsetsRemoved(sets); |
|
319 | emit barsetsRemoved(sets); | |
320 | emit countChanged(); |
|
320 | emit countChanged(); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | Returns number of sets in series. |
|
325 | Returns number of sets in series. | |
326 | */ |
|
326 | */ | |
327 | int QAbstractBarSeries::count() const |
|
327 | int QAbstractBarSeries::count() const | |
328 | { |
|
328 | { | |
329 | Q_D(const QAbstractBarSeries); |
|
329 | Q_D(const QAbstractBarSeries); | |
330 | return d->m_barSets.count(); |
|
330 | return d->m_barSets.count(); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | Returns a list of sets in series. Keeps ownership of sets. |
|
334 | Returns a list of sets in series. Keeps ownership of sets. | |
335 | */ |
|
335 | */ | |
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
337 | { |
|
337 | { | |
338 | Q_D(const QAbstractBarSeries); |
|
338 | Q_D(const QAbstractBarSeries); | |
339 | return d->m_barSets; |
|
339 | return d->m_barSets; | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | /*! |
|
342 | /*! | |
343 | Sets the visibility of labels in series to \a visible |
|
343 | Sets the visibility of labels in series to \a visible | |
344 | */ |
|
344 | */ | |
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | Q_D(QAbstractBarSeries); |
|
347 | Q_D(QAbstractBarSeries); | |
348 | if (d->m_labelsVisible != visible) { |
|
348 | if (d->m_labelsVisible != visible) { | |
349 | d->setLabelsVisible(visible); |
|
349 | d->setLabelsVisible(visible); | |
350 | emit labelsVisibleChanged(); |
|
350 | emit labelsVisibleChanged(); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns the visibility of labels |
|
355 | Returns the visibility of labels | |
356 | */ |
|
356 | */ | |
357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
357 | bool QAbstractBarSeries::isLabelsVisible() const | |
358 | { |
|
358 | { | |
359 | Q_D(const QAbstractBarSeries); |
|
359 | Q_D(const QAbstractBarSeries); | |
360 | return d->m_labelsVisible; |
|
360 | return d->m_labelsVisible; | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
364 |
|
364 | |||
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
366 | QAbstractSeriesPrivate(q), |
|
366 | QAbstractSeriesPrivate(q), | |
367 | m_barWidth(0.5), // Default value is 50% of category width |
|
367 | m_barWidth(0.5), // Default value is 50% of category width | |
368 | m_labelsVisible(false), |
|
368 | m_labelsVisible(false), | |
369 | m_visible(true) |
|
369 | m_visible(true) | |
370 | { |
|
370 | { | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
373 | int QAbstractBarSeriesPrivate::categoryCount() const | |
374 | { |
|
374 | { | |
375 | // No categories defined. return count of longest set. |
|
375 | // No categories defined. return count of longest set. | |
376 | int count = 0; |
|
376 | int count = 0; | |
377 | for (int i=0; i<m_barSets.count(); i++) { |
|
377 | for (int i=0; i<m_barSets.count(); i++) { | |
378 | if (m_barSets.at(i)->count() > count) { |
|
378 | if (m_barSets.at(i)->count() > count) { | |
379 | count = m_barSets.at(i)->count(); |
|
379 | count = m_barSets.at(i)->count(); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | return count; |
|
383 | return count; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
387 | { |
|
387 | { | |
388 | if (width < 0.0) { |
|
388 | if (width < 0.0) { | |
389 | width = 0.0; |
|
389 | width = 0.0; | |
390 | } |
|
390 | } | |
391 | m_barWidth = width; |
|
391 | m_barWidth = width; | |
392 | emit updatedBars(); |
|
392 | emit updatedBars(); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
395 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
396 | { |
|
396 | { | |
397 | return m_barWidth; |
|
397 | return m_barWidth; | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
401 | { |
|
401 | { | |
402 | return m_barSets.at(index); |
|
402 | return m_barSets.at(index); | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
406 | { |
|
406 | { | |
407 | m_visible = visible; |
|
407 | m_visible = visible; | |
408 | emit updatedBars(); |
|
408 | emit updatedBars(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
412 | { |
|
412 | { | |
413 | m_labelsVisible = visible; |
|
413 | m_labelsVisible = visible; | |
414 | emit labelsVisibleChanged(visible); |
|
414 | emit labelsVisibleChanged(visible); | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | qreal QAbstractBarSeriesPrivate::min() |
|
417 | qreal QAbstractBarSeriesPrivate::min() | |
418 | { |
|
418 | { | |
419 | if (m_barSets.count() <= 0) { |
|
419 | if (m_barSets.count() <= 0) { | |
420 | return 0; |
|
420 | return 0; | |
421 | } |
|
421 | } | |
422 | qreal min = INT_MAX; |
|
422 | qreal min = INT_MAX; | |
423 |
|
423 | |||
424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
424 | for (int i = 0; i < m_barSets.count(); i++) { | |
425 | int categoryCount = m_barSets.at(i)->count(); |
|
425 | int categoryCount = m_barSets.at(i)->count(); | |
426 | for (int j = 0; j < categoryCount; j++) { |
|
426 | for (int j = 0; j < categoryCount; j++) { | |
427 | qreal temp = m_barSets.at(i)->at(j); |
|
427 | qreal temp = m_barSets.at(i)->at(j); | |
428 | if (temp < min) |
|
428 | if (temp < min) | |
429 | min = temp; |
|
429 | min = temp; | |
430 | } |
|
430 | } | |
431 | } |
|
431 | } | |
432 | return min; |
|
432 | return min; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | qreal QAbstractBarSeriesPrivate::max() |
|
435 | qreal QAbstractBarSeriesPrivate::max() | |
436 | { |
|
436 | { | |
437 | if (m_barSets.count() <= 0) { |
|
437 | if (m_barSets.count() <= 0) { | |
438 | return 0; |
|
438 | return 0; | |
439 | } |
|
439 | } | |
440 | qreal max = INT_MIN; |
|
440 | qreal max = INT_MIN; | |
441 |
|
441 | |||
442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
442 | for (int i = 0; i < m_barSets.count(); i++) { | |
443 | int categoryCount = m_barSets.at(i)->count(); |
|
443 | int categoryCount = m_barSets.at(i)->count(); | |
444 | for (int j = 0; j < categoryCount; j++) { |
|
444 | for (int j = 0; j < categoryCount; j++) { | |
445 | qreal temp = m_barSets.at(i)->at(j); |
|
445 | qreal temp = m_barSets.at(i)->at(j); | |
446 | if (temp > max) |
|
446 | if (temp > max) | |
447 | max = temp; |
|
447 | max = temp; | |
448 | } |
|
448 | } | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | return max; |
|
451 | return max; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
455 | { |
|
455 | { | |
456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
456 | if ((set < 0) || (set >= m_barSets.count())) { | |
457 | // No set, no value. |
|
457 | // No set, no value. | |
458 | return 0; |
|
458 | return 0; | |
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
460 | // No category, no value. |
|
460 | // No category, no value. | |
461 | return 0; |
|
461 | return 0; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | return m_barSets.at(set)->at(category); |
|
464 | return m_barSets.at(set)->at(category); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
468 | { |
|
468 | { | |
469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
469 | if ((set < 0) || (set >= m_barSets.count())) { | |
470 | // No set, no value. |
|
470 | // No set, no value. | |
471 | return 0; |
|
471 | return 0; | |
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
473 | // No category, no value. |
|
473 | // No category, no value. | |
474 | return 0; |
|
474 | return 0; | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | qreal value = m_barSets.at(set)->at(category); |
|
477 | qreal value = m_barSets.at(set)->at(category); | |
478 | qreal sum = categorySum(category); |
|
478 | qreal sum = categorySum(category); | |
479 | if ( qFuzzyIsNull(sum) ) { |
|
479 | if ( qFuzzyIsNull(sum) ) { | |
480 | return 0; |
|
480 | return 0; | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | return value / sum; |
|
483 | return value / sum; | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
487 | { |
|
487 | { | |
488 | qreal sum(0); |
|
488 | qreal sum(0); | |
489 | int count = m_barSets.count(); // Count sets |
|
489 | int count = m_barSets.count(); // Count sets | |
490 | for (int set = 0; set < count; set++) { |
|
490 | for (int set = 0; set < count; set++) { | |
491 | if (category < m_barSets.at(set)->count()) |
|
491 | if (category < m_barSets.at(set)->count()) | |
492 | sum += m_barSets.at(set)->at(category); |
|
492 | sum += m_barSets.at(set)->at(category); | |
493 | } |
|
493 | } | |
494 | return sum; |
|
494 | return sum; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
498 | { |
|
498 | { | |
499 | qreal sum(0); |
|
499 | qreal sum(0); | |
500 | int count = m_barSets.count(); // Count sets |
|
500 | int count = m_barSets.count(); // Count sets | |
501 | for (int set = 0; set < count; set++) { |
|
501 | for (int set = 0; set < count; set++) { | |
502 | if (category < m_barSets.at(set)->count()) |
|
502 | if (category < m_barSets.at(set)->count()) | |
503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
503 | sum += qAbs(m_barSets.at(set)->at(category)); | |
504 | } |
|
504 | } | |
505 | return sum; |
|
505 | return sum; | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
509 | { |
|
509 | { | |
510 | qreal max = INT_MIN; |
|
510 | qreal max = INT_MIN; | |
511 | int count = categoryCount(); |
|
511 | int count = categoryCount(); | |
512 | for (int i = 0; i < count; i++) { |
|
512 | for (int i = 0; i < count; i++) { | |
513 | qreal sum = categorySum(i); |
|
513 | qreal sum = categorySum(i); | |
514 | if (sum > max) |
|
514 | if (sum > max) | |
515 | max = sum; |
|
515 | max = sum; | |
516 | } |
|
516 | } | |
517 | return max; |
|
517 | return max; | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | qreal QAbstractBarSeriesPrivate::minX() |
|
520 | qreal QAbstractBarSeriesPrivate::minX() | |
521 | { |
|
521 | { | |
522 | if (m_barSets.count() <= 0) { |
|
522 | if (m_barSets.count() <= 0) { | |
523 | return 0; |
|
523 | return 0; | |
524 | } |
|
524 | } | |
525 | qreal min = INT_MAX; |
|
525 | qreal min = INT_MAX; | |
526 |
|
526 | |||
527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
527 | for (int i = 0; i < m_barSets.count(); i++) { | |
528 | int categoryCount = m_barSets.at(i)->count(); |
|
528 | int categoryCount = m_barSets.at(i)->count(); | |
529 | for (int j = 0; j < categoryCount; j++) { |
|
529 | for (int j = 0; j < categoryCount; j++) { | |
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
531 | if (temp < min) |
|
531 | if (temp < min) | |
532 | min = temp; |
|
532 | min = temp; | |
533 | } |
|
533 | } | |
534 | } |
|
534 | } | |
535 | return min; |
|
535 | return min; | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
538 | qreal QAbstractBarSeriesPrivate::maxX() | |
539 | { |
|
539 | { | |
540 | if (m_barSets.count() <= 0) { |
|
540 | if (m_barSets.count() <= 0) { | |
541 | return 0; |
|
541 | return 0; | |
542 | } |
|
542 | } | |
543 | qreal max = INT_MIN; |
|
543 | qreal max = INT_MIN; | |
544 |
|
544 | |||
545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
545 | for (int i = 0; i < m_barSets.count(); i++) { | |
546 | int categoryCount = m_barSets.at(i)->count(); |
|
546 | int categoryCount = m_barSets.at(i)->count(); | |
547 | for (int j = 0; j < categoryCount; j++) { |
|
547 | for (int j = 0; j < categoryCount; j++) { | |
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
549 | if (temp > max) |
|
549 | if (temp > max) | |
550 | max = temp; |
|
550 | max = temp; | |
551 | } |
|
551 | } | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 | return max; |
|
554 | return max; | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 |
|
557 | |||
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
559 | { |
|
559 | { | |
560 | qreal minX(domain.minX()); |
|
560 | qreal minX(domain.minX()); | |
561 | qreal minY(domain.minY()); |
|
561 | qreal minY(domain.minY()); | |
562 | qreal maxX(domain.maxX()); |
|
562 | qreal maxX(domain.maxX()); | |
563 | qreal maxY(domain.maxY()); |
|
563 | qreal maxY(domain.maxY()); | |
564 |
|
564 | |||
565 | qreal seriesMinX = this->minX(); |
|
565 | qreal seriesMinX = this->minX(); | |
566 | qreal seriesMaxX = this->maxX(); |
|
566 | qreal seriesMaxX = this->maxX(); | |
567 | qreal y = max(); |
|
567 | qreal y = max(); | |
568 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
568 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
569 | minY = qMin(minY, y); |
|
569 | minY = qMin(minY, y); | |
570 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
570 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
571 | maxY = qMax(maxY, y); |
|
571 | maxY = qMax(maxY, y); | |
572 |
|
572 | |||
573 | domain.setRange(minX,maxX,minY,maxY); |
|
573 | domain.setRange(minX,maxX,minY,maxY); | |
574 | } |
|
574 | } | |
575 |
|
575 | |||
576 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
576 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
577 | { |
|
577 | { | |
578 | Q_UNUSED(presenter); |
|
578 | Q_UNUSED(presenter); | |
579 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
579 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
580 | return 0; |
|
580 | return 0; | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
583 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
584 | { |
|
584 | { | |
585 | Q_Q(QAbstractBarSeries); |
|
585 | Q_Q(QAbstractBarSeries); | |
586 | QList<LegendMarker*> markers; |
|
586 | QList<LegendMarker*> markers; | |
587 | foreach(QBarSet* set, q->barSets()) { |
|
587 | foreach(QBarSet* set, q->barSets()) { | |
588 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
588 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
589 | markers << marker; |
|
589 | markers << marker; | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | return markers; |
|
592 | return markers; | |
593 | } |
|
593 | } | |
594 |
|
594 | |||
595 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
595 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
596 | { |
|
596 | { | |
597 | Q_Q(QAbstractBarSeries); |
|
597 | Q_Q(QAbstractBarSeries); | |
598 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
598 | if ((m_barSets.contains(set)) || (set == 0)) { | |
599 | // Fail if set is already in list or set is null. |
|
599 | // Fail if set is already in list or set is null. | |
600 | return false; |
|
600 | return false; | |
601 | } |
|
601 | } | |
602 | m_barSets.append(set); |
|
602 | m_barSets.append(set); | |
603 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
603 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
604 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
604 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
605 | emit restructuredBars(); // this notifies barchartitem |
|
605 | emit restructuredBars(); // this notifies barchartitem | |
606 | if (m_dataset) { |
|
606 | if (m_dataset) { | |
607 | m_dataset->updateSeries(q); // this notifies legend |
|
607 | m_dataset->updateSeries(q); // this notifies legend | |
608 | } |
|
608 | } | |
609 | return true; |
|
609 | return true; | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
612 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
613 | { |
|
613 | { | |
614 | Q_Q(QAbstractBarSeries); |
|
614 | Q_Q(QAbstractBarSeries); | |
615 | if (!m_barSets.contains(set)) { |
|
615 | if (!m_barSets.contains(set)) { | |
616 | // Fail if set is not in list |
|
616 | // Fail if set is not in list | |
617 | return false; |
|
617 | return false; | |
618 | } |
|
618 | } | |
619 | m_barSets.removeOne(set); |
|
619 | m_barSets.removeOne(set); | |
620 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
620 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
621 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
621 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
622 | emit restructuredBars(); // this notifies barchartitem |
|
622 | emit restructuredBars(); // this notifies barchartitem | |
623 | if (m_dataset) { |
|
623 | if (m_dataset) { | |
624 | m_dataset->updateSeries(q); // this notifies legend |
|
624 | m_dataset->updateSeries(q); // this notifies legend | |
625 | } |
|
625 | } | |
626 | return true; |
|
626 | return true; | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
629 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
630 | { |
|
630 | { | |
631 | Q_Q(QAbstractBarSeries); |
|
631 | Q_Q(QAbstractBarSeries); | |
632 | foreach (QBarSet* set, sets) { |
|
632 | foreach (QBarSet* set, sets) { | |
633 | if ((set == 0) || (m_barSets.contains(set))) { |
|
633 | if ((set == 0) || (m_barSets.contains(set))) { | |
634 | // Fail if any of the sets is null or is already appended. |
|
634 | // Fail if any of the sets is null or is already appended. | |
635 | return false; |
|
635 | return false; | |
636 | } |
|
636 | } | |
637 | if (sets.count(set) != 1) { |
|
637 | if (sets.count(set) != 1) { | |
638 | // Also fail if same set is more than once in given list. |
|
638 | // Also fail if same set is more than once in given list. | |
639 | return false; |
|
639 | return false; | |
640 | } |
|
640 | } | |
641 | } |
|
641 | } | |
642 |
|
642 | |||
643 | foreach (QBarSet* set, sets) { |
|
643 | foreach (QBarSet* set, sets) { | |
644 | m_barSets.append(set); |
|
644 | m_barSets.append(set); | |
645 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
645 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
646 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
646 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
647 | } |
|
647 | } | |
648 | emit restructuredBars(); // this notifies barchartitem |
|
648 | emit restructuredBars(); // this notifies barchartitem | |
649 | if (m_dataset) { |
|
649 | if (m_dataset) { | |
650 | m_dataset->updateSeries(q); // this notifies legend |
|
650 | m_dataset->updateSeries(q); // this notifies legend | |
651 | } |
|
651 | } | |
652 | return true; |
|
652 | return true; | |
653 | } |
|
653 | } | |
654 |
|
654 | |||
655 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
655 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
656 | { |
|
656 | { | |
657 | Q_Q(QAbstractBarSeries); |
|
657 | Q_Q(QAbstractBarSeries); | |
658 | if (sets.count() == 0) { |
|
658 | if (sets.count() == 0) { | |
659 | return false; |
|
659 | return false; | |
660 | } |
|
660 | } | |
661 | foreach (QBarSet* set, sets) { |
|
661 | foreach (QBarSet* set, sets) { | |
662 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
662 | if ((set == 0) || (!m_barSets.contains(set))) { | |
663 | // Fail if any of the sets is null or is not in series |
|
663 | // Fail if any of the sets is null or is not in series | |
664 | return false; |
|
664 | return false; | |
665 | } |
|
665 | } | |
666 | if (sets.count(set) != 1) { |
|
666 | if (sets.count(set) != 1) { | |
667 | // Also fail if same set is more than once in given list. |
|
667 | // Also fail if same set is more than once in given list. | |
668 | return false; |
|
668 | return false; | |
669 | } |
|
669 | } | |
670 | } |
|
670 | } | |
671 |
|
671 | |||
672 | foreach (QBarSet* set, sets) { |
|
672 | foreach (QBarSet* set, sets) { | |
673 | m_barSets.removeOne(set); |
|
673 | m_barSets.removeOne(set); | |
674 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
674 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
675 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
675 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
676 | } |
|
676 | } | |
677 |
|
677 | |||
678 | emit restructuredBars(); // this notifies barchartitem |
|
678 | emit restructuredBars(); // this notifies barchartitem | |
679 | if (m_dataset) { |
|
679 | if (m_dataset) { | |
680 | m_dataset->updateSeries(q); // this notifies legend |
|
680 | m_dataset->updateSeries(q); // this notifies legend | |
681 | } |
|
681 | } | |
682 | return true; |
|
682 | return true; | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
685 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
686 | { |
|
686 | { | |
687 | Q_Q(QAbstractBarSeries); |
|
687 | Q_Q(QAbstractBarSeries); | |
688 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
688 | if ((m_barSets.contains(set)) || (set == 0)) { | |
689 | // Fail if set is already in list or set is null. |
|
689 | // Fail if set is already in list or set is null. | |
690 | return false; |
|
690 | return false; | |
691 | } |
|
691 | } | |
692 | m_barSets.insert(index, set); |
|
692 | m_barSets.insert(index, set); | |
693 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
693 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
694 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
694 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
695 | emit restructuredBars(); // this notifies barchartitem |
|
695 | emit restructuredBars(); // this notifies barchartitem | |
696 | if (m_dataset) { |
|
696 | if (m_dataset) { | |
697 | m_dataset->updateSeries(q); // this notifies legend |
|
697 | m_dataset->updateSeries(q); // this notifies legend | |
698 | } |
|
698 | } | |
699 | return true; |
|
699 | return true; | |
700 | } |
|
700 | } | |
701 |
|
701 | |||
702 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
702 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
703 | { |
|
703 | { | |
704 | if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Horizontal) |
|
704 | if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Horizontal) | |
705 | { |
|
705 | { | |
706 | QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
706 | QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis); | |
707 | Q_ASSERT(cataxis); |
|
707 | Q_ASSERT(cataxis); | |
708 | QStringList categories; |
|
708 | QStringList categories; | |
|
709 | if(cataxis->categories().isEmpty()){ | |||
709 | for (int i(1); i < categoryCount()+1; i++) |
|
710 | for (int i(1); i < categoryCount()+1; i++) | |
710 | categories << QString::number(i); |
|
711 | categories << QString::number(i); | |
711 | cataxis->append(categories); |
|
712 | cataxis->append(categories); | |
712 | } |
|
713 | } | |
713 | } |
|
714 | } | |
|
715 | } | |||
714 |
|
716 | |||
715 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
717 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
716 | { |
|
718 | { | |
717 | Q_UNUSED(orientation); |
|
719 | Q_UNUSED(orientation); | |
718 | return QAbstractAxis::AxisTypeNoAxis; |
|
720 | return QAbstractAxis::AxisTypeNoAxis; | |
719 | } |
|
721 | } | |
720 |
|
722 | |||
721 |
|
723 | |||
722 | #include "moc_qabstractbarseries.cpp" |
|
724 | #include "moc_qabstractbarseries.cpp" | |
723 | #include "moc_qabstractbarseries_p.cpp" |
|
725 | #include "moc_qabstractbarseries_p.cpp" | |
724 |
|
726 | |||
725 |
|
727 | |||
726 | QTCOMMERCIALCHART_END_NAMESPACE |
|
728 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,89 | |||||
1 | #include "qhorizontalbarseries.h" |
|
1 | #include "qhorizontalbarseries.h" | |
2 | #include "qhorizontalbarseries_p.h" |
|
2 | #include "qhorizontalbarseries_p.h" | |
3 | #include "horizontalbarchartitem_p.h" |
|
3 | #include "horizontalbarchartitem_p.h" | |
4 | #include "horizontalbaranimation_p.h" |
|
4 | #include "horizontalbaranimation_p.h" | |
5 | #include "qbarcategoriesaxis.h" |
|
5 | #include "qbarcategoriesaxis.h" | |
6 |
|
6 | |||
7 | #include "chartdataset_p.h" |
|
7 | #include "chartdataset_p.h" | |
8 | #include "charttheme_p.h" |
|
8 | #include "charttheme_p.h" | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : |
|
13 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) : | |
14 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) |
|
14 | QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const |
|
18 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const | |
19 | { |
|
19 | { | |
20 | return QAbstractSeries::SeriesTypeHorizontalBar; |
|
20 | return QAbstractSeries::SeriesTypeHorizontalBar; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 |
|
23 | |||
24 |
|
24 | |||
25 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
26 |
|
26 | |||
27 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
27 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
28 | { |
|
28 | { | |
29 |
|
29 | |||
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) |
|
32 | void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain) | |
33 | { |
|
33 | { | |
34 | qreal minX(domain.minX()); |
|
34 | qreal minX(domain.minX()); | |
35 | qreal minY(domain.minY()); |
|
35 | qreal minY(domain.minY()); | |
36 | qreal maxX(domain.maxX()); |
|
36 | qreal maxX(domain.maxX()); | |
37 | qreal maxY(domain.maxY()); |
|
37 | qreal maxY(domain.maxY()); | |
38 |
|
38 | |||
39 | qreal y = categoryCount(); |
|
39 | qreal y = categoryCount(); | |
40 | qreal x = max(); |
|
40 | qreal x = max(); | |
41 | minX = qMin(minX, x); |
|
41 | minX = qMin(minX, x); | |
42 | minY = qMin(minY, - (qreal)0.5); |
|
42 | minY = qMin(minY, - (qreal)0.5); | |
43 | maxX = qMax(maxX, x); |
|
43 | maxX = qMax(maxX, x); | |
44 | maxY = qMax(maxY, y - (qreal)0.5); |
|
44 | maxY = qMax(maxY, y - (qreal)0.5); | |
45 |
|
45 | |||
46 | domain.setRange(minX,maxX,minY,maxY); |
|
46 | domain.setRange(minX,maxX,minY,maxY); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
50 | Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
51 | { |
|
51 | { | |
52 | Q_Q(QHorizontalBarSeries); |
|
52 | Q_Q(QHorizontalBarSeries); | |
53 |
|
53 | |||
54 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); |
|
54 | HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); | |
55 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
55 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
56 | bar->setAnimator(presenter->animator()); |
|
56 | bar->setAnimator(presenter->animator()); | |
57 | bar->setAnimation(new HorizontalBarAnimation(bar)); |
|
57 | bar->setAnimation(new HorizontalBarAnimation(bar)); | |
58 | } |
|
58 | } | |
59 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
59 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
60 | return bar; |
|
60 | return bar; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void QHorizontalBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
63 | void QHorizontalBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
64 | { |
|
64 | { | |
65 |
|
65 | |||
66 | if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Vertical) |
|
66 | if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Vertical) | |
67 | { |
|
67 | { | |
68 | QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
68 | QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis); | |
69 | Q_ASSERT(cataxis); |
|
69 | Q_ASSERT(cataxis); | |
70 | QStringList categories; |
|
70 | QStringList categories; | |
|
71 | if(cataxis->categories().isEmpty()){ | |||
71 | for (int i(1); i < categoryCount()+1; i++) |
|
72 | for (int i(1); i < categoryCount()+1; i++) | |
72 | categories << QString::number(i); |
|
73 | categories << QString::number(i); | |
73 | cataxis->append(categories); |
|
74 | cataxis->append(categories); | |
74 | } |
|
75 | } | |
75 | } |
|
76 | } | |
|
77 | } | |||
76 |
|
78 | |||
77 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
79 | QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
78 | { |
|
80 | { | |
79 | if(orientation==Qt::Vertical) |
|
81 | if(orientation==Qt::Vertical) | |
80 | return QAbstractAxis::AxisTypeCategories; |
|
82 | return QAbstractAxis::AxisTypeCategories; | |
81 | else |
|
83 | else | |
82 | return QAbstractAxis::AxisTypeValues; |
|
84 | return QAbstractAxis::AxisTypeValues; | |
83 | } |
|
85 | } | |
84 |
|
86 | |||
85 | #include "moc_qhorizontalbarseries.cpp" |
|
87 | #include "moc_qhorizontalbarseries.cpp" | |
86 |
|
88 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,62 | |||||
1 | #include "qhorizontalpercentbarseries.h" |
|
1 | #include "qhorizontalpercentbarseries.h" | |
2 | #include "qhorizontalpercentbarseries_p.h" |
|
2 | #include "qhorizontalpercentbarseries_p.h" | |
3 | #include "horizontalpercentbarchartitem_p.h" |
|
3 | #include "horizontalpercentbarchartitem_p.h" | |
4 | #include "horizontalpercentbaranimation_p.h" |
|
4 | #include "horizontalpercentbaranimation_p.h" | |
5 |
|
5 | |||
6 | #include "chartdataset_p.h" |
|
6 | #include "chartdataset_p.h" | |
7 | #include "charttheme_p.h" |
|
7 | #include "charttheme_p.h" | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) : |
|
11 | QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) : | |
12 | QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent) |
|
12 | QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent) | |
13 | { |
|
13 | { | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const |
|
16 | QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const | |
17 | { |
|
17 | { | |
18 | return QAbstractSeries::SeriesTypeHorizontalPercentBar; |
|
18 | return QAbstractSeries::SeriesTypeHorizontalPercentBar; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 |
|
21 | |||
22 |
|
22 | |||
23 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
24 |
|
24 | |||
25 | QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
25 | QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
26 | { |
|
26 | { | |
27 |
|
27 | |||
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | void QHorizontalPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
30 | void QHorizontalPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
31 | { |
|
31 | { | |
32 | qreal minX(domain.minX()); |
|
32 | qreal minX(domain.minX()); | |
33 | qreal minY(domain.minY()); |
|
33 | qreal minY(domain.minY()); | |
34 | qreal maxX(domain.maxX()); |
|
34 | qreal maxX(domain.maxX()); | |
35 | qreal maxY(domain.maxY()); |
|
35 | qreal maxY(domain.maxY()); | |
36 |
|
36 | |||
37 | qreal y = categoryCount(); |
|
37 | qreal y = categoryCount(); | |
38 | minX = 0; |
|
38 | minX = 0; | |
39 | maxX = 100; |
|
39 | maxX = 100; | |
40 | minY = qMin(minY, - (qreal)0.5); |
|
40 | minY = qMin(minY, - (qreal)0.5); | |
41 | maxY = qMax(maxY, y - (qreal)0.5); |
|
41 | maxY = qMax(maxY, y - (qreal)0.5); | |
42 |
|
42 | |||
43 | domain.setRange(minX,maxX,minY,maxY); |
|
43 | domain.setRange(minX,maxX,minY,maxY); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
46 | Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
47 | { |
|
47 | { | |
48 | Q_Q(QHorizontalPercentBarSeries); |
|
48 | Q_Q(QHorizontalPercentBarSeries); | |
49 |
|
49 | |||
50 | HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter); |
|
50 | HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter); | |
51 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
51 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
52 | bar->setAnimator(presenter->animator()); |
|
52 | bar->setAnimator(presenter->animator()); | |
53 | bar->setAnimation(new HorizontalPercentBarAnimation(bar)); |
|
53 | bar->setAnimation(new HorizontalPercentBarAnimation(bar)); | |
54 | } |
|
54 | } | |
55 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
55 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
56 | return bar; |
|
56 | return bar; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisXType() const |
|
|||
60 | { |
|
|||
61 | return QAbstractAxis::AxisTypeValues; |
|
|||
62 | } |
|
|||
63 |
|
||||
64 | QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisYType() const |
|
|||
65 | { |
|
|||
66 | return QAbstractAxis::AxisTypeCategories; |
|
|||
67 | } |
|
|||
68 |
|
||||
69 |
|
59 | |||
70 | #include "moc_qhorizontalpercentbarseries.cpp" |
|
60 | #include "moc_qhorizontalpercentbarseries.cpp" | |
71 |
|
61 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
62 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,51 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
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 |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QHORIZONTALPERCENTBARSERIES_P_H |
|
30 | #ifndef QHORIZONTALPERCENTBARSERIES_P_H | |
31 | #define QHORIZONTALPERCENTBARSERIES_P_H |
|
31 | #define QHORIZONTALPERCENTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractbarseries_p.h" |
|
33 | #include "qabstractbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
38 | class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate | |
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries* q); |
|
41 | QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries* q); | |
42 | Chart* createGraphics(ChartPresenter* presenter); |
|
42 | Chart* createGraphics(ChartPresenter* presenter); | |
43 | void scaleDomain(Domain& domain); |
|
43 | void scaleDomain(Domain& domain); | |
44 | QAbstractAxis::AxisType defaultAxisXType() const; |
|
|||
45 | QAbstractAxis::AxisType defaultAxisYType() const; |
|
|||
46 |
|
44 | |||
47 | private: |
|
45 | private: | |
48 | Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries) |
|
46 | Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries) | |
49 | }; |
|
47 | }; | |
50 |
|
48 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
50 | |||
53 | #endif // QHORIZONTALPERCENTBARSERIES_P_H |
|
51 | #endif // QHORIZONTALPERCENTBARSERIES_P_H |
@@ -1,434 +1,433 | |||||
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 "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
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 "qabstractseries_p.h" |
|
26 | #include "qabstractseries_p.h" | |
27 | #include "qabstractbarseries.h" |
|
27 | #include "qabstractbarseries.h" | |
28 | #include "qstackedbarseries.h" |
|
28 | #include "qstackedbarseries.h" | |
29 | #include "qpercentbarseries.h" |
|
29 | #include "qpercentbarseries.h" | |
30 | #include "qpieseries.h" |
|
30 | #include "qpieseries.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) |
|
34 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) | |
35 | { |
|
35 | { | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDataSet::~ChartDataSet() |
|
39 | ChartDataSet::~ChartDataSet() | |
40 | { |
|
40 | { | |
41 | removeAllSeries(); |
|
41 | removeAllSeries(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
44 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
45 | { |
|
45 | { | |
46 | Domain* domain = m_seriesDomainMap.value(series); |
|
46 | Domain* domain = m_seriesDomainMap.value(series); | |
47 |
|
47 | |||
48 | if(domain) { |
|
48 | if(domain) { | |
49 | qWarning() << "Can not add series. Series already on the chart"; |
|
49 | qWarning() << "Can not add series. Series already on the chart"; | |
50 | return; |
|
50 | return; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | domain = new Domain(series); |
|
53 | domain = new Domain(series); | |
54 | m_seriesDomainMap.insert(series,domain); |
|
54 | m_seriesDomainMap.insert(series,domain); | |
55 | series->d_ptr->scaleDomain(*domain); |
|
55 | series->d_ptr->scaleDomain(*domain); | |
56 |
|
56 | |||
57 | createSeriesIndex(series); |
|
57 | createSeriesIndex(series); | |
58 |
|
58 | |||
59 | series->setParent(this); // take ownership |
|
59 | series->setParent(this); // take ownership | |
60 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
60 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
61 | series->d_ptr->m_dataset = this; |
|
61 | series->d_ptr->m_dataset = this; | |
62 |
|
62 | |||
63 | emit seriesAdded(series,domain); |
|
63 | emit seriesAdded(series,domain); | |
64 |
|
64 | |||
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
67 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | if(!m_seriesDomainMap.contains(series)) { |
|
70 | if(!m_seriesDomainMap.contains(series)) { | |
71 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
71 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
72 | return; |
|
72 | return; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | emit seriesRemoved(series); |
|
75 | emit seriesRemoved(series); | |
76 |
|
76 | |||
77 | Domain* domain = m_seriesDomainMap.take(series); |
|
77 | Domain* domain = m_seriesDomainMap.take(series); | |
78 | delete domain; |
|
78 | delete domain; | |
79 | domain = 0; |
|
79 | domain = 0; | |
80 |
|
80 | |||
81 | removeSeriesIndex(series); |
|
81 | removeSeriesIndex(series); | |
82 |
|
82 | |||
83 | series->setParent(0); |
|
83 | series->setParent(0); | |
84 | series->d_ptr->m_chart = 0; |
|
84 | series->d_ptr->m_chart = 0; | |
85 | series->d_ptr->m_dataset = 0; |
|
85 | series->d_ptr->m_dataset = 0; | |
86 |
|
86 | |||
87 | removeAxes(series); |
|
87 | removeAxes(series); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 |
|
90 | |||
91 |
|
91 | |||
92 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) |
|
92 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) | |
93 | { |
|
93 | { | |
94 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
94 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
95 |
|
95 | |||
96 | int key=0; |
|
96 | int key=0; | |
97 | while (i.hasNext()) { |
|
97 | while (i.hasNext()) { | |
98 | i.next(); |
|
98 | i.next(); | |
99 | if(i.key()!=key) { |
|
99 | if(i.key()!=key) { | |
100 | break; |
|
100 | break; | |
101 | } |
|
101 | } | |
102 | key++; |
|
102 | key++; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | m_indexSeriesMap.insert(key,series); |
|
105 | m_indexSeriesMap.insert(key,series); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) |
|
108 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) | |
109 | { |
|
109 | { | |
110 | int key = seriesIndex(series); |
|
110 | int key = seriesIndex(series); | |
111 | Q_ASSERT(key!=-1); |
|
111 | Q_ASSERT(key!=-1); | |
112 | m_indexSeriesMap.remove(key); |
|
112 | m_indexSeriesMap.remove(key); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void ChartDataSet::createDefaultAxes() |
|
115 | void ChartDataSet::createDefaultAxes() | |
116 | { |
|
116 | { | |
117 |
|
117 | |||
118 | if(m_seriesDomainMap.isEmpty()) return; |
|
118 | if(m_seriesDomainMap.isEmpty()) return; | |
119 |
|
119 | |||
120 | QAbstractAxis::AxisTypes typeX(0); |
|
120 | QAbstractAxis::AxisTypes typeX(0); | |
121 | QAbstractAxis::AxisTypes typeY(0); |
|
121 | QAbstractAxis::AxisTypes typeY(0); | |
122 |
|
122 | |||
123 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
123 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
124 | while (i.hasNext()) { |
|
124 | while (i.hasNext()) { | |
125 | i.next(); |
|
125 | i.next(); | |
126 | removeAxes(i.key()); |
|
126 | removeAxes(i.key()); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | i.toFront(); |
|
129 | i.toFront(); | |
130 |
|
130 | |||
131 | while (i.hasNext()) { |
|
131 | while (i.hasNext()) { | |
132 | i.next(); |
|
132 | i.next(); | |
133 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
133 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
134 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
134 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
135 | if(axisX) typeX&=axisX->type(); |
|
135 | if(axisX) typeX&=axisX->type(); | |
136 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
136 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); | |
137 | if(axisY) typeY&=axisY->type(); |
|
137 | if(axisY) typeY&=axisY->type(); | |
138 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
138 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | createAxes(typeX,Qt::Horizontal); |
|
141 | createAxes(typeX,Qt::Horizontal); | |
142 | createAxes(typeY,Qt::Vertical); |
|
142 | createAxes(typeY,Qt::Vertical); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) |
|
145 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) | |
146 | { |
|
146 | { | |
147 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
147 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
148 |
|
148 | |||
149 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) |
|
149 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) | |
150 | { |
|
150 | { | |
151 | while (i.hasNext()) { |
|
151 | while (i.hasNext()) { | |
152 | i.next(); |
|
152 | i.next(); | |
153 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); |
|
153 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); | |
154 | if(!axis) continue; |
|
154 | if(!axis) continue; | |
155 | initializeAxis(axis,i.key()); |
|
155 | initializeAxis(axis,i.key()); | |
156 | emit axisAdded(axis,i.value()); |
|
156 | emit axisAdded(axis,i.value()); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | } |
|
159 | } | |
160 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
160 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
161 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); |
|
161 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); | |
162 | i.toFront(); |
|
162 | i.toFront(); | |
163 | while (i.hasNext()) { |
|
163 | while (i.hasNext()) { | |
164 | i.next(); |
|
164 | i.next(); | |
165 | initializeAxis(axis,i.key()); |
|
165 | initializeAxis(axis,i.key()); | |
166 | } |
|
166 | } | |
167 | emit axisAdded(axis,i.value()); |
|
167 | emit axisAdded(axis,i.value()); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 |
|
171 | |||
172 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) |
|
172 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) | |
173 | { |
|
173 | { | |
174 | QAbstractAxis* axis =0; |
|
174 | QAbstractAxis* axis =0; | |
175 |
|
175 | |||
176 | switch(type) { |
|
176 | switch(type) { | |
177 | case QAbstractAxis::AxisTypeValues: |
|
177 | case QAbstractAxis::AxisTypeValues: | |
178 | axis = new QValuesAxis(this); |
|
178 | axis = new QValuesAxis(this); | |
179 | break; |
|
179 | break; | |
180 | case QAbstractAxis::AxisTypeCategories: |
|
180 | case QAbstractAxis::AxisTypeCategories: | |
181 | axis = new QBarCategoriesAxis(this); |
|
181 | axis = new QBarCategoriesAxis(this); | |
182 | break; |
|
182 | break; | |
183 | default: |
|
183 | default: | |
184 | axis = 0; |
|
184 | axis = 0; | |
185 | break; |
|
185 | break; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | if(axis) |
|
188 | if(axis) | |
189 | axis->d_ptr->setOrientation(orientation); |
|
189 | axis->d_ptr->setOrientation(orientation); | |
190 |
|
190 | |||
191 | return axis; |
|
191 | return axis; | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) |
|
194 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) | |
195 | { |
|
195 | { | |
196 | Domain* domain = m_seriesDomainMap.value(series); |
|
196 | Domain* domain = m_seriesDomainMap.value(series); | |
197 | axis->d_ptr->intializeDomain(domain); |
|
197 | axis->d_ptr->intializeDomain(domain); | |
198 | series->d_ptr->initializeAxis(axis); |
|
198 | series->d_ptr->initializeAxis(axis); | |
199 | if(axis->orientation()==Qt::Horizontal) { |
|
199 | if(axis->orientation()==Qt::Horizontal) { | |
200 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
200 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
201 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
201 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
202 | m_seriesAxisXMap.insert(series,axis); |
|
202 | m_seriesAxisXMap.insert(series,axis); | |
203 | } |
|
203 | } | |
204 | else { |
|
204 | else { | |
205 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
205 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
206 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
206 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
207 | m_seriesAxisYMap.insert(series,axis); |
|
207 | m_seriesAxisYMap.insert(series,axis); | |
208 | } |
|
208 | } | |
209 | axis->d_ptr->emitUpdated(); |
|
209 | axis->d_ptr->emitUpdated(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
212 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |
213 | { |
|
213 | { | |
214 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
214 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
215 |
|
215 | |||
216 | if(axisX) { |
|
216 | if(axisX) { | |
217 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
217 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
218 | int x = axesX.indexOf(axisX); |
|
218 | int x = axesX.indexOf(axisX); | |
219 |
|
219 | |||
220 | if(x==-1) { |
|
220 | if(x==-1) { | |
221 | emit axisRemoved(axisX); |
|
221 | emit axisRemoved(axisX); | |
222 | axisX->deleteLater(); |
|
222 | axisX->deleteLater(); | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
226 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
227 |
|
227 | |||
228 | if(axisY) { |
|
228 | if(axisY) { | |
229 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
229 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
230 |
|
230 | |||
231 | int y = axesY.indexOf(axisY); |
|
231 | int y = axesY.indexOf(axisY); | |
232 |
|
232 | |||
233 | if(y==-1) { |
|
233 | if(y==-1) { | |
234 | emit axisRemoved(axisY); |
|
234 | emit axisRemoved(axisY); | |
235 | axisY->deleteLater(); |
|
235 | axisY->deleteLater(); | |
236 | } |
|
236 | } | |
237 | } |
|
237 | } | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | void ChartDataSet::removeAllSeries() |
|
240 | void ChartDataSet::removeAllSeries() | |
241 | { |
|
241 | { | |
242 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
242 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
243 | foreach(QAbstractSeries *s , series) { |
|
243 | foreach(QAbstractSeries *s , series) { | |
244 | removeSeries(s); |
|
244 | removeSeries(s); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
247 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
248 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
248 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
249 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
249 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
250 |
|
250 | |||
251 | qDeleteAll(series); |
|
251 | qDeleteAll(series); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
254 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
255 | { |
|
255 | { | |
256 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
256 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
257 |
|
257 | |||
258 |
|
258 | |||
259 | blockAxisSignals(true); |
|
259 | blockAxisSignals(true); | |
260 |
|
260 | |||
261 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
261 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
262 |
|
262 | |||
263 | while (i.hasNext()) { |
|
263 | while (i.hasNext()) { | |
264 | i.next(); |
|
264 | i.next(); | |
265 | i.value()->zoomIn(rect,size); |
|
265 | i.value()->zoomIn(rect,size); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | blockAxisSignals(false); |
|
268 | blockAxisSignals(false); | |
269 |
|
269 | |||
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
272 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
273 | { |
|
273 | { | |
274 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
274 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
275 |
|
275 | |||
276 | blockAxisSignals(true); |
|
276 | blockAxisSignals(true); | |
277 |
|
277 | |||
278 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
278 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
279 |
|
279 | |||
280 | while (i.hasNext()) { |
|
280 | while (i.hasNext()) { | |
281 | i.next(); |
|
281 | i.next(); | |
282 | i.value()->zoomOut(rect,size); |
|
282 | i.value()->zoomOut(rect,size); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | blockAxisSignals(false); |
|
285 | blockAxisSignals(false); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
288 | void ChartDataSet::blockAxisSignals(bool enabled) | |
289 | { |
|
289 | { | |
290 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
290 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
291 | while (i.hasNext()) { |
|
291 | while (i.hasNext()) { | |
292 | i.next(); |
|
292 | i.next(); | |
293 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
293 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
294 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
294 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
295 | if(axisX) axisX->d_ptr->blockSignals(enabled); |
|
295 | if(axisX) axisX->d_ptr->blockSignals(enabled); | |
296 | if(axisY) axisY->d_ptr->blockSignals(enabled); |
|
296 | if(axisY) axisY->d_ptr->blockSignals(enabled); | |
297 | } |
|
297 | } | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
300 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
301 | { |
|
301 | { | |
302 | int count=0; |
|
302 | int count=0; | |
303 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
303 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
304 | while (i.hasNext()) { |
|
304 | while (i.hasNext()) { | |
305 | i.next(); |
|
305 | i.next(); | |
306 | if(i.key()->type()==type) count++; |
|
306 | if(i.key()->type()==type) count++; | |
307 | } |
|
307 | } | |
308 | return count; |
|
308 | return count; | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
311 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
312 | { |
|
312 | { | |
313 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
313 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
314 | while (i.hasNext()) { |
|
314 | while (i.hasNext()) { | |
315 | i.next(); |
|
315 | i.next(); | |
316 | if (i.value() == series) |
|
316 | if (i.value() == series) | |
317 | return i.key(); |
|
317 | return i.key(); | |
318 | } |
|
318 | } | |
319 | return -1; |
|
319 | return -1; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
322 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
323 | { |
|
323 | { | |
324 | if(series == 0) { |
|
324 | if(series == 0) { | |
325 |
|
325 | |||
326 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); |
|
326 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); | |
327 |
|
327 | |||
328 | while (i.hasNext()) { |
|
328 | while (i.hasNext()) { | |
329 | i.next(); |
|
329 | i.next(); | |
330 | if(i.value()->isVisible()) return i.value(); |
|
330 | if(i.value()->isVisible()) return i.value(); | |
331 | } |
|
331 | } | |
332 | return 0; |
|
332 | return 0; | |
333 | } |
|
333 | } | |
334 | return m_seriesAxisXMap.value(series); |
|
334 | return m_seriesAxisXMap.value(series); | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
337 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
338 | { |
|
338 | { | |
339 | if(series == 0) { |
|
339 | if(series == 0) { | |
340 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); |
|
340 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); | |
341 |
|
341 | |||
342 | while (i.hasNext()) { |
|
342 | while (i.hasNext()) { | |
343 | i.next(); |
|
343 | i.next(); | |
344 | if(i.value()->isVisible()) return i.value(); |
|
344 | if(i.value()->isVisible()) return i.value(); | |
345 | } |
|
345 | } | |
346 | return 0; |
|
346 | return 0; | |
347 | } |
|
347 | } | |
348 | return m_seriesAxisYMap.value(series); |
|
348 | return m_seriesAxisYMap.value(series); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
351 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) | |
352 | { |
|
352 | { | |
353 | Q_ASSERT(axis); |
|
353 | Q_ASSERT(axis); | |
354 |
|
354 | |||
355 | if(!series) { |
|
355 | if(!series) { | |
356 | qWarning() << "Series not found on the chart."; |
|
356 | qWarning() << "Series not found on the chart."; | |
357 | return; |
|
357 | return; | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | Domain* domain = m_seriesDomainMap.value(series); |
|
360 | Domain* domain = m_seriesDomainMap.value(series); | |
361 |
|
361 | |||
362 | if(!domain) { |
|
362 | if(!domain) { | |
363 | qWarning() << "Series not found on the chart."; |
|
363 | qWarning() << "Series not found on the chart."; | |
364 | return; |
|
364 | return; | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { |
|
367 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { | |
368 | qWarning()<<"Axis already defined as axis Y"; |
|
368 | qWarning()<<"Axis already defined as axis Y"; | |
369 | return; |
|
369 | return; | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { |
|
372 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { | |
373 | qWarning()<<"Axis already defined as axis X"; |
|
373 | qWarning()<<"Axis already defined as axis X"; | |
374 | return; |
|
374 | return; | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | axis->d_ptr->setOrientation(orientation); |
|
377 | axis->d_ptr->setOrientation(orientation); | |
378 |
|
378 | |||
379 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
379 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
380 |
|
380 | |||
381 | if(orientation==Qt::Vertical) { |
|
381 | if(orientation==Qt::Vertical) { | |
382 | seriesAxisMap= &m_seriesAxisYMap; |
|
382 | seriesAxisMap= &m_seriesAxisYMap; | |
383 |
|
||||
384 | }else{ |
|
383 | }else{ | |
385 | seriesAxisMap= &m_seriesAxisXMap; |
|
384 | seriesAxisMap= &m_seriesAxisXMap; | |
386 | } |
|
385 | } | |
387 |
|
386 | |||
388 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
387 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); | |
389 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); |
|
388 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); | |
390 |
|
389 | |||
391 | if(oldAxis) { |
|
390 | if(oldAxis) { | |
392 | if(axes.indexOf(oldAxis)==-1) { |
|
391 | if(axes.indexOf(oldAxis)==-1) { | |
393 | emit axisRemoved(oldAxis); |
|
392 | emit axisRemoved(oldAxis); | |
394 | oldAxis->deleteLater(); |
|
393 | oldAxis->deleteLater(); | |
395 | } |
|
394 | } | |
396 | } |
|
395 | } | |
397 |
|
396 | |||
398 | if(axes.indexOf(axis)==-1) { |
|
397 | if(axes.indexOf(axis)==-1) { | |
399 | initializeAxis(axis,series); |
|
398 | initializeAxis(axis,series); | |
400 | emit axisAdded(axis,domain); |
|
399 | emit axisAdded(axis,domain); | |
401 | }else{ |
|
400 | }else{ | |
402 | initializeAxis(axis,series); |
|
401 | initializeAxis(axis,series); | |
403 | } |
|
402 | } | |
404 | } |
|
403 | } | |
405 |
|
404 | |||
406 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
405 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
407 | { |
|
406 | { | |
408 | return m_seriesDomainMap.value(series); |
|
407 | return m_seriesDomainMap.value(series); | |
409 | } |
|
408 | } | |
410 |
|
409 | |||
411 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
410 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
412 | { |
|
411 | { | |
413 | blockAxisSignals(true); |
|
412 | blockAxisSignals(true); | |
414 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
413 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
415 | while (i.hasNext()) { |
|
414 | while (i.hasNext()) { | |
416 | i.next(); |
|
415 | i.next(); | |
417 | i.value()->move(dx,dy,size); |
|
416 | i.value()->move(dx,dy,size); | |
418 | } |
|
417 | } | |
419 | blockAxisSignals(false); |
|
418 | blockAxisSignals(false); | |
420 | } |
|
419 | } | |
421 |
|
420 | |||
422 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
421 | QList<QAbstractSeries*> ChartDataSet::series() const | |
423 | { |
|
422 | { | |
424 | return m_seriesDomainMap.keys(); |
|
423 | return m_seriesDomainMap.keys(); | |
425 | } |
|
424 | } | |
426 |
|
425 | |||
427 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
426 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
428 | { |
|
427 | { | |
429 | emit seriesUpdated(series); |
|
428 | emit seriesUpdated(series); | |
430 | } |
|
429 | } | |
431 |
|
430 | |||
432 | #include "moc_chartdataset_p.cpp" |
|
431 | #include "moc_chartdataset_p.cpp" | |
433 |
|
432 | |||
434 | QTCOMMERCIALCHART_END_NAMESPACE |
|
433 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now