@@ -1,164 +1,184 | |||||
1 | #include "axisitem_p.h" |
|
1 | #include "axisitem_p.h" | |
|
2 | #include "qchartaxis.h" | |||
2 | #include <QPainter> |
|
3 | #include <QPainter> | |
3 | #include <QDebug> |
|
4 | #include <QDebug> | |
4 |
|
5 | |||
5 | #define LABEL_PADDING 5 |
|
6 | #define LABEL_PADDING 5 | |
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
9 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : |
|
10 | AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : | |
10 | ChartItem(parent), |
|
11 | ChartItem(parent), | |
|
12 | m_axis(axis), | |||
11 | m_ticks(4), |
|
13 | m_ticks(4), | |
12 | m_type(type) |
|
14 | m_type(type) | |
13 | { |
|
15 | { | |
14 | } |
|
16 | } | |
15 |
|
17 | |||
16 | AxisItem::~AxisItem() |
|
18 | AxisItem::~AxisItem() | |
17 | { |
|
19 | { | |
18 | } |
|
20 | } | |
19 |
|
21 | |||
20 | void AxisItem::setLength(int length) |
|
22 | void AxisItem::setLength(int length) | |
21 | { |
|
23 | { | |
22 | QPainterPath path; |
|
24 | QPainterPath path; | |
23 | path.moveTo(QPointF(0,0)); |
|
25 | path.moveTo(QPointF(0,0)); | |
24 | path.lineTo(length,0); |
|
26 | path.lineTo(length,0); | |
25 | // path.lineTo(length-4,0); |
|
27 | // path.lineTo(length-4,0); | |
26 | // path.lineTo(length,3); |
|
28 | // path.lineTo(length,3); | |
27 | // path.lineTo(length-4,6); |
|
29 | // path.lineTo(length-4,6); | |
28 | // path.lineTo(length-4,4); |
|
30 | // path.lineTo(length-4,4); | |
29 | // path.lineTo(0,4); |
|
31 | // path.lineTo(0,4); | |
30 | // path.lineTo(0,2); |
|
32 | // path.lineTo(0,2); | |
31 | m_path=path; |
|
33 | m_path=path; | |
32 | update(); |
|
34 | update(); | |
33 | } |
|
35 | } | |
34 |
|
36 | |||
35 | QRectF AxisItem::boundingRect() const |
|
37 | QRectF AxisItem::boundingRect() const | |
36 | { |
|
38 | { | |
37 | return m_rect; |
|
39 | return m_rect; | |
38 | } |
|
40 | } | |
39 |
|
41 | |||
40 | void AxisItem::setPlotDomain(const PlotDomain& plotDomain) |
|
|||
41 | { |
|
|||
42 | m_plotDomain = plotDomain; |
|
|||
43 | createItems(); |
|
|||
44 | } |
|
|||
45 |
|
||||
46 | void AxisItem::setSize(const QSizeF &size) |
|
|||
47 | { |
|
|||
48 | m_rect = QRectF(QPoint(0,0),size); |
|
|||
49 | createItems(); |
|
|||
50 | } |
|
|||
51 |
|
42 | |||
52 | /* |
|
43 | /* | |
53 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) |
|
44 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |
54 | { |
|
45 | { | |
55 | if (!m_rect.isValid()) |
|
46 | if (!m_rect.isValid()) | |
56 | return; |
|
47 | return; | |
57 |
|
48 | |||
58 | if(m_type==X_AXIS) { |
|
49 | if(m_type==X_AXIS) { | |
59 |
|
50 | |||
60 | const qreal deltaX = m_rect.width() / m_ticks; |
|
51 | const qreal deltaX = m_rect.width() / m_ticks; | |
61 |
|
52 | |||
62 | for (int i = 0; i <= m_ticks; ++i) { |
|
53 | for (int i = 0; i <= m_ticks; ++i) { | |
63 |
|
54 | |||
64 | int x = i * deltaX + m_rect.left(); |
|
55 | int x = i * deltaX + m_rect.left(); | |
65 |
|
56 | |||
66 | if(i==0) x--; |
|
57 | if(i==0) x--; | |
67 | if(i==m_ticks) x++; |
|
58 | if(i==m_ticks) x++; | |
68 |
|
59 | |||
69 | qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX() |
|
60 | qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX() | |
70 | / m_ticks); |
|
61 | / m_ticks); | |
71 | painter->drawLine(x, m_rect.top()-1, x, m_rect.bottom()+1); |
|
62 | painter->drawLine(x, m_rect.top()-1, x, m_rect.bottom()+1); | |
72 | // painter->drawLine(x, m_rect.bottom()-1, x, m_rect.bottom()-1 + 5); |
|
63 | // painter->drawLine(x, m_rect.bottom()-1, x, m_rect.bottom()-1 + 5); | |
73 |
|
64 | |||
74 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,Qt::AlignHCenter | Qt::AlignTop, QString::number(label)); |
|
65 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,Qt::AlignHCenter | Qt::AlignTop, QString::number(label)); | |
75 | } |
|
66 | } | |
76 | } |
|
67 | } | |
77 |
|
68 | |||
78 | if(m_type==Y_AXIS) { |
|
69 | if(m_type==Y_AXIS) { | |
79 |
|
70 | |||
80 | const qreal deltaY = (m_rect.height()) / m_ticks; |
|
71 | const qreal deltaY = (m_rect.height()) / m_ticks; | |
81 |
|
72 | |||
82 | for (int j = 0; j <= m_ticks; ++j) { |
|
73 | for (int j = 0; j <= m_ticks; ++j) { | |
83 |
|
74 | |||
84 | int y = j * -deltaY + m_rect.bottom(); |
|
75 | int y = j * -deltaY + m_rect.bottom(); | |
85 |
|
76 | |||
86 | if(j==0) y++; |
|
77 | if(j==0) y++; | |
87 | if(j==m_ticks) y--; |
|
78 | if(j==m_ticks) y--; | |
88 |
|
79 | |||
89 | qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY() |
|
80 | qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY() | |
90 | / m_ticks); |
|
81 | / m_ticks); | |
91 |
|
82 | |||
92 | painter->drawLine(m_rect.left()-1, y, m_rect.right()+1, y); |
|
83 | painter->drawLine(m_rect.left()-1, y, m_rect.right()+1, y); | |
93 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); |
|
84 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); | |
94 | //TODO : margin = 50 ; |
|
85 | //TODO : margin = 50 ; | |
95 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, |
|
86 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, | |
96 | Qt::AlignRight | Qt::AlignVCenter, |
|
87 | Qt::AlignRight | Qt::AlignVCenter, | |
97 | QString::number(label)); |
|
88 | QString::number(label)); | |
98 | } |
|
89 | } | |
99 | } |
|
90 | } | |
100 |
|
91 | |||
101 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); |
|
92 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); | |
102 | } |
|
93 | } | |
103 | */ |
|
94 | */ | |
104 | void AxisItem::createItems() |
|
95 | void AxisItem::createItems() | |
105 | { |
|
96 | { | |
106 |
|
97 | |||
107 | //TODO: this is very inefficient handling |
|
98 | if(!m_rect.isValid()) return; | |
108 |
|
||||
109 | qDeleteAll(m_shades); |
|
|||
110 | m_shades.clear(); |
|
|||
111 | qDeleteAll(m_grid); |
|
|||
112 | m_grid.clear(); |
|
|||
113 | qDeleteAll(m_labels); |
|
|||
114 | m_labels.clear(); |
|
|||
115 |
|
||||
116 |
|
99 | |||
117 | if(m_type==X_AXIS) { |
|
100 | if(m_type==X_AXIS) { | |
118 |
|
101 | |||
119 | const qreal deltaX = m_rect.width() / m_ticks; |
|
102 | const qreal deltaX = m_rect.width() / m_ticks; | |
120 |
|
103 | |||
121 | for (int i = 0; i <= m_ticks; ++i) { |
|
104 | for (int i = 0; i <= m_ticks; ++i) { | |
122 |
|
105 | |||
123 | int x = i * deltaX + m_rect.left(); |
|
106 | int x = i * deltaX + m_rect.left(); | |
124 |
|
107 | |||
125 |
qreal label = m_ |
|
108 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); | |
126 |
|
109 | |||
127 | m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this); |
|
110 | m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this); | |
128 |
|
111 | |||
129 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); |
|
112 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); | |
130 | QPointF center = text->boundingRect().center(); |
|
113 | QPointF center = text->boundingRect().center(); | |
131 | text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING); |
|
114 | text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING); | |
132 | //text->rotate(-45); |
|
115 | //text->rotate(-45); | |
133 | m_labels<<text; |
|
116 | m_labels<<text; | |
134 | } |
|
117 | } | |
135 | } |
|
118 | } | |
136 |
|
119 | |||
137 | if(m_type==Y_AXIS) { |
|
120 | if(m_type==Y_AXIS) { | |
138 |
|
121 | |||
139 | const qreal deltaY = m_rect.height()/ m_ticks; |
|
122 | const qreal deltaY = m_rect.height()/ m_ticks; | |
140 |
|
123 | |||
141 | for (int j = 0; j <= m_ticks; ++j) { |
|
124 | for (int j = 0; j <= m_ticks; ++j) { | |
142 |
|
125 | |||
143 | int y = j * -deltaY + m_rect.bottom(); |
|
126 | int y = j * -deltaY + m_rect.bottom(); | |
144 |
|
127 | |||
145 |
qreal label = m_ |
|
128 | qreal label = m_domain.m_minY + (j * m_domain.spanY() | |
146 | / m_ticks); |
|
129 | / m_ticks); | |
147 |
|
130 | |||
148 | m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this); |
|
131 | m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this); | |
149 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); |
|
132 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); | |
150 | QPointF center = text->boundingRect().center(); |
|
133 | QPointF center = text->boundingRect().center(); | |
151 |
|
134 | |||
152 | text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y()); |
|
135 | text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y()); | |
153 | //text->rotate(-45); |
|
136 | //text->rotate(-45); | |
154 | m_labels<<text; |
|
137 | m_labels<<text; | |
155 |
|
138 | |||
156 | } |
|
139 | } | |
157 | } |
|
140 | } | |
158 |
|
141 | |||
159 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); |
|
142 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); | |
160 | } |
|
143 | } | |
161 |
|
144 | |||
|
145 | void AxisItem::clear() | |||
|
146 | { | |||
|
147 | qDeleteAll(m_shades); | |||
|
148 | m_shades.clear(); | |||
|
149 | qDeleteAll(m_grid); | |||
|
150 | m_grid.clear(); | |||
|
151 | qDeleteAll(m_labels); | |||
|
152 | m_labels.clear(); | |||
|
153 | } | |||
|
154 | ||||
|
155 | void AxisItem::updateDomain() | |||
|
156 | { | |||
|
157 | clear(); | |||
|
158 | createItems(); | |||
|
159 | } | |||
|
160 | ||||
|
161 | void AxisItem::handleAxisChanged() | |||
|
162 | { | |||
|
163 | //m_axis-> | |||
|
164 | } | |||
|
165 | ||||
|
166 | void AxisItem::handleDomainChanged(const Domain& domain) | |||
|
167 | { | |||
|
168 | m_domain = domain; | |||
|
169 | clear(); | |||
|
170 | createItems(); | |||
|
171 | } | |||
|
172 | ||||
|
173 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |||
|
174 | { | |||
|
175 | Q_ASSERT(rect.isValid()); | |||
|
176 | m_rect = rect; | |||
|
177 | clear(); | |||
|
178 | createItems(); | |||
|
179 | } | |||
|
180 | ||||
162 | //TODO "nice numbers algorithm" |
|
181 | //TODO "nice numbers algorithm" | |
|
182 | #include "moc_axisitem_p.cpp" | |||
163 |
|
183 | |||
164 | QTCOMMERCIALCHART_END_NAMESPACE |
|
184 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,73 | |||||
1 | #ifndef AXISITEM_H_ |
|
1 | #ifndef AXISITEM_H_ | |
2 | #define AXISITEM_H_ |
|
2 | #define AXISITEM_H_ | |
3 |
|
3 | |||
4 |
#include " |
|
4 | #include "domain_p.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class AxisItem : public ChartItem |
|
10 | class QChartAxis; | |
|
11 | ||||
|
12 | class AxisItem : public QObject, public ChartItem | |||
11 | { |
|
13 | { | |
|
14 | Q_OBJECT | |||
12 | public: |
|
15 | public: | |
13 | enum AxisType{X_AXIS,Y_AXIS}; |
|
16 | enum AxisType{X_AXIS,Y_AXIS}; | |
14 |
|
17 | |||
15 | AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); |
|
18 | AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
16 | ~AxisItem(); |
|
19 | ~AxisItem(); | |
17 |
|
20 | |||
18 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
19 | QRectF boundingRect() const; |
|
22 | QRectF boundingRect() const; | |
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; | |
21 |
|
24 | |||
|
25 | protected slots: | |||
|
26 | void handleAxisChanged(); | |||
|
27 | void handleDomainChanged(const Domain& domain); | |||
|
28 | void handleGeometryChanged(const QRectF& size); | |||
|
29 | ||||
|
30 | protected: | |||
|
31 | void updateDomain(); | |||
|
32 | ||||
|
33 | private: | |||
|
34 | void clear(); | |||
|
35 | ||||
|
36 | ||||
22 | public: // from ChartItem |
|
37 | public: // from ChartItem | |
23 | void setSize(const QSizeF &size); |
|
38 | void setSize(const QSizeF &size){}; | |
24 | void setPlotDomain(const PlotDomain& data); |
|
39 | void setPlotDomain(const PlotDomain& data){}; | |
25 |
|
40 | |||
26 | public: |
|
41 | public: | |
27 | void setLength(int length); |
|
42 | void setLength(int length); | |
28 | void setWidth(int width); |
|
43 | void setWidth(int width); | |
29 | AxisType axisType() const {return m_type;}; |
|
44 | AxisType axisType() const {return m_type;}; | |
30 |
|
45 | |||
|
46 | protected: | |||
|
47 | ||||
|
48 | ||||
31 | private: |
|
49 | private: | |
32 | void createItems(); |
|
50 | void createItems(); | |
33 | private: |
|
51 | private: | |
34 | QRectF m_rect; |
|
52 | ||
|
53 | QChartAxis* m_axis; | |||
|
54 | AxisType m_type; | |||
35 | int m_ticks; |
|
55 | int m_ticks; | |
36 |
|
|
56 | Domain m_domain; | |
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | QRectF m_rect; | |||
|
61 | ||||
37 | QPainterPath m_path; |
|
62 | QPainterPath m_path; | |
38 |
|
63 | |||
|
64 | ||||
39 | QList<QGraphicsLineItem*> m_grid; |
|
65 | QList<QGraphicsLineItem*> m_grid; | |
40 | QList<QGraphicsRectItem*> m_shades; |
|
66 | QList<QGraphicsRectItem*> m_shades; | |
41 | QList<QGraphicsSimpleTextItem*> m_labels; |
|
67 | QList<QGraphicsSimpleTextItem*> m_labels; | |
42 | AxisType m_type; |
|
68 | ||
43 | }; |
|
69 | }; | |
44 |
|
70 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
72 | |||
47 | #endif /* AXISITEM_H_ */ |
|
73 | #endif /* AXISITEM_H_ */ |
@@ -1,226 +1,243 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
|
2 | #include "qchartaxis.h" | |||
2 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
3 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
4 | //series |
|
5 | //series | |
5 | #include "barchartseries.h" |
|
6 | #include "barchartseries.h" | |
6 | #include "stackedbarchartseries.h" |
|
7 | #include "stackedbarchartseries.h" | |
7 | #include "percentbarchartseries.h" |
|
8 | #include "percentbarchartseries.h" | |
8 | #include "qxychartseries.h" |
|
9 | #include "qxychartseries.h" | |
9 | //items |
|
10 | //items | |
|
11 | #include "axisitem_p.h" | |||
10 | #include "bargroup.h" |
|
12 | #include "bargroup.h" | |
11 | #include "stackedbargroup.h" |
|
13 | #include "stackedbargroup.h" | |
12 | #include "xylinechartitem_p.h" |
|
14 | #include "xylinechartitem_p.h" | |
13 | #include "percentbargroup.h" |
|
15 | #include "percentbargroup.h" | |
14 | #include "linechartanimationitem_p.h" |
|
16 | #include "linechartanimationitem_p.h" | |
15 |
|
17 | |||
16 | #include <QAbstractAnimation> |
|
18 | #include <QAbstractAnimation> | |
17 | #include <QPropertyAnimation> |
|
19 | #include <QPropertyAnimation> | |
18 |
|
20 | |||
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
20 |
|
22 | |||
21 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
23 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
22 | m_chart(chart), |
|
24 | m_chart(chart), | |
23 | m_dataset(dataset), |
|
25 | m_dataset(dataset), | |
24 | m_domainIndex(0), |
|
26 | m_domainIndex(0), | |
25 | m_marginSize(0), |
|
27 | m_marginSize(0), | |
26 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
28 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
27 | { |
|
29 | { | |
28 |
|
|
30 | createConnections(); | |
|
31 | createDeafultAxis(); | |||
29 | } |
|
32 | } | |
30 |
|
33 | |||
31 | ChartPresenter::~ChartPresenter() |
|
34 | ChartPresenter::~ChartPresenter() | |
32 | { |
|
35 | { | |
33 | } |
|
36 | } | |
34 |
|
37 | |||
35 |
void ChartPresenter::cre |
|
38 | void ChartPresenter::createDeafultAxis() | |
|
39 | { | |||
|
40 | //default axis | |||
|
41 | QChartAxis* axisX = new QChartAxis(this); | |||
|
42 | QChartAxis* axisY = new QChartAxis(this); | |||
|
43 | ||||
|
44 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); | |||
|
45 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); | |||
|
46 | ||||
|
47 | foreach(AxisItem* item, m_axis) { | |||
|
48 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
49 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |||
|
50 | } | |||
|
51 | } | |||
|
52 | ||||
|
53 | void ChartPresenter::createConnections() | |||
36 | { |
|
54 | { | |
37 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
55 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
38 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
56 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
39 | } |
|
57 | } | |
40 |
|
58 | |||
41 | void ChartPresenter::handleGeometryChanged() |
|
59 | void ChartPresenter::handleGeometryChanged() | |
42 | { |
|
60 | { | |
43 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
61 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
44 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
62 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
45 | emit geometryChanged(m_rect); |
|
63 | emit geometryChanged(m_rect); | |
46 | } |
|
64 | } | |
47 |
|
65 | |||
48 | int ChartPresenter::margin() const |
|
66 | int ChartPresenter::margin() const | |
49 | { |
|
67 | { | |
50 | return m_marginSize; |
|
68 | return m_marginSize; | |
51 | } |
|
69 | } | |
52 |
|
70 | |||
53 | void ChartPresenter::setMargin(int margin) |
|
71 | void ChartPresenter::setMargin(int margin) | |
54 | { |
|
72 | { | |
55 | m_marginSize = margin; |
|
73 | m_marginSize = margin; | |
56 | } |
|
74 | } | |
57 |
|
75 | |||
58 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
76 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
59 | { |
|
77 | { | |
60 | switch(series->type()) |
|
78 | switch(series->type()) | |
61 | { |
|
79 | { | |
62 | case QChartSeries::SeriesTypeLine: { |
|
80 | case QChartSeries::SeriesTypeLine: { | |
63 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); |
|
81 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); | |
64 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
82 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
65 | item->setPen(lineSeries->pen()); |
|
83 | item->setPen(lineSeries->pen()); | |
66 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
84 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
67 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
85 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
68 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
86 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
69 | m_chartItems.insert(series,item); |
|
87 | m_chartItems.insert(series,item); | |
70 | break; |
|
88 | break; | |
71 | } |
|
89 | } | |
72 |
|
90 | |||
73 | case QChartSeries::SeriesTypeBar: { |
|
91 | case QChartSeries::SeriesTypeBar: { | |
74 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
92 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
75 | BarGroup* item = new BarGroup(*barSeries,m_chart); |
|
93 | BarGroup* item = new BarGroup(*barSeries,m_chart); | |
76 |
|
94 | |||
77 | // Add some fugly colors for 5 fist series... |
|
95 | // Add some fugly colors for 5 fist series... | |
78 | item->addColor(QColor(255,0,0,128)); |
|
96 | item->addColor(QColor(255,0,0,128)); | |
79 | item->addColor(QColor(255,255,0,128)); |
|
97 | item->addColor(QColor(255,255,0,128)); | |
80 | item->addColor(QColor(0,255,0,128)); |
|
98 | item->addColor(QColor(0,255,0,128)); | |
81 | item->addColor(QColor(0,0,255,128)); |
|
99 | item->addColor(QColor(0,0,255,128)); | |
82 | item->addColor(QColor(255,128,0,128)); |
|
100 | item->addColor(QColor(255,128,0,128)); | |
83 |
|
101 | |||
84 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
102 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
85 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
103 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
86 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
104 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
87 | m_chartItems.insert(series,item); |
|
105 | m_chartItems.insert(series,item); | |
88 | // m_axisXItem->setVisible(false); |
|
106 | // m_axisXItem->setVisible(false); | |
89 | break; |
|
107 | break; | |
90 | } |
|
108 | } | |
91 |
|
109 | |||
92 | case QChartSeries::SeriesTypeStackedBar: { |
|
110 | case QChartSeries::SeriesTypeStackedBar: { | |
93 |
|
111 | |||
94 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
112 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
95 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); |
|
113 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); | |
96 |
|
114 | |||
97 | // Add some fugly colors for 5 fist series... |
|
115 | // Add some fugly colors for 5 fist series... | |
98 | item->addColor(QColor(255,0,0,128)); |
|
116 | item->addColor(QColor(255,0,0,128)); | |
99 | item->addColor(QColor(255,255,0,128)); |
|
117 | item->addColor(QColor(255,255,0,128)); | |
100 | item->addColor(QColor(0,255,0,128)); |
|
118 | item->addColor(QColor(0,255,0,128)); | |
101 | item->addColor(QColor(0,0,255,128)); |
|
119 | item->addColor(QColor(0,0,255,128)); | |
102 | item->addColor(QColor(255,128,0,128)); |
|
120 | item->addColor(QColor(255,128,0,128)); | |
103 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
121 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
104 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
122 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
105 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
123 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
106 | m_chartItems.insert(series,item); |
|
124 | m_chartItems.insert(series,item); | |
107 | break; |
|
125 | break; | |
108 | } |
|
126 | } | |
109 |
|
127 | |||
110 | case QChartSeries::SeriesTypePercentBar: { |
|
128 | case QChartSeries::SeriesTypePercentBar: { | |
111 |
|
129 | |||
112 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
130 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
113 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); |
|
131 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); | |
114 |
|
132 | |||
115 | // Add some fugly colors for 5 fist series... |
|
133 | // Add some fugly colors for 5 fist series... | |
116 | item->addColor(QColor(255,0,0,128)); |
|
134 | item->addColor(QColor(255,0,0,128)); | |
117 | item->addColor(QColor(255,255,0,128)); |
|
135 | item->addColor(QColor(255,255,0,128)); | |
118 | item->addColor(QColor(0,255,0,128)); |
|
136 | item->addColor(QColor(0,255,0,128)); | |
119 | item->addColor(QColor(0,0,255,128)); |
|
137 | item->addColor(QColor(0,0,255,128)); | |
120 | item->addColor(QColor(255,128,0,128)); |
|
138 | item->addColor(QColor(255,128,0,128)); | |
121 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
139 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
122 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
140 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
123 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
141 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
124 | m_chartItems.insert(series,item); |
|
142 | m_chartItems.insert(series,item); | |
125 | break; |
|
143 | break; | |
126 |
|
|
144 | } | |
127 | /* |
|
145 | /* | |
128 | case QChartSeries::SeriesTypeScatter: { |
|
146 | case QChartSeries::SeriesTypeScatter: { | |
129 |
|
|
147 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
130 |
|
|
148 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
131 |
|
|
149 | scatterSeries->d->setParentItem(this); | |
132 |
|
|
150 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
133 |
|
|
151 | m_chartItems << scatterSeries->d; | |
134 |
|
|
152 | m_chartTheme->addObserver(scatterSeries->d); | |
135 |
|
153 | |||
136 | foreach (qreal x, scatterSeries->d->m_x) { |
|
154 | foreach (qreal x, scatterSeries->d->m_x) { | |
137 | domain.m_minX = qMin(domain.m_minX, x); |
|
155 | domain.m_minX = qMin(domain.m_minX, x); | |
138 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
156 | domain.m_maxX = qMax(domain.m_maxX, x); | |
139 | } |
|
157 | } | |
140 | foreach (qreal y, scatterSeries->d->m_y) { |
|
158 | foreach (qreal y, scatterSeries->d->m_y) { | |
141 | domain.m_minY = qMin(domain.m_minY, y); |
|
159 | domain.m_minY = qMin(domain.m_minY, y); | |
142 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
160 | domain.m_maxY = qMax(domain.m_maxY, y); | |
143 | } |
|
161 | } | |
144 |
|
162 | |||
145 | break; |
|
163 | break; | |
146 | } |
|
164 | } | |
147 | case QChartSeries::SeriesTypePie: { |
|
165 | case QChartSeries::SeriesTypePie: { | |
148 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
166 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
149 | pieSeries->d->setParentItem(this); |
|
167 | pieSeries->d->setParentItem(this); | |
150 | m_chartItems << pieSeries->d; |
|
168 | m_chartItems << pieSeries->d; | |
151 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
169 | pieSeries->d->m_chartTheme = m_chartTheme; | |
152 | m_chartTheme->addObserver(pieSeries->d); |
|
170 | m_chartTheme->addObserver(pieSeries->d); | |
153 | break; |
|
171 | break; | |
154 | } |
|
172 | } | |
155 | default: |
|
173 | default: | |
156 | break; |
|
174 | break; | |
157 | } |
|
175 | } | |
158 | */ |
|
176 | */ | |
159 |
|
177 | |||
160 | default: { |
|
178 | default: { | |
161 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
179 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
162 | break; |
|
180 | break; | |
163 | } |
|
181 | } | |
164 | } |
|
182 | } | |
165 | } |
|
183 | } | |
166 |
|
184 | |||
167 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
185 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
168 | { |
|
186 | { | |
169 | //TODO: |
|
187 | //TODO: | |
170 | } |
|
188 | } | |
171 |
|
189 | |||
172 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
190 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
173 | { |
|
191 | { | |
174 | if(!rect.isValid()) return; |
|
192 | if(!rect.isValid()) return; | |
175 | QRectF r = rect.normalized(); |
|
193 | QRectF r = rect.normalized(); | |
176 | r.translate(-m_marginSize, -m_marginSize); |
|
194 | r.translate(-m_marginSize, -m_marginSize); | |
177 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
195 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
178 | m_dataset->addDomain(domain); |
|
196 | m_dataset->addDomain(domain); | |
179 | } |
|
197 | } | |
180 |
|
198 | |||
181 |
|
||||
182 | void ChartPresenter::zoomIn() |
|
199 | void ChartPresenter::zoomIn() | |
183 | { |
|
200 | { | |
184 | if (!m_dataset->nextDomain()) { |
|
201 | if (!m_dataset->nextDomain()) { | |
185 | QRectF rect = m_rect; |
|
202 | QRectF rect = m_rect; | |
186 | rect.setWidth(rect.width()/2); |
|
203 | rect.setWidth(rect.width()/2); | |
187 | rect.setHeight(rect.height()/2); |
|
204 | rect.setHeight(rect.height()/2); | |
188 | rect.moveCenter(m_rect.center()); |
|
205 | rect.moveCenter(m_rect.center()); | |
189 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
206 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
190 | m_dataset->addDomain(domain); |
|
207 | m_dataset->addDomain(domain); | |
191 | } |
|
208 | } | |
192 | } |
|
209 | } | |
193 |
|
210 | |||
194 | void ChartPresenter::zoomOut() |
|
211 | void ChartPresenter::zoomOut() | |
195 | { |
|
212 | { | |
196 | m_dataset->previousDomain(); |
|
213 | m_dataset->previousDomain(); | |
197 | } |
|
214 | } | |
198 |
|
215 | |||
199 | void ChartPresenter::zoomReset() |
|
216 | void ChartPresenter::zoomReset() | |
200 | { |
|
217 | { | |
201 | m_dataset->clearDomains(); |
|
218 | m_dataset->clearDomains(); | |
202 | } |
|
219 | } | |
203 |
|
220 | |||
204 | /* |
|
221 | /* | |
205 | void ChartPresenter::setAxisX(const QChartAxis& axis) |
|
222 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |
206 | { |
|
223 | { | |
207 |
|
|
224 | setAxis(m_axisXItem,axis); | |
208 | } |
|
225 | } | |
209 | void ChartPresenter::setAxisY(const QChartAxis& axis) |
|
226 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |
210 | { |
|
227 | { | |
211 |
|
|
228 | setAxis(m_axisYItem.at(0),axis); | |
212 | } |
|
229 | } | |
213 |
|
230 | |||
214 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) |
|
231 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |
215 | { |
|
232 | { | |
216 |
|
|
233 | //TODO not implemented | |
217 | } |
|
234 | } | |
218 |
|
235 | |||
219 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) |
|
236 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |
220 | { |
|
237 | { | |
221 |
|
|
238 | item->setVisible(axis.isAxisVisible()); | |
222 | } |
|
239 | } | |
223 | */ |
|
240 | */ | |
224 | #include "moc_chartpresenter_p.cpp" |
|
241 | #include "moc_chartpresenter_p.cpp" | |
225 |
|
242 | |||
226 | QTCOMMERCIALCHART_END_NAMESPACE |
|
243 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,64 +1,65 | |||||
1 | #ifndef CHARTPRESENTER_H_ |
|
1 | #ifndef CHARTPRESENTER_H_ | |
2 | #define CHARTPRESENTER_H_ |
|
2 | #define CHARTPRESENTER_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class ChartItem; |
|
9 | class ChartItem; | |
10 | class QChartSeries; |
|
10 | class QChartSeries; | |
11 | class ChartDataSet; |
|
11 | class ChartDataSet; | |
12 | class QChart; |
|
12 | class QChart; | |
13 | class Domain; |
|
13 | class Domain; | |
14 | class QXYChartSeries; |
|
14 | class AxisItem; | |
15 | class XYLineChartItem; |
|
|||
16 |
|
15 | |||
17 | class ChartPresenter: public QObject |
|
16 | class ChartPresenter: public QObject | |
18 | { |
|
17 | { | |
19 | Q_OBJECT |
|
18 | Q_OBJECT | |
20 | public: |
|
19 | public: | |
21 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
20 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
22 | virtual ~ChartPresenter(); |
|
21 | virtual ~ChartPresenter(); | |
23 | /* |
|
22 | /* | |
24 | void setAxisX(const QChartAxis& axis); |
|
23 | void setAxisX(const QChartAxis& axis); | |
25 | void setAxisY(const QChartAxis& axis); |
|
24 | void setAxisY(const QChartAxis& axis); | |
26 | void setAxisY(const QList<QChartAxis>& axis); |
|
25 | void setAxisY(const QList<QChartAxis>& axis); | |
27 |
|
26 | |||
28 |
|
27 | |||
29 | */ |
|
28 | */ | |
30 |
|
29 | |||
31 | void setMargin(int margin); |
|
30 | void setMargin(int margin); | |
32 | int margin() const; |
|
31 | int margin() const; | |
33 |
|
32 | |||
34 | void zoomInToRect(const QRectF& rectangle); |
|
33 | void zoomInToRect(const QRectF& rectangle); | |
35 | void zoomIn(); |
|
34 | void zoomIn(); | |
36 | void zoomOut(); |
|
35 | void zoomOut(); | |
37 | void zoomReset(); |
|
36 | void zoomReset(); | |
38 |
|
37 | |||
39 | private: |
|
38 | private: | |
40 | void creteConnections(); |
|
39 | void createConnections(); | |
|
40 | void createDeafultAxis(); | |||
41 |
|
41 | |||
42 | public slots: |
|
42 | public slots: | |
43 | void handleSeriesAdded(QChartSeries* series); |
|
43 | void handleSeriesAdded(QChartSeries* series); | |
44 | void handleSeriesRemoved(QChartSeries* series){}; |
|
44 | void handleSeriesRemoved(QChartSeries* series){}; | |
45 | void handleSeriesChanged(QChartSeries* series); |
|
45 | void handleSeriesChanged(QChartSeries* series); | |
46 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); |
|
46 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
47 | void handleGeometryChanged(); |
|
47 | void handleGeometryChanged(); | |
48 |
|
48 | |||
49 | signals: |
|
49 | signals: | |
50 | void geometryChanged(const QRectF& rect); |
|
50 | void geometryChanged(const QRectF& rect); | |
51 |
|
51 | |||
52 | private: |
|
52 | private: | |
53 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
53 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
54 | QChart* m_chart; |
|
54 | QChart* m_chart; | |
55 | ChartDataSet* m_dataset; |
|
55 | ChartDataSet* m_dataset; | |
56 | QVector<Domain> m_domains; |
|
56 | QVector<Domain> m_domains; | |
|
57 | QList<AxisItem*> m_axis; | |||
57 | int m_domainIndex; |
|
58 | int m_domainIndex; | |
58 | int m_marginSize; |
|
59 | int m_marginSize; | |
59 | QRectF m_rect; |
|
60 | QRectF m_rect; | |
60 | }; |
|
61 | }; | |
61 |
|
62 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
63 |
|
64 | |||
64 | #endif /* CHARTPRESENTER_H_ */ |
|
65 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,232 +1,231 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
6 | #include "qpieseries_p.h" | |
7 | #include "qchartaxis.h" |
|
7 | #include "qchartaxis.h" | |
8 | #include "charttheme_p.h" |
|
8 | #include "charttheme_p.h" | |
9 | #include "chartitem_p.h" |
|
9 | #include "chartitem_p.h" | |
10 | #include "plotdomain_p.h" |
|
10 | #include "plotdomain_p.h" | |
11 | #include "axisitem_p.h" |
|
11 | #include "axisitem_p.h" | |
12 | #include "chartpresenter_p.h" |
|
12 | #include "chartpresenter_p.h" | |
13 | #include "chartdataset_p.h" |
|
13 | #include "chartdataset_p.h" | |
14 |
|
14 | |||
15 | //series |
|
15 | //series | |
16 | #include "barchartseries.h" |
|
16 | #include "barchartseries.h" | |
17 | #include "stackedbarchartseries.h" |
|
17 | #include "stackedbarchartseries.h" | |
18 | #include "percentbarchartseries.h" |
|
18 | #include "percentbarchartseries.h" | |
19 | #include "qxychartseries.h" |
|
19 | #include "qxychartseries.h" | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | #include <QGraphicsScene> |
|
22 | #include <QGraphicsScene> | |
23 | #include <QGraphicsSceneResizeEvent> |
|
23 | #include <QGraphicsSceneResizeEvent> | |
24 | #include <QDebug> |
|
24 | #include <QDebug> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
28 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
29 | m_backgroundItem(0), |
|
29 | m_backgroundItem(0), | |
30 | m_titleItem(0), |
|
30 | m_titleItem(0), | |
31 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), |
|
31 | m_axisXItem(0), | |
32 | m_plotDataIndex(0), |
|
32 | m_plotDataIndex(0), | |
33 | m_chartTheme(new ChartTheme(this)), |
|
33 | m_chartTheme(new ChartTheme(this)), | |
34 | //m_dataset(0), |
|
34 | //m_dataset(0), | |
35 | m_dataset(new ChartDataSet(this)), |
|
35 | m_dataset(new ChartDataSet(this)), | |
36 | //m_presenter(0) |
|
36 | //m_presenter(0) | |
37 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
37 | m_presenter(new ChartPresenter(this,m_dataset)) | |
38 | { |
|
38 | { | |
39 | // TODO: the default theme? |
|
39 | // TODO: the default theme? | |
40 | setTheme(QChart::ChartThemeDefault); |
|
40 | setTheme(QChart::ChartThemeDefault); | |
41 |
|
41 | |||
42 | PlotDomain domain; |
|
42 | PlotDomain domain; | |
43 | m_plotDomainList << domain; |
|
43 | m_plotDomainList << domain; | |
44 |
|
44 | |||
45 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
45 | //m_chartItems << m_axisXItem; | |
46 |
m_chartItems << m_axis |
|
46 | //m_chartItems << m_axisYItem.at(0); | |
47 | m_chartItems << m_axisYItem.at(0); |
|
|||
48 | } |
|
47 | } | |
49 |
|
48 | |||
50 | QChart::~QChart(){} |
|
49 | QChart::~QChart(){} | |
51 |
|
50 | |||
52 | void QChart::addSeries(QChartSeries* series) |
|
51 | void QChart::addSeries(QChartSeries* series) | |
53 | { |
|
52 | { | |
54 | m_dataset->addSeries(series); |
|
53 | m_dataset->addSeries(series); | |
55 | } |
|
54 | } | |
56 |
|
55 | |||
57 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
56 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
58 | { |
|
57 | { | |
59 | // TODO: support also other types; not only scatter and pie |
|
58 | // TODO: support also other types; not only scatter and pie | |
60 |
|
59 | |||
61 | QChartSeries *series(0); |
|
60 | QChartSeries *series(0); | |
62 |
|
61 | |||
63 | switch (type) { |
|
62 | switch (type) { | |
64 | case QChartSeries::SeriesTypeLine: { |
|
63 | case QChartSeries::SeriesTypeLine: { | |
65 | series = QXYChartSeries::create(); |
|
64 | series = QXYChartSeries::create(); | |
66 | break; |
|
65 | break; | |
67 | } |
|
66 | } | |
68 | case QChartSeries::SeriesTypeBar: { |
|
67 | case QChartSeries::SeriesTypeBar: { | |
69 | series = new BarChartSeries(this); |
|
68 | series = new BarChartSeries(this); | |
70 | break; |
|
69 | break; | |
71 | } |
|
70 | } | |
72 | case QChartSeries::SeriesTypeStackedBar: { |
|
71 | case QChartSeries::SeriesTypeStackedBar: { | |
73 | series = new StackedBarChartSeries(this); |
|
72 | series = new StackedBarChartSeries(this); | |
74 | break; |
|
73 | break; | |
75 | } |
|
74 | } | |
76 | case QChartSeries::SeriesTypePercentBar: { |
|
75 | case QChartSeries::SeriesTypePercentBar: { | |
77 | series = new PercentBarChartSeries(this); |
|
76 | series = new PercentBarChartSeries(this); | |
78 | break; |
|
77 | break; | |
79 | } |
|
78 | } | |
80 | case QChartSeries::SeriesTypeScatter: { |
|
79 | case QChartSeries::SeriesTypeScatter: { | |
81 | series = new QScatterSeries(this); |
|
80 | series = new QScatterSeries(this); | |
82 | break; |
|
81 | break; | |
83 | } |
|
82 | } | |
84 | case QChartSeries::SeriesTypePie: { |
|
83 | case QChartSeries::SeriesTypePie: { | |
85 | series = new QPieSeries(this); |
|
84 | series = new QPieSeries(this); | |
86 | break; |
|
85 | break; | |
87 | } |
|
86 | } | |
88 | default: |
|
87 | default: | |
89 | Q_ASSERT(false); |
|
88 | Q_ASSERT(false); | |
90 | break; |
|
89 | break; | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 | addSeries(series); |
|
92 | addSeries(series); | |
94 | return series; |
|
93 | return series; | |
95 | } |
|
94 | } | |
96 |
|
95 | |||
97 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
96 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
98 | { |
|
97 | { | |
99 |
|
98 | |||
100 | if(!m_backgroundItem){ |
|
99 | if(!m_backgroundItem){ | |
101 | m_backgroundItem = new QGraphicsRectItem(this); |
|
100 | m_backgroundItem = new QGraphicsRectItem(this); | |
102 | m_backgroundItem->setZValue(-1); |
|
101 | m_backgroundItem->setZValue(-1); | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | m_backgroundItem->setBrush(brush); |
|
104 | m_backgroundItem->setBrush(brush); | |
106 | m_backgroundItem->update(); |
|
105 | m_backgroundItem->update(); | |
107 | } |
|
106 | } | |
108 |
|
107 | |||
109 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
108 | void QChart::setChartBackgroundPen(const QPen& pen) | |
110 | { |
|
109 | { | |
111 |
|
110 | |||
112 | if(!m_backgroundItem){ |
|
111 | if(!m_backgroundItem){ | |
113 | m_backgroundItem = new QGraphicsRectItem(this); |
|
112 | m_backgroundItem = new QGraphicsRectItem(this); | |
114 | m_backgroundItem->setZValue(-1); |
|
113 | m_backgroundItem->setZValue(-1); | |
115 | } |
|
114 | } | |
116 |
|
115 | |||
117 | m_backgroundItem->setPen(pen); |
|
116 | m_backgroundItem->setPen(pen); | |
118 | m_backgroundItem->update(); |
|
117 | m_backgroundItem->update(); | |
119 | } |
|
118 | } | |
120 |
|
119 | |||
121 | void QChart::setTitle(const QString& title,const QFont& font) |
|
120 | void QChart::setTitle(const QString& title,const QFont& font) | |
122 | { |
|
121 | { | |
123 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
122 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
124 | m_titleItem->setPlainText(title); |
|
123 | m_titleItem->setPlainText(title); | |
125 | m_titleItem->setFont(font); |
|
124 | m_titleItem->setFont(font); | |
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 | int QChart::margin() const |
|
127 | int QChart::margin() const | |
129 | { |
|
128 | { | |
130 | m_presenter->margin(); |
|
129 | m_presenter->margin(); | |
131 | } |
|
130 | } | |
132 |
|
131 | |||
133 | void QChart::setMargin(int margin) |
|
132 | void QChart::setMargin(int margin) | |
134 | { |
|
133 | { | |
135 | m_presenter->setMargin(margin); |
|
134 | m_presenter->setMargin(margin); | |
136 | } |
|
135 | } | |
137 |
|
136 | |||
138 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
137 | void QChart::setTheme(QChart::ChartThemeId theme) | |
139 | { |
|
138 | { | |
140 | m_chartTheme->setTheme(theme); |
|
139 | m_chartTheme->setTheme(theme); | |
141 |
|
140 | |||
142 | QLinearGradient backgroundGradient; |
|
141 | QLinearGradient backgroundGradient; | |
143 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); |
|
142 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); | |
144 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); |
|
143 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); | |
145 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
144 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
146 | setChartBackgroundBrush(backgroundGradient); |
|
145 | setChartBackgroundBrush(backgroundGradient); | |
147 |
|
146 | |||
148 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
147 | // TODO: Move the controlling of the series presentations into private implementation of the | |
149 | // series instead of QChart controlling themes for each |
|
148 | // series instead of QChart controlling themes for each | |
150 | // In other words, the following should be used when creating xy series: |
|
149 | // In other words, the following should be used when creating xy series: | |
151 | // m_chartTheme->addObserver(xyseries) |
|
150 | // m_chartTheme->addObserver(xyseries) | |
152 | foreach (QChartSeries *series, m_chartSeries) { |
|
151 | foreach (QChartSeries *series, m_chartSeries) { | |
153 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
152 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
154 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
153 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
155 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
154 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
156 | xyseries->setPen(seriesTheme.linePen); |
|
155 | xyseries->setPen(seriesTheme.linePen); | |
157 | } |
|
156 | } | |
158 | } |
|
157 | } | |
159 |
|
158 | |||
160 | update(); |
|
159 | update(); | |
161 | } |
|
160 | } | |
162 |
|
161 | |||
163 | QChart::ChartThemeId QChart::theme() |
|
162 | QChart::ChartThemeId QChart::theme() | |
164 | { |
|
163 | { | |
165 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; |
|
164 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; | |
166 | } |
|
165 | } | |
167 |
|
166 | |||
168 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
167 | void QChart::zoomInToRect(const QRectF& rectangle) | |
169 | { |
|
168 | { | |
170 | m_presenter->zoomInToRect(rectangle); |
|
169 | m_presenter->zoomInToRect(rectangle); | |
171 | } |
|
170 | } | |
172 |
|
171 | |||
173 | void QChart::zoomIn() |
|
172 | void QChart::zoomIn() | |
174 | { |
|
173 | { | |
175 | m_presenter->zoomIn(); |
|
174 | m_presenter->zoomIn(); | |
176 | } |
|
175 | } | |
177 |
|
176 | |||
178 | void QChart::zoomOut() |
|
177 | void QChart::zoomOut() | |
179 | { |
|
178 | { | |
180 | m_presenter->zoomOut(); |
|
179 | m_presenter->zoomOut(); | |
181 | } |
|
180 | } | |
182 |
|
181 | |||
183 | void QChart::zoomReset() |
|
182 | void QChart::zoomReset() | |
184 | { |
|
183 | { | |
185 | m_presenter->zoomReset(); |
|
184 | m_presenter->zoomReset(); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | void QChart::setAxisX(const QChartAxis& axis) |
|
187 | void QChart::setAxisX(const QChartAxis& axis) | |
189 | { |
|
188 | { | |
190 | setAxis(m_axisXItem,axis); |
|
189 | setAxis(m_axisXItem,axis); | |
191 | } |
|
190 | } | |
192 | void QChart::setAxisY(const QChartAxis& axis) |
|
191 | void QChart::setAxisY(const QChartAxis& axis) | |
193 | { |
|
192 | { | |
194 | setAxis(m_axisYItem.at(0),axis); |
|
193 | setAxis(m_axisYItem.at(0),axis); | |
195 | } |
|
194 | } | |
196 |
|
195 | |||
197 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
196 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
198 | { |
|
197 | { | |
199 | //TODO not implemented |
|
198 | //TODO not implemented | |
200 | } |
|
199 | } | |
201 |
|
200 | |||
202 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
201 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
203 | { |
|
202 | { | |
204 | item->setVisible(axis.isAxisVisible()); |
|
203 | item->setVisible(axis.isAxisVisible()); | |
205 | } |
|
204 | } | |
206 |
|
205 | |||
207 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
206 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
208 | { |
|
207 | { | |
209 |
|
208 | |||
210 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
209 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
211 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
210 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
212 |
|
211 | |||
213 | // recalculate title position |
|
212 | // recalculate title position | |
214 | if (m_titleItem) { |
|
213 | if (m_titleItem) { | |
215 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
214 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
216 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
215 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
217 | } |
|
216 | } | |
218 |
|
217 | |||
219 | //recalculate background gradient |
|
218 | //recalculate background gradient | |
220 | if (m_backgroundItem) { |
|
219 | if (m_backgroundItem) { | |
221 | m_backgroundItem->setRect(rect); |
|
220 | m_backgroundItem->setRect(rect); | |
222 | } |
|
221 | } | |
223 |
|
222 | |||
224 | QGraphicsWidget::resizeEvent(event); |
|
223 | QGraphicsWidget::resizeEvent(event); | |
225 | update(); |
|
224 | update(); | |
226 | } |
|
225 | } | |
227 |
|
226 | |||
228 |
|
227 | |||
229 |
|
228 | |||
230 | #include "moc_qchart.cpp" |
|
229 | #include "moc_qchart.cpp" | |
231 |
|
230 | |||
232 | QTCOMMERCIALCHART_END_NAMESPACE |
|
231 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,43 +1,53 | |||||
1 |
|
1 | |||
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | QChartAxis::QChartAxis(): |
|
6 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), | |
7 | m_axisVisible(true), |
|
7 | m_axisVisible(true), | |
8 | m_girdVisible(true), |
|
8 | m_girdVisible(true), | |
9 | m_labelsVisible(true), |
|
9 | m_labelsVisible(true), | |
10 | m_rowShadesVisible(true) |
|
10 | m_rowShadesVisible(true) | |
11 | { |
|
11 | { | |
12 | // TODO Auto-generated constructor stub |
|
12 | // TODO Auto-generated constructor stub | |
13 |
|
13 | |||
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | QChartAxis::~QChartAxis() |
|
16 | QChartAxis::~QChartAxis() | |
17 | { |
|
17 | { | |
18 | // TODO Auto-generated destructor stub |
|
18 | // TODO Auto-generated destructor stub | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
|
21 | void QChartAxis::setAxisPen(const QPen& pen) | |||
|
22 | { | |||
|
23 | m_axisPen = pen; | |||
|
24 | } | |||
|
25 | ||||
|
26 | void QChartAxis::setAxisBrush(const QBrush& brush) | |||
|
27 | { | |||
|
28 | m_axisBrush = brush; | |||
|
29 | } | |||
|
30 | ||||
21 | void QChartAxis::setAxisVisible(bool visible) |
|
31 | void QChartAxis::setAxisVisible(bool visible) | |
22 | { |
|
32 | { | |
23 | m_axisVisible=visible; |
|
33 | m_axisVisible=visible; | |
24 | } |
|
34 | } | |
25 |
|
35 | |||
26 | void QChartAxis::setGridVisible(bool visible) |
|
36 | void QChartAxis::setGridVisible(bool visible) | |
27 | { |
|
37 | { | |
28 | m_girdVisible=visible; |
|
38 | m_girdVisible=visible; | |
29 | } |
|
39 | } | |
30 |
|
40 | |||
31 | void QChartAxis::setLabelsVisible(bool visible) |
|
41 | void QChartAxis::setLabelsVisible(bool visible) | |
32 | { |
|
42 | { | |
33 | m_labelsVisible=visible; |
|
43 | m_labelsVisible=visible; | |
34 | } |
|
44 | } | |
35 |
|
45 | |||
36 | void QChartAxis::setRowShadesVisible(bool visible) |
|
46 | void QChartAxis::setRowShadesVisible(bool visible) | |
37 | { |
|
47 | { | |
38 | m_rowShadesVisible=visible; |
|
48 | m_rowShadesVisible=visible; | |
39 | } |
|
49 | } | |
40 |
|
50 | |||
41 |
|
51 | #include "moc_qchartaxis.cpp" | ||
42 |
|
52 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
53 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,31 +1,75 | |||||
1 | #ifndef QCHARTAXIS_H_ |
|
1 | #ifndef QCHARTAXIS_H_ | |
2 | #define QCHARTAXIS_H_ |
|
2 | #define QCHARTAXIS_H_ | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
|
5 | #include <QPen> | |||
|
6 | ||||
5 |
|
7 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
9 | |||
8 | class QChartAxis |
|
10 | class QChartAxis : public QObject | |
9 | { |
|
11 | { | |
|
12 | Q_OBJECT | |||
|
13 | ||||
|
14 | Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); | |||
|
15 | Q_PROPERTY(QPen axisPen READ axisPen WRITE setAxisPen NOTIFY axisPenChanged); | |||
|
16 | Q_PROPERTY(QBrush axisBrush READ axisBrush WRITE setAxisBrush NOTIFY axisBurshChanged); | |||
|
17 | ||||
|
18 | // Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); | |||
10 | public: |
|
19 | public: | |
11 | QChartAxis(); |
|
20 | enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE }; | |
|
21 | ||||
|
22 | QChartAxis(QObject* parent = 0); | |||
12 | virtual ~QChartAxis(); |
|
23 | virtual ~QChartAxis(); | |
13 |
|
24 | |||
|
25 | //axis | |||
14 | bool isAxisVisible() const { return m_axisVisible;}; |
|
26 | bool isAxisVisible() const { return m_axisVisible;}; | |
15 | void setAxisVisible(bool visible); |
|
27 | void setAxisVisible(bool visible); | |
|
28 | void setAxisPen(const QPen& pen); | |||
|
29 | const QPen& axisPen() const { return m_axisPen;}; | |||
|
30 | void setAxisBrush(const QBrush& brush); | |||
|
31 | const QBrush& axisBrush() const { return m_axisBrush;}; | |||
|
32 | ||||
|
33 | //grid | |||
16 | bool isGridVisible() const { return m_girdVisible;}; |
|
34 | bool isGridVisible() const { return m_girdVisible;}; | |
17 | void setGridVisible(bool visible); |
|
35 | void setGridVisible(bool visible); | |
|
36 | ||||
18 | bool isLabelsVisible() const { return m_labelsVisible;}; |
|
37 | bool isLabelsVisible() const { return m_labelsVisible;}; | |
19 | void setLabelsVisible(bool visible); |
|
38 | void setLabelsVisible(bool visible); | |
|
39 | ||||
20 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; |
|
40 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; | |
21 | void setRowShadesVisible(bool visible); |
|
41 | void setRowShadesVisible(bool visible); | |
22 |
|
42 | |||
|
43 | /* | |||
|
44 | void setLabelFont(const QFont& font); | |||
|
45 | const QFont& labelFont(); | |||
|
46 | ||||
|
47 | void setLabelPen(const QPen& pen); | |||
|
48 | const QPen& labelPen(); | |||
|
49 | ||||
|
50 | void setGridPen(const QPen& pen); | |||
|
51 | const QPen& gridPen(); | |||
|
52 | ||||
|
53 | void setGridBrush(const QBrush& brush); | |||
|
54 | const QBrush& gridBrush(); | |||
|
55 | */ | |||
|
56 | ||||
|
57 | signals: | |||
|
58 | void axisVisibilityChanged(); | |||
|
59 | void axisPenChanged(); | |||
|
60 | void axisBurshChanged(); | |||
|
61 | ||||
|
62 | ||||
23 | private: |
|
63 | private: | |
|
64 | ||||
24 | bool m_axisVisible; |
|
65 | bool m_axisVisible; | |
|
66 | QPen m_axisPen; | |||
|
67 | QBrush m_axisBrush; | |||
|
68 | ||||
25 | bool m_girdVisible; |
|
69 | bool m_girdVisible; | |
26 | bool m_labelsVisible; |
|
70 | bool m_labelsVisible; | |
27 | bool m_rowShadesVisible; |
|
71 | bool m_rowShadesVisible; | |
28 | }; |
|
72 | }; | |
29 |
|
73 | |||
30 | QTCOMMERCIALCHART_END_NAMESPACE |
|
74 | QTCOMMERCIALCHART_END_NAMESPACE | |
31 | #endif /* QCHARTAXIS_H_ */ |
|
75 | #endif /* QCHARTAXIS_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now