@@ -1,73 +1,68 | |||||
1 | #ifndef AXISITEM_H_ |
|
1 | #ifndef AXISITEM_H_ | |
2 | #define AXISITEM_H_ |
|
2 | #define AXISITEM_H_ | |
3 |
|
3 | |||
4 | #include "domain_p.h" |
|
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 QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class AxisItem : public QObject, public ChartItem |
|
12 | class AxisItem : public QObject, public ChartItem | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | enum AxisType{X_AXIS,Y_AXIS}; |
|
16 | enum AxisType{X_AXIS,Y_AXIS}; | |
17 |
|
17 | |||
18 | AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); |
|
18 | AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisItem(); |
|
19 | ~AxisItem(); | |
20 |
|
20 | |||
21 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
22 | QRectF boundingRect() const; |
|
22 | QRectF boundingRect() const; | |
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; | |
24 |
|
24 | |||
25 | protected slots: |
|
25 | protected slots: | |
26 | void handleAxisChanged(); |
|
26 | void handleAxisChanged(); | |
27 | void handleDomainChanged(const Domain& domain); |
|
27 | void handleDomainChanged(const Domain& domain); | |
28 | void handleGeometryChanged(const QRectF& size); |
|
28 | void handleGeometryChanged(const QRectF& size); | |
29 |
|
29 | |||
30 | protected: |
|
30 | protected: | |
31 | void updateDomain(); |
|
31 | void updateDomain(); | |
32 |
|
32 | |||
33 | private: |
|
33 | private: | |
34 | void clear(); |
|
34 | void clear(); | |
35 |
|
35 | |||
36 |
|
||||
37 | public: // from ChartItem |
|
|||
38 | void setSize(const QSizeF &size){}; |
|
|||
39 | void setPlotDomain(const PlotDomain& data){}; |
|
|||
40 |
|
||||
41 | public: |
|
36 | public: | |
42 | void setLength(int length); |
|
37 | void setLength(int length); | |
43 | void setWidth(int width); |
|
38 | void setWidth(int width); | |
44 | AxisType axisType() const {return m_type;}; |
|
39 | AxisType axisType() const {return m_type;}; | |
45 |
|
40 | |||
46 | protected: |
|
41 | protected: | |
47 |
|
42 | |||
48 |
|
43 | |||
49 | private: |
|
44 | private: | |
50 | void createItems(); |
|
45 | void createItems(); | |
51 | private: |
|
46 | private: | |
52 |
|
47 | |||
53 | QChartAxis* m_axis; |
|
48 | QChartAxis* m_axis; | |
54 | AxisType m_type; |
|
49 | AxisType m_type; | |
55 | int m_ticks; |
|
50 | int m_ticks; | |
56 | Domain m_domain; |
|
51 | Domain m_domain; | |
57 |
|
52 | |||
58 |
|
53 | |||
59 |
|
54 | |||
60 | QRectF m_rect; |
|
55 | QRectF m_rect; | |
61 |
|
56 | |||
62 | QPainterPath m_path; |
|
57 | QPainterPath m_path; | |
63 |
|
58 | |||
64 |
|
59 | |||
65 | QList<QGraphicsLineItem*> m_grid; |
|
60 | QList<QGraphicsLineItem*> m_grid; | |
66 | QList<QGraphicsRectItem*> m_shades; |
|
61 | QList<QGraphicsRectItem*> m_shades; | |
67 | QList<QGraphicsSimpleTextItem*> m_labels; |
|
62 | QList<QGraphicsSimpleTextItem*> m_labels; | |
68 |
|
63 | |||
69 | }; |
|
64 | }; | |
70 |
|
65 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE | |
72 |
|
67 | |||
73 | #endif /* AXISITEM_H_ */ |
|
68 | #endif /* AXISITEM_H_ */ |
@@ -1,30 +1,22 | |||||
1 | #ifndef CHARTITEM_H_ |
|
1 | #ifndef CHARTITEM_H_ | |
2 | #define CHARTITEM_H_ |
|
2 | #define CHARTITEM_H_ | |
3 |
|
3 | |||
4 | #include "plotdomain_p.h" |
|
4 | #include "plotdomain_p.h" | |
5 | #include "domain_p.h" |
|
5 | #include "domain_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartAnimationManager; |
|
10 | class ChartAnimationManager; | |
11 |
|
11 | |||
12 | class ChartItem : public QGraphicsItem |
|
12 | class ChartItem : public QGraphicsItem | |
13 | { |
|
13 | { | |
14 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; |
|
14 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; | |
15 | public: |
|
15 | public: | |
16 | ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; |
|
16 | ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; | |
17 | virtual ~ChartItem(){}; |
|
17 | virtual ~ChartItem(){}; | |
18 |
|
||||
19 | virtual void setSize(const QSizeF& size) = 0; |
|
|||
20 | virtual void setPlotDomain(const PlotDomain& data) = 0; |
|
|||
21 |
|
||||
22 | //future interface |
|
|||
23 | virtual void setDomain(const Domain& data){}; |
|
|||
24 | virtual void updateItem(){}; |
|
|||
25 | virtual ChartAnimationManager* animationManager(){ return 0;}; |
|
|||
26 | }; |
|
18 | }; | |
27 |
|
19 | |||
28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
20 | QTCOMMERCIALCHART_END_NAMESPACE | |
29 |
|
21 | |||
30 | #endif /* CHARTITEM_H_ */ |
|
22 | #endif /* CHARTITEM_H_ */ |
@@ -1,231 +1,226 | |||||
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(0), |
|
31 | m_axisXItem(0), | |
32 | m_plotDataIndex(0), |
|
|||
33 | m_chartTheme(new ChartTheme(this)), |
|
32 | m_chartTheme(new ChartTheme(this)), | |
34 | //m_dataset(0), |
|
33 | //m_dataset(0), | |
35 | m_dataset(new ChartDataSet(this)), |
|
34 | m_dataset(new ChartDataSet(this)), | |
36 | //m_presenter(0) |
|
35 | //m_presenter(0) | |
37 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
36 | m_presenter(new ChartPresenter(this,m_dataset)) | |
38 | { |
|
37 | { | |
39 | // TODO: the default theme? |
|
38 | // TODO: the default theme? | |
40 | setTheme(QChart::ChartThemeDefault); |
|
39 | setTheme(QChart::ChartThemeDefault); | |
41 |
|
||||
42 | PlotDomain domain; |
|
|||
43 | m_plotDomainList << domain; |
|
|||
44 |
|
||||
45 | //m_chartItems << m_axisXItem; |
|
40 | //m_chartItems << m_axisXItem; | |
46 | //m_chartItems << m_axisYItem.at(0); |
|
41 | //m_chartItems << m_axisYItem.at(0); | |
47 | } |
|
42 | } | |
48 |
|
43 | |||
49 | QChart::~QChart(){} |
|
44 | QChart::~QChart(){} | |
50 |
|
45 | |||
51 | void QChart::addSeries(QChartSeries* series) |
|
46 | void QChart::addSeries(QChartSeries* series) | |
52 | { |
|
47 | { | |
53 | m_dataset->addSeries(series); |
|
48 | m_dataset->addSeries(series); | |
54 | } |
|
49 | } | |
55 |
|
50 | |||
56 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
51 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
57 | { |
|
52 | { | |
58 | // TODO: support also other types; not only scatter and pie |
|
53 | // TODO: support also other types; not only scatter and pie | |
59 |
|
54 | |||
60 | QChartSeries *series(0); |
|
55 | QChartSeries *series(0); | |
61 |
|
56 | |||
62 | switch (type) { |
|
57 | switch (type) { | |
63 | case QChartSeries::SeriesTypeLine: { |
|
58 | case QChartSeries::SeriesTypeLine: { | |
64 | series = QXYChartSeries::create(); |
|
59 | series = QXYChartSeries::create(); | |
65 | break; |
|
60 | break; | |
66 | } |
|
61 | } | |
67 | case QChartSeries::SeriesTypeBar: { |
|
62 | case QChartSeries::SeriesTypeBar: { | |
68 | series = new BarChartSeries(this); |
|
63 | series = new BarChartSeries(this); | |
69 | break; |
|
64 | break; | |
70 | } |
|
65 | } | |
71 | case QChartSeries::SeriesTypeStackedBar: { |
|
66 | case QChartSeries::SeriesTypeStackedBar: { | |
72 | series = new StackedBarChartSeries(this); |
|
67 | series = new StackedBarChartSeries(this); | |
73 | break; |
|
68 | break; | |
74 | } |
|
69 | } | |
75 | case QChartSeries::SeriesTypePercentBar: { |
|
70 | case QChartSeries::SeriesTypePercentBar: { | |
76 | series = new PercentBarChartSeries(this); |
|
71 | series = new PercentBarChartSeries(this); | |
77 | break; |
|
72 | break; | |
78 | } |
|
73 | } | |
79 | case QChartSeries::SeriesTypeScatter: { |
|
74 | case QChartSeries::SeriesTypeScatter: { | |
80 | series = new QScatterSeries(this); |
|
75 | series = new QScatterSeries(this); | |
81 | break; |
|
76 | break; | |
82 | } |
|
77 | } | |
83 | case QChartSeries::SeriesTypePie: { |
|
78 | case QChartSeries::SeriesTypePie: { | |
84 | series = new QPieSeries(this); |
|
79 | series = new QPieSeries(this); | |
85 | break; |
|
80 | break; | |
86 | } |
|
81 | } | |
87 | default: |
|
82 | default: | |
88 | Q_ASSERT(false); |
|
83 | Q_ASSERT(false); | |
89 | break; |
|
84 | break; | |
90 | } |
|
85 | } | |
91 |
|
86 | |||
92 | addSeries(series); |
|
87 | addSeries(series); | |
93 | return series; |
|
88 | return series; | |
94 | } |
|
89 | } | |
95 |
|
90 | |||
96 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
91 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
97 | { |
|
92 | { | |
98 |
|
93 | |||
99 | if(!m_backgroundItem){ |
|
94 | if(!m_backgroundItem){ | |
100 | m_backgroundItem = new QGraphicsRectItem(this); |
|
95 | m_backgroundItem = new QGraphicsRectItem(this); | |
101 | m_backgroundItem->setZValue(-1); |
|
96 | m_backgroundItem->setZValue(-1); | |
102 | } |
|
97 | } | |
103 |
|
98 | |||
104 | m_backgroundItem->setBrush(brush); |
|
99 | m_backgroundItem->setBrush(brush); | |
105 | m_backgroundItem->update(); |
|
100 | m_backgroundItem->update(); | |
106 | } |
|
101 | } | |
107 |
|
102 | |||
108 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
103 | void QChart::setChartBackgroundPen(const QPen& pen) | |
109 | { |
|
104 | { | |
110 |
|
105 | |||
111 | if(!m_backgroundItem){ |
|
106 | if(!m_backgroundItem){ | |
112 | m_backgroundItem = new QGraphicsRectItem(this); |
|
107 | m_backgroundItem = new QGraphicsRectItem(this); | |
113 | m_backgroundItem->setZValue(-1); |
|
108 | m_backgroundItem->setZValue(-1); | |
114 | } |
|
109 | } | |
115 |
|
110 | |||
116 | m_backgroundItem->setPen(pen); |
|
111 | m_backgroundItem->setPen(pen); | |
117 | m_backgroundItem->update(); |
|
112 | m_backgroundItem->update(); | |
118 | } |
|
113 | } | |
119 |
|
114 | |||
120 | void QChart::setTitle(const QString& title,const QFont& font) |
|
115 | void QChart::setTitle(const QString& title,const QFont& font) | |
121 | { |
|
116 | { | |
122 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
117 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
123 | m_titleItem->setPlainText(title); |
|
118 | m_titleItem->setPlainText(title); | |
124 | m_titleItem->setFont(font); |
|
119 | m_titleItem->setFont(font); | |
125 | } |
|
120 | } | |
126 |
|
121 | |||
127 | int QChart::margin() const |
|
122 | int QChart::margin() const | |
128 | { |
|
123 | { | |
129 | m_presenter->margin(); |
|
124 | m_presenter->margin(); | |
130 | } |
|
125 | } | |
131 |
|
126 | |||
132 | void QChart::setMargin(int margin) |
|
127 | void QChart::setMargin(int margin) | |
133 | { |
|
128 | { | |
134 | m_presenter->setMargin(margin); |
|
129 | m_presenter->setMargin(margin); | |
135 | } |
|
130 | } | |
136 |
|
131 | |||
137 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
132 | void QChart::setTheme(QChart::ChartThemeId theme) | |
138 | { |
|
133 | { | |
139 | m_chartTheme->setTheme(theme); |
|
134 | m_chartTheme->setTheme(theme); | |
140 |
|
135 | |||
141 | QLinearGradient backgroundGradient; |
|
136 | QLinearGradient backgroundGradient; | |
142 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); |
|
137 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); | |
143 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); |
|
138 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); | |
144 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
139 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
145 | setChartBackgroundBrush(backgroundGradient); |
|
140 | setChartBackgroundBrush(backgroundGradient); | |
146 |
|
141 | |||
147 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
142 | // TODO: Move the controlling of the series presentations into private implementation of the | |
148 | // series instead of QChart controlling themes for each |
|
143 | // series instead of QChart controlling themes for each | |
149 | // In other words, the following should be used when creating xy series: |
|
144 | // In other words, the following should be used when creating xy series: | |
150 | // m_chartTheme->addObserver(xyseries) |
|
145 | // m_chartTheme->addObserver(xyseries) | |
151 | foreach (QChartSeries *series, m_chartSeries) { |
|
146 | foreach (QChartSeries *series, m_chartSeries) { | |
152 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
147 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
153 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
148 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
154 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
149 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
155 | xyseries->setPen(seriesTheme.linePen); |
|
150 | xyseries->setPen(seriesTheme.linePen); | |
156 | } |
|
151 | } | |
157 | } |
|
152 | } | |
158 |
|
153 | |||
159 | update(); |
|
154 | update(); | |
160 | } |
|
155 | } | |
161 |
|
156 | |||
162 | QChart::ChartThemeId QChart::theme() |
|
157 | QChart::ChartThemeId QChart::theme() | |
163 | { |
|
158 | { | |
164 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; |
|
159 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; | |
165 | } |
|
160 | } | |
166 |
|
161 | |||
167 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
162 | void QChart::zoomInToRect(const QRectF& rectangle) | |
168 | { |
|
163 | { | |
169 | m_presenter->zoomInToRect(rectangle); |
|
164 | m_presenter->zoomInToRect(rectangle); | |
170 | } |
|
165 | } | |
171 |
|
166 | |||
172 | void QChart::zoomIn() |
|
167 | void QChart::zoomIn() | |
173 | { |
|
168 | { | |
174 | m_presenter->zoomIn(); |
|
169 | m_presenter->zoomIn(); | |
175 | } |
|
170 | } | |
176 |
|
171 | |||
177 | void QChart::zoomOut() |
|
172 | void QChart::zoomOut() | |
178 | { |
|
173 | { | |
179 | m_presenter->zoomOut(); |
|
174 | m_presenter->zoomOut(); | |
180 | } |
|
175 | } | |
181 |
|
176 | |||
182 | void QChart::zoomReset() |
|
177 | void QChart::zoomReset() | |
183 | { |
|
178 | { | |
184 | m_presenter->zoomReset(); |
|
179 | m_presenter->zoomReset(); | |
185 | } |
|
180 | } | |
186 |
|
181 | |||
187 | void QChart::setAxisX(const QChartAxis& axis) |
|
182 | void QChart::setAxisX(const QChartAxis& axis) | |
188 | { |
|
183 | { | |
189 | setAxis(m_axisXItem,axis); |
|
184 | setAxis(m_axisXItem,axis); | |
190 | } |
|
185 | } | |
191 | void QChart::setAxisY(const QChartAxis& axis) |
|
186 | void QChart::setAxisY(const QChartAxis& axis) | |
192 | { |
|
187 | { | |
193 | setAxis(m_axisYItem.at(0),axis); |
|
188 | setAxis(m_axisYItem.at(0),axis); | |
194 | } |
|
189 | } | |
195 |
|
190 | |||
196 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
191 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
197 | { |
|
192 | { | |
198 | //TODO not implemented |
|
193 | //TODO not implemented | |
199 | } |
|
194 | } | |
200 |
|
195 | |||
201 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
196 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
202 | { |
|
197 | { | |
203 | item->setVisible(axis.isAxisVisible()); |
|
198 | item->setVisible(axis.isAxisVisible()); | |
204 | } |
|
199 | } | |
205 |
|
200 | |||
206 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
201 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
207 | { |
|
202 | { | |
208 |
|
203 | |||
209 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
204 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
210 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
205 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
211 |
|
206 | |||
212 | // recalculate title position |
|
207 | // recalculate title position | |
213 | if (m_titleItem) { |
|
208 | if (m_titleItem) { | |
214 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
209 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
215 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
210 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
216 | } |
|
211 | } | |
217 |
|
212 | |||
218 | //recalculate background gradient |
|
213 | //recalculate background gradient | |
219 | if (m_backgroundItem) { |
|
214 | if (m_backgroundItem) { | |
220 | m_backgroundItem->setRect(rect); |
|
215 | m_backgroundItem->setRect(rect); | |
221 | } |
|
216 | } | |
222 |
|
217 | |||
223 | QGraphicsWidget::resizeEvent(event); |
|
218 | QGraphicsWidget::resizeEvent(event); | |
224 | update(); |
|
219 | update(); | |
225 | } |
|
220 | } | |
226 |
|
221 | |||
227 |
|
222 | |||
228 |
|
223 | |||
229 | #include "moc_qchart.cpp" |
|
224 | #include "moc_qchart.cpp" | |
230 |
|
225 | |||
231 | QTCOMMERCIALCHART_END_NAMESPACE |
|
226 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,101 +1,99 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarGroup; |
|
17 | class BarGroup; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
25 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
27 | // public: QChartGraphicsItem(QChart &chart); |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | * TODO: define the responsibilities |
|
30 | * TODO: define the responsibilities | |
31 | */ |
|
31 | */ | |
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum ChartThemeId { |
|
36 | enum ChartThemeId { | |
37 | ChartThemeInvalid = -1, |
|
37 | ChartThemeInvalid = -1, | |
38 | /*! The default theme follows the GUI style of the Operating System */ |
|
38 | /*! The default theme follows the GUI style of the Operating System */ | |
39 | ChartThemeDefault, |
|
39 | ChartThemeDefault, | |
40 | ChartThemeVanilla, |
|
40 | ChartThemeVanilla, | |
41 | ChartThemeIcy, |
|
41 | ChartThemeIcy, | |
42 | ChartThemeGrayscale, |
|
42 | ChartThemeGrayscale, | |
43 | ChartThemeScientific, |
|
43 | ChartThemeScientific, | |
44 | ChartThemeUnnamed1 |
|
44 | ChartThemeUnnamed1 | |
45 | }; |
|
45 | }; | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
49 | ~QChart(); |
|
49 | ~QChart(); | |
50 |
|
50 | |||
51 | void addSeries(QChartSeries* series); |
|
51 | void addSeries(QChartSeries* series); | |
52 |
|
52 | |||
53 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
53 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
54 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
54 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
55 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
55 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
56 |
|
56 | |||
57 | void setMargin(int margin); |
|
57 | void setMargin(int margin); | |
58 | int margin() const; |
|
58 | int margin() const; | |
59 | void setTheme(QChart::ChartThemeId theme); |
|
59 | void setTheme(QChart::ChartThemeId theme); | |
60 | QChart::ChartThemeId theme(); |
|
60 | QChart::ChartThemeId theme(); | |
61 |
|
61 | |||
62 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
62 | void setTitle(const QString& title,const QFont& font = QFont()); | |
63 | void setChartBackgroundBrush(const QBrush& brush); |
|
63 | void setChartBackgroundBrush(const QBrush& brush); | |
64 | void setChartBackgroundPen(const QPen& pen); |
|
64 | void setChartBackgroundPen(const QPen& pen); | |
65 |
|
65 | |||
66 | void zoomInToRect(const QRectF& rectangle); |
|
66 | void zoomInToRect(const QRectF& rectangle); | |
67 | void zoomIn(); |
|
67 | void zoomIn(); | |
68 | void zoomOut(); |
|
68 | void zoomOut(); | |
69 | void zoomReset(); |
|
69 | void zoomReset(); | |
70 |
|
70 | |||
71 | void setAxisX(const QChartAxis& axis); |
|
71 | void setAxisX(const QChartAxis& axis); | |
72 | void setAxisY(const QChartAxis& axis); |
|
72 | void setAxisY(const QChartAxis& axis); | |
73 | void setAxisY(const QList<QChartAxis>& axis); |
|
73 | void setAxisY(const QList<QChartAxis>& axis); | |
74 |
|
74 | |||
75 | protected: |
|
75 | protected: | |
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | void setAxis(AxisItem *item, const QChartAxis& axis); |
|
79 | void setAxis(AxisItem *item, const QChartAxis& axis); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | Q_DISABLE_COPY(QChart) |
|
82 | Q_DISABLE_COPY(QChart) | |
83 | QGraphicsRectItem* m_backgroundItem; |
|
83 | QGraphicsRectItem* m_backgroundItem; | |
84 | QGraphicsTextItem* m_titleItem; |
|
84 | QGraphicsTextItem* m_titleItem; | |
85 | AxisItem* m_axisXItem; |
|
85 | AxisItem* m_axisXItem; | |
86 | QList<AxisItem*> m_axisYItem; |
|
86 | QList<AxisItem*> m_axisYItem; | |
87 | QRectF m_rect; |
|
87 | QRectF m_rect; | |
88 | QList<QChartSeries *> m_chartSeries; |
|
88 | QList<QChartSeries *> m_chartSeries; | |
89 | QList<ChartItem *> m_chartItems; |
|
89 | QList<ChartItem *> m_chartItems; | |
90 | QVector<PlotDomain> m_plotDomainList; |
|
|||
91 | int m_plotDataIndex; |
|
|||
92 | ChartTheme *m_chartTheme; |
|
90 | ChartTheme *m_chartTheme; | |
93 |
|
91 | |||
94 |
|
92 | |||
95 | ChartDataSet *m_dataset; |
|
93 | ChartDataSet *m_dataset; | |
96 | ChartPresenter *m_presenter; |
|
94 | ChartPresenter *m_presenter; | |
97 | }; |
|
95 | }; | |
98 |
|
96 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
100 |
|
98 | |||
101 | #endif |
|
99 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now