@@ -1,117 +1,140 | |||||
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 " |
|
23 | #include "qbarcategoriesaxis_p.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include <cmath> | |
25 | #include <QGraphicsLayout> |
|
|||
26 | #include <QFontMetrics> |
|
|||
27 |
|
25 | |||
28 | static int label_padding = 5; |
|
26 | static int label_padding = 5; | |
29 |
|
27 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
29 | |||
32 | ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
30 | ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
33 |
|
|
31 | m_categoriesAxis(axis) | |
34 | { |
|
32 | { | |
35 |
|
33 | |||
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 | ChartCategoriesAxisX::~ChartCategoriesAxisX() |
|
36 | ChartCategoriesAxisX::~ChartCategoriesAxisX() | |
39 | { |
|
37 | { | |
40 | } |
|
38 | } | |
41 |
|
39 | |||
42 | QVector<qreal> ChartCategoriesAxisX::calculateLayout() const |
|
40 | QVector<qreal> ChartCategoriesAxisX::calculateLayout() const | |
43 | { |
|
41 | { | |
44 | Q_ASSERT(m_categoriesAxis->categories().count()>=1); |
|
42 | Q_ASSERT(m_categoriesAxis->categories().count()>=1); | |
45 |
|
43 | |||
46 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
47 | points.resize(m_categoriesAxis->categories().count()+1); |
|
45 | points.resize(m_categoriesAxis->categories().count()+1); | |
48 |
|
46 | |||
49 | // TODO: shift logic |
|
47 | const qreal delta = m_rect.width()/(m_categoriesAxis->categories().count()); | |
50 |
const qreal |
|
48 | const qreal min = m_categoriesAxis->d_ptr->min(); | |
51 | for (int i = 0; i < m_categoriesAxis->categories().count()+1; ++i) { |
|
49 | const qreal max = m_categoriesAxis->d_ptr->max(); | |
52 | int x = i * deltaX + m_rect.left(); |
|
50 | qreal start =-min-0.5; | |
|
51 | if(start<=0) { | |||
|
52 | start = fmod(start * m_rect.width()/(max - min),delta) + delta; | |||
|
53 | } | |||
|
54 | else { | |||
|
55 | start = fmod(start * m_rect.width()/(max - min),delta); | |||
|
56 | } | |||
|
57 | ||||
|
58 | points[m_categoriesAxis->categories().count()] = m_rect.left() + m_rect.width(); | |||
|
59 | ||||
|
60 | for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { | |||
|
61 | qreal x = start + i * delta + m_rect.left(); | |||
53 | points[i] = x; |
|
62 | points[i] = x; | |
54 | } |
|
63 | } | |
|
64 | ||||
55 | return points; |
|
65 | return points; | |
56 | } |
|
66 | } | |
57 |
|
67 | |||
58 | void ChartCategoriesAxisX::updateGeometry() |
|
68 | void ChartCategoriesAxisX::updateGeometry() | |
59 | { |
|
69 | { | |
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
70 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 |
|
71 | |||
62 | m_minWidth = 0; |
|
72 | m_minWidth = 0; | |
63 | m_minHeight = 0; |
|
73 | m_minHeight = 0; | |
64 |
|
74 | |||
65 | if(layout.isEmpty()) return; |
|
75 | if(layout.isEmpty()) return; | |
66 |
|
76 | |||
67 | QStringList ticksList; |
|
77 | QStringList ticksList; | |
68 |
|
78 | |||
69 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); |
|
79 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); | |
70 |
|
80 | |||
71 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
81 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
72 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
82 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
73 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
83 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
74 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
84 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
75 |
|
85 | |||
76 |
Q_ASSERT(labels.size() |
|
86 | Q_ASSERT(labels.size() == ticksList.size()); | |
77 |
Q_ASSERT(layout.size() |
|
87 | Q_ASSERT(layout.size() == ticksList.size()); | |
|
88 | ||||
|
89 | const qreal delta = m_rect.width()/(m_categoriesAxis->categories().count()); | |||
78 |
|
90 | |||
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
91 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
80 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
92 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
81 |
|
93 | |||
|
94 | qreal width = m_rect.left(); | |||
82 | for (int i = 0; i < layout.size(); ++i) { |
|
95 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
96 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
97 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
98 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | if (i>=1) { |
|
99 | labelItem->setText(ticksList.at(i)); | |
87 | labelItem->setText(ticksList.at(i-1)); |
|
|||
88 | const QRectF& rect = labelItem->boundingRect(); |
|
100 | const QRectF& rect = labelItem->boundingRect(); | |
89 | QPointF center = rect.center(); |
|
101 | QPointF center = rect.center(); | |
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
102 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
91 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
103 | ||
92 | m_minWidth+=rect.width(); |
|
104 | if(i==layout.size()-1){ | |
93 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); |
|
105 | labelItem->setPos(layout[i-1] + (delta)/2 - center.x(), m_rect.bottom() + label_padding); | |
94 | }else{ |
|
106 | }else{ | |
|
107 | labelItem->setPos(layout[i] - (delta)/2 - center.x(), m_rect.bottom() + label_padding); | |||
|
108 | } | |||
|
109 | ||||
|
110 | if(labelItem->pos().x()<=width || labelItem->pos().x()+ rect.width()>m_rect.right()) { | |||
95 | labelItem->setVisible(false); |
|
111 | labelItem->setVisible(false); | |
96 | } |
|
112 | } | |
|
113 | else { | |||
|
114 | labelItem->setVisible(true); | |||
|
115 | width=rect.width()+labelItem->pos().x(); | |||
|
116 | } | |||
|
117 | ||||
|
118 | m_minWidth+=rect.width(); | |||
|
119 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |||
97 |
|
120 | |||
98 | if ((i+1)%2 && i>1) { |
|
121 | if ((i+1)%2 && i>1) { | |
99 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
122 | 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()); |
|
123 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
101 | } |
|
124 | } | |
102 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
125 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
103 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
126 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
104 | } |
|
127 | } | |
105 | } |
|
128 | } | |
106 |
|
129 | |||
107 | void ChartCategoriesAxisX::handleAxisUpdated() |
|
130 | void ChartCategoriesAxisX::handleAxisUpdated() | |
108 | { |
|
131 | { | |
109 | if(m_categoriesAxis->categories()!=m_categories) |
|
132 | if(m_categoriesAxis->categories()!=m_categories) | |
110 | { |
|
133 | { | |
111 | m_categories=m_categoriesAxis->categories(); |
|
134 | m_categories=m_categoriesAxis->categories(); | |
112 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); |
|
135 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); | |
113 | } |
|
136 | } | |
114 | ChartAxis::handleAxisUpdated(); |
|
137 | ChartAxis::handleAxisUpdated(); | |
115 | } |
|
138 | } | |
116 |
|
139 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,145 | |||||
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 " |
|
23 | #include "qbarcategoriesaxis_p.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include <QDebug> | |
25 |
#include < |
|
25 | #include <cmath> | |
26 | #include <QFontMetrics> |
|
|||
27 | #include <QBarCategoriesAxis> |
|
|||
28 |
|
26 | |||
29 | static int label_padding = 5; |
|
27 | static int label_padding = 5; | |
30 |
|
28 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
30 | |||
33 | ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
31 | ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
34 |
|
|
32 | m_categoriesAxis(axis) | |
35 | { |
|
33 | { | |
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 | ChartCategoriesAxisY::~ChartCategoriesAxisY() |
|
36 | ChartCategoriesAxisY::~ChartCategoriesAxisY() | |
39 | { |
|
37 | { | |
40 | } |
|
38 | } | |
41 |
|
39 | |||
42 | QVector<qreal> ChartCategoriesAxisY::calculateLayout() const |
|
40 | QVector<qreal> ChartCategoriesAxisY::calculateLayout() const | |
43 | { |
|
41 | { | |
44 | Q_ASSERT(m_categoriesAxis->categories().count()>=1); |
|
42 | Q_ASSERT(m_categoriesAxis->categories().count()>=1); | |
45 |
|
43 | |||
46 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
47 | points.resize(m_categoriesAxis->categories().count()+1); |
|
45 | points.resize(m_categoriesAxis->categories().count()+1); | |
48 |
|
46 | |||
49 |
|
|
47 | qreal delta = m_rect.height()/(m_categoriesAxis->categories().count()); | |
50 | for (int i = 0; i < m_categoriesAxis->categories().count()+1; ++i) { |
|
48 | ||
51 | int y = i * -deltaY + m_rect.bottom(); |
|
49 | const qreal min = m_categoriesAxis->d_ptr->min(); | |
|
50 | const qreal max = m_categoriesAxis->d_ptr->max(); | |||
|
51 | ||||
|
52 | qreal start =-min-0.5; | |||
|
53 | ||||
|
54 | if(start<=0) { | |||
|
55 | start = fmod(start * m_rect.height()/(max - min),delta) + delta; | |||
|
56 | } | |||
|
57 | else { | |||
|
58 | start = fmod(start * m_rect.height()/(max - min),delta); | |||
|
59 | } | |||
|
60 | ||||
|
61 | points[m_categoriesAxis->categories().count()] = m_rect.top(); | |||
|
62 | ||||
|
63 | for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) { | |||
|
64 | int y = m_rect.bottom() - i * delta - start; | |||
52 | points[i] = y; |
|
65 | points[i] = y; | |
53 | } |
|
66 | } | |
54 |
|
67 | |||
55 | return points; |
|
68 | return points; | |
56 | } |
|
69 | } | |
57 |
|
70 | |||
58 | void ChartCategoriesAxisY::updateGeometry() |
|
71 | void ChartCategoriesAxisY::updateGeometry() | |
59 | { |
|
72 | { | |
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
73 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 |
|
74 | |||
62 | m_minWidth = 0; |
|
75 | m_minWidth = 0; | |
63 | m_minHeight = 0; |
|
76 | m_minHeight = 0; | |
64 |
|
77 | |||
65 | if(layout.isEmpty()) return; |
|
78 | if(layout.isEmpty()) return; | |
66 |
|
79 | |||
67 | QStringList ticksList; |
|
80 | QStringList ticksList; | |
68 |
|
81 | |||
69 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); |
|
82 | createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories()); | |
70 |
|
83 | |||
71 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
84 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
72 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
85 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
73 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
86 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
74 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
87 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
75 |
|
88 | |||
76 |
Q_ASSERT(labels.size() |
|
89 | Q_ASSERT(labels.size() == ticksList.size()); | |
77 |
Q_ASSERT(layout.size() |
|
90 | Q_ASSERT(layout.size() == ticksList.size()); | |
|
91 | ||||
|
92 | const qreal delta = m_rect.height()/(m_categoriesAxis->categories().count()); | |||
78 |
|
93 | |||
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
94 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
80 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
95 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
81 |
|
96 | |||
|
97 | qreal height = m_rect.bottom(); | |||
82 | for (int i = 0; i < layout.size(); ++i) { |
|
98 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
99 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
100 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
101 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | if(i>=1){ |
|
102 | labelItem->setText(ticksList.at(i)); | |
87 | labelItem->setText(ticksList.at(i-1)); |
|
|||
88 | const QRectF& rect = labelItem->boundingRect(); |
|
103 | const QRectF& rect = labelItem->boundingRect(); | |
89 | QPointF center = rect.center(); |
|
104 | QPointF center = rect.center(); | |
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
105 | 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()); |
|
106 | ||
92 | m_minWidth+=rect.width(); |
|
107 | if(i==layout.size()-1) { | |
93 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); |
|
108 | labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i-1] - (delta)/2 - center.y()); | |
94 |
} |
|
109 | } | |
|
110 | else { | |||
|
111 | labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i] + (delta)/2 - center.y()); | |||
|
112 | } | |||
|
113 | ||||
|
114 | if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < m_rect.top()) { | |||
95 |
|
|
115 | labelItem->setVisible(false); | |
96 | } |
|
116 | } | |
|
117 | else { | |||
|
118 | labelItem->setVisible(true); | |||
|
119 | height=labelItem->pos().y(); | |||
|
120 | } | |||
97 |
|
121 | |||
|
122 | m_minWidth+=rect.width(); | |||
|
123 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |||
98 |
|
124 | |||
99 | if ((i+1)%2 && i>1) { |
|
125 | if ((i+1)%2 && i>1) { | |
100 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
126 | 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]); |
|
127 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
102 | } |
|
128 | } | |
103 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
129 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
104 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
130 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
105 | } |
|
131 | } | |
106 | } |
|
132 | } | |
107 |
|
133 | |||
108 |
|
||||
109 | void ChartCategoriesAxisY::handleAxisUpdated() |
|
134 | void ChartCategoriesAxisY::handleAxisUpdated() | |
110 | { |
|
135 | { | |
111 |
|
136 | |||
112 | if(m_categoriesAxis->categories()!=m_categories) |
|
137 | if(m_categoriesAxis->categories()!=m_categories) | |
113 | { |
|
138 | { | |
114 | m_categories=m_categoriesAxis->categories(); |
|
139 | m_categories=m_categoriesAxis->categories(); | |
115 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); |
|
140 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); | |
116 | } |
|
141 | } | |
117 | ChartAxis::handleAxisUpdated(); |
|
142 | ChartAxis::handleAxisUpdated(); | |
118 | } |
|
143 | } | |
119 |
|
144 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
145 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,427 +1,439 | |||||
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 | m_min(0.0), | |||
|
316 | m_max(0.0) | |||
315 | { |
|
317 | { | |
316 |
|
318 | |||
317 | } |
|
319 | } | |
318 |
|
320 | |||
319 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
321 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() | |
320 | { |
|
322 | { | |
321 |
|
323 | |||
322 | } |
|
324 | } | |
323 |
|
325 | |||
324 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
326 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) | |
325 | { |
|
327 | { | |
326 | setRange(min,m_maxCategory); |
|
328 | setRange(min,m_maxCategory); | |
327 | } |
|
329 | } | |
328 |
|
330 | |||
329 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
331 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) | |
330 | { |
|
332 | { | |
331 | setRange(m_minCategory,max); |
|
333 | setRange(m_minCategory,max); | |
332 | } |
|
334 | } | |
333 |
|
335 | |||
334 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
336 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
335 | { |
|
337 | { | |
336 | Q_Q(QBarCategoriesAxis); |
|
338 | Q_Q(QBarCategoriesAxis); | |
337 | QString value1 = min.toString(); |
|
339 | QString value1 = min.toString(); | |
338 | QString value2 = max.toString(); |
|
340 | QString value2 = max.toString(); | |
339 | q->setRange(value1,value2); |
|
341 | q->setRange(value1,value2); | |
340 | } |
|
342 | } | |
341 |
|
343 | |||
342 | qreal QBarCategoriesAxisPrivate::min() |
|
344 | qreal QBarCategoriesAxisPrivate::min() | |
343 | { |
|
345 | { | |
344 | //TODO:: cache it |
|
346 | //TODO:: cache it | |
345 |
return |
|
347 | return m_min;//m_categories.indexOf(m_minCategory) - 0.5; | |
346 | } |
|
348 | } | |
347 |
|
349 | |||
348 | qreal QBarCategoriesAxisPrivate::max() |
|
350 | qreal QBarCategoriesAxisPrivate::max() | |
349 | { |
|
351 | { | |
350 | //TODO:: cache it |
|
352 | //TODO:: cache it | |
351 |
return |
|
353 | return m_max;//m_categories.indexOf(m_maxCategory) + 0.5; | |
352 | } |
|
354 | } | |
353 |
|
355 | |||
354 | void QBarCategoriesAxisPrivate::handleDomainUpdated() |
|
356 | void QBarCategoriesAxisPrivate::handleDomainUpdated() | |
355 | { |
|
357 | { | |
|
358 | Domain* domain = qobject_cast<Domain*>(sender()); | |||
|
359 | ||||
|
360 | if(m_orientation==Qt::Horizontal){ | |||
|
361 | m_min = domain->minX(); | |||
|
362 | m_max = domain->maxX(); | |||
|
363 | }else if(m_orientation==Qt::Vertical){ | |||
|
364 | m_min = domain->minY(); | |||
|
365 | m_max = domain->maxY(); | |||
|
366 | } | |||
|
367 | ||||
356 | // Q_Q(QBarCategoriesAxis); |
|
368 | // Q_Q(QBarCategoriesAxis); | |
357 |
|
369 | |||
358 | // TODO: causes crash in some situations. added to known issues |
|
370 | // TODO: causes crash in some situations. added to known issues | |
359 | /* |
|
371 | /* | |
360 | int minIndex = qFloor(min); |
|
372 | int minIndex = qFloor(min); | |
361 | int maxIndex = qFloor(max); |
|
373 | int maxIndex = qFloor(max); | |
362 |
|
374 | |||
363 | if (minIndex < 0) { |
|
375 | if (minIndex < 0) { | |
364 | minIndex = 0; |
|
376 | minIndex = 0; | |
365 | } |
|
377 | } | |
366 | if (maxIndex > m_categories.count()-1){ |
|
378 | if (maxIndex > m_categories.count()-1){ | |
367 | maxIndex = m_categories.count()-1; |
|
379 | maxIndex = m_categories.count()-1; | |
368 | if (maxIndex<0) { |
|
380 | if (maxIndex<0) { | |
369 | maxIndex = 0; |
|
381 | maxIndex = 0; | |
370 | } |
|
382 | } | |
371 | } |
|
383 | } | |
372 |
|
384 | |||
373 | bool changed = false; |
|
385 | bool changed = false; | |
374 | if (m_minCategory != m_categories.at(minIndex)) { |
|
386 | if (m_minCategory != m_categories.at(minIndex)) { | |
375 | m_minCategory = m_categories.at(minIndex); |
|
387 | m_minCategory = m_categories.at(minIndex); | |
376 | emit q->minChanged(m_minCategory); |
|
388 | emit q->minChanged(m_minCategory); | |
377 | changed = true; |
|
389 | changed = true; | |
378 | } |
|
390 | } | |
379 |
|
391 | |||
380 | if (m_maxCategory != m_categories.at(maxIndex)) { |
|
392 | if (m_maxCategory != m_categories.at(maxIndex)) { | |
381 | m_maxCategory = m_categories.at(maxIndex); |
|
393 | m_maxCategory = m_categories.at(maxIndex); | |
382 | emit q->maxChanged(m_maxCategory); |
|
394 | emit q->maxChanged(m_maxCategory); | |
383 | changed = true; |
|
395 | changed = true; | |
384 | } |
|
396 | } | |
385 |
|
397 | |||
386 | if (changed) { |
|
398 | if (changed) { | |
387 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
399 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
388 | } |
|
400 | } | |
389 | */ |
|
401 | */ | |
390 | } |
|
402 | } | |
391 |
|
403 | |||
392 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
404 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
393 | { |
|
405 | { | |
394 | Q_Q(QBarCategoriesAxis); |
|
406 | Q_Q(QBarCategoriesAxis); | |
395 | if(m_orientation == Qt::Vertical){ |
|
407 | if(m_orientation == Qt::Vertical){ | |
396 | return new ChartCategoriesAxisY(q,presenter); |
|
408 | return new ChartCategoriesAxisY(q,presenter); | |
397 | }else{ |
|
409 | }else{ | |
398 | return new ChartCategoriesAxisX(q,presenter); |
|
410 | return new ChartCategoriesAxisX(q,presenter); | |
399 | } |
|
411 | } | |
400 | } |
|
412 | } | |
401 |
|
413 | |||
402 | /* |
|
414 | /* | |
403 | void QBarCategoriesAxisPrivate::emitRange() |
|
415 | void QBarCategoriesAxisPrivate::emitRange() | |
404 | { |
|
416 | { | |
405 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); |
|
417 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); | |
406 | } |
|
418 | } | |
407 | */ |
|
419 | */ | |
408 |
|
420 | |||
409 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) |
|
421 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) | |
410 | { |
|
422 | { | |
411 | Q_UNUSED(domain); |
|
423 | Q_UNUSED(domain); | |
412 | // TODO: this causes crash now. added to known issues. |
|
424 | // TODO: this causes crash now. added to known issues. | |
413 | /* |
|
425 | /* | |
414 | if (qFuzzyCompare(m_max, m_min)) { |
|
426 | if (qFuzzyCompare(m_max, m_min)) { | |
415 | if(m_orientation==Qt::Vertical){ |
|
427 | if(m_orientation==Qt::Vertical){ | |
416 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); |
|
428 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); | |
417 | }else{ |
|
429 | }else{ | |
418 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); |
|
430 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); | |
419 | } |
|
431 | } | |
420 | } |
|
432 | } | |
421 | */ |
|
433 | */ | |
422 | } |
|
434 | } | |
423 |
|
435 | |||
424 | #include "moc_qbarcategoriesaxis.cpp" |
|
436 | #include "moc_qbarcategoriesaxis.cpp" | |
425 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
437 | #include "moc_qbarcategoriesaxis_p.cpp" | |
426 |
|
438 | |||
427 | QTCOMMERCIALCHART_END_NAMESPACE |
|
439 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,74 | |||||
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 QBARCATEGORIESAXIS_P_H |
|
30 | #ifndef QBARCATEGORIESAXIS_P_H | |
31 | #define QBARCATEGORIESAXIS_P_H |
|
31 | #define QBARCATEGORIESAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qbarcategoriesaxis.h" |
|
33 | #include "qbarcategoriesaxis.h" | |
34 | #include "qabstractaxis_p.h" |
|
34 | #include "qabstractaxis_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class Domain; |
|
38 | class Domain; | |
39 |
|
39 | |||
40 | class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate |
|
40 | class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | QBarCategoriesAxisPrivate(QBarCategoriesAxis *q); |
|
45 | QBarCategoriesAxisPrivate(QBarCategoriesAxis *q); | |
46 | ~QBarCategoriesAxisPrivate(); |
|
46 | ~QBarCategoriesAxisPrivate(); | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
49 | ChartAxis* createGraphics(ChartPresenter* presenter); | |
50 | void intializeDomain(Domain* domain); |
|
50 | void intializeDomain(Domain* domain); | |
51 | void handleDomainUpdated(); |
|
51 | void handleDomainUpdated(); | |
52 | qreal min(); |
|
52 | qreal min(); | |
53 | qreal max(); |
|
53 | qreal max(); | |
54 |
|
54 | |||
55 | private: |
|
55 | private: | |
56 | //range handling |
|
56 | //range handling | |
57 | void setMin(const QVariant &min); |
|
57 | void setMin(const QVariant &min); | |
58 | void setMax(const QVariant &max); |
|
58 | void setMax(const QVariant &max); | |
59 | void setRange(const QVariant &min, const QVariant &max); |
|
59 | void setRange(const QVariant &min, const QVariant &max); | |
60 |
|
60 | |||
61 | private: |
|
61 | private: | |
62 | QStringList m_categories; |
|
62 | QStringList m_categories; | |
63 | QString m_minCategory; |
|
63 | QString m_minCategory; | |
64 | QString m_maxCategory; |
|
64 | QString m_maxCategory; | |
|
65 | qreal m_min; | |||
|
66 | qreal m_max; | |||
65 |
|
67 | |||
66 | private: |
|
68 | private: | |
67 | Q_DECLARE_PUBLIC(QBarCategoriesAxis) |
|
69 | Q_DECLARE_PUBLIC(QBarCategoriesAxis) | |
68 | }; |
|
70 | }; | |
69 |
|
71 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
73 | |||
72 | #endif // QBARCATEGORIESAXIS_P_H |
|
74 | #endif // QBARCATEGORIESAXIS_P_H |
@@ -1,395 +1,395 | |||||
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 "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartanimator_p.h" |
|
25 | #include "chartanimator_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 | #include <qmath.h> |
|
29 | #include <qmath.h> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter), |
|
33 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter), | |
34 | m_chartAxis(axis), |
|
34 | m_chartAxis(axis), | |
35 | m_labelsAngle(0), |
|
35 | m_labelsAngle(0), | |
36 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
36 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
37 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
37 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
38 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
38 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
39 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), |
|
39 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
40 | m_min(0), |
|
40 | m_min(0), | |
41 | m_max(0), |
|
41 | m_max(0), | |
42 | m_animation(0), |
|
42 | m_animation(0), | |
43 | m_minWidth(0), |
|
43 | m_minWidth(0), | |
44 | m_minHeight(0) |
|
44 | m_minHeight(0) | |
45 | { |
|
45 | { | |
46 | //initial initialization |
|
46 | //initial initialization | |
47 | m_axis->setZValue(ChartPresenter::AxisZValue); |
|
47 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
48 | m_axis->setHandlesChildEvents(false); |
|
48 | m_axis->setHandlesChildEvents(false); | |
49 |
|
49 | |||
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
51 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
51 | m_grid->setZValue(ChartPresenter::GridZValue); | |
52 |
|
52 | |||
53 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
53 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
54 |
|
54 | |||
55 | QGraphicsSimpleTextItem item; |
|
55 | QGraphicsSimpleTextItem item; | |
56 | m_font = item.font(); |
|
56 | m_font = item.font(); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | ChartAxis::~ChartAxis() |
|
59 | ChartAxis::~ChartAxis() | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartAxis::setAnimation(AxisAnimation* animation) |
|
63 | void ChartAxis::setAnimation(AxisAnimation* animation) | |
64 | { |
|
64 | { | |
65 | m_animation=animation; |
|
65 | m_animation=animation; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
68 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
69 | { |
|
69 | { | |
70 | m_layoutVector=layout; |
|
70 | m_layoutVector=layout; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartAxis::createItems(int count) |
|
73 | void ChartAxis::createItems(int count) | |
74 | { |
|
74 | { | |
75 | if (m_axis->children().size() == 0) |
|
75 | if (m_axis->children().size() == 0) | |
76 | m_axis->addToGroup(new AxisItem(this)); |
|
76 | m_axis->addToGroup(new AxisItem(this)); | |
77 | for (int i = 0; i < count; ++i) { |
|
77 | for (int i = 0; i < count; ++i) { | |
78 | m_grid->addToGroup(new QGraphicsLineItem()); |
|
78 | m_grid->addToGroup(new QGraphicsLineItem()); | |
79 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); |
|
79 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
80 | m_axis->addToGroup(new QGraphicsLineItem()); |
|
80 | m_axis->addToGroup(new QGraphicsLineItem()); | |
81 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); |
|
81 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); | |
82 | } |
|
82 | } | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void ChartAxis::deleteItems(int count) |
|
85 | void ChartAxis::deleteItems(int count) | |
86 | { |
|
86 | { | |
87 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
87 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
88 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
88 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
89 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
89 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
90 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
90 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
91 |
|
91 | |||
92 | for (int i = 0; i < count; ++i) { |
|
92 | for (int i = 0; i < count; ++i) { | |
93 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
93 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
94 | delete(lines.takeLast()); |
|
94 | delete(lines.takeLast()); | |
95 | delete(labels.takeLast()); |
|
95 | delete(labels.takeLast()); | |
96 | delete(axis.takeLast()); |
|
96 | delete(axis.takeLast()); | |
97 | } |
|
97 | } | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
100 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
101 | { |
|
101 | { | |
102 | int diff = m_layoutVector.size() - layout.size(); |
|
102 | int diff = m_layoutVector.size() - layout.size(); | |
103 |
|
103 | |||
104 | if (diff>0) { |
|
104 | if (diff>0) { | |
105 | deleteItems(diff); |
|
105 | deleteItems(diff); | |
106 | } |
|
106 | } | |
107 | else if (diff<0) { |
|
107 | else if (diff<0) { | |
108 | createItems(-diff); |
|
108 | createItems(-diff); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | if(diff<0) handleAxisUpdated(); |
|
111 | if(diff<0) handleAxisUpdated(); | |
112 |
|
112 | |||
113 | if (m_animation) { |
|
113 | if (m_animation) { | |
114 | switch(presenter()->state()){ |
|
114 | switch(presenter()->state()){ | |
115 | case ChartPresenter::ZoomInState: |
|
115 | case ChartPresenter::ZoomInState: | |
116 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
116 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
117 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
117 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
118 | break; |
|
118 | break; | |
119 | case ChartPresenter::ZoomOutState: |
|
119 | case ChartPresenter::ZoomOutState: | |
120 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
120 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
121 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
121 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
122 | break; |
|
122 | break; | |
123 | case ChartPresenter::ScrollUpState: |
|
123 | case ChartPresenter::ScrollUpState: | |
124 | case ChartPresenter::ScrollLeftState: |
|
124 | case ChartPresenter::ScrollLeftState: | |
125 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
125 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
126 | break; |
|
126 | break; | |
127 | case ChartPresenter::ScrollDownState: |
|
127 | case ChartPresenter::ScrollDownState: | |
128 | case ChartPresenter::ScrollRightState: |
|
128 | case ChartPresenter::ScrollRightState: | |
129 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
129 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
130 | break; |
|
130 | break; | |
131 | case ChartPresenter::ShowState: |
|
131 | case ChartPresenter::ShowState: | |
132 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
132 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
133 | break; |
|
133 | break; | |
134 | } |
|
134 | } | |
135 | m_animation->setValues(m_layoutVector,layout); |
|
135 | m_animation->setValues(m_layoutVector,layout); | |
136 | presenter()->startAnimation(m_animation); |
|
136 | presenter()->startAnimation(m_animation); | |
137 | } |
|
137 | } | |
138 | else { |
|
138 | else { | |
139 | setLayout(layout); |
|
139 | setLayout(layout); | |
140 | updateGeometry(); |
|
140 | updateGeometry(); | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void ChartAxis::setAxisOpacity(qreal opacity) |
|
144 | void ChartAxis::setAxisOpacity(qreal opacity) | |
145 | { |
|
145 | { | |
146 | m_axis->setOpacity(opacity); |
|
146 | m_axis->setOpacity(opacity); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | qreal ChartAxis::axisOpacity() const |
|
149 | qreal ChartAxis::axisOpacity() const | |
150 | { |
|
150 | { | |
151 | return m_axis->opacity(); |
|
151 | return m_axis->opacity(); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void ChartAxis::setGridOpacity(qreal opacity) |
|
154 | void ChartAxis::setGridOpacity(qreal opacity) | |
155 | { |
|
155 | { | |
156 | m_grid->setOpacity(opacity); |
|
156 | m_grid->setOpacity(opacity); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | qreal ChartAxis::gridOpacity() const |
|
159 | qreal ChartAxis::gridOpacity() const | |
160 | { |
|
160 | { | |
161 | return m_grid->opacity(); |
|
161 | return m_grid->opacity(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
164 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
165 | { |
|
165 | { | |
166 | m_labels->setOpacity(opacity); |
|
166 | m_labels->setOpacity(opacity); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | qreal ChartAxis::labelsOpacity() const |
|
169 | qreal ChartAxis::labelsOpacity() const | |
170 | { |
|
170 | { | |
171 | return m_labels->opacity(); |
|
171 | return m_labels->opacity(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
174 | void ChartAxis::setShadesOpacity(qreal opacity) | |
175 | { |
|
175 | { | |
176 | m_shades->setOpacity(opacity); |
|
176 | m_shades->setOpacity(opacity); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | qreal ChartAxis::shadesOpacity() const |
|
179 | qreal ChartAxis::shadesOpacity() const | |
180 | { |
|
180 | { | |
181 | return m_shades->opacity(); |
|
181 | return m_shades->opacity(); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void ChartAxis::setLabelsAngle(int angle) |
|
184 | void ChartAxis::setLabelsAngle(int angle) | |
185 | { |
|
185 | { | |
186 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
186 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
187 | item->setRotation(angle); |
|
187 | item->setRotation(angle); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | m_labelsAngle=angle; |
|
190 | m_labelsAngle=angle; | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
193 | void ChartAxis::setLabelsPen(const QPen &pen) | |
194 | { |
|
194 | { | |
195 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
195 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
196 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
196 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
197 | } |
|
197 | } | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
200 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
201 | { |
|
201 | { | |
202 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
202 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
203 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
203 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void ChartAxis::setLabelsFont(const QFont &font) |
|
207 | void ChartAxis::setLabelsFont(const QFont &font) | |
208 | { |
|
208 | { | |
209 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
209 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
210 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
210 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
211 | } |
|
211 | } | |
212 | m_font = font; |
|
212 | m_font = font; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
215 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
216 | { |
|
216 | { | |
217 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
217 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
218 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
218 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void ChartAxis::setShadesPen(const QPen &pen) |
|
222 | void ChartAxis::setShadesPen(const QPen &pen) | |
223 | { |
|
223 | { | |
224 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
224 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
225 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
225 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
226 | } |
|
226 | } | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | void ChartAxis::setAxisPen(const QPen &pen) |
|
229 | void ChartAxis::setAxisPen(const QPen &pen) | |
230 | { |
|
230 | { | |
231 | foreach(QGraphicsItem* item , m_axis->childItems()) { |
|
231 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
232 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
232 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void ChartAxis::setGridPen(const QPen &pen) |
|
236 | void ChartAxis::setGridPen(const QPen &pen) | |
237 | { |
|
237 | { | |
238 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
238 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
239 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
239 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | bool ChartAxis::isEmpty() |
|
243 | bool ChartAxis::isEmpty() | |
244 | { |
|
244 | { | |
245 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max); |
|
245 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | void ChartAxis::handleDomainUpdated() |
|
248 | void ChartAxis::handleDomainUpdated() | |
249 | { |
|
249 | { | |
250 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
250 | Domain* domain = qobject_cast<Domain*>(sender()); | |
251 | qreal min(0); |
|
251 | qreal min(0); | |
252 | qreal max(0); |
|
252 | qreal max(0); | |
253 |
|
253 | |||
254 | if(m_chartAxis->orientation()==Qt::Horizontal) { |
|
254 | if(m_chartAxis->orientation()==Qt::Horizontal) { | |
255 | min = domain->minX(); |
|
255 | min = domain->minX(); | |
256 | max = domain->maxX(); |
|
256 | max = domain->maxX(); | |
257 | } |
|
257 | } | |
258 | else if (m_chartAxis->orientation()==Qt::Vertical) |
|
258 | else if (m_chartAxis->orientation()==Qt::Vertical) | |
259 | { |
|
259 | { | |
260 | min = domain->minY(); |
|
260 | min = domain->minY(); | |
261 | max = domain->maxY(); |
|
261 | max = domain->maxY(); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) |
|
264 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) | |
265 | { |
|
265 | { | |
266 | m_min = min; |
|
266 | m_min = min; | |
267 | m_max = max; |
|
267 | m_max = max; | |
268 |
|
268 | |||
269 | if (!isEmpty()) { |
|
269 | if (!isEmpty()) { | |
270 | QVector<qreal> layout = calculateLayout(); |
|
270 | QVector<qreal> layout = calculateLayout(); | |
271 | updateLayout(layout); |
|
271 | updateLayout(layout); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void ChartAxis::handleAxisUpdated() |
|
276 | void ChartAxis::handleAxisUpdated() | |
277 | { |
|
277 | { | |
278 | if(isEmpty()) return; |
|
278 | if(isEmpty()) return; | |
279 |
|
279 | |||
280 | if (!m_chartAxis->isVisible()) { |
|
280 | if (!m_chartAxis->isVisible()) { | |
281 | setAxisOpacity(0); |
|
281 | setAxisOpacity(0); | |
282 | setGridOpacity(0); |
|
282 | setGridOpacity(0); | |
283 | setLabelsOpacity(0); |
|
283 | setLabelsOpacity(0); | |
284 | setShadesOpacity(0); |
|
284 | setShadesOpacity(0); | |
285 | } |
|
285 | } | |
286 | else { |
|
286 | else { | |
287 |
|
287 | |||
288 | if (m_chartAxis->isArrowVisible()) { |
|
288 | if (m_chartAxis->isArrowVisible()) { | |
289 | setAxisOpacity(100); |
|
289 | setAxisOpacity(100); | |
290 | } |
|
290 | } | |
291 | else { |
|
291 | else { | |
292 | setAxisOpacity(0); |
|
292 | setAxisOpacity(0); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | if (m_chartAxis->isGridLineVisible()) { |
|
295 | if (m_chartAxis->isGridLineVisible()) { | |
296 | setGridOpacity(100); |
|
296 | setGridOpacity(100); | |
297 | } |
|
297 | } | |
298 | else { |
|
298 | else { | |
299 | setGridOpacity(0); |
|
299 | setGridOpacity(0); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | if (m_chartAxis->labelsVisible()) { |
|
302 | if (m_chartAxis->labelsVisible()) { | |
303 | setLabelsOpacity(100); |
|
303 | setLabelsOpacity(100); | |
304 | } |
|
304 | } | |
305 | else { |
|
305 | else { | |
306 | setLabelsOpacity(0); |
|
306 | setLabelsOpacity(0); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | if (m_chartAxis->shadesVisible()) { |
|
309 | if (m_chartAxis->shadesVisible()) { | |
310 | setShadesOpacity(100); |
|
310 | setShadesOpacity(100); | |
311 | } |
|
311 | } | |
312 | else { |
|
312 | else { | |
313 | setShadesOpacity(0); |
|
313 | setShadesOpacity(0); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
317 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
318 | setAxisPen(m_chartAxis->axisPen()); |
|
318 | setAxisPen(m_chartAxis->axisPen()); | |
319 | setLabelsPen(m_chartAxis->labelsPen()); |
|
319 | setLabelsPen(m_chartAxis->labelsPen()); | |
320 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
320 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
321 | setLabelsFont(m_chartAxis->labelsFont()); |
|
321 | setLabelsFont(m_chartAxis->labelsFont()); | |
322 | setGridPen(m_chartAxis->gridLinePen()); |
|
322 | setGridPen(m_chartAxis->gridLinePen()); | |
323 | setShadesPen(m_chartAxis->shadesPen()); |
|
323 | setShadesPen(m_chartAxis->shadesPen()); | |
324 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
324 | setShadesBrush(m_chartAxis->shadesBrush()); | |
325 |
|
325 | |||
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | void ChartAxis::handleGeometryChanged(const QRectF &rect) |
|
328 | void ChartAxis::handleGeometryChanged(const QRectF &rect) | |
329 | { |
|
329 | { | |
330 | if(m_rect != rect) |
|
330 | if(m_rect != rect) | |
331 | { |
|
331 | { | |
332 | m_rect = rect; |
|
332 | m_rect = rect; | |
333 | if (isEmpty()) return; |
|
333 | if (isEmpty()) return; | |
334 | QVector<qreal> layout = calculateLayout(); |
|
334 | QVector<qreal> layout = calculateLayout(); | |
335 | updateLayout(layout); |
|
335 | updateLayout(layout); | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 |
|
339 | |||
340 | qreal ChartAxis::minimumWidth() |
|
340 | qreal ChartAxis::minimumWidth() | |
341 | { |
|
341 | { | |
342 | if(m_minWidth == 0) updateGeometry(); |
|
342 | if(m_minWidth == 0) updateGeometry(); | |
343 | return m_minWidth; |
|
343 | return m_minWidth; | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | qreal ChartAxis::minimumHeight() |
|
346 | qreal ChartAxis::minimumHeight() | |
347 | { |
|
347 | { | |
348 | if(m_minHeight == 0) updateGeometry(); |
|
348 | if(m_minHeight == 0) updateGeometry(); | |
349 | return m_minHeight; |
|
349 | return m_minHeight; | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 |
|
352 | |||
353 | void ChartAxis::axisSelected() |
|
353 | void ChartAxis::axisSelected() | |
354 | { |
|
354 | { | |
355 | qDebug()<<"TODO: axis clicked"; |
|
355 | qDebug()<<"TODO: axis clicked"; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 |
|
358 | |||
359 | void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const |
|
359 | void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const | |
360 | { |
|
360 | { | |
361 | Q_ASSERT(max>min); |
|
361 | Q_ASSERT(max>min); | |
362 | Q_ASSERT(ticks>1); |
|
362 | Q_ASSERT(ticks>1); | |
363 |
|
363 | |||
364 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
364 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
365 | n++; |
|
365 | n++; | |
366 | for (int i=0; i< ticks; i++) { |
|
366 | for (int i=0; i< ticks; i++) { | |
367 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
367 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
368 | labels << QString::number(value,'f',n); |
|
368 | labels << QString::number(value,'f',n); | |
369 | } |
|
369 | } | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const |
|
372 | void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const | |
373 | { |
|
373 | { | |
374 | Q_ASSERT(max>min); |
|
374 | Q_ASSERT(max>min); | |
375 | Q_UNUSED(max); |
|
375 | Q_UNUSED(max); | |
376 |
|
376 | |||
377 |
int x = q |
|
377 | int x = qFloor(min+0.5); | |
378 | int count = 0; |
|
378 | int count = 0; | |
379 |
|
379 | |||
380 | // Try to find category for x coordinate |
|
380 | // Try to find category for x coordinate | |
381 | while (count < categories.count()) { |
|
381 | while (count < categories.count()+1) { | |
382 | if ((x < categories.count()) && (x >= 0)) { |
|
382 | if ((x < categories.count()) && (x >= 0)) { | |
383 | labels << categories.at(x); |
|
383 | labels << categories.at(x); | |
384 | } else { |
|
384 | } else { | |
385 | // No label for x coordinate |
|
385 | // No label for x coordinate | |
386 | labels << ""; |
|
386 | labels << ""; | |
387 | } |
|
387 | } | |
388 | x++; |
|
388 | x++; | |
389 | count++; |
|
389 | count++; | |
390 | } |
|
390 | } | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | #include "moc_chartaxis_p.cpp" |
|
393 | #include "moc_chartaxis_p.cpp" | |
394 |
|
394 | |||
395 | QTCOMMERCIALCHART_END_NAMESPACE |
|
395 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now